/*
* BOTFOCUS
* 	- When loaded the field value is set to the title (will just be blank if the title is not set)
*	- When the field gains focus, the value is cleared only if the value is equal to the title
*	- When the field loses focus, the value is reset to the title if the value is nothing
*	NOTES:
*	- Works well with the jquery validation class
* REQUIRES
* - jquery 1.3.2
* 
* Jay Richardson
* Werkbot Studios - www.werkbot.com
*/
$(document).ready(function() {	
	//SET THE VALUE OF THE INPUT FIELD TO THE TITLE
		$(".botfocus input:text").each( function() {
			if($(this).attr("title")){
				$(this).val($(this).attr("title"));		
			}
		});	
	//DEFINE THE FOCUS FUNCTION - IF THE VALUE IS EQUAL TO THE TITLE OF THE FIELD WE SET THE VALUE TO EMPTY
		$(".botfocus input:text").focus(function () {
			if($(this).val()==$(this).attr("title")){
				$(this).val("");	
			}
		});
	//DEFINE THE BLUR FUNCTION - IF THE VALUE IS EMPTY WE SET THE VALUE OF THE FIELD TO THE TITLE OF THE FIELD
		$(".botfocus input:text").blur(function () {
			if($(this).val()==""){
				$(this).val($(this).attr("title"));		
			}
		});	
	//WHEN A FORM IS SUBMITTED WE CLEAR THE VALUE OF THE FIELD IF THE VALUE IS EQUAL TO THE TITLE OF THE FIELD
		$(".botfocus").submit( function () {
			$(this).find("input:text").each( function() {
				if($(this).val()==$(this).attr("title")){
					$(this).val("");
				}
			});	
		});
});