/// Send message to Suydersee
function validateofferteformulierFormOnSubmit(theForm){
var reason = "";
	if(theForm.offerteformulier_name.value.length == 0){
		reason += "Please enter your naam!\n";
		theForm.offerteformulier_name.style.background = '#FFFF99'; 
	}else{
		theForm.offerteformulier_name.style.background = 'White'; 
	}

	if(theForm.offerteformulier_adres.value.length == 0){
		reason += "Please enter your adres!\n";
		theForm.offerteformulier_adres.style.background = '#FFFF99'; 
	}else{
		theForm.offerteformulier_adres.style.background = 'White'; 
	}

	reason += validateEmail(theForm.offerteformulier_email);

	if(theForm.offerteformulier_activiteiten.value.length == 0){
		reason += "Please enter your korte omschrijving activiteiten!\n";
		theForm.offerteformulier_activiteiten.style.background = '#FFFF99'; 
	}else{
		theForm.offerteformulier_activiteiten.style.background = 'White'; 
	}

	if(theForm.offerteformulier_afgelopen.value.length == 0){
		reason += "Please enter your jaaromzet over het afgelopen jaar!\n";
		theForm.offerteformulier_afgelopen.style.background = '#FFFF99'; 
	}else{
		theForm.offerteformulier_afgelopen.style.background = 'White'; 
	}

	if(theForm.offerteformulier_jaaromzet.value.length == 0){
		reason += "Please enter your geschatte jaaromzet huidig jaar!\n";
		theForm.offerteformulier_jaaromzet.style.background = '#FFFF99'; 
	}else{
		theForm.offerteformulier_jaaromzet.style.background = 'White'; 
	}

	if(theForm.offerteformulier_persoonlijk.value.length == 0){
		reason += "Please enter your ik wil eerst graag een persoonlijk gesprek ja/nee!\n";
		theForm.offerteformulier_persoonlijk.style.background = '#FFFF99'; 
	}else{
		theForm.offerteformulier_persoonlijk.style.background = 'White'; 
	}

	if(theForm.secure_num.value == 0){
		reason += "Please enter veiligheids code!\n";
		theForm.secure_num.style.background = '#FFFF99'; 
	}else{
		theForm.secure_num.style.background = 'White';
	}

	if (reason != "") {
		alert("Yellow fields need correction:\n" + reason);
		return false;
	}

  return true;
}


function validateContactFormOnSubmit(theForm){
var reason = "";
	if(theForm.customer_name.value.length == 0){
		reason += "Please enter your name!\n";
		theForm.customer_name.style.background = '#FFFF99'; 
	}else{
		theForm.customer_name.style.background = 'White'; 
	}

	reason += validateEmail(theForm.customer_email);

	if(theForm.customer_country_code.value.length != 0){
		if(isNaN(theForm.customer_country_code.value)){
			reason += "Your country code must be digit only!\n";
			theForm.customer_country_code.style.background = '#FFFF99'; 
		}else{
			theForm.customer_country_code.style.background = 'White'; 
		}
	}else{
		reason += "Please enter country code!\n";
		theForm.customer_country_code.style.background = '#FFFF99'; 
	}

	if(theForm.customer_area_code.value.length != 0){
		if(isNaN(theForm.customer_area_code.value)){
			reason += "Your country code must be digit only!\n";
			theForm.customer_area_code.style.background = '#FFFF99'; 
		}else{
			theForm.customer_area_code.style.background = 'White'; 
		}
	}else{
		reason += "Please enter area code!\n";
		theForm.customer_area_code.style.background = '#FFFF99'; 
	}

	if(theForm.customer_phone.value.length != 0){
		if(isNaN(theForm.customer_phone.value)){
			reason += "Your phone must be digit only!\n";
			theForm.customer_phone.style.background = '#FFFF99'; 
		}else{
			theForm.customer_phone.style.background = 'White'; 
		}
	}else{
		reason += "Please enter phone number!\n";
		theForm.customer_phone.style.background = '#FFFF99'; 
	}
	
	if(theForm.customer_message.value.length == 0){
		reason += "Please enter message!\n";
		theForm.customer_message.style.background = '#FFFF99'; 
	}else{
		theForm.customer_message.style.background = 'White'; 
	}

	if(theForm.secure_num.value == 0){
		reason += "Please enter security number!\n";
		theForm.secure_num.style.background = '#FFFF99'; 
	}else{
		theForm.secure_num.style.background = 'White';
	}

	if (reason != "") {
		alert("Yellow fields need correction:\n" + reason);
		return false;
	}

  return true;
}

