//***************************************************
//           TEST CAPTCHA
//***************************************************

var chaptchaGood = false;
var imgref;
var imgrollover;
var loadingImg = '/images/captcha/loading.gif';
var wrongImg = '/images/captcha/wrong.png';

function checkCaptch(id,ref,rollover) {
	
	// keep track of clicked image so it can be verified when the information is sent
	if (object('CAPVER')) {
		object('CAPVER').value = id;
	}
	
	imgref = ref;
	
	// dont do anything if everything is good
	if (chaptchaGood || imgref.src.substring(imgref.src.length-8,imgref.src.length) == wrongImg.substring(wrongImg.length-8,wrongImg.length)) { return;	}

	imgref.src = loadingImg;
	imgrollover = rollover;
	
	var index = ajax.length;
	ajax[index] = new sack();	
	ajax[index].requestFile = '/captcha/checkCaptcha.php?captchaID='+id;
	ajax[index].onCompletion = function(){ checkCaptchReturn(index) };
	ajax[index].runAJAX();

}

function checkCaptchReturn(index) {

	eval(ajax[index].response);
	if (chaptchaGood) {
		CAPTCHA = true;
		imgref.src = imgrollover;
		changeStyle('formalert-good', document.getElementById('formalert-CAPTCHA'));
	} else {
		CAPTCHA = false;
		imgref.src = wrongImg;
	}
};

