function form_validator(theForm)
{
	if(theForm.email.value == "") {
		 alert("missing_email");
		 theForm.email.focus();
		 return(false);
	}
	if(theForm.name.value == "") {
		 alert("missing_name");
		 theForm.name.focus();
		 return(false);
	}
	if(theForm.address.value == "") {
		 alert("missing_address");
		 theForm.address.focus();
		 return(false);
	}
	if(theForm.city.value == "") {
		 alert("missing_city!");
		 theForm.city.focus();
		 return(false);
	}
	if(theForm.zip.value == "") {
		 alert("missing_zip!");
		 theForm.zip.focus();
		 return(false);
	}
	if(theForm.state.value == "") {
		 alert("missing_state!");
		 theForm.state.focus();
		 return(false);
	}
	if(theForm.country.value == "") {
		 alert("missing_country!");
		 theForm.country.focus();
		 return(false);
	}
	if(theForm.phone.value == "") {
		 alert("missing_phone!");
		 theForm.phone.focus();
		 return(false);
	}
	if(theForm.pmt_value.value =="" ) {
		 alert("missing credit cart number!");
		 theForm.pmt_value.focus();
		 return(false);}
	if(1){
		setDate = new Date(theForm.exyear.value, theForm.exmonth.value, 00 );
		today = new Date();
		if (setDate <= today){
			alert("incorect expiration date!");
			theForm.exmonth.focus();
			return(false);
		 }
	}
	if (theForm.subtotal.value < 100){
		alert("Mimimal Order $100!");
		return(false);
	}
	return (true);
}
	function alterError(value) {
		if (value<=0.99) {
			newPounds = '0';
		} else {
			newPounds = parseInt(value);
		}
		newPence = parseInt((value+.0008 - newPounds)* 100);
		if (eval(newPence) <= 9) newPence='0'+newPence;
		newString = newPounds + '.' + newPence;
		return (newString);
	}
function getPrice(qty, q1, p1,q2,p2,q3,p3){
	myq = parseInt(qty);
		if(myq >= parseInt(q3)){
			return p3;
		}else if(myq >= parseInt(q2)){
			return p2;
		}else{
			return p1;
		}
	}
	// showItems in orderform

