//v1.2 070118
//1.3 070723
function saveForm() {
	if (window.location.href.indexOf('ps1') > 0 )  { 
		var tmp="";
		for (var i=0; i < document.form.elements.length; i++) 
			tmp = tmp + document.form.elements[i].name+'='+document.form.elements[i].value+',';
			
		//alert (tmp)
		setCookie("formcontents",tmp);
	}
}

function loadForm() {
	if (window.location.href.indexOf('ps1') > 0 )  { 
		contents =  readCookie();
		if (contents == undefined) return;
		aPairs = contents.split(",");
		for(var i=0;i<aPairs.length;i++) {
			//aPairs[i]= aPairs[i].replace(" ","");
			atmp = aPairs[i].split("=");
			//alert(atmp[0] + '=' + atmp[1]);
			atmp[0]= atmp[0].replace(" ",""); 
			if (atmp[1] != "" && atmp[0] != "" && atmp[0].indexOf('submit') < 0 ) document.form[atmp[0]].value = atmp[1];
		}
	}
	
}

function setCookie(key,value) {
	 var cookieDate = new Date(2010,11,10,19,30,30);
	 document.cookie=key + "=" + escape(value) + "; expires=" + cookieDate.toGMTString(  ) + "; path=/";
}

function readCookie() {
	a=document.cookie.split(";");
	for(var i=0;i<a.length;i++) {
		if (i>100) break; 
		if (a[i].indexOf("formcontents") >= 0) {
			contents = unescape(a[i].replace("formcontents=",""));
			//alert("cookie :"+contents);
			return(contents);
		}
	} 
}    

function bla(){ 
	alert("bla");
}	

function validate1() {
	alert("validate" + document.form);
	var isFull = checkforblanks(document.form.upload.value);

	if (!isFull) {
	 return false;
	}
}

function validateStep1() {
	if ((document.form.type[0].checked==false) && (document.form.type[1].checked==false) 
	&& (document.form.type[2].checked==false) && (document.form.type[3].checked==false) && (document.form.type[4].checked==false) && (document.form.type[5].checked==false)) {
		lang == "nl"?alert("Kies een type a.u.b."):alert("Please enter a type");  
		return false;
	}
}

function validateStep3() {
	//alert("validate" + document.form.dest);
	if ((document.form.dest[0].checked==false) && (document.form.dest[1].checked==false)
		&& (document.form.dest[2].checked==false) ) {
		lang == "nl"?alert("Voer een bestemming in a.u.b."):alert("Please enter a destination");  
		return false;
	}
}

function validateStep5() {
	//alert("validate" + document.form.akkoord.value);
	var subm =document.getElementById("akkoord"); 
	if (!subm.checked) {
		lang == "nl"?alert("Accepteer gaarne onze voorwaarden"):alert("Please accept our terms");
		return false;
	}
	else window.location='?f=px_ps1';
}

function calcprice(i,type) {
	var nrmsg = (lang=="nl")?"Voer gaarne een getal in.":"Please enter a number";

	var nr =eval("document.form.nr"+i);
	var pr =eval("document.form.price"+i);

	if (!checkforblanknrs(nr.value,nrmsg)) {
			nr.focus();nr.select();
			return false;
	}  
							
	if (type == "TCD") {
		pr.value = nr.value * pr.value; 
		return;
	}

	var psw = eval("document.form.psw"+i);
	var psh = eval("document.form.psh"+i); 

//var dim = ps.value.match(/\d+/g);      //45,45
	var w = psw.value.match(/\d+/);
	var h = psh.value.match(/\d+/);

	//090602
	if (eval("document.form.tc"+i) != undefined)   {
		var tc = eval("document.form.tc"+i);

		if (tc.options[tc.options.selectedIndex].value == "6040") {   //tb
			w = 60;    h = 40;
			var min = aPrices[5];  //091016
		}
		else if (tc.options[tc.options.selectedIndex].value == "4545"){  //tb
			w = 45;    h = 45;    
			var min = aPrices[5];                                               
		}

		if (tc.options[tc.options.selectedIndex].value == "6060") {   //tc
			w = 60;    h = 60;
			var min = aPrices[7]; 
		}
		else if (tc.options[tc.options.selectedIndex].value == "7550"){   //tc
			w = 75;    h = 50;    
			var min = aPrices[7]; 
		}
		//091007
		//090515
		psw.value = w;  
		psh.value = h;

		//alert (w+ "+"+h);
	}

	else { //091016

		if (h == undefined  || h == 0  || w == undefined  || w == 0) 
			pr.value =0;
		else {
			//lang == "nl"?alert("Afmeting mag maximaal 30cm zijn"):alert("Maximum size is 30cm");
			if (type ==30) {
				var min = aPrices[3];
				if (h>40) {
					psh.value=40; 
				}
				if (w>40) {
					psw.value=40; 
				} 
				if (parseInt(h) + parseInt(w) > 70) { psh.value=0;  psw.value=0;  alert("max 30x40 of 40x30");}       //110616
			}
			else if (type ==45) {
				var min = aPrices[5];  
				if (h>45) {
					psh.value=45; 
				}
				 if (w>45) {
					psw.value=45; 
				}
			} 
			else if (type ==50) {
				var min = aPrices[7];  
				if (h>200) {
					psh.value=200;
				}
				 if (w>120) {
					psw.value=120; 
				}
			}   
			else if (type == "alg") {   //table
				pr.value = nr.value * 35; 
				return;
			}   
		}

	}   
	var totalsize = w * h;        //2805
	for (i=0; i < aPrices.length; i++) {
			if  (totalsize < aPrices[i]) {      //3000
				 break;
			}
			i++;
	}
	var total = nr.value * aPrices[i-1];
	pr.value= total;
	if (aPrices[i-1] < min) 
		pr.value = nr.value * min;
	
		//var aPrices = new Array (
//   1        3        5        7
//0,25, 1200,25, 2025,75, 2500,95, 3000,115, 3500,135 ,4000,155, 4800,185, 5400,210,6000,230, 7000,270, 8000,310, 9000,350, 10000,390, 100000,390
	
	//  alert("type: "+type+" totalprice : "+total+" minprice: "+min+" totsz:"+totalsize+" ,ap i: "+aPrices[i]+" len: "+aPrices.length);


}
		
