function ShowInPopUp( sURL , iWidth , iHeight )
{ 	popwin = window.open( sURL , "popupwin" , 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,left=200,top=200,width=' + iWidth + ',height=' + iHeight );
        popwin.focus();
}

function isGreaterThenZero( cValue, cNoNumber, cNumberToLow )
{	if (isNaN(cValue) || cValue == "")
  	{ 	alert (cNoNumber);
    	return false;
	}
  	else
  	{ 	if (cValue <= 0)
    	{ 	alert (cNumberToLow);
	  		return false;
		}
  	}
  	return true;
}

function isAtLeastZero( cValue, cNoNumber, cNumberToLow)
{	if (isNaN(cValue) || cValue == "")
	{	alert (cNoNumber);
		return false;
	}
	else
	{	if (cValue < 0)
		{	alert (cNumberToLow);
			return false;
		}
	}
	return true;
}

function processBasket(cAction, cNoNumber, cNumberToLow, cAllQuantitiesAreZero, cMinimumBuy, cPackFactor)
{		   
    i = 1;
	dummyNoValFound = false;
	allZero = true;
    while (i < document.basketForm.elements.length)
	{	if (document.basketForm.elements[i].name == "tabnquantity")
		{	if (!dummyNoValFound) // skip dummy value 'NoVal'
			{ 	dummyNoValFound = true;
			}
			else
			{	if (!isAtLeastZero(document.basketForm.elements[i].value, cNoNumber, cNumberToLow))
				{	return false;  // exit function if there is a wrong value entered
				}
				if (document.basketForm.elements[i].value > 0)
				{	allZero = false;
				}
				cSalesQuantity = document.basketForm.elements[i].getAttribute('sales');
				cPackQuantity  = document.basketForm.elements[i].getAttribute('pack');
				cUnit	       = document.basketForm.elements[i].getAttribute('unit');
				cProduct       = document.basketForm.elements[i].getAttribute('product');
				if(parseFloat(document.basketForm.elements[i].value) < parseFloat(cSalesQuantity) && cSalesQuantity != "" && cSalesQuantity != null && document.basketForm.elements[i].value > 0)
                {
	               alert(cProduct+": "+cMinimumBuy+" " +cSalesQuantity+" "+cUnit);
	               document.basketForm.elements[i].value = cSalesQuantity;
	               return;
                }
                if(((parseFloat(document.basketForm.elements[i].value)/parseFloat(cPackQuantity))%parseInt(1)) != 0 && cPackQuantity != "" && cPackQuantity != null && document.basketForm.elements[i].value > 0) 
                {
 	           var nieuwaantal = (Math.ceil((parseFloat(document.basketForm.elements[i].value)/parseFloat(cPackQuantity))))*parseFloat(cPackQuantity);
                   var pack = confirm(cProduct+": "+cPackFactor + " " + nieuwaantal+" "+cUnit +"?"); 
  	               if(pack == true)
	               { document.basketForm.elements[i].value = nieuwaantal; }
	               else
	               { 
  	                 document.basketForm.elements[i].value = "1";
	                 return; 
	               }
			    }			
		    }
		}
		i++;
	}
	if (cAction == "checkout" && allZero == true)
	{	alert (cAllQuantitiesAreZero);
		return false;
	}
 	if (cAction == "update")
  	{ 	document.basketForm.caction.value = "update";
  	}
  	else
  	{ 	if (cAction == "checkout")
    	{  	document.basketForm.caction.value = "checkout";
    	}
  	}
  	document.basketForm.submit();
}

function ConfirmBasket ( inp )
{ if (inp == "confirm")
  {  document.checkOutForm.caction.value = "confirm";
  }
  document.checkOutForm.submit();
}

function processProfile( inp )
{ if (inp == "update")
  { document.profileForm.caction.value = "update";
  }
  document.profileForm.submit();
}

function DeleteConfirmation ( inp )
{ if (inp == "delete")
  { document.confirmationForm.caction.value = "delete";
  }
  document.confirmationForm.submit();
}
        
function processPersonal (ntype,caction, nperscat,cnaam, cmsg)
{   
  var formnaam;
  if(ntype == 0) 
  { formnaam = 'custForm'; }
  else
  { if(ntype == 1) { formnaam = 'personalForm'; }}
  if (caction == "delete")
  { document.forms[formnaam].caction.value  = "delete";
    document.forms[formnaam].nperscat.value = nperscat;
    document.forms[formnaam].submit();
  }
  else
  { if (caction == "insert")
    { if (document.personalForm.cperscat.value == "")
	  { alert (cmsg);}
	  else
	  { document.forms[formnaam].cperscat.value = document.personalForm.cperscat.value;
	    document.forms[formnaam].caction.value = "insert";
        document.forms[formnaam].submit();
	  }
	}
	else
    { if (caction == "switch")
      { 
	      document.forms[formnaam].cperscat.value = cnaam;
	      document.forms[formnaam].caction.value = "switch";
		  document.forms[formnaam].nperscat.value = nperscat;
          document.forms[formnaam].submit();
	  }  	  
    }
  }
}

function validateProduct( cFormObject, cNoNumber, cNumberToLow )
{ 	if (isGreaterThenZero(cFormObject.nquantity.value, cNoNumber, cNumberToLow))
  	{ 	
     	return true;  // submit form
  	}
  	else
  	{ 	
  	return false; // do not submit form
  	}
}

function processProduct( cAction, cFormObject, cNoNumber, cNumberToLow, cSalesQuantity, cPackQuantity, cMinimumBuy, cPackFactor, cUnit, nMaxOrder, cMaxOrder, nWarnOrder, cWarnOrder, nCursor, nOrdered, cOrdered)
{   if (validateProduct( cFormObject, cNoNumber, cNumberToLow ))
    {  
       //alreadyOrdered
	   if(cFormObject.nOrdered.value == 1 )
	   {
		   var ordered = confirm(cOrdered);
		   if(ordered != true)
		   {
			 cFormObject.nquantity.value = "1";
			 return false;
		   }
	   }
	   //maxOrder
       if(parseFloat(cFormObject.nquantity.value) > parseFloat(nMaxOrder))
       {
         alert(cMaxOrder.replace(/p_order/,nMaxOrder.toString()+" "+cUnit));
	 cFormObject.nquantity.value = "1";
	 return false;
       }
       //warnOrder
       if(parseFloat(cFormObject.nquantity.value) >= parseFloat(nWarnOrder)) 
       {
         var pack = confirm(cWarnOrder.replace(/p_order/,cFormObject.nquantity.value.toString()+" "+cUnit)); 
	 if(pack != true)
	    { cFormObject.nquantity.value = "1";
	      return false; 
	    }
       }
       //minhoev
       if(parseFloat(cFormObject.nquantity.value) < parseFloat(cSalesQuantity) && cSalesQuantity != "" && cSalesQuantity != null)
       {
         alert(cMinimumBuy+cSalesQuantity.toString()+" "+cUnit);
	 cFormObject.nquantity.value = cSalesQuantity;
	 return false;
       }
       //verp
       if( ((parseFloat(cFormObject.nquantity.value)/parseFloat(cPackQuantity))%parseInt(1)) != 0 && cPackQuantity != "" && cPackQuantity != null) 
       {
	 var nieuwaantal = (Math.ceil((parseFloat(cFormObject.nquantity.value)/parseFloat(cPackQuantity))))*parseFloat(cPackQuantity);
         var pack = confirm(cPackFactor +" "+ nieuwaantal+" "+cUnit +"?"); 
	 if(pack == true)
	    { cFormObject.nquantity.value = nieuwaantal; }
	 else
	    { 
	      cFormObject.nquantity.value = "1";
	      return false; 
            }
       }
	   
	    if (cAction == "buy")
    	{ 	        cFormObject.target = "popupwin";
    	                cFormObject.caction.value = "buy";
						cFormObject.nOrdered.value = 1;
	  		ShowInPopUp("../../shop/common/empty.html",500,300);
	  		cFormObject.submit();
	  		
	  		if (nCursor == "1") { cFormObject.nquantity.blur(); };
	  		
		        return false;
		}
		else
	  	{ 	if (cAction == "add")		
	    	{ 	cFormObject.caction.value = "add";
	    	        cFormObject.target = "popupwin";
		  		ShowInPopUp("../../shop/common/empty.html",500,300);
	  			cFormObject.submit();
	    	}
  			else
			{ 	if (cAction == "delete")
    	  		{ 
    	  				cFormObject.target = "popupwin";
                                        cFormObject.caction.value = "delete";
		  			ShowInPopUp("../../shop/common/empty.html",500,300);
			  		cFormObject.submit();
    	  		}
				else
				{  if(cAction == "fast")
				   {
				     cFormObject.caction.value = "fast";
					 cFormObject.target = "_self";
					 cFormObject.nOrdered.value = 1;
					 cFormObject.submit();
  		                         return false;
				   }
				   else
				   {  if(cAction == "buy2")
				      {
				        cFormObject.target = "header";
				    	cFormObject.caction.value = "buy2";
						cFormObject.nOrdered.value = 1;
	  		                cFormObject.submit();

	  		                if (nCursor == "1") { cFormObject.nquantity.blur(); };
	  		
				      }
 	                              return false;
  				   } 
				} 
    		}
		}
	}
	else
	{
	  return false;
	}
}

function processProductInPopup ( cAction )
{	if (cAction == "add")
	{ 	document.productInPopupForm.caction.value = "add";
  	}
  	else
  	{ 	if (cAction == "delete")
    	{ 	document.productInPopupForm.caction.value = "delete";
		}
  	}
  	document.productInPopupForm.submit();
}

function ProcessTrace( inp )
{ ShowInPopUp('empty.html',500,300);
  if (inp == "reorder")
  { document.ReOrderForm.caction.value = "reorder";
  }
  document.ReOrderForm.submit();
}

function processSearch ( cMsgEmpty, cMsgBoth )
{ if (document.searchForm.ctext.value == "" && document.searchFormCust.ctextCust.value == "" && document.searchForm2.ctext2.value == "")
  { alert (cMsgEmpty); return false;
  }
  else if (document.searchForm.ctext.value != "" && document.searchFormCust.ctextCust.value != "")
  { alert (cMsgBoth); return false;
  }
  else if (document.searchForm2.ctext2.value != "" && document.searchFormCust.ctextCust.value != "")
  { alert (cMsgBoth); return false;
  }
  else if (document.searchForm.ctext.value != "" && document.searchForm2.ctext2.value != "")
  { alert (cMsgBoth); return false;
  }
  else
  { document.searchForm.ctextCust.value = document.searchFormCust.ctextCust.value; 
    document.searchForm.ctext2.value = document.searchForm2.ctext2.value;
    return true;
  }
}

function processSearch2 ( cMsgEmpty, cMsgBoth )
{ if (document.searchForm.ctext.value == "" && document.searchFormCust.ctextCust.value == "" && document.searchForm2.ctext2.value == "")
  { alert (cMsgEmpty); return false;
  }
  else if (document.searchForm.ctext.value != "" && document.searchFormCust.ctextCust.value != "")
  { alert (cMsgBoth); return false;
  }
  else if (document.searchForm2.ctext2.value != "" && document.searchFormCust.ctextCust.value != "")
  { alert (cMsgBoth); return false;
  }
  else if (document.searchForm.ctext.value != "" && document.searchForm2.ctext2.value != "")
  { alert (cMsgBoth); return false;
  }
  else
  { document.searchForm2.ctextCust.value = document.searchFormCust.ctextCust.value; 
    document.searchForm2.ctext.value = document.searchForm.ctext.value;
    return true;
  }
}

function processSearchCust ( cMsgEmpty, cMsgBoth )
{ if (document.searchForm.ctext.value == "" && document.searchFormCust.ctextCust.value == "" && document.searchForm2.ctext2.value == "")
  { alert (cMsgEmpty); return false;
  }
  else if (document.searchForm.ctext.value != "" && document.searchFormCust.ctextCust.value != "")
  { alert (cMsgBoth); return false;
  }
  else if (document.searchForm2.ctext2.value != "" && document.searchFormCust.ctextCust.value != "")
  { alert (cMsgBoth); return false;
  }
  else if (document.searchForm.ctext.value != "" && document.searchForm2.ctext2.value != "")
  { alert (cMsgBoth); return false;
  }
 
  else
  { document.searchFormCust.ctext.value = document.searchForm.ctext.value; 
    document.searchFormCust.ctext2.value = document.searchForm2.ctext2.value; 
    return true; 
  }
}

function addAccountSubmission ( inp )
{ 
   if (inp == "check")
   { if (document.processAddAccountForm.cpaswoord.value == "")
     { alert ("You must enter a pasword");
     }
     else
     { if (document.processAddAccountForm.cpaswoord.value == document.processAddAccountForm.cpaswoordconf.value)
       { document.processAddAccountForm.submit();
       }
       else
       { alert ("Your paswoord confirmation did not match please re-enter");
       }
     }
   }
}

function processUpdateAccount( inp )
{ 
  if (inp == "delete")
  {  document.processUpdateAccountForm.caction.value = "delete";
  }
  if (inp == "update")
  {  document.processUpdateAccountForm.caction.value = "update";
  }
  document.processUpdateAccountForm.submit();
}
                                
                                
function encode_b64 (Str) 
{
  var encStr = "";
  var base64 = [
  'A','B','C','D','E','F','G','H','I','J','K','L','M',
  'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
  'a','b','c','d','e','f','g','h','i','j','k','l','m',
  'n','o','p','q','r','s','t','u','v','w','x','y','z',
  '0','1','2','3','4','5','6','7','8','9','+','/'];
  for (var i = 0; i<Str.length; i += 3) {
  encStr += base64[(Str.charCodeAt(i) >>>2)];
  if(!Str.charAt(i+1)) {encStr += '=='; break;}
  encStr += base64 [(((Str.charCodeAt(i) & 0x03) <<4)
                       | Str.charCodeAt (i+1) >>>4)];
  if(!Str.charAt(i+2)) {encStr += '='; break;}
  encStr += base64[(((Str.charCodeAt(i+1) & 0x0F) <<2)
                       | Str.charCodeAt(i+2) >>>6)];
  encStr += base64[(Str.charCodeAt(i+2) & 0x3F)];
  }
return encStr;
}
     
function GoOutput(Str)
{
 	location = Str;
}
                     
function GoUgrpDupl(cadmin)
{
    var locatie;
    if(cadmin=="")
	{ locatie= "html";}
	else
	{ locatie= "admin";}
 	location = locatie+".modifyUgrp?caction=DUP&nID="+ document.form.nID.value+"&ctaal="+cadmin;
}

function GoUgrpDel(cadmin)
{
    var locatie;
    if(cadmin=="")
	{ locatie= "html";}
	else
	{ locatie= "admin";}
 	popwin = window.open( locatie+".deleteUgrp?nID=" + document.form.nID.value+"&ctaal="+cadmin, "popupwin" , 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes, resizable=yes, copyhistory=no,left=200,top=200,width=500,height=350');
    popwin.focus();      	
}
 
function RefreshUgrp(caction, cid, ccode, cnaam,cadmin)
{
   var locatie;
    if(cadmin=="")
	{ locatie= "html";}
	else
	{ locatie= "admin";}
 	location = locatie+".modifyUgrp?nID=" + cid +
 				   	"&cCODE=" + ccode +
 					"&cNAAM=" + cnaam +
				    "&cACTION=" + caction +
					"&ctaal="+cadmin;
}
               
function UgrpDel(cadmin)
{
	location = ("shp_usergroup_pa.Del?nID=" + document.form.nID.value + "&cChecksum="+ document.form.cChecksum.value+"&ctaal="+cadmin);
	window.close();
	var locatie;
    if(cadmin=="")
	{ locatie= "html";}
	else
	{ locatie= "admin";}
	window.opener.location.replace(locatie+".searchugrp?ctaal="+cadmin);
}

function RefreshExcep(caction, nUgrp, nid, cProd, nMain, nSub, nDetail, cvv01, cvv02, cvv03, cvv04, cvv05, cvv06,cvalidfrom,cvalidtill,cadmin)
{ 
   var locatie;
   if(cadmin=="")
   { locatie= "html";}
   else
   { locatie= "admin";}
    location = locatie+".modifyexecpugrp?nUgrp=" + nUgrp +
	                       "&nid="+ nid +
 					       "&cProd=" + cProd +
 					       "&nMaingroup=" + nMain +
 					       "&nSubgroup=" + nSub +
 					       "&nDetailgroup=" + nDetail +
 					       "&cvv01=" + cvv01 +
 					       "&cvv02=" + cvv02 +
 					       "&cvv03=" + cvv03 +
 					       "&cvv04=" + cvv04 +
						   "&cvv05=" + cvv05 +
 					       "&cvv06=" + cvv06 +
						   "&caction=" + caction +
						   "&cvalidfrom=" + cvalidfrom +
						   "&cvalidtill=" + cvalidtill +
						   "&ctaal="+cadmin;
}               

function GoExcepDupl(cadmin)
{
    var locatie;
    if(cadmin=="")
	{ locatie= "html";}
	else
	{ locatie= "admin";}
 	location = locatie+".modifyexecpugrp?caction=DUP&nID=" + document.form.nID.value+"&ctaal="+cadmin;
}

function GoExcepDel(cadmin)
{
    var locatie;
    if(cadmin=="")
	{ locatie= "html";}
	else
	{ locatie= "admin";}
    popwin = window.open(locatie+".deleteexecpugrp?nID=" + document.form.nID.value+"&ctaal="+cadmin, "popupwin" , 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes, resizable=yes, copyhistory=no,left=200,top=200,width=500,height=350');
    popwin.focus();      	
}                               

function ExcepDel(cadmin)
{
	location = ("shp_usergroup_pa.DelExcep?nID=" + document.form.nID.value + "&cChecksum="+ document.form.cChecksum.value+"&ctaal="+cadmin);
	window.close();
	var locatie;
    if(cadmin=="")
	{ locatie= "html";}
	else
	{ locatie= "admin";}
	window.opener.location.replace(locatie+".searchexecpugrp?ctaal="+cadmin);
}

function disableProd()
{

   var vraag = "document.form.nMaingroup.value=='' && document.form.nSubgroup.value=='' && document.form.nDetailgroup.value=='' ";
   if(document.form.cVV01) { vraag += "&& document.form.cVV01.value=='' "; }
   if(document.form.cVV02) { vraag += "&& document.form.cVV02.value=='' "; }
   if(document.form.cVV03) { vraag += "&& document.form.cVV03.value=='' "; }
   if(document.form.cVV04) { vraag += "&& document.form.cVV04.value=='' "; }
   if(document.form.cVV05) { vraag += "&& document.form.cVV05.value=='' "; }
   if(document.form.cVV06) { vraag += "&& document.form.cVV06.value=='' "; }
   

   eval("if("+vraag+") { document.form.cProd.disabled=false; } else { document.form.cProd.disabled=true; }");
}

function disableList()
{
  if(document.form.cProd.value!="")
  {
     document.form.nMaingroup.disabled=true;
	 document.form.nSubgroup.disabled=true;
	 document.form.nDetailgroup.disabled=true;
     if(document.form.cVV01) { document.form.cVV01.disabled=true; }
     if(document.form.cVV02) { document.form.cVV02.disabled=true; }
     if(document.form.cVV03) { document.form.cVV03.disabled=true; }
     if(document.form.cVV04) { document.form.cVV04.disabled=true; }
     if(document.form.cVV05) { document.form.cVV05.disabled=true; }
     if(document.form.cVV06) { document.form.cVV06.disabled=true; }
  }
  else
  {
     document.form.nMaingroup.disabled=false;
	 document.form.nSubgroup.disabled=false;
	 document.form.nDetailgroup.disabled=false;
     if(document.form.cVV01) { document.form.cVV01.disabled=false; }
     if(document.form.cVV02) { document.form.cVV02.disabled=false; }
     if(document.form.cVV03) { document.form.cVV03.disabled=false; }
     if(document.form.cVV04) { document.form.cVV04.disabled=false; }
     if(document.form.cVV05) { document.form.cVV05.disabled=false; }
     if(document.form.cVV06) { document.form.cVV06.disabled=false; }
  }
} 

function tryJump(node) 
{
  try
  {parent.tree.jump(node);} 
  catch(ex)
  {setTimeout("tryJump('"+node+"');",100);}
}

function tryResetAll() 
{  
  try
  {parent.tree.resetAll();} 
  catch(ex)
  {setTimeout("tryResetAll();",100);}
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function ReloadPage(typeHeader)
{     
   if(typeHeader != 'CATALOG' && parent.frames.length > 0)
   { 
      top.location.href = self.location;
	  createCookie("EcommerceReload","true",100);
   }
   else
   {
     if(typeHeader != 'CATALOG' && parent.frames.length == 0 && readCookie("EcommerceReload") == "true")
	 {
	   createCookie("EcommerceReload","false",100);
   	   self.location.reload(true);
	 }
	 else
	 {
        createCookie("EcommerceReload","false",100);
	 }
   }
}

function resizePhoto(breedte,hoogte)
{
  if(document.photo)
  {
     var w = document.photo.width;
     var h = document.photo.height;
     var mw = breedte;
     var mh = hoogte;
  
     if((w - mw) > (h - mh))
     {
       if (w > mw)
   	   {
	     document.photo.width = mw;
	     document.photo.height =h*mw/w;	  
	   }	
     }
     else
     {
       if (h > mh)
	   {
	     document.photo.height = mh;
	     document.photo.width = w* mh/h;
	   }
     }
   }   
}

function SubmitFast ()
{
	var prod = document.getElementById("cProduct");
	var quant = document.getElementById("nQuantity");
	
	if ( prod.value != "" && quant.value != "" )
	{
		document.basketForm.caction.value = "quick";
		document.basketForm.submit();
	}
}