function isAlpha(strValue)
{ var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz -'.: ذضصثقفغعهخحجدشسيبلاتنمكطئءؤرلاىةوزظ~ًٌٌَََُّلإإٍِلأأْلآآ ";
  var checkStr = strValue
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    //alert(strMessage);
    return (false);
  }
return true;
}


function IsLarge(currDay,currMonth,currYear,reqDay,reqMonth,reqYear)
{


var day1 =currDay;
var month1 =currMonth;
var year1 = currYear;

var day2 = reqDay;
var month2 =reqMonth;
var year2 = reqYear;



if(year2==year1 && month1==month2 && day1==day2)
{
  return true;
}


if(year2>year1)
{
  return true;
}

else if(year2==year1)
{
if(month2>month1)
{
  return true;
}
else if (month2==month1)
{
  if(day2>day1)
{
return true;
}
else
{
  return false;
}
}
}



return false;


}

function validatePhone( objControlToValidate,lang) {

 //**********************************************
 //To validate the Phone  
 //**********************************************
	var len = objControlToValidate.value.length;
	var strValue=objControlToValidate.value;
    var returnValue;
    var expression;
    var flag =true;
    // Check for correct phone number
     expression = new RegExp(/^\d+$/);
    returnValue = strValue.match(expression);
    
   // if (returnValue != strValue)
   
   if(!IsNumber(strValue))
   {
		if(lang==1)
		{
			alert('invalid number');
		}
		else
		{
			alert('خطأ في ادخال الرقم');
		}
		flag=false;
       
        objControlToValidate.focus();
      
        return flag;
    
   }
   else if(len < 9 )
   {
   
		if(lang==1)
		{
			alert('number of digits must be larger than or equal 9');
		}
		else
		{
			alert('عدد الأرقام يجب أن يكون أكبر من أو يساوي 9');
		}
   
		flag=false;
       
        objControlToValidate.focus();
         
        return flag;
        
   }
    else 
    {    
  
       return flag;
     }
   //*************************************************
  } 

function checkEmail(strValue){

       var returnValue;
       var expression;
      

      var flag =true;

      if (Trim(strValue) != "" )

      {

 

            expression="['A-Za-z_]+['A-Za-z0-9_-]*[.]?['A-Za-z0-9_-]+[@]['A-Za-z0-9_-]+[.]['A-Za-z0-9_]+[.]?['A-Za-z0-9_]+" ;

            

            returnValue = strValue.match(expression);

            if (returnValue != strValue) 

            {

                  flag=false;

            }

      }

      
   // if(!flag)  alert(strAlert);
      return flag;

}
function IsEmpty(strValue)
{
	test = true;
	valtrimed = Trim(strValue);
	testlen = valtrimed.length;

	if (testlen == 0) 
	{
		test = false;
	
	}
	return(test);	
}	

