/************************************************************************************/
// 
/************************************************************************************/
var rosterRec = new Array();
function validate()
{
	  xmlHttp=GetXmlHttpObject();
  	  if (xmlHttp==null)
	  {
			 alert ("Your browser does not support AJAX!");
			 return;
	 }
  url="http://www.thescoutingedge.com/index.php/clogon/verifyLogin";
  url=url+"?email="+document.form1.email.value;
  url=url+"&pass="+document.form1.pass.value;
  xmlHttp.onreadystatechange=stateChanged;
  xmlHttp.open("POST",url,true);
  xmlHttp.send(null);
}
// ------------------------------------------------------------------------
function checkuser()
{
	if (document.form2.username.value!="")
	{
		 xmlHttp=GetXmlHttpObject();
		 if (xmlHttp==null)
		{
				 alert ("Your browser does not support AJAX!");
				 return;
		}
		 url="/index.php/clogon/check";
		 url=url+"?email="+document.form2.username.value;
		 url=url+"&pass="+document.form2.password.value;
		 xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("POST",url,true);
		xmlHttp.send(null);
	}		
}
// ------------------------------------------------------------------------
function passwordcheck()
{
	 xmlHttp=GetXmlHttpObject();
	 if (xmlHttp==null)
	{
		 alert ("Your browser does not support AJAX!");
		 return;
	}
		url="/index.php/clogon/checkpass";
		url=url+"?user="+document.form3.username1.value;
	    url=url+"&ques="+document.form3.sqn1.value;
		url=url+"&pass="+document.form3.answer1.value;
		
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("POST",url,true);
		xmlHttp.send(null);
	
}
// ------------------------------------------------------------------------
function stateChanged()
{
	
	if (xmlHttp.readyState==4)
   {
	 
	  	if (xmlHttp.responseText  == "Invalid") 
		{
			alert("Invalid Email and Password. Please try again."); 
			document.forms['form1'].reset();
			document.forms['form1'].email.focus();
			return;
        }  
		else if(xmlHttp.responseText =="Valid")
		{
		 	document.location="/index.php/userLogon/cp";
			document.forms['form1'].reset();
	    }

		else if (xmlHttp.responseText =="YES") 
		{
			alert("Email already exist."); 
			document.forms['form2'].username.value="";
			document.forms['form2'].username.focus();
			return;
		}  
		else if (xmlHttp.responseText =="NO") 
		{
			
        }  
		
		else if (xmlHttp.responseText == "FALSE")
		   {
				alert("Please check  your details.");
				document.forms['form3'].reset();
				document.form3.username1.focus();
		   }
		else if (xmlHttp.responseText =="TRUE") 
		{
			alert("Your password will be sent to the email address you used at the time of registering with thescoutingedge.com \n\n\t\t\t\tThank You.");
			url="?user="+document.form3.username1.value;
			url=url+"&ques="+document.form3.sqn1.value;
			url=url+"&pass="+document.form3.answer1.value;
			document.location="/index.php/clogon/sendPass"+url;
			document.location="/index.php/userLogon";
		}  
		
		else if (xmlHttp.responseText =="PENDING")
		{
			document.location="/index.php/userLogon/confirm/1";
			document.forms['form1'].reset();
        	} else {

		// alert('in else ' + xmlHttp.responseText);
		}

				
	}
}

// ------------------------------------------------------------------------

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 addRecord(rosterid, num, email) {
   rosterRec.push(new Array(rosterid, num, email));
}
// -----------------------------------------------------------------------------------------
function checkDuplicateNumber(num, rosterid) {

  var a = new Array();
  var retVal = false;

  for (var i = 0; i < rosterRec.length; i++) {
    a = rosterRec[i]; 

    if ((a[1] == num) && (a[0] != rosterid)) {
//	alert("Roster ID - Array  is " + a[0] + "Rosterid working on is : " + rosterid);
	retVal = true;
	
	break;	
    } 
  } // For Loop
  return retVal;
}
// -----------------------------------------------------------------------------------------
