	//*****Copyright 2007 2pTech.com. All rights reserved.
	//******************product definitions***************************
	var keys = new Array(); //@@@@@@add new product or change descript here
	var descripts = new Array();
	keys[0]	= "lblkg";			descripts[0]	= "LabelSense";
	keys[1]	= "bcrtr";			descripts[1]	= "BarcodeCreator";
	keys[2]	= "bcrtrBasic";		descripts[2]	= "BarcodeCreatorBasic";
	keys[3] = "ldsgnr";			descripts[3]	= "LabelDesigner";
	
	//******************qty group discount*********************************
	var qtyGrps = new Array(); //@@@@@@change qty groups here
	var qtyGrpDscnts = new Array();   //if reach qtyGrps[i], then use qtyGrpDscnts[i];
	qtyGrps[0] = 5;			qtyGrpDscnts[0] = 5;
	qtyGrps[1] = 10;		qtyGrpDscnts[1] = 8;
	qtyGrps[2] = 15;		qtyGrpDscnts[2] = 10;
	qtyGrps[3] = 20;		qtyGrpDscnts[3] = 15;
	qtyGrps[4] = 30;		qtyGrpDscnts[4] = 18;
	qtyGrps[5] = 50;		qtyGrpDscnts[5] = 20;
	qtyGrps[6] = 80;		qtyGrpDscnts[6] = 25;
	qtyGrps[7] = 100;		qtyGrpDscnts[7] = 30;

	RefreshAll(0);

	//add in dscnt table data to ul-lstDscnts
	FillInDiscntData();


	function FillInDiscntData()
	{
		var lst=document.getElementById("lstDscnts");
		str = szZhekou;
		var newText = document.createTextNode(str);
		var newNode = document.createElement("li");
		newNode.appendChild(newText);
		lst.appendChild(newNode);
		for(i=0; i<qtyGrps.length; i++)
		{
			str = szMai+qtyGrps[i]+szFen;
			//pad spaces
			if(10>qtyGrps[i])
				str += "  ";
			else if(100>qtyGrps[i])
				str += " ";

			str += "    -->    "+qtyGrpDscnts[i]+"%"+" "+szJian3;
			newText = document.createTextNode(str);
			newNode = document.createElement("li");
			newNode.appendChild(newText);
			lst.appendChild(newNode);
		}
    }
	function RefreshAll(fromBtn)
	{
		RefreshAllRows(fromBtn);
		RefreshPriceTotal();
	}
	function SetTotalCell(id, total)
	{
		document.getElementById(id).innerHTML = "<font size=2 color='#0000FF'>$"+FloatRoundToFixedDecimalPlaces(total,0)+"</font>";
	}
	function RefreshAllRows(fromBtn)
	{
		var i;
		for(i=0; i<keys.length; i++)
		{
//if(1==fromBtn)alert("2fdsf2");
			OnQtyChg(document.getElementById(keys[i]+'qty'), keys[i], 0);
		}
	}
	function RefreshPriceTotal()
	{
		var i, total=0;
		for(i=0; i<keys.length; i++)
		{//get row total
			rowprc = GetCellVal(document.getElementById(keys[i]+'prc').innerHTML);
			if(0>rowprc)
				rowprc = 0;
//alert(rowprc+'-');
			total += rowprc;
		}
		OnCDChg();OnCDQtyChg(0);//reset cdprice
		total += GetCellVal(document.getElementById('cdprice').innerHTML);
		SetTotalCell('totalprice', total);
		OnCouponChg(document.getElementById('discountCode') );
	}
	function SetCellVal(key, colkey, val)
	{//@@@@must be in body, not header!!!
		k = key + colkey;
//alert(document.getElementById(k).innerHTML);
		document.getElementById(k).innerHTML = "<font size=2>$"+FloatRoundToFixedDecimalPlaces(val,0)+"</font>";
	}
	function GetCellVal(cellHtml)
	{//@@@@must be in body, not header!!!  max one pair of html tag (<...>)!
		var result=0;
		if(1>cellHtml.length)
			return 0;
		idxDollar = cellHtml.indexOf('$');
		st = 0;
		if(-1<idxDollar)
			st = idxDollar+1;//got num area start pos
		else
		{
			idx = cellHtml.indexOf('<');
			if(-1<idx)
			{//found tag
				idx = cellHtml.indexOf('>');
				if(0<idx) 
					st = idx+1;//got num area start pos
			}
		}
		s = cellHtml.substring(st);
		st = 0;
		end = s.length;
		idx = s.indexOf('<');//find end
		if(-1<idx)
			end = idx;
		if('$'==s[st] || 'Y'==s[st+1])
			st++;
		s = s.substring(st, end);
		result = parseFloat(s);
//alert(result+'fff');
		if('NaN'==result+'')
			return -1;
		return result;
	}
	function OnQtyChg(qtyObj, key, doTotal)
	{//@@@@must be in body, not header!!!
	//alert(key);
		var i;
		s=qtyObj.value;
		if(1<s.length)
		{
			s0 = s.substring(0,1);
			if('0'==s0)
			{
				s=s.substring(1,s.length);
				qtyObj.value = s;
			}
		}
		qty = parseInt(s, 10); 
		if(0>qty)
		{
			qtyObj.value = "0";
			qty = 0;
		}
		rowTotal=0;
		qtyDscnt=0;
		if(0<qty)
		{
			idPrc0 = key + "prc0";
			prc0 = GetCellVal(document.getElementById(idPrc0).innerHTML);
			idPrcsp = key + "prcsp";//special price
			prc1 = GetCellVal(document.getElementById(idPrcsp).innerHTML);
			if(0>prc0)//if it's only one, use it
				prc = prc1;
			else if(0>prc1)
				prc = prc0;
			else if(prc0>prc1)//get min
				prc = prc1;
			else
				prc = prc0;
			rowTotal = prc*qty;
			//calc qtyDscnt
			for(i=qtyGrps.length-1; 0<=i; i=i-1)
			{
//alert('Ref-'+qtyGrps[i]);
				if(qtyGrps[i]<=qty)
				{
					qtyDscnt = qtyGrpDscnts[i];
					break;
				}
			}
		}
		//set dscnt show
		dscntCellId = key + 'dscnt';
		if(0<qtyDscnt)
		{
			document.getElementById(dscntCellId).innerHTML = "<font size=2>-"+qtyDscnt+"%</font>";
			rowTotal = rowTotal*(100-qtyDscnt)/100.0;
		}
		else
			document.getElementById(dscntCellId).innerHTML = "&nbsp;";

		rowTotal = FloatRoundToFixedDecimalPlaces(rowTotal,0);
//alert(rowTotal+'*');
		SetCellVal(key, 'prc', rowTotal);
		if(0<doTotal)
		{
//alert('Ref row');
			RefreshPriceTotal();
		}
	}
	function OnCouponChg(cpnObj)
	{
		//1.set percnt
		var cpnPcntOff=0;//0%
		if('CPN10'==cpnObj.value)//@@@@@@@ add counpon here!!!!!
			cpnPcntOff = 10;
		else if('178'==cpnObj.value)//Fla teacher
			cpnPcntOff = 5;
		else if('SEB4A'==cpnObj.value.toUpperCase() )//SEB fellows
			cpnPcntOff = 10;
		else if('GOODVALUE'==cpnObj.value.toUpperCase() || 'GOOD VALUE'==cpnObj.value.toUpperCase() )//25
			cpnPcntOff = 25;
		cellCpnPcnt = 'discountShow';
		if(0>=cpnPcntOff)
			document.getElementById(cellCpnPcnt).innerHTML = "&nbsp;";
		else
			document.getElementById(cellCpnPcnt).innerHTML = "<font size=2>&nbsp;-"+cpnPcntOff+"%</font>";
		//2.Set final price
		//2.1 get total
		totalprc = GetCellVal(document.getElementById('totalprice').innerHTML);
		floatFinalprice = totalprc*(100-cpnPcntOff)/100.0;
//alert('Ref='+floatFinalprice);
		SetTotalCell('finalprice', floatFinalprice);
	}
	function FloatRoundToFixedDecimalPlaces(floatNum, numOfDecimal)
	{
//alert(floatNum+'');
		if(2==numOfDecimal)
			return Math.round(floatNum*100)/100;
		else if(1==numOfDecimal)
			return Math.round(floatNum*10)/10;
		return Math.round(floatNum);
	}
  	function ltrim(varIn)
   	{/*Purpose: Trims the leading spaces from a string*/
   		var varOut = "";
    	if(!varIn)
	   	{
      		// string is null, so nothing to do
     	}
	    else // string has at least one character
     	{
	      	for(intI=0; intI < varIn.length; intI++)
       		{
        		if(varIn.charAt(intI) != " ")
         		{
		          //first non-space char found so return
		          //string from this character forward
		          varOut = varIn.substring(intI);
		          break;
         		}
      		}
     	}
     	return varOut;
	}
	function OnCDQtyChg(doTotal)
	{//@@@@must be in body, not header!!!
		var i;
		cdobj=document.getElementById('cdqty');
		qty = parseInt(cdobj.value, 10); 
		if(0>qty)
		{
			cdobj.value = "0";
			qty = 0;
		}
		rowTotal=0;
		if(0<qty)
		{
			prc = GetCellVal(document.getElementById('cdprc').innerHTML);
			if(10>prc)
				prc = 10;
			if(1==qty)
				rowTotal=prc;
			else
				rowTotal = prc+(qty-1)*prc/2;
		}
		rowTotal = FloatRoundToFixedDecimalPlaces(rowTotal,0);
//alert(rowTotal+'*');
		document.getElementById('cdprice').innerHTML = "<font size=2>$"+FloatRoundToFixedDecimalPlaces(rowTotal,0)+"</font>";
		if(doTotal)
			RefreshPriceTotal();
	}
