// JavaScript Document

function basketRedirect(){
parent.location.href="?extEvent=basketStep4";
}

function condPurchase() {
smallWin = window.open('conditionsPurchase.asp','conditionsPurchase','width=400,height=400,resize=no,scrollbars=yes');
}

function popupWin() {
smallWin = window.open('popupWin.asp','popupWin','width=400,height=550,resize=no,scrollbars=yes');
}

function validateUnregisteredUser() {
var cForm = document.customerProfile;
var strStatement;
var strFds;
var requiredFds;

requiredFds = 0;
strStatement = "Du har inte fyllt i alternativ i följande fält:\n\n";
strFds = "\n";

	if(cForm.customerName.value.length < 1){
	strFds = strFds + "Namn/företag\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.address.value.length < 1){
	strFds = strFds + "Adress\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.postal.value.length < 4){
	strFds = strFds + "Postnr\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.city.value.length < 1){
	strFds = strFds + "Ort\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.customerContact.value.length < 1){
	strFds = strFds + "Kontakt\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.conditionsPurchase.checked != true){
	strFds = strFds + "Godkännande av Parmas köpvillkor\n";
	requiredFds = requiredFds + 1;
	}
strFds = strFds + "\n";

	if(requiredFds == 0){
	return true;
	}
	else{
	alert(strStatement + strFds);
	return false;
	}
}

function validateCustomerProfile() {
var cForm = document.customerProfile;
var strStatement;
var strFds;
var requiredFds;

requiredFds = 0;
strStatement = "Du har inte fyllt i alternativ i följande fält:\n\n";
strFds = "\n";

	if(cForm.conditionsPurchase.checked != true){
	strFds = strFds + "Godkännande av Parmas köpvillkor\n";
	requiredFds = requiredFds + 1;
	}
strFds = strFds + "\n";

	if(requiredFds == 0){
	return true;
	}
	else{
	alert(strStatement + strFds);
	return false;
	}
}

function validateCustomerProfile_2() {
var cForm = document.customerProfile;
var strStatement;
var strFds;
var requiredFds;

requiredFds = 0;
strStatement = "Du har inte fyllt i alternativ i följande fält:\n\n";
strFds = "\n";

	if(cForm.customerContact.value.length < 1){
	strFds = strFds + "Kontakt\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.address.value.length < 1){
	strFds = strFds + "Adress\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.postal.value.length < 6){
	strFds = strFds + "Postnr\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.city.value.length < 1){
	strFds = strFds + "Ort\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.customerMail.value.length < 1){
	strFds = strFds + "Epost\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.phone.value.length < 1){
	strFds = strFds + "Tel\n";
	requiredFds = requiredFds + 1;
	}

strFds = strFds + "\n";

	if(requiredFds == 0){
	return true;
	}
	else{
	alert(strStatement + strFds);
	return false;
	}
}

function validateFreeArticles() {
var el = document.forms[0].elements;
	for(var i = 0 ; i < el.length ; ++i){
		if(el[i].type == "radio"){
		var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
		var itemchecked = false;
			for(var j = 0 ; j < radiogroup.length ; ++j){
				if(radiogroup[j].checked){
				itemchecked = true;
				break;
				}
			}
			if(!itemchecked) { 
			alert("Var god välj valfri artikel.\n");
			return false;
			}
			else{
			return true;
			}
		}
	}
}

function addToBasket(itemForm) {
var itemForm;
var oForm = document.forms[itemForm];

	if(oForm.addon.value == 1){
		if(oForm.addonProductId.value < 1){
		alert("Var god välj valfri tillvalsprodukt i rullisten\n för den produkt du vill lägga i varukorgen.")
		return false;
		}
		else{
		return true;
		}
	}
	else{
	return true;
	
	}
}

