function MM_swapImgRestore() { 
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function popup(mypage, myname, w, h, scroll,tool,stat) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable,toolbar='+tool+',status='+stat+''
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) 
		{ 
			win.window.focus(); 
		}
}
function popup2(mypage, myname, w, h, scroll,tool,stat,menu) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable,toolbar='+tool+',status='+stat+',menubar='+menu+''
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) 
		{ 
			win.window.focus(); 
		}
}

function updateparent(newurl)
{
	if (window.opener && !window.opener.closed) 
		{
			window.opener.location = newurl; 
			window.close();
		} 
	else 
		{
			window.location = newurl;
		}
/*	
opener.document.location=newurl;
window.close();
*/
}

function MM_callJS(jsStr) {
  return eval(jsStr)
}

function open_window(mypage, myname, w, h, scroll,tool,stat) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable,toolbar='+tool+',status='+stat+''
	win = window.open(mypage, myname, winprops)
	//if (parseInt(navigator.appVersion) >= 4) 
		//{ 
			//win.window.focus(); 
	//	}
}
function trim(str)
{
    str.replace(/^\s*/, '').replace(/\s*$/, '');
	return str;
}
function getHTTPVariable(_var, _loc)
	{
		var input = _loc.search.substring(1);
		if (input)
			{
				var _search = input.split("&");
				var _tmp = new Array();
				for (i = 0; i < _search.length; i++)
					{
						_tmp = _search[i].split("=");
						if (_tmp[0] == _var)
							return _tmp[1];
						}
							if(_search.length <= 0)
							{
								_tmp = _input.split('=');
								return _tmp[1];
							}
						return "";
					}
				return "";
			}

function emailCheck (emailStr)
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Please input a valid E-mail Address (check @ and .'s). Thank You.")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) {
	    alert("The username doesn't seem to be valid. Please input a valid E-mail Address. Thank You.")
	    return false
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
			    if (IPArray[i]>255) {
			        alert("Destination IP address is invalid! Please input a valid Email Address. Thank You.")
					return false
			    }
		    }
	    return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("The domain name doesn't seem to be valid. Please input a valid Email Address. Thank You.")
	    return false
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 ||
	    domArr[domArr.length-1].length>3) {
	   alert("The address must end in a three-letter domain, or two letter country. Please input a valid Email Address. Thank You.")
	   return false
	}

	if (len<2) {
	   var errStr="This address is missing a hostname. Please input a valid E-mail Address. Thank You."
	   alert(errStr)
	   return false
	}

	return true;
}


function survey_chk_answers(_form, survey_number)
{
	var ctr = 0;
	for (idx=0;idx<_form.elements.length;idx++)
	{
		var _element = _form.elements[idx];
		var _type = _element.type;
		
		if((_type =="textarea") && (_element.value == ""))
		{
			alert("Please provide answer for this question. Thank you.");
			_element.focus();
			ctr++;
			break;
		}
	}
	
	//all questions are answered
	if(ctr == 0)
	{
		transfer_data(survey_number, _form)
		_form.submit();
	}
}


function transfer_data(current_page, _form)
{
	switch(current_page)
	{
		case "personal":
			_form.hfname.value = _form.fname.value;
			_form.hlname.value = _form.lname.value;
			_form.htitle.value = _form.title.value;
			_form.hcompany.value = _form.company.value;
			_form.haddress.value = _form.address.value;
			_form.hcity.value = _form.city.value;
			_form.hprovince.value = _form.province.value;
			_form.hcountry.value = _form.country.value;
			_form.hemail.value = _form.email.value;
			_form.hchain_role.value = _form.chain_role[_form.chain_role.selectedIndex].value;
			_form.hppis.value = _form.ppis[_form.ppis.selectedIndex].value;
			_form.hwebsite.value = _form.website.value;
		break;
		
		case "survey1":
			_form.hq1.value = _form.q1.value;
			_form.hq2.value = _form.q2.value;
			_form.hq3.value = _form.q3.value;
		break;
		
		case "survey2":
			_form.hq4.value = _form.q4.value;
			_form.hq5.value = _form.q5.value;
			_form.hq6.value = _form.q6.value;
			_form.hq7.value = _form.q7.value;
		break;
		
		case "survey3":
			_form.hq8.value = _form.q8.value;
			_form.hq9.value = _form.q9.value;
			_form.hq10.value = _form.q10.value;
			_form.hq11.value = _form.q11.value;
			_form.hq12.value = _form.q12.value;
		break;				
	}	
}	