function validate()
{
	//1.get final price
	floatFinalprice = GetCellVal(document.getElementById('finalprice').innerHTML);
	//3.final price must >0
	if(0.0>=floatFinalprice)
	{
		alert("Please select a product.");
		return false;
	}
	document.frmCheckCout.amount.value = floatFinalprice+'';
	//2.get CD option
	var cdchked = document.getElementById('cdchk').checked;
	//4.get names
	ltrim(document.frmCheckCout.FirstName.value);
	ltrim(document.frmCheckCout.LastName.value);
	document.frmCheckCout.on0.value = document.frmCheckCout.LastName.value+","+ document.frmCheckCout.FirstName.value;//pass names
//alert(document.frmCheckCout.on0.value);
//alert(document.frmCheckCout.amount.value);

	//document.frmCheckCout.os0 pass cmpny name
	if( (ltrim(document.frmCheckCout.os0.value)).length == 0)
	{
		alert("Please Enter Company Name. For personal use, you can enter \"Private\"");
		document.frmCheckCout.os0.focus();
		return false;
	}
//alert(document.frmCheckCout.os0.value);
	//5.get item/qty array
	document.frmCheckCout.item_name.value = "";//max 127
	document.frmCheckCout.custom.value = "";//max 256
	document.frmCheckCout.item_number.value = "";
	cnt=0;
	var i;//must declare to avoid conflits. no-declare=global
	for(i=0; i<keys.length; i++)
	{
		n = parseInt(document.getElementById(keys[i]+'qty').value);//this remv leading 0 and trim spaces
		if(0<n)
		{
			if(0<cnt)
			{
				document.frmCheckCout.item_name.value += ',';
				document.frmCheckCout.item_number.value += ',';
			}
			document.frmCheckCout.item_name.value		+= descripts[i]+'(';
			document.frmCheckCout.item_name.value		+= n+')';
			document.frmCheckCout.custom.value			+= keys[i]+'-';
			document.frmCheckCout.custom.value			+= n+',';
			if(0<i)
				document.frmCheckCout.item_number.value += '#';
			document.frmCheckCout.item_number.value += (i+1);
			cnt++;
		}
	}
	if(cdchked)
	{
		cdobj=document.getElementById('cdqty');
		cdQty=parseInt(cdobj.value, 10); 
		document.frmCheckCout.item_name.value+='CD('+cdQty+')';
		document.frmCheckCout.custom.value+='CD-'+cdQty;
		document.frmCheckCout.no_shipping="2";//requir addr
	}
//alert(document.frmCheckCout.item_name.value);
	document.frmCheckCout.os1.value = document.frmCheckCout.item_name.value;

	//6.pass coupon code
	if(document.getElementById('discountCode').value.length > 0)
	{
		cpn = document.getElementById('discountCode').value;
		document.frmCheckCout.custom.value += "("+cpn+")";//test to see whether we can get this custom info
		document.frmCheckCout.item_number.value += " -"+cpn;
	}
	//Submit the form
	return true;
}
function OnCDChg()
{
	cdchked = document.getElementById('cdchk').checked;
	cdobj=document.getElementById('cdqty');
	if(cdchked)
	{
		if(1>parseInt(cdobj.value, 10))
			cdobj.value= "1";
		cdobj.style.visibility="visible";
	}
	else
	{
		cdobj.value= "0";
		cdobj.style.visibility="hidden";
	}
}
