 /**
 * @brief	Fonctions js Champs Input,...
 * @author	Nicolas Bodrefaux
 * @since	20/06/2010
 * @version	1.0
 */

function FaitTableau(n)
{
	// Création d'un tableau (array)
	// aux dimensions du nombre de paramètres.
	this.length = n;
	for (var i = 0; i <= n; i++)
	{
		this[i] = 0;
	}
	return this
}

function clear_form(name) {
    $(name).find(':input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
                $(this).val('');
            break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
        }
    });
}

$(function()																	// JQUERY
{
	$("input").live("change", function()										// Supprime les espaces avant et eprès la valeur .
	{																			// . pour tous les champs
		var valeurtrim = jQuery.trim($(this).attr('value'));
		$(this).val(valeurtrim);
	});
	$("textarea").live("change", function()										// Supprime les espaces avant et eprès la valeur .
	{																			// . pour tous les champs
		var valeurtrim = jQuery.trim($(this).attr('value'));
		$(this).val(valeurtrim);
	});

/* NEW JS - v4.2 */
	$(".actif").live("change", function()										// Pour la vérification des champs actifs
	{
		if(($(this).attr('value')!='') && ($(this).attr('value')!='http://') && ($(this).attr('value')!='http%3A%2F%2F'))
		{
			$(this).css({ border: "#78FF37 solid 1px", background: "#FFFFFF" });
		}else{
			$(this).css({ border: "#99CCFF solid 1px", background: "#FFFFFF" });
		}
	});
	$(".obligatoire").live("change", function()									// Pour la vérification des champs obligatoires
	{
		if(($(this).attr('value')!='') && ($(this).attr('value')!='http://') && ($(this).attr('value')!='http%3A%2F%2F'))
		{
			$(this).css({ border: "#999 solid 1px", background: "#FFF" });
		}else{
			$(this).css({ border: "#FF0000 solid 1px", background: "#FFF" });
		}
	});
/* -------- v4.2 */
	
	$(".verifnonobli").live("change", function()								// Pour la vérification des champs non obligatoires
	{
		if(($(this).attr('value')!='') && ($(this).attr('value')!='http://') && ($(this).attr('value')!='http%3A%2F%2F'))
		{
			$(this).css({ border: "#78FF37 solid 1px", background: "#FFFFFF" });
		}else{
			$(this).css({ border: "#99CCFF solid 1px", background: "#FFFFFF" });
		}
	});
	/*
	$(".verifobli").live("change", function()										// Pour la vérification des champs obligatoires
	{																				// Class verifoblisv pour ne pas affiche le valid ou invalid
		if(($(this).attr('value')!='') && ($(this).attr('value')!='http://') && ($(this).attr('value')!='http%3A%2F%2F'))
		{
			if(($(this).attr('class'))!='verifobli verifoblip')
			{
				$(this).next().attr({innerHTML:'<img src="../site/img/biblico/chargementDonnees.gif" alt="Loading"/>'});
			}else{
				if(($(this).attr('class'))!='verifobli verifoblisv'){ $(this).next().attr({innerHTML:'<img src="../site/img/biblico/ico_valid.png" alt=""/>'}); }
				$(this).css({ border: "#78FF37 solid 1px", background: "#D1FFBB" });
			}
		}else{
			if(($(this).attr('class'))!='verifobli verifoblisv'){ $(this).next().attr({innerHTML:'<img src="../site/img/biblico/ico_invalid.png" alt=""/>'}); }
			$(this).css({ border: "#FF0000 solid 1px", background: "#FFDEB3" });
		}
		
		var data_valtab	=	$(".verifobli").serialize().split("&"); 				// Récupère tous les champs, noms et valeurs. split .
		var data_valu = new FaitTableau(data_valtab.length);						// . sépare les données en tableau
		var y = 0;
		
		for (var i=0;i<(data_valtab.length);i++)									// y correspond au nombre de champs vide
		{																			// i correspond au nombre de champs
			data_valu[i]	=	data_valtab[i].substring(data_valtab[i].indexOf("=")+1,data_valtab[i].length); // Récupère la valeur des champs
			if((data_valu[i]=='')||(data_valu[i]=='http://')||(data_valu[i]=='http%3A%2F%2F')){ y++; }
		}
		$("textarea[name='ajcomm']").live("change", function(){ $("input[name='ajcommb']").attr({ disabled:false }); });
		
		if(y==0)
		{
			$("input[name=ajcritiqueb]").attr({ disabled:false });
			$("input[name=creamod]").attr({ disabled:false });
		}else{
			$("input[name=ajcritiqueb]").attr({ disabled:true });
			$("input[name=creamod]").attr({ disabled:true });
		}
	});*/
});
