// VCode Validation
var lastVcodeKey = '';
function vcodeChange() {
	var vcodeInput = document.getElementById('vcode');
	if (vcodeInput) {
		var vcode = vcodeInput.value;
		if (vcode == lastVcodeKey) return; // to safeguard from double ajax calls via keyup/keydown
		lastVcodeKey = vcode;
		if (vcode.length < 5) {
			document.getElementById('vcodeErr').innerHTML = 'Too short';
		} else {
			document.getElementById('vcodeErr').innerHTML = 'Checking..';
			var url = '/_std.ajax?action=4&vcode=' + escape(vcode);
			var vcodeKeyInput = document.getElementById('vcode_key');
			if (vcodeKeyInput) url += '&vcode_key=' + escape(vcodeKeyInput.value);
			ajaxCall(url, vcodeResponse, true);
		}
	}
}
function vcodeResponse() {
	if (! (ajax.readyState == 4 || ajax.readyState == "complete")) return;
	if (ajax.responseText == 'PASS') {
		document.getElementById('vcodeErr').innerHTML = 'Code is correct';
		document.getElementById('submitBtn').disabled = false;
		document.getElementById('submitBtn').focus();
		var vSection = document.getElementById('vcodeSection');
		if (vSection) vSection.style.display = 'none';
	} else {
		document.getElementById('vcodeErr').innerHTML = '<span style="color: #FF0000">Code does not match</span> (<a href="javascript:window.location.reload()">refresh</a>)';
	}
}

