d = document;
var popup="Op de afbeeldingen ligt het copyright bij Jacobi Drachten";
function noway(go) {
       if (typeof(event) != 'undefined') { if (event.button == 2) { alert(popup); return false; } }
  else if (typeof(go)    != 'undefined') { if (go.which == 3)     { alert(popup); return false; } }
}
if (d.layers) { d.captureEvents(Event.MOUSEDOWN); }
//d.onmousedown  =noway;
//d.oncontextmenu=new Function("return false")

var besteldata = '';
function mandje(nr,prijs,max) {
	if ( typeof(max) == 'undefined' || max.length == 0 ) { max = 999 }
//	d.write('<td align=center>');
//	d.write('<b>'+prijs+' </b><br>');
	valuta_ID = '';
	if ( besteldata.length < 1) { besteldata = getCookie('besteldata'); }
//	d.write('</td>');
	d.write('<table BORDER=0 CELLSPACING=0 CELLPADDING=0 align=right><tr>');
//	d.write('<td nowrap>&nbsp;</td>');
	d.write('<td nowrap>');
	if ( nr.length > 0 ) {
		d.write('<a href="javascript:void(\'\')"');
		d.write(' onmousedown="plus(\'X'+nr+'\',1,'+max+');');
		d.write('timerID=setTimeout(\'timerID2=setInterval(\\\'plus(\\\\\\\'X'+nr+'\\\\\\\',10,'+max+')\\\',300)\',700)"');
		d.write('  onmouseup="if(typeof(timerID)!=\'undefined\'){clearTimeout(timerID)};if(typeof(timerID2)!=\'undefined\'){clearInterval(timerID2)}"');
		d.write(' onMouseOut="if(typeof(timerID)!=\'undefined\'){clearTimeout(timerID)};if(typeof(timerID2)!=\'undefined\'){clearInterval(timerID2)}"');
		d.write('><img src="img/mandje-plus.gif" border=0 width=20 height=17></a>');

		d.write('<a href="javascript:void(\'\')"');
		d.write(' onmousedown="minus(\'X'+nr+'\');');
		d.write('timerID=setTimeout(\'timerID2=setInterval(\\\'minus(\\\\\\\'X'+nr+'\\\\\\\',10)\\\',300)\',700)"');
		d.write('  onmouseup="if(typeof(timerID)!=\'undefined\'){clearTimeout(timerID)};if(typeof(timerID2)!=\'undefined\'){clearInterval(timerID2)}"');
		d.write(' onMouseOut="if(typeof(timerID)!=\'undefined\'){clearTimeout(timerID)};if(typeof(timerID2)!=\'undefined\'){clearInterval(timerID2)}"');
		d.write('><img src="img/mandje-min.gif" border=0 width=20 height=17></a>');

		d.write('<br>');
		d.write('<img src="img/mandje-links.gif" border=0 width=8  height=11><img src="img/-.gif" width=8 height=11 name=\'X'+nr+'#2\'><img src="img/-.gif" width=8 height=11 name=\'X'+nr+'#1\'><img src="img/-.gif" width=8 height=11 name=\'X'+nr+'#0\'><img src="img/mandje-rechts.gif" border=0 width=8 height=11><br>');
		d.write('<img src="img/mandje-onder.gif" border=0 width=38 height=14><br>');
		if ( typeof(besteldata) != 'undefined' ) { update('X'+nr); }
		else                                     { setTimeout("update('X"+nr+"');",2000); }
	} else {
		d.write('<div align="center"><span class="tekstheelklein"><font color="red">');
		d.write('Dit artikel<br>');
		d.write('kan nu nog niet<br>');
		d.write('worden besteld.<br>');
		d.write('</font></span></div>');
	}
	d.write('<td nowrap>&nbsp;</td>');
	d.write('</td></tr></table>');
}
function mandjeK(nr,prijs,max) {
	if ( typeof(max) == 'undefined' || max.length == 0 ) { max = 999 }
//	d.write('<td align=center>');
//	d.write('<b>'+prijs+' </b><br>');
	valuta_ID = '';
	if ( typeof(besteldata) == 'undefined'
	 || besteldata.length < 1) {
		besteldata = getCookie('besteldata');
	}
//	d.write('</td>');
	d.write('<table BORDER=0 CELLSPACING=0 CELLPADDING=0 align=right><tr>');
	d.write('<td nowrap>&nbsp; &nbsp;</td>');
	d.write('<td nowrap valign="center">');
	if ( nr.length > 0 ) {
		d.write('<img src="img/-.gif" width=8 height=11 name=\'X'+nr+'#2\'><img src="img/-.gif" width=8 height=11 name=\'X'+nr+'#1\'><img src="img/-.gif" width=8 height=11 name=\'X'+nr+'#0\'><br>');

		d.write('</td>');
		d.write('<td nowrap valign="center">');
		d.write('<a href="javascript:void(\'\')"');
		d.write(' onmousedown="plus(\'X'+nr+'\',1,'+max+');');
		d.write('timerID=setTimeout(\'timerID2=setInterval(\\\'plus(\\\\\\\'X'+nr+'\\\\\\\',10,'+max+')\\\',300)\',700)"');
		d.write('  onmouseup="if(typeof(timerID)!=\'undefined\'){clearTimeout(timerID)};if(typeof(timerID2)!=\'undefined\'){clearInterval(timerID2)}"');
		d.write(' onMouseOut="if(typeof(timerID)!=\'undefined\'){clearTimeout(timerID)};if(typeof(timerID2)!=\'undefined\'){clearInterval(timerID2)}"');
		d.write('><img src="img/plus.gif" border=0 width=14 height=17></a>');

		d.write('<a href="javascript:void(\'\')"');
		d.write(' onmousedown="minus(\'X'+nr+'\');');
		d.write('   timerID=setTimeout(\'timerID2=setInterval(\\\'minus(\\\\\\\'X'+nr+'\\\\\\\',10)\\\',300)\',700)"');
		d.write(' onmouseup="if(typeof(timerID)!=\'undefined\'){clearTimeout(timerID)};if(typeof(timerID2)!=\'undefined\'){clearInterval(timerID2)}"');
		d.write(' onMouseOut="if(typeof(timerID)!=\'undefined\'){clearTimeout(timerID)};if(typeof(timerID2)!=\'undefined\'){clearInterval(timerID2)}"');
		d.write('><img src="img/min.gif" border=0 width=14 height=17></a>');

		if ( typeof(besteldata) != 'undefined' ) { update('X'+nr); }
		else                                     { setTimeout("update('X"+nr+"');",2000); }
	} else {
		d.write('<div align="center"><span class="tekstheelklein"><font color="red">');
		d.write('Dit artikel<br>');
		d.write('kan nu nog niet<br>');
		d.write('worden besteld.<br>');
		d.write('</font></span></div>');
	}
	d.write('</td></tr></table>');
}

