// JavaScript Document
function login(showhide){
    if(showhide == "show"){
        document.getElementById('popupbox').style.visibility="visible"; /* If the function is called with the variable 'show', show the login box */
    }else if(showhide == "hide"){
        document.getElementById('popupbox').style.visibility="hidden"; /* If the function is called with the variable 'hide', hide the login box */
    }
  }
  function checkEmail() {
  
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.getElementById('txtEmail').value;

   if (document.getElementById('txtEmail').value == '') {
         alert("Please enter your email address");
      return false;
   } else if (reg.test(address) == false) {
      alert("Please enter a valid email address.");
      return false;
   } else {
      //document.login.submit();
	  checkLogin();
   }
	}    
	
//ajax login check
 var http = createXMLHttpRequestObject(); // We create the HTTP Object

 function checkLogin() {
 	 var url = "/Login.cfm?txtEmail="; // The server-side script
     http.open("GET", url + escape(document.getElementById('txtEmail').value), true);
     http.onreadystatechange = handleHttpResponse;
     http.send(null);
  }
  
 function handleHttpResponse()
 { 
 	var loggedIn=0;
	
	
 	if (http.readyState == 4) {
        // if(http.responseText.length > 8)
         //{alert(http.responseText);
          //document.getElementById('txtEmail').value = '';
		  
		  var statusGood=http.responseText.indexOf('http://');
		  var activateGood=http.responseText.indexOf('not activated');
			if (statusGood==-1)
			 { 
			  //alert(http.responseText);
			  	if (activateGood==-1) {
					 document.getElementById('response').style.display = 'block';
			  		 document.getElementById('response').innerHTML = http.responseText;
			 		 document.getElementById('txtEmail').value = '';}
				else {
					 document.getElementById('response').style.display = 'block';
					 document.getElementById('actLink').style.display = 'block';
					 document.getElementById('loginFields').style.display = 'none';
					 document.getElementById('response').innerHTML = http.responseText;
			 		}
			 }
			else {
			 window.location=http.responseText;
			 //alert(http.responseText);
			}
         }
 }

 function createXMLHttpRequestObject()
 {
   // xmlHttp will store the reference to the XMLHttpRequest object
   var xmlHttp;
   // try to instantiate the native XMLHttpRequest object
   try
   {
     // create an XMLHttpRequest object
     xmlHttp = new XMLHttpRequest();
   }
   catch(e)
   {
     // assume IE6 or older
     try
     {
       xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
     }
     catch(e) { }
   }
   // return the created object or display an error message
   if (!xmlHttp)
     alert("Error creating the XMLHttpRequest object.");
   else
     return xmlHttp;
 }

       

function sendActivation (theEmail)
{
 var url = "/resendActEmail.cfm"; // The server-side script
	 
	 xmlhttp.open("GET", "url + escape(document.getElementById('txtEmail').value)",true);
	 xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4) {
	   alert(xmlhttp.responseText)
	  }
	 };
	 xmlhttp.send(null);

 document.getElementById('actLink').style.display = 'none';
 document.getElementById('response').innerHTML = 'Your activation email has been sent out successfully. Please check your email and activate your user account before continue.';
}


