/// Send message to QuinL
function validateProfileFormOnSubmit(theForm){
var reason = "";
	if(theForm.customer_name.value.length == 0){
		reason += "Please enter your name!\n";
		theForm.customer_name.style.background = '#E3EFF2'; 
	}else{
		theForm.customer_name.style.background = 'White'; 
	}

	reason += validateEmail(theForm.customer_email);

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

	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 = '#E3EFF2'; 
		}else{
			theForm.customer_country_code.style.background = 'White'; 
		}
	}else{
		reason += "Please enter country code!\n";
		theForm.customer_country_code.style.background = '#E3EFF2'; 
	}

	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 = '#E3EFF2'; 
		}else{
			theForm.customer_area_code.style.background = 'White'; 
		}
	}else{
		reason += "Please enter area code!\n";
		theForm.customer_area_code.style.background = '#E3EFF2'; 
	}

	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 = '#E3EFF2'; 
		}else{
			theForm.customer_phone.style.background = 'White'; 
		}
	}else{
		reason += "Please enter phone number!\n";
		theForm.customer_phone.style.background = '#E3EFF2'; 
	}
	
	if(theForm.customer_message.value.length == 0){
		reason += "Please enter message!\n";
		theForm.customer_message.style.background = '#E3EFF2'; 
	}else{
		theForm.customer_message.style.background = 'White'; 
	}

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

	if (reason != "") {
		alert("Blue 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 = '#E3EFF2'; 
	}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 = '#E3EFF2'; 
				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 = '#E3EFF2'; 
		}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 = '#E3EFF2';
		}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 = '#E3EFF2';
		}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 = '#E3EFF2';
		}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 = '#E3EFF2';
		}else{
				 theForm.mobile_phone_number.style.background = 'White';
		}
		if(theForm.member_dep.value=="-1"){
				reason += "Please select department\n";
				theForm.member_dep.style.background = '#E3EFF2'; 
		}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 = '#E3EFF2'; 
			}else{
					 theForm.secure_num.style.background = 'White';
			}
		}else{
			reason += "Please enter security code!\n";
			theForm.secure_num.style.background = '#E3EFF2'; 
		}
  
	if (reason != "") {
		alert("Blue fields need correction:\n" + reason);
		return false;
	}

  return true;
}

function validateEmpty(fld) {
    var error = "";
  
    if (fld.value.length == 0) {
		error = "Please full fill in Blue field. \n";
        fld.style.background = '#E3EFF2'; 
    } 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 = '#E3EFF2'; 
        error = "You didn't enter a username\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        fld.style.background = '#E3EFF2'; 
        error = "The username is the wrong length\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = '#E3EFF2'; 
        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 = '#E3EFF2';
        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 = '#E3EFF2';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters\n";
        fld.style.background = '#E3EFF2';
    } 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 = '#E3EFF2';
    } 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 = '#E3EFF2';
        error = "You didn't enter an email address\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#E3EFF2';
        error = "Please enter a valid email address\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#E3EFF2';
        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 = '#E3EFF2';
    }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 = '#E3EFF2';
  //  } 
    return error;
}
