 function checkProductForm(vProductID,vProductTitle,vProductNr,vProductPrice,vProductStartPrice,vProductDiscount,vProductAmount,vProductVAT,vProductWeight,vProductDescription){
	oForm = document.forms["productForm"]
	oForm.ProductAmount.value = vProductAmount;
	oForm.ProductID.value = vProductID;
	oForm.ProductTitle.value = vProductTitle;
	oForm.ProductNr.value = vProductNr;
	oForm.ProductPrice.value = vProductPrice;
	oForm.ProductStartPrice.value = vProductStartPrice;
	oForm.ProductDiscount.value = vProductDiscount;
	oForm.ProductVAT.value = vProductVAT;
	oForm.ProductWeight.value = vProductWeight;
	oForm.ProductDescription.value = vProductDescription;
 	oForm.submit();
 }
 
 function changeProduct(vProductID,vOrdern){
	var oForm = document.forms['shoppingcart'];
	oForm.ProductID.value = vProductID;
	oForm.ProductAmount.value = eval("oForm.Itemid"+vOrdern).value;	
	oForm.mode.value = "update";
	oForm.action = "web/newshoppingcart.asp";	
	//return true
	oForm.submit();
}
 
  function deleteProduct(vOrderID){
	var oForm = document.forms['shoppingcart'];
	var ifDeleteAll = confirm(orderAlert[0])
	if(ifDeleteAll){
		oForm.mode.value = "delete";
		oForm.orderID.value = vOrderID;
		oForm.action = "web/newshoppingcart.asp";		
 		//return true 
		oForm.submit();
	}
	//else return false
 }
 
 function deleteAllProducts(vShopUserID){
	var oForm = document.forms['shoppingcart'];
	var ifDeleteAll = confirm(orderAlert[1])
	if(ifDeleteAll){
		oForm.mode.value = "delete";
		oForm.ShopUserID.value = vShopUserID;
		oForm.action = "web/newshoppingcart.asp";
		oForm.orderID.value = "";
 		oForm.submit();
	}
	else return false
 }

function setCouponForm(){
	var oForm = document.forms[0]
}

