// validation functions

function validlogin(lf) {

	wronginfo = "";
	validnumber = "0123456789";
	validchar = "abcdefghijklmnopqrstuvxzwyABCDEFGHIJKLMNOPQRSTUVXZWY";
	if (document.forms[lf].name.value == "") wronginfo += "\n - You must enter a userid ";
	if (document.forms[lf].password.value == "") wronginfo += "\n - You must enter a password ";
	if (wronginfo != '') {
		wronginfo = "To login, you must enter:" + wronginfo;
		alert (wronginfo);
		return false
	}else{
		return true
	}
}

function validcontact() {

	wronginfo = "";
	validnumber = "0123456789";
	validchar = "abcdefghijklmnopqrstuvxzwyABCDEFGHIJKLMNOPQRSTUVXZWY";
	if (document.forms['contact'].message.value == "") wronginfo += "\n - You must write your message before sending it to us.";
	if (wronginfo != '') {
		alert (wronginfo);
		return false
	}else{
		return true
	}
}

function validsearch() {

	wronginfo = "";
	if (document.forms['searchform'].criteria.value == "") wronginfo += "\n - You must type at least one criteria we can search for.";
	if (wronginfo != '') {
		alert (wronginfo);
		return false
	}else{
		return true
	}
}

function validcomment() {

	wronginfo = "";
	if (document.forms['commentform'].commtext.value == "") wronginfo += "\n - You must type your message before sending it.";
	if (wronginfo != '') {
		alert (wronginfo);
		return false
	}else{
		return true
	}
}

function validfaq() {

	wronginfo = "";
	if (document.forms['editfaqform'].newfaqquestion.value == "") wronginfo += "\n - You must type the question to this FAQ.";
	if (document.forms['editfaqform'].newfaqanswer.value == "") wronginfo += "\n - You must type the answer to this FAQ.";
	if (wronginfo != '') {
		alert (wronginfo);
		return false
	}else{
		return true
	}
}

function validvote() {
	wronginfo = "";
	if ((document.forms['voteform'].rate[0].checked == false) &&
		(document.forms['voteform'].rate[1].checked == false) &&
		(document.forms['voteform'].rate[2].checked == false) &&
		(document.forms['voteform'].rate[3].checked == false) &&
		(document.forms['voteform'].rate[4].checked == false))
		wronginfo += "\n - You must choose a rate before voting.";
	if (wronginfo != '') {
		alert (wronginfo);
		return false
	}else{
		return true
	}
}

function validpage() {

	wronginfo = "";
	validnumber = "0123456789";
	validchar = "abcdefghijklmnopqrstuvxzwyABCDEFGHIJKLMNOPQRSTUVXZWY";
	
	// first name, surname, gender, sin date of birth
	
	if (document.forms['editpageform'].newpgnav.value == "") {
		wronginfo += "\n - Page navigation cannot be blank ";
	}

	if (document.forms['editpageform'].newpgdescription.value == "") {
		wronginfo += "\n - Page description must be entered ";
	}

	if (document.forms['editpageform'].newpgtitle.value == "") {
		wronginfo += "\n - Page title is mandatory ";
	}

	if (document.forms['editpageform'].newpglink.value == "") {
		wronginfo += "\n - Page link should not be changed but is mandatory ";
	}

	if (document.forms['editpageform'].newpglogin.value == "") {
		wronginfo += "\n - Classification if navigation visible is mandatory ";
	}

	if (wronginfo != "") {
		wronginfo = "\n You failed to correctly enter the following: \n" + 
					  wronginfo 
		alert (wronginfo);
		return false;
	} 
	else {
		return true;
	}
}

function validuser(uf) {

	wronginfo = "";
	validnumber = "0123456789";
	validchar = "abcdefghijklmnopqrstuvxzwyABCDEFGHIJKLMNOPQRSTUVXZWY";
	
	// first name, surname, gender, sin date of birth
	
	if (document.forms[uf].newfname.value == "") {
		wronginfo += "\n - First name cannot be blank ";
	}
	if (document.forms[uf].newlname.value == "") {
		wronginfo += "\n - Last name cannot be blank ";
	}
	if (document.forms[uf].newuser.value == "") {
		wronginfo += "\n - Userid cannot be blank ";
	}
	else if ((document.forms[uf].newuser.value.length < 6) || (document.forms[uf].newuser.value.length > 12)) {
		wronginfo += "\n - Userid must have between 6 and 12 characters ";
	}
	if ((uf == "registeruserform") && (document.forms[uf].newpw.value == "")) {
		wronginfo += "\n - Password cannot be blank ";
	} 
	else if ((uf == "registeruserform") && ((document.forms[uf].newpw.value.length < 6)||(document.forms[uf].newpw.value.length > 12))) {
		wronginfo += "\n - Password must have between 6 and 12 characters ";
	}
	else if (document.forms[uf].newpw.value != document.forms[uf].confpw.value) {
		wronginfo += "\n - Password and confirmed password must match ";
	}
	if (document.forms[uf].newemail.value == "") {
		wronginfo += "\n - e-mail address cannot be blank ";
	} 
	else if (document.forms[uf].newemail.value != document.forms[uf].confemail.value) {
		wronginfo += "\n - e-mail and confirmed e-mail must match ";
	}

	if (wronginfo != "") {
		wronginfo = "\n You failed to correctly enter the following: \n" + 
					  wronginfo 
		alert (wronginfo);
		return false;
	} 
	else {
		return true;
	}
}

