﻿
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 userlogin()
		{
			
			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("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;
			}
			
		}