// Global use javascript functions
// Copyright 2009. All Rights Reserved.
// Author: Jason Wagner


/*****************************************************************************
* Function: redirectMe(url,sec)
* Input: Takes the url to redirect to. And the time before redirect, in seconds.
* Returns: N/A
******************************************************************************/
	function redirectMe(url,sec) {
		window.setTimeout("window.location.href = '" + url + "';",sec * 1000);
		return true;
	}
	
/*****************************************************************************
* Function: saveOrder(listclass,hiddenfield)
* Input: Call this to serialize and store the order of sortable elements.
* Returns: N/A
******************************************************************************/
	function saveOrder(listclass,hiddenfield) {
		var order = Sortable.serialize(listclass);
		document.getElementById(hiddenfield).value = order;
		document.position.submit();
		return false;
	}

/*****************************************************************************
* Function: fadeBlock(myElement,command)
* Input: Takes the element to open/close (usually a div).  Takes "open" or 
* 		"close" as an action.
* Returns: N/A
******************************************************************************/
	function fadeBlock(myElement,command) {
		if(command == "close")
			new Effect.Fade(document.getElementById(myElement));
		if(command == "open")
			new Effect.Appear(document.getElementById(myElement));	 
		return true;   
	}
	
	
/*****************************************************************************
* Function: checkValues()
* Input: Validates form input
* Returns: Submits form
******************************************************************************/
function chkEmail(email) {
	return (email.indexOf(".") > 2) && (email.indexOf("@") > 0);
}
function checkValues() 
{
	
	var string = "Please fill out the required information:\n ";
  
    if (chkEmail(document.getElementById("email").value) == false)  {
		alert("Please enter a valid email address.");
		return
	}
	  
    if (document.getElementById("name").value == "") 
      string += "\n -Name";
    if (document.getElementById("email").value == "") 
      string += "\n -Email Address";
	if (document.getElementById("subject").value == "") 
      string += "\n -Subject";
    if (document.getElementById("message").value == "") 
      string += "\n -Message";
    
	
	if (string == "Please fill out the required information:\n ")
			document.getElementById("contact").submit();
	else {
		alert(string);
		return;
	}	
}

