// JavaScript Document
$(document).ready(function(){
	// MENU WATERMARK
	var adrInput = $("#txtAddress");
	
	function removeAdr(){
		var adrVal = adrInput.val();
		if(adrVal == "City, State or Zip"){
			adrInput.val("");	
		}
	}
	
	function resetAdr(){
		var adrVal = adrInput.val();
		if(adrVal == ""){
			adrInput.val("City, State or Zip")
		}
	}
	adrInput.focus(removeAdr);
	adrInput.blur(resetAdr);
	
	// FEEDBACK.PHP
	$("#error").hide();
					
	// create variables for these divs that we will be targetting with jQuery				
	var nameInput = $("#name");
	var emailInput = $("#email");
	var msgInput = $("#message");
	
	// this function will remove whatever is in the Name field by setting it's value to nothing.  
	// NAME
	function removeName(){
		var nameVal = nameInput.val();
		if(nameVal == "Name"){
			nameInput.val("");	
		}
	}
	
	// when there is nothing in the field, set the value to Name
	function resetName() {
		var nameVal = nameInput.val();
		if(nameVal == "") {
			nameInput.val("Name"); 
		}	
	}
	// attach these two effects to the appropriate input field and tell them to execute the corresponding functions we just created.
	nameInput.focus(removeName);
	nameInput.blur(resetName);
	
	// EMAIL
	function removeEmail(){
		var emailVal = emailInput.val(); 
		if(emailVal == "Email"){
			emailInput.val("");
		}
	}
	
	function resetEmail(){
		var emailVal = emailInput.val();
		if(emailVal == "") {
			emailInput.val("Email");	
		}
	}
	emailInput.focus(removeEmail);
	emailInput.blur(resetEmail);
	
	// LOGO
	function removeMsg(){
		var msgVal = msgInput.val();
		if(msgVal == "Message"){
			msgInput.val("");	
		}
	}
	
	function resetMsg(){
		var msgVal = msgInput.val();
		if(msgVal == "") {
			msgInput.val("Message");	
		}
	}
	msgInput.focus(removeMsg);
	msgInput.blur(resetMsg);
			
	// targetting the form.. when they hit submit, run the checkThis function.
	$("#fb").submit(checkThis);
	
	// check to make sure that the name fields are not set to the values that we gave them (Name, Email, Message). If they do have those, it will display our error. The error is in the feedback.php file.. I placed it where it would need to show up.. it doesn't show up at first because of the error.hide that we did at the beginning of this block of jQuery.
	// VALIDATION of FORM
	function checkThis(){
		var nameVal = nameInput.val();
		var emailVal = emailInput.val();
		var msgVal = msgInput.val();
		if(nameVal == "Name" || emailVal == "Email" || msgVal == "Message"){
			$("#error").show();
			return false;	
		}else{
			return true;	
		}
	}
	
});
