	//checkCart() - tests to see if the form is sending a list of images.  If not the user gets a warning.
	function checkCart() {
		alert("checkCart");
		CookLength = document.cookie.length;
		if (CookLength < 15) {
			if (confirm("You are about to submit an order with no photos selected!\n\n If that is not your intention please click Cancel and use your browser's 'Back' button and select some photos from the database.\n\n If you did select photos, then you probably have your browser configured not to accept cookies.\n\n If necessary, make a list of the photo reference numbers and sizes and write them in the Comments field.\n\n Clicking OK now will submit the form as it is, with no photograph references.")) {
				return true;
			} else {
				return false;
			}
		}
	}


	/////// ver-cc() - verifies that credit card is valid number//////////
	function verCC(CCnum) {
		var CCnumber = ""
		var CardNum = ""
		CCnumber = CCnum
		
		// removes spaces and hyphens from number
		for ( var i=0; i<CCnumber.length; i++ ) {
			if ( CCnumber.charAt(i)!=" " && CCnumber.charAt(i)!= "-" ) {
   			CardNum = CardNum + CCnumber.charAt(i);
			} 
		}
		// checks that it is a number of 16 characters
		if ( isNaN(CardNum ) || CardNum.length!=16) {
 	 		CardInvalid()
 	 		return false
  		}	

  		// Populate array cc with the numbers
  		cc = new Array(16);
  		for ( var i=0; i<16; i++ ) {
   		cc[i] = CardNum.charAt(i);
		}
		
  		// checks that first digit is 4 or 5
  		if ( cc[0] != 4 && cc[0] != 5 ) {
   		CardInvalid()
   		return false
		}
		
		var cc0a = cc[0] * 2;
		var cc2a = cc[2] * 2;
		var cc4a = cc[4] * 2;
		var cc6a = cc[6] * 2;
		var cc8a = cc[8] * 2;
		var cc10a = cc[10] * 2;
		var cc12a = cc[12] * 2;
		var cc14a = cc[14] * 2;
      
      
      
		if (cc0a >= 10) {
			cc0b = parseInt(cc0a / 10);
			cc0c = cc0a % 10   	
			cc[0] = (cc0b+cc0c);
		} else {
			cc[0] = cc0a;
		}
      
		if (cc2a >= 10) {
			cc2b = parseInt(cc2a / 10);
        	cc2c = cc2a % 10   	
        	cc[2] = (cc2b+cc2c);
		} else {
			cc[2] = cc2a;
		}

		if (cc4a >= 10) {
			cc4b = parseInt(cc4a / 10);
			cc4c = cc4a % 10   	
			cc[4] = (cc4b+cc4c);
		} else {
			cc[4] = cc4a;
		}

		if (cc6a >= 10) {
			cc6b = parseInt(cc6a / 10);
			cc6c = cc6a % 10   	
			cc[6] = (cc6b+cc6c);
		} else {
			cc[6] = cc6a;
		}

		if (cc8a >= 10) {
			cc8b = parseInt(cc8a / 10);
			cc8c = cc8a % 10   	
			cc[8] = (cc8b+cc8c);
		} else {
			cc[8] = cc8a;
		}

		if (cc10a >= 10) {
			cc10b = parseInt(cc10a / 10);
			cc10c = cc10a % 10   	
			cc[10] = (cc10b+cc10c);
		} else {
			cc[10] = cc10a;
		}

		if (cc12a >= 10) {
			cc12b = parseInt(cc12a / 10);
			cc12c = cc12a % 10   	
			cc[12] = (cc12b+cc12c);
		} else {
			cc[12] = cc12a;
		}

		if (cc14a >= 10) {
			cc14b = parseInt(cc14a / 10);
			cc14c = cc14a % 10   	
			cc[14] = (cc14b+cc14c);
		} else {
			cc[14] = cc14a;
		}

		var CardEval = 0
		for ( var i=0; i<16; i++ ) {
			CardEval += parseInt(cc[i]);
		}
		
		if ( CardEval % 10 != 0 ) {
			CardInvalid()
		}
		}
	

		// message if card is invalid
		function CardInvalid() {
		alert("That is not a valid credit card number.  Please check it carefully.")
		return

}


	// alterError - fixes a rounding bug in Netscape 2
	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);
	}

	var printCart = Array()
	var digiCart = Array()
	

	// showItems () - creates a table of items in the basket and
	// creates the start of a form which sets information for
	// basket items.
	function showItems(){
		var shipping = 0
		var shipTotal = 0
		var printTotal = 0
		var calendarTotal = 0
		var theitem = ""
		var itemCost = 0
		var theimage = ""
		var thequantity = 0
		var itemTotal = 0
		var totalCost = 0
		digipix = false
		var allImageCost = 0
		allImageDiscount = 0
		CDprice = top.menu.document.dataForm.CDprice.value;
		var CDval = top.menu.document.dataForm.CD.value;  //yes if a CD is to be shipped
		data=""
		pickup = true       //whether the order is suitable for pickup at an event
		CD = false      //becomes true if order contains off-line digital image or customer requests CD
		MB = 0          //Total megabytes for download
		var mix = false  //true when there is a mix of downloadable and non-downloadable digital images
		var mixTest = ""
		var mixCount = 0
		printOrder = false
		calendar = false
		cdlist = ""  //list of all the digital images that cannot be downloaded
		downloadlist = "" //list of all the images for download
		
		
		readCookie();
		printCart.sort();
		len = printCart[0][0].length
		
		document.writeln('<FORM name="CCform" onSubmit="return checkCart();">');
		document.writeln('<TABLE BORDER="1" cellspacing="0" cellpadding="3">');

		if (len>0){
			for (var i=0; i<printCart.length; i++){
				//alert("printCart[0][0]= "+printCart[0][0]+"  printCart.length="+printCart.length+"  printCart[0].length="+printCart[0].length);
				if ((printCart[i][0]==1) || (printCart[i][0]==5)){ //this checks print or digital 1=print 2=all digital images 3=selected digital images 4=calendars 5=art prints
					//alert("i="+i+" printCart[i][0]= "+printCart[i][0]+"   "+printCart[i][2]);
					
 					theitem = printCart[i][1]+" - "+printCart[i][7]+"<br> "+printCart[i][2];
					theitem2 = printCart[i][1]+" "+printCart[i][2]+" Quantity= "+thequantity+" Cost= US$"+alterError(itemTotal);

 					itemCost = printCart[i][3];
 					theimage = printCart[i][4];
 					thequantity = printCart[i][5];
					var boatName = printCart[i][7];
 					itemTotal = Number(itemCost) * thequantity;
					data = data+"##"+printCart[i][0]+"|"+printCart[i][1]+"|"+printCart[i][5]+"|"+printCart[i][7]+"|"+printCart[i][8]+"|"+alterError(itemTotal);
 					printTotal = printTotal+itemTotal;
   					if (theitem.indexOf("Print") != -1) {
   						// alert ("Print");
   						if (shipping < 10) {
   							shipping = 10
   						}
   					}
   					if (theitem.indexOf("Poster") != -1) {
   						//alert ("Poster");
   						if (shipping < 15) {
   							shipping = 15
   						}
   					}
					if (printOrder==false){
						printOrder = true;
						document.writeln('<TR bgcolor="#ffffee"><TD align=center><font size=4><b>Prints</b></font></TD><TD align=center><font size=2><b>Quantity</b></font></TD><TD align=center><font size=2><b>Cost US$</b></font></TD><TD align=center><font size=2>&nbsp</font></TD></TR>');
					}

					quantbox = "quant"+i    //name of text field holding quantity information
   					//document.writeln('<tr valign="top" bgcolor="#ffffee"><td align=center><font size=2>'+theitem+'<br><img src="'+theimage+'"></font></td><td align=center><font size=2>'+thequantity+'</font></td><td align=center><font size=2>'+alterError(itemTotal)+'</font></td></td><td align=center><font size=2><a href="javascript:removeItem('+i+')">Remove</a></font></td></tr>');
   					document.writeln('<tr valign="top" bgcolor="#ffffee"><td align=center><font size=2>'+theitem+'<br><img src="'+theimage+'"></font></td><td align=center><input type="text" name="'+quantbox+'" value="'+thequantity+'" size="3" maxlength="3" onBlur="changeQuant('+quantbox+')"></td><td align=center><font size=2>'+alterError(itemTotal)+'</font></td></td><td align=center><font size=2><a href="javascript:removeItem('+i+')">Remove</a></font></td></tr>');
   					document.writeln('<INPUT TYPE="hidden" NAME="Item'+i+'" VALUE="'+theitem+'" SIZE="100">');
   					document.writeln('<INPUT TYPE="hidden" NAME="Quantity'+i+'" VALUE="'+thequantity+'" SIZE="40">');
   					document.writeln('<INPUT TYPE="hidden" NAME="Total cost US$'+i+'" VALUE="'+alterError(itemTotal)+'" SIZE="40">');
				}
			}
			if(printOrder){
				
				//document.writeln('<tr bgcolor="#ffffee"><td colspan=2><font size=2><b>Prints Sub-total</b></font></td><td align=center><font size=2>'+alterError(printTotal)+'</font></td><td>.</td></tr>');
				//document.writeln('<tr bgcolor="#ffffee"><td colspan=2><font size=2><b>Print Shipping and handling</b></font></td><td align=center><font size=2>'+alterError(shipping)+'</font></td><td>(May be less in UK or Europe)</td></tr>');
				//printTotal = printTotal+shipping;
				//shipTotal = shipTotal+shipping;
				document.writeln('<tr bgcolor="#F1DCE2"><td colspan=2><font size=2><b>Print Total</b></font></td><td align=center><font size=2>'+alterError(printTotal)+'</font></td><td>&nbsp</td></tr>');
			}
			//shipping=0
			for (var i=0; i<printCart.length; i++){
				if(printCart[i][0]==4) {   //Calendars
					theitem = printCart[i][1]+" - "+printCart[i][7]+"<br> "+printCart[i][2];
					itemCost = printCart[i][3];
					theimage = printCart[i][4]+".jpg";
					thequantity = printCart[i][5];
					itemTotal = itemCost * thequantity;
					//alert("itemTotal = "+itemTotal);
					calendarTotal = calendarTotal+itemTotal;
					
					//if (theitem.indexOf("Desk") != -1) {
					//	if (shipping < 10) {
					//		shipping = 10
					//	}
					//}
					
					if (shipping < 10){
						shipping = 10
					}
					
					//if (theitem.indexOf("Wall") != -1) {
					//	if (shipping < 15) {
					//		shipping = 15
					//	}
					//}
					
					quantbox = "quant"+i    //name of text field holding quantity information
					//document.writeln('<tr valign="top" bgcolor="#ffffee"><td align=center><font size=2>'+theitem+'<br><img src="'+theimage+'"></font></td><td align=center><font size=2>'+thequantity+'</font></td><td align=center><font size=2>'+alterError(itemTotal)+'</font></td></td><td align=center><font size=2><a href="javascript:removeItem('+i+')">Remove</a></font></td></tr>');
					if (calendar==false){
						calendar=true;
						document.writeln('<TR bgcolor="#ffffee"><TD align=center><font size=4><b>Calendars</b></font></TD><TD align=center><font size=2><b>Quantity</b></font></TD><TD align=center><font size=2><b>Cost US$</b></font></TD><TD align=center><font size=2>&nbsp</font></TD></TR>');
					}
					document.writeln('<tr valign="top" bgcolor="#ffffee"><td align=center><font size=2>'+theitem+'<br><img src="'+theimage+'"></font></td><td align=center><input type="text" name="'+quantbox+'" value="'+thequantity+'" size="3" maxlength="3" onBlur="changeQuant('+quantbox+')"></td><td align=center><font size=2>'+alterError(itemTotal)+'</font></td></td><td align=center><font size=2><a href="javascript:removeItem('+i+')">Remove</a></font></td></tr>');
					document.writeln('<INPUT TYPE="hidden" NAME="Item'+i+'" VALUE="'+theitem+'" SIZE="100">');
					document.writeln('<INPUT TYPE="hidden" NAME="Quantity'+i+'" VALUE="'+thequantity+'" SIZE="40">');
					document.writeln('<INPUT TYPE="hidden" NAME="Total cost US$'+i+'" VALUE="'+alterError(itemTotal)+'" SIZE="40">');
					//alert("280 = "+printCart[i]);
					data = data+"##"+printCart[i][0]+"|"+printCart[i][2]+"|"+printCart[i][5]+"|"+printCart[i][3]+"|"+alterError(itemTotal)+"|"+printCart[i][7];
					//alert("282 = "+data);
				}
			}
			if(calendar){
				//document.writeln('<tr bgcolor="#ffffee"><td colspan=2><font size=2><b>Calendars Sub-total</b></font></td><td align=center><font size=2>'+alterError(calendarTotal)+'</font></td><td>.</td></tr>');
				//document.writeln('<tr bgcolor="#ffffee"><td colspan=2><font size=2><b>Calendar shipping and handling</b></font></td><td align=center><font size=2>'+alterError(shipping)+'</font></td><td>.</td></tr>');
				//calendarTotal = calendarTotal+shipping;
				//shipTotal=shipTotal+shipping;
				document.writeln('<tr bgcolor="#F1DCE2"><td colspan=2><font size=2><b>Calendar Total</b></font></td><td align=center><font size=2>'+alterError(calendarTotal)+'</font></td><td>&nbsp</td></tr>');
			}
			for (var i=0; i<printCart.length; i++){
				if((printCart[i][0]==2)||(printCart[i][0]==3)) {
					  digipix = true
					  //alert("digipix");
				}
			}
			
				
			if (digipix){
				//document.writeln('<TR bgcolor="#ffffee"><TD align=center><font size=2>.</font></TD><TD align=center><font size=2>.</font></TD><TD align=center><font size=2>.</font></TD><td>.</td></TR>');
				//document.writeln('<TR bgcolor="#ffffee"><TD align=center><font size=4><b>Digital Images</b></font></TD><TD align=center><font size=2><b>Quantity</b></font></TD><TD align=center><font size=2><b>Cost<br>US$</b></font></TD><td>&nbsp</td><TD align=center><font size=2><b>Down<br>load</b></font></TD><TD align=center><font size=2><b>MB</b></font></TD></TR>');
				document.writeln('<TR bgcolor="#ffffee"><TD align=center><font size=4><b>Digital Images</b></font></TD><TD align=center><font size=2><b>Quantity</b></font></TD><TD align=center><font size=2><b>Cost<br>US$</b></font></TD><td>&nbsp</td></TR>');

			}
			var digiItem = 1
			var digiItemCost
			var digiTotal = 0
			thequantity=1
			itemlist = 0
			var lastBoatNum
			var boatNum
			var imageCount
			var allImageDiscount = 0
					
			//now display the digital images - ALL images
			for(i=0; i<printCart.length; i++){
				if (printCart[i][0]==2) {  //ALL images selected
					var allpix = true
					//alert(printCart[i][9]);  //image list
					var string = printCart[i][9];
					listing = string.split(",");
					var OnLine = printCart[i][10];
					if ((OnLine == "no")&&(top.menu.document.dataForm.ElectronicDelivery.value == "no")){
						CD = true;
					}
					
					if (mixCount >0){
						if (mixTest != printCart[i][10]){
							mix = true //because there are a mix of downloadable and non-downloadable images
						}
					}
					mixTest = printCart[i][10]					
					mixCount++

					priceFormula = printCart[i][11]
					PF = priceFormula.split (" ");
					var priceOne = parseInt(PF[0]);
					var priceTwo = parseInt(PF[1]);
					var priceThree = parseInt(PF[2]);
					var priceFour = parseInt(PF[3]);
					var priceFive = parseInt(PF[4]);
					var priceTwenty = parseInt(PF[5]);
					var priceDiscount = parseInt(PF[6]);
					//alert("priceOne+priceTwo = "+ (priceThree+priceFour))
					
					
					var allImageCost = 0
 				 	theimage = printCart[i][4];
					theitem = "all "+listing.length+" images of "+printCart[i][7]+" (-"+priceDiscount+"%)";
 				 	theimage = printCart[i][4];
					var length = printCart[i][5];
				 	boatNum = printCart[i][1];
					imageCount = listing.length;
					var boatName = printCart[i][7];
					for (var p=0; p<imageCount; p++){
	   					switch(p){
	   						case 0:
								digiItemCost = priceOne
	   							break
	  						case 1:
								digiItemCost = priceTwo
	  							break
	  						case 2:
								digiItemCost = priceThree
	  							break
	  						case 3:
								digiItemCost = priceFour
	  							break
	  						default: if (p > 19) {           //charge $5 for more than 20 images
									digiItemCost = priceTwenty
									break
								}else {
									digiItemCost = priceFive

								}
						} //switch
						if (length > 45) {  //charge more for over 45 feet
							digiItemCost = parseInt(digiItemCost * (length / 45));
						}
						allImageCost += digiItemCost;
					}
						allImageDiscount += allImageCost * (priceDiscount/100);

					digiTotal+= allImageCost;
					MBytes = top.menu.document.dataForm.AvSize.value * imageCount
					if (OnLine=="yes" || top.menu.document.dataForm.ElectronicDelivery.value=="yes"){
   						//document.writeln('<tr valign="top" bgcolor="#ffffee"><td align=center><font size=2>'+theitem+'<br><img src="/CD.gif"></font></td><td align=center><font size=2>'+imageCount+'</font></td><td align=center><font size=2>'+alterError(allImageCost)+'</font></td></td><td align=center><font size=2><a href="javascript:removeItem('+i+')">Remove</a></font></td><td align=center><font size=2>'+OnLine+'</font></td><td align=center><font size=2>'+MBytes+'</font></td></tr>');
   						document.writeln('<tr valign="top" bgcolor="#ffffee"><td align=center><font size=2>'+theitem+'<br><img src="/CD.gif"></font></td><td align=center><font size=2>'+imageCount+'</font></td><td align=center><font size=2>'+alterError(allImageCost)+'</font></td></td><td align=center><font size=2><a href="javascript:removeItem('+i+')">Remove</a></font></td></tr>');

   						MB = MB + MBytes
   					}else{
   						//document.writeln('<tr valign="top" bgcolor="#ffffee"><td align=center><font size=2>'+theitem+'<br><img src="/CD.gif"></font></td><td align=center><font size=2>'+imageCount+'</font></td><td align=center><font size=2>'+alterError(allImageCost)+'</font></td></td><td align=center><font size=2><a href="javascript:removeItem('+i+')">Remove</a></font></td><td align=center><font size=2>'+OnLine+'</font></td><td align=center><font size=2>&nbsp</font></td></tr>');
   						document.writeln('<tr valign="top" bgcolor="#ffffee"><td align=center><font size=2>'+theitem+'<br><img src="/CD.gif"></font></td><td align=center><font size=2>'+imageCount+'</font></td><td align=center><font size=2>'+alterError(allImageCost)+'</font></td></td><td align=center><font size=2><a href="javascript:removeItem('+i+')">Remove</a></font></td></tr>');

   					}
					theitem = theitem+"$US0.00"  //add this so that the parser works properly when extracting the data drom email
   					document.writeln('<INPUT TYPE="hidden" NAME="Item'+i+'" VALUE="'+theitem+'" SIZE="100">');
   					document.writeln('<INPUT TYPE="hidden" NAME="Quantity'+i+'" VALUE="'+imageCount+'" SIZE="40">');
   					document.writeln('<INPUT TYPE="hidden" NAME="Total cost US$'+i+'" VALUE="'+alterError(allImageCost)+'" SIZE="40">');
					data = data+"##"+printCart[i][0]+"|"+printCart[i][2]+"|"+printCart[i][6]+"|"+printCart[i][7]+"|"+printCart[i][8]+"|"+alterError(allImageCost)+"|"+printCart[i][9]+"|"+CDval;
					if (printCart[i][10] == "no"){
						if (cdlist.length >0){
							cdlist = cdlist+","
						}
						cdlist = cdlist + printCart[i][9];
					}
					//alert("320 printCart[i][10] = "+printCart[i][10]);
					if (printCart[i][10] == "yes"){
						if (downloadlist.length >0){
							downloadlist = downloadlist+","
						}
						downloadlist = downloadlist+printCart[i][9];
					}
				}
			}
					
					
			for(i=0; i<printCart.length; i++){  
				if (printCart[i][0]==3) { //this checks print or digital 1=print 2=all digital images 3=selected digital images
					theitem = printCart[i][2]+" "+printCart[i][3]+" - "+printCart[i][7];
 				 	theimage = printCart[i][4];
					var length = printCart[i][5];
				 	boatNum = printCart[i][1];
				 	var OnLine = printCart[i][10];
				 	if ((OnLine == "no")&&(top.menu.document.dataForm.ElectronicDelivery.value == "no")){
						CD = true;
					}
					
					if (mixCount >0){
						if (mixTest != printCart[i][10]){
							mix = true //because there are a mix of downloadable and non-downloadable images
						}
					}
					mixTest = printCart[i][10]					
					mixCount++
					
					priceFormula = printCart[i][11]
					PF = priceFormula.split (" ");
					var priceOne = parseInt(PF[0]);
					var priceTwo = parseInt(PF[1]);
					var priceThree = parseInt(PF[2]);
					var priceFour = parseInt(PF[3]);
					var priceFive = parseInt(PF[4]);
					var priceTwenty = parseInt(PF[5]);
					var priceDiscount = parseInt(PF[6]);
					//alert("priceOne+priceTwo = "+ (priceThree+priceFour))
					
					
					if (boatNum != 999){
						if (boatNum != lastBoatNum){
							digiItem = 1  // so that price breaks start again for different boats
						}
					}else{
						if (allpix == true){
							digiItem = 5;
						}
					}
					lastBoatNum = boatNum
					switch(digiItem){
   						case 1:
							digiItemCost = priceOne
   							break
  						case 2:
							digiItemCost = priceTwo
  							break
  						case 3:
							digiItemCost = priceThree
  							break
  						case 4:
							digiItemCost = priceFour
  							break
  						default: if (digiItem > 20) {           //charge $5 for more than 20 images
								digiItemCost = priceTwenty
								break
							}else {
								digiItemCost = priceFive

							}
					} //switch
					if (length > 45) {  //charge more for over 45 feet
						digiItemCost = parseInt(digiItemCost * (length / 45));
					}
					digiTotal += digiItemCost;

					itemlist++
					MBytes = thequantity * top.menu.document.dataForm.AvSize.value
					
					//writes lines only for digital images
					if (OnLine == "yes" || top.menu.document.dataForm.ElectronicDelivery.value=="yes"){
						//document.writeln('<tr valign="top" bgcolor="#ffffee"><td align=center><font size=2>'+theitem+'<br><img src="'+theimage+'"></font></td><td align=center><font size=2>'+thequantity+'</font></td><td align=center><font size=2>'+alterError(digiItemCost)+'</font></td></td><td align=center><font size=2><a href="javascript:removeItem('+i+')">Remove</a></font></td><td align=center><font size=2>'+OnLine+'</font></td><td align=center><font size=2>'+MBytes+'</font></td></tr>');
						document.writeln('<tr valign="top" bgcolor="#ffffee"><td align=center><font size=2>'+theitem+'<br><img src="'+theimage+'"></font></td><td align=center><font size=2>'+thequantity+'</font></td><td align=center><font size=2>'+alterError(digiItemCost)+'</font></td></td><td align=center><font size=2><a href="javascript:removeItem('+i+')">Remove</a></font></td></tr>');

						MB =MB+MBytes;
					}else{
						//document.writeln('<tr valign="top" bgcolor="#ffffee"><td align=center><font size=2>'+theitem+'<br><img src="'+theimage+'"></font></td><td align=center><font size=2>'+thequantity+'</font></td><td align=center><font size=2>'+alterError(digiItemCost)+'</font></td></td><td align=center><font size=2><a href="javascript:removeItem('+i+')">Remove</a></font></td><td align=center><font size=2>'+OnLine+'</font></td><td align=center><font size=2>&nbsp</font></td></tr>');
						document.writeln('<tr valign="top" bgcolor="#ffffee"><td align=center><font size=2>'+theitem+'<br><img src="'+theimage+'"></font></td><td align=center><font size=2>'+thequantity+'</font></td><td align=center><font size=2>'+alterError(digiItemCost)+'</font></td></td><td align=center><font size=2><a href="javascript:removeItem('+i+')">Remove</a></font></td></tr>');

					}
   					
					theitem = theitem+"$US0.00"  //add this so that the parser works properly when extracting the data drom email
   					document.writeln('<INPUT TYPE="hidden" NAME="Item'+i+'" VALUE="'+theitem+'" SIZE="100">');
   					document.writeln('<INPUT TYPE="hidden" NAME="Quantity'+i+'" VALUE="'+thequantity+'" SIZE="40">');
   					document.writeln('<INPUT TYPE="hidden" NAME="Total cost US$'+i+'" VALUE="'+alterError(digiItemCost)+'" SIZE="40">');
					
					data = data+"##"+printCart[i][0]+"|"+printCart[i][2]+"|"+printCart[i][6]+"|"+printCart[i][7]+"|"+printCart[i][8]+"|"+alterError(digiItemCost)+"||"+CDval;
					if (printCart[i][10] == "no"){
						if (cdlist.length >0){
							cdlist = cdlist+","
						}
						cdlist = cdlist + printCart[i][2]+".jpg";
					}
					
					if (printCart[i][10] == "yes"){
						if (downloadlist.length >0){
							downloadlist = downloadlist+","
						}
						downloadlist = downloadlist+printCart[i][2]+".jpg";
					}

					digiItem++
				} //if
			} //for
			if (digipix){
				var discount = "-"+alterError(allImageDiscount);
				document.writeln('<tr bgcolor="#ffffee"><td colspan=2><font size=2><b>Digital Sub-total</b></font></td><td align=center><font size=2>'+alterError(digiTotal)+'</font></td><td>&nbsp</td></tr>');
				if (allImageDiscount > 0){
					document.writeln('<tr bgcolor="#ffffee"><td colspan=2><font size=2><b>Discount for buying all images</b></font></td><td align=center><font size=2>'+discount+'</font></td><td>&nbsp</td></tr>');
					digiTotal -= allImageDiscount;
					document.writeln('<tr bgcolor="#ffffee"><td colspan=2><font size=2><b>New total for digital images</b></font></td><td align=center><font size=2>'+alterError(digiTotal)+'</font></td><td>&nbsp</td></tr>');
					
				}
				CD = false;                                                  //makes all delivery digital
				mix = false;
				top.menu.document.dataForm.ElectronicDelivery.value="yes"   //makes all delivery digital
				
				if (CD){
					CDprice = top.menu.document.dataForm.CDprice.value;
					document.writeln('<tr bgcolor="#ffffee"><td colspan=2><font size=2><b>Delivery of Digital Images (on CD)</b></font></td><td align=center><font size=2>'+alterError(parseInt(CDprice))+'</font></td><td>&nbsp</td></tr>');
					digiTotal += parseInt(CDprice);
				}else{
					document.writeln('<tr bgcolor="#ffffee"><td colspan=2><font size=2><b>Online Delivery of Digital Images</b></font></td><td align=center><font size=2>Free</font></td><td>&nbsp</td></tr>');
				}
				document.writeln('<tr bgcolor="#F1DCE2"><td colspan=2><font size=2><b>Digital Image Total</b></font></td><td align=center><font size=2>'+alterError(digiTotal)+'</font></td><td>&nbsp</td></tr>');
			}
			var orderTotal = printTotal+calendarTotal+digiTotal
			//alert("digipix printOrder calendar = "+digipix+"  "+printOrder+"  "+calendar);
			if ((digipix==true) && (printOrder==false) && (calendar==false)){
				top.menu.document.dataForm.cdonly.value = "yes";
			}else{
				top.menu.document.dataForm.cdonly.value = "no";
				document.writeln('<tr bgcolor="#ffffee"><td colspan=2><font size=2><b>Shipping & Handling will be added</b></font></td><td align=center><font size=2>&nbsp</font></td><td>&nbsp</td></tr>');
			}
			//top.menu.document.dataForm.orderTotal.value = alterError(orderTotal)
			document.writeln('<tr bgcolor="#ffffee"><td colspan=2><font size=2><b>Order Total</b></font></td><td align=center><font size=2 color="#FF0000">'+alterError(orderTotal)+'</font></td><td align=center><input type="button" name="Button" value="Remove All" onClick="clearBasket()"></td></tr>');
			document.writeln('<INPUT TYPE="hidden" NAME="Shipping US$" VALUE="'+alterError(shipping)+'" SIZE="40">');
			document.writeln('<INPUT TYPE="hidden" NAME="Goods Total US$" VALUE="'+alterError(orderTotal)+'" SIZE="40">');

			document.writeln('</TABLE>');
			
			top.menu.document.dataForm.shipping.value = 0;			
			top.menu.document.dataForm.orderTotal2.value = alterError(orderTotal);	
			top.menu.document.dataForm.data.value = data;
			top.menu.document.dataForm.allImageDiscount.value = alterError(allImageDiscount);
			top.menu.document.dataForm.downloadlist.value = downloadlist;
			top.menu.document.dataForm.cdlist.value = cdlist;
			//alert(top.menu.document.dataForm.orderTotal2.value)
			
			
			
			
			
			//alert("CD = "+CD+"  digipix = "+digipix+"  mix = "+mix+" top.menu.document.dataForm.ElectronicDelivery.value = "+top.menu.document.dataForm.ElectronicDelivery.value);
			if (top.menu.document.dataForm.ElectronicDelivery.value=="yes"){
				
				if (digipix){
					if (mix){
						document.writeln("<p>Some of the digital images you are ordering are available for instant download but others are not. The remainder will be added to your download folder as soon as possible.  The total download is approximately "+parseInt(MB+.5)+" megabytes. If you also want to receive the images on a CD you must check below (you will be charged an extra $"+top.menu.document.dataForm.CDprice.value+").<br><br>Send CD<INPUT type='checkbox' NAME='checkCD'><p>")
						top.menu.document.dataForm.mix.value = "yes";
					}else{	
						top.menu.document.dataForm.mix.value = "no";					
						if (OnLine == "yes"){
							document.writeln("<p>After taking your credit card details you will be able to download your images immediately.  The total download is approximately "+parseInt(MB+.5)+" megabytes. If you also want to receive the images on a CD you must check below (you will be charged an extra $"+top.menu.document.dataForm.CDprice.value+").<br><br>Send CD<INPUT type='checkbox' NAME='checkCD'><p>")
						}else{
							document.writeln("<p>As soon as possible after payment I will upload your digital images to a folder from which you can download them at your leisure.  I will send a link to your email address when the images are ready.  In some circumstances I may prefer to send a CD, in which case you will be notified by email.<p>")
						}
					}
	
				}
			}else{
				if (CD==false && digipix){
					document.writeln("<p>You can download your digital images after payment.  The total download is approximately "+parseInt(MB+.5)+" megabytes. If you prefer to receive the images on a CD via mail you must check below (you will be charged an extra $"+top.menu.document.dataForm.CDprice.value+").<br><br>Send CD<INPUT type='checkbox' NAME='checkCD'><p>")
				}
				
				if (mix){
					document.writeln('<p>Some of the digital images you are ordering are available for instant download but others are not. Where possible they will be made available immediately but all your images will be mailed on a CD.<p>')
					top.menu.document.dataForm.mix.value = "yes";
				}else{
					top.menu.document.dataForm.mix.value = "no";
				}
			}
			
		}
	}
	
	
	
	
	
	function changeQuant(q){
		string1 = q.name;
		var textIndex = 0
		val1 = string1.substr(5);
		textIndex = parseInt(val1);
		if (q.value<1){
			quant=1;
		}else{
			quant=q.value;
		}
		quant=parseInt(quant);
		printCart[textIndex][5] = quant;
		writeCookie()
		top.display.location = window.location;
	}
		

	function readCookie(){
		index = document.cookie.indexOf("TheBasket2");
		if (index != -1){
			countbegin = (document.cookie.indexOf("=", index) + 1);
			if (document.cookie.charAt(countbegin)=="."){
				countbegin++
			}
        		countend = document.cookie.indexOf(";", index);
        		if (countend == -1) {
            		countend = document.cookie.length;
        		}
			fulllist = document.cookie.substring(countbegin, countend);
			//alert("fulllist= "+fulllist);
			var Order = fulllist.split("#");
 			for (var i = 0; i<Order.length; i++){
				printCart[i] = new Array()
				var Item = Order[i].split("|");
				for (var p = 0; p<Item.length; p++){
					printCart[i][p] = Item[p]
					//alert("printCart["+i+"]["+p+"]= "+printCart[i][p]);
				}
			}
		}else{ //this stops error messages on first startup
			printCart = new Array(1);
			printCart[0] = new Array(1);
			printCart[0][0]=".";
			index = document.cookie.indexOf("TheBasket2");
			document.cookie="TheBasket2=.";
			top.display.location = window.location;

		}
	}

	function writeCookie(){
		//new_window = window.open ("array.htm","array_1");


		var cookieText = "";
		for (i=0; i<printCart.length; i++){
			len = printCart[i].length;
			if (len==1){
				i++
			}
			for (p=0; p<printCart[i].length; p++){
				cookieText += printCart[i][p];
				if(p != printCart[i].length -1){
					cookieText += "|";
				}
			}
			if (i != printCart.length -1){
				cookieText += "#";
			}
		}
		top.menu.burnCookie(cookieText); //must burn(write it) from menu
 		//new_window.document.form1.array_text.value = document.cookie;
 		//new_window.document.form1.textfield.value = printCart[0][0];
 		//new_window.document.form1.textfield2.value = printCart[0].length;

	}

	function removeItem(itemno){
		//alert("printCart.length= "+printCart.length);
		//alert("printCart= "+printCart);
		//alert("itemno= "+itemno);
		if (printCart.length == 1){
			clearBasket()
		}else{
			//removed = printCart.splice(itemno,1);
			// had to change this because some versions of JavaScript do not support Split
			
			
			var newCart = new Array();
			var newCartNum = 0
			for (i=0; i<printCart.length; i++){
				if (i==itemno){
					//skip
				}else{
					newCart[newCartNum] = new Array()
					for (var p=0; p<printCart[i].length; p++){
						newCart[newCartNum][p]=printCart[i][p];
					}
					newCartNum++
				}
			}
			printCart=new Array();
			for (i=0; i<newCart.length; i++){
				printCart[i]=new Array()
				for(p=0; p<newCart[i].length; p++){
					printCart[i][p]=newCart[i][p];
				}
			}

			
			printCart.sort();
			writeCookie()
		}
		top.display.location = window.location;
	}

	// clearBasket() - removes all items from the basket
	function clearBasket() {
		if (confirm('Are you sure you wish to clear the basket')) {
			index = document.cookie.indexOf("TheBasket2");
			document.cookie="TheBasket2=.";
			top.display.location = window.location;
		}
	}
	function checkDelivery(){
		alert("printCart= "+printCart);
		if (document.cookie.indexOf("20x30")!=-1||document.cookie.indexOf("12x18")!=-1||document.cookie.indexOf("16x24")!=-1){
			alert("The order must be mailed because you have chosen one or more item that cannot be supplied locally. If you wish to take your photos with you click the INFORMATION link below to see how you must amend your order.");
			this.document.location = "/t2information.htm"; //   "/DB/templates/t1buy-scc.htm"
		}
	}
