document.write("<div name=shoppop id=shoppop class=ShopPop></div>");
document.write("<div name=shopshadow id=shopshadow class=ShopShadow></div>");
var ids=[];

function ReCalcFunction(obj,id,url){
	var a=new Array();
	
	if(!obj)obj=document.forms["CheckOutForm"];
	else obj=obj.form;

	
	
	for(var i=0;i<obj.length;i++){
		var s=new String(obj[i].name);
		if(s.indexOf("aantal")==0)a[a.length]=obj[i].name+"="+obj[i].value;
  	}

  	if(a.length==0)alert("Leeg mandje ?");
  	else
  		window.location=url+((url.indexOf("?")<0)?"?":"&")+a.join("&");

}

function BuyDirect(){
	if(document.getElementById('CodeDirect').value=='')alert("Ongeldige artikelcode!!");
	else window.location='cart.php?watte=BUYDIRECT&CD='+document.getElementById('CodeDirect').value;
	return false;
}

function DrawCart(aantal){	
  if(document.getElementById('Cart')){
    document.getElementById('Cart').innerHTML="<img align=texttop src=icons/cart.png border=0> "+aantal+" artikel(en).";
    if(aantal>0)document.getElementById('Cart').innerHTML+="<br><img src=pics/trans.gif width=20 height=10>Klik hier voor een overzicht";
  }
}

function HideShoppop(){
  layerShow('shopshadow',false);
  layerShow("shoppop",false);
}

function ShowShoppop(s){
	
  layerCenter("shoppop");
  layerMoveTo("shopshadow",layerLeft("shoppop")+5,layerTop("shoppop")+5);
  document.getElementById('shoppop').innerHTML=s;
  layerShow('shopshadow',true);
  layerShow("shoppop",true);
}

function _Buy(s){
  s=eval(s);
	
  DrawCart(s[0]);  
  
  if((s.length>4)&&(s[3]>1)){
	  AWindow("Kies","productproduct.php?layer=true&popup=true&key="+s[5]+"&ID="+s[4]+"&n="+s[1]+"&vervolg="+escape(s[2]));

  }	  	
  else ShowShoppop(s[2]);
  layerShow('cart',true);
}

function RealBack(){
	//for(var i=0;i<history.length;i++)alert(history[i]);
	history.go(-1)
}

function Perform(url,fname){
  var D=new Date();
  if(window.ActiveXObject)var http = new ActiveXObject("Microsoft.XMLHTTP");
  if(window.XMLHttpRequest)var http = new XMLHttpRequest();
  url+="&t="+eval(D.getTime());

  if(fname!="") http.onreadystatechange = function () {
	if(http.readyState==4){
//			alert(url+"    \n\n "+http.responseText);
		//alert(fname+"(http.responseText)");
		//alert(http.responseText);
		
		if(fname=="TWindow")eval(fname+"(http.responseText)");
		else if(fname!="")eval(fname+"(http.responseText)");
	}	
  }	
  http.open("GET",url,true);
  http.send(null);
}

function Coupon(){
	//var s=prompt("aas","s");
		
	AWindow("Actiecode ingeven","coupon.php?layer=true&popup=true");	
	
}

function ABuy(id,aantal){
  Perform("cart.php?aantal=1&watte=ABUY&ID="+id,"_Buy");
}

function Buy(id,aantal){
  if(isNaN(aantal)||(aantal<=0))alert("Check aantal!");
  else Perform("cart.php?aantal="+aantal+"&watte=BUY&ID="+id,"_Buy");
}

function _QuickBuy(s){
  s=eval(s);

	  if((s.length>4)&&(s[3]>1)){		  
		  AWindow("Kies","productproduct.php?vervolg=RELOAD&layer=true&popup=true&key="+s[5]+"&ID="+s[4]+"&n="+s[1]);
		  return ;
	  }	  

  window.location=QueryReplace(window.location,"watte","");
}

function QuickBuy(obj,obj2,obj3){
	//alert("cart.php?aantal="+obj.form.Aantal.value+"&watte=BUY&ID="+obj2[0],"_QuickBuy");
	Perform("cart.php?aantal="+obj.form.Aantal.value+"&watte=BUY&ID="+obj2[0],"_QuickBuy");
}