function checkCouponValue(){
	var oForm = document.forms['shoppingcart'];
	if(oForm.CouponCode.value!=""){
		oForm.mode.value = "coupong";
		oForm.submit();
	}
	else{
		alert("Ange ev. rabattkod/presenkort");
		oForm.CouponCode.focus();
	}
}


 
var shopActionFM = "web/shop_pay.asp";
var shopActionBP = "web/newshoppingcart.asp" ;
var shopActionPayex = "web/payex.asp"; 
var fakturaAction = "http://online.acmegroup.se/paycontrol/getPCOrder.asp";
 
 
 var win;
 
 function checkContactInfo(){
	var oForm = document.forms['shoppingcart'];
 	var minSumma = 85.00*currencyValueArray[currencyarrayindex];
	//alert(minSumma+'-'+parseInt(oForm.totalSumma.value))
	//if(parseInt(oForm.firstSummaReductionCost.value)<minSumma){
	if(oForm.totalSumma.value<minSumma){
		alert(orderAlert[16]);
		return false;		
	}
	else{
		switch(currencyarrayindex){
			case 0:
				oForm.shipmentfee.value = 0;
			break
			
			case 1:
				//oForm.shipmentfee.value = 1760;
			break
			
			case 2:
				//oForm.shipmentfee.value = 176;
			break
			
			case 3:
				//oForm.shipmentfee.value = 1760;
			break
			
			default:
				//oForm.shipmentfee.value = 0;
			break
		}
		//alert(oForm.shipmentfee.value);
		if(oForm.country.options[oForm.country.options.selectedIndex].value==""){
			alert("Välj land");
			oForm.country.focus();
			return false;
		}
		else oForm.countryName.value = oForm.country.options[oForm.country.options.selectedIndex].text;	
		
		
		if(oForm.Payment.length!=null&&oForm.Payment.length!="undefined"){	
			var PaymentSelectedIndex = -1;
			for(i=0; i<oForm.Payment.length; i++){
				if(oForm.Payment[i].checked) PaymentSelectedIndex = i;	
			}
			if(PaymentSelectedIndex==-1){
				alert(orderAlert[15]);
				return false;		
			}	
			if(oForm.villkor!=null&&oForm.villkor!="undefined"){
				if(oForm.Payment[0].checked&&!oForm.villkor.checked){
					alert(orderAlert[17]);
					oForm.villkor.focus();
					return false;		
				}
			}
		}
		else{
			if(!oForm.Payment.checked){
				alert(orderAlert[15]);
				return false;			
			}
		}		
		
	 	if(oForm.fname.value==""){
			alert(orderAlert[2]);
			oForm.fname.focus();
			return false;		
		}
	 	if(oForm.lname.value==""){
			alert(orderAlert[3]);
			oForm.lname.focus();
			return false;
		}
	 	if(oForm.pno!=null&&oForm.pno!="undefined"){ //Danmark visar inget fält för personnummer
			if(oForm.pno.value==""&&oForm.Payment[0].checked){
				alert(orderAlert[14]);
				oForm.pno.focus();
				return false;
			}
		}	
	 	if(oForm.street.value==""){
			alert(orderAlert[4]);
			oForm.street.focus();
			return false;
		}
	 	if(oForm.postno.value==""){
			alert(orderAlert[5]);
			oForm.postno.focus();
			return false;					
		}
	 	if(oForm.city.value==""){
			alert(orderAlert[6]);
			oForm.city.focus();
			return false;
		}
		
		if(oForm.email.value==""){
			alert(orderAlert[7]);						
			oForm.email.focus();
			return false;
		}
		else if(!checkMail(oForm.email.value, oForm.email)) return false;
	
		if(oForm.email2.value==""){
			alert(orderAlert[7]);						
			oForm.email2.focus();
			return false;
		}
		else if(!checkMail(oForm.email2.value, oForm.email2)) return false;
	
		if(oForm.email.value!=oForm.email2.value){
			alert("E-postadresserna matchar inte varandra. Försök igen!");
			oForm.email2.value = "";						
			oForm.email2.focus();
			return false;
		
		}
	
		if(oForm.telno.value==""){
			alert(orderAlert[8]);
			oForm.telno.focus();
			return false;
		}

		if(oForm.Payment[0]!="undefined"&&oForm.Payment[0]!=null){//Danmark visar inget fält för personnummer
			if(oForm.Payment[0].checked){
				oForm.action = (oForm.Payment[0].value==4703)? shopActionFM:shopActionBP;
			}
		}
		else oForm.action = shopActionBP;	
		/* Case-> till Payex*/
		var payexText = ""
		if(oForm.country.value=="OS"){
			payexText = sentToPayex;
			if(confirm(payexText)){
				var payexUrl = "/web/payex.asp?CurrentOrderID="+oForm.CurrentOrderID.value+"&prodsPrice="+oForm.prodsPrice.value+"&currencyCase=SEK&ShopUserID="+oForm.ShopUserID.value+"&Baske="+oForm.Baske.value;
				oForm.action = shopActionPayex;
			}
			else return false;
		}
		else{
			if(oForm.Payment[1].checked&&oForm.Payment[1].value==8522){
				var payexText = ""
				if (oForm.country.value=="SE"||oForm.country.value=="OS") payexText = sentToPayex;
				else payexText = sentToPayex2;
				
				if(confirm(payexText)){
					var payexUrl = "/web/payex.asp?CurrentOrderID="+oForm.CurrentOrderID.value+"&prodsPrice="+oForm.prodsPrice.value+"&currencyCase=SEK&ShopUserID="+oForm.ShopUserID.value+"&Baske="+oForm.Baske.value;
					oForm.action = shopActionPayex;
				}
				else return false;
			}	
		}
		oForm.mode.value = "send";
		oForm.submit();
	}	
}

 function checkProductInfo(){
	var oForm = document.forms['productForm'];
 	if(oForm.ProductDescription.value==""){
		alert(orderAlert[14]);
		oForm.ProductDescription.focus();
		return false;		
	}
	return true	
}


function checkMail(sInputValue,oFormField){
	var myRe = /[a-z0-9_.=-]+@([a-z0-9-]+\.)+([a-z]{2,3})/i;
	if (!(sInputValue).match(myRe))	{
		alert(emailErrorML)
		oFormField.focus()
		return false
	}
	else {
		return true
	}
}

function closeWin(){
	win.close()
}

function setPerssonNr(oObj,iCase){
	if(oObj.pno!=null&&oObj.pno!="undefined"){
		if(iCase==0){
			document.getElementById("persnoSPAN").className = "redtext";
			document.getElementById("prioText").className = "";		
			document.getElementById("prioStart").className = "redtext";	
			oObj.action = shopActionFM;
			oObj.pno.style.backgroundColor = "#F4F4F4";
			oObj.pno.disabled = "";
			oObj.pno.focus();
			if(oObj.getAddressBtn!=null&&oObj.getAddressBtn!="undefined") oObj.getAddressBtn.style.display = "block";
			setPostCost(0);
		}
		else{
			document.getElementById("persnoSPAN").className = "greytext";
			document.getElementById("prioText").className = "greytext";		
			document.getElementById("prioStart").className = "greytext";
			oObj.action = shopActionBP;	
			oObj.pno.style.backgroundColor = "#cccccc";
			oObj.pno.value = "";
			oObj.pno.disabled = "disabled"
			oObj.villkor.checked = "";
			if(oObj.getAddressBtn!=null&&oObj.getAddressBtn!="undefined") oObj.getAddressBtn.style.display = "none";		
			if(iCase==5){
				//setPostCost(1);
				//document.forms[0].totalSumma.value
				//document.getElementById("totalSummaSPAN").innerHTML = parseFloat(document.getElementById("shipmentfeeSPAN").innerHTML)+parseFloat(document.forms[0].totalSumma.value);
			}
			else setPostCost(0);
		}
	}
}

