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 isAlpha(strValue)
{ 


var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz -'.: ذضصثقفغعهخحجدشسيبلاتنمكطئءؤرلاىةوزظ~ًٌٌَََُّلإإٍِلأأْلآآ ";
  var checkStr = strValue;
  var allValid = true;
  var validGroups = true;
  for (ii = 0;  ii < checkStr.length;  ii++)
  {
    ch = checkStr.charAt(ii);
    for (jj = 0;  jj < checkOK.length;  jj++)
      if (ch == checkOK.charAt(jj))
        break;
    if (jj == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    //alert(strMessage);
    return (false);
  }
return true;
}
 
  
function validateEmail( objControlToValidate,sMessage) {

 //**********************************************
 //To validate the email
 //**********************************************
	var strValue=objControlToValidate.value;
    var returnValue;
    var expression;
    var flag =true;
    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;
        alert(sMessage);
        objControlToValidate.focus();
        return flag;
      } 
       return flag;
   //*************************************************
  }
  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
    var regex1=/^[+]?[0-9]*$/; 
     //this is the pattern of regular expersion
     if(regex1.test(objControlToValidate.value)== false)
   {
		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 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 ValidateCustomerValues()
{

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;
}

//Telephone validation
//telephone validation
if(IsEmpty(document.getElementById(txtTelephone).value))
{
	if(!validatePhone(document.getElementById(txtTelephone),lang))
	{
		return false;
	}

}


//email validation
//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;
	}
}


//country and occupation

if(!IsEmpty(document.getElementById(txtOccupation).value))
{
	if(lang==1)
	{
		alert('please enter the Occupation');
	}
	else
	{
		alert('الرجاء ادخال المهنة ');
	}
	document.getElementById(txtOccupation).focus();
	return false;
}
if(!IsEmpty(document.getElementById(txtCountry).value))
{
	if(lang==1)
	{
		alert('please enter the country');
	}
	else
	{
		alert('الرجاء ادخال البلد ');
	}
	document.getElementById(txtCountry).focus();
	return false;
}
//Question validation
if(!IsEmpty(document.getElementById(txtQuestion).value))
{
if(lang==1)
{
	alert ("Please insert question");
}
else
{
	alert ("الرجاء إدخال السؤال, الإستفسار");		
}
document.getElementById(txtQuestion).focus();
return false;
}

if(IsEmpty(document.getElementById(txtQuestion).value))
{
	if(document.getElementById(txtQuestion).value.length>350)
	{
		if(lang==1)
		{
		alert('maximum number of characters is 350')
		}
		else
		{
		alert('الحد الأعلى لعدد الأحرف هو 350');
		}
		document.getElementById(txtQuestion).focus();
		return false;
	}
	
}
/////

return true;
}  
  
 
