function chkDecimal(val,field)
{
	var str = new String(val);
	if (str.indexOf(".")!=-1 && str.indexOf(",")!=-1)
	{
	alert(" U heeft of meer dan 1000 Euro besteld, corrigeer bestelling AUB")
	var sURL2 = "../overzichten1/stuur_melding.asp?message=`punt en komma in bestelling"+document.cart.username.value+document.cart.t.value
	loadXMLDoc(sURL2);
	return false;
	}
//	if (str.indexOf(",")!=-1)
//	{
//	alert(" U heeft of meer dan 1000 Euro besteld, corrigeer bestelling AUB")
//	var sURL2 = "../overzichten1/stuur_melding.asp?message=`komma in bestelling"+document.cart.username.value+document.cart.t.value
//	loadXMLDoc(sURL2);
//	return false;
//	}
	str=str.replace(".",",")
 	var decStr="0,00"	
	if(str.indexOf(",")!=-1)
 	{
 	string=str.split(",")
	var str1=string[0];
	var str2=string[1];
		if(str2.length==0) 
		{
			decStr=str1+","+"00"
		}
		if (str2.length==1)
		{
			var decStr=str1+","+str2+"0";
		}
		if (str2.length==2)
		{
			var decStr=str1+","+str2;
		}
		if (str2.length>2)
		{
			if(parseInt(str2.substring(2,3))>5)
			{
				  var add=parseInt(str2.substring(1,2))+parseInt(1)
			  	var decStr=str1 + ","+str2.substring(0,1)+ add;
			}
			else
	 		{
				  var decStr=str1 + ","+str2.substring(0,2);
			}
		}
	}
	else 
	{
		decStr=str+","+"00"
	}
   document.getElementById(field).value='€' +' '+ decStr + ' ';



}

  function checkAlphaNumeric(obj)
  {
 	if(IsNumeric(obj.value)==false)
		{
			obj.value="";
		}
 }

function add(val1,val2)
{
  if (isFinite(val1)==false)
  { 
 	 val1=val1.replace(",",".")
  }
  if (isFinite(val2)==false)
  { 
 	 val2=val2.replace(",",".")
  }
  
  som=parseFloat(val1)+parseFloat(val2)
  return som
}

function subtract(val1,val2)
{
  if (isFinite(val1)==false)
  { 
 	 val1=val1.replace(",",".")
  }
  if (isFinite(val2)==false)
  { 
 	 val2=val2.replace(",",".")
  }
  
  som=parseFloat(val1)-parseFloat(val2)
  return som
}


function multiply(val1,val2)
{
  val1=val1.replace(",",".")
  val2=val2.replace(",",".")
  som=String(parseFloat(val1)*parseFloat(val2)).replace(".",",")
  return som
}
 
  function calculate(obj)
  {

  var aantal=obj.value
  var length=obj.name.length
  var nr=obj.name.substr(1,length)
  var param="param"+nr;
  var linetot="linetot"+nr;
  var linetotval="linetotval"+nr; 

  var val=document.getElementById(param).value
  som=multiply(val,aantal)
  chkDecimal(som,linetot)
  
  document.getElementById(obj.name).value=obj.value;
  document.getElementById(linetotval).value=som;
  var sTotal=0;
  var sTotal=0;
  var discount=0;
  var shipcost=0;
	var tablines=document.getElementById("orderlines").rows.length-5
  for (i=1; i < tablines+1; i++)
  {
	var linetotval="linetotval"+i
  	var val=document.getElementById(linetotval).value
//	sTotal=parseFloat(sTotal.replace(",","."))+parseFloat(val.replace(",","."));
	sTotal=add(sTotal,val)
	}

	var field=new String("sub_cost")
	chkDecimal(sTotal,field)
	document.getElementById("sub_costh").value=sTotal;
	field="discount"

	if (sTotal < 50 )
	{
		chkDecimal(discount,field)
	} 

	if (sTotal > 50 && sTotal < 100)
	{
		discount=sTotal*0.1;
		chkDecimal(discount,field)
		
	} 
	if (sTotal > 100)
	{
		discount=sTotal*0.15;
		chkDecimal(discount,field)
		
	} 
	
	document.getElementById("disch").value=discount;
	shipcost=document.getElementById("ship_costh").value
	total=add(sTotal,shipcost)
	total=subtract(total,discount)

//	total=parseFloat(sTotal)-parseFloat(discount)+parseFloat(shipcost);
	var field= new String("total_cost") 
	chkDecimal(total,field)
	document.getElementById("total_costh").value=total;
 
 }
 
 
 
 function IsNumeric(sText)
 {
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
    for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsNumber = false;
      }
    }
   return IsNumber;
 }
 
  //----- function to check if all the quantity are more than 1 and updated ............
     function validatequant(){
	 
//	 alert("hallo")

     }
	//----- function to interchange the values between temp variable and quantity fields..
	function changevalue(obj1,obj2){
		//---- check whether the quantity field is null or not.......
		if(obj1.value == "") 
		{
			obj1.value = 0
			return 0
		}
		try{
		obj1.value = parseInt(obj1.value)
		}
		catch(e)
		{
			obj1.value = obj2.value;
		}
		if(obj1.value == ""){			
			obj1.value = obj2.value;			
		}
		obj2.value = obj1.value;
		//alert(obj2.value);
	}
	
	var req;

