// JavaScript Document


// Redirect function used once a new entry has been created or a message has been removed.
  function redirect_to_home() {
    setTimeout("location.href='guestbook.php'", 2000);
  }
  // Redirect function used once a new entry has been created or a message has been removed.
  function redirect_to(pagename) {
    setTimeout("location.href=pagename", 2000);
  }
  
//Check is the subject/message is blank in the guestbook form.
function message_validate ()
{
	var subj = document.add_form.subject.value;
	var msg = document.add_form.message.value;
	
	if (subj == '')
	{document.add_form.subject.style.backgroundColor = "#F33";
	alert ("Subject is blank.")
	return false;
	
	}else if (msg == '')
	{document.add_form.message.style.backgroundColor = "#F33";
	alert ("Message is blank.")
	return false;

	}else{
	return true;
	}	
	}
	
	
	
	//------------------------------------------------------------------------------------------------------------------------------------------------
	//											The following is form validation for the register form
	
	function showImage(imagename, imageurl, myvalidate) {
document[imagename].src = imageurl;
}

function myvalidate()
  {
	  var first_name = document.rego.first_name.value;
	  var last_name = document.rego.last_name.value;
	  var email = document.rego.email.value;
	  var uname = document.rego.uname.value;
	  var pword = document.rego.pword.value;
	   
	  if (first_name == '')
	   		{document.rego.first_name.style.backgroundColor = "#F33";
	   		showImage("reqfirst_name", "../_images/req.gif")
	  }else{
		   document.rego.first_name.style.backgroundColor = "#6F3";
		   showImage("reqfirst_name", "../_images/ach.gif")
	  }
	   
	  if (last_name == '')
	   		{document.rego.last_name.style.backgroundColor = "#F33";
	  		 showImage("reqlast_name", "../_images/req.gif")
	  }else{
		   document.rego.last_name.style.backgroundColor = "#6F3";
		   showImage("reqlast_name", "../_images/ach.gif")
	  }
	   
	  if (email == '')
	  		 {document.rego.email.style.backgroundColor = "#F33";
	  		 showImage("reqemail", "../_images/req.gif")
	  
	  }else if (email.indexOf("@") <= 0)
		   	{document.rego.email.style.backgroundColor = "#F33";
			showImage("reqemail", "../_images/req.gif")
			
	  }else if (email.indexOf(".") <= 1 )
			{document.rego.email.style.backgroundColor = "#F33";
			showImage("reqemail", "../_images/req.gif") 
			
	 }else{		 
		 	document.rego.email.style.backgroundColor = "#6F3";
	   		showImage("reqemail", "../_images/ach.gif")
	 }
			
	   if (uname == '')
	  		{document.rego.uname.style.backgroundColor = "#F33";
	  		showImage("requname", "../_images/req.gif")
	   }else{
		   document.rego.uname.style.backgroundColor = "#6F3";
		   showImage("requname", "../_images/ach.gif")
	   }
	   
	   if (pword == '')
		   {document.rego.pword.style.backgroundColor = "#F33";
		   showImage("reqpword", "../_images/req.gif")
	   }else{
		   document.rego.pword.style.backgroundColor = "#6F3";
		   showImage("reqpword", "../_images/ach.gif")
	   }
	    		   		   	   	   	   
	   if (first_name == "")
	   		{alert("Please fill in First Name");
			return false;
   		
		}else if (last_name == "")
			{alert("Please fill in Last Name");
			return false;
			
		}else if (email.indexOf("@") <= 0)
		   	{alert("Please fill in email");
			return false;
			
		}else if (email.indexOf(".") <= 1 )
			{alert("Please fill a valid email");
			return false;
			
		}else if (uname == "")
			{alert("Please enter a Username");
			return false;
			
		}else if (pword == "")
			{alert("please fill in a password")
			return false;
			
		}else if (pword != "")
		{var answer = confirm('Is the following correct? \nFirst name: ' + document.rego.first_name.value + '\nLast name: ' +  document.rego.last_name.value + '\nEmail: '+ document.rego.email.value + '\nUser name: ' +  document.rego.uname.value);
		if (answer)	
			{alert("Thank you for registering.")
			return true ;
		}else
			alert("Please correct errors")
			return false;
			
			}
  }
    
function resetfirst_name()
	{
		var first_name = document.rego.first_name.value;
		document.rego.first_name.style.backgroundColor = "#FFF";
	}
	
function resetlast_name()
	{
		var last_name = document.rego.last_name.value;	
		document.rego.last_name.style.backgroundColor = "#FFF";
	}

function resetemail()
	{
		var email = document.rego.email.value;		
		document.rego.email.style.backgroundColor = "#FFF";
	}

function resetuname()
	
	{
		var uname = document.rego.uname.value;		
		document.rego.uname.style.backgroundColor = "#FFF";
	}
function resetpword()
	
	{
		var pword = document.rego.pword.value;		
		document.rego.pword.style.backgroundColor = "#FFF";
	}
	
	
	
	
function resetimg()
	{showImage("reqfirst_name", "../_images/blank.gif")
	document.rego.first_name.style.backgroundColor = "#FFF";
	showImage("reqlast_name", "../_images/blank.gif")
	document.rego.last_name.style.backgroundColor = "#FFF";
	showImage("reqemail", "../_images/blank.gif")
	document.rego.email.style.backgroundColor = "#FFF";
	showImage("requname", "../_images/blank.gif")
	document.rego.uname.style.backgroundColor = "#FFF";
	showImage("reqpword", "../_images/blank.gif")
	document.rego.pword.style.backgroundColor = "#FFF";
	}
	
	
	//																	End of register validation
	//------------------------------------------------------------------------------------------------------------------------------------------------
	