
var strings_js = 1;


/***********************************************************************************
 *
 * metodi della classe 'String' per effettuare il trimming
 * 
 * esempio:
 * 	var trimmedString = str.trim();
 * 
 ***********************************************************************************/

String.prototype.ltrim = new Function("return this.replace(/^\\s+/,'')");
String.prototype.rtrim = new Function("return this.replace(/\\s+$/,'')");
String.prototype.trim  = new Function("return this.replace(/^\\s+|\\s+$/g,'')");



/***********************************************************************************
*
* funzioni per il trimming
*
* esempio:
* 	var trimmedString = trim(str);
*
***********************************************************************************/

function ltrim(inpStr) 
{
	if (inpStr)
	{
		var re=/^\s+/g;
		return inpStr.replace(re,"");
	}
	else
	{
		return inpStr;
	}
}

function rtrim(inpStr) 
{
	if (inpStr)
	{
		var re=/\s+$/g;
		return inpStr.replace(re,"");
	}
	else
	{
		return inpStr;
	}
}

function trim(inpStr) 
{
	if (inpStr)
	{
		var re=/\s+$|^\s+/g;
		return inpStr.replace(re,"");
	}
	else
	{
		return inpStr;
	}
}

/*
function isString(str)
{
	return (typeof(str) == "string");
}
*/

/********************************************
 *
 * usare questa funzione per decodificare stringhe codificate con la funzione PHP urlencode()
 * (ad esempio per operazione Ajax in cui si elaborano le stringhe rese da un file php.)
 *
 * This function decodes the any string
 * that's been encoded using URL encoding technique
 * http://www.kamath.com/codelibrary/cl006_url.asp
 *
 *********************************************/
function URLDecode(psEncodeString)
{
  // Create a regular expression to search all +s in the string
  var lsRegExp = /\+/g;
  // Return the decoded string
  return unescape(String(psEncodeString).replace(lsRegExp, " "));
}



/***************************************************
 *
 * sosituisce al carattere newline la stringa '<br>'
 *
 ***************************************************/
function nl2br(str)
{
	if (str)
	{
		var re=/\n/g;
		return str.replace(re,"<br>");
	}
	return str;	
}




/***************************************************
 *
 * sosituisce alla stringa '<br>' il carattere newline 
 *
 ***************************************************/
function br2nl(str)
{
	if (str)
	{
		//var re=/<br>/g;
		var re=/<br\s*\/?>/g;
		return str.replace(re,"\n");
	}
	return str;	
}

/*********************************************************
 *  sostituisce la stringa '&nbsp;' con uno spazio
 *********************************************************/
function nbsp2wtsp(str)
{
	if (str)
	{
		var re=/&nbsp;/g;
		return str.replace(re," ");
	}
	return str;	
}

/*********************************************************
 * sostituisce ogni withespace con la stringa '&nbsp;'
 *********************************************************/
function wtsp2nbsp(str)
{
	if (str)
	{
		var re=/[ \t]/g;
		return str.replace(re,"&nbsp;");
	}
	return str;	
}


/*********************************************************
 *
 * html2txt sosituisce alcuni tag HTML tipici di un testo
 * ne relativi caratteri ascii: es. <br> => \n  &nbsp; => spazio
 *
 *********************************************************/
function html2txt(str)
{
	if (str)
	{		
		str = br2nl(nbsp2wtsp(str));
		// leva i tag ininfluenti
		var re=/<\/*b>/g;
		return str.replace(re,"");
	}
	return str;
}