function showItems() {
		index = document.cookie.indexOf("TheBasket");
		countbegin = (document.cookie.indexOf("=", index) + 1);
        	countend = document.cookie.indexOf(";", index);
        	if (countend == -1) {
            		countend = document.cookie.length;
        	}
		fulllist = document.cookie.substring(countbegin, countend);
		shortlist = "";
		subtotal = 0;
		document.writeln('<table cellpadding="2" cellspacing="1" border="0">');
		document.writeln('<TR><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Qty</b></FONT></TD><TD  BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Item ID</b></FONT></TD><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Product Name</b></FONT></TD><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Price</b></FONT></TD><td BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Item Total</b></FONT></td></TR>');
		itemlist = 0;
		counter = 1;
			for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				thisitem = 1;
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				thequantity = fulllist.substring(itemstart, itemend);
				theprice = (Math.round((getPrice(thequantity,qL1,pL1,qL2,pL2,qL3,pL3))*100)/100);
				itemtotal = 0;
				itemlist=itemlist+1;
				itemtotal = 0;
				itemtotal = (Math.round((theprice*thequantity)*100)/100);
				shortlist = shortlist +itemlist+" "+ theitem + " "+thename+" "+thequantity+" $"+itemtotal+"|";
				temptotal = itemtotal * 100;
				subtotal = subtotal + itemtotal;				
				document.write('<tr><td align=middle BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+thequantity+'</FONT></td>');
				document.writeln('<td BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+theitem+'</FONT></td><td align=left BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+thename+'</FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+alterError(theprice)+'</FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+alterError(itemtotal)+'</FONT></td></tr>');
		  
			} else if (fulllist.substring(i,i+1) == '|') {
				if (thisitem==1) theitem = fulllist.substring(itemstart, i);
				if (thisitem==2) thename = fulllist.substring(itemstart, i);
				if (thisitem==3) qL1 = fulllist.substring(itemstart, i);
				if (thisitem==4) pL1 = fulllist.substring(itemstart, i);
				if (thisitem==5) qL2 = fulllist.substring(itemstart, i);
				if (thisitem==6) pL2 = fulllist.substring(itemstart, i);
				if (thisitem==7) qL3 = fulllist.substring(itemstart, i);
				if (thisitem==8) pL3 = fulllist.substring(itemstart, i);
				thisitem++;
				itemstart=i+1;
				
			}
			
		}

		totprice = (Math.round(subtotal*100)/100);
	        shipping = getShipping(totprice)* 1.2 ;
		totalcost = (totprice+shipping);
		hidlist = shortlist.substring(shortlist, shortlist.length-1);
		tax = 0;
    	document.writeln('<tr><td align=right BGCOLOR="#B3B3B3" colspan=4><font size="-2" face="Verdana, Arial,	Helvetica, sans-serif"><b>Sub Total</b></FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+alterError(totprice)+'</FONT></td></tr>');
		document.writeln('<tr><td align=right BGCOLOR="#B3B3B3" colspan=4><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Estimate Shipping</b></FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+alterError(shipping)+'</FONT></td></tr>');
		document.writeln('<tr><td align=right BGCOLOR="#B3B3B3" colspan=4><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Total</b></FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+alterError(totalcost+tax)+'</FONT></td></tr>');
  		document.writeln('<INPUT TYPE="hidden" NAME="subtotal" VALUE='+totprice+'>');
 		document.writeln('<INPUT TYPE="hidden" NAME="shipping" VALUE='+shipping+'>');
  		document.writeln('<INPUT TYPE="hidden" NAME="total" VALUE='+totalcost+'>');
  		document.writeln("<INPUT TYPE='hidden' NAME='fulllist' VALUE='"+hidlist+"' >");
		document.writeln('</TABLE>');

	}
function getShipping(totprice){
iprice = parseInt(totprice);
	if(iprice<= 50){
		return 7.5;
	}else if(iprice <= 100){
		return 10;
	}else if(iprice <= 150){
		return 12.5;
	}else if(iprice <= 200){
		return 15;
	}else if(iprice <= 250){
		return 17.5;
	}else if(iprice <= 300){
		return 20;
	}else if(iprice <= 350){
		return 22.5;
	}else if(iprice <= 400){
		return 25;
	}else if(iprice <= 450){
		return 27.5;
	}else if(iprice <= 500){
		return 30;
	}else if(iprice <= 550){
		return 32.5;
	}else if(iprice <= 600){
		return 35;
	}else if(iprice <= 700){
		return 40.0;
	}else if(iprice <= 800){
		return 45;
	}else if(iprice <= 900){
		return 50;
	}else if(iprice <= 1000){
		return 55;
	}else if(iprice <= 1100){
		return 60;
	}else if(iprice <= 1200){
		return 65;
	}else if(iprice <= 1300){
		return 70;
	}else if(iprice <= 1400){
		return 75;
	}else if(iprice <= 1500){
		return 80;
	}else if(iprice <= 1600){
		return 85;
	}else if(iprice <= 1700){
		return 90;
	}else if(iprice <= 1800){
		return 95;
	}else if(iprice <= 1900){
		return 100;
	}else if(iprice <= 2000){
		return 105;
	}else if(iprice <= 2200){
		return 115;
	}else if(iprice <= 2400){
		return 125;
	}else if(iprice <= 2600){
		return 135;
	}else if(iprice <= 2800){
		return 145;
	}else if(iprice <= 3000){
		return 155;
	}else if(iprice <= 3200){
		return 165;	
	}else if(iprice <= 3400){
		return 175;
	}else if(iprice <= 3600){
		return 185;
	}else if(iprice <= 3800){
		return 195;
	}else if(iprice <= 4000){
		return 205;
	}else if(iprice <= 4200){
		return 215;
	}else if(iprice <= 4400){
		return 225;	
	}else if(iprice <= 4600){
		return 235;
	}else if(iprice <= 4800){
		return 245;
	}else if(iprice <= 5000){
		return 255;
	}else{
		return eval(iprice * 0.045 );
	}
}
