// VCode Validation

lastVcodeKey = '';

function vcodeChange() {

	vcodeInput = document.getElementById('vcode');

	if (vcodeInput) {

		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..';

			ajaxCall('/_std.ajax?action=4&vcode='+escape(vcode), 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();

		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>)';

	}

}