/* Created by Acenius IT solutions (c) 2002
     Visit us at: http://www.acenius.com
	 E-mail info@acenius.com */

// alterError - fixes a rounding bug in Netscape 2
function order (){
	  parent.header.location = "header_order.html"; 
      parent.left.location = "left_order.html";
    return;
}


function alterError(value) {
		if (value<=0.99) {
			newEuro = '0';
		} else {
			newEuro = parseInt(value);
		}
		newCent = parseInt((value+.0008 - newEuro)* 100);
		if (eval(newCent) <= 9) newCent='0'+newCent;
		newString = newEuro + '.' + newCent;
		return (newString);
	}

// buyItem - adds an item to the shooping basket
function buyItem(newItem, newPrice, newQuantity, newOption) {
		if ((newQuantity <= 0) || (isNaN(newQuantity))) {
			rc = alert('Quantity not set or incorrect!');
		} else {
				alert ('Adding ' + newQuantity + ' ' + newItem + ' to shopping basket.');
                if (newQuantity >= 0) {
                        index = document.cookie.indexOf("TheBasket");
                        countbegin = (document.cookie.indexOf("=", index) + 1);
                        countend = document.cookie.indexOf(";", index);
                        if (countend == -1) {
                                countend = document.cookie.length;
			top.frames[3].location = "basket.htm";
                        }
		                document.cookie="TheBasket="+document.cookie.substring(countbegin, countend)+"["+newItem+"|"+newPrice+"|"+newOption+"|"+newQuantity+"]";
						parent.basket.location.reload();
			}
		}
	}

// showItems() - displays shopping basket in a table
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);
		subtotal = 0;
		document.writeln('<FORM><select class="menu"><option>Shoppingbasket</option>');
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
				thisitem = 1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				thequantity = fulllist.substring(itemstart, itemend);
				itemtotal = 0;
				itemtotal = (eval(theprice*thequantity));
				temptotal = itemtotal * 100;
				subtotal = subtotal + itemtotal;
				itemlist=itemlist+1;
				document.write('<option>'+thequantity+' st '+theitem+'</option>');
				
			} else if (fulllist.substring(i,i+1) == '|') {
				if (thisitem==1) theitem = fulllist.substring(itemstart, i);
				if (thisitem==2) theprice = fulllist.substring(itemstart, i);
				if (thisitem==3) theoption = fulllist.substring(itemstart, i);
				thisitem++;
				itemstart=i+1;
			}
		}
		document.write('</select><font class="normaal"> Total: <font class="normaal">&euro; '+alterError(subtotal));
							
		if (subtotal != 0){
		document.write('&nbsp;&nbsp;&nbsp;<a href="change.phtml" target="main" OnClick="order()"><u>Change</u></A>&nbsp;&nbsp;<a href="order.phtml" target="main" OnClick="order()"><u>Order</u></A>&nbsp;&nbsp;</form>');
		}
		else{
		document.write('&nbsp;&nbsp;&nbsp;<font class="boldblue"><u>Change</u></font>&nbsp;&nbsp;<font class="boldblue"><u>Order</u></font>&nbsp;&nbsp;</form>');
		}
}