function validateWijzigingen(theForm){
var reason = "";
	if(theForm.naam_verzekerde.value.length == 0){
		reason += "Please enter your name!\n";
		theForm.naam_verzekerde.style.background = '#FFFF99'; 
	}else{
		theForm.naam_verzekerde.style.background = 'White'; 
	}

	if(theForm.adres_verzekerde.value.length == 0){
		reason += "Please enter your name!\n";
		theForm.adres_verzekerde.style.background = '#FFFF99'; 
	}else{
		theForm.adres_verzekerde.style.background = 'White'; 
	}

	if(theForm.postcode_plaatsnaam_verzekerde.value.length == 0){
		reason += "Please enter your name!\n";
		theForm.postcode_plaatsnaam_verzekerde.style.background = '#FFFF99'; 
	}else{
		theForm.postcode_plaatsnaam_verzekerde.style.background = 'White'; 
	}

	if(theForm.tel.value.length == 0){
		reason += "Please enter your name!\n";
		theForm.tel.style.background = '#FFFF99'; 
	}else{
		theForm.tel.style.background = 'White'; 
	}

	reason += validateEmail(theForm.email);

	if (reason != "") {
		alert("Yellow fields need correction:\n" + reason);
		return false;
	}

  return true;
}

function validateProfileFormOnSubmit(theForm){
var reason = "";
	if(theForm.achternaam.value.length == 0){
		reason += "Please enter achternaam!\n";
		theForm.achternaam.style.background = '#FFFF99'; 
	}else{
		theForm.achternaam.style.background = 'White'; 
	}
	
	if(theForm.voorletters.value.length == 0){
		reason += "Please enter voorletters!\n";
		theForm.voorletters.style.background = '#FFFF99'; 
	}else{
		theForm.voorletters.style.background = 'White'; 
	}

	if(theForm.geslacht.value.length == 0){
		reason += "Please enter Geslacht!\n";
		theForm.geslacht.style.background = '#FFFF99'; 
	}else{
		theForm.geslacht.style.background = 'White'; 
	}

	if(theForm.straat_huisnummer.value.length == 0){
		reason += "Please enter Straat en huisnummer!\n";
		theForm.straat_huisnummer.style.background = '#FFFF99'; 
	}else{
		theForm.straat_huisnummer.style.background = 'White'; 
	}
	reason += validateEmail(theForm.email);

	if (reason != "") {
		alert("Yellow fields need correction:\n" + reason);
		return false;
	}

  return true;
}

function validateSchadeaangifteFormOnSubmit(theForm){
var reason = "";
	if(theForm.naam_van_de_verzekerde.value.length == 0){
		reason += "Please enter Naam van de verzekerde!\n";
		theForm.naam_van_de_verzekerde.style.background = '#FFFF99'; 
	}else{
		theForm.naam_van_de_verzekerde.style.background = 'White'; 
	}
	
	if(theForm.straat_en_huisnummer1.value.length == 0){
		reason += "Please enter Straat en huisnummer!\n";
		theForm.straat_en_huisnummer1.style.background = '#FFFF99'; 
	}else{
		theForm.straat_en_huisnummer1.style.background = 'White'; 
	}

	if(theForm.straat_en_huisnummer2.value.length == 0){
		reason += "Please enter Straat en huisnummer!\n";
		theForm.straat_en_huisnummer2.style.background = '#FFFF99'; 
	}else{
		theForm.straat_en_huisnummer2.style.background = 'White'; 
	}

	if(theForm.postcode_en_plaatsnaam1.value.length == 0){
		reason += "Please enter Postcode en plaatsnaam!\n";
		theForm.postcode_en_plaatsnaam1.style.background = '#FFFF99'; 
	}else{
		theForm.postcode_en_plaatsnaam1.style.background = 'White'; 
	}

	if(theForm.postcode_en_plaatsnaam2.value.length == 0){
		reason += "Please enter Postcode en plaatsnaam!\n";
		theForm.postcode_en_plaatsnaam2.style.background = '#FFFF99'; 
	}else{
		theForm.postcode_en_plaatsnaam2.style.background = 'White'; 
	}

	if(theForm.telefoon_prive.value.length == 0){
		reason += "Please enter Telefoon prive!\n";
		theForm.telefoon_prive.style.background = '#FFFF99'; 
	}else{
		theForm.telefoon_prive.style.background = 'White'; 
	}
	reason += validateEmail(theForm.email);

	if (reason != "") {
		alert("Yellow fields need correction:\n" + reason);
		return false;
	}

  return true;
}

