// JavaScript Document
  function readImgDetails(id,w){ 
    if (document.xmlHttp) {
       try {
		 if (document.xmlHttp.readyState==0||document.xmlHttp.readyState==4){
		   document.xmlHttp.open("GET","/art/read_img_details.php?id="+id+'&w='+w,true)
	       document.xmlHttp.onreadystatechange=handleRSCIMG
	       document.xmlHttp.send(null);
		   }
		   else setTimeout("readImgDetails("+id+","+w+")",500)
	  }
   catch (e) {}
  }
  else alert('browser does not allow http-request')
}
function handleRSCIMG(){ 
  if (document.xmlHttp.readyState==4) {
    if (document.xmlHttp.status==200) {
	  try { 
        var xmlResponse=document.xmlHttp.responseXML
        var xmlDoc=xmlResponse.documentElement
		var xmlTerug=xmlDoc.firstChild.data
		if (document.spanImgL) document.spanImgL.innerHTML=xmlTerug
	  }
	  catch(e) { }
	 }
   }
}
  function addToFav(id){  
    if (document.xmlHttp) {
       try {
		 if (document.xmlHttp.readyState==0||document.xmlHttp.readyState==4){
		   document.xmlHttp.open("GET","/art/add_to_fav.php?id="+id,true)
	       document.xmlHttp.onreadystatechange=handleRSC
	       document.xmlHttp.send(null);
		   }
		   else setTimeout("addToFav("+id+")",500)
	  }
   catch (e) {}
  }
  else alert('browser does not allow http-request')
}
  function offFav(id){ document.changeFav=true
    var d=document.getElementById('outerbox_'+id)
	if (d) {  // tenminste een van onderstaande verdwijntruc zal toch wel werken!
	  d.style.display='none';
	  d.outerHTML='' 
	  }
    if (document.xmlHttp) {
       try {
		 if (document.xmlHttp.readyState==0||document.xmlHttp.readyState==4){
		   document.xmlHttp.open("GET","/art/off_fav.php?id="+id,true)
	       document.xmlHttp.onreadystatechange=handleRSC
	       document.xmlHttp.send(null);
		   }
		   else setTimeout("offFav("+id+")",500)
	  }
   catch (e) {}
  }
  else alert('browser does not allow http-request')
}

function handleRSC() { 
  if (document.xmlHttp.readyState==4) {
    if (document.xmlHttp.status==200) {
	  try { handleServerResponse(); }
	  catch(e) { }
	 }
   }
}
function offCart(id){
    if (document.xmlHttp) {
       try {
		 if (document.xmlHttp.readyState==0||document.xmlHttp.readyState==4){
  	       document.xmlHttp.open("GET","/art/off_cart.php?id="+id,true)
	       document.xmlHttp.send(null)
		   }
		   else setTimeout("offCart("+id+")",500)
	  }
   catch (e) {}
  }
  else alert('browser does not allow http-request')
}
function addToCart(id,a,w,h,m){
    if (document.cookie=='') { alert('Deze browser-sessie staat het gebruik van cookies niet toe.\r\n\r\nAls gevolg is het niet mogelijk een winkelwagen bij te houden'); return }
    if (document.xmlHttp) {
       try {
		 if (document.xmlHttp.readyState==0||document.xmlHttp.readyState==4){
		   var opdracht="/art/add_to_cart.php?id="+id+'&aantal='+a+'&hoogte='+h+'&breedte='+w+'&materiaal='+m
  	       document.xmlHttp.open("GET",opdracht,true)
	       document.xmlHttp.onreadystatechange=handleRSC2
	       document.xmlHttp.send(null)
		   }
		   else setTimeout("addToCart("+id+","+a+","+w+","+h+","+m+")",500)
	  }
   catch (e) {}
  }
  else alert('browser does not allow http-request')
}
function handleRSC2() {   
  if (document.xmlHttp.readyState==4) {
    if (document.xmlHttp.status==200) {
	  try { handleServerResponse2(); }
	  catch(e) { }
	 }
   }
}

