var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTabContact(input,len,e)
{

				var keyCode = (isNN) ? e.which : e.keyCode; 
				var filter = (isNN) ? [0,8,9,16,17,18] : [0,8,9,16,17,18,37,38,39,40,46];
				if(input.value.length >= len && !containsElement(filter,keyCode)) {
					input.value = input.value.slice(0, len);
					input.form[(getIndex(input)+1) % input.form.length].focus();
					//input.form[(getIndex(input)+1) % input.form.length].select();
					return input;
}
}


function GetNext(CurrentField,NextField,NumberForNext)
{

	if (CurrentField.value.length==NumberForNext)
	NextField.focus();

}

function OpenWindow(theURL,Name,Params)
{
x=window.open(theURL,Name,Params);
x.focus();
}
function OpenBrWindow(theURL) 
{ 

x=window.open(theURL,'newWindow','scrollbars=yes,resizable=yes,width=350,height=450');
x.focus();
}

function OpenSmallBrWindow(theURL) 
{ 
 

x = window.open(theURL,'smallWindow','scrollbars=yes,resizable=yes,width=350,height=200');
x.focus();
}


			


				function autoTab(input,len, e) {
				SameInfo();
				var keyCode = (isNN) ? e.which : e.keyCode; 
				var filter = (isNN) ? [0,8,9,16,17,18] : [0,8,9,16,17,18,37,38,39,40,46];
				if(input.value.length >= len && !containsElement(filter,keyCode)) {
					input.value = input.value.slice(0, len);
					input.form[(getIndex(input)+1) % input.form.length].focus();
					//input.form[(getIndex(input)+1) % input.form.length].select();
					return input;
				}
			
				function containsElement(arr, ele) {
					var found = false, index = 0;
					while(!found && index < arr.length)
						if(arr[index] == ele)
							found = true;
						else
							index++;
							return found;
				}
				
				function getIndex(input) {
					var index = -1, i = 0, found = false;
					while (i < input.form.length && index == -1)
						if (input.form[i] == input)index = i;
							else i++;
							return index;
					}
					return true;
			}



function CopyShippingInfo()
{

	if (document.Form1.CopyShipping.checked==true)
	{
		document.forms["Form1"].elements["TxtShippingFirstName"].value=document.forms["Form1"].elements["TxtBillingFirstName"].value;
		document.forms["Form1"].elements["TxtShippingLastName"].value=document.forms["Form1"].elements["TxtBillingLastName"].value;
		document.forms["Form1"].elements["TxtShippingCompany"].value=document.forms["Form1"].elements["TxtBillingCompany"].value;
		document.forms["Form1"].elements["TxtShippingAddress1"].value=document.forms["Form1"].elements["TxtBillingAddress1"].value;
		document.forms["Form1"].elements["TxtShippingAddress2"].value=document.forms["Form1"].elements["TxtBillingAddress2"].value;
		document.forms["Form1"].elements["TxtShippingCity"].value=document.forms["Form1"].elements["TxtBillingCity"].value;
		document.forms["Form1"].elements["TxtShippingZip"].value=document.forms["Form1"].elements["TxtBillingZip"].value;
		document.forms["Form1"].elements["ShippingPhoneA"].value=document.forms["Form1"].elements["PhoneA"].value;
		document.forms["Form1"].elements["ShippingPhoneB"].value=document.forms["Form1"].elements["PhoneB"].value;
		document.forms["Form1"].elements["ShippingPhoneC"].value=document.forms["Form1"].elements["PhoneC"].value;
		document.forms["Form1"].elements["ShippingPhoneX"].value=document.forms["Form1"].elements["PhoneX"].value;
		document.forms["Form1"].elements["ShippingStateList"].value=document.forms["Form1"].elements["TxtBillingStateList"].value;
	}

	if (document.Form1.CopyShipping.checked==false)
	{
		document.forms["Form1"].elements["TxtShippingFirstName"].value="";
		document.forms["Form1"].elements["TxtShippingLastName"].value="";
		document.forms["Form1"].elements["TxtShippingCompany"].value="";
		document.forms["Form1"].elements["TxtShippingAddress1"].value="";
		document.forms["Form1"].elements["TxtShippingAddress2"].value="";
		document.forms["Form1"].elements["TxtShippingCity"].value="";
		document.forms["Form1"].elements["ShippingStateList"].value="-";
		document.forms["Form1"].elements["TxtShippingZip"].value="";
		document.forms["Form1"].elements["ShippingPhoneA"].value="";
		document.forms["Form1"].elements["ShippingPhoneB"].value="";
		document.forms["Form1"].elements["ShippingPhoneC"].value="";
		document.forms["Form1"].elements["ShippingPhoneX"].value="";
	}



	



}