function validateFormOnSubmit(theForm,randomStr){
    var reason = "";
	if(theForm.member_province_id.value=="-1"){
			reason += "Please select Country\n";
			theForm.member_province_id.style.background = '#FFFF99'; 
	}else{
			 theForm.member_province_id.style.background = 'White';
	}
	//reason += validateEmpty(theForm.member_type);
	var btn = valButton(theForm.member_type);
	if (btn==null){
		reason +="Please select Member Type (You are a..)\n";
	}
	function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
	}
	
	//reason += validateEmpty(theForm.have_website);
	var btn2 = valButton2(theForm.member_havewebsite);
	if (btn2==null){
		reason +="Please select Member website (Do you have a website..?)\n";
	}
	function valButton2(btn2) {
    var cnt2 = -1;
    for (var i=btn2.length-1; i > -1; i--) {
        if (btn2[i].checked) {cnt2 = i; i = -1;}
    }
    if (cnt2 > -1) return btn2[cnt2].value;
    else return null;
	}
	reason += validateEmpty(theForm.business_email);
    reason += validateEmail(theForm.business_email);
	reason += validateEmpty(theForm.password);
	reason += validatePassword(theForm.password);
	   if(theForm.password.value!=theForm.passwordc.value){
				reason += "Password invalid\n";
				theForm.password.style.background = '#FFFF99'; 
				error = "The required field has not been filled in\n"
		}else{
				 theForm.password.style.background = 'White';
		}

	reason += validateEmpty(theForm.member_name);
	reason += validateEmpty(theForm.member_lastname);
	//reason += validateEmpty(theForm.sex);
	var btn3 = valButton3(theForm.sex);
	if (btn3==null){
		reason +="Please select your Sex\n";
	}
	function valButton3(btn3){
	var cnt3 = -1;
	for (var i=btn3.length-1; i > -1; i--){
			if(btn3[i].checked){
				cnt3 = i;
				i= -1;
		}
	}
	if(cnt3 > -1)
		return btn3[cnt3].value;
	else return null;
	}

	reason += validateEmpty(theForm.member_street);
	reason += validateEmpty(theForm.member_city);
	reason += validateEmpty(theForm.member_zip);
	reason += validateEmpty(theForm.country_code);
	reason += validateEmpty(theForm.area_code);
	reason += validateEmpty(theForm.phone_number);
	reason += validatePhone(theForm.country_code);
	reason += validatePhone(theForm.area_code);
	reason += validatePhone(theForm.phone_number);
	reason += validateEmpty(theForm.company_name);
		
		if(isNaN(theForm.fax_country_code.value)){
			reason += "Fax Country code must be digit only!\n";
			theForm.fax_country_code.style.background = '#FFFF99'; 
		}else{
				 theForm.fax_country_code.style.background = 'White';
		}
		if(isNaN(theForm.fax_area_code.value)){
			reason += "Your Fax area code must be digit only!\n";
			theForm.fax_area_code.style.background = '#FFFF99';
		}else{
				 theForm.fax_area_code.style.background = 'White';
		}
		if(isNaN(theForm.fax_phone_number.value)){
			reason += "Your Fax number must be digit only!\n";
			theForm.fax_phone_number.style.background = '#FFFF99';
		}else{
				 theForm.fax_phone_number.style.background = 'White';
		}
		if(isNaN(theForm.mobile_phone_number_code.value)){
			reason += "Your Mobile code must be digit only!\n";
			theForm.mobile_phone_number_code.style.background = '#FFFF99';
		}else{
				 theForm.mobile_phone_number_code.style.background = 'White';
		}
		if(isNaN(theForm.mobile_phone_number.value)){
			reason += "Your Mobile number must be digit only!\n";
			theForm.mobile_phone_number.style.background = '#FFFF99';
		}else{
				 theForm.mobile_phone_number.style.background = 'White';
		}
		if(theForm.member_dep.value=="-1"){
				reason += "Please select department\n";
				theForm.member_dep.style.background = '#FFFF99'; 
		}else{
				 theForm.member_dep.style.background = 'White';
		}
	
		if(theForm.secure_num.value != 0){
			if(theForm.secure_num.value!=randomStr){
					reason += "Secure Number invalid.\n";
					theForm.secure_num.style.background = '#FFFF99'; 
			}else{
					 theForm.secure_num.style.background = 'White';
			}
		}else{
			reason += "Please enter security code!\n";
			theForm.secure_num.style.background = '#FFFF99'; 
		}
  
	if (reason != "") {
		alert("Yellow fields need correction:\n" + reason);
		return false;
	}

  return true;
}

function validateEmpty(fld) {
    var error = "";
  
    if (fld.value.length == 0) {
		error = "Please full fill in Yellow field. \n";
        fld.style.background = '#FFFF99'; 
    } else {
        fld.style.background = 'White';
    }
    return error;   
}
function validateUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = '#FFFF99'; 
        error = "You didn't enter a username\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        fld.style.background = '#FFFF99'; 
        error = "The username is the wrong length\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = '#FFFF99'; 
        error = "The username contains illegal characters\n";
    } else {
        fld.style.background = 'White';
    } 
    return error;
}
function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = '#FFFF99';
        error = "You didn't enter a password.\n";
    } else if ((fld.value.length < 7) || (fld.value.length > 15)) {
        error = "The password is the wrong length\n";
        fld.style.background = '#FFFF99';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters\n";
        fld.style.background = '#FFFF99';
    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        error = "The password must contain at least one numeral\n";
        fld.style.background = '#FFFF99';
    } else {
        fld.style.background = 'White';
    }
   return error;
}   
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (fld.value == "") {
        fld.style.background = '#FFFF99';
        error = "You didn't enter an email address\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#FFFF99';
        error = "Please enter a valid email address\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#FFFF99';
        error = "The email address contains illegal characters\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');     

	if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters\n";
        fld.style.background = '#FFFF99';
    }else {
        fld.style.background = 'White';
    }// else if (!(stripped.length == 10)) {
      //  error = "The phone number is the wrong length. Make sure you included an area code.\n";
      //  fld.style.background = '#FFFF99';
  //  } 
    return error;
}
