//Gets the browser specific XmlHttpRequest Object 
function getXmlHttpRequestObject() {
 if (window.XMLHttpRequest) {
    return new XMLHttpRequest(); //Mozilla, Safari ...
 } else if (window.ActiveXObject) {
    return new ActiveXObject("Microsoft.XMLHTTP"); //IE
 } else {
    //Display our error message
    alert("Your browser doesn't support the XmlHttpRequest object.");
 }
}

//Our XmlHttpRequest object
var receiveReq = getXmlHttpRequestObject();

//Initiate the AJAX request
function makeRequest(url, param) {
	
   //If our readystate is either not started or finished, initiate a new request

      if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
          //Set up the connection to captcha_test.html. True sets the request to asyncronous(default) 
          //alert(document.getElementById('username').value);
          receiveReq.open("GET", "ajax_check_publisher.php?user="+document.getElementById('name23').value, true);
              //Set the function that will be called when the XmlHttpRequest objects state changes
          receiveReq.onreadystatechange = updatePage; 

         //Make the request
          receiveReq.send(param);
     }   
}

//Initiate the AJAX request
function makeRequestForEmail(url, param) {
	
   //If our readystate is either not started or finished, initiate a new request

      if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
          //Set up the connection to captcha_test.html. True sets the request to asyncronous(default) 
          //alert(document.getElementById('username').value);
          receiveReq.open("GET", "ajax_check_email.php?email="+document.getElementById('email').value, true);
              //Set the function that will be called when the XmlHttpRequest objects state changes
          receiveReq.onreadystatechange = updatePageEmail; 

         //Make the request
          receiveReq.send(param);
     }   
}

//Called every time our XmlHttpRequest objects state changes
function updatePage() {
 //Check if our response is ready
 
 	  document.getElementById('result').innerHTML = "Checking....";
	if (receiveReq.readyState == 4) {
	  document.getElementById('result').innerHTML = receiveReq.responseText;
          theglobalajaxmsg = receiveReq.responseText;
    }
}


//Called every time our XmlHttpRequest objects state changes
function updatePageEmail() 
{
 //Check if our response is ready
    document.getElementById('result').innerHTML = "";
    document.getElementById('resultemail').innerHTML = "Checking....";
    if (receiveReq.readyState == 4) 
    {
        document.getElementById('result').innerHTML = "";
        document.getElementById('resultemail').innerHTML = receiveReq.responseText;
        theglobalajaxmsg = receiveReq.responseText;
    }
}

//Called every time when form is perfomed
function getParam(frmCaptcha) {
      theglobalajaxmsg = "";
     //Set the URL
     if(frmCaptcha=='username')
     {
        var url = 'ajax_check_publisher.php';
        //Set up the parameters of our AJAX call
        var postStr = document.getElementById('name23').value;  
        makeRequest(url, postStr);
     }
     if(frmCaptcha=='email')
     {
        //Set the URL
        var url = 'ajax_check_email.php';
        //Set up the parameters of our AJAX call
        var postStr = document.getElementById('email').value;  
        makeRequestForEmail(url, postStr);         
     }
         
}

//Called every time when form is perfomed
function getEmail() {
     //Set the URL
     var url = 'ajax_check_email.php';
    //Set up the parameters of our AJAX call
    var postStr = document.getElementById('email').value;
    //alert("Global Var - " + theglobalvar);
   
    makeRequestForEmail(url, postStr);
}
