var discary = new Array(0,0,15,20,25,30,35);
var promochange=true,emailchange=true,pd=0,rd=0;
function selectPrevious()
{
	var pcodelist;
	pcodelist = readCookie("pcodelist");
	if(pcodelist == "" || pcodelist == null)
	{
		setTotal();
		return;

	}

	var pcodearray = pcodelist.split(",");
	var k = pcodearray.length;

	for(i=0;i<k;i++)
	{
		pcode = pcodearray[i];

		if (pcode.length>5)
		{
			if (readCookie(pcode) ==1)
			{
				qty= readCookie("qty["+pcode+"]") ;
				pname= readCookie("name["+pcode+"]") ;
				lic= readCookie("lic["+pcode+"]") ;
				price= readCookie("price["+pcode+"]") ;
				addtocollection1(true,pcode,pname,qty,price,lic);
			}
		}
	}
	updateTotal();
}

function addtocollection1(cbx,pcode,pname,qty,price,lic)
{

	var netamt=0;
	var curkit =findProd(pcode);
	if (cbx )
	{
		if (curkit >= 0)
		{
			return;
		}
		if(qty<=0) {qty=1;}
		if(lic<=0) {lic=1;}
		var oRow,ocell;
		oRow = document.getElementById("seleprepkit").insertRow(1);
		oRow.id = pcode;
		oRow.className = "selectedPrepKitRow";

		ocell = oRow.insertCell(0);
		ocell.innerHTML = addCommas(parseInt(( (price * qty * lic * 100 )) + .01) /100)   ;
		ocell.align="right";

		ocell = oRow.insertCell(0);
		ocell.innerHTML = addCommas(parseInt(price * lic * 100 ) /100)   ;
		ocell.align="right";

		ocell = oRow.insertCell(0);
		ocell.innerHTML = "<a href=\"javascript:addtocollection1(false,'"+pcode+"',0,0);\"><img src='"+SITE_LINK_URL+"/images/trash.gif' width='12' height='14'></a>";
		ocell.align="center";

		ocell = oRow.insertCell(0);
		ocell.innerHTML = '<input id="price['+pcode+']" name="price['+pcode+']" type=hidden value="' +price +'" ><input id="qty['+pcode+']" name="qty['+pcode+']" type=text size=1 value="' +qty +'" onChange="changeQty(this);"  onblur="this.className=\'nf\';" onfocus="this.className=\'sf\';">';
		ocell.align="center";

		ocell = oRow.insertCell(0);
		ocell.align="left";
		lss ="";
		lhw ="";
		lsb ="";
		len ="";
		if(lic=="s")
		{
			lss="  Selected ";
		}
		if(lic=="h")
		{
			lhw="  Selected ";
		}
		if(lic=="b")
		{
			lsb="  Selected ";
		}
		if(lic=="e")
		{
			len="  Selected ";
		}
		vhlp = "window.open('"+SITE_URL+"/cart/help/license.html','popupwindow','top=300,left=350, width=400,height=250,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');";
		vhlp = '<a href="" onclick="return false;"><img src="'+SITE_LINK_URL+'/images/question.gif" width=18 height=18 onclick="'+ vhlp +';return false;"></a>';
                ocell.innerHTML = '<nobr><select style="display:;" id="lic['+pcode+']" name="lic['+pcode+']" onChange="changeLicense(this);" ><option value="s" '+lss+'>Single User</option><option value="h"  '+lhw+'>Home & Work</option><option value="b"  '+lsb+'>Small Biz 5 Lic.</option></select>'+vhlp+'</nobr>';

		ocell = oRow.insertCell(0);
		ocell.align="left";
		ocell.innerHTML = pname+'<input type=hidden name="prod[]" value="'+pcode+'">';

		ocell = oRow.insertCell(0);
		ocell.innerHTML =pcode ;

		createCookie(pcode,1,1);
		createCookie("qty["+pcode+"]",qty,1);
		createCookie("name["+pcode+"]",pname,1);
		createCookie("lic["+pcode+"]",lic,1);
		createCookie("price["+pcode+"]",price,1);


	}

	else
	{
		if (curkit < 0){return;}
		if(window.confirm("Do you want to remove "+pcode+" from the shopping cart?"))
		{
			document.getElementById("seleprepkit").deleteRow(curkit);
			eraseCookie(pcode);
			eraseCookie("qty["+pcode+"]");
			eraseCookie("name["+pcode+"]");
			eraseCookie("lic["+pcode+"]");
			eraseCookie("price["+pcode+"]");

		}
	}

	setTotal();
}
function changeQty(obj)
{
	qty = obj.value;
	id = obj.id;
	createCookie(id,qty,1);
	setTotal();
}


