﻿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 IsWord(strString)
		//  check for valid numeric strings	
		{
			var strValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ";
			var strChar;
			var blnResult = true;

			if (strString.length == 0) return false;

			//  test strString consists of valid characters listed above
			for (i = 0; i < strString.length && blnResult == true; i++)
				{
				strChar = strString.charAt(i);
				if (strValidChars.indexOf(strChar) == -1)
					{
					blnResult = false;
					}
				}
			return blnResult;
		}
		
		function IsWordMessage(strString)
		//  check for valid numeric strings	
		{
			var strValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\!.()-_?\r\n ";
			var strChar;
			var blnResult = true;

			if (strString.length == 0) return false;

			//  test strString consists of valid characters listed above
			for (i = 0; i < strString.length && blnResult == true; i++)
				{
				strChar = strString.charAt(i);
				if (strValidChars.indexOf(strChar) == -1)
					{
					blnResult = false;
					}
				}
			return blnResult;
		}
		
		function IsEmpty(strString)
		{	
			var blnResult = false;
			
			if(strString.length == 0)
			{
				blnResult = true;
			}
			
			return blnResult;
		}
		
		function LenghtCheck(strString)
		//  check for valid numeric strings	
		{
			var blnResult = true;
			
			if (strString.length > 20)
			{
				blnResult = false;
			}
			return blnResult;
		}
		
		function LenghtCheckFifty(strString)
		//  check for valid numeric strings	
		{
			var blnResult = true;
			
			if (strString.length > 50)
			{
				blnResult = false;
			}
			return blnResult;
		}
		
		function LenghtCheckMessage(strString)
		//  check for valid numeric strings	
		{
			var blnResult = true;
			
			if (strString.length > 400)
			{
				blnResult = false;
			}
			return blnResult;
		}
		
		function IsTrue(strString)
		{
			var blnResult = true;
			
			if(strString == "-1")
			{
				blnResult = false;
			}
			return blnResult;
		}
		
		function ClearAll()
		{
			document.getElementById('txtName').value = "";
			document.getElementById('txtEmail').value = "";
			//document.getElementById('txtOrganization').value = "";
			document.getElementById('txtMessage').value = "";
			return false;
		}
		
		function Check_Form()
		{
			if (document.getElementById('txtName').value == "")
			{
				alert("من فضلك أدخل الإسم");
				document.getElementById('txtName').focus();
				return false;
			}
			//else if (IsWord(document.getElementById('txtName').value)!= true)
			//{
			//	alert("Name must be alphanumeric");
			//	document.getElementById('txtName').focus();
			//	return false;
			//}
			else if(LenghtCheck(document.getElementById('txtName').value) != true)
			{
				alert("من فضلك ادخل 20 حرفاً فقط");
				document.getElementById('txtName').focus();
				return false;
			}
			else if (document.getElementById('txtEmail').value == "")
			{
				alert("من فضلك قم بإدخال البريد الإلكتروني");
				document.getElementById('txtEmail').focus();
				return false;
			}
			else if(LenghtCheckFifty(document.getElementById('txtEmail').value) != true)
			{
				alert("من فضلك ادخل 50 حرفاً فقط");
				document.getElementById('txtEmail').focus();
				return false;
			}
			else if (echeck(document.getElementById('txtEmail').value)==false)
			{
				document.getElementById('txtEmail').value=""
				document.getElementById('txtEmail').focus()
				return false
			}
			else if(IsTrue(document.getElementById('drpNationality').value) != true)
			{
				alert("من فضلك قم بإختيار البلد");
				document.getElementById('drpNationality').focus();
				return false;
			}
			else if (document.getElementById('txtMessage').value == "")
			{
				alert("من فضلك أدخل الرّسالة");
				document.getElementById('txtMessage').focus();
				return false;
			}
			//else if (IsWordMessage(document.getElementById('txtMessage').value)!= true)
			//{
			//	alert("Enter alphanumeric and '\!.()-_?' literals for Message");
			//	document.getElementById('txtMessage').focus();
			//	return false;
			//}
			else if(LenghtCheckMessage(document.getElementById('txtMessage').value) != true)
			{
				alert("من فضلك ادخل 400 حرفاً فقط");
				document.getElementById('txtMessage').focus();
				return false;
			}
			//else if((IsEmpty(document.getElementById('txtOrganization').value) != true) && (IsWord(document.getElementById('txtOrganization').value)!= true))
			//{	
			//	alert("Organization Text must be alphanumeric");
			//	document.getElementById('txtOrganization').focus();
			//	return false;
			//}
			
			else
			{
				//document.getElementById('flag2').value = "true";
				//alert("The Message has been posted successfully");
				return true;
			}
		}
		function userlogin()
		{
			
			if (document.getElementById('Textbox1').value == "")
			{
				alert("من فضلك أدخل الإسم");
				document.getElementById('Textbox1').focus();
				return false;
			}
			//else if (IsWord(document.getElementById('txtname').value)!= true)
			//{
			//	alert("Name must be alphanumeric");
			//	document.getElementById('txtname').focus();
			//	return false;
			//}
			/*else if (LenghtCheck(document.getElementById('txtname').value) != true)
			{
				alert("Name must be less than 50 characters");
				document.getElementById('txtname').focus();
				return false;
			}*/
			else if (document.getElementById('txtemails').value == "")
			{
				alert("من فضلك قم بإدخال البريد الإلكتروني");
				document.getElementById('txtemails').focus();
				return false;
			}
			/*else if(LenghtCheck(document.getElementById('txtemails').value) != true)
			{
				alert("Email Address must be less than 50 characters");
				document.getElementById('txtemails').focus();
				return false;
			}*/
			else if (echeck(document.getElementById('txtemails').value)==false)
			{
				document.getElementById('txtemails').value="";
				document.getElementById('txtemails').focus();
				return false;
			}
			else
			{
				return true;
			}
			
		}