function validateNrs(total) {
//  alert("validatenrs : " + total);
//  
	for (var i=0; i < total; i++) {
		//alert("ps: "+document.form.ps0.value);
		
		var nr =eval("document.form.nr"+i);
		//alert("nr" + i + " : " + elm.value);
		var psmsg = (lang=="nl")?"Voer gaarne een geldige afmeting in.":"Please enter a valid size";     
		var nrmsg = (lang=="nl")?"Voer gaarne een getal in.":"Please enter a number";
		//alert(msg);
		if (!checkforblanks(nr.value,nrmsg) || nr.value == 0) {
			nr.focus();nr.select();
			return false;
		}  

		var psw = eval("document.form.psw"+i);
		if (psw == undefined) continue;     //coupon

		var psh = eval("document.form.psh"+i); 

		var w = psw.value.match(/\d+/);
		var h = psh.value.match(/\d+/);
		
		//alert("dim: "+dim[0] + " ,"+dim[1]);
		//if (dim[0] == undefined  || dim[0] == 0 || dim[1] == undefined || dim[1] == 0) {
		if (h == undefined  || h == 0) {  
			alert(psmsg);
			psh.focus();psh.select();
			return false;
		} 
		if (w == undefined  || w == 0) {
			alert(psmsg);
			psw.focus();psw.select();
			return false;
		} 
		
	
	}  
	 
	return true;
}

var emailregex = /^[a-z][a-z\-\_0-9\.]+@[a-z-_0-9\.]+\.[a-z]{2,4}$/i

function correct_email(str) {
				return emailregex.test(str)
}

function validateEmail() {
	if(!correct_email(document.form.email.value)) {
		lang=="nl"?alert("Ongeldig E-mail adres !"):alert("Not a valid email address !");
		document.form.email.focus()
		document.form.email.select()
		return false	
	}
	return true
}


function checkforblanks() {
	for (var i = 0; i < arguments.length; i += 2) {
		if (!arguments[i])  {
			if (lang=="nl") alert("We missen uw " + arguments[i+1] + ".");
			else alert("Your " + arguments[i+1] + " is missing.");
			return false;
		}
	}
	return true;
}


function checkforblanknrs()   {
	for (var i = 0; i < arguments.length; i += 2)    {
		if (!arguments[i]) {
			alert(arguments[i+1]);
			return false;}
	}
	return true;
}

function validate() {
	if (lang=="nl") 
		var isFull = checkforblanks( 
document.form.firstname.value, "voornaam",
document.form.lastname.value, "achternaam",
document.form.street.value, "straat en huisnummer",
document.form.city.value, "stad",
document.form.phone.value, "telefoonnummer",
document.form.zip.value, "postcode",
document.form.country.value, "landkeuze",
document.form.email.value, "e-mail adres");

	else 
		var isFull = checkforblanks( 
document.form.firstname.value, "first name",
document.form.lastname.value, "last name",
document.form.street.value, "street name",
document.form.city.value, "city",
document.form.state.value, "state",
document.form.zip.value, "postal code",
document.form.country.value, "country",
document.form.phone.value, "phone nr",
document.form.email.value, "e-mail address");

	if (!isFull || !validateEmail()) {
		return false;
	}
		
	//prevent user clicking twice
	document.getElementById('submit').disabled=true;   
}
	
	var emailregex = /^[a-z][a-z\-\_0-9\.]+@[a-z-_0-9\.]+\.[a-z]{2,4}$/i

function correct_email(str) {
				return emailregex.test(str)
}

/*  EN 

function validate()
	{
	var isFull = checkforblanks( 
document.form.firstname.value, "your first name",
document.form.lastname.value, "your last name",
document.form.street.value, "your street name",
document.form.city.value, "your city",
document.form.state.value, "your state",
document.form.zip.value, "your postal code",
document.form.country.value, "your country",
document.form.phone.value, "your phone nr",
document.form.email.value, "your e-mail address");

	if (!isFull || !validateEmail())
		{return false;}
		
			//prevent user clicking twice
	document.getElementById('submit').disabled=true; 
}
	
	var emailregex = /^[a-z][a-z\-\_0-9\.]+@[a-z-_0-9\.]+\.[a-z]{2,4}$/i

function correct_email(str) {
				return emailregex.test(str)
}

function validateEmail() {
	if(!correct_email(document.form.email.value)) {
		alert("Not a valid email address !")
		document.form.email.focus()
		document.form.email.select()
		return false  
	}
	return true
}

/*
function checkforblanks()   {
	for (var i = 0; i < arguments.length; i += 2)    {
		if (!arguments[i]) {
			alert(arguments[i+1]);
			return false;}
	}
	return true;
}
*/