mandje1 = new Image(); mandje1.src = "img/mandje-plus.gif";
mandje2 = new Image(); mandje2.src = "img/mandje-min.gif";
mandje3 = new Image(); mandje3.src = "img/mandje-links.gif";
mandje4 = new Image(); mandje4.src = "img/mandje-rechts.gif";
mandje5 = new Image(); mandje5.src = "img/mandje-onder.gif";
mandje6 = new Image(); mandje6.src = "img/plus.gif";
mandje7 = new Image(); mandje7.src = "img/min.gif";

getal_ = new Image(); getal_.src = "img/-.gif";
getal1 = new Image(); getal1.src = "img/1.gif";
getal2 = new Image(); getal2.src = "img/2.gif";
getal3 = new Image(); getal3.src = "img/3.gif";
getal4 = new Image(); getal4.src = "img/4.gif";
getal5 = new Image(); getal5.src = "img/5.gif";
getal6 = new Image(); getal6.src = "img/6.gif";
getal7 = new Image(); getal7.src = "img/7.gif";
getal8 = new Image(); getal8.src = "img/8.gif";
getal9 = new Image(); getal9.src = "img/9.gif";
getal0 = new Image(); getal0.src = "img/0.gif";

var besteldata;
function leesbestelcookie(){
	besteldata = getCookie("besteldata");
//  document.Bestel.text.value  = besteldata;
//  document.Bestel2.text.value = besteldata;
//	taal_update(taal);
//	valuta_update(valuta);
	document.title = typeof(document.getElementById('mandje'));
	if ( typeof(document.getElementById('mandje')) != 'undefined' ) {
		mandjeupdate(1);
	}
}

