<!--//This is a js page that has all the functions for the product page for Internet Explorer
var productNumber = 1;	//This is used to track the number of products that are 'active', 
						//so we can set the kit id = 0 if there are more than 1 products or
						//to "" if there is only 1.
						//This is because we add products with certain imprints like customerproof
						//and photoreturn.
var strPage = "product_rs.asp";
var str = "";
var total = 0;

function roundToPennies(n)
{
   pennies = n * 100;
   pennies = Math.round(pennies);
   strPennies = "" + pennies;
   len = strPennies.length;
   first = strPennies.substring(0, len - 2) + ".";
   last = strPennies.substring(len - 2, len);
   if(first == ".")
   {
      first = "0."
   }
   if(last.length == 1)
   {
      last += "0";
   }
   return first + last;
}

function zeroPad(price){
	var position;
	var len;
	var diff;
	rice = "" + price;
	position = price.search(/\./);
	position = position + 1;
	if (position != -1){
		len = price.length
		diff = len - position
	
		if (diff < 2) {
			if (diff == 1) price = price + '0'
			if (diff == 0) price = price + '00'
		}
		if (position == 0) price = price + '.00'
	}
	else {
		price = price + '.00'
	}
	return price;
}

function checkTotal(icount,action){
	document.getElementById("p1").style.display='none';
	document.getElementById("p2").style.display='';
	str="";
	total = 0;
	totalOrder(action);
}

function switchBack(){
//	document.getElementById("p1").style.display='';
//	document.getElementById("p2").style.display='none';
	str = "";
}

function doUpsell(){
	for (var i in oUpsell){
		if(eval("oUpsell." + i + "()")){
		}else{
			//alert(i);
			return false;
		}
	}	
	return true;	
}


function addToCart(){
	var returnPrice = new Array(9);
	//var productid;
	//var quantity;
	//var itemnumber;
	//alert("came")
	var str = '';
	var delim = '';
	var pcount = document.form1.productid.length;
	if (document.form1.imprintproduct.value == 'true'){
		doSeparateMethods(envelope);
		if(!doSeparateMethods()){
			return;
		}
		if (!doMethods()){
			return;
		}
	}
	if (document.form1.upsell_itemnumber){
		if(!doUpsell()){
		//alert("IN DOUPSELL");
			return;
		}
	}
	
	for (var i = 0; i < document.form1.elements.length; i++) {
		el = document.form1.elements[i];
		if (el.name){
			if ((el.name == 'productid')||(el.name == 'originalproductid')||(el.name == 'quantity')||(el.name == 'promocode')||(el.name == 'promoid')||(el.name == 'priceoverride')||(el.name == 'priceoverridecode')||(el.name == 'priceoverridecomment')||(el.name == 'imp_dbazip')||(el.name == 'imp_ret_address')||(el.name == 'imp_return_zip')||(el.name == 'imp_return_state')){
				str += delim + el.name + "|" + el.value;
				delim = "|";	
			}
		}
	}
	str += delim + "invoiceitemid|" + invoiceitemid;
	delim = "|";
	//alert(str)
	RSExecute("product_rs.asp","RS_PostProduct", str);
	
}

function rtn_RS_PostProduct(){
	var raMsg = return_value;
	return_value = "";
	//alert(raMsg)
	if(raMsg == "OK"){
		submitInfo();
	}else{
		alert(raMsg);
		switchBack();
	}
}

function submitInfo(){
	// UI may currently be disabled due to remote script call.
	// Disabled form elements do NOT get posted, so enable UI now!
	EnableUI();
	
	document.form1.submit();
}	

function addImprint(){
	var tmpstr='';
	var tmpstrheading;
	var iname;
	var ival;
	var fcount = document.form1.length;
	tmpstrheading = "<table><tr><td><b>Imprint Information:</b></td></tr>";
	for (i=0; i < fcount; i++){
		iname = document.form1.elements[i].name;
		ival = document.form1.elements[i].value;
		if (ival != ''){
			if (iname.search(/imp_/) != -1){
				if (iname.search(/h_imp_/) == -1){
					if (document.form1.elements[i].type == "radio"){
						if (document.form1.elements[i].checked){
							iname = eval("document.form1.h_" + iname + ".value");
							tmpstr += "<tr><td>" + iname + " : " + ival + "</td></tr>";
						}
					}else{
						iname = eval("document.form1.h_" + iname + ".value");
						tmpstr += "<tr><td>" + iname + " : " + ival + "</td></tr>";
					}
				}
			}
		}
	}
	tmpstr += "</table>";
	if (tmpstr != ''){
		return tmpstrheading + tmpstr;
	}
	else
	{
		return tmpstr;
	}
}
function checkProdID(){
}
function kit(){
	//Properties
	this.productid = '';						
	//Methods
}
var oKit = new kit();

function setKitObj(){
	var f = document.form1
	
	if(document.form1.productid.value){
		oKit.productid = document.form1.productid.value;
	}else if (document.form1.productid[0].value){
		oKit.productid = document.form1.productid[0].value;
	}
	
	
	//alert('oKit: ' + oKit.productid + '');
	
	var i;
	var tempval;
	for(i=0;i < f.elements.length;i++){	
		if(i>0){
			if(i % 3 == 0){
				tempval += '\n'
			}			
		}	
		tempval += f.elements[i].name + ' : ' + f.elements[i].value + ' | '
	} 	
//alert(tempval);
}

function getNextPage(divid,direction){
	var currentpage;
	var nextpagenum;
	var nextpage;
	myTestTable = document.getElementById("mytest");
	myTestTable.style.display = '';
	myTestTextBox = document.getElementById("mtest");
	myTestAction = document.getElementById("myAction").value;
	//alert('test: ' + myTestAction + '');
	//alert('direction: ' + direction + '');
	if((myTestAction == '')&&(direction == 1)){
		document.getElementById("mtest").style.display = '';
		document.getElementById("mtest").focus();
		document.getElementById("mtest").style.display = 'none';
	}else{
		document.getElementById("mtest").style.display = '';
		document.getElementById("mtest").focus();
		document.getElementById("mtest").style.display = 'none';
	}
	nextpagenum = parseInt(divid) + parseInt(direction);
	currentpage = document.getElementById("page" + divid);
	nextpage= document.getElementById("page" + nextpagenum);
	currentpage.style.display = 'none';
	nextpage.style.display = '';
	//alert('\ncurrentpage:' + currentpage.name + '\nnextpage: ' + nextpage.name + '\ncpage.style:' + currentpage.style.display + '\nnpage.style:' + nextpage.style.display);
	//document.location.reload(true);
	
}


//End script-->
