﻿//  Globale qui indique si on affiche un message pour les champs les uns aprÃ¨s les autres, ou tous les champs d'un coup !var FORM_GLOBAL_SHOWALLMESSAGE_IN_ONE = true;/*	Permet de Lier / Executer les Handlers créé dynamiquements par le moteur*/function FORM_FillSelectFromDataSource( Url, oSelect, DataSource, FieldLabel, Params, fnc_OnAppended ){	$.ajax({		type: "GET",		url: Url+"?datasource="+DataSource+"&"+Params,		select_dest: oSelect,		field_label: FieldLabel,		dataType: "xml",		error:	function(xhr,err,e){ Error_Report( "Erreur lors de la recuperation des valeurs du &lt;select&gt;", xhr.responseText ); }, 		success: function(xml) {			var oSelect = $(this).attr("select_dest");			var sFieldLabelName = $(this).attr("field_label");			$(this).attr("select_dest").find("option[value!='']").remove();			/* On ajoute les nouvelles options */			$(xml).find('datasource').find('row').each(function(i,obj){				var id = $(this).find('ID').text();				var label = $(this).find( sFieldLabelName ).text();				oSelect.append( "<option value=\""+id+"\">"+label+"</option>" )			});						if ( typeof fnc_OnAppended != "undefined" ) fnc_OnAppended.call(oSelect);		}	});	}function FORM_ResetSelect( oSelect ){	oSelect.find("option[value!='']").remove();}function FORM_DoTestFieldEmpy( field ){	if ( $(field).getValue( ) == "" ) 	{		if ( !FORM_GLOBAL_SHOWALLMESSAGE_IN_ONE )		{			alert( "Veuillez saisir " + FORM_GetCleanName( field.attr("Description") ) );			field.focus( );			return false;		}		else		{			return "\t- " + FORM_GetCleanName( field.attr("Description"), false ) + "\n";		}	}	if ( !FORM_GLOBAL_SHOWALLMESSAGE_IN_ONE )		return true;	else											return "";}function FORM_DoTestFieldValue( field, hFnTest ){	if ( $(field).getValue( ) != "" ) 	{		if ( typeof hFnTest != "undefined" && hFnTest != null )		{			if ( ! hFnTest.call( field, field.getValue() ) )			{				// Sinon process classique				var sExample = field.attr("Example");				if ( sExample != "" ) sExample = " (ex: "+sExample+")";								if ( !FORM_GLOBAL_SHOWALLMESSAGE_IN_ONE )				{					alert( "Veuillez saisir " + FORM_GetCleanName( field.attr("Description") ) + " valide. "+sExample );					field.focus( );					return false;				}				else				{					return "\t- " + FORM_GetCleanName( field.attr("Description"), false ) + ": valeur incorrecte! "+sExample+"\n";				}			}		}		else		{			alert( "DoTestFieldValue: La fonction " + hFnTest + " n'existe pas pour tester le champ " + field.name );		}	}	if ( !FORM_GLOBAL_SHOWALLMESSAGE_IN_ONE )		return true;	else											return "";}/*	Format un champ description (.NET : Collecion.Item.Name = f:Femme, m:Homme, f pour feminin, m pour masculin )	Si pas de ":" ---> renvoie la description	s : Description*/function FORM_GetCleanName(s, disableForcePronom){	if ( typeof disableForcePronom == "undefined" ) disableForcePronom = true;		var r = "";	var aDatas = s.split(":");	if ( aDatas.length == 1 ) return s;	switch(aDatas[0].toLowerCase())	{		case "m":	r = "un ";					break;		case "f":	r = "une ";					break;	}	if ( disableForcePronom )	return r+aDatas[1];	return aDatas[1];}function FORM_PostTo( url, p_oForm, callbackOk, callbackError ){	var sQuery = "";		//var funcValidForm = eval( "OnPost_" + p_oForm.name );	//if ( typeof funcValidForm != "undefined" && !funcValidForm.call(this) ) return;	sQuery = FORM_GetQuery( p_oForm );	$.ajax({		type: "POST",		url: url + "?form="+p_oForm.name,		data: sQuery,		dataType: "xml",		error:	callbackError, 		success: callbackOk	});	}/*	Fonction qui permet de récuper l'ensemble des variables d'un formulaire (FORM.elements mais aussi les nos "InputList" !!! )*/function FORM_GetQuery( p_oForm ){	var sQuery = "";	// Les élements 'classic' du formulaire	$( p_oForm ).map(function(){ return $.makeArray(this.elements); }).each(function(i,obj){		if ( (typeof this.id != "undefined" && this.id != "" && this.id.indexOf( "VIEWSTATE" ) < 0 ) || $(this).attr( "name" ) != "" )		{			var name = $(this).attr( "name" );			if( name == "" && typeof this.id != "undefined" && this.id != "" )	name = this.id;						var val = ""+this.value;			if( $(this).attr( 'type' ) == "radio" )			{				if( $(this).attr( "checked" )+"" == "true" )				{					sQuery += "&" + name +"=" + FORM_encodeUTF8ForQuery( val ); // + "\n";				}			}			else			{				sQuery += "&" + name +"=" + FORM_encodeUTF8ForQuery( val ); // + "\n";			}		}	});		// Les élements de type inputlist( liste avancées de choix)	var aInputList = $( p_oForm ).data('inputlist_array');	if ( typeof aInputList !="undefined" && aInputList != null )	{		for ( var i = 0 ; i < aInputList.length ; i++ )		{			var val = ""+$(aInputList[i]).getValue();			sQuery += "&" + $(aInputList[i]).attr('id') +"=" + FORM_encodeUTF8ForQuery( val ); 		}	}	return sQuery;}function FORM_encodeUTF8ForQuery(str) {	return str.replace(/&/g,"%26").replace(/\n/g,"%0A").replace(/\r/g,"%0D");/*	    var bytes= '';    for (var i= 0; i<str.length; i++)        bytes+= str.charCodeAt(i)<256? str.charAt(i) : '?';    return escape(bytes).split('+').join('%2B');*/}/***********************************************************************************************************************************************************************************************	TEST DE FORMULAIRE TYPES***********************************************************************************************************************************************************************************************/function FORM_ValidEmail( value ){	var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	var email = $(this).val();	if ( regex.test(email) ) return true;	else return false;}function verifMail(mailteste){	var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	if(regex.test(mailteste))	return(true);	return(false);}function FormatMilliers( p_iPrice ){	var sReturnPrice = "";		p_iPrice = p_iPrice+"";	p_iPrice = internalReplace( p_iPrice, ".", "," );			p_iPrice = p_iPrice.split( "," )[ 0 ];	for ( var i = 0 ; i < p_iPrice.length ; i++ )	{		if ( i == 3 || i == 6 || i == 9 || i == 12 )			sReturnPrice = p_iPrice.charAt( p_iPrice.length-i-1 )+"&#160;" + sReturnPrice;		else 			sReturnPrice = p_iPrice.charAt( p_iPrice.length-i-1 ) + sReturnPrice;	}	return sReturnPrice;}
