$(document).ready(function() {

	/**
	 * Remove suggestions before submitting the form.
	 */
	$("#adminLoginForm").submit(function() {
		$(".suggestion").each(removeSuggestion);
	});
	
	/**
	 * Attach focus/blur events to suggestion fields.
	 */
	handleSuggestions();
});

function handleSuggestions() {	
	$(".suggestion").focus(removeSuggestion).blur(applySuggestion);
	$(".suggestion").each(applySuggestion);
}

/**
 * Apply the title attribute to any empty fields.
 */
var applySuggestion = function() {
	if ( $(this).val() == "" || $(this).val() == $(this).attr("title") ) {
		$(this).val($(this).attr("title"));
		$(this).addClass("suggestionStyle");
	} else {
		$(this).removeClass("suggestionStyle");
	}
}

/**
 * Remove suggestions from any blank fields.
 */
var removeSuggestion = function() {
	if ( $(this).val() == $(this).attr("title") ) {
		//if ( $(this).hasClass("firstField") ) {
			//$(this).select();
			//var name = $(this).attr("name");
			//setTimeout('$("input[name='+name+']").removeClass("firstField")', 100);
		//} else {
			$(this).val("");
		//}
		$(this).removeClass("suggestionStyle");
	//} else {
		//$(this).select();
	}
}


