// initieren van de variabelen:
TextColor1 = "#ffffff";
BackColor1 = "#003466";
BackColor2 = "#fff000";
Text1 = "Winkelwagen legen, zeker weten?";
Text2 = "Verwijderen";
hrij=new Array();
arij=new Array();
trij=new Array();
rrij=new Array();
var h = "1"; // aantal boeken
var a = ""; // naam van het boek
var t = ""; // prijs per boek
var r = ""; // porto kosten per boek
var maxport = "0,00"
var verloop = new Date(); verloop.setTime(verloop.getTime() + 3600000);  

// de functies:
function order(a,p,porto) 
{ 
	if (DD(a)) 
	{ if (Cl("h")) 
		h=Cl("h")+";1"; 
	  else h=1+";"; 
	  if (Cl("a")) a=Cl("a")+";"+a; 
	  	else a=a+";"; 
	  	if (Cl("r")) r=Cl("r")+";"+porto;
	  		else r=porto+";";
	  		if (Cl("t")) t=Cl("t")+";"+p; 
	  			else t=p+";"; C2("h", h, verloop); C2("a", a, verloop); C2("t", t, verloop); C2("r", r, verloop);	  		  
	} winkelwagen=window.open("winkelwagen.html","winkelwagen","width=550,height=620,scrollbars=1,toolbar=0,directories=0,resizable=0,dependent=0,titlebar=0,personalbar=0,menubar=0,status=0,location=0")
}

function winkelhelp()
{
winkelwagen=window.open("winkelhelp.html","winkelhelp","width=550,height=620,scrollbars=1,toolbar=0,directories=0,resizable=0,dependent=0,titlebar=0,personalbar=0,menubar=0,status=0,location=0")
}

function DD(n) 
	{ KR(); for(var f = 0; f < arij.length; f++) 
		if (n == arij[f]) return false; return true 
	}

function KR() 
{ 	
	if (Cl("h"))
		h=Cl("h");
	if (Cl("a"))
		a=Cl("a");
	if (Cl("t"))
		t=Cl("t");
	if (Cl("r")) 
		r=Cl("r");		
		hrij = h.split(";");
		arij = a.split(";");
		rrij = r.split(";");
		trij = t.split(";");
}	
	
function RK() 
{ 
	C3("h");
	C3("a");
	C3("t");
	C3("r");
	h=hrij.join(";");
	a=arij.join(";");
	t=trij.join(";");
	r=rrij.join(";");
	C2("h", h, verloop);
	C2("a", a, verloop);
	C2("r", r, verloop);
	C2("t", t, verloop);
}

function Dl(n)
{ 
	KR();
	if (window.confirm(Text2 + "\n\n" + arij[n] + "?    \n\n"))
	{
		hrij[n] = 0;
		arij[n] = 0;
		trij[n] = 0;
		rrij[n] = 0;
		RK();
		document.location.replace("winkelwagen.html")
	}
}

function X(n,n2)
{ 
	KR(); 
	dpl = eval(trij[n]); //totaal prijs boeken
	dp2 = eval(hrij[n]); //aantal boeken
	dp3 = dpl/dp2; // prijs per boek
	dp4 = eval(rrij[n]); // totaal porto kosten
	dp5 = dp4/dp2; // porto kosten per boek
	if (n2 > 0) hrij[n]=n2; if (hrij[n] > 0)
	{ 
		trij[n] = dp3 * hrij[n]; 
		rrij[n] = dp5 * hrij[n];
		RK(); document.location.replace("winkelwagen.html") 
	}; if (n2 == 0) Dl(n) // indien aantal nul verwijder boek uit winkelwagen
}

function DlAlle()
{ 
	KR(); 
	if (window.confirm("   " + Text1 + "  \n"))
	{ 
		C3("h");
		C3("a");
		C3("t");
		C3("r");
		for(var f = 0; f < arij.length; f++) 
		{ 
			hrij[f] = 0;
			arij[f] = 0;
			trij[f] = 0;
			rrij[f] = 0;
		}; 
		window.opener.document.location.reload() ; window.close() 
	}
}