function setPostCost(iCase){
	var postcostTRElm = document.getElementById("postcostTR");
	if(postcostTRElm!=null&&postcostTRElm!="undefined"){
		if(iCase==0){
			postcostTRElm.style.display = "none";
		}
		else{
			postcostTRElm.style.display = "block";
			
		}
	}
}

function setPaymentType_(oObj, iIndex){
	//if(oForm.country.options.selectedIndex>0){
		if(iIndex==0){
			document.getElementById("pnTR").style.display = "block";
			document.getElementById("pnTR").style.visibility = "visible";
			document.getElementById("persnoSPAN").innerHTML = "ÅÅMMDD-XXXX";
			oObj.action = shopActionFM;
			oObj.country.options.length = 0;
			oObj.country.options[0] = new Option(" - Välj land - ","");
			oObj.country.options[1] = new Option("Sverige","SE");
			oObj.country.options[2] = new Option("Norge","NO");
			oObj.country.options[3] = new Option("Finland","FI");	
			//oObj.country.options[4] = new Option("Danmark","DK");
			for(i=0;i<oObj.country.options.length;i++){
				if(oObj.country.options[i].value == cCountry ){
					oObj.country.options[i].selected=true  
				}
			}
		}
		else{
			document.getElementById("pnTR").style.display = "none";
			document.getElementById("pnTR").style.visibility = "hidden";
			oObj.action = shopActionBP;
			oObj.country.options.length = 0;
			oObj.country.options[0] = new Option(" - Välj land - ","");
			oObj.country.options[1] = new Option("Sverige","SE");
			if(iIndex==1){
				oObj.country.options[2] = new Option("Norge","NO");
				oObj.country.options[3] = new Option("Finland","FI");
				oObj.country.options[4] = new Option("Danmark","DK");
			}
			oObj.villkor.checked = false;
			//document.location.href = "#liveryLink";
		}	
		oObj.country.options.selectedIndex = 0;
		document.forms[0].shipmentfee.value = 0
		document.getElementById("shipmentfeeSPAN").innerHTML = 0
		document.getElementById("totalSummaSPAN").innerHTML = parseInt(document.forms[0].totalSumma.value);
	//}
	
}

function setShopSelectedBox(oSelect, sCase){
	alert(oSelect)
	oSelect.options.length = 0;
	switch(parseInt(sCase)){
		case 0:
			oSelect.options[0] = new Option(" - Välj land - ","");
			oSelect.options[1] = new Option("Sverige","SE");
			oSelect.options[2] = new Option("Norge","NO");
			oSelect.options[3] = new Option("Finland","FI");	
			//oSelect.options[4] = new Option("Danmark","DK");
		case 1:
			oSelect.options[0] = new Option(" - Välj land - ","");		
			oSelect.options[1] = new Option("Sverige","SE");
			oSelect.options[2] = new Option("Norge","NO");
			oSelect.options[3] = new Option("Finland","FI");	
			oSelect.options[4] = new Option("Danmark","DK");
		case 2:
			oSelect.options[0] = new Option(" - Välj land - ","");		
			oSelect.options[1] = new Option("Sverige","SE");
		case 3:
			oSelect.options[0] = new Option(" - Välj land - ","");		
			oSelect.options[1] = new Option("Sverige","SE");
		case 4:
			oSelect.options[0] = new Option(" - Välj land - ","");		
			oSelect.options[1] = new Option("Sverige","SE");			
		default:	
			oSelect.options[0] = new Option(" - Välj land - ","");		
			oSelect.options[1] = new Option("Sverige","SE");	
	}
	
	oSelect.options.selectedIndex = 0;

}


function setSAPNText(oSelect){
	if(oSelect.options[oSelect.options.selectedIndex].value=="FI"){
		document.forms["shoppingcart"].currencyV.value = 10;
	}
	else{
		document.forms["shoppingcart"].currencyV.value = 1
	}
	document.forms["shoppingcart"].mode.value = "";
	document.forms["shoppingcart"].action = hostPath + "/web/newshoppingcart.asp";
	document.forms["shoppingcart"].submit();	
}

