/*
 * Default texts inputs
 *
 * @version		1.0.0	Remi	17/12/2008
 * @dependancy 	Jquery
 *
 * @tutorial
 *	- In form, put an input hidden" with id name id="defval" and you default
 *	text in a value attribut just after your <input type="text">
 *	- Change your class name disabled color in sClassTextColorDisabled
 *	- Enjoy :-)
 *
 * @example
 *	<input type="text" name="some_name" id="some_name" value="" />
 *	<input type="hidden" id="defval" value="Default text value" />
 *
 */

$(document).ready(function(){

	var sClassTextColorDisabled = 'text-color-disabled';

	// On load page put default input text
	$('input[id=\"defval\"]').each(function () {
		var oB = $(this).prev();
		$(oB).removeClass(sClassTextColorDisabled);
	   	if($(oB).val() == '') {
	     	$(oB).val($(this).val());
			$(oB).addClass(sClassTextColorDisabled);
		}
	});

	// On focus input we delete if the default text
	$('input[id=\"defval\"]').prev().focus(function () {
		var oB = $(this).next();
	   	if( ($(this).val()== oB.val()) ) {
	     	$(this).val('');
			$(this).removeClass(sClassTextColorDisabled);
		}
	});

	// On blur input verif if we put the default text
	$('input[id=\"defval\"]').prev().blur(function () {
		var oB = $(this).next();
		$(this).removeClass(sClassTextColorDisabled);
	   	if( ($(this).val() == '') || ($(this).val()== oB.val()) ) {
	   		$(this).val(oB.val());
	   		$(this).addClass(sClassTextColorDisabled);
		}
	});

	// On keyup input remove the class text color disabled
	$('input[id=\"defval\"]').prev().keyup(function () {
		$(this).removeClass(sClassTextColorDisabled);
	});

	// On submit form remove the default value
	$('form').submit(function() {
		$('input[id=\"defval\"]').prev().each(function () {
	    	if( $(this).val()== $(this).next().val() ) {
	      		$(this).val('');
	     		$(this).removeClass(sClassTextColorDisabled);
			}
		});
	});
})

