function validate() {
var r1 = new RegExp("^req_");
var frm;  
//document.frmInfo.desc.value=document.frmInfos.desc.value;
for(var i=0;i<document.frmInfo.elements.length-1;i++){
	
	frm=document.frmInfo.elements[i];
//	alert(frm.name + " " + frm.value);
	if(r1.test(frm.name) && frm.value==""){
		alert('"' + frm.name.substr(4) + '"' + ' is a required field. Please try again.');
		return(false);
	}
	if(frm.name=="desc"){
		alert(frm.name);
		frm.value=document.frmInfos.desc.value;
	}
	
	Set_Cookie(frm.name,frm.value,expires_date);
}

return(true);
}

function fillForm(){
var frm;  
for(var i=0;i<document.frmInfo.elements.length-1;i++){
	
	frm=document.frmInfo.elements[i];
	if(frm.name!="submit" & frm.name!="returl" & frm.name!="submission"){
		frm.value = Get_Cookie(frm.name);
		if(frm.value=="null")
			frm.value="";
	}
}
}
var today = new Date();
var zero_date = new Date(0,0,0);
today.setTime(today.getTime() - zero_date.getTime());

var todays_date = new Date(today.getYear(),today.getMonth(),today.getDate(),0,0,0);
var expires_date = new Date(todays_date.getTime() + (8 * 7 * 86400000));

function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

function Delete_Cookie(name,path,domain) {
    if (Get_Cookie(name)) document.cookie = name + "=" +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
function addItem(value){
	for(var i=1;i<10;i++){
		if(Get_Cookie("item" + i)==null) break;
	}
	Set_Cookie("item" + i,value,expires_date);
}
function removeItem(num){
 Delete_Cookie("item" + num);
}
function round(number,X) {
// rounds number to X decimal places, defaults to 2
    X = (!X ? 2 : X);
    return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function showItems(){
	var itm="";
	var aItm="";
	var ttl=0.0;
	var des="";
	var Total="";
  for(var i=1;i<10;i++){
		itm=Get_Cookie("item" + i);
		if(itm!="" && itm!=null)
		{
			aItm=itm.split(",");
document.write('<table cellSpacing="0" cellPadding="5" width="400" bgColor="#FFFFFF" border="0"><tr>');
document.write('<td vAlign="top" align="left" bgColor="#FFFFFF" colspan="3" width="200" ' + 'class="smallTextDark">');
if(aItm[3]=="null")
	document.write('<b>&nbsp;</b>');
else
	document.write('<b>' + aItm[3] + '</b>');
document.write('<br>');
if(aItm[4]=="null")
	document.write('<i>&nbsp;</i>');
else
	document.write('<i>' + aItm[4] + '</i>');
document.write("</b><br>#" + aItm[0] + " <a href='#' onclick='removeItem(" + i + ");document.location.replace(\"shoppingCart.php\");return(false);' class='smallLinkDark2'><u>remove</u></a></td>");
document.write('<td  vAlign="top" align="center" bgColor="#FFFFFF" width="30" class="smallTextDark">');
if(aItm[2]=="null")
	document.write("&nbsp;</td>");
else
	document.write("<img src='images/" + aItm[2] + "'/></td>");

for(var j=0;j<5;j++){
	switch(j){
		case 1:
			des+="Price:_" + aItm[j] + ";";
			break;
		case 0:
			des+="Item Number:_" + aItm[j] + ";";
			break;
		
	}
	itm+=aItm[j] + ",";
}



document.write('<td vAlign="top" align="center" bgColor="#FFFFFF" width="50" class="smallTextDark">');
document.write('<span class="smallLinkDark2"><b>$' + aItm[1] + "</b></td>");
Total=aItm[1];
if(aItm[5]){
  document.write("<td valign='top' class='smallTextDark' width='120' align='right'>quantity: <input type='text' size='4' maxlength='20' class='smallTextDark' value='" + aItm[5] + "' name='qty" + i + "'>");
  Total = aItm[1]*aItm[5];
  des += "Quantity:_" + aItm[5] + ";";
}
else{
  document.write("<td valign='top' class='smallTextDark' width='120' align='right'>quantity: <input type='text' size='4' maxlength='20' class='smallTextDark' value='1' name='qty" + i + "'>");
  des += "Quantity:_1;";
 }
itm="";
for(var j=0;j<5;j++)
		itm+=aItm[j] + ",";
document.write("<input type='hidden' value='" + itm + "' name='invString'>");

document.write("<br><a class='smallLinkDark2' href='#' onclick='setQty(" + i + ",\"" + itm + "\");return(false);'><u>update total</u></a> <img src='images/recalc.gif' border='0'></td>");
document.write('</tr></table><br><br>');


//<a href='#' onclick='removeItem(" + i + ");document.location.replace(\"shoppingCart.php\");return(false);'>remove</a><br>");
			ttl+= (Total - 0.00);
		}
	}
	document.write('<table cellSpacing="0" cellPadding="5" width="400" bgColor="#FFFFFF" border="0"> <tr> <td vAlign="top" align="right" bgColor="#FFFFFF" width="400" class="smallTextDark"> Total: <b>$' + round(ttl,2) + '</b><br><br> </td> </tr> </table>');
	//alert(des + "Total:_" + ttl +  ";;;\n");
	return(des + "Total:_" + ttl +  ";;;\n");
}
function setQty(item,startVal,qty){
	//alert(item);
//	alert(startVal);
//	alert(eval("document.frmInfos.qty" + item + ".value"));
	Set_Cookie("item" + item,startVal + eval("document.frmInfos.qty" + item + ".value"));
	document.location.replace("shoppingCart.php");
}