function submitform(formId) {
	$('#' + formId).submit();
}
function validform(formId,aImputName,aImputLibelle,aImputControle,sDivToShow,sContent,iValMin)
{  
	// DDS 
	// formId 			= Id du formulaire
	// aImputName 		= nom du champ a valider (array)
	// aImputLibelle 	= libelle du champ pour le message d'erreur (array)
	// aImputControle	= type du champ 1=Numérique; 2=Bouton radio; 3=Texte; 4=Email; 5=Numérique avec valeur Min. obligatoire TODO : etc... (array)
	// iValMin			= Valeur minimum obligatoire si type de champ = 5
	
	errors          = 0;
	errorMsg		= "";
	aImput			= new Array();
	
	if (iValMin==undefined){
		var iValMin = 0;
	}
	
	for (var i=0;i<aImputName.length;i++)
 	{
 		aImput[i] = new Array();
 		aImput[i]["name"]		= aImputName[i];
 		aImput[i]["error"]		= aImputName[i]+"_error";
 		aImput[i]["value"]		= $("#"+aImputName[i]).val();
 		aImput[i]["libelle"]	= aImputLibelle[i];
 		aImput[i]["controle"]	= aImputControle[i]
 		$("#"+aImput[i]["error"]).empty().hide();
	 	$("#"+aImput[i]["name"]).removeClass("highlight");
	    if ((aImput[i]["value"] == null && aImput[i]["controle"] != 5)||(aImput[i]["value"] == '' && aImput[i]["controle"] != 5)) 
	    {	
	    	errorMsg = locale.sValidFormMsg1; 
	        $("#"+aImput[i]["name"]).addClass("highlight");
	        
	        if (aImput[i]["name"] == 'NOM' || aImput[i]["name"] == 'PRENOM') {	
	        $("#"+aImput[i]["error"]).show() 
			.append(aImput[i]["libelle"]+".");
	        } else {
		        $("#"+aImput[i]["error"]).show() 
				.append(aImput[i]["libelle"]+" "+locale.sObligatoire+"."); 
	        }	       
	        errors++; 
	    } else if (aImput[i]["controle"] == 1 && !isNumeric(aImput[i]["value"])) 
    	{ 
    		errorMsg = locale.sValidFormMsg2;
	        $("#"+aImput[i]["name"]).addClass("highlight");
	        $("#"+aImput[i]["error"]).show() 
			.append(aImput[i]["libelle"]+" "+locale.sNumerique); 
	        errors++; 
	    } else if (aImput[i]["controle"] == 4 && !isMail(aImput[i]["value"])) 
    	{ 
    		errorMsg = locale.sValidFormMsg3;
	        $("#"+aImput[i]["name"]).addClass("highlight");
	        $("#"+aImput[i]["error"]).show() 
			.append(aImput[i]["libelle"]+" "+locale.sEmail); 
	        errors++; 
	    } else if (aImput[i]["controle"] == 5 && (!isNumeric(aImput[i]["value"]) || aImput[i]["value"] < iValMin)) 
    	{ 
    		errorMsg = locale.sValidFormMsg2;
	        $("#"+aImput[i]["name"]).addClass("highlight");
	        $("#"+aImput[i]["error"]).show() 
			.append(aImput[i]["libelle"]+" "+iValMin+" "+locale.sObligatoire+"."); 
	        errors++; 
	    }
 	} 
 		
    if (errors > 0) 
    { 
        return false; 
    } else 
    {
    	if (sDivToShow != undefined){
    		if (sContent != undefined){
    			var dc = $(sContent);
				$("body").append(dc);
    		}
    		$("#"+sDivToShow).dialog({ 
    			modal: true,
    			title : "Message : ",
    			overlay: { 
    				opacity: 0.5, 
    				background: "black" 
    			} 
    		});
    	}
    	$('#'+formId).submit();
    }
	
}	
function isNumeric(form_value) 
{ 
    if (form_value.match(/^\d+$/) == null) 
        return false; 
    else 
        return true; 
} 	
function isMail(form_value) 
{ 
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(form_value)) 
        return true; 
    else 
        return false; 
} 
function loadRub(iIdRub, iLangue, iLevel, iSelectedRub, sDefault) {
	giLevel = iLevel;

	url = config.path + 'model/navigation/rubriqueDecorator.cfc?wsdl';

	$.getJSON(url, {
				iRub : iIdRub,
				selectedRub : iSelectedRub,
				level : iLevel,
				isPageAccueil : config.isHome,
				Langue : iLangue,
				method : 'getSelect',
				returnformat : 'json',
				queryformat : 'column'

			}, outputRubContent);
}
function outputRubContent(qGetSelect) {
	if (qGetSelect.ROWCOUNT == 0) {
		resetChildsRub(giLevel);
		$('#div-post-form').show(300);

	} else {
		var sRetour = "";
		var sOptions = "";
		var sSelected = "";

		for (var i = 0; i < qGetSelect.ROWCOUNT; i++) {

			iId = qGetSelect.DATA.id[i];
			sLibelle = qGetSelect.DATA.libelle[i];
			iSelected = qGetSelect.DATA.selected[i];
			sTypeOf = qGetSelect.DATA.typeOf[i];
			sEntete = qGetSelect.DATA.entete[i];
			iLevel = qGetSelect.DATA.level[i];
			iLangue = qGetSelect.DATA.langue[i];

			sSelected = (iSelected == 1) ? "Selected" : "";

			sOptions += "<option value='" + iId + "' " + sSelected + ">"
					+ " " + sLibelle + "</option>";

		}
		sRetour = sEntete + "<br/><select id='sel-Rub-Level-" + iLevel + "' ";
		if (qGetSelect.DATA.typeOf[0] == 'rub') {
			sRetour += "onChange='javascript:loadNextRub(" + iLevel + "," + iLangue + ");' ";
		}
		sRetour += ">";
		sRetour += "<option value='-1'>-- " + locale.sChoisir + " --</option>";
		sRetour += sOptions + "</select>";
		$('#div-Rub-Level-' + iLevel).html(sRetour);
		$('#div-Rub-Level-' + iLevel).show(300);
	}
}
function loadNextRub(iLevel,iLangue) {
	var selRub = $('#sel-Rub-Level-' + iLevel)[0].value;
	var nextLevel = iLevel + 1
	$('#div-Rub-Level-' + nextLevel)
			.html("<br><select class='cascade-loading'><option value='-1'>-- " + locale.sChargement + "--</option></select>");
	if (selRub > 0) {
		$('#rid')[0].value = selRub;
		loadRub(selRub, iLangue, nextLevel, -1);
		resetChildsRub(nextLevel + 1);
	} else {
		resetChildsRub(nextLevel);
		resetChildsRub(nextLevel + 1);
	}
}
function resetChildsRub(iLevel) {
	for (i = iLevel; i < 7; i++) {
		if (iLevel == 2) {
			$('#div-Rub-Level-' + 2)
					.html("<br/><select id='sel-Rub-Level-2'><option value='-1'>-- " + locale.sChoisir + " --</option></select>");
		} else {
			$('#div-Rub-Level-' + i).hide(300);
			$('#div-Rub-Level-' + i).html("");
		}
		$('#div-post-form').hide(300);
	}
}