 var qq=0; 
 var crap=new Array(); 
 var j=0; 
 var crud="" 
 var car=0; 
 var begin=0; 
 var end=0; 
 var price=0; 
 var stock; 
 var howmany; 
 var booky; 
 start();
  
 function person(booktit,price,stock,quantity) 
 { 
 this.quantity=quantity 
 this.booktit=booktit 
 this.stock=stock 
 this.price=price
} 
  
 var i=0; 
 var book="|"; 


function add()
{
var q=document.theform.elements.length; //q is the number ofelements.Its -2 because two elements are reset and submit

while(i!=q)
    {
if (!document.theform.elements[i+1])  //if somehow we got beyond the last element break.
break;
if (document.theform.elements[i].checked || document.theform.elements[i].type=="select-one") //if there is a checkbox checked and it is true OR if its not a checkbox, i.e., a drop down list
{
var si=0 
if (document.theform.elements[i].type=="select-one") //If the current element is a list THEN...
{
	if (document.theform.elements[i].options[document.theform.elements[i].options.selectedIndex].value!="YM") //Check to make sure that it just doen't say "SELECT YOUR OPTION"
	{
		if (document.theform.elements[i+1].type=="select-one")
		{
		do_ops();
		}
		else
		{
		var jmj=document.theform.elements[i].options[document.theform.elements[i].options.selectedIndex].value
		var bg=0;
		var en=0;
		var prod1=""
		bg=jmj.indexOf("|");
		prod1=jmj.substring(0,bg) //Get the product description
		bg=jmj.indexOf("|",en)+1
		en=jmj.indexOf("|",bg+1)
		var firstprice=jmj.substring(bg,en) //Get the price
		bg=jmj.indexOf("|",en)+1
		en=jmj.length
		var stock1=jmj.substring(bg,en)
		if(document.theform.elements[i+1].value=="") 
			document.theform.elements[i+1].value=0
			book+=prod1+"|"+firstprice+"|"+stock1+"|"
			book+=document.theform.elements[i+1].value+"|";
		}
	}
	else si=777 //Nope, it was just the default "Click here to select options" setting
}

//Now check the checkbox
		if (document.theform.elements[i].type!="select-one" && document.theform.elements[i].value!="")
		{
   	    	if (document.theform.elements[i+1].type=="select-one")
			{
				do_ops()
			}
			else book+=document.theform.elements[i].value+"|"+document.theform.elements[i+1].value+"|"
        }
	}
//----------------------------------------------------------------------------
//If the checkbox hasn't been checked and it has options, skip all the optiosn
//----------------------------------------------------------------------------

//alert(document.theform.elements[i+1].type)
if (document.theform.elements[i+1].type=="select-one")
{
	i++;
	while(document.theform.elements[i].type=="select-one")
	{	
		i++;
	}
	i--
}

i+=2; //this is an increment by two because every second elementis the checkbox

}

cookie_update("cook=", book, 0);

}

function cookie_update(tag, value, replace) 
    {
    var allcookies = document.cookie;
    var start = allcookies.indexOf(tag);

    if (!replace && start != -1)	// Existing data in cookie
	{
	var end = allcookies.indexOf(";")
	if (end == -1)
	    end = allcookies.length;
	// In order to maintain compatibility with existing shop cookie
	// format we discard the first character of the existing value
	// This gives |a1|a2|a3|b1|b2|b3| rather than |a1|a2|a3||b1|b2|b3|
	value += allcookies.substring(start + 1 + tag.length, end);
	}

    // Expire after N hours (currently 8)
    var expirewhen = new Date();
    expirewhen.setTime(expirewhen.getTime() + 1000 * 60 * 60 * 8);
    value += "; expires="+expirewhen.toGMTString();

    // If more than two components in the hostname, strip off the first and
    // set as a domain, so we can pass cookies around within a domain
    var domain = window.location.hostname;
    var dotpos = domain.indexOf(".");
    if (dotpos != -1 && domain.indexOf(".", dotpos+1) != -1)
	value += "; domain="+domain.substring(dotpos);

    document.cookie=tag + value;
    }

function check(val)
{
	var d=document.theform.elements
	var nogood="false"
	for (var zit = 0; zit < val.length; zit++) 
	{
		var ha = val.substring(zit, zit + 1)
		if (ha < "0" || ha > "9") 
		{
			alert("Please enter a number for the quantity you require.")
			nogood="true"
			for (zit=0; zit<d.length; zit++)
			{
				if (d[zit].value==val) d[zit].focus();
			}
		}
	}

	for (zit=0; zit<document.theform.elements.length-2; zit++)
	{
		if (nogood=="false" && document.theform.elements[zit].type=="text" && document.theform.elements[zit].value!="")
		{
			document.theform.elements[zit-1].checked=true
		}

		if (d[zit].value=="" || d[zit].value=="0" && d[zit].type=="text") 
			d[zit-1].checked=false
	}

} //end function check


