

////////////// Function To Validate Required Fields ////////////////
function checkTheForm()
{
var oForm=document.getElementById("form_1");
oForm.firstname.style.backgroundColor='#e4efff';
oForm.lastname.style.backgroundColor='#e4efff';
oForm.phone.style.backgroundColor='#e4efff';
oForm.altmail.style.backgroundColor='#e4efff';
oForm.username.style.backgroundColor='#e4efff';
oForm.password.style.backgroundColor='#e4efff';
oForm.cnfpass.style.backgroundColor='#e4efff';
oForm.pquestion.style.backgroundColor='#e4efff';
oForm.preminder.style.backgroundColor='#e4efff';
//oForm.benchnum.style.backgroundColor='#e4efff';
//oForm.benchnum.style.backgroundColor='#e4efff';
//oForm.yrs[0].style.backgroundColor='#e4efff';
//oForm.yrs[1].style.backgroundColor='#e4efff';

//checking stage only if seat != null
//	if (oForm.benchnum.value!="" && !oForm.yrs[0].checked && !oForm.yrs[1].checked)
	if (oForm.firstname.value == "")
	{
		alert( astage);
		//oForm.yrs[0].style.backgroundColor='pink';
//		oForm.yrs[1].style.backgroundColor='pink';
//		oForm.benchnum.focus();

	return false;
	}//end of if

//checking fname...
	if (oForm.firstname.value == "")
	{
		alert( afName);
		oForm.firstname.style.backgroundColor='pink';
		oForm.firstname.focus();
		return false;
	}//end of if

//checking lname...
	if (oForm.lastname.value == "")
	{
		alert( alName);
		oForm.lastname.style.backgroundColor='pink';
		oForm.lastname.focus();
		return false;
	}//end of if

	if (oForm.phone.value != "" && oForm.phone.value.length < 6)
	{
		alert( aphone);
		oForm.phone.style.backgroundColor='pink';
		oForm.phone.focus();
		return false;
	}//end of if 
	var phoneRes = checkForIllegalChars(oForm.phone.value,"ÇáÊáíÝÜÜæä");
	if (oForm.phone.value != "" && phoneRes == 1)
		{
			alert(aphone);
			oForm.phone.style.backgroundColor='pink';
			oForm.phone.focus();
			return false;
		}
	
	//checking Email...
	at=oForm.altmail.value.indexOf("@");
	if (oForm.altmail.value != "" )
	{
		if (at == -1)
		{
			alert(amail);
			oForm.altmail.style.backgroundColor='pink';
			oForm.altmail.focus();
			return false;
		}//end of if
		else
		{
			at=oForm.altmail.value.indexOf(".");
			if (at == -1)
			{
				alert(amail);
				oForm.altmail.style.backgroundColor='pink';
				oForm.altmail.focus();
				return false;
			}//end of if
		}//end of else
	}//end of big if
	
	//checking uname...
	if (oForm.username.value == "")
	{
		alert(auName);
		oForm.username.style.backgroundColor='pink';
		oForm.username.focus();
		return false;
	}//end of if
	
	var nam="";
        var str="";
        var str1="";
        var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
        var str1 = "0123456789";
        str=str.toLowerCase();
        if(oForm)
           {
            nam = oForm.username.value;
            nam = nam.toLowerCase();
            if(nam.length < 4)
              {
                  alert(auName4);
                  event.returnValue=false;
				  oForm.username.style.backgroundColor='pink';
				  oForm.username.focus();
                  return false;
              }
             
             for(var i=0;i<nam.length;i++)
               {
                   var chr=nam.charAt(i);

                   if(str.indexOf(chr)== -1 && str1.indexOf(chr)==-1)
                     {
                         alert(auNameEn);
                         event.returnValue=false;
						 oForm.username.style.backgroundColor='pink';
				   		 oForm.username.focus();
                         return false;
                     }

               }
              var chr1=nam.charAt(0);
              var chr2=nam.charAt(1);
              if(str.indexOf(chr1)==-1 && str.indexOf(chr2)==-1)
                {
                  alert(auNameL);
                  event.returnValue=false; 
				  oForm.username.style.backgroundColor='pink';
				  oForm.username.focus();
                  return false;
                }
           }
	
	//checking pass...
	if (oForm.password.value == "")
	{
		alert( apass);
		oForm.password.style.backgroundColor='pink';
		oForm.password.focus();
		return false;
	}//end of if
	
	//is passwords are the same?
	if (oForm.password.value!=oForm.cnfpass.value) 
	{
		alert( aconPass);
		oForm.cnfpass.style.backgroundColor='pink';
		oForm.cnfpass.focus();
		return false;
	}//end of if
	
		
//checking birth day...
	if (oForm.day.value != "0")
	{
	if (oForm.month.value == "2")
	{
		var max = getMaxFeb(parseInt(oForm.byear.value))
		if( parseInt(oForm.birth_day.value)>max)
		{
			alert(aFeb+max+aday);
			return false;
		}
	}
	if ((oForm.month.value == "4"||oForm.month.value == "6" ||oForm.month.value == "9"||oForm.month.value == "11" )&& parseInt(oForm.day.value)>30)
	{
		alert(a30);
		return false;}
	}//end of else
	
		user_flag = "1";
		return true;
	
}//end of function

////////////// Function To Clear All Form Fields ////////////////
function clearFormFields(theTargetForm)
{
	theTargetForm.reset();
}

///////////// Function to change English Numeric to Arabic /////////
function changeToArabic (enNum)
{
	arNum = "";
	enNumLen = enNum.length ;
	for (numCounter=0;numCounter<enNumLen;numCounter++)
	{
		currentNum = enNum.charAt(numCounter);
		currentNum = parseInt(currentNum) + 1632;
		arNum = arNum+"&#"+currentNum+";";
	}//end of for
	return arNum;
}//end of function 

/////////// Function to get max day of Feb according to year////////
function getMaxFeb(y)
{
	return  y%4?28:29;
}


////////////////// Function to check for illegal characters in phone numbers////////
function checkForIllegalChars(pNum,pName)
	{
		var rFlag= 0;
		var spaceFlag = 0;
		for (count=0;count<pNum.length;count++)
		{
			if (pNum.charAt(count)!="0" && pNum.charAt(count)!="1" && pNum.charAt(count)!="2" && pNum.charAt(count)!="3" && pNum.charAt(count)!="4" && pNum.charAt(count)!="5" && pNum.charAt(count)!="6" && pNum.charAt(count)!="7" && pNum.charAt(count)!="8" && pNum.charAt(count)!="9" && pNum.charAt(count)!="(" && pNum.charAt(count)!=")" && pNum.charAt(count)!="-" && pNum.charAt(count)!="/" && pNum.charAt(count)!="+" && pNum.charAt(count)!=" " )
			rFlag = 1;
			if (pNum.charAt(count)==" ")spaceFlag++;
		}//end of for
		if (rFlag == 1 || pNum.length==spaceFlag)
			{
				//alert("ÚÝæðÇ.. ÑÞã "+pName+"  ÛíÑ ÕÍíÍ");
				return 1;
			}
		else
			return 0;
	}//end of function