function bestelling_leegmaken() {
  if (besteldata.length > 1 ) {
		besteldata = "|";
//    parent.header.document.Bestel.text.value = "|";
//    parent.header.document.Bestel2.text.value = "|";
  	saveCookie("besteldata",besteldata,-1);
  	saveCookie("mandjeinfo",'',-1);
		mandjeupdate(0);
  }
}

function update(prod) {
  aantal  = 0;
  shopper = parseInt(aantal,10);
  if (besteldata.indexOf(prod) != -1 ) {
    positie = besteldata.indexOf('|',besteldata.indexOf(prod));
    aantal  = besteldata.substr(positie+1,3);
    shopper = parseInt(aantal,10);
//		alert(besteldata.indexOf(prod)+'->'+prod+' '+shopper+' '+besteldata)
//    if (shopper > 0 ) { setImage(prod,shopper); }
	}
  setImage(prod,shopper);
}

function plus(prod,veranderaant,max){
	if ( typeof(max) == 'undefined' ) { max=999 }
	if ( typeof(veranderaant) == 'undefined') { veranderaant = 1 }
  var shopper;
  if (besteldata.indexOf(prod) == -1) {
    shopper = veranderaant;
    besteldata  = besteldata + prod + '|001|';
//    document.Bestel2.text.value = document.Bestel.text.value;
  } else { // dus al minimaal 1
    positie = besteldata.indexOf('|',besteldata.indexOf(prod));
    aantal  = besteldata.substr(positie+1,3);
		if ( aantal < max ) {
    	shopper = parseInt(aantal,10) + veranderaant;
			if (shopper > max ) {shopper = max}
    	if (shopper >  999) {shopper = 999}                      // lengte instellen zichtbaar
    	aantal=setlengthcijfer(shopper);
    	deel1 = besteldata.substring(0,positie+1);
    	deel2 = besteldata.substring(positie+4,besteldata.length);
    	besteldata = deel1 + aantal + deel2;
//    	document.Bestel2.text.value = document.Bestel.text.value;
		} else {
    	shopper = parseInt(aantal,10);
		}
  }
  saveCookie("besteldata",besteldata,-1);
//	parent.document.title = besteldata
  setImage(prod,shopper);
	mandjeupdate();
}

function minus(prod,veranderaant){
	if ( typeof(veranderaant) == 'undefined') { veranderaant = 1 }
  var shopper = besteldata;
  if (shopper.indexOf(prod) != -1) { // dus al minimaal 1
    positie = shopper.indexOf('|',shopper.indexOf(prod));
    aantal  = besteldata.substr(positie+1,3);
    shopper = parseInt(aantal,10) - veranderaant;
  	if ( shopper  < 0 ) { shopper = 0 }
    if ( shopper == 0 ) {
      deel1 = besteldata.substring(0,positie - prod.length);
      deel2 = besteldata.substring(positie+5,besteldata.length);
      besteldata = deel1 + deel2;
//      document.Bestel2.text.value = document.Bestel.text.value;
    } else {
      aantal=setlengthcijfer(shopper);
      deel1 = besteldata.substring(0,positie+1);
      deel2 = besteldata.substring(positie+4,besteldata.length);
      besteldata = deel1 + aantal + deel2;
//      document.Bestel2.text.value = document.Bestel.text.value;
    }
    saveCookie("besteldata",besteldata,-1);
//		parent.document.title = besteldata
    setImage(prod,shopper);
		mandjeupdate();
  }
}