function SameInfo()
{
	if (document.Form1.CopyShipping.checked==true)
	{
		document.forms["Form1"].elements["TxtShippingFirstName"].value=document.forms["Form1"].elements["TxtBillingFirstName"].value;
		document.forms["Form1"].elements["TxtShippingLastName"].value=document.forms["Form1"].elements["TxtBillingLastName"].value;
		document.forms["Form1"].elements["TxtShippingCompany"].value=document.forms["Form1"].elements["TxtBillingCompany"].value;
		document.forms["Form1"].elements["TxtShippingAddress1"].value=document.forms["Form1"].elements["TxtBillingAddress1"].value;
		document.forms["Form1"].elements["TxtShippingAddress2"].value=document.forms["Form1"].elements["TxtBillingAddress2"].value;
		document.forms["Form1"].elements["TxtShippingCity"].value=document.forms["Form1"].elements["TxtBillingCity"].value;
		document.forms["Form1"].elements["TxtShippingZip"].value=document.forms["Form1"].elements["TxtBillingZip"].value;
		document.forms["Form1"].elements["ShippingPhoneA"].value=document.forms["Form1"].elements["PhoneA"].value;
		document.forms["Form1"].elements["ShippingPhoneB"].value=document.forms["Form1"].elements["PhoneB"].value;
		document.forms["Form1"].elements["ShippingPhoneC"].value=document.forms["Form1"].elements["PhoneC"].value;
		document.forms["Form1"].elements["ShippingPhoneX"].value=document.forms["Form1"].elements["PhoneX"].value;
		document.forms["Form1"].elements["ShippingStateList"].value=document.forms["Form1"].elements["TxtBillingStateList"].value;
	}



}

function CheckStateTax()
{

	var s = document.getElementById("ShippingCostTxt");
	var x = document.getElementById("TaxCalc");	
	var y = document.getElementById("SubTotalTxt");
	var z = document.getElementById("TaxInc");
	var TaxAmount="8.75";

	

	if ( (document.forms["Form1"].elements["BillingStateTxt"].value=="CA") ||(document.forms["Form1"].elements["BillingStateTxt"].value=="ca") )
	{

		alert("An "+TaxAmount+"% tax amount will be automatically added to your total if ordering from 'CA'");
		x.innerHTML=TaxAmount;
	}
	else	
		x.innerHTML="0.00";


	
	z.innerHTML=(x.innerHTML.replace(/\,/g,'') * y.innerHTML.replace(/\,/g,'')/100).toFixed(2);
	document.getElementById("TotalTxt").innerHTML=(y.innerHTML.replace(/\,/g,'')-0)+(s.innerHTML.replace(/\,/g,'')-0)+(z.innerHTML.replace(/\,/g,'')-0);
	

}

function limitText(limitField, limitCount, limitNum) {

	



	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.innerHTML  = limitNum - limitField.value.length;
	}



}
 