function validatePaymentType() {
var pForm = document.paymentForm;
var strStatement;
var strFds;
var requiredFds;
var el = document.forms["paymentForm"].elements;

requiredFds = 0;
strStatement = "Du har inte fyllt i alternativ i följande fält:\n\n";
strFds = "\n";

	for(var i = 0 ; i < el.length ; ++i){
		if(el[i].type == "radio"){
		var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
		var itemchecked = false;
			for(var j = 0 ; j < radiogroup.length ; ++j){
				if(radiogroup[j].checked){
				itemchecked = true;
				break;
				}
			}
		}
	}

	if(!itemchecked) { 
	strFds = strFds + "Betalningssätt\n";
	requiredFds = requiredFds + 1;
	}

	if(requiredFds == 0){
	return true;
	}
	else{
	alert(strStatement + strFds);
	return false;
	}
}

function validateShipmentType() {
var pForm = document.shipmentForm;
var strStatement;
var strFds;
var requiredFds;
var el = document.forms["shipmentForm"].elements;

requiredFds = 0;
strStatement = "Du har inte fyllt i alternativ i följande fält:\n\n";
strFds = "\n";

	for(var i = 0 ; i < el.length ; ++i){
		if(el[i].type == "radio"){
		var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
		var itemchecked = false;
			for(var j = 0 ; j < radiogroup.length ; ++j){
				if(radiogroup[j].checked){
				itemchecked = true;
				break;
				}
			}
		}
	}

	if(!itemchecked) { 
	strFds = strFds + "Leveranssätt\n";
	requiredFds = requiredFds + 1;
	}

	if(requiredFds == 0){
	return true;
	}
	else{
	alert(strStatement + strFds);
	return false;
	}
}

function validateUserPaymentType1() {
var cForm = document.customerProfile;
var strStatement;
var strFds;
var requiredFds;

requiredFds = 0;
strStatement = "Du har inte fyllt i alternativ i följande fält:\n\n";
strFds = "";

	if(cForm.customerFirstName.value.length < 1){
	strFds = strFds + "Förnamn\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.customerLastName.value.length < 1){
	strFds = strFds + "Efternamn\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.address.value.length < 1){
	strFds = strFds + "Adress\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.postal.value.length < 4){
	strFds = strFds + "Postnr\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.city.value.length < 1){
	strFds = strFds + "Ort\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.customerMail.value.length > 0){
		if(cForm.customerMail.value.search("@") == -1 || cForm.customerMail.value.search(".") == -1){
		strFds = strFds + "E-post\n";
		requiredFds = requiredFds + 1;
		}
	}

if(cForm.conditionsPurchase.checked != true){
	strFds = strFds + "Godkännande av Parmas köpvillkor\n";
	requiredFds = requiredFds + 1;
	}

	if(requiredFds == 0){
	return true;
	}
	else{
	alert(strStatement + strFds);
	return false;
	}
}

function validateUserPaymentType2() {
var cForm = document.customerProfile;
var strStatement;
var strFds;
var requiredFds;

requiredFds = 0;
strStatement = "Du har inte fyllt i alternativ i följande fält:\n\n";
strFds = "";

	if(cForm.customerFirstName.value.length < 1){
	strFds = strFds + "Förnamn\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.customerLastName.value.length < 1){
	strFds = strFds + "Efternamn\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.address.value.length < 1){
	strFds = strFds + "Adress\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.postal.value.length < 4){
	strFds = strFds + "Postnr\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.city.value.length < 1){
	strFds = strFds + "Ort\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.customerMail.value.length > 0){
		if(cForm.customerMail.value.search("@") == -1 || cForm.customerMail.value.search(".") == -1){
		strFds = strFds + "E-post\n";
		requiredFds = requiredFds + 1;
		}
	}

if(cForm.conditionsPurchase.checked != true){
	strFds = strFds + "Godkännande av Parmas köpvillkor\n";
	requiredFds = requiredFds + 1;
	}

	if(requiredFds == 0){
	return true;
	}
	else{
	alert(strStatement + strFds);
	return false;
	}
}

