/*
01-02-07 drs Created simple AJAX call system to display Captcha validation.
01/14/07 ajb, updated to send status back to the calling page.
         This is called by:  \include\incUserFeedbackFormShow.asp
         

showCaptcha() - determines whether to call LiveCaptcha.asp based upon length of comments field
                and setting of bRequireCaptcha. If length of comments is zero (0) or bRequireCaptcha
                is false, then Captcha will not be displayed.

stateChanged() - sends message to calling program that Captcha is ready to be displayed.

getxmlHttpObject() - determines which browser's XMLhttpRequest() to use.

*/
var xmlHttp

function showCaptcha(str, bRequireCaptcha)
{
	if (str.length==0 || bRequireCaptcha==0 ){ 
		document.getElementById("CaptchaME").innerHTML="";
		return;
	}

	funAjaxComplete(false); // Set the status to false (this function must be defined in the calling object 	
		
	xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null){
			alert ("Browser does not support HTTP Request");
			return;
		}
	var url="/LiveCaptcha.asp";
	url=url+"?RC="+bRequireCaptcha;
	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("CaptchaME").innerHTML=xmlHttp.responseText;
		funAjaxComplete(true); // We have completed the call
	} 
} 


function GetXmlHttpObject()
{ 
var objXMLHttp=null;

	if (window.XMLHttpRequest) { // Mozilla, Safari,... 
		objXMLHttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) { // IE 
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	return objXMLHttp;
} 
	
	
	

//  Use so set a status messag on the calling page.  Note:  They must have the label  "lblCaptchaStatus"
function funAjaxComplete(bStatus){
	if (bStatus == true){
			// We have returned the capcha image
			document.getElementById("lblCaptchaStatus").innerHTML = '';
			bCaptchaImageComplete = true;  // Defined in  include\incUerFeedbackFormShow.asp	
			bCapchaAlreadyLoaded = true;   // Defined in  include\incUerFeedbackFormShow.asp
		}
	else{
		bCaptchaImageComplete = false;		
		document.getElementById("lblCaptchaStatus").innerHTML = 'Creating  Captcha Image...';
		}
}