function IsNumber(strValue){
  var checkOK = "0123456789.,";
  var checkStr = strValue;
  var allValid = true;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
   // alert(strAlert);
    return false;
  }
  
  return (true);
  }
  function LTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for (i = 0; i < String.length; i++)
	{
		if (String.substr(i, 1) != ' ' && String.substr(i, 1) != '\t')
			break; 
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

function RTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for(j = String.length - 1; j >= 0; j--)
	{
		if (String.substr(j, 1) != ' ' && String.substr(j, 1) != '\t')
			break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}


function Trim(String)
{
	if (String == null)
		return (false);
	return RTrim(LTrim(String));
}



function validateForm(lang)
{

//first name validation
if(!IsEmpty(document.getElementById(txtFirstName).value))
{
if(lang==1)
{
	alert('please enter the First Name');
}
else
{
	alert('الرجاء ادخال الاسم الأول');
}
document.getElementById(txtFirstName).focus();
return false;
}

if(!isAlpha(document.getElementById(txtFirstName).value))
{
if(lang==1)
{
	alert('please enter characters only');
}
else
{
	alert('الرجاء ادخال أحرف فقط');
}
document.getElementById(txtFirstName).focus();
return false;
}

//last name validation
if(!IsEmpty(document.getElementById(txtLastName).value))
{
if(lang==1)
{
	alert('please enter the Last Name');
}
else
{
	alert('الرجاء ادخال اسم العائلة');
}
document.getElementById(txtLastName).focus();
return false;
}

if(!isAlpha(document.getElementById(txtLastName).value))
{
if(lang==1)
{
	alert('please enter characters only');
}
else
{
	alert('الرجاء ادخال أحرف فقط');
}
document.getElementById(txtLastName).focus();
return false;
}



//company validation
if(!IsEmpty(document.getElementById(txtCompany).value))
{
if(lang==1)
{
	alert('please enter the Company');
}
else
{
	alert('الرجاء ادخال الشركة');
}
document.getElementById(txtCompany).focus();
return false;
}

if(!isAlpha(document.getElementById(txtCompany).value))
{
if(lang==1)
{
	alert('please enter characters only');
}
else
{
	alert('الرجاء ادخال أحرف فقط');
}
document.getElementById(txtCompany).focus();
return false;
}

//address validation

if(!IsEmpty(document.getElementById(txtAddress).value))
{
if(lang==1)
{
	alert('please enter the Address');
}
else
{
	alert('الرجاء ادخال العنوان');
}
document.getElementById(txtAddress).focus();
return false;
}

if(IsEmpty(document.getElementById(txtAddress).value))
{
	if(document.getElementById(txtAddress).value.length>100)
	{
		if(lang==1)
		{
		alert('maximum number of characters is 100')
		}
		else
		{
		alert('الحد الأعلى لعدد الأحرف هو 100');
		}
		document.getElementById(txtAddress).focus();
		return false;
	}
	
}


//city validation
if(!IsEmpty(document.getElementById(txtCity).value))
{
if(lang==1)
{
	alert('please enter the City');
}
else
{
	alert('الرجاء ادخال المدينة');
}
document.getElementById(txtCity).focus();
return false;
}

if(!isAlpha(document.getElementById(txtCity).value))
{
if(lang==1)
{
	alert('please enter characters only');
}
else
{
	alert('الرجاء ادخال أحرف فقط');
}
document.getElementById(txtCity).focus();
return false;
}


//country validation
if(!IsEmpty(document.getElementById(txtCountry).value))
{
if(lang==1)
{
	alert('please enter the Country');
}
else
{
	alert('الرجاء ادخال البلد');
}
document.getElementById(txtCountry).focus();
return false;
}

if(!isAlpha(document.getElementById(txtCountry).value))
{
if(lang==1)
{
	alert('please enter characters only');
}
else
{
	alert('الرجاء ادخال أحرف فقط');
}
document.getElementById(txtCountry).focus();
return false;
}

//postal code validation
if(!IsEmpty(document.getElementById(txtPostalCode).value))
{
if(lang==1)
{
	alert('please enter the Postal Code');
}
else
{
	alert('الرجاء ادخال الرمز البريدي');
}
document.getElementById(txtPostalCode).focus();
return false;
}

if(!IsNumber(document.getElementById(txtPostalCode).value))
{
if(lang==1)
{
	alert('please enter numbers only');
}
else
{
	alert('الرجاء ادخال أرقام فقط');
}
document.getElementById(txtPostalCode).focus();
return false;
}



//telephone validation
if(!IsEmpty(document.getElementById(txtTelephone).value))
	{
		if(lang==1)
		{
			alert('please enter the Phone');
		}
		else
		{
			alert('الرجاء ادخال رقم الهاتف');
		}
		document.getElementById(txtTelephone).focus();
		return false;
}

if(!validatePhone(document.getElementById(txtTelephone),lang))
{
	return false;
}



//fax validation
if(!IsEmpty(document.getElementById(txtFax).value))
	{
		if(lang==1)
		{
			alert('please enter the Fax');
		}
		else
		{
			alert('الرجاء ادخال رقم الفاكس');
		}
		document.getElementById(txtFax).focus();
		return false;
}

if(!validatePhone(document.getElementById(txtFax),lang))
{
	return false;
}

//email validation
if(!IsEmpty(document.getElementById(txtEmail).value))
	{
		if(lang==1)
		{
			alert('please enter the Email');
		}
		else
		{
			alert('الرجاء ادخال البريد الالكتروني');
		}
		document.getElementById(txtEmail).focus();
		return false;
}
if(IsEmpty(document.getElementById(txtEmail).value))
{
if(!checkEmail(document.getElementById(txtEmail).value))
{
if(lang==1)
{
alert('invalid e-mail address');
}
else
{
alert('خطأ في ادخال البريد الالكتروني ');
}
document.getElementById(txtEmail).focus();
return false;
}
}

//comments validation

if(!IsEmpty(document.getElementById(txtComments).value))
{
if(lang==1)
{
	alert('please enter the Comments');
}
else
{
	alert('الرجاء ادخال الملاحظات');
}
document.getElementById(txtComments).focus();
return false;
}

if(IsEmpty(document.getElementById(txtComments).value))
{
	if(document.getElementById(txtComments).value.length>250)
	{
		if(lang==1)
		{
		alert('maximum number of characters is 250')
		}
		else
		{
		alert('الحد الأعلى لعدد الأحرف هو 250');
		}
		document.getElementById(txtComments).focus();
		return false;
	}
	
}

/////////////////////////////////////////////////////
return true;
}


function resetForm()
{

document.getElementById(txtFirstName).value = "";
document.getElementById(txtLastName).value = "";
document.getElementById(txtCompany).value = "";
document.getElementById(txtAddress).value = "";
document.getElementById(txtCity).value = "";
document.getElementById(txtCountry).value = "";
document.getElementById(txtPostalCode).value = "";
document.getElementById(txtTelephone).value = "";
document.getElementById(txtFax).value = "";
document.getElementById(txtEmail).value = "";
document.getElementById(txtComments).value = "";


return false;
}