function calculate(_value, lang)
{
	quant = document.frm_paypal.quantity.value;

	//set dvd amount
	if(_value == "rw")
	{
		document.frm_paypal.currency_code.value = "USD";
		this_amount = 115;

		//hide states select box
		document.frm_paypal.state.options[0].selected = true;
		container = document.getElementById('stateContainer');
		container.style.display = "none";
		
		
		//calculate shipping
		if(eval(quant) == 1)
		{ ship_amount = 10; }
		else if((eval(quant) > 1) && (eval(quant) <= 5))
		{ ship_amount = 13; }
		else if((eval(quant) > 5) && (eval(quant) <= 10))
		{ ship_amount = 21; }
		else
		{ ship_amount = 0; quant = 0;}
		
		total = eval(this_amount) * eval(quant);		
					
		document.frm_paypal.shipping.value = ship_amount;
		document.frm_paypal.ship_amount.value = "$ "+ship_amount;
		document.frm_paypal.item_amount.value = "$ "+total+" ($ "+this_amount+" @ "+quant+")";
		document.frm_paypal.tax_amount.value = "0.00";
		document.frm_paypal.tax.value = "0";
	}
	else if(_value == "eu")
	{
		document.frm_paypal.currency_code.value = "EUR";
		this_amount = 90;
		
		
		//hide states select box
		document.frm_paypal.state.options[0].selected = true;
		container = document.getElementById('stateContainer');
		container.style.display = "none";
		
		//calculate shipping
		if(eval(quant) == 1)
		{ ship_amount = 6; }
		else if((eval(quant) > 1) && (eval(quant) <= 5))
		{ ship_amount = 8; }
		else if((eval(quant) > 5) && (eval(quant) <= 10))
		{ ship_amount = 13; }
		else
		{ ship_amount = 0; quant = 0;}		
		
		total = eval(this_amount) * eval(quant);
		
		document.frm_paypal.shipping.value = ship_amount;
		document.frm_paypal.ship_amount.value = "€ "+ship_amount;
		document.frm_paypal.item_amount.value = "€ "+total+" (€ "+this_amount+" @ "+quant+")";
		document.frm_paypal.tax_amount.value = "0.00";
		document.frm_paypal.tax.value = "0";
		
	}
	else if(_value == "ss")
	{
		document.frm_paypal.currency_code.value = "USD";
		this_amount = 115;
		
		container = document.getElementById('stateContainer');
		container.style.display = "block";
		
		//calculate shipping
		if(eval(quant) == 1)
		{ ship_amount = 10; }
		else if((eval(quant) > 1) && (eval(quant) <= 5))
		{ ship_amount = 13; }
		else if((eval(quant) > 5) && (eval(quant) <= 10))
		{ ship_amount = 21; }
		else
		{ ship_amount = 0; quant = 0;}
		
		total = eval(this_amount) * eval(quant);		
		
			
		document.frm_paypal.shipping.value = ship_amount;
		document.frm_paypal.ship_amount.value = "$ "+ship_amount;
		document.frm_paypal.item_amount.value = "$ "+total+" ($ "+this_amount+" @ "+quant+")";				
		
	}
	
	if(_value == "")
	{
		document.frm_paypal.item_amount.value = "Please select country.";
	}
	
	if(document.frm_paypal.quantity.value == 0)
	{
		if(lang == 'en') {
			document.frm_paypal.item_amount.value = "Please select quantity.";
		}
		else {
			document.frm_paypal.item_amount.value = "Selectionner une quantité";
		}		
	}
	
	document.frm_paypal.amount.value = this_amount;		
}

