﻿function Check_email(emailStr) 
{
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|COM|NET|ORG|EDU|INT|MIL|GOV|ARPA|BIZ|AERO|NAME|COOP|INFO|PRO|MUSEUM)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);
if (document.HotLineForm.Email.value==0)
{
	return true;
}
else 
{
if (matchArray==null) {
alert("الرجاء إدخال عنوان البريد الإكتروني  بشكل صحيح");
document.HotLineForm.Email.focus();
document.HotLineForm.Email.select();
return false;
}
var user=matchArray[1];
var domain=matchArray[2];
for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Your email address contains invalid characters.");
document.HotLineForm.Email.focus();
document.HotLineForm.Email.select();
return false;
   } 
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Your email address contains a domain name with invalid characters.");
document.HotLineForm.Email.focus();
document.HotLineForm.Email.select();
return false;
   }
}
if (user.match(userPat)==null) { 
alert("Your email address does not appear to be valid.");
document.HotLineForm.Email.focus();
document.HotLineForm.Email.select();
return false;
}var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("The IP address used in your email address is invalid!");
document.HotLineForm.Email.focus();
document.HotLineForm.Email.select();
return false;
   }
}
return true;
}
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("Your email does not have a valid domain name.");
document.HotLineForm.Email.focus();
document.HotLineForm.Email.select();
return false;
   }
}
if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("Your email address must end in a well-known domain name or two letter country.");
document.HotLineForm.Email.focus();
document.HotLineForm.Email.select();
return false;
}
if (len<2) {
alert("Your email address is missing a hostname");
document.HotLineForm.Email.focus();
document.HotLineForm.Email.select();
return false;
}
}
return true;
}

function ValidateForm()
{
	
	if (document.HotLineForm.Name.value==0) 
	{
		alert("الرجاء إدخال الإسم");
		document.HotLineForm.Name.focus();
		return false;
	}
		 
	
   else if(document.HotLineForm.Email.value==0)
	{ 
		alert("الرجاء إدخال عنوان البريد الإكتروني");
		document.HotLineForm.Email.focus();
		return false;
	}		
	else if(Check_email(document.HotLineForm.Email.value)==false) 
	{
		return false;
	} 
	
	else if (document.HotLineForm.subject.value==0) 
	{
		alert("الرجاء إدخال الموضوع");
		document.HotLineForm.Name.focus();
		return false;
	}
		 
	
		
	//document.HotLineForm.action="../util/send_testdrive_email.asp";
	//document.HotLineForm.submit();
	//}	
	
	document.HotLineForm.lblAction.value="ContactUs"
	document.HotLineForm.submit()
    return true;
	
}