function handleServerResponse(){ 
  xmlResponse=document.xmlHttp.responseXML
  xmlDoc=xmlResponse.documentElement
  xmlTerug=xmlDoc.firstChild.data.split('|')
  if (xmlTerug[0]&&xmlTerug[0]!='ok') {
     if (xmlTerug[1]) xmlTerug[1]=xmlTerug[1].replace(/---/g,'\r\n')
     alert(xmlTerug[1])
	 }
  else if (xmlTerug[2]) showSuccess(xmlTerug[1],15)
  else alert(xmlTerug[1])
  if (document.changeFav) location.reload(true)

}
function handleServerResponse2(){ 
  xmlResponse=document.xmlHttp.responseXML; 
  xmlDoc=xmlResponse.documentElement
  xmlTerug=xmlDoc.firstChild.data.split('|') ; 
  if (xmlTerug[0]&&xmlTerug[0]!='ok') {
     if (xmlTerug[1]) xmlTerug[1]=xmlTerug[1].replace(/---/g,'\r\n')
     alert(xmlTerug[1])
	 }
  else if (xmlTerug[2])  updateCart(xmlTerug[3]); // showSuccess(xmlTerug[1],15) 
  else alert('676767'+xmlTerug[1])
}
function updateCart(n){ 
 var b=document.getElementById('cart_number')
 var a=document.getElementById('afrekenButton')
 var mv=document.getElementById('cart_MV')
 var uheeft=document.getElementById('uheeft')
if (n>0&&b) { b.innerHTML=n; if (n>9) uheeft.innerHTML=''; }
 else if (b) b.innerHTML='geen'
 if (n>0&&a) a.style.display='inline'
 if (n==1&&mv) mv.style.display='none'
 else if (mv) mv.style.display='inline'
}
function showSuccess(id,g){
   if (g<0) g=0
   var d=document.getElementById(id); if (!d) { alert(id); return }
   var hD="0123456789ABCDEF";
   var h = hD.substr(g,1), kleur='#0000'+h+h
   d.style.fontWeight='bold'
   d.style.color=kleur
   if (g>0) setTimeout("showSuccess('"+id+"',"+(g-1)+")",30) 
   else d.style.fontWeight='normal'
}

function hideIMG(){
   document.onmousemove=''
   var d=gettrailobj()
   if (d){
     d.style.display='none'
     d.style.left='-400px'
     document.hideSTO=false
    }
}
function imgOnload() { 
   document.imgL.width=document.curW
   document.imgL.height=document.curH
   if (document.fotoId>0) readImgDetails(document.fotoId,document.curW)
   else document.spanImgL.innerHTML=''
 }
function toonIMG(w,h,img,id) { if (w==0) return
//    img_src='http://fotografie.nl/inc/imageViewe.php?i='+id
    img_src='http://fotografie.nl/'+img
//	prompt(img_src,img_src )
    if (w>500) { h=Math.round(500/w*h); w=500; }
    if (h>400) { w=Math.round(400/h*w); h=400; }
    document.curW=w; document.curH=h; document.fotoId=id
    var div=gettrailobj()
    if  (!div) return
    document.spanImgL=div.getElementsByTagName('span')[0]
    if (!document.spanImgL) return
    document.imgL=div.getElementsByTagName('img')[0]
    if (document.imgL.src!=img_src){
	   document.imgL.src=img_src;
       document.imgL.width=1
       document.imgL.height=1
       document.spanImgL.innerHTML='<span style="background:#900;font-size:11px; font-family:Arial; color:#fff">loading&nbsp;image,&nbsp;please&nbsp;wait...</span><br>'
	   }
    document.imgL.onload=imgOnload
  	document.onmousemove=followmouse;
}
function followmouse(e){
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight)+100 : Math.max(document.body.offsetHeight, window.innerHeight)
    docheight=getDocHeight()
    var dx=30
    var dy=-35
	if (typeof (e) != "undefined"){
			xcoord = e.pageX +dx; 
			if (xcoord+document.curW+20>docwidth) xcoord=e.pageX-document.curW-dx
			ycoord = e.pageY +dy
			if (ycoord+document.curH>docheight) ycoord=e.pageY-document.curH-dy
		}
	else if (typeof (window.event) != "undefined"){
			xcoord = event.clientX +dx;
            if (xcoord+document.curW+20>docwidth) xcoord = event.clientX-document.curW -dx
			ycoord = event.clientY+truebody().scrollTop +dy;
            if (ycoord+document.curH+40-truebody().scrollTop>docheight) ycoord=docheight-document.curH-40+truebody().scrollTop
			//ycoord = event.clientY+truebody().scrollTop-document.curH -dy
	}
//	var docwidth=document.all? truebody().clientWidth : pageXOffset+window.innerWidth-15
var xc0=xcoord
//    if (xcoord+document.curW>990) xcoord=xcoord-document.curW
//    if (ycoord+document.curH+200>docheight) ycoord=ycoord-document.curH-40

	var div=gettrailobj()
	div.style.left=xcoord+"px"
	div.style.top=ycoord+"px"
    div.style.display='block';
//	div.getElementsByTagName('span')[0].innerHTML='x: '+xcoord+', w: '+document.curW+', total w: '+docwidth+'<br>y: '+ycoord+', h: '+document.curH+', total h: '+docheight
}
function gettrailobj(){
if (document.getElementById)
return document.getElementById("BIGIMG")
else if (document.all)
return document.all.BIGIMG
}

function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function getDocHeight(){
	return (document.all? Math.min(getTrueBody().scrollHeight, getTrueBody().clientHeight) : Math.min(window.innerHeight));
}

function getTrueBody(){
	return ( (!window.opera && document.compatMode && document.compatMode!="BackCompat") || window.opera)? document.documentElement : document.body
}