function changeLicense(obj)
{
	lic = obj.value;
	id = obj.id;
	createCookie(id,lic,1);
	setTotal();
}
function updateTotal()
{
	email =document.scform.email.value;
	if (email !="")
	{
		if(emailchange)
		{
			getOldCustomerDisc(email);
		}
	}
	else
	{
		rd=0;
	}

	promocode = document.scform.promocode.value;
	if(promocode !="")
	{
		if(promochange)
		{
			getpromoDisc(promocode);
		}
	}
	else
	{
		pd=0;
	}

	setTotal();
}

function dataChange(changewhat)
{
	if (changewhat==1)
	{
		promochange=true;
	}
	else
	{
		emailchange=true;
	}
	updateTotal();
}

function changecurrency(obj)
{
	ocurrencylist = obj;
	currencycodev = ocurrencylist.value;
	ocurrencyoption = ocurrencylist.options[ocurrencylist.selectedIndex];
	document.getElementById("cratio").value = ocurrencyoption.getAttribute('cratio');
	document.getElementById("cpsc").value = ocurrencyoption.getAttribute('psc');
	document.getElementById("currencycode").value=currencycodev;
	document.getElementById("currency").innerHTML=currencycodev;
	createCookie("currencycode",currencycodev,30);

	setspo();
	setTotal();
}




function spo(o)
{
	document.scform.psc.value=o.value;
}
function findProd(pcode)
{
	var curkit;
	curkit = -1;
	obj = document.getElementById("seleprepkit");
	totalrow = obj.rows.length;
	for(var i=0;i < totalrow ;i++)
	{
		if(obj.rows[i].cells[0].innerHTML == pcode)
		{
			curkit = i ;
		}
	}
	return curkit;
}



function setOldCustomerDisc(aI)
{

	rd =daX[aI].response;

	daX[aI] = false;
	setTotal();
}


function getOldCustomerDisc(email)
{
	var aI = daX.length;
	daX[aI] = new sack();

	daX[aI].requestFile = SITE_LINK_URL+"/order_book/checkrepeatdiscount.php?email="+email;
	daX[aI].onCompletion = function(){ setOldCustomerDisc(aI); };	// Specify function that will be executed after file has been found
	daX[aI].runAJAX();		// Execute AJAX function
}

function setpromoDisc(aI)
{
	pd = daX[aI].response;
	daX[aI] = false;
	setTotal();
}

function getpromoDisc(code)
{
	var aI = daX.length;
	daX[aI] = new sack();
	daX[aI].requestFile = SITE_LINK_URL+"/order_book/checkpromocode.php?code="+code;
	daX[aI].onCompletion = function(){ setpromoDisc(aI); };	// Specify function that will be executed after file has been found
	daX[aI].runAJAX();		// Execute AJAX function
}




	function sh(o)
	{
		document.getElementById("help").innerHTML = o.title;
	}


		function validateCheckNull()
		{
			if(CheckNull(document.scform.fname.value))
			{
				alert("Please enter First Name.");
				document.scform.fname.select();
				return false;
			}
			if(CheckNull(document.scform.lname.value))
			{
				alert("Please enter Last Name.");
				document.scform.lname.select();
				return false;
			}
			if(CheckNull(document.scform.address.value))
			{
				alert("Please enter the street address.");
				document.scform.address.select();
				return false;
			}

			if(CheckNull(document.scform.city.value))
			{
				alert("Please enter city.");
				document.scform.city.select();
				return false;
			}

			if(CheckNull(document.scform.state.value))
			{
				alert("Please enter state.");
				document.scform.state.select();
				return false;
			}

			if(CheckNull(document.scform.zip.value))
			{
				alert("Please enter post code.");
				document.scform.zip.select();
				return false;
			}

			if(CheckNull(document.scform.country.value))
			{
				alert("Please enter country.");

				return false;
			}

			if(CheckNull(document.scform.phone.value))
			{
				alert("Please enter telephone number.");
				document.scform.phone.select();
				return false;
			}
	}

	function ccValidate()
	{
			if(CheckNull(document.scform.card_num.value))
			{
				alert("Please enter card number.");
				document.scform.card_num.select();
				return false;
			}
			if(CheckNull(document.scform.card_code.value))
			{
				alert("Please enter card code.");
				document.scform.card_code.select();
				return false;
			}
			return true;
	}



