﻿function select_deselectAll (chkVal, idVal) { 
var frm = document.forms[0];

// Loop through all elements
for (i=0; i<frm.length; i++) {
// Look for our Header Template's Checkbox
	if (idVal.indexOf ('CheckAll') != -1) {
		// Check if main checkbox is checked, then select or deselect datagrid checkboxes 
		if(chkVal == true) {
			frm.elements[i].checked = true;
		} else {
			frm.elements[i].checked = false;
		}
	// Work here with the Item Template's multiple checkboxes
	} else if (idVal.indexOf ('DeleteThis') != -1) {
		// Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
		if(frm.elements[i].checked == false) {
			frm.elements[1].checked = false; //Uncheck main select all checkbox
		}
	}
}
}

function SwitchMenu(obj, main, disp){
	if(document.getElementById){
		var el = document.getElementById(obj);
		var ar = document.getElementById(main).getElementsByTagName("DIV");
		el.style.display = disp;
	}
}

function ChangeClass(menu, newClass) {
	if (document.getElementById) {
		document.getElementById(menu).className = newClass;
	}
}



function validatePwd(type) {
var errorMsg = "";
var space  = " ";
fieldname   = document.getElementById('ctl00_txtNewPassword'); 
fieldvalue  = fieldname.value; 
fieldlength = fieldvalue.length; 

fieldname2 = document.getElementById('ctl00_txtRepeat'); 
fieldvalue2  = fieldname2.value; 

fieldMail = document.getElementById('ctl00_txtMail'); 
fieldMailvalue  = fieldMail.value; 

fieldFullName = document.getElementById('ctl00_txtName'); 
fieldFullNamevalue  = fieldFullName.value; 

fieldCity = document.getElementById('ctl00_drpCity'); 
fieldCityvalue  = fieldCity.value; 

if (type == 1 ) {
fieldName = document.getElementById('ctl00_txtLoginID'); 
fieldNamevalue  = fieldName.value; 

if (fieldNamevalue == "" ) {
errorMsg += "\nأدخل اسم المستخدم .\n";
}}

if (fieldFullNamevalue == "" ) {
errorMsg += "\nأدخل الاسم الثلاثي .\n";
}
if (fieldCityvalue == "-" ) {
errorMsg += "\nاختر المدينة.\n";
}

if (fieldMailvalue == "" ) {
errorMsg += "\nأدخل البريد الإلكتروني .\n";
} else
{
if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(fieldMailvalue)) {

	errorMsg += "\nالبريد الإلكتروني غير صحيح.\n";
}}

if (type==1) {
  if (fieldvalue == "")
{
	errorMsg += "\nأدخل كلمة المرور.\n";
} }
if (fieldvalue != "")
 {
 
//It must not contain a space
if (fieldvalue.indexOf(space) > -1) {
     errorMsg += "\nيجب أن لا تحتوي كلمة المرور على مسافات.\n";
}     
 
//It must contain at least one number character
if (!(fieldvalue.match(/\d/))) {
     errorMsg += "\nيجب أن تحتوي كلمة المرور على أرقام.\n";
}
//It must start with at least one letter     
if (!(fieldvalue.match(/^[a-zA-Z]+/))) {
     errorMsg += "\nيجب أن تبدأ كلمة المرور بحرف.\n";
}
//It must contain at least one upper case character     
if (!(fieldvalue.match(/[A-Z]/))) {
     errorMsg += "\nيجب أن تحتوي كلمة المرور على حرف كبير.\n";
}
//It must contain at least one lower case character
if (!(fieldvalue.match(/[a-z]/))) {
     errorMsg += "\nيجب أن تحتوي كلمة المرور على حرف صغير.\n";
}
//It must contain at least one special character
if (!(fieldvalue.match(/\W+/))) {
     errorMsg += "\nيجب أن تحتوي كلمة المرور على أحد الرموز التالية - #,@,%,!\n";
}
//It must be at least 7 characters long.
if (!(fieldlength >= 6)) {
     errorMsg += "\nيجب أن لا يقل طول كلمة المرور عن 6 أحرف.\n";
}
if (!(fieldlength <= 10)) {
     errorMsg += "\nيجب أن لا يزيد طول كلمة المرور على 10 أحرف.\n";
}

if (!(fieldvalue2 == fieldvalue)){
     errorMsg += "\nيحب أن يتطابق التكرار مع كلمة المرور الجديدة.\n";
} } 
//If there is aproblem with the form then display an error
     if (errorMsg != ""){
          msg = "______________________________________________________\n\n";
          msg += "تحقق مما يلي:\n";
          msg += "______________________________________________________\n";
          errorMsg += alert(msg + errorMsg + "\n\n");
          fieldname.focus();
          return false;
     }
     
     return true;
}