function loadXMLDoc(url) {

 	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
  
	  req.open("GET", url, false);
	  req.send("");
	  				
		if(req.statusText == 'OK')
		{  
			if (req.responseText != "NULL")
			{
		     	
			   return true;
			 }
		}
}

function update_naam()
{ 
	var sURL2 = "../overzichten1/update_naam.asp?naam="+document.cart.username.value;
		   loadXMLDoc(sURL2);
		   
}

function submitcart()
{
	try{
	document.cart.action="shopping_cart.asp?act=update";
//	document.cart.action="document.location.href='products.asp?stat=cont'"
	document.cart.submit();
	}catch(e){}
}
function bck() { //v2.0
 document.location.href="products.asp";
}
function showPayment(val)
{
		
	if(document.getElementById("country").selectedIndex!=0 )
	{
		var sURL2 = "get_shipcost.asp?id="+document.getElementById("country").value;
		loadXMLDoc(sURL2);
		ship_cost = req.responseText;
		var field=new String("ship_cost")
		chkDecimal(ship_cost,field)
		document.getElementById("ship_costh").value=ship_cost;
	}	
		
		sTotal=document.getElementById("sub_costh").value;
		discount=document.getElementById("disch").value;
		tot=add(sTotal,ship_cost)
		tot=subtract(tot,discount)
//		var tot=parseFloat(sTotal) + parseFloat(ship_cost)-parseFloat(discount);
		var field = new String("total_cost")
		chkDecimal(tot,field);
		document.getElementById("total_costh").value=tot;

		
		
 	if(val=="Nederland")
	{
		 	document.getElementById("payment1").disabled=false;
			document.getElementById("payment2").disabled=false;
			document.getElementById("payment3").disabled=false;
 			document.getElementById("payment2").checked=true;	
	}
 	if(val=="Deutschland")
	{
		 	document.getElementById("payment1").disabled=false;
			document.getElementById("payment2").disabled=false;
			document.getElementById("payment3").disabled=true;
 			document.getElementById("payment2").checked=true;	
	}	
 	if(val!=="Nederland" && val!=="Deutschland")
	{
			document.getElementById("payment1").disabled=true;
			document.getElementById("payment2").disabled=false;
			document.getElementById("payment3").disabled=true;
			document.getElementById("payment2").checked=true; 	
	}
 
}

function chkCountry(val)
{
	
//	var sTotal=document.getElementById("t").value;
	if(document.cart.country.selectedIndex==0)
	{
		this.checked=false;
		alert("Selecteer een land!");
		return false;
	}
}


function contshop()
{

	document.cart.action="products.asp?act=moreshop"
	document.cart.submit();
}


 function changeTo(obj)
	{
	
	 obj.style.backgroundColor="#84C1FF"
	 obj.style.color='#000000'
	}
	
function changeBack(obj)
	{
	
	 obj.style.backgroundColor="#999999"
	 obj.style.color='#ffffff'
	}

function IsAlphaNumeric(obj,cnt)
  {
 	if(IsNumeric(obj.value)==false)
	 {
		obj.value="";
	 }
	else
	 {
	   document.getElementById("chk_"+cnt).checked=true;
	 } 
	 
	if(obj.value==0)
	 {
	   document.getElementById("chk_"+cnt).checked=false;
	 }
 }
 
 
 function leftTrim(objStr) 
	{
		sString=objStr.value
		while (sString.substring(0,1) == ' ')
		{
		sString = sString.substring(1, sString.length);
		}
		objStr.value=sString
	}
	
 function IsAlphaNumeric(obj,sText)
 {
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
    for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsNumber = false;
      }
    }
	
	if(IsNumber==false)
	 {
		obj.value="";
	 }
   
 }
 
 function isSpecialChar(fieldname)
	{
		 var iChars = "!@#$%&()~`^*+=\\\';,.{}|\":<>?";
		 for (var i = 0; i < fieldname.length; i++) 
	 	{
			if (iChars.indexOf(fieldname.charAt(i)) != -1)
			{
				return false;
			}
		 }
	}
	
	function getFocus(fieldname)
	{
  		document.getElementById(fieldname).focus(); 
	}

function isEmail(email)
	{
	var result = false
	var theStr = new String(email)
	var index = theStr.indexOf("@");
	if (index > 0)	{
	var pindex = theStr.indexOf(".",index);
	if ((pindex > index+1) && (theStr.length > pindex+1))
		result = true;
	}
	return result;
	}
	
	function putDecimal(val)
	{
	var amt = new String(val);
	
	if (amt != "")
	{
		var parsedamt = amt.split(".")
		var intamt = parsedamt[0];
		var decamt = parsedamt[1];		
		if(decamt!="")
		{
			if(decamt.length==1)
				putDecimal=intamt+ "." + decamt + "0";
		}
		else
		{
			putDecimal=intamt+ "." + "00";
		}
	}
	else
	{
			putDecimal="";
	}
		alert(putDecimal);
	}
function closewindow()
	{
	alert("hallo")
	
} 