function validateUserPaymentType3() {
var cForm = document.customerProfile;
var strStatement;
var strFds;
var requiredFds;

requiredFds = 0;
strStatement = "Du har inte fyllt i alternativ i följande fält:\n\n";
strFds = "";

	if(cForm.socialNumber.value.length != 10){
	strFds = strFds + "Personnummer\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.customerFirstName.value.length < 1){
	strFds = strFds + "Förnamn\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.customerLastName.value.length < 1){
	strFds = strFds + "Efternamn\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.address.value.length < 1){
	strFds = strFds + "Adress\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.postal.value.length < 4){
	strFds = strFds + "Postnr\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.city.value.length < 1){
	strFds = strFds + "Ort\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.customerMail.value.length > 0){
		if(cForm.customerMail.value.search("@") == -1 || cForm.customerMail.value.search(".") == -1){
		strFds = strFds + "E-post\n";
		requiredFds = requiredFds + 1;
		}
	}

if(cForm.conditionsPurchase.checked != true){
	strFds = strFds + "Godkännande av Parmas köpvillkor\n";
	requiredFds = requiredFds + 1;
	}

	if(requiredFds == 0){
	return true;
	}
	else{
	alert(strStatement + strFds);
	return false;
	}
}

function validateUserPaymentType4() {
var cForm = document.customerProfile;
var strStatement;
var strFds;
var requiredFds;

requiredFds = 0;
strStatement = "Du har inte fyllt i alternativ i följande fält:\n\n";
strFds = "\n";

	if(cForm.customerContact.value.length < 1){
	strFds = strFds + "Kontakt\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.address.value.length < 1){
	strFds = strFds + "Adress\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.postal.value.length < 6){
	strFds = strFds + "Postnr\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.city.value.length < 1){
	strFds = strFds + "Ort\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.customerMail.value.length < 1){
	strFds = strFds + "Epost\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.phone.value.length < 1){
	strFds = strFds + "Tel\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.conditionsPurchase.checked != true){
	strFds = strFds + "Godkännande av Parmas köpvillkor\n";
	requiredFds = requiredFds + 1;
	}
strFds = strFds + "\n";

	if(requiredFds == 0){
	return true;
	}
	else{
	alert(strStatement + strFds);
	return false;
	}
}

function validateUserPaymentType5() {
var cForm = document.customerProfile;
var strStatement;
var strFds;
var requiredFds;

requiredFds = 0;
strStatement = "Du har inte fyllt i alternativ i följande fält:\n\n";
strFds = "";

	if(cForm.socialNumber.value.length != 10){
	strFds = strFds + "Personnummer\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.customerFirstName.value.length < 1){
	strFds = strFds + "Förnamn\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.customerLastName.value.length < 1){
	strFds = strFds + "Efternamn\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.address.value.length < 1){
	strFds = strFds + "Adress\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.postal.value.length < 4){
	strFds = strFds + "Postnr\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.city.value.length < 1){
	strFds = strFds + "Ort\n";
	requiredFds = requiredFds + 1;
	}
	if(cForm.customerMail.value.length > 0){
		if(cForm.customerMail.value.search("@") == -1 || cForm.customerMail.value.search(".") == -1){
		strFds = strFds + "E-post\n";
		requiredFds = requiredFds + 1;
		}
	}

if(cForm.conditionsPurchase.checked != true){
	strFds = strFds + "Godkännande av Parmas köpvillkor\n";
	requiredFds = requiredFds + 1;
	}

	if(requiredFds == 0){
	return true;
	}
	else{
	alert(strStatement + strFds);
	return false;
	}
}

function submitForm(oForm) {
var oForm;
   if(document.forms[oForm].onsubmit && !document.forms[oForm].onsubmit()){
        return;
    }
 document.forms[oForm].submit();
}

function emptyField(fld) {
var oField = fld; 
oField.value = "";
}

function validateSearchForm() {
var searchForm = document.searchForm;
	if(searchForm.searchStr.value == "Sök på parma.se...") {
	searchForm.searchStr.value = "";
	searchForm.searchStr.focus();
	return false;
	}
}

function productNotify(itemForm) {
var itemForm;
var oForm = document.forms[itemForm];
var strStatement;
var strFds;
var requiredFds;

requiredFds = 0;
strStatement = "Du har inte fyllt i alternativ i följande fält:\n\n";
strFds = "\n";

	if(oForm.notifyEmailPhone.value.length < 1){
	strFds = strFds + "E-post\n";
	requiredFds = requiredFds + 1;
	}

strFds = strFds + "\n";

	if(requiredFds == 0){
	return true;
	}
	else{
	alert(strStatement + strFds);
	return false;
	}
}
