
var xmlHttp;

function createXMLHttpRequest() 
{
    if (window.ActiveXObject) 
    {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) 
    {
        xmlHttp = new XMLHttpRequest();
    }
}

function captchaValidation() 
{
	var captcha = document.getElementById("captcha").value;
	removeElementIfAvailable();//Removes the tool tip if available
	createXMLHttpRequest();
	queryString =   "./CaptchaValidationServlet" ;
	var parameter = "?captcha=" + captcha;
	queryString = queryString + parameter;
	xmlHttp.onreadystatechange = handleStateChange;
	xmlHttp.open("GET", queryString, true);
	xmlHttp.send(null);
}

function handleStateChange( )
{
    if( xmlHttp.readyState == 4 )
    { 
        if( xmlHttp.status == 200 )
        {
        	var responseText1    =   document.createTextNode(xmlHttp.responseText);
        	var returnElements  =   xmlHttp.responseText;
		  	if(returnElements.length > 2 )
	  		{
				var newSpanForCaptcha 	= 	document.getElementById( "captcha_empty_font" );
	   			document.getElementById("captcha").style.borderColor = "#cc0000";
	   			var field = document.getElementById('captcha_empty_font');						  
				var newSpanForCaptcha = document.createElement('span');
				newSpanForCaptcha.setAttribute('id','newIdForCaptcha');						  
				newSpanForCaptcha.innerHTML = "&nbsp;&nbsp;<span class=\"hint\" style=\"height: 75px;\">The characters you entered didn't match the word verification.  Please try again.<span class=\"hint-pointer\">&nbsp;</span></span>";//Creates the tool tip for the job
				if(document.getElementById('newIdForCaptcha') == null)
				{
					field.appendChild(newSpanForCaptcha);//Appends the tool tip to the parent
				}
				refreshdiv();
				
	  		}
		  	else
			{
			  	formsubmit();
			}
		}
	    else
	    {
	       alert("Error loading pagen"+ xmlHttp.status + ":" + xmlHttp.statusText);
	    }
    }
}


 


//Customise those settings

var seconds = 5000000;
var divid = "id2";
var url = "./simpleImg";

////////////////////////////////
//
// Refreshing the DIV
//
////////////////////////////////

function refreshdiv(){

// The XMLHttpRequest object

	if (window.ActiveXObject) 
	{
	    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else if (window.XMLHttpRequest) 
	{
	    xmlHttp = new XMLHttpRequest();
	}

// Timestamp for preventing IE caching the GET request

fetch_unix_timestamp = function()
{
return parseInt(new Date().getTime().toString().substring(0, 10))
}

var timestamp = fetch_unix_timestamp();
var nocacheurl = url+"?t="+timestamp;

// The code...

xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp.responseText;
document.getElementById(divid).innerHTML="<img src="+nocacheurl+" >";
setTimeout('refreshdiv()',seconds*1000);
}
}
xmlHttp.open("GET",nocacheurl,true);
xmlHttp.send(null);
}

// Start the refreshing process