function ClearCart(){
  Perform("cart.php?watte=BUY&ID="+id,"DrawCart(0);alert");
}

function ChangeAantal(id,aantal){
  if(window.ActiveXObject)var http = new ActiveXObject("Microsoft.XMLHTTP");
  if(window.XMLHttpRequest)var http = new XMLHttpRequest();
  var url="cart.php?watte=CHANGE&ID="+id+"&aantal="+aantal;
	
  //http.onreadystatechange = function () {if(http.readyState==4)alert(http.responseText);  }	
  http.open("GET",url,true);
  http.send(null);
}

function DeleteItem(id){
  if(window.ActiveXObject)var http = new ActiveXObject("Microsoft.XMLHTTP");
  if(window.XMLHttpRequest)var http = new XMLHttpRequest();
  var url="cart.php?watte=DELETE&ID="+id;
	
  //http.onreadystatechange = function () {if(http.readyState==4)alert(http.responseText);  }	
  http.open("GET",url,true);
  http.send(null);
}


function PopPlaatje(id) {
  	
  var url=(id==0)?QueryReplace(document.plaatje.src,"limit",""):"getimage.php?limit=&id="+id;
	
  var p=window.open(url,'','left=50,top=50,resizable=yes,directories=no,titlebar=0,titlebar=no,scrollbars=yes,modal=yes,toolbar=no,status=no,menubar=no');  
/*  
  var s="<html><head><title>Detail</title></head><body marginwidth=0 marginheight=0 leftmargin=0 topmargin=0 rightmargin=0 bottommargin=0><img name=plaatje onClick='window.close();' src='"+url+"'></body></html>";
 
  var p=window.open('','','left='+(screen.width/2)+',top='+(screen.height/2)+',width=100,height=100,resizable=yes,directories=no,titlebar=0,titlebar=no,scrollbars=yes,modal=yes,toolbar=no,status=no,menubar=no');
  p.document.write(s);
  p.document.close();
  var w=p.document.plaatje.width+10,h=p.document.plaatje.height+75;
  p.moveTo((screen.width-w)/2,(screen.height-h)/2);
  p.resizeTo(w,h);  
  p.focus();
*/  
}


var layer1,layer2,img;
var pTimer=null;
var ie=navigator.userAgent.toLowerCase().indexOf("msie")>=0;

