// JavaScript Document
function phone() {
var numericExpression = /^[0-9]+$/;	
if (document.myform.txtPhone.value.match(numericExpression)) {
return true;
} else {
	alert("Numbers Only");
	document.myform.txtPhone.value="";
	document.myform.txtPhone.focus();
}
};
function subby() {
		var question = "What is the sum of " + rand1 + " and " + rand2 + "?";
		var ans = prompt(question, "");
		checkPerson2(ans);
		
};


function verify() {
var dot = document.myform.txtEmail.value.indexOf(".");	
var at = document.myform.txtEmail.value.indexOf("@");	
if (document.myform.txtName.value == "" || document.myform.txtName.value.length < 5 || document.myform.txtName.value.indexOf("  ") > -1) {
alert("Please enter your name");
document.myform.txtName.value = "";
document.myform.txtName.focus();
}
else if (document.myform.txtBusName.value == "" || document.myform.txtBusName.value.length < 5 || document.myform.txtBusName.value.indexOf("  ") > -1) {
	alert("Please enter your the name of the business");
	document.myform.txtBusName.value = "";
	document.myform.txtBusName.focus();
}
else if (document.myform.txtBusType.value == "" || document.myform.txtBusType.value.length < 5 || document.myform.txtBusType.value.indexOf("  ") > -1) {
	alert("Please enter the type of business");
	document.myform.txtBusType.value = "";
	document.myform.txtBusType.focus();
}

else if (document.myform.txtPhone.value == "" || document.myform.txtPhone.value.length != 10) {
	alert("Please enter your 10 digit telephone number");
	document.myform.txtPhone.focus();
}

else if (document.myform.txtSite.value == "" || document.myform.txtSite.value.length < 3 || document.myform.txtSite.value.indexOf("  ") > -1) {
	alert("Please enter your current web address");
	document.myform.txtSite.value="N/A";
	document.myform.txtSite.focus();
}
else if (document.myform.txtEmail.value == "" || at == -1 || dot == -1 || document.myform.txtEmail.value.length < 5 || document.myform.txtEmail.value == "someone@something.com" || document.myform.txtEmail.value.indexOf("  ") > -1) {
	alert("Please enter a valid email address");	
	document.myform.txtEmail.value = "someone@something.com";
	document.myform.txtEmail.focus();
}
else if (document.myform.txtHear.value == "" || document.myform.txtHear.value.indexOf("  ") > -1) {
	alert("Please tell where you heard about us")
	document.myform.txtHear.value = "N/A";
	document.myform.txtHear.focus();
}
else if (document.myform.txtDetails.value == "" || document.myform.txtDetails.value.length < 10 || document.myform.txtDetails.value.indexOf("  ") > -1) {
	alert("Please tell us about the project");	
	document.myform.txtDetails.value = "";
	document.myform.txtDetails.focus();
}
else {
subby();
}

}
/****************************************************/
function phone2() {	
var numericExpression = /^[0-9]+$/;	
if (document.form1.phone.value.match(numericExpression)) {
return true;
}
else {
	alert("Numbers Only");
	document.form1.phone.value="";
	document.form1.phone.focus();
}
};

function verifyRefer() {
var dott = document.form1.fremail.value.indexOf(".");		
var att = document.form1.fremail.value.indexOf("@");
	
	if (document.form1.frname.value == "" || document.form1.frname.value.length < 5) {
		alert("Please fill in your name");
		document.form1.frname.focus();
} 
	else if (document.form1.frhow.value == "" || document.form1.frhow.value.length <3) {
		alert("Please tell us how you relate to this person");
		document.form1.frhow.focus();
}

	else if (document.form1.fremail.value == "" || document.form1.fremail.value.length < 5 || document.form1.fremail.value == "someone@something.com" || att == -1 || dott == -1) {
		alert("Please type your email");
		document.form1.fremail.value = "someone@something.com";		
		document.form1.fremail.focus();		
}

	else if (document.form1.fname.value == "" || document.form1.fname.value.length < 3) {
		alert("Please enter the name of the person you are refering.");
		document.form1.fname.focus();
	}
	else if (document.form1.lname.value == "" || document.form1.lname.value.length < 3) {
		alert("Please enter the last name of the person you are refering.");
		document.form1.lname.focus();
	}
	
	else if (document.form1.phone.value.length != 10) {
		alert("Please enter 10 digit telephone number");
		document.form1.phone.focus();
	}
	
	else if (document.form1.message.value == "" || document.form1.message.value.length <5) {
		alert("Please tell us about your friend");
		document.form1.message.value = "   N/A";
		document.form1.message.focus();
	}

	
	else {
		var question = "What is the sum of " + rand1 + " and " + rand2 + "?";
		var ans = prompt(question, "");
		checkPerson(ans);
	}


}

function checkPerson(ans) {
	if(ans == rand1 + rand2) {
		alert("Form has been correctly filled out");
		$("#form").append("<input type='hidden' name='isjavascript' value='true' />");
		document.form1.submit();
	} else {
		alert("Try again");
		verifyRefer();
	}	
}
function checkPerson2(ans) {
	if(ans == rand1 + rand2) {
		$("#form").append("<input type='hidden' name='isjavascript' value='true' />");
		document.myform.submit();
	} else {
		alert("Try again");
		verify();
	}	
}