function do_ops()
{
	var jmj;
	if (document.theform.elements[i].type=="select-one")
		jmj=document.theform.elements[i].options[document.theform.elements[i].options.selectedIndex].value
	else 
		jmj=document.theform.elements[i].value;
	var sag=document.theform.elements[i+1].options[document.theform.elements[i+1].options.selectedIndex].value
	var bg=0;
	var en=0;
	var prod1=""
	bg=jmj.indexOf("|");
	prod1=jmj.substring(0,bg) //Get the product description

	bg=jmj.indexOf("|",en)+1
	en=jmj.indexOf("|",bg+1)
	var firstprice=jmj.substring(bg,en) //Get the price

	bg=jmj.indexOf("|",en)+1
	en=jmj.length
	var stock1=jmj.substring(bg,en)
	bg=sag.indexOf("|") 
	var prod2=sag.substring(0,bg) //get the description of the option
	prod1+="-"+prod2 //Product description PLUS OPTION description

	bg=sag.indexOf("|")+1
	en=sag.indexOf("|",bg)
	var secondprice=sag.substring(bg,en) //price

	bg=sag.indexOf("|",en)+1
    var stock2=sag.substring(bg,sag.length) //the stock #	
	stock1+="-"+stock2
	parseInt(firstprice); parseInt(secondprice); firstprice++; firstprice--; secondprice++; secondprice--; firstprice+=secondprice; firstprice=Math.round(firstprice*100)/100
	i++;

    if (document.theform.elements[i+1].type=="select-one")
	{
		i++;
		while(document.theform.elements[i].type=="select-one")
		{
        	sag=document.theform.elements[i].options[document.theform.elements[i].options.selectedIndex].value

			bg=sag.indexOf("|")
            prod2=sag.substring(0,bg) //get the description of the option
			prod1+="-"+prod2 //Product description PLUS OPTION description
			bg=sag.indexOf("|",bg)+1
			en=sag.indexOf("|",bg)

			secondprice=sag.substring(bg,en) //price
            parseInt(secondprice); secondprice++; secondprice--; firstprice+=secondprice; firstprice=Math.round(firstprice*100)/100
        	bg=sag.indexOf("|",en)+1
            stock2=sag.substring(bg,sag.length) //the stock #	
		    stock1+="-"+stock2
			i++;
		}
		i--
	}
	book+=prod1+"|"+firstprice+"|"+stock1
	book+="|"+document.theform.elements[i+1].value+"|"
} // end function do_ops
  
function start() 
{
	i=0; 
	j=0; 
	var cookie=document.cookie; 
	var crud=""; 
	var end=0; 
  
	while (crud!="true") 
	{ 
		begin=cookie.indexOf("|",end); 
		end=cookie.indexOf("|",begin+1) 
		book=cookie.substring(begin+1,end) 
  
		if (end==-1 || end=="") 
			crud="true" 
  
		begin=cookie.indexOf("|",end); 
		end=cookie.indexOf("|",begin+1) 
		price=cookie.substring(begin+1,end) 
  
 		begin=cookie.indexOf("|",end); 
		end=cookie.indexOf("|",begin+1) 
		stock=cookie.substring(begin+1,end) 
  
		begin=cookie.indexOf("|",end); 
		end=cookie.indexOf("|",begin+1) 
		howmany=cookie.substring(begin+1,end) 
  
		if (crud !="true") 
		{ 
			crap[j]=new person(book,price,stock,howmany); 
			j++; 
		} 
  
	} //end of while 
} //end function start

// function special()
// {
// 	var tempthing=document.cookie
// 	var beginthing=tempthing.indexOf("cook=")+5
// 	tempthing=tempthing.substring(beginthing,tempthing.length)
// 	var moretemp=""
// 	for (var dum1=0; dum1<tempthing.length; dum1++)
// 	{
// 		if (tempthing.substring(dum1,dum1+1)==" ")
// 		{
// 			moretemp+="%20"
// 		}
// 		else
// 			moretemp+=tempthing.substring(dum1,dum1+1)
// 	}
// 	document.cookie="cook="+moretemp
// 
// 	var special=document.cookie
// 	var bspecial=special.indexOf("cook=")+5
// 	var bend=special.indexOf(";",bspecial)
// 	if (bend==-1 || bend=="")
// 		bend=special.length
// 	special=special.substring(bspecial,bend)
// 	location.href="/shop/checkbasket.html?"+special
// } //end function special