function showChangeItems() {
	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);
		subtotal = 0;
		document.writeln('<font class="kop">Shopping Basket</FONT><P>');
		//Change kant
		if(fulllist.length > 1)
		{
		document.writeln('<FORM NAME="updateform" ID="updateform"><TABLE BORDER=1 bordercolor="f26522" CELLSPACING=1 CELLPADDING=2>');
		document.writeln('<TR><TD BGCOLOR="#FFFFFF"><font class="normaal"><b>Quantity</b></font></TD><TD BGCOLOR="#FFFFFF"><font class="normaal"><b>Author</b></font></TD><TD BGCOLOR="#FFFFFF"><font class="normaal"><b>Title</b></font></TD><TD BGCOLOR="#FFFFFF"><font class="normaal"><b>Price</b></font></TD><td BGCOLOR="#FFFFFF"><font class="normaal"><b>Sub Total</b></font></TD><TD BGCOLOR="#FFFFFF">&nbsp;</TD></TR>');
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
				thisitem = 1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				thequantity = fulllist.substring(itemstart, itemend);
				itemtotal = 0;
				itemtotal = (eval(theprice*thequantity));
				temptotal = itemtotal * 100;
				subtotal = subtotal + itemtotal;
				itemlist=itemlist+1;
				document.write('<tr><td align=middle BGCOLOR="#FFFFFF"><INPUT class="normaal" TYPE=TEXT NAME="quant'+itemlist+'" ID="quant'+itemlist+'" VALUE="'+thequantity+'" SIZE=3></td><td BGCOLOR="#FFFFFF"><font class="normaal">'+theitem+'</font></td>');
				document.write('<td align=left BGCOLOR="#FFFFFF"><FONT class="normaal">' + theoption + '</FONT></td>');
				document.write('<td valign="bottom" BGCOLOR="#FFFFFF"><table width=70><tr><td width=10><font class="normaal">&euro; </font></td><td width=60 align=right><font class="normaal">'+theprice+'</font></td></tr></table></td>');
				document.write('<td valign="bottom" BGCOLOR="#FFFFFF"><table width=70><tr><td width=10><font class="normaal">&euro; </font></td><td width=60 align=right><font class="normaal">'+alterError(itemtotal)+'</font></td></tr></table></td><td WIDTH="38" BGCOLOR="#FFFFFF" valign=middle align=right><a href="javascript:amendItem('+itemlist+',document.updateform.quant'+itemlist+'.value)"><IMG SRC="images/update.gif" WIDTH="13" HEIGHT="15" BORDER="0" ALT="Update"></a><IMG SRC="image/space.gif" WIDTH="3" HEIGHT="2" ALT=""><a href="javascript:removeItem('+itemlist+')"><IMG SRC="images/remove.gif" WIDTH="13" HEIGHT="15" BORDER="0" ALT="Remove"></a>&nbsp;</td></tr>');
			} else if (fulllist.substring(i,i+1) == '|') {
				if (thisitem==1) theitem = fulllist.substring(itemstart, i);
				if (thisitem==2) theprice = fulllist.substring(itemstart, i);
				if (thisitem==3) theoption = fulllist.substring(itemstart, i);
				thisitem++;
				itemstart=i+1;
			}
		}
		document.writeln('<tr><td align=right BGCOLOR="#FFFFFF" colspan=4><font class="normaal"><b>Total</b></font></td><td valign="bottom" BGCOLOR="#FFFFFF"><table width=70><tr><td width=10><font class="normaal"><b>&euro; </b></font></td><td width=60 align=right><font class="normaal"><b>'+alterError(subtotal)+'</b></font></td></tr></table></td><td BGCOLOR="#FFFFFF"><a href="order.phtml" name="Order">Order</a></td></tr>');
		document.writeln('</TABLE>&nbsp;<IMG SRC="images/update.gif" WIDTH="13" HEIGHT="15" BORDER="0" ALT="Update"><font class="blue"> = Update  </font><IMG SRC="images/remove.gif" WIDTH="13" HEIGHT="15" BORDER="0" ALT="Remove"><font class="blue"> = Remove</font></FONT>');
		document.writeln('</FORM>');
		}
		// als .
		else {
		document.write('The shoppingbasket is empty');
		}
}

