var http_check_Captcha=false;
//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObjectCaptcha()
{
 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 http_request_Captcha = getXmlHttpRequestObjectCaptcha();

//Initiate the AJAX request
function makeRequestCaptcha(url, param) {
//If our readystate is either not started or finished, initiate a new request
 if (http_request_Captcha.readyState == 4 || http_request_Captcha.readyState == 0) {
   //Set up the connection to captcha_test.html. True sets the request to asyncronous(default) 
   http_request_Captcha.open("POST", url, true);
   //Set the function that will be called when the XmlHttpRequest objects state changes
   http_request_Captcha.onreadystatechange = updatePageCaptcha; 

   //Add HTTP headers to the request
   http_request_Captcha.setRequestHeader("Content-type","application/x-www-form-urlencoded");
   http_request_Captcha.setRequestHeader("Content-length", param.length);
   http_request_Captcha.setRequestHeader("Connection", "close");

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

//Called every time our XmlHttpRequest objects state changes
function updatePageCaptcha()
{
 //Check if our response is ready
 if (http_request_Captcha.readyState == 4)
 {
   //Set the content of the DIV element with the response text
   document.getElementById('captchaSpan').innerHTML = http_request_Captcha.responseText;
   var retvalue = http_request_Captcha.responseText;
   if(retvalue=="false")
   {
   document.getElementById('captchaSpan').innerHTML = "Invalid Security Code. Try again.!";
   document.getElementById('Submit').disabled = false;
   http_check_Captcha = false;
   //Get a reference to CAPTCHA image
   img = document.getElementById('imgCaptcha'); 
   //Change the image
  // img.src = 'loadImage.php?' + Math.random();
   }
   else if(retvalue=="true")
   {
   //document.getElementById('captchaSpan').innerHTML = http_request_Captcha.responseText;
   //document.getElementById('msgDiv').innerHTML = 'Link to this deal has been sent. <a href="#" class="Arial-comments-pageprevnext" onClick="history.back();">Click here to go to delas Page</a>';
   document.getElementById('msgDiv').style.visibility = 'visible';
   document.mailFrm.reset();
   document.getElementById('mailTable').style.visibility = 'hidden';   
   //document.getElementById('Submit').disabled = false;
   http_check_Captcha = true;
   }
 }
 else
 {
 document.getElementById('captchaSpan').innerHTML = '<img src="../images/loader.gif" />';
 //document.getElementById('Submit').disabled = true;
 }

}

//Called every time when form is perfomed
function getCaptcha(theForm)
{
 //Set the URL
 var url = '../deals/mailtofriends.php';
 //Set up the parameters of our AJAX call
 //var postStr = theForm.txtSecurityCode.name + "=" + encodeURIComponent(theForm.txtSecurityCode.value );

var postStr = theForm.txtSecurityCode.name + "=" + encodeURIComponent(theForm.txtSecurityCode.value ) + "&" + theForm.mynameTxt.name + "=" + encodeURIComponent(theForm.mynameTxt.value ) + "&" + theForm.mymailTxt.name + "=" + encodeURIComponent(theForm.mymailTxt.value ) + "&" + theForm.friendnameTxt1.name + "=" + encodeURIComponent(theForm.friendnameTxt1.value ) + "&" + theForm.friendnameTxt2.name + "=" + encodeURIComponent(theForm.friendnameTxt2.value ) + "&" + theForm.friendnameTxt3.name + "=" + encodeURIComponent(theForm.friendnameTxt3.value ) + "&" + theForm.friendnameTxt4.name + "=" + encodeURIComponent(theForm.friendnameTxt4.value ) + "&" + theForm.friendmailTxt1.name + "=" + encodeURIComponent(theForm.friendmailTxt1.value ) + "&" + theForm.friendmailTxt2.name + "=" + encodeURIComponent(theForm.friendmailTxt2.value ) + "&" + theForm.friendmailTxt3.name + "=" + encodeURIComponent(theForm.friendmailTxt3.value ) + "&" + theForm.friendmailTxt4.name + "=" + encodeURIComponent(theForm.friendmailTxt4.value ) + "&" + theForm.urlHid.name + "=" + encodeURIComponent(theForm.urlHid.value ) + "&" + theForm.titleHid.name + "=" + encodeURIComponent(theForm.titleHid.value );




 //Call the function that initiate the AJAX request
 makeRequestCaptcha(url, postStr);
}
