/*var formURL = "https://www.sandbox.paypal.com/cgi-bin/webscr";*/
var formURL = "https://www.paypal.com/cgi-bin/webscr";

function load() {

   var form = document.getElementById("viewCart");
   if (form!=null)
      form.action = formURL;
   form = document.getElementById("addCart");
   if (form!=null)
      form.action = formURL;
      
      
   if (typeof(products)!='undefined') {
	   for (i=0; i<products.length; i++) {
	      updateProduct(products[i]);
	   }
   }
}

function updateProduct(pid) {

    eval('var select = document.getElementById("'+pid +'Select");');
	eval('var price = '+pid+'Prices['+select.selectedIndex+'];');
	
	eval('var mprice = document.getElementById("'+pid+'Price");');
	mprice.firstChild.nodeValue = price+".00";
	
	eval('var mquantity = document.getElementById("'+pid+'Quantity").value;');
	eval('var mtotal = document.getElementById("'+pid+'Total");');
	mquantity = parseInt(mquantity);
	if (!isNaN(mquantity)) {		
		mtotal.firstChild.nodeValue = price*mquantity+".00";
	}
	else {
		eval('document.getElementById("'+pid+'Quantity").value=1;');
		mtotal.firstChild.nodeValue=price+".00";
	}
}

function addToCart(pid) {
   eval('var select = document.getElementById("'+pid +'Select");');
   eval('var mprice = '+pid+'Prices['+select.selectedIndex+'];');
   eval('var mquantity = document.getElementById("'+pid+'Quantity").value;');
   eval('var mdescription = document.getElementById("'+pid+'Descripton").innerHTML;');
  
   var payDesc= document.getElementById("payDesc");
   var payAmount= document.getElementById("payAmount");
   var payWeight= document.getElementById("payWeight");
   var payQuantity= document.getElementById("payQuantity");

   // selected.value does not works on IE
   var val = select[select.selectedIndex].text;       
   payDesc.value = val + " - "+mdescription;
   payAmount.value = mprice;
   payQuantity.value = mquantity;
   payWeight.value = marriedWeight[select.selectedIndex];
   
  document.paypal.submit();
}