function showOrderItems() {
  index = document.cookie.indexOf("TheBasket");
  countbegin = (document.cookie.indexOf("=", index) + 1);
         countend = document.cookie.indexOf(";", index);
         if (countend == -1) {
              countend = document.cookie.length;
         }
		 document.writeln('<font class="kop">Orderform</FONT><P>');
  //Order
  fulllist = document.cookie.substring(countbegin, countend);	
if(fulllist.length > 1)
  {
  subtotal = 0;
  document.writeln('<TABLE BORDER=1 bordercolor="f26522" CELLSPACING=1 CELLPADDING=2>');
  document.writeln('<TR><TD BGCOLOR="#FFFFFF"><font class="normaal"><b>Quantity<\/b></font><\/TD><TD BGCOLOR="#FFFFFF"><font class="normaal"><b>Author</b></font><\/TD><TD BGCOLOR="#FFFFFF"><font class="normaal"><B>Title<\/B></font><\/TD><TD BGCOLOR="#FFFFFF"><font class="normaal"><b>Price<\/b></font><\/TD><td BGCOLOR="#FFFFFF"><font class="normaal"><b>Sub total<\/b></font><\/td><\/TR>');
  itemlist = 0;

  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);
    itemtotal = 0;
    itemtotal = (eval(theprice*thequantity));
    temptotal = itemtotal * 100;
    subtotal = subtotal + itemtotal;
    itemlist=itemlist+1;
    document.write('<tr><td align=middle BGCOLOR="#FFFFFF">'+thequantity+'<\/td>');
    document.writeln('<td BGCOLOR="#FFFFFF"><font class="normaal">'+theitem+'</font><\/td><td align=left BGCOLOR="#FFFFFF"><font class="normaal">'+theoption+'</font><\/td><td valign=bottom BGCOLOR="#FFFFFF"><table width=70><tr><td width=10><font class="normaal">&euro; </font></td><td width=60 align=right><font class="normaal">'+theprice+'</font></td></tr></table><\/td><td valign=bottom BGCOLOR="#FFFFFF"><table width=70><tr><td width=10><font class="normaal">&euro; </font></td><td width=60 align=right><font class="normaal">'+alterError(itemtotal)+'</font></td></tr></table><\/td><\/tr>');
                                document.writeln('<INPUT TYPE="hidden" NAME="quantity'+itemlist+'" VALUE="'+thequantity+'  X" SIZE="40">');
    document.writeln('<INPUT TYPE="hidden" NAME="item'+itemlist+'" VALUE="'+theitem+'" SIZE="40">');
                                document.writeln('<INPUT TYPE="hidden" NAME="price_each'+itemlist+'" VALUE="'+theprice+'" SIZE="40">');
                                document.writeln('<INPUT TYPE="hidden" NAME="total_cost'+itemlist+'" VALUE="'+alterError(itemtotal)+'" SIZE="40">');
                                document.writeln('<INPUT TYPE="hidden" NAME="option'+itemlist+'" VALUE="'+theoption+'" SIZE="40">');
   } else if (fulllist.substring(i,i+1) == '|') {
    if (thisitem==1) theitem = fulllist.substring(itemstart, i);
    if (thisitem==2) theprice = fulllist.substring(itemstart, i);
    if (thisitem==3) theoption = fulllist.substring(itemstart, i);
    thisitem++;
    itemstart=i+1;
   }
  }
  totprice = (Math.round(subtotal*100)/100);
  document.writeln('<tr><td align=right BGCOLOR="#FFFFFF" colspan=4><font class="normaal"><b>Total<\/b></font<\/td><td BGCOLOR="#FFFFFF"><table width=70><tr><td width=10><font class="normaal"><b>&euro; </b></font></td><td width=60 align=right><font class="normaal"><b>'+alterError(totprice)+'</b></font></td></tr></table><\/td><\/tr>');
  document.writeln('<INPUT TYPE="hidden" NAME="Goods_Total" VALUE="'+alterError(totprice)+'" SIZE="40">');
  document.writeln('<\/TABLE>');
  document.writeln('<INPUT TYPE="hidden" NAME="aantal" VALUE="'+itemlist+'">');
  } else {
  document.write('There are no items in the shoppingbasket.');
  }
}

function amendItem(itemno, newquant) {
		newItemList = null;
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				thisitem = 1;
				itemstart = i+1;
				fullstart = i+1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				itemlist=itemlist+1;
				if (itemlist != itemno) {
					newItemList = newItemList+'['+fulllist.substring(fullstart, itemend)+']';
				} else {
					newItemList = newItemList + '['+theitem+'|'+theprice+'|'+theoption+'|'+newquant+']';
				}
			} else if (fulllist.substring(i,i+1) == '|') {
				if (thisitem==1) theitem = fulllist.substring(itemstart, i);
				if (thisitem==2) theprice = fulllist.substring(itemstart, i);
				if (thisitem==3) theoption = fulllist.substring(itemstart, i);
				thisitem++;
				itemstart=i+1;
			}
		}
		index = document.cookie.indexOf("TheBasket");
		document.cookie="TheBasket="+newItemList;
		self.location = "change.phtml";
}

function removeItem(itemno) {
		newItemList = null;
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				theitem = fulllist.substring(itemstart, itemend);
				itemlist=itemlist+1;
				if (itemlist != itemno) {
					newItemList = newItemList+'['+fulllist.substring(itemstart, itemend)+']';
				}
			}
		}
		index = document.cookie.indexOf("TheBasket");
		document.cookie="TheBasket="+newItemList;
		self.location = "change.phtml";
}

// clearBasket() - removes all items from the basket
function clearBasket() {
		if (confirm('Reset shoppingbasket?')) {
			index = document.cookie.indexOf("TheBasket");
			document.cookie="TheBasket=.";
			top.frames[3].location = "basket.htm";
			self.location = "main_stock.phtml";
			
		}
	}
// clearBasket() - removes all items from the basket
function resetBasket() {
			index = document.cookie.indexOf("TheBasket");
			document.cookie="TheBasket=.";
			top.frames[3].location = "basket.htm";
}

