// JavaScript Document

function getAjaxObject(){
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser doesn't suppport Ajax!");
				return false;
			}
		}
	}
	return ajaxRequest;
}

function loadCaptcha(){
				document.getElementById("captcha").src='captcha_image.php?id=' + Math.random();
	}
	
function checkCaptcha(value){
var res1=getAjaxObject();
res1.onreadystatechange=function(){
	if(res1.readyState==4){
		if(res1.responseText=='no'){
			document.getElementById("errorCaptcha").innerHTML='(Invalid Character)';
		}
		else{
			document.getElementById("errorCaptcha").innerHTML="";
			return true;
		}
	
	}
}
res1.open("GET","check_captcha.php?code="+ value +"&id="+Math.random(),true);
res1.send(null);
}
	
function loadNewCaptcha(captchaDivId){
	document.getElementById(captchaDivId).src='captcha_image.php?id=' + Math.random();
}
function checkNewCaptcha(value,errorId){
	var ErrorInCaptcha= '';
	var url = "check_captcha.php?code="+value;
	http_check.open("GET", url, true);				
	http_check.onreadystatechange = function test(){
		if(http_check.readyState == 4) {
			var response = http_check.responseText;
			if(response=='yes'){
				document.getElementById(errorId).innerHTML = '';
				ErrorInCaptcha='';
			}else{
				document.getElementById(errorId).innerHTML = 'Invalid code';
				ErrorInCaptcha='yes';
				return false;
			}
		}
	}				
	http_check.send(null);
}
	
