// JavaScript Document

//Options for Everyone:
MonetarySymbol        = '$';
TaxRate               = 0.06;
TaxByRegion           = false;
TaxPrompt             = 'For tax purposes, please select if you are an Michigan resident before continuing';
TaxablePrompt         = 'Michigan Residents';
NonTaxablePrompt      = 'Other States';
MinimumOrder          = 0.00;
taxtogoindex          = 0;
orderitems			  = "";

//Payment Processor Options:
PaymentProcessor      = 'lp';
//Shopaccountnumber	  = '1001184055';

function RadioChecked( radiobutton ) {
   var bChecked = false;
   var rlen = radiobutton.length;
   for ( i=0; i < rlen; i++ ) {
      if ( radiobutton[i].checked )
         bChecked = true;
   }    
   return bChecked;
} 
function moneyFormat(input) {
   var dollars = Math.floor(input);
   var tmp = new String(input);

   for ( var decimalAt = 0; decimalAt < tmp.length; decimalAt++ ) {
      if ( tmp.charAt(decimalAt)=="." )
         break;
   }

   var cents  = "" + Math.round(input * 100);
   cents = cents.substring(cents.length-2, cents.length)
           dollars += ((tmp.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0;

   if ( cents == "0" )
      cents = "00";

   return(dollars + "." + cents);
}
// add to cart 
function addtocart(productid){
  if (productid ==1)	

{
document.main.qtybrn.value="1";	
quanclick1_onclick();	
}
 if (productid ==2)	

{
document.main.qtygry.value="1";	
quanclick2_onclick();	
}
 if (productid ==3)	

{
document.main.qtytan.value="1";	
quanclick3_onclick();	
}

//tax
}
function taxbynumbers() {
if (taxtogoindex == 1)
	{
		 var tax = 0;
		  var l = parseFloat(document.main.txtsubtot.value)
		  var taxtot = document.main.textfield11.value;
		 tax =document.main.txtsubtot.value * TaxRate;
		 document.main.textfield10.value= moneyFormat(tax);
		 //moneyFormat(document.main.textfield10.value)= moneyFormat(tax) + moneyFormat(document.main.txtsubtot.value);	
		taxtot = tax + l;
		document.main.textfield11.value= moneyFormat(taxtot);
		//document.main.textfield11.disabled=true;
		processor();
	}
if (taxtogoindex == 0)
	{
	//alert("Tax was not charged");

	//var tt = parseFloat(document.main.textfield10.value);
	//monetFormat(tt)= 0;
	document.main.textfield10.value= 0;	
	//moneyFormat(document.main.textfield11.value)=moneyFormat(document.main.txtsubtot.value);
document.main.textfield11.value= document.main.txtsubtot.value;
processor();
	}

}

function tax_onclick(tindex) {

	if (tindex == 1)
	{
	     //alert(document.main.mitchout[tindex].value);
		 //add tax 
		 taxtogoindex = 1;
		 taxbynumbers();
		 processor();
		 } 
		if (tindex == 0)
		 {
		 //alert(document.main.mitchout[tindex].value);
		 //notax
		taxtogoindex = 0;
		 taxbynumbers();
		 processor();
		 }
		 
	
	 }



function canada_shipping() {

		
		if(document.main.radCanadaShipping.checked == true){

			 document.main.textfield6.value= 50.00 * parseFloat(document.main.qtytan.value);
			 document.main.textfield5.value= 50.00 * parseFloat(document.main.qtygry.value);
			 document.main.textfield4.value= 50.00 * parseFloat(document.main.qtybrn.value);
		 
		}
		 else{
		 
		 
			 document.main.textfield6.value= '0.00';
			 document.main.textfield5.value= '0.00';
			 document.main.textfield4.value= '0.00';
		 
		 
		 }
		 
		 
		 taxbynumbers();
		 processor();
		 quanclick1_onclick();
		 quanclick2_onclick();
		 quanclick3_onclick();		 


	
	 }



// This section deals with quantity equations
function quanclick1_onclick() {
	
	var uni = 0;
	var qui = 0;
	var tot = 0;
	var sh1 = 0;
	
	if(document.main.radCanadaShipping.checked == true){
	
		//sh1= parseFloat(document.main.textfield4.value);

		sh1 = 100.00 * parseFloat(document.main.qtybrn.value);
		 document.main.textfield4.value= 100.00 * parseFloat(document.main.qtybrn.value);

}else{
		  
		  
		sh1= parseFloat(document.main.textfield4.value);
		
	}
	
	
	
		tot= parseFloat(document.main.textfield7.value);
		qui= parseFloat(document.main.qtybrn.value);
		uni= parseFloat(document.main.textfield.value);
	
	
	tot = qui * (uni + sh1);
	
	document.main.textfield7.value= moneyFormat(tot);
	
	txtsubtot();
taxbynumbers();
processor();	
	
}

function quanclick2_onclick() {
	
	var uni = 0;
	var qui = 0;
	var tot = 0;
	var sh1 = 0;

	if(document.main.radCanadaShipping.checked == true){
	
		//sh1= parseFloat(document.main.textfield5.value);
		sh1 = 100.00 * parseFloat(document.main.qtygry.value);
		 document.main.textfield5.value= 100.00 * parseFloat(document.main.qtygry.value);
		

	}else{
		  
		  
		sh1= parseFloat(document.main.textfield5.value);
		
	}



	tot= parseFloat(document.main.textfield8.value);
	qui= parseFloat(document.main.qtygry.value);
	uni= parseFloat(document.main.textfield2.value);

	
	tot = qui * (uni + sh1);
	
	document.main.textfield8.value= moneyFormat(tot);
	
txtsubtot();
taxbynumbers();	
processor();
}

function quanclick3_onclick() {
	
	var uni = 0;
	var qui = 0;
	var tot = 0;
	var sh1 = 0;



	if(document.main.radCanadaShipping.checked == true){
	
	 //sh1= parseFloat(document.main.textfield6.value);
		sh1 = 100.00 * parseFloat(document.main.qtytan.value);
		 document.main.textfield6.value= 100.00 * parseFloat(document.main.qtytan.value);
		

	}else{
		  
		  
		sh1= parseFloat(document.main.textfield6.value);
		
	}

	tot= parseFloat(document.main.textfield9.value);
	qui= parseFloat(document.main.qtytan.value);
	uni= parseFloat(document.main.textfield3.value);
	
	tot = qui * (uni + sh1);
	
	document.main.textfield9.value= moneyFormat(tot);
	
txtsubtot();
taxbynumbers();	
processor();
}


function txtsubtot() {
	var txttot =parseFloat(document.main.txtsubtot.value);
	txttot=0;
	txttot= parseFloat(document.main.textfield7.value) + parseFloat(document.main.textfield8.value) + parseFloat(document.main.textfield9.value) ;
	document.main.txtsubtot.value=moneyFormat(txttot);
	//document.main.textfield11.value=tot
	
}

function processor() {
	orderitems="";
	orderitems = "  Thank you for your order;  You have ordered  "
	if (parseFloat(document.main.qtybrn.value) > 0)
	{
		orderitems += document.main.qtybrn.value + " x Units Standard Kit - Gray ";
	}
	if (parseFloat(document.main.qtygry.value) > 0)
	{
		orderitems += document.main.qtygry.value + " x Units Standard Kit - Dark Gray ";
	}
	if (parseFloat(document.main.qtytan.value) > 0)
	{
		orderitems += document.main.qtytan.value + " x Units Standard Kit - Tan ";
	}
	
	var goout = "";//document.main.trythis.value;
	var toter =parseFloat(document.main.textfield11.value);
	goout += "Total To be Charged  " +  moneyFormat(toter);
	//goout += orderitems;
	// test  goout += "<input type=hidden name=\"storename\" value=\"1909113434\">";
	goout += "<input type=hidden name=\"storename\" value=\"1001184055\">";
	goout += "<input type=hidden name=\"comments\" value=\""+ orderitems + "\">";
	goout += "<input type=hidden name=\"mode\" value=\"fullpay\">";
	goout += "<input type=hidden name=\"chargetotal\" value=\""+ moneyFormat(toter) + "\">";
	goout += "<input type=hidden name=\"txntype\" value=\"sale\"> <br><br>";
	

	
document.getElementById("trythis").innerHTML =goout;
//document.write(document.getElementById("main").innerHTML);
	// document.close();
}

