
var xmlHttp = false; 
var isValidCode = 0 ;
var isValidMobile = 0; 

function checkCode(){ 

				 authCode = document.getElementById('authCode').value;
				 mobileNum = document.getElementById('mobileNum').value;
				 _thisForm = document.forms[0];

				 xmlHttp=GetXmlHttpObject()
				 if (xmlHttp==null) {
				 		 alert ("Browser does not support HTTP Request")
						  return
							 }
				 var url="activateMobile.php"
				 url=url+"?authCode="+authCode+"&mobileNum="+mobileNum
				 url=url+"&sid="+Math.random()
				 xmlHttp.onreadystatechange=stateChanged 
				 xmlHttp.open("GET",url,true)
				 xmlHttp.send(null)
	}
function stateChanged(){ 
				 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
				 		 document.getElementById("errText").innerHTML=xmlHttp.responseText;
						 if (xmlHttp.responseText == "Incorrect Mobile Number or Activation Code. Try Again.") DisableEnableForm(_thisForm,false); 
  			 } 
}
function GetXmlHttpObject(){
				 var xmlHttp=null;
				 try{
				 		  // Firefox, Opera 8.0+, Safari
							 xmlHttp=new XMLHttpRequest();
				 }
				 catch (e){
				 			  //Internet Explorer
								 try{
								   xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
								  }
				 					catch (e){
									 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
									}
			   }
				 return xmlHttp;
 }
 
 function callAjax(_this){
				 if(_this.id =='authCode'){
				 						authCodePat = /^[a-zA-Z0-9]{8}$/;
										if(!authCodePat.test(_this.value)){
													document.getElementById('rsp_code').innerHTML='Invalid Code';
													isValidCode = 0; 
													
									  } else{ isValidCode = 1; document.getElementById('rsp_code').innerHTML =''; }
				 }
				 else if (_this.id == 'mobileNum') {
				  					mobileNumPat = /^([9]{1})([02346789]{1})([0-9]{8})$/;
										if(!mobileNumPat.test(_this.value)){
													document.getElementById('rsp_mobile').innerHTML='Invalid Mobile Number';
														isValidMobile = 0; 													 
		 								}	 else{ isValidMobile=1; document.getElementById('rsp_mobile').innerHTML ='';}		 
				}
				
}

function clearComment(){ 		
				 document.getElementById('rsp_mobile').innerHTML ='';
				 document.getElementById('rsp_code').innerHTML='';
				 document.getElementById('errText').innerHTML='';
	}

function checkForm(_thisForm){

		if((isValidCode + isValidMobile) == 2 && _thisForm.authCode.value != '' && _thisForm.mobileNum.value != '') { 
				clearComment();
      	DisableEnableForm(_thisForm,true);
				checkCode(); 
		} 
		else document.getElementById("errText").innerHTML = "Please complete all fields Properly!";
	  
}

function DisableEnableForm(xForm,xHow){
  objElems = xForm.elements;
  for(i=0;i<objElems.length;i++){
    objElems[i].disabled = xHow;
  }
}

function enter_pressed(e){
				 var keycode;
				 if (window.event) keycode = window.event.keyCode; 
				 else if (e) keycode = e.which; 
				 else return false; 
				 if (keycode == 13){ 
				 		callAjax (document.forms[0].authCode);
				 		callAjax (document.forms[0].mobileNum);
						return true;
						}			 
 }