function checkout(){
	top.controls.location="/t2black_page.htm";
	top.main.location="/t2blue_page.htm";
	top.newsearch.countClicks();
	window.location="https://www.photoaction.com/DB/templates/t1buy-scc.htm";
}

function checkout2(){
	//alert("CD= "+CD+"   digipix= "+digipix);
	//if(CD==false && digipix){
	//	if (document.CCform.checkCD.checked){
	//		top.menu.document.dataForm.CD.value="yes"
	//	}else{
	//		top.menu.document.dataForm.CD.value="no"
	//	}
	//}else{
		if(digipix){
			top.menu.document.dataForm.CD.value="yes"
		}else{
			top.menu.document.dataForm.CD.value="no"
		}
	//}
	//alert("CD.value= "+top.menu.document.dataForm.CD.value);
	top.controls.location="/t2black_page.htm";
	if(printOrder){
		//top.main.location="/t3blue_pageCalendarNoShip.htm";
		top.main.location="/t2blue_page.htm";
	}else{
		if(digipix){
			//top.main.location="/t3blue_pageCalendar.htm";
			top.main.location="/t2blue_page.htm";
		}else{
			top.main.location="/t2blue_page.htm";
		}
	}
	//top.newsearch.countClicks();
	//window.location="/DB/templates/t2buy-scc.htm";
	window.location="/DB/templates/t4buy-address.htm";
}
