// ----------------------------------------------------------------
// CAPTCHA antispam form code
// ----------------------------------------------------------------
// public methods
// ----------------------------------------------------------------

// Attach to body onLoad event
function fnCaptchaLoad() {
	fnCaptchaGetImage();
	document.Resume.SUBMIT.disabled=false
	return true;
	}

// Attach to 'get new picture' button press event
function fnCaptchaNew() {
	fnCaptchaGetImage();
	document.Resume.captcha.focus();
	return true;
	}

// Attach to form reset event
function fnCaptchaReset() {
	var e = document.getElementById('captcha_error');
	e.innerHTML='&nbsp;';
	return true;
	}

// Attach to form submit event
function fnCaptchaSubmit() {
	if(fnCaptchaRequiredFields()&&fnCaptchaCheck()){
		return true;
		}else{
		return false;
		}
	}

// ----------------------------------------------------------------
// private methods
// ----------------------------------------------------------------

function fnCaptchaRequiredFields(){
	var f = document.Resume;
	var e = document.getElementById('captcha_error')
	if(f.name.value.length==0){
		e.innerHTML='<font color="#FF0000" face="arial">Please enter your name in the form and try again.</font>';		
		f.name.focus();
		return false;
		}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(f.email.value)){
		// regexp is valid email format
	}else{
		e.innerHTML='<font color="#FF0000" face="arial">Please enter your email in the form and try again.</font>';		
		f.email.focus();
		return false;
		}
	if(f.phone.value.length==0){
		e.innerHTML='<font color="#FF0000" face="arial">Please enter your phone in the form and try again.</font>';		
		f.phone.focus();
		return false;
		}
	return true;
	}

function fnCaptchaCheck() {
	var f = document.Resume;
	var e = document.getElementById('captcha_error');
	if(f.captcha_text.value.toLowerCase()==f.captcha_value.value.toLowerCase()){
		f.action = f.captcha_action.value;
		return true;
	}else{
		f.action = document.location.href // redirects to same page on error
		e.innerHTML='<font color="#FF0000" face="arial">Typed characters do not match the picture. Please try again.</font>';
		return false;
		}
	}

function fnCaptchaGetImage(){
	var f = document.Resume;
	var a = new Array('noscript','2m94y3','6nh24p','8w7x9z','9y4e5e','h2pec9','k4y75u');
	var i = Math.floor(Math.random()*6)+1;  // generates a random number between 1 and 6
	// fnCaptchaReset();
	f.captcha_image.src = 'resources/captcha/' + a[i] + '.gif';
	f.captcha_value.value = a[i];
	f.captcha_text.value = '';
	return true;
	}

// ----------------------------------------------------------------