function setImage(ID, aantal){
  aantal =setlength(aantal);
  times  =aantal.length;
  for(x=0, y=times-1; x < times; x++, y--) {
    imgID=ID + "#" + x.toString();
    if (typeof(document.images[imgID]) != 'undefined' ) {
      document.images[imgID].src="img/" + aantal.charAt(y) + ".gif";
    }
  }
}

function setlength(getl){
  getl = getl.toString();
  for(i=getl.length; i<3; i++){ getl = "-"+getl; }          // lengte instellen zichtbaar
  return getl;
}

function setlengthcijfer(getl){
  getl = getl.toString();
  for(i=getl.length; i<3; i++){ getl = "0"+getl; }
  return getl;
}

//teller = 0;
var mandje_timeout;
var basis_hoesnel = 1500;
function mandjeupdate(hoesnel){ // 0 = from cookie..
	if (typeof(hoesnel) == 'undefined'      ) { hoesnel = basis_hoesnel }
//	top.document.title= "U "+hoesnel+' '+top.document.title;
	if (mandje_timeout && hoesnel > 0) window.clearTimeout(mandje_timeout);// teller++;parent.document.title=teller;
	mandjeinfo = getCookie("mandjeinfo");
	if ( besteldata.length < 1) { besteldata = getCookie('besteldata'); }
	if( (hoesnel > 0 && (Math.random() > 0.9 || hoesnel == basis_hoesnel) )
	 || (mandjeinfo.length == 0 && besteldata.length > 0) ) {
		mandje_timeout = setTimeout("ajaxpage('bestellen.cgi?stap=prijs&bestelling='+besteldata, 'mandje', 'mandje')",hoesnel);
	} else {
		document.getElementById('mandje').innerHTML=getCookie("mandjeinfo");
	}
}
function mandjetxt(content){
	test_content = content.replace(/[^0-9]/g,"");
	if ( test_content > 0 ) {
		bestelgroepen = besteldata.split("|");
		aantal = 0;
		start  = 0;
		if (      bestelgroepen[0].indexOf('X') == 0 ) { start = 1 }
		else if ( bestelgroepen[1].indexOf('X') == 0 ) { start = 2 }
		else {
			alert(besteldata+"\n0 "+bestelgroepen[0]+"\n1 "+bestelgroepen[1]+"\n2 "+bestelgroepen[2])
		}
//		alert(+"\n0 "+besteldata+"\n0 "+bestelgroepen[0]+"\n1 "+bestelgroepen[1]+"\n2 "+bestelgroepen[2])
		for ( i=start;i<bestelgroepen.length;i+=2 ) {
			aantal+= eval(bestelgroepen[i].replace(/^0+/,""));
//top.document.title = aantal+' ('+bestelgroepen[i].replace(/^0+/,"")+') '+top.document.title;
		}
		if ( aantal > 1 ) { aantal+= ' producten' }
		else              { aantal+= ' product' }
		content = aantal+', &euro; '+content+'';
	} else {
		content = '';
	}
  saveCookie("mandjeinfo",content,0.33);
	return content;
}
function KS_nu_txt(content){
	test_content = content.replace(/[^0-9]/g,"");
 	content = test_content+' bezoekers online';
	return content;
}
//setTimeout( "ajaxpage('nu.cgi?'+new Date().getTime(), 'KS_nu', 'KS_nu');",1000);
//setInterval("ajaxpage('nu.cgi?'+new Date().getTime(), 'KS_nu', 'KS_nu');",120*1000);
//setInterval("document.title=besteldata+' '+getCookie('besteldata')",1000);

