/*
	STRING.JS - Fonctions de manipulations de Strings

	Fonctions fournies :
	
		int internalParseInt( string p_strChaine )
		string internalTrim( string p_strChaine )
		string internalReplace( string p_strChaine, string p_strFind, string p_strReplace )
		string internalSubstring( string p_strChaine, int p_iStart, int p_iEnd )
		string internalTrimLeft( string p_strChaine, char p_Caractere )

*/


String.prototype.trim = function() {
	var x=this.toString();
	x=x.replace(new RegExp("^\\s+",""),"");
	x=x.replace(new RegExp("\\s+$",""),"");
	return x;
}
String.prototype.ltrim = function() {
	var x=this.toString();
	x=x.replace(new RegExp("^\\s+",""),"");
	return x;
}
String.prototype.rtrim = function() {
	var x=this.toString();
	x=x.replace(new RegExp("\\s+$",""),"");
	return x;
}


function dateToString( p_oDate, p_bOptionalWithoutTime )
{
	alert( "Ne devrait plus etre utilisée !!!" );
	return;
	var sDate = "";
	var sDay, sMonth, sYear, sHour, sMin, sSecond;	
	
	sDay	= ( p_oDate.getDate() < 10 ? "0" + p_oDate.getDate() : p_oDate.getDate() )
	sMonth	= (p_oDate.getMonth() < 9 ? "0" + ( p_oDate.getMonth( ) + 1 ) : ( p_oDate.getMonth( ) + 1 ) );
	sYear	= p_oDate.getFullYear( );

	sDate = sDay + "/" + sMonth + "/" + sYear;
	
	if ( typeof p_bOptionalWithoutTime == undefined || !p_bOptionalWithoutTime )
	{
		sHour =		( p_oDate.getHours() < 10 ? "0" + p_oDate.getHours() : p_oDate.getHours() );
		sMin =		( p_oDate.getMinutes() < 10 ? "0" + p_oDate.getMinutes() : p_oDate.getMinutes() );
		sSecond = 	( p_oDate.getSeconds() < 10 ? "0" + p_oDate.getSeconds() : p_oDate.getSeconds() );
		sDate	= sDate + " " + sHour + ":" + sMin + ":" + sSecond;
	}
	return sDate;
}


// [ internalParseInt ] ------------------------------------------------------------

//	Entrées :	la chaine a parser
//	Sortie :	boolean indiquant si oui ou non la chaine contient un entier
// 	Description :	Fonction qui supprimer tout les espaces, tabs, ... avant et apres la chaine

function internalParseInt( p_strChaine )
{
	var returnInt = "";
	var i = 0;
	
	p_strChaine = p_strChaine + "";				// S'il s'agit d'un int, on le transforme implicitement en string
	p_strChaine = internalTrimLeft( p_strChaine, "0" );
	
	for ( i = 0 ; i < p_strChaine.length ; i++ )
	{
		if ( p_strChaine.charAt( i ) > '9' || p_strChaine.charAt( i ) < '0')
		{
			break;
		}
		else
		{
			returnInt += p_strChaine.charAt( i );
		}
	}
	
	if ( returnInt == "" )
	{
		return 0;
	}
	
	return parseInt( returnInt );

}

// [ internalTrim ] ------------------------------------------------------------

//	Entrées :	la chaine a "trimer"
//	Sortie :	la chaine "trimée"
// 	Description :	Fonction qui supprimer tout les espaces, tabs, ... avant et apres la chaine

function internalTrim( p_strChaine )
{
	return p_strChaine.replace( /(^\s*)|(\s*$)/g, "" );
}


// [ internalReplaceCase ] ------------------------------------------------------------

//	Entrées :	la chaine a traiter
//			la chaine a rechercher
//			la chaine de remplacement
//			si oui ou non on tient compte de la casse
//	Sortie :	la chaine remplacée
// 	Description :	Fonction qui remplace une chaine par une autre

function internalReplaceCase( p_strChaine, p_strFind, p_strReplace, p_bCaseSensitive )
{
	var iPos = -1;
	var returnChaine = p_strChaine;
	var decallageChaine = 0;
	if ( p_strReplace != "" ) decallageChaine = p_strReplace.length - 1; 
	
	if( !returnChaine ) return "";

	if ( p_bCaseSensitive )
	{
		p_strFind = p_strFind.toLowerCase( );
	}
	
	do {
		if ( p_bCaseSensitive )
		{
			iPos = returnChaine.toLowerCase( ).indexOf ( p_strFind, iPos + 1 )
		}
		else
		{
			iPos = returnChaine.indexOf ( p_strFind, iPos + 1 )
		}
		if ( iPos >= 0 )
		{
			returnChaine = returnChaine.substring ( 0, iPos ) + p_strReplace + returnChaine.substring ( iPos + p_strFind.length, returnChaine.length ) ;
			iPos += decallageChaine;
		}
		
	} while ( iPos >= 0 );

	return returnChaine;
}


// [ internalReplace ] ------------------------------------------------------------

//	Entrées :	la chaine a traiter
//			la chaine a rechercher
//			la chaine de remplacement
//	Sortie :	la chaine remplacée
// 	Description :	Fonction qui remplace une chaine par une autre, en ne tenant pas compte de la casse

function internalReplace( p_strChaine, p_strFind, p_strReplace )
{
	return internalReplaceCase( p_strChaine, p_strFind, p_strReplace, false );
}



// [ internalSubstring ] ------------------------------------------------------------

//	Entrées :	la chaine à couper
//			la position de debut
//			la position de fin
//	Sortie :	la chaine coupée
// 	Description :	Fonction qui renvoie un fragment d'une chaine

function internalSubstring( p_strChaine, p_iStart, p_iEnd )
{
	var returnChaine = "";
	var i = 0;

	for ( i = p_iStart ; i < p_iStart + p_iEnd && i < p_strChaine.length ; i++ )
	{
		returnChaine += p_strChaine.charAt(i);
	}

	return returnChaine;
}



// [ internalTrimLeft ] ------------------------------------------------------------

//	Entrées :	la chaine à traiter
//			le caractere à supprimer
//	Sortie :	la chaine "trimée"
// 	Description :	Fonction qui supprime n fois un caractere se trouvant en debut de chaine ( exemple : "00000903" -> "903" )

function internalTrimLeft( p_strChaine, p_Caractere )
{
	var strNewChaine = '';
	var i = 0;
	var bDisableTrim = false;
	
	for( i = 0 ; i < p_strChaine.length ; i++ )
	{
		if ( p_strChaine.charAt( i ) != p_Caractere || bDisableTrim  )
		{
			bDisableTrim = true;
			strNewChaine += p_strChaine.charAt( i );
		}
	}
	return strNewChaine;
}




