
var oRequest = null;
var sCaptchaScriptURL = '/scripts/captcha.pl';
if(window.XMLHttpRequest){
	oRequest = new XMLHttpRequest();
}else if(window.ActiveXObject){
	oRequest=new ActiveXObject("Msxml2.XMLHTTP");
	if (!oRequest){
		oRequest=new ActiveXObject("Microsoft.XMLHTTP");
	}
}

function getNewCaptcha(){
	new Ajax(sCaptchaScriptURL, {method: 'get'}).request().addEvent('onComplete', function(text,xml)
	{
		if(xml){
			var root =  xml.documentElement;
			switch(root.nodeName){
				case "captcha":
					if($('capImg') && $('capCrypt')){
						$('capImg').setProperty("src", root.getAttribute("src"));
						$('capCrypt').setProperty("value", root.getAttribute("md5"));
					}
				break;
			}
		}
	});
}


function refreshCallback(){
	if(oRequest){
		oRequest.onreadystatechange=function(){
			if(oRequest.readyState == 4){
				if(oRequest.status == 200 && oRequest.responseXML){
					var root =  oRequest.responseXML.documentElement;
					switch(root.nodeName){
						case "captcha":
							var capImg = document.getElementById("capImg");
							var capCrypt = document.getElementById("capCrypt");
							if(capImg && capCrypt){
								capImg.setAttribute("src", root.getAttribute("src"));
								capCrypt.setAttribute("value", root.getAttribute("md5"));
							}
						break;
					}
				}
			}
		}
	}
}

