/*JavaScript Document
Yaakov benYosef
10/22/06
copywrite 2006
Java script form validation
the reuse of this code requires a link back to about-torah.org
*/


function validate(){ // validation function header

var hyper = document.guestbook.entrycomments.value.toLowerCase(); // convert all comments to lower case
var theHyper = document.guestbook.entrycomments.value;//entred comments
var hyperLoc = theHyper.indexOf("http://"); //hypertext entry format
var nameLen = document.guestbook.entryname.value.length; // name length
var commentsLen = document.guestbook.entrycomments.value.length; // comment entry length
var theEmail = document.guestbook.entryemail.value; // entred email address      
var atLoc = theEmail.indexOf("@"); //email @ entry format
var dotLoc = theEmail.indexOf(".");// email . entry format
var len = theEmail.length; // email length

if (!document.guestbook.entryname.value || nameLen > 40){ // check entred name value for existance and length
	alert ("You are required to enter a first name and it must be less than 40 characters long.");
	document.guestbook.entryname.focus();
	return false;
	}
if (atLoc < 1 || dotLoc < 3 || len < dotLoc+3){ //check email format for @ and . at proper locations
	alert ("Please enter your e-mail address properly.");
	document.guestbook.entryemail.focus();
	return false;
	}
if (commentsLen > 80 || hyperLoc >= 0){ // check comments length alsa look and reject for url
	alert ("You are required to enter comments that must be less than 80 characters long and without web addresses.");
	document.guestbook.entrycomments.focus();
	return false;
	}
	else{
		return true;// return control to html doc
		}
}
