
	var unitIDPrefix='unit';
	//id of unit input field is unit+articleid
	var priceIDPrefix='price';
	//id of price input field is price+articleid
	
	var contactChange=false;
	//boolean to check if contactdata is changed
	
	function clearictdata()
	{
		callscript("frmupdate","/webscripts/ictdatafill.php?clearall=1");
	}

	function saveictdata()
	{
		extra="";
		if(arguments[0])
		{
			//extra="?addopm="+arguments[0];
		}
		if(createnewcontact)
		{
			if(extra)
			{
				extra+="&addnewcontact=1";
			}
			else
			{
				extra+="?addnewcontact=1";
			}
		}
		//alert("/webscripts/ictdatasave.php"+extra);
		callscript("frmupdate","/webscripts/ictdatasave.php"+extra);
	}
	
	var callcount=0;
	var nexturl='';
	var readyurl='';
	var readyframeid='';
	var nexturlreplace='';
	var ordertype='';
	var createnewcontact;
	
	function taordersubmit(ifr,scriptcall,url,conftxt)
	{		
		
		if(arguments[0]) 
		{
			readyframeid=arguments[0];
			if(contactChange && typeof(conftxt)!="undefined" && conftxt)
			{
				createnewcontact=!confirm(conftxt);
				//createnewcontact=!confirm("Voor het wijzigen van bestaande contactpersoon gegevens, klik op OK. Voor het toevoegen van een nieuwe contactpersoon, klik op Cancel.");
			}
			//saveictdata(ordertype);
		}
		if(arguments[1])
		{						
			readyurl=arguments[1];
			if(contactChange)
			{
				if(createnewcontact)
				{
					readyurl+="&ADDNEWCON=1";
				}
				else
				{
					readyurl+="&UPDATECON=1";
				}
			}
			if(ordertype)
			{
				readyurl+="&addopm="+ordertype;
			}
		}
		if(arguments[2])
		{
			nexturl=arguments[2];
		}
	
		if(document.getElementById(readyframeid).readyState!="complete" && callcount<25)
		{
			setTimeout("taordersubmit()",100);
			callcount++;
		}	
		else
		{
			callscript(readyframeid,readyurl);
			isreadygourl(readyframeid,url);
		}	
	}
	
	function isreadycallnext()
	{
		//takes two arguments, the id of the iframe and the url to navigate the iframe when ready
		
		if(arguments[0]) readyframeid=arguments[0];
		if(arguments[1]) readyurl=arguments[1];
		
		if(document.getElementById(readyframeid).readyState!="complete" && callcount<100)
		{
			setTimeout("isreadycallnext()",100);
			callcount++;
			return(false);
		}	
		else
		{
			callscript(readyframeid,readyurl);
		}
	}
	
	function isreadygourl()
	{
		//takes two arguments, the id of the iframe and the url to navigate the iframe when ready
		

		if(arguments[0]) 
		{
			readyframeid=arguments[0];
			callcount=0;
		}
		if(arguments[1]) nexturl=arguments[1];
		
		if(arguments[2]) nexturlreplace=arguments[1];
		
		if(document.getElementById(readyframeid).readyState!="complete" && callcount<10)
		{
			setTimeout("isreadygourl()",100);
			callcount++;
		}	
		else
		{			
			gotourl(nexturl,nexturlreplace);
		}
	}

	function fillresult(val)
	{
		//alert(val);		
		callscript("frmupdate","/webscripts/ictdatafill.php?idstring="+val);
		//if(!RefreshOK)
		{
			isreadygourl("frmupdate",document.location.href);
		}
		//alert('klaar');
	}
 
	function dosearch()
	{
		//search in ICT clients and contact data
		document.getElementById('kltsearchrow').style.display='';
		callscript("frmupdate","/webscripts/ictsearch.php");
	}
	
	function switchEdit(artid)
	{
		//switches the edit/view function for the shop fase 2		
		if(artid)
		{			
			unitText=document.getElementById(unitIDPrefix+"txt"+artid);
			//alert(unitText.innerHTML);
			unitInput=document.getElementById(unitIDPrefix+artid);
			
			if(unitText && typeof(unitText)!="undefined" && unitInput && typeof(unitInput)!="undefined")
			{
				unitText.style.display='none';
				unitInput.style.display='';
			}
			priceText=document.getElementById(priceIDPrefix+"txt"+artid);
			priceInput=document.getElementById(priceIDPrefix+artid);
			if(priceText && typeof(priceText)!="undefined" && priceInput && typeof(priceInput)!="undefined")
			{
				priceText.style.display='none';
				priceInput.style.display='';
			}
		}
	}
	
	function saveOrderOnEnter()
	{
		if(window.event.keyCode==13)
		{
			uid='';
			if (arguments[0])
			{
				uid=arguments[0];
				refreshorder(uid);
			}		
		}
	}			
	
	function refreshorder()
	{
		//voor delete met twee parameters aanroepen, anders update
		
		utype='';
		uid='';
		if (arguments[1])
		{
			utype=arguments[1];
		}
		if (arguments[0])
		{
			uid=arguments[0];
		}			
		if(utype=='del' && uid)
		{
			document.getElementById('addbst').src='/ws/addorder.php?delartid='+uid;
			//alert(document.getElementById('addbst').src);
			var sURL = unescape(window.location.pathname);
			//alert(window.location.pathname);
			window.location.replace(sURL);
		}
		else if(uid)
		{
			priceElm=document.getElementById(priceIDPrefix+uid);
			unitElm=document.getElementById(unitIDPrefix+uid);
			
			pricePlus='';
			unitPlus='';
			if(priceElm && typeof(priceElm)!="undefined")	pricePlus='&price='+priceElm.value;
			if(unitElm && typeof(unitElm)!="undefined")	unitPlus='&unit='+unitElm.value;
			//alert('artid='+uid+pricePlus+unitPlus+'&aantal='+document.getElementById('nr'+uid).value);
			document.getElementById('addbst').src='/ws/addorder.php?artid='+uid+pricePlus+unitPlus+'&aantal='+document.getElementById('nr'+uid).value;
			//alert(document.getElementById('addbst').src);
			var sURL = unescape(window.location.pathname);
			//alert(window.location.pathname);
			//redirects window, quote for debugging
			window.location.href = sURL;						
		}
	}
	
	function toggleimage(imgid,img1,img2,imgpath)
		//toggles between 2 imgages in the same image directory
	{			
		if(imgpath)
		{
			//a path is defined
			if(imgpath.substr(-1)!="/")
			{
				//check endslash
				imgpath+="/";
			}
		}
		imgelm=document.getElementById(imgid);
		if(imgelm.src.indexOf(img1)>-1)
		{
			imgelm.src=imgpath+img2;
		}
		else
		{
			imgelm.src=imgpath+img1;
		}
		
	}	
	
	function showhidetable(tblid)
	{	
		//toggles showing or hiding the rows of a table
		//first row will always be visible
		//parameter takes id of the html table element
		//optional second parameter gets scrollable div							
		tbl=document.getElementById(tblid);			
		arrtr=tbl.getElementsByTagName('TR');
		//alert(arrtr.length);
		arrtrlen=arrtr.length;					
		if(arrtrlen>1)
		{								
			if(arrtr[1].style.display=='none')
			{						
				disp='';
				if(arguments[1])
				{					
					divje=document.getElementById(arguments[1]);
					curpos=divje.scrollTop;
				}
			}
			else
			{
				disp='none';
			}
			i=1;
			while(i<arrtrlen)
			{
				//alert('in');
				arrtr[i].style.display=disp;
				if(!disp)
				{
					if(divje)
					{
						curpos=curpos+30;
						divje.scrollTop=curpos;
					}
					else
					{
						window.scrollBy(0,30);	
					}		
				}
				i++;
			}															
		}						
	}		
	
	var showproduct=new Array();
		
	function delorderblock(curelm)
	{
		if(showproduct[curelm])
		{
			ifr=document.getElementById('fraProdID'+showproduct[curelm]);
			ifr.parentNode.removeChild(ifr);
		}
	}
	
	function showhideelm(elmid)
	{
		if(document.getElementById(elmid))
		{
			elm=document.getElementById(elmid);
			if(elm.style.display=='none')
			{
				elm.style.display='';
			}
			else
			{
				elm.style.display='none';
			}
		}
	}
	
	function showorderblock(prodid,curelm,land,taal)
	{//product id (hoofdprodukt in artikel table)
	 //element id after which the orderblock is parsed
	 //optional: before, boolean (0,1) to instruct the function to insert before the curelm
	 //default setting is inserting after		
	 	showproduct[curelm]=prodid;
		curelm=document.getElementById(curelm);
		ifr=document.createElement('iframe');		
		//alert('create');		
		ifr.id='fraProdID'+prodid;
		//alert('id');
		ifr.name='fraProd';
		//alert('name');
		ifr.src="../ws/frameproduct.php?shop=1&taal="+taal+"&land="+land+"&prod="+prodid;
		//alert('src');
		ifr.allowTransparency=true;
		ifr.frameBorder=0;
		//alert('frameBorder');
		//ifr.style.scrolling=no;
		ifr.height=60;
		//alert('height');
		if(arguments[2]==1)
		{//the parameter 'before' is set
			//alert('before');
			curelm.parentNode.insertBefore(ifr,curelm);
		}	
		else if(!curelm.nextSibling)
		{//no next node, appendChild puts the node at the end
			curelm.parentNode.appendChild(ifr);			
		}
		else
		{
			//alert('after');
			curelm.parentNode.insertBefore(ifr,curelm.nextSibling);			
		}		
	}
	
	function openProdSel()
	{
		window.open('/webscripts/prodselshop.php?taal=nl&landcode=NL&klanttaal=NL','prodselwin',"width=600,height=600");
	}

	function setProdSel()
	{
		
		setTimeout('openProdSel()',100);
	}	
