function validateFormOnSubmitEN(theForm) {
var reason = "";
  reason += validateUsernameEN(theForm.username);
  reason += validateEmailEN(theForm.email);
  reason += validatePhoneEN(theForm.phone);
  reason += validateEmptyEN(theForm.message);
      
  if (reason != "") {
    alert(reason);
    return false;
  }

  return true;
}




function validateFormOnSubmit(theForm) {
var reason = "";
//alert("trgrg");
  reason += validateUsername(theForm.username);
 // reason += validatePassword(theForm.pwd);
  reason += validateEmail(theForm.email);
  reason += validatePhone(theForm.phone);
  reason += validateEmpty(theForm.message);
      
  if (reason != "") {
    alert(reason);
    return false;
  }

  return true;
}

//Validate Mailing list Form
function  validatemailingForm(theform)
{
var reason = "";
  reason += validateUsername(theform.username1);
  reason += validateEmail(theform.email1);
 if (reason != "") {
    alert(reason);
    return false;
  }

  return true;

}




function validateEmpty(fld) {
    var error = "";
 // alert("validateEmpty");
    if (fld.value.length == 0) {
        fld.style.background = '#ffffb0'; 
        error = "الرجاء ملئ الحقول كاملة.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;   
}



function validateEmptyEN(fld) {
    var error = "";
 // alert("validateEmpty");
    if (fld.value.length == 0) {
        fld.style.background = '#ffffb0'; 
        error = "Please fill in all fields.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;   
}



function validateUsername(fld) {
  //alert("validateUsername");
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = '#ffffb0'; 
        error = "الرجاء إدخال الإسم.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 30)) {
        fld.style.background = 'Yellow'; 
        error = " الإسم اقل من 30 واكثر من 5 محارف.\n";
    } else {
        fld.style.background = 'White';
    } 
    return error;
}

function validateUsernameEN(fld) {
  //alert("validateUsername");
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = '#ffffb0'; 
        error = "اplease enter your name.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 30)) {
        fld.style.background = 'Yellow'; 
        error = " name must be at least 5 and not more than 30 character.\n";
    } else {
        fld.style.background = 'White';
    } 
    return error;
}


function validatePassword(fld) {
  //alert("validatePasswor");
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = '#ffffb0';
        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 = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
        fld.style.background = '#ffffb0';
    } 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 = '#ffffb0';
    } else {
        fld.style.background = 'White';
    }
   return error;
}





function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 



function validateEmail(fld) {
  //alert("validateEmail");
    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 = '#ffffb0';
        error = "الرجاء إدخال بريد الكتروني.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#ffffb0';
        error = "الرجاء التاكد من صحة البريد.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#ffffb0';
        error = "البريد يجب ان لايحوي محارف خاصة.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}





function validateEmailEN(fld) {
  //alert("validateEmail");
    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 = '#ffffb0';
        error = "Please enter your e-mail.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#ffffb0';
        error = "اPlease verify your e-mail.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#ffffb0';
        error = "Email You must not contain special characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}









function validatePhone(fld) {
  //alert("validatePhone");
    var error = "";
  var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');     
   if (fld.value == "")
 {
        error = "الرجاء إدخال رقم الهاتف.\n";
        fld.style.background = '#ffffb0';
    }
	 else if ((isNaN(parseInt(stripped)))||(parseInt(stripped)==0))
	{
      	  error = "(9331234567)الهاتف يجب ان لايحوي محارف .\n";
      	  fld.style.background = '#ffffb0';
   	 } else if (!(stripped.length == 9))
		 {
       		 error = "الرجاء التاكد من صحة رقم الهاتف مع رمز المنطقة(9 ارقام).\n";
       		 fld.style.background = '#ffffb0';
  		  }else {     fld.style.background = 'White';}
    return error;
}


function validatePhoneEN(fld) {
  //alert("validatePhone");
    var error = "";
  var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');     
   if (fld.value == "")
 {
        error = "Please enter your phone number.\n";
        fld.style.background = '#ffffb0';
    }
	 else if ((isNaN(parseInt(stripped)))||(parseInt(stripped)==0))
	{
      	  error = "(9331234567)Phone must not contain characters .\n";
      	  fld.style.background = '#ffffb0';
   	 } else if (!(stripped.length == 9))
		 {
       		 error = "Please verify the phone number with area code (9 digits).\n";
       		 fld.style.background = '#ffffb0';
  		  }else {     fld.style.background = 'White';}
    return error;
}