function D2Alle()
{ 
	KR(); 
	C3("h");
	C3("a");
	C3("t");
	C3("r");
	for(var f = 0; f < arij.length; f++) 
	{ 
		hrij[f] = 0;
		arij[f] = 0;
		trij[f] = 0;
		rrij[f] = 0;
	};
	window.close() 
}

function K(n) 
{ 
	cent=n*100;
	cent=Math.round(cent);
	CS= "" + cent;
	len = CS.length;
	return CS.substring(0, len - 2) + "," + CS.substring(len -2,len);
}

function FRMl() 
{ 
	KR();
	SW= "";
	FRM2 = "";
	ST = 0;
	PT = 0;
	for(var f = 0;
	f < arij.length; f++) 
	{ if (arij[f] != "" && arij[f] != "0")
		{ if (BackColor2 == "#FFFFFF") 
			{ 
				BackColor2="#EEEEEE"
			} else 
			{
				BackColor2="#FFFFFF"
			}; SW = SW + "<tr><td align='right' valign='top' bgcolor='" + BackColor2 + "'><font face='Arial,Helvetica' size=2 color='#8b0000'>" + hrij[f] + "&nbsp;x&nbsp;</td><td width=530 valign='top' bgcolor='" + BackColor2 + "'><font face='Arial,Helvetica' size=2 color='#8b0000'>" + arij[f] + "</td><td valign='bottom' align='right' bgcolor='" + BackColor2 + "'><font face='Arial,Helvetica' size=2 color='#8b0000'>" + K(trij[f]) + "</td></tr>"; 
			   FRM2 = "\n" + FRM2 + hrij[f] + " x " + arij[f] + " (" + K(trij[f]) + ")\n"; ST = ST + eval(trij[f]); PT = PT + eval(rrij[f])
		}
	}; if (PT > maxport){ PT = maxport
}
	; ST=ST + eval(PT); schrijfEUR = ST; ST = K(ST); PT = K(PT); PT = maxport;

	SW = SW + "<tr><td colspan=3 align='right' bgcolor='#fff000'><font face='Arial,Helvetica' size=2 color='#8b0000'>Porto  " + PT +"</td></tr>"; FRM2 = "\n" + FRM2 +"Porto  (" + PT + ")\n" 

	}

function Cl(n)
{ 
	var cn = n + "=";
	var dc = document.cookie;
	if (dc.length > 0)
	{ begin = dc.indexOf(cn);
		if (begin != -1)
		{ begin += cn.length;
			end = dc.indexOf(";", begin);
			if (end == -1) end = dc.length; return unescape(dc.substring(begin, end)) 
		}
	}; return null 
}

function C2(n,v,e) 
{ 
	document.cookie = n + "=" + escape(v) + ((e == null) ? "" : "; path=/ ; expires=" + e.toGMTString())
}

function C3(n) 
{ 
	if (Cl(n)) document.cookie = n + "=" + "; path=/ ; expires=Thu, 01-Jan-70 00:00:01 GMT" 
}