function calculate125(_value, lang)
{
	quant = document.frm_paypal.quantity.value;

	//set dvd amount
	if(_value == "rw")
	{
		document.frm_paypal.currency_code.value = "USD";
		this_amount = 125;

		//hide states select box
		document.frm_paypal.state.options[0].selected = true;
		container = document.getElementById('stateContainer');
		container.style.display = "none";
		
		
		//calculate shipping
		if(eval(quant) == 1)
		{ ship_amount = 10; }
		else if((eval(quant) > 1) && (eval(quant) <= 5))
		{ ship_amount = 13; }
		else if((eval(quant) > 5) && (eval(quant) <= 10))
		{ ship_amount = 21; }
		else
		{ ship_amount = 0; quant = 0;}
		
		total = eval(this_amount) * eval(quant);		
					
		document.frm_paypal.shipping.value = ship_amount;
		document.frm_paypal.ship_amount.value = "$ "+ship_amount;
		document.frm_paypal.item_amount.value = "$ "+total+" ($ "+this_amount+" @ "+quant+")";
		document.frm_paypal.tax_amount.value = "0.00";
		document.frm_paypal.tax.value = "0";
	}
	else if(_value == "eu")
	{
		document.frm_paypal.currency_code.value = "EUR";
		this_amount = 95;
		
		
		//hide states select box
		document.frm_paypal.state.options[0].selected = true;
		container = document.getElementById('stateContainer');
		container.style.display = "none";
		
		//calculate shipping
		if(eval(quant) == 1)
		{ ship_amount = 6; }
		else if((eval(quant) > 1) && (eval(quant) <= 5))
		{ ship_amount = 8; }
		else if((eval(quant) > 5) && (eval(quant) <= 10))
		{ ship_amount = 13; }
		else
		{ ship_amount = 0; quant = 0;}		
		
		total = eval(this_amount) * eval(quant);
		
		document.frm_paypal.shipping.value = ship_amount;
		document.frm_paypal.ship_amount.value = "€ "+ship_amount;
		document.frm_paypal.item_amount.value = "€ "+total+" (€ "+this_amount+" @ "+quant+")";
		document.frm_paypal.tax_amount.value = "0.00";
		document.frm_paypal.tax.value = "0";
		
	}
	else if(_value == "ss")
	{
		document.frm_paypal.currency_code.value = "USD";
		this_amount = 125;
		
		container = document.getElementById('stateContainer');
		container.style.display = "block";
		
		//calculate shipping
		if(eval(quant) == 1)
		{ ship_amount = 10; }
		else if((eval(quant) > 1) && (eval(quant) <= 5))
		{ ship_amount = 13; }
		else if((eval(quant) > 5) && (eval(quant) <= 10))
		{ ship_amount = 21; }
		else
		{ ship_amount = 0; quant = 0;}
		
		total = eval(this_amount) * eval(quant);		
		
			
		document.frm_paypal.shipping.value = ship_amount;
		document.frm_paypal.ship_amount.value = "$ "+ship_amount;
		document.frm_paypal.item_amount.value = "$ "+total+" ($ "+this_amount+" @ "+quant+")";				
		
	}
	
	if(_value == "")
	{
		document.frm_paypal.item_amount.value = "Please select country.";
	}
	
	if(document.frm_paypal.quantity.value == 0)
	{
		if(lang == 'en') {
			document.frm_paypal.item_amount.value = "Please select quantity.";
		}
		else {
			document.frm_paypal.item_amount.value = "Selectionner une quantité";
		}		
	}
	
	document.frm_paypal.amount.value = this_amount;		
}

