 function checkProductForm(vProductID,vProductTitle,vProductNr,vProductPrice,vProductAmount){
	oForm = document.forms[1]
	oForm.ProductAmount.value = vProductAmount;
	oForm.ProductID.value = vProductID;
	oForm.ProductTitle.value = vProductTitle;
	oForm.ProductNr.value = vProductNr;
	oForm.ProductPrice.value = vProductPrice;
 	oForm.submit();
 }
 
 function changeProduct(vProductOrdern, vProductsOrderID){
	oForm = document.forms[0]
	oForm.orderID.value = vProductsOrderID;
	oForm.mode.value = "update";
	oForm.ProductAmount.value = eval("oForm.Quantity"+vProductOrdern).value;
	oForm.CustomerReference.value = oForm.FirstName.value + ' ' + oForm.SurName.value;	
	if(oForm.FirstNameL.value!="") oForm.AddressB1.value = oForm.FirstNameL.value;
	if(oForm.SurNameL.value!="") oForm.AddressB1.value = oForm.AddressB1.value + "_" + oForm.SurNameL.value;	
	if(oForm.AddressL.value!="") oForm.AddressB1.value = oForm.AddressB1.value + "_" + oForm.AddressL.value;	
	if(oForm.ZipcodeL.value!="") oForm.AddressB1.value = oForm.AddressB1.value + "_" + oForm.ZipcodeL.value;		
	if(oForm.CityL.value!="") oForm.AddressB1.value = oForm.AddressB1.value + "_" + oForm.CityL.value;		
	return true
}
 
  function deleteProduct(vOrderID){
	var oForm = document.forms[0]
	var ifDeleteAll = confirm(orderAlert[0])
	if(ifDeleteAll){
		oForm.mode.value = "delete";
		oForm.orderID.value = vOrderID;
		oForm.CustomerReference.value = oForm.FirstName.value + ' ' + oForm.SurName.value;	
		if(oForm.FirstNameL.value!="") oForm.AddressB1.value = oForm.FirstNameL.value;
		if(oForm.SurNameL.value!="") oForm.AddressB1.value = oForm.AddressB1.value + "_" + oForm.SurNameL.value;	
		if(oForm.AddressL.value!="") oForm.AddressB1.value = oForm.AddressB1.value + "_" + oForm.AddressL.value;	
		if(oForm.ZipcodeL.value!="") oForm.AddressB1.value = oForm.AddressB1.value + "_" + oForm.ZipcodeL.value;		
		if(oForm.CityL.value!="") oForm.AddressB1.value = oForm.AddressB1.value + "_" + oForm.CityL.value;			
 		return true 
	}
	else return false
 }
 
 function deleteAllProducts(vOrderID){
	var oForm = document.forms[0]
	var ifDeleteAll = confirm(orderAlert[1])
	if(ifDeleteAll){
		oForm.mode.value = "delete";
		oForm.orderID.value = "";
 		return true 
	}
	else return false
 }

function setCouponForm(){
	var oForm = document.forms[0]
	oForm.CustomerReference.value = oForm.FirstName.value + ' ' + oForm.SurName.value;	
	if(oForm.FirstNameL.value!="") oForm.AddressB1.value = oForm.FirstNameL.value;
	if(oForm.SurNameL.value!="") oForm.AddressB1.value = oForm.AddressB1.value + "_" + oForm.SurNameL.value;	
	if(oForm.AddressL.value!="") oForm.AddressB1.value = oForm.AddressB1.value + "_" + oForm.AddressL.value;	
	if(oForm.ZipcodeL.value!="") oForm.AddressB1.value = oForm.AddressB1.value + "_" + oForm.ZipcodeL.value;		
	if(oForm.CityL.value!="") oForm.AddressB1.value = oForm.AddressB1.value + "_" + oForm.CityL.value;			
 }
 