function setCountryBox(sCase){
	var oSelectBox = document.forms["shoppingcart"].country;
	oSelectBox.options.selectedIndex = (sCase=="OS")? 5:1;
	setSAPNText(oSelectBox);
}

function setSAPNText_(oSelect){
	alert(oSelect.options[oSelect.options.selectedIndex].value)
	if(oSelect.options[oSelect.options.selectedIndex].value=="FI"){
		document.forms["shoppingcart"].currencyV.value = 10;
		document.forms["shoppingcart"].action = hostPath + "/web/newshoppingcart.asp"
		document.forms["shoppingcart"].submit();
	}
	if(oSelect.options[oSelect.options.selectedIndex].value=="SE"){	
		document.getElementById("persnoSPAN").innerHTML = "ÅÅMMDD-XXXX";
		document.forms["shoppingcart"].currencyV.value = 1
		document.forms["shoppingcart"].action = hostPath + "/web/newshoppingcart.asp"
		document.forms["shoppingcart"].submit();		
	}
	else{
		document.getElementById("persnoSPAN").innerHTML = "ÅÅMMDDXXXXX";
		document.forms["shoppingcart"].currencyV.value = 1
		document.forms["shoppingcart"].action = hostPath + "/web/newshoppingcart.asp"
		document.forms["shoppingcart"].submit();				
	}
	//document.forms[0].shipment.value = oSelect.options[oSelect.options.selectedIndex].value
	if(oSelect.options.selectedIndex>1) document.forms[0].shipmentfee.value = 22;
	else document.forms[0].shipmentfee.value = 0;
	document.getElementById("shipmentfeeSPAN").innerHTML = document.forms[0].shipmentfee.value/currencyCase;
	document.getElementById("totalSummaSPAN").innerHTML = parseFloat(document.getElementById("shipmentfeeSPAN").innerHTML)+parseFloat(document.forms[0].totalSumma.value);
}

function setVillkorBox(oForm, oObj){
	if(oObj.checked){
		oForm.Payment[0].checked = true;
		setPerssonNr(oForm,0)
		//setPaymentType(oForm, 0);
		//document.location.href = "#liveryLink";
	}
}

function getCustemerAdress(){
	var oForm = document.forms['shoppingcart'];
	if(oForm.pno.value!=""){
		makeRequest("/web/shop_get_addresses_customer.asp","pno="+oForm.pno.value+"&pnoencoding="+oForm.pnoencoding.value+"&atype=old&eid=1471&secret="+oForm.secret.value+"&rnd="+Math.random(),"GET", document.getElementById("ajaxDiv"), null);					
	}
	else{
		alert("Ange ditt persornummer!");
		oForm.pno.focus();
	}
}

function alertContents(http_request, oDiv){ //Det är hit vi kommer sen

	if (http_request.readyState == 4){ //Om allt har laddat klart...
		if (http_request.status == 200){ //kontrollera ifall allt är OK, för isåfall...
			if(oDiv!=null){
				oDiv.innerHTML = convertStr(http_request.responseText);//hämta texten och visa den i en DIV (lajv)
				setCustomerAddress();			
			}	
			else{	
				//alert(http_request.responseText)
				document.getElementById('ajaxDiv').innerHTML = convertStr(http_request.responseText); //hämta texten och visa den i en DIV (lajv)
				setCustomerAddress();
			}
		}
		else{
			if(oDiv!=null) oDiv.innerHTML = adm_AjaxRequestError; //...annars så har något gått snett
			else document.getElementById('ajaxDiv').innerHTML = adm_AjaxRequestError; //...annars så har något gått snett
		}
	}
}

function convertStr(sStr) {
	sStr = sStr.replace(/&quot;/gi, '"');
    sStr = sStr.replace(/&apos;/gi, "'");
    sStr = sStr.replace(/&gt;/gi,   ">");
    sStr = sStr.replace(/&lt;/gi,   "<");
    sStr = sStr.replace(/&amp;/gi,  "&");
    return sStr;
}	

function setCustomerAddress(){
	var oForm = document.forms['shoppingcart'];
	if(oForm.cAddress0!=null&&oForm.cAddress0!="undefined"){
		oForm.fname.value = oForm.cAddress0.value;	
		oForm.lname.value = oForm.cAddress1.value;
		oForm.street.value = oForm.cAddress2.value;
		oForm.postno.value = oForm.cAddress3.value;
		oForm.city.value = oForm.cAddress4.value;
		oForm.telno.focus();	
	}
	else{
		alert(document.getElementById('ajaxDiv').innerText);
		oForm.pno.focus();
	}
}