var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function GetNext(CurrentField,NextField,NumberForNext)
{

	if (CurrentField.value.length==NumberForNext)
	NextField.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.25";

	

	if (document.forms["Form1"].elements["TxtBillingStateList"].value=="CA")
	{
		alert("A "+TaxAmount+"% tax will automatically be added to the subtotal for 'CA'");
		x.innerHTML=TaxAmount;
	}
	else	
		x.innerHTML="0.00";

	
	z.innerHTML=(x.innerHTML * y.innerHTML/100).toFixed(2);
	document.getElementById("TotalTxt").innerHTML=((y.innerHTML-0) + (s.innerHTML-0)+ (z.innerHTML-0)).toFixed(2);

}

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)
    {
    CartForm.action="UpdateCart.aspx?m="+method;
    CartForm.submit();
       }
    
    
    function CalculateShipping(ShippingID)
    {
	
        document.getElementById("ShippingCostTxt").innerHTML=ShippingArray[ShippingID].toFixed(2);
        
       var ShippingFixed =ShippingArray[ShippingID];
       var TotalCostFixed = document.getElementById("SubTotalTxt").innerHTML;
       var Total=0;
        
		Total=parseFloat(ShippingFixed/1)+parseFloat(TotalCostFixed/1);
		
		document.getElementById("TotalTxt").innerHTML=Total.toFixed(2);
       
       
       //document.getElementById("TotalTxt").innerHTML=(parseFloat((ShippingFixed/1).toFixed(2))+parseFloat((TotalCostFixed/1).toFixed(2))).toFixed(2);
        
    
    }
 //END STUFF PULLED OUT FROM VIEWCART.ASPX   