var shopAction = "web/shoppingcart.asp" 
var fakturaAction = "http://online.acmegroup.se/paycontrol/getPCOrder.asp"
var testAction = "http://online.acmegroup.se/paycontrol/fields.asp"
 
 function checkContactInfo(){
	var oForm = document.forms[0]
 	if(oForm.FirstName.value==""){
		alert(orderAlert[2]);
		oForm.FirstName.focus();
		return false;
	}
 	if(oForm.SurName.value==""){
		alert(orderAlert[3]);
		oForm.SurName.focus();
		return false;
	}
	if(oForm.SSN.value==""){
		alert(orderAlert[14]);						
		oForm.SSN.focus();
		return false;
	}	
	if(!new personnummer(oForm.SSN.value).valid&&!new organisationsnummer(oForm.SSN.value).valid){
		alert('Ogiltigt personnummer/org.nummer.');
		oForm.SSN.focus();
		return false;		
	}
 	if(oForm.AddressB2.value==""){
		alert(orderAlert[4]);
		oForm.AddressB2.focus();
		return false;
	}
 	if(oForm.ZipcodeB.value==""){
		alert(orderAlert[5]);
		oForm.ZipcodeB.focus();
		return false;					
	}
 	if(oForm.CityB.value==""){
		alert(orderAlert[6]);
		oForm.CityB.focus();
		return false;
	}
	if(oForm.PhoneHome.value==""&&oForm.PhoneWork.value==""&&oForm.PhoneMobile.value==""){
		alert(orderAlert[15]);						
		oForm.PhoneHome.focus();
		return false;
	}
	if(oForm.Email.value==""){
		alert(orderAlert[7]);						
		oForm.Email.focus();
		return false;
	}

	/*	if(oForm.Fornamn_Faktura.value==""){
		alert(orderAlert[9]);
		oForm.Fornamn_Faktura.focus();
		return false;
	}
 	if(oForm.Efternamn_Faktura.value==""){
		alert(orderAlert[10]);
		oForm.Efternamn_Faktura.focus();
		return false;
	}
 	if(oForm.Adress_Faktura.value==""){
		alert(orderAlert[11]);
		oForm.Adress_Faktura.focus();
		return false;
	}
 	if(oForm.Postnummer_Faktura.value==""){
		alert(orderAlert[12]);
		oForm.Postnummer_Faktura.focus();
		return false;
	}
 	if(oForm.Postort_Faktura.value==""){
		alert(orderAlert[13]);
		oForm.Postort_Faktura.focus();
		return false;
	}		
	*/	
	//oForm.mode.value = "send";
	if(!oForm.okDeal.checked){
		alert(orderAlert[16]);						
		oForm.okDeal.focus();
		return false;
	}		
	oForm.CustomerReference.value = oForm.FirstName.value + ' ' + oForm.SurName.value;	
	
	if(oForm.FirstNameL.value!="") oForm.AddressB1.value = oForm.FirstNameL.value;
	if(oForm.SurNameL.value!="") oForm.AddressB1.value = oForm.AddressB1.value + "_" + oForm.SurNameL.value;	
	if(oForm.AddressL.value!="") oForm.AddressB1.value = oForm.AddressB1.value + "_" + oForm.AddressL.value;	
	if(oForm.ZipcodeL.value!="") oForm.AddressB1.value = oForm.AddressB1.value + "_" + oForm.ZipcodeL.value;		
	if(oForm.CityL.value!="") oForm.AddressB1.value = oForm.AddressB1.value + "_" + oForm.CityL.value;	
	/*
	if(UserLoggedIn!="True") oForm.action = fakturaAction;
	else{
		if(UserLoggedIn=="True") oForm.action = testAction;
		else oForm.action = fakturaAction;
	}
	*/
	oForm.mode.value = "send";
	return true	
 }
 
 function checkBookInfo(){
	var oForm = document.forms['productForm']
 	if(oForm.Fornamn.value==""){
		alert(orderAlert[2]);
		oForm.Fornamn.focus();
		return false;		
	}
 	if(oForm.Efternamn.value==""){
		alert(orderAlert[3]);
		oForm.Efternamn.focus();
		return false;
	}
 	if(oForm.Alder.value==""){
		alert(orderAlert[8]);
		oForm.Alder.focus();
		return false;
	}
 	if(oForm.Stad.value==""){
		alert(orderAlert[9]);
		oForm.Stad.focus();
		return false;					
	}
 	if(oForm.Kompis1.value==""){
		alert(orderAlert[10]);
		oForm.Kompis1.focus();
		return false;
	}
	if(oForm.Kompis2.value==""){
		alert(orderAlert[11]);						
		oForm.Kompis2.focus();
		return false;
	}
 	if(oForm.Kompis3.value==""){
		alert(orderAlert[12]);
		oForm.Kompis3.focus();
		return false;
	}
	if(oForm.Present.value==""){
		alert(orderAlert[13]);						
		oForm.Present.focus();
		return false;
	}	
	//oForm.mode.value = "send";
	return true		
}

 function checkProductInfo(){
	var oForm = document.forms['productForm']
 	if(oForm.ProductDescription.value==""){
		alert(orderAlert[14]);
		oForm.ProductDescription.focus();
		return false;		
	}
	return true	
}

function personnummer(nr){ 
	this.valid=false; 
	if(!nr.match(/^(\d{2})(\d{2})(\d{2})\-(\d{4})$/)) return false;
	this.now=new Date(); 
	this.nowFullYear = this.now.getFullYear()+""; 
	this.nowCentury = this.nowFullYear.substring(0,2); 
	this.nowShortYear = this.nowFullYear.substring(2,4); 
	this.year = RegExp.$1; 
	this.month = RegExp.$2; 
	this.day = RegExp.$3; 
	this.controldigits = RegExp.$4; 
	this.fullYear = (this.year*1<=this.nowShortYear*1)?(this.nowCentury+this.year)*1:((this.nowCentury*1-1)+this.year)*1; 
	var months = new Array(31,28,31,30,31,30,31,31,30,31,30,31); 
	if(this.fullYear%400==0||this.fullYear%4==0&&this.fullYear%100!=0) months[1]=29;
	if(this.month*1>12||this.day*1>months[this.month*1-1]) return false;
	this.alldigits=this.year+this.month+this.day+this.controldigits; 
	var nn=""; 
	for(var n=0;n<this.alldigits.length;n++){
		nn += ((((n+1)%2)+1)*this.alldigits.substring(n,n+1));
	} 
	this.checksum=0; 
	for(var n=0;n<nn.length;n++){
		this.checksum+=nn.substring(n,n+1)*1;
	} 
	this.valid = (this.checksum%10==0)? true:false; 
	this.sex = parseInt(this.controldigits.substring(2,3))%2; 
} 

function organisationsnummer(nr){ 
	this.valid=false; 
	if(!nr.match(/^(\d{1})(\d{5})\-(\d{4})$/)){ return false; } 
	this.group=RegExp.$1; 
	this.controldigits=RegExp.$3; 
	this.alldigits=this.group+RegExp.$2+this.controldigits; 
	if(this.alldigits.substring(2,3)<2){ return false } 
	var nn=""; 
	for(var n=0;n<this.alldigits.length;n++){ nn+=((((n+1)%2)+1)*this.alldigits.substring(n,n+1)); } 
	this.checksum=0; 
	for(var n=0;n<nn.length;n++){ this.checksum+=nn.substring(n,n+1)*1; } 
	this.valid=(this.checksum%10==0)?true:false; 
} 
