function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"").replace(/^　*|　*$/g,"");
}

function TrimInto(str)
{
	var prev_car='';
	var str_return='';
	for (var i=0;i<str.length;i++)
	{
		if ( ( prev_car != ' ' && prev_car != '　' ) || ( str.charAt(i) != ' ' && str.charAt(i) != '　' ) )
		{
			str_return += str.charAt(i);
		}
		prev_car=str.charAt(i);
	}
	return str_return;
}

function alphaNumericCheck(chaine,ChiffresOk,MinusculesOk,MajusculesOk,UnderscoreOk,PointAutorise)
{
	var ok=true;
	var i=0;
	if ( chaine == '' ) { ok=false; }
	for (i=0;i<chaine.length;i++)
	{
		if (alphaNumCheck(chaine.charCodeAt(i),ChiffresOk,MinusculesOk,MajusculesOk,UnderscoreOk,PointAutorise) == false )
		{
			ok=false;
		}
	}
	return ok;
}

function alphaNumCheck(theChar,ChiffresOk,MinusculesOk,MajusculesOk,UnderscoreOk,PointAutorise)
{
	if (
	    (((theChar > 47) && (theChar < 58 )) && ( ChiffresOk == 1 )) ||
	    (((theChar > 96) && (theChar < 123)) && ( MinusculesOk == 1 )) ||
	    (((theChar > 64) && (theChar < 91 )) && ( MajusculesOk == 1 )) ||
	    ( theChar == 95 && UnderscoreOk == 1) ||
	    ( theChar == 46 && PointAutorise == 1 )
	   )
	{return true;}else{return false;}
}

function encodeperso2(LeTexte)
{
	var istr=LeTexte;
	var istr2='';
	for (var i=0;i<istr.length;i++)
	{
		if ( i>0 ) { istr2+=','; }
		var thecode=istr.charCodeAt(i);
		// conversion des romanjis minuscules et majuscule de l'alphabet japonais en romanjis courants
		if ( thecode >= 65345 && thecode <= 65370 ) { thecode-=65248; }
		if ( thecode >= 65313 && thecode <= 65370 ) { thecode-=65216; }
		// espace jap
		if ( thecode == 12288 ) { thecode=32; }
		// autres caracteres
		if ( thecode == 12443 ) { thecode=34; }
		if ( thecode == 8217  ) { thecode=39; }
		if ( thecode == 65288 ) { thecode=40; }
		if ( thecode == 65289 ) { thecode=41; }
		if ( thecode == 65285 ) { thecode=37; }
		if ( thecode == 65284 ) { thecode=36; }
		if ( thecode == 65281 ) { thecode=33; }
		if ( thecode == 65306 ) { thecode=58; }
		if ( thecode == 65307 ) { thecode=59; }
		if ( thecode == 12290 ) { thecode=46; }
		if ( thecode == 12289 ) { thecode=44; }
		if ( thecode == 65311 ) { thecode=63; }
		//
		istr2+=thecode;
	}
	istr2=','+istr2+',';
	istr2=istr2.replace(/,13,/g, ',');
	istr2=StrRight(StrLeft(istr2,(istr2.length-1)),istr2.length-2);
	// ci dessus, code residu d'IE6 lors des retours chariots de textaray
	return istr2;
}

function decodeperso2(LeTexte)
{
	if (trim(LeTexte) != '')
	{
		eval('var toto = String.fromCharCode('+LeTexte+');');
	}
	else
	{
		var toto='';
	}
	//toto=toto.replace(/"/g, '&quot;');
	//toto=toto.replace(/"/g, '&acute;');
	//toto=toto.replace(/</g, '&lt;');
	//toto=toto.replace(/>/g, '&gt;');
	//toto=toto.replace(/&/g, '&amp;');
	return toto;
}

function StrLeft(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function StrRight(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