function calculate_item(_value, lang)
{
	currency = document.frm_paypal.currency_code.value;
	quant = _value;
	if(currency == "USD")
	{			
		amount = 115;
		
		//calculate shipping
		if(eval(quant) == 1)
		{ ship_amount = 10; }
		else if((eval(quant) > 1) && (eval(quant) <= 5))
		{ ship_amount = 13; }
		else if((eval(quant) > 5) && (eval(quant) <= 10))
		{ ship_amount = 21; }
		else
		{ ship_amount = 0; quant = 0;}
		
		
		total = eval(amount) * eval(quant);
		
		if(document.frm_paypal.country_code.options[document.frm_paypal.country_code.selectedIndex].value == "ss")
		{
			if(document.frm_paypal.state.options[document.frm_paypal.state.selectedIndex].value == "")
			{
				document.frm_paypal.tax_amount.value = "Please select a State";
				document.frm_paypal.tax.value = "0";
			}
			else if(document.frm_paypal.state.options[document.frm_paypal.state.selectedIndex].value == "ca")
			{
				mytax = total * .0825;
				round_tax = Math.round(mytax * 100)/100 ;
				document.frm_paypal.tax.value = round_tax;
				document.frm_paypal.tax_amount.value = round_tax;			
			}
			else
			{
				document.frm_paypal.tax_amount.value = "0.00";
				document.frm_paypal.tax.value = "0";
			}
		}
		
		document.frm_paypal.shipping.value = ship_amount;
		document.frm_paypal.ship_amount.value = "$ "+ship_amount;
		document.frm_paypal.item_amount.value = "$ "+total+" ($ "+this_amount+" @ "+quant+")";	
	}
	else if(currency == "EUR")
	{
		amount = 90;
		
		//calculate shipping
		if(eval(quant) == 1)
		{ ship_amount = 6; }
		else if((eval(quant) > 1) && (eval(quant) <= 5))
		{ ship_amount = 8; }
		else if((eval(quant) > 5) && (eval(quant) <= 10))
		{ ship_amount = 13; }
		else
		{ ship_amount = 0; quant = 0;}
		
		
		total = eval(amount) * eval(quant);
		
		document.frm_paypal.shipping.value = ship_amount;
		document.frm_paypal.ship_amount.value = "€ "+ship_amount;
		document.frm_paypal.item_amount.value = "€ "+total+" (€ "+this_amount+" @ "+quant+")";
		
		document.frm_paypal.tax_amount.value = "0.00";
		document.frm_paypal.tax.value = "0";
		
	}
	
	if(_value == 0)
	{
		
		if(lang == 'en') {
			document.frm_paypal.item_amount.value = "Please select quantity.";
		}
		else {
			document.frm_paypal.item_amount.value = "Selectionner une quantité";
		}
	}
	
	if(document.frm_paypal.country_code.options[document.frm_paypal.country_code.options.selectedIndex].value == "")
	{
		document.frm_paypal.item_amount.value = "Please select country.";
	}
		
}



function calculate_item125(_value, lang)
{
	currency = document.frm_paypal.currency_code.value;
	quant = _value;
	if(currency == "USD")
	{			
		amount = 125;
		
		//calculate shipping
		if(eval(quant) == 1)
		{ ship_amount = 10; }
		else if((eval(quant) > 1) && (eval(quant) <= 5))
		{ ship_amount = 13; }
		else if((eval(quant) > 5) && (eval(quant) <= 10))
		{ ship_amount = 21; }
		else
		{ ship_amount = 0; quant = 0;}
		
		
		total = eval(amount) * eval(quant);
		
		if(document.frm_paypal.country_code.options[document.frm_paypal.country_code.selectedIndex].value == "ss")
		{
			if(document.frm_paypal.state.options[document.frm_paypal.state.selectedIndex].value == "")
			{
				document.frm_paypal.tax_amount.value = "Please select a State";
				document.frm_paypal.tax.value = "0";
			}
			else if(document.frm_paypal.state.options[document.frm_paypal.state.selectedIndex].value == "ca")
			{
				mytax = total * .0825;
				round_tax = Math.round(mytax * 100)/100 ;
				document.frm_paypal.tax.value = round_tax;
				document.frm_paypal.tax_amount.value = round_tax;			
			}
			else
			{
				document.frm_paypal.tax_amount.value = "0.00";
				document.frm_paypal.tax.value = "0";
			}
		}
		
		document.frm_paypal.shipping.value = ship_amount;
		document.frm_paypal.ship_amount.value = "$ "+ship_amount;
		document.frm_paypal.item_amount.value = "$ "+total+" ($ "+this_amount+" @ "+quant+")";	
	}
	else if(currency == "EUR")
	{
		amount = 95;
		
		//calculate shipping
		if(eval(quant) == 1)
		{ ship_amount = 6; }
		else if((eval(quant) > 1) && (eval(quant) <= 5))
		{ ship_amount = 8; }
		else if((eval(quant) > 5) && (eval(quant) <= 10))
		{ ship_amount = 13; }
		else
		{ ship_amount = 0; quant = 0;}
		
		
		total = eval(amount) * eval(quant);
		
		document.frm_paypal.shipping.value = ship_amount;
		document.frm_paypal.ship_amount.value = "€ "+ship_amount;
		document.frm_paypal.item_amount.value = "€ "+total+" (€ "+this_amount+" @ "+quant+")";
		
		document.frm_paypal.tax_amount.value = "0.00";
		document.frm_paypal.tax.value = "0";
		
	}
	
	if(_value == 0)
	{
		
		if(lang == 'en') {
			document.frm_paypal.item_amount.value = "Please select quantity.";
		}
		else {
			document.frm_paypal.item_amount.value = "Selectionner une quantité";
		}
	}
	
	if(document.frm_paypal.country_code.options[document.frm_paypal.country_code.options.selectedIndex].value == "")
	{
		document.frm_paypal.item_amount.value = "Please select country.";
	}
		
}

