// Contact Us Validation: English version

// Funnction to check email
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("البريد الإلكتروني غير صحيح")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("البريد الإلكتروني غير صحيح")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   alert("البريد الإلكتروني غير صحيح")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   alert("البريد الإلكتروني غير صحيح")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   alert("البريد الإلكتروني غير صحيح")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   alert("البريد الإلكتروني غير صحيح")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   alert("البريد الإلكتروني غير صحيح")
		    return false
		 }

 		 return true					
	}

// function checkall to check form fields
function checkall(form)
{
	// Check Name field
	  if ( (document.form.name.value == "") || (document.form.name.value == " ") )
	  {
			alert ("الرجاء إدخال الاسم");
			document.form.name.focus();
			return false;
	  }
	
	// Check Job Title field
	  if ( (document.form.jobTitle.value == "") || (document.form.jobTitle.value == " ") )
	  {
			alert ("الرجاء إدخال المسمى الوظيفي");
			document.form.jobTitle.focus();
			return false;
	  }

	// Check Company field
	  if ( (document.form.company.value == "") || (document.form.company.value == " ") )
	  {
			alert ("الرجاء إدخال الشركة");
			document.form.company.focus();
			return false;
	  }

	// Check country field
	  if ( (document.form.country.value == 0) )
	  {
			alert ("الرجاء إدخال البلد");
			document.form.country.focus();
			return false;
	  }
	
	// Check Email field
	  if ( (document.form.email.value == "") || (!echeck(document.form.email.value)) )
	  {
			alert ("الرجاء إدخال البريد الإلكتروني");
			document.form.email.focus();
			return(false);
	  }

	// Check Telephone field
	  if ( (document.form.telephone.value == "") || (document.form.telephone.value == " ") )
	  {
			alert ("الرجاء إدخال رقم الهاتف");
			document.form.telephone.focus();
			return false;
	  }

	// Check subject field
	  if ( (document.form.subject.value == "") || (document.form.subject.value == " ") )
	  {
			alert ("الرجاء إدخال الموضوع");
			document.form.subject.focus();
			return false;
	  }

	// Check Comments field
	  if ( (document.form.comments.value == "") || (document.form.comments.value == " ") )
	  {
			alert ("الرجاء إدخال الملاحظات");
			document.form.comments.focus();
			return false;
	  }


}
