function popup(url,width,height){
	attr = 'resizable=yes,scrollbars=no,width=' + width + ',height=' +
	height + '';
	window.open(url, 'popup', attr);
}

function checkQuantity(stock,order){
	if (stock < order & stock != "-1") {
					alert('Tillräckligt antal finns för närvarande inte i lager!\n\nFör större order, vänligen kontakta oss');
					return false;
	} else {
					alert('Varan har lagts i din varukorg!');
					return true;
	}
}


var gEBI = (document.getElementById) ? true : false;
var da = (document.all) ? true : false;
var lay = (document.layers) ? true : false;

function expand(param) {   
	param.style.display=(param.style.display=="none")?"":"none";   
}

	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 = "basket.php";
	
	}

	function clearBasket() {
		if (confirm('Säkert att du vill tömma varukorgen?')) {
			index = document.cookie.indexOf("TheBasket");
			document.cookie="TheBasket=.";
			self.location = "basket_empty.php";
		}
	}


	function alterError(value) {
		if (value<=0.99) {
			newDollar = '0';
		} else {
			newDollar = parseInt(value);
		}
		newCent = parseInt((value+.0008 - newDollar)* 100);
		if (eval(newCent) <= 9) newCent='0'+newCent;
		newString = newDollar + '.' + newCent;
		return (newString);
	}

        function addItem(newItem, newPrice, newQuantity,  newNumber, newOption, newOption2, newWeight) {
		if (newQuantity >= 51) {
			rc = alert('Du har angett ett felaktigt antal!');
		} else {
                	if (newQuantity >= 1) {
				window.alert(''+newQuantity+' st '+newItem+' har lagts i din varukorg');				
                        	index = document.cookie.indexOf("TheBasket");
                        	countbegin = (document.cookie.indexOf("=", index) + 1);
                        	countend = document.cookie.indexOf(";", index);
                        	if (countend == -1) {
                        		countend = document.cookie.length;
                        	}
				
		     		document.cookie="TheBasket="+document.cookie.substring(countbegin, countend)+"["+newItem+"|"+newPrice+"|"+newNumber+"|"+newOption+"|"+newOption2+"|"+newWeight+"|"+newQuantity+"]";

			}
			top.location = "produkt.php?id="+newNumber;
		}
	}

	function showBasket() {
		index = document.cookie.indexOf("TheBasket");
		countbegin = (document.cookie.indexOf("=", index) + 1);
        	countend = document.cookie.indexOf(";", index);
        	if (countend == -1) {
            		countend = document.cookie.length;
        	}
		fulllist = unescape( document.cookie.substring(countbegin, countend) );
		subtotal = 0;
		document.writeln('<CENTER><FORM NAME="updateform"><center><H1>D I N  &nbsp; V A R U K O R G</H1></center><IMG src="images/linediv2.gif">');
		document.writeln('<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=5>');

document.writeln('<TR><TD><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Antal</b></FONT></TD><TD><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>ArtNr</b></FONT></TD><TD><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Namn</b></FONT></TD><TD><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Val</b></FONT></TD><TD><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Pris</b></FONT></TD><TD><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Delsumma</b></FONT><TD><b><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">Ändra</FONT></b></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 TYPE=TEXT NAME="quant'+itemlist+'" VALUE="'+thequantity+'" SIZE=2 class="field"></TD>');
				document.write('<TD BGCOLOR="#FFFFFF"><A href=produkt.php?id='+thenumber+'><P>'+thenumber+'</P></A></TD>');
				document.write('<TD align=left BGCOLOR="#FFFFFF"><A href=produkt.php?id='+thenumber+'><P>'+theitem+'</P></A></TD>');
				document.write('<TD align=left BGCOLOR="#FFFFFF"><P>'+theoption+' '+theoption2+'</P></TD>');
				document.write('<TD align=left BGCOLOR="#FFFFFF"><P>'+theprice+'</P></TD>');
				document.write('<TD align=left BGCOLOR="#FFFFFF"><P>'+alterError(itemtotal)+'</P></TD>');
				document.write('<TD WIDTH="43" align=right BGCOLOR="#FFFFFF"><A href="javascript:updateItem('+itemlist+',document.updateform.quant'+itemlist+'.value)"><IMG SRC="images/update.gif" WIDTH="15" HEIGHT="21" BORDER="0" ALT="Uppdatera"></a><IMG SRC="images/space.gif" WIDTH="5" HEIGHT="2" ALT=""><A href="javascript:deleteItem('+itemlist+')"><IMG SRC="images/delete.gif" WIDTH="15" HEIGHT="21" BORDER="0" ALT="Radera"></A></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) thenumber = fulllist.substring(itemstart, i);
				if (thisitem==4) theoption = fulllist.substring(itemstart, i);
				if (thisitem==5) theoption2 = fulllist.substring(itemstart, i);
				if (thisitem==6) theweight = fulllist.substring(itemstart, i);
				thisitem++;
				itemstart=i+1;
			}
		}

		document.writeln('<TR><TD colspan=7 align="center"><IMG src="images/linediv2.gif"></TD></TR><TR><TD align=right colspan=5><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b>Totalt inkl moms:</b></FONT></TD><TD align=right BGCOLOR="#FFFFFF"><b>'+alterError(subtotal)+'</b></TD><TD>&nbsp;</TD></TR>');
		document.writeln('</TABLE></CENTER>');
		document.writeln('</FORM>');
	}



	function updateItem(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+'|'+theoption2+'|'+thenumber+'|'+theweight+'|'+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);
				if (thisitem==4) theoption2 = fulllist.substring(itemstart, i);
				if (thisitem==5) thenumber = fulllist.substring(itemstart, i);
				if (thisitem==6) theweight = fulllist.substring(itemstart, i);
				thisitem++;
				itemstart=i+1;
			}
		}
		index = document.cookie.indexOf("TheBasket");
		document.cookie="TheBasket="+newItemList;
		top.location = "view_basket.php";
	

	}

	function deleteItem(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;
		top.location = "view_basket.php";
	
	}

	function clearBasket() {
		if (confirm('Säkert att du vill tömma varukorgen?')) {
		index = document.cookie.indexOf("TheBasket");
		document.cookie="TheBasket=.";
		top.location = "view_basket.php";
		}
	}


	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 = unescape( document.cookie.substring(countbegin, countend) );
		subtotal = 0;
		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;

				
			} 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) thenumber = fulllist.substring(itemstart, i);
				if (thisitem==4) theoption = fulllist.substring(itemstart, i);
				if (thisitem==5) theoption2 = fulllist.substring(itemstart, i);
				if (thisitem==6) theweight = fulllist.substring(itemstart, i);
				thisitem++;
				itemstart=i+1;
			}
		}

		document.write('<FONT SIZE="2" COLOR=#000000 FACE="Verdana, Arial, Helvetica, sans-serif">&nbsp;Total summa: <B>'+alterError(subtotal)+' SEK</B></FONT>');
		
	}