//ALL PULLED OUT FROM VIEWCART.ASPX
   
    function CheckInput(sText)
    {
		var ValidChars = "0123456789";
		var IsNumber=true;
		var Char;
		
		 for (i = 0; i < sText.value.length && IsNumber == true; i++) 
		  { 
			Char = sText.value.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) 
			{
				IsNumber = false;
			}
		}

		
	if (IsNumber==false)
	{
		alert("Input must be a number");
		sText.value=0;
	}
	
    }
    
    function CheckInput2(sText)
    {
    
		if (sText.value.length==0)
			sText.value=0;
	
    
    }
    
	//This function updates the cart according to the method that is called.
    function CheckoutProc(method)
    {
    document.CartForm.action="UpdateCart.aspx?m="+method;
    document.CartForm.submit();
       }
    
    
    function CalculateShipping(ShippingID)
    {

	 var CountryShippingFixed= document.getElementById("CountryCostTxt").innerHTML;
	 var HandlingFixed = document.getElementById("HandlingCostTxt").innerHTML;	
	
	if (CountryShippingFixed!=0)
	{
		alert('The shipping you have selected is not available for international Orders');
		document.CartForm.ShippingList.selectedIndex=3;      
		document.getElementById("ShippingCostTxt").innerHTML="0.00";

	}
	else
	{
		if (document.CartForm.ShippingList.selectedIndex==3)
		{
			HandlingFixed=3;
			document.getElementById("HandlingCostTxt").innerHTML="3.00";
		}
		else
			document.getElementById("HandlingCostTxt").innerHTML=JSHandlingCost.toFixed(2);



      	document.getElementById("ShippingCostTxt").innerHTML=ShippingArray[ShippingID].toFixed(2);

      	var ShippingFixed =ShippingArray[ShippingID];

      	var TotalCostFixed = document.getElementById("SubTotalTxt").innerHTML;
      
      	var Total=0;
        
		Total=parseFloat(CountryShippingFixed/1)+parseFloat(TotalCostFixed/1)+parseFloat(ShippingFixed/1)+parseFloat(HandlingFixed/1);
		
		document.getElementById("TotalTxt").innerHTML=Total.toFixed(2);

	
	}
        
    
    }

 function CalculateCountry(ShippingCountryID)
    {


if ((ShippingCountryID=="226")||(ShippingCountryID=="14")||(ShippingCountryID=="21")||(ShippingCountryID=="33")||(ShippingCountryID=="55")||(ShippingCountryID=="57")||(ShippingCountryID=="74")||(ShippingCountryID=="75")||(ShippingCountryID=="82")||(ShippingCountryID=="36")||(ShippingCountryID=="99")||(ShippingCountryID=="100")||(ShippingCountryID=="103")||(ShippingCountryID=="141")||(ShippingCountryID=="150")||(ShippingCountryID=="161")||(ShippingCountryID=="171")||(ShippingCountryID=="176")||(ShippingCountryID=="187")||(ShippingCountryID=="193")||(ShippingCountryID=="194")||(ShippingCountryID=="207")||(ShippingCountryID=="208"))
{
alert("We currently do not ship to the EU. To place an order, please visit 'http://www.energiseforlife.com'");
}
       document.getElementById("CountryCostTxt").innerHTML=CountryShippingArray[ShippingCountryID].toFixed(2);

       var CountryShippingFixed = CountryShippingArray[ShippingCountryID];
      
	if (CountryShippingFixed!=0)
	{
		document.CartForm.ShippingList.selectedIndex=3;      
		document.getElementById("ShippingCostTxt").innerHTML="0.00";
		
  	}
	else
	{
		document.CartForm.ShippingList.selectedIndex=0;      
		document.getElementById("ShippingCostTxt").innerHTML=ShippingArray[1].toFixed(2);
		

	}

	var TotalCostFixed = document.getElementById("SubTotalTxt").innerHTML;
       var ShippingFixed = document.getElementById("ShippingCostTxt").innerHTML;
       var Total=0;


	Total=parseFloat(CountryShippingFixed/1)+parseFloat(TotalCostFixed/1)+parseFloat(ShippingFixed/1);
		
	document.getElementById("TotalTxt").innerHTML=Total.toFixed(2);
       
     alert("International shipping rates vary from Country to Country dependent also on the postal codes. International shipping charge of $75 may not include the complete fees for shipping. The customer may be charged additionally over and above that amount due. perfectlyhealthy team members will notify a customer of additional shipping charges before product is shipped via email.");
    
    }
 //END STUFF PULLED OUT FROM VIEWCART.ASPX   


function ShowMenu(MenuName)
{
	HideAllMenus();
	document.getElementById(MenuName).style.visibility="visible";
}
	
function HideAllMenus()
{
	document.getElementById("ProductsMenu").style.visibility="hidden";
}
	
