

function valname(){

if (!document.survey.name.value){
        alert("You must enter your name");
        document.survey.name.focus();
        return false;
    }else{
        return true;
    }
}

function valspamcheck(){
var mycheck = document.survey.maths.value;
if (!document.survey.maths.value){
        alert("Please add 2 + 5 for our antispam");
        document.survey.maths.focus();
        return false;
    }else{
		if(mycheck==7){
        return true;
		}
		else{
			alert("Please check your maths");
        	document.survey.maths.focus();
        	return false;
		}
			
    }
}

function valnum1(){
    var theNumbersOnly = "";
    var theChar = "";
    var theInput = document.survey.phone.value;
    
    for (i = 0; i < theInput.length; i++){
        theChar = theInput.substring(i,i+1);
        if (theChar >= "0" && theChar <= "9"){
            theNumbersOnly = "" + theNumbersOnly + theChar;
        }
}
    
}

function valnum2(){

if (!document.survey.phone.value){
        alert("Please enter your phone number");
        document.survey.phone.focus();
        return false;
    }else{
        return true;
    }

}

function valemail(){
var address = document.survey.email.value;
var atLoc = address.indexOf('@',1);
var dotLoc = address.indexOf('.', atLoc+2);
var length = address.length;

if ((atLoc>0) && (dotLoc>0) && (length>dotLoc+2)){
	return true;
	
	}else{
	alert("Sorry, but you have entered an invalid e-mail address. Please enter a valid address and try again, thanks.")
        document.survey.email.focus();
	return false;
	}

}

function validate(){

	var name = document.survey.name.value;
	var phone = document.survey.phone.value;
	var email = document.survey.email.value;


	if (valname () && valnum2 () && valemail () && valspamcheck()){
		document.feedback.feedback.value = ("Your Name: " + name + "\r\nEmail: " + email + "\r\nTel#: " + phone)
		return true;
	}else{
		return false;
	}

}