function Schrijf(){
	KR();
	totaal = 0;
	totaalport = 0;
	for(var f = 0; f < arij.length; f++) { 
		if (trij[f] != "") {totaal = eval(totaal) + eval(trij[f]);}
		if (rrij[f] != "") {totaalport = eval(totaalport) + eval(rrij[f]);}
		if (totaalport > eval(maxport)) {totaalport = eval(maxport);}
		
	}
	totaal = totaal + eval(totaalport)
	document.writeln('<style>');
	document.writeln('<!--');
	document.writeln('a:link {text-decoration: none;}');
	document.writeln('a:visited {text-decoration: none;}');
	document.writeln('a:hover {background-color: #eeeeee; text-decoration: none; color: #000000;}');
	document.writeln('-->');
	document.writeln('</style>');

	document.writeln('<font size=4 face="Arial,Helvetica" color="#000000">');
	document.writeln('<b>Winkelwagen</b><p>');
	document.writeln('</font>');

	document.writeln('<table width=500 border=0 cellspacing=0 cellpadding=2>');
	document.writeln('<tr><td colspan=2 bgcolor="'+BackColor1+'">');
	document.writeln('<font size=2 face="Arial,Helvetica" color="'+TextColor1+'">');
	document.writeln('&nbsp;<b>Aantal</b></font></td>');
	document.writeln('<td width=500 bgcolor="'+BackColor1+'">');
	document.writeln('<font size=2 face="Arial,Helvetica" color="'+TextColor1+'">');
	document.writeln('<b>Titel boek</b></td><td align="right" bgcolor="'+BackColor1+'">');
	document.writeln('<font size=2 face="Arial,Helvetica" color="'+TextColor1+'"><b>Prijs</b>&nbsp;</td></tr>');

	for(var f = 0; f < arij.length; f++) {
		if (arij[f] != ""  && arij[f] != "0") {

	if (BackColor2 == "#FFFFFF") { BackColor2="#EEEEEE"}
			else {BackColor2="#FFFFFF"}

			document.writeln('<form onSubmit="X('+f+',textaantal.value)" >');
			document.writeln('<tr><td valign=top bgColor='+BackColor2+'>');
			document.writeln('<input onChange="X('+f+',this.value)" type="text" name="textaantal" size=2 value="'+hrij[f]+'">');
			document.writeln('</td>');
			document.writeln('<td valign="center" align=left bgColor='+BackColor2+'>');
			document.writeln('<a href="javascript:Dl('+f+')">');
			document.writeln('<img src="images/../../afbeeldingen/vuilnisbak.gif" width=14 height=17 border=0 alt="Verwijder boek"></a></td>');
			document.writeln('<td bgColor="'+BackColor2+'">');
			document.writeln('<font face="Arial,Helvetica" size=2 color="#000000">'+arij[f]+'</font></td>');
			document.writeln('<td valign=bottom align=right bgColor="'+BackColor2+'">');
			document.writeln('<font face="Arial,Helvetica" size=1  color="#000000">'+K(trij[f])+'</font></td></tr>');
			document.writeln('</form>');

		}
	}

	if (totaal == 0) { 
	document.writeln('<tr><td valign=top align=center bgColor='+BackColor2+' colspan=4>');
	document.writeln('<font face="Arial,Helvetica" size=2 color="#000000">');
	document.writeln('Winkelwagen is leeg</td>');
	document.writeln('</font></td></tr>');
	}
	
	if (totaalport != 0)  document.write('<tr>') 
	if (totaalport != 0)  document.write('<td colspan="4" align="right" bgcolor="#FFF000">') 
	if (totaalport != 0)  document.write('<font size=2 face="Arial,Helvetica" color="#000000">&nbsp;')  
	if (totaalport != 0)  document.write('<b>Porto&nbsp;&nbsp;') 
	if (totaalport != 0)  document.write(K(totaalport))
	document.write('<tr>');
	document.write('<td colspan="4" align="right" bgcolor="'+BackColor1+'">');
	document.write('<font size=2 face="Arial,Helvetica" color="'+TextColor1+'">&nbsp;');
	if (totaal != 0)  document.write('<b>Totaal&nbsp;&nbsp;')
	if (totaal != 0)  document.write(K(totaal))
	document.write('</b></td></tr>');
	document.write('</table><p>');

	document.write('[<a href="winkelhulp.html">');
	document.write('<font size=2 face="Arial,Helvetica" color="#000000">');
	document.write('Winkelhulp</font></a>]');

	if (totaal != 0) {
		document.write('&nbsp;&nbsp;[<a href="javascript:DlAlle()">');
		document.write('<font size=2 face="Arial,Helvetica" color="#000000">');
		document.write('Leeg winkelwagen</font></a>]');

		document.write('&nbsp;&nbsp;[<a href="kassa.html">');
		document.write('<font size=2 face="Arial,Helvetica" color="#000000">');
		document.write('Naar de kassa</font></a>]');
	}

	document.write('<br><br>')
	document.write('</body></html>')
}

function sluit(){ window.close()}
