function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//******
function SwitchDisplay(n, layout){
	for (var i=0; i<n; i++){
		if ( i=0 ){
			i=1
		} else {
	document.getElementById(current).id=layout; //DynamicDrive.com change	
			}
	}
var current=layout
}
// Add an event listener to an element
function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    //alert("Handler could not be attached");
  }
}

//******
// Remove an event listener from an element
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    //alert("Handler could not be removed");
  }
}

//****** Retrieve a reference to an object in the document
//
function getObj(objID)
{
	if (document.getElementById){
		return document.getElementById(objID);
	} else if (document.all){
		return document.all[objID];
	} else if (document.layers){
		return document.layers[objID];
	}
}

//****** Set a div's display attribute to show
//
function showDiv(div)
{
	getObj(div).style.display = '';
}

//****** Set a div's display attribute to none
//
function hideDiv(div)
{
	getObj(div).style.display = 'none';
}

//******
// Generate a random number
function Rndm(max) {
  return 1 + Math.floor(Math.random() * max);
}

//******
// Send a request to a url through the src
// attribute of an image.
function preserveSession(){
    
    var strReq  = '/index.cfm?fuseAction=preserveSession&random=' + Rndm(10000);
    var imgObj  = getObj('psImg');      
    
    if(imgObj){
        imgObj.src = strReq;       
    }   
   
} 

//******
// Open a popup window
function openWindow(url,name,props){
    newwindow = window.open(url,name,props);
}

//******
// Add a Trim function to the string datatype
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };

//Random Number to prevent Caching
var randomnumber=Math.floor(Math.random()*100000)

//******
// DivID
// ObjectID
// WIDTH - swf file width
// HEIGHT - swf file height
// URL - swf file path
// align - left, right, middle
// varString - cariable string to attach to swf file path
// bgcolor -  hexidecimal color
// scale -  noBorder or leave blank
// autStrt -  true, false
// wmode -  transparent, opaque 
function flashObj(DivID, ObjectID, URL, varString, WIDTH, HEIGHT, align, bgcolor, scale, autoSrt, wmode, version)
{
  document.getElementById(DivID).innerHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='" + version + "' width=" + WIDTH + " height=" + HEIGHT + " id=" + ObjectID + " align=" + align + "><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value=" + URL + varString + "&noCache=" + randomnumber + " /><param name='menu' value='false' /><param name='quality' value='high' /><param name='SCALE' value=" + scale + "><param name='autostart' value="+autoSrt+" /> <param name='bgcolor' value="+ bgcolor +" /><param name='wmode' value="+wmode+" /><embed src=" + URL + varString + "&noCache=" + randomnumber + "' menu='false' quality='high' wmode="+ wmode +" width=" + WIDTH + " name="+ ObjectID +" height=" + HEIGHT + " align=" + align + " allowscriptaccess='sameDomain' type='application/x-shockwave-flash' scale=" + scale + "/></embed></object>";
}

function popNvinSearch(source)
{
	var referral = document.appForm.referral.value;
	
	if(source == 'sponsor'){			
		if(referral.length == 0){
			alert('The Referred By field must be filled first.');
			return;
		}
	}
	
	aWin = window.open('index.cfm?fuseAction=dspVemnSearch&popUp=1&source='+source+'&referral='+referral,'nvinSearchWin','width=550,height=375,top=100,left=100,scrollbars=yes,resizable=yes');
	if(!aWin.focus()) aWin.focus();
}

//Created this function to get around a var name collision on 'source'
function popVemnSearch(curField)
{
	var referral = document.appForm.referral.value;
	
	if(curField == 'sponsor'){			
		if(referral.length == 0){
			alert('The Referred By field must be filled first.');
			return;
		}
	}
	
	aWin = window.open('index.cfm?fuseAction=dspVemnSearch&popUp=1&curField='+curField+'&referral='+referral,'nvinSearchWin','width=550,height=375,top=100,left=100,scrollbars=yes,resizable=yes');
	if(!aWin.focus()) aWin.focus();
}


	function popPolicies()
	{
		var theCountry = document.appForm.countryCode.value;
		if(theCountry == 'JP'){
			aWin = window.open('../backoffice/pdf/Vemma_pnp_Japanese_013006.pdf','PolicyWindow','width=700,height=350,top=100,left=100,scrollbars=yes,resizable=yes');
		}
		else{
			aWin = window.open('../backoffice/pdf/vemmapnp.pdf','PolicyWindow','width=700,height=350,top=100,left=100,scrollbars=yes,resizable=yes');
		}
		
	}
	
	function popAgreement()
	{
		var strLink;
		var strParams;
		var theCountry = document.appForm.countryCode.value;
		if(theCountry == "USA"){
			strLink = 'http://vemma.com/checkOut/html/vemma_agreement.html';
			strParams	= 'width=520,height=350,top=100,left=100,scrollbars=yes';
		}
		else if(theCountry == "CA"){
			strLink	= 'pdf/CanadaAnA.pdf';
			strParams	= 'width=700,height=350,top=100,left=100,scrollbars=yes,resizable=yes';
		}	
		else if(theCountry == "AUS" || theCountry == "NZL"){
			strLink = 'pdf/AUSAnA.pdf';
			strParams	= 'width=700,height=350,top=100,left=100,scrollbars=yes,resizable=yes';
		}
		else if(theCountry == 'SG' || theCountry == 'PH' || theCountry == 'MY' || theCountry == 'ID' || theCountry == 'TW' || theCountry == 'HK'){
			strLink = 'pdf/AsiaVemma_Reg_Form.pdf';
			strParams	= 'width=700,height=350,top=100,left=100,scrollbars=yes,resizable=yes';
		}
		else if(theCountry == 'JP'){
			strLink	= 'pdf/Vemma_Gaiyo-shomen_print_Jan06.pdf';
			strParams	= 'width=700,height=350,top=100,left=100,scrollbars=yes,resizable=yes';
		}
		else{
			strLink = 'pdf/european_union_policy.pdf';
			strParams	= 'width=700,height=350,top=100,left=100,scrollbars=yes,resizable=yes';
		}	
		
		aWin = window.open(strLink,'AgreeWindow',strParams);
	}	

//*********************
function stripAlphaChars(pstrSource) 
{ 
var m_strOut = new String(pstrSource); 
    m_strOut = m_strOut.replace(/[^0-9]/g, ''); 

    return m_strOut; 
}

//*******************
//JavaScript does not offer Left and Right functions. Use the following functions to extract the left or the right part of a string.
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}
/* 
Methods for resizing the flash stage at runtime.

setFlashWidth(divid, newW)
divid: id of the div containing the flash movie.
newW: new width for flash movie

setFlashWidth(divid, newH)
divid: id of the div containing the flash movie.
newH: new height for flash movie

setFlashSize(divid, newW, newH)
divid: id of the div containing the flash movie.
newW: new width for flash movie
newH: new height for flash movie

canResizeFlash()
returns true if browser supports resizing flash, false if not. 
*/
function setFlashWidth(divid, newW){
	document.getElementById(divid).style.width = newW+"px";
}
function setFlashHeight(divid, newH){
	document.getElementById(divid).style.height = newH+"px";		
}
function setFlashSize(divid, newW, newH){
	setFlashWidth(divid, newW);
	setFlashHeight(divid, newH);
}
function canResizeFlash(){
	var ua = navigator.userAgent.toLowerCase();
	var opera = ua.indexOf("opera");
	if( document.getElementById ){
		if(opera == -1) return true;
		else if(parseInt(ua.substr(opera+6, 1)) >= 7) return true;
	}
	return false;
}