function calculateByState(_value, lang)
{

	if(document.frm_paypal.quantity.value == 0)
	{
		if(lang == 'en') {
			document.frm_paypal.item_amount.value = "Please select quantity.";
		}
		else {
			document.frm_paypal.item_amount.value = "Selectionner une quantité";
		}
		document.frm_paypal.tax_amount.value = "0.00";
		document.frm_paypal.tax.value = "0";
		
	}
	else
	{
		amount = 115;
		this_amount = document.frm_paypal.amount.value;
		quant = document.frm_paypal.quantity.value;
		
		total = eval(amount) * eval(quant);		
		
		//if state is California, add 8.25% for state tax
		if(_value == "ca")
		{
			mytax = total * .0825;
			round_tax = Math.round(mytax * 100)/100 ;
			document.frm_paypal.tax.value = round_tax;
			document.frm_paypal.tax_amount.value = round_tax;
		}
		else
		{
			document.frm_paypal.tax_amount.value = "0.00";
			document.frm_paypal.tax.value = "0";
		}
	}
}


function calculateByState125(_value, lang)
{

	if(document.frm_paypal.quantity.value == 0)
	{
		if(lang == 'en') {
			document.frm_paypal.item_amount.value = "Please select quantity.";
		}
		else {
			document.frm_paypal.item_amount.value = "Selectionner une quantité";
		}
		document.frm_paypal.tax_amount.value = "0.00";
		document.frm_paypal.tax.value = "0";
		
	}
	else
	{
		amount = 125;
		this_amount = document.frm_paypal.amount.value;
		quant = document.frm_paypal.quantity.value;
		
		total = eval(amount) * eval(quant);		
		
		//if state is California, add 8.25% for state tax
		if(_value == "ca")
		{
			mytax = total * .0825;
			round_tax = Math.round(mytax * 100)/100 ;
			document.frm_paypal.tax.value = round_tax;
			document.frm_paypal.tax_amount.value = round_tax;
		}
		else
		{
			document.frm_paypal.tax_amount.value = "0.00";
			document.frm_paypal.tax.value = "0";
		}
	}
}

function check_paypalemail(_form)
{
	if(_form.email.value == "")
	{
		alert("Please enter your email address.");
		_form.email.focus();
		return false;
	}
	else
	{
		if (!emailCheck(trim(_form.email.value)))
		{
			_form.email.focus();
			return false;
		}
	}
	
	if(_form.email2.value == "")
	{
		alert("Please re-enter your email address.");
		_form.email2.focus();
		return false;
	}
	else if(trim(_form.email.value) != trim(_form.email2.value))
	{
		alert("Make sure that it matches your email address.");
		_form.email2.focus();
		return false;
	}

	if(_form.night_phone_a.value == "")
	{
		alert("Please enter your area code.");
		_form.night_phone_a.focus();
		return false;
	}
	
	if(_form.night_phone_b.value == "")
	{
		alert("Please enter your telephone number.");
		_form.night_phone_b.focus();
		return false;
	}

	return true;
}


function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}