// Global use javascript functions
// Copyright 2010. 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: fadeBlock(element_id,command)
* Input: Takes the element to open/close (usually a div).  Takes "open" or 
* 		"close" as an action.
* Returns: N/A
******************************************************************************/
	function fadeBlock(element_id,command) {
		if(command == "close") {
			$("#" + element_id).fadeOut();
		}
		if(command == "open") {
			$("#" + element_id).fadeIn(); 
		}
		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;
	}	
}

/*****************************************************************************
* Function: arrows()
* Input: Shows the next and previous arrows when hoving over a photo in the gallery.
* Returns: N/A
******************************************************************************/
function arrows() {
	$(".prevArrow").toggle();
	$(".nextArrow").toggle();
}


/*****************************************************************************
* Function: deleteBlog(id)
* Input: Deletes selected blog
* Returns: N/A
******************************************************************************/
function deletePhoto(id) {				
		var sure = confirm("Are you sure you want to delete?");		
		if(sure) {			
			$.ajax({
			  url: "savedata.php?action=delete&id=" + id,
			  success: function(html){
			  	fadeBlock('item_'+id,"close");
			  }
			});		
		}
}