function validatePwdEnglish(type) {
var errorMsg = "";
var space  = " ";
fieldname   = document.getElementById('ctl00_txtNewPassword'); 
fieldvalue  = fieldname.value; 
fieldlength = fieldvalue.length; 

fieldname2 = document.getElementById('ctl00_txtRepeat'); 
fieldvalue2  = fieldname2.value; 

fieldMail = document.getElementById('ctl00_txtMail'); 
fieldMailvalue  = fieldMail.value; 

fieldFullName = document.getElementById('ctl00_txtName'); 
fieldFullNamevalue  = fieldFullName.value; 

fieldCity = document.getElementById('ctl00_drpCity'); 
fieldCityvalue  = fieldCity.value; 

if (type == 1 ) {
fieldName = document.getElementById('ctl00_txtLoginID'); 
fieldNamevalue  = fieldName.value; 

if (fieldNamevalue == "" ) {
errorMsg += "\nEnter User Name.\n";
}}

if (fieldFullNamevalue == "" ) {
errorMsg += "\nEnter Full Name.\n";
}
if (fieldCityvalue == "-" ) {
errorMsg += "\nChoose the City.\n";
}

if (fieldMailvalue == "" ) {
errorMsg += "\nEnter your E-Mail.\n";
} else
{
if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(fieldMailvalue)) {

	errorMsg += "\nInvalid E-Mail.\n";

}}




if (type==1) {
  if (fieldvalue == "")
{
	errorMsg += "\nEnter Password.\n";
} }
if (fieldvalue != "")
 {
//It must not contain a space
if (fieldvalue.indexOf(space) > -1) {
     errorMsg += "\nPasswords cannot include a space.\n";
}     
 
//It must contain at least one number character
if (!(fieldvalue.match(/\d/))) {
     errorMsg += "\nPasswords must include at least one number.\n";
}
//It must start with at least one letter     
if (!(fieldvalue.match(/^[a-zA-Z]+/))) {
     errorMsg += "\nPasswords must start with at least one letter.\n";
}
//It must contain at least one upper case character     
if (!(fieldvalue.match(/[A-Z]/))) {
     errorMsg += "\nPasswords must include at least one uppercase letter.\n";
}
//It must contain at least one lower case character
if (!(fieldvalue.match(/[a-z]/))) {
     errorMsg += "\nPasswords must include one or more lowercase letters.\n";
}
//It must contain at least one special character
if (!(fieldvalue.match(/\W+/))) {
     errorMsg += "\nPasswords must include at least one special character - #,@,%,!\n";
}
//It must be at least 7 characters long.
if (!(fieldlength >= 6)) {
     errorMsg += "\nPasswords must be at least 6 characters long.\n";
}
if (!(fieldlength <= 10)) {
     errorMsg += "\nPasswords must be maximum 10 characters long.\n";
}

if (!(fieldvalue2 == fieldvalue)){
     errorMsg += "\nReapeat Password doesn't match.\n";
}}
//If there is aproblem with the form then display an error
     if (errorMsg != ""){
          msg = "______________________________________________________\n\n";
          msg += "Please correct the problem(s) and test it again.\n";
          msg += "______________________________________________________\n";
          errorMsg += alert(msg + errorMsg + "\n\n");
          fieldname.focus();
          return false;
     }
     
     return true;
}


