// Checks to make sure the passed field is not blank
// returns true if it is blank
function isblank(s){
	for(var i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if((c != ' ') && (c != '\n') && (c != '\t')) return false;
		}
	return true;
	}

// Checks to make sure all necessary information is present in error submission form
function submission_validate(f){
	if (isblank(f.name.value) ||
	isblank(f.school_name.value) ||
	isblank(f.address.value) ||
	isblank(f.city.value) ||
	isblank(f.state.value) ||
	isblank(f.zip.value) ||
	isblank(f.country.value) ||
	isblank(f.email.value) ||
	isblank(f.phone.value)){
		alert('You must fill in all your contact information'); return false;
		}
		
	if (isblank(f.book_title.value) ||
	isblank(f.book_grade.value) ||
	isblank(f.copyright.value)){
		alert('You must fill in all required book information'); return false;
		}

	if ((isblank(f.error1_page.value) || isblank(f.error1.value)) &&
		(isblank(f.error2_page.value) || isblank(f.error2.value)) &&
		(isblank(f.error3_page.value) || isblank(f.error3.value))){
			alert('You must fill in some error information'); return false;
			}

	if (isblank(f.isbn.value)){
		return isbn_validate(f);
		}
		
	return true;
	}
	
// Checks to make sure all parts of an ISBN are filled in	
function isbn_validate(f){
	if (isblank(f.isbn1.value) ||
		isblank(f.isbn2.value) ||
		isblank(f.isbn3.value) ||
		isblank(f.isbn4.value)){
			alert('You must fill in all parts of the isbn'); return false;
		}

	}	

// Checks to make sure all necessary information is present when submitting book 
// information in the admin section.	
function book_validate(f){
	if (isblank(f.booktitle.value) ||
		isblank(f.grade.value) ||
		isblank(f.copyright.value) ||
		(f.type[f.type.selectedIndex].value == "")){
				alert('You must fill in all required fields'); return false;
		}
		
	if((f.type[f.type.selectedIndex].value == "other") && (f.othertype.value == "")){
			alert('You must fill in all required fields'); return false;
		}
		
	if (isblank(ISBN)){
		return isbn_validate(f);
		}

	return true;
	}
	
// Checks to make sure that all the necessary information is present when submitting
// error information in the admin section
function error_validate(f){
	if (isblank(f.page.value) ||
		isblank(f.location.value) ||
		isblank(f.original.value) ||
		isblank(f.revision.value) ||
		(f.type[f.type.selectedIndex].value == "")){
		
		alert('You must fill in all required fields'); return false;
		}

	
	return true;
	}
	
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateEmail(theform){
	var emailID=theform.email;
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

