//v1.2 070118
function bla(){ 
	alert("bla");
}	

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

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)) {
    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) && (document.form.dest[3].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);
	if (!document.form.akkoord.checked) {
		lang == "nl"?alert("Accepteer gaarne onze voorwaarden"):alert("Please accept our terms");
		return false;
	}
}

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

  var psw = eval("document.form.psw"+i);
  var psh = eval("document.form.psh"+i); 
  var nr =eval("document.form.nr"+i);
  var pr =eval("document.form.price"+i);
  
  if (!checkforblanks(nr.value,nrmsg)) {
      nr.focus();nr.select();
      return false;
  }  
  //var dim = ps.value.match(/\d+/g);      //45,45
  var w = psw.value.match(/\d+/);
  var h = psh.value.match(/\d+/);
    
  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>30) {
        psh.value=30; 
      }
       if (w>40) {
        psw.value=40; 
      }
    }
    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>100) {
        psh.value=100;
      }
       if (w>100) {
        psw.value=100; 
      }
    }   
    else if (type == "alg") {
      var min = aPrices[1];  
      if (h>hmax) {
        psh.value=hmax; 
      }
       if (w>wmax) {
        psw.value=wmax; 
      }
    }   
    
    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 psw = eval("document.form.psw"+i);
    var psh = eval("document.form.psh"+i); 
    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);
    //var dim = ps.value.match(/\d+/g);      //45,45
    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;
    } 
    
    if (!checkforblanks(nr.value,nrmsg) || nr.value == 0) {
      nr.focus();nr.select();
      return false;
    }  
  }  
   
  return true;
}

/*
wordt (nog) niet gebruikt
function validate()  {
	if (lang == "nl") {
	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.email.value, "your e-mail address");
	}
	else {
	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.email.value, "your e-mail address");
	}
	if (!isFull || !validateEmail()) 		{
		return false;
	}
}*/
	
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
}