function Step(steps,i){
	if(pTimer)clearTimeout(pTimer);
	

	
  var dx=(img.width+((ie)?0:10))/steps;
  var dy=(img.height+((ie)?0:10))/steps;
	
	//alert(steps+' '+i+' '+dx+' '+dy);
  layer2.style.width=dx*i;
  layer2.style.height=dy*i;
  	
  	
  	
  layer2.style.left=(layer1.clientWidth-(dx*i))/2;
  layer2.style.top=(layer1.clientHeight-(dy*i))/2;
	
  if(i<=steps)pTimer=setTimeout("Step("+steps+","+(i+1)+")",1);
}
/*

function ShowBijlage(id){
  var url="popbijlage.php?"+id;
  
  var W=400;
  var H=300;
  var L=(screen.width)?(screen.width-W)/2:0;
  var T=(screen.height)?(screen.height-H)/2:0;
  
  
  var s="resizable=yes,directories=no,scrollbars=yes,toolbar=no,status=no,menubar=no,width="+W+",height="+H+",left="+L+",top="+T;
  
  

    var oNewDoc = window.open(url,'pop',s);
    //oNewDoc.document.open();
    //oNewDoc.document.write("<html><head><title>Bijlage</title></head><body><img src='"+url+"'></body></html>");
    //oNewDoc.document.close();
}	
*/
function _ShowPlaatje(url,animate,hidebutton){
  
  layer1=document.createElement('div');

  layer1.style.position = 'absolute';
  layer1.style.left = 0;
  layer1.style.top = 0;    
  layer1.style.width = "100%";
  layer1.style.height = "100%";
  layer1.style.zIndex=100;
  layer1.style.backgroundColor="black";
  layer1.style.filter = 'alpha(opacity=50)';
  
  
  
  layer1.style.opacity=0.5;
  layer1.style["-moz-opacity"]=0.5;
  
  document.body.appendChild(layer1);     

  
  
  
  
  layer2=document.createElement('div');
  layer2.style.position = 'absolute';
  
  
  
  layer2.style.left = 0;
  layer2.style.top = 0;    
  layer2.style.width=150;
  layer2.style.height=150;
  
  layer2.style.overflow="hidden";
  layer2.style.zIndex=110;  
  layer2.style.padding="10";
  layer2.style.backgroundColor="white";
    
  layer2.innerHTML="<img id=theimage lowsrc=pics/img50.gif style=\"margin:5;filter:'alpha(opacity=100)';\" src='"+url+"'>";
  
  if(!hidebutton)layer2.innerHTML=layer2.innerHTML+"<br><img src=pics/closelabel.gif style='cursor:pointer;left:0;'>";

  
  document.body.appendChild(layer2);     
  
  
//  layer2.style.left=(layer1.clientWidth-layer2.document.images.theimage.width)/2;
//  layer2.style.top=(layer1.clientHeight-layer2.document.images.theimage.height)/2;
	
  
  img=layer2.document.images.theimage;
  if(animate)img.onload=function(){Step(10,0);}
  else img.onload=function(){
  	layer2.style.width=layer2.document.images.theimage.width;
    layer2.style.height=layer2.document.images.theimage.height;
    layer2.style.left=(layer1.clientWidth-layer2.document.images.theimage.width)/2;
    layer2.style.top=(layer1.clientHeight-layer2.document.images.theimage.height)/2;
    
  }
  
  layer2.onmousedown=layer1.onmousedown=function(){
  	 document.body.removeChild(layer1);
  	 document.body.removeChild(layer2);
  }
}

function ShowPlaatje(id){
	

	
}


function CallShop(Shop,url){
	if(window.XMLHttpRequest)var http = new XMLHttpRequest();
	var start=(new Date()).getTime();
	http.onreadystatechange = function () {
	  if(http.readyState==4){
	  	 document.getElementById(Shop).innerHTML=http.responseText+(((new Date()).getTime()-start)/1000)+"s";
	  	 //debug(window);
	  	window.scrollTo(0,document.getElementById(Shop).top);
	  }
	}
	http.open("GET",URLEncrypt(url),true);
	http.send(null);
}

function DrawShop(Shop,page,order){
	CallShop(Shop,QueryReplace(QueryReplace(QueryReplace("shop.php","p",page),"o",order),"guid",Shop));
	return false;
}

function SetShopModus(Shop,modus,page){
	CallShop(Shop,QueryReplace(QueryReplace(QueryReplace("shop.php","m",modus),"guid",Shop),"p",page));
	return false;
}

function CheckProductAantal(obj,aantal,maxaantal,eenheid,simple){
	var val=parseInt(obj.value);
	if((isNaN(val)||(val==0))&&(simple))obj.value="";
	else if(((aantal>0)&&(aantal>val))||((maxaantal>0)&&(val>maxaantal))){
			
		if(val<aantal){
			obj.value=aantal;
			alert("Min. bestelaantal is "+aantal);
		}
		else {
			obj.value=maxaantal;
			alert("Max. bestelaantal is "+maxaantal);
		}
		return false;
	}
	else {
		var r=val/eenheid;
		var f=r-Math.floor(r);
		
		if((f!=0)&&(f!=eenheid)){
			obj.value=Math.ceil(r)*eenheid;
			alert("Aantal moet een veelvoud van "+eenheid+" zijn.");
			return false;
		}	
	}
	return true;
}

function SnelBestellen(form){
	var ids=Array();
	for(var j in form){
			var s=new String(j);
			if((s.substr(0,6)=="Aantal")&&(form[j].value!="")){
				ids[ids.length]=s.substr(6)+","+form[j].value;
			}
	}
	
	
	if(ids.length>0)Perform("cart.php?watte=SNELBUY&ID="+ids.join("|")+"&opmerkingen="+escape(form.Opmerkingen.value),"_Buy");
	else alert("Geen artikelen geselecteerd");
}
