//**********************************************************//
// Variabile globale per la verifica della modifica dei dati//
// nella pagina                                             // 
//**********************************************************//
var modificato=false;

//**********************************************************//
// Funzione da invocare per confermare l'uscita da una      //
// funzionalita'                                            // 
//**********************************************************//
function confirmEsci()
{
	if (modificato)
		return (confirm("ATTENZIONE !\n\nUscendo si perderanno le modifiche effettuate !\n\nPremere 'OK' per confermare."))
    else		
		return confirm("Sei sicuro di voler uscire?\n\nPremere 'OK' per confermare. ")
    
}

//**********************************************************//
// Funzione da invocare per confermare il cambio pagina all'interno di una funzionalita  //
//**********************************************************//
function confirmChange()
{
    if (modificato)
		return (confirm("ATTENZIONE !\n\nContinuando si perderanno le eventuali modifiche effettuate !\n\nPremere 'OK' per confermare."))
    else		
		return true;
}

//**********************************************************//
// Funzione da invocare per confermare di una delete di un dato      //
//**********************************************************//
function confirmDelete(aForm)
{
    if (confirm("Sei sicuro di voler eliminare il dato?\n\nPremere 'OK' per confermare. "))
    {
        aForm.submit();
    }
    return false;
}

function confirmDelete()
{
    return confirm("Sei sicuro di voler eliminare il dato?\n\nPremere 'OK' per confermare. ");
}

function confirmDeleteStampa()
{
    return confirm("Sei sicuro di volere rigenerare un nuovo documento PDF?\n\nPremere 'OK' per eliminare quello al momento presente. ");
}

//**********************************************************//
// Crea l'oggetto DATE e ritorna il Popup per la gestione   //
// delle date.                                              //
//**********************************************************//
function popupCalendar(object) {
    if (object.disabled==false)
    {
        var calendar = new calendar1(object);
        calendar.year_scroll = true;
        calendar.time_comp = false;
        calendar.PATH = '';

        return calendar.popup();
    }
    else
    {
        return false;
    }
}

//**********************************************************//
// Sostituisce i bottoni attivi alla modifica di un campo   //
//**********************************************************//
function setModificato() {
	if (modificato!=true)
	{
            if (document ['butt_annulla_mod']!=null)
            {
		document ['butt_annulla_mod'].src = "images/butt_annulla_mod.gif";
		document ['butt_accetta_mod'].src = "images/butt_accetta_mod.gif";
            }
            modificato=true;
	}

	return true;
}

//***************************************************************//
// Sostituisce i bottoni disattivati alla modifica di un campo   //
//***************************************************************//
function unSetModificato() {
	if (modificato!=false)
	{
            if (document ['butt_annulla_mod']!=null)
            {
		document ['butt_annulla_mod'].src = "images/butt_annulla_mod_off.gif";
		document ['butt_accetta_mod'].src = "images/butt_accetta_mod_off.gif";
            }
            modificato=false;
	}

	return false;
}

function getModificato() {
	return modificato;
}

//**********************************************************//
// Controlla la numericità del campo			            //
//**********************************************************//
function numeroDecimale(field) {
	
if (!isBlank(field))
{

	  s = field.value;
	  
	  RefString="1234567890";
	  var numChar = "";
	  for (var i=0; (i <= s.length);)
	  {
		numChar = s.charAt(i);	   	  
		if ((RefString.indexOf (numChar, 0)!=-1) 
	 		|| (s.charAt(i)==",")) {
				i++; 
			} else { 
				alert("Inserire un valore numerico."); 
				field.focus(); 
				return false;
			}
	  } 
	  return true;
}
}


//**********************************************************//
//															//
//		isInteger(field) - return true or false				//
//															//
//	Funzione che controlla che il valore del campo del form //
//	HTML <field> sia un valore numerico	intero				//
//															//
//**********************************************************//

function isInteger (field){
	var valid = "0123456789";
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = "no";
	}
	if (ok == "no") {
		//alert("Valore non valido! Per questo campo sono ammessi solo numeri interi!");
		field.focus();
		field.select();
		return false;
   	}
	else return true;
}

//**********************************************************//
// Gestione apertura del popup ed intercettazione della sua chiusura			            //
//**********************************************************//
var popupTimeout;
var popup=null;
var afterClosePopup;
var NN = navigator.appName == "Netscape"

function popupFocus()
{
    if(NN)
    {
        if (popup && !popup.closed)
        {
              popup.focus();
               self.blockEvents();
        }    
    }
}

function openPopup(url,target,params,afterCloseFunction)
{
    if ( (popup==null) || (popup.closed) )
    {
        popup = window.open(url,target,params);
        if (afterCloseFunction!=null) {
	        afterClosePopup=afterCloseFunction;
	        checkPopupClosed();
	    }
    }
    return false;		
}

function checkPopupClosed()
{
     if(popup.closed)
     {
       clearTimeout(popupTimeout);
       afterClosePopup();
     }
     else
     {
        popupTimeout = setTimeout("checkPopupClosed();",100);
     }
 }
//**********************************************************//




//**********************************************************//
//															//
//		isEmpty(field) - return true or false				//
//															//
//	Funzione che controlla se il campo di input <field> e'	//
//	vuoto													//
//															//
//**********************************************************//

function isEmpty (field)
{
	if (field.value.length == 0)
		return true;
  else
		return false;
}

//**********************************************************//
//															//
//		isBlank(field) - return true se solo spazi or false se non solo spazi				//
//															//
//	Funzione che controlla se il campo di input <field> e'	//
//	pieno solo di spazi													//
//															//
//**********************************************************//

function isBlank (field)
{
	var mflag=true;
	for (var i=0; i<field.value.length; i++) {
	if (field.value.charAt(i) != " ")
		mflag = false;
	}
	return mflag;
}

//**********************************************************//
//															//
//		isEmail(field) - return "OK", "VUOTO" or "ERRATO"	//
//															//
//	Funzione per il controllo della validita' della mail	//
//	dove <field> e' il campo del form HTML					//
//															//
//**********************************************************//

function isEmail (field) {
	var reEmail = /^.+\@.+\..+$/

	if (field.value == "") return false;
    else {
       if(reEmail.test(field.value)) return true;
       else return false;
    }
}


//**********************************************************//
//															//
//		UCase(field) - return void							//
//															//
//	Funzione che trasforma il campo del form HTML <field>   //
//	in maiuscolo											//
//															//
//**********************************************************//

function UCase(obj) {
	var valore = new String (obj.value);
	obj.value = valore.toUpperCase();
	return;
}

//**********************************************************//
//															//
//		isDigit(field) - return true or false				//
//															//
//	Funzione che controlla che il valore del campo del form //
//	HTML <field> sia un valore numerico						//
//															//
//**********************************************************//

function isDigit (field){
	var valid = "0123456789.";
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = "no";
	}
	if (ok == "no") {
		//alert("Valore non valido! Per questo campo sono ammessi solo numeri!");
		field.focus();
		field.select();
		return false;
   	}
	else return true;
}

//**********************************************************//
//															//
//	isCodiceFiscale(field)- return "OK","VUOTO" or "ERRATO"	//
//															//
//	Funzione che controlla che il valore del campo del form //
//	HTML <field> sia un codice fiscale valido				//
//															//
//**********************************************************//

function isCodiceFiscale(obj)
{
	var nTempNum;
	var nAppoNum;
	var i;
	var szTempCodFisc;
	var szLastChar;
	var szValued;
	var szInValued;

	szCodFisc = obj.value;

	if (szCodFisc.length<16) return false
	if (szCodFisc == "") return false;
	else {
		szCodFisc =szCodFisc.toUpperCase();
		szLastChar = szCodFisc.substr(szCodFisc.length - 1,1);
		szTempCodFisc =szCodFisc.substr(0,szCodFisc.length - 1);
		nTempNum = 0;
		i = 0;

		while (true) {
			szValued="B1A0KKPPLLC2QQD3RRE4VVOOSSF5TTG6UUH7MMI8NNJ9WWZZYYXX";
			// I DISPARI
			szInValued=szTempCodFisc.substr(i,1);
			nAppoNum = szValued.search(szInValued);
			nTempNum = nTempNum + (nAppoNum &  0x7FFE) / 2;
			i = i + 1;
			if (i>15)
				break;
			szValued="A0B1C2D3E4F5G6H7I8J9KKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ";
			// I PARI
			szInValued=szTempCodFisc.substr(i,1);
			nAppoNum = szValued.search(szInValued);
			nTempNum =  nTempNum + (nAppoNum &  0x7FFE) / 2;
			i = i + 1;
		}
		nTempNum = nTempNum % 26; //mod
		szValued="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		szValued= szValued.substr(nTempNum, 1);
		if (szValued==szLastChar) return true;
		else return false;
	}
}


		////**********************************************************////
		////**********************************************************////
	 /**////														  ////**\
/*******////	  FUNZIONI PER IL CONTROLLO VALIDITA' DELLE DATE	  ////*******\
	 /**////														  ////**\
		////**********************************************************////
		////**********************************************************////

//**********************************************************//
//															//
//		chkdate(strDate,type) - return true or false			//
//															//
//	Funzione che controlla che il valore del campo del form //
//	HTML <field> sia una data valida nel formato <type> che //
//	puo' essere o "EU" per lo stile italiano o				//
//				  "US" per quello americano					//
//															//
//	(Si serve anche della funzione LeapYear definita dopo)	//
//															//
//**********************************************************//

function chkdate(strDate, type) {
	//var strDatestyle = "US";  //United States date style
	//var strDatestyle = "EU";  //European date style
	var strDatestyle = type;
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
//	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".",":");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "01";
	strMonthArray[1] = "02";
	strMonthArray[2] = "03";
	strMonthArray[3] = "04";
	strMonthArray[4] = "05";
	strMonthArray[5] = "06";
	strMonthArray[6] = "07";
	strMonthArray[7] = "08";
	strMonthArray[8] = "09";
	strMonthArray[9] = "10";
	strMonthArray[10] = "11";
	strMonthArray[11] = "12";
//	strDate = datefield.value;
	if (strDate.length < 1) {
		return true;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) {
				err = 1;
				return false;
			}
			else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
	        }
	}
	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}
	if (strYear.length == 2) {
		if (strYear < 95)
			strYear = '20' + strYear;
		else
			strYear = '19' + strYear;
	}
	if (strYear.length == 3) {
		return false;
	}
	// US style

	if (strDatestyle == "US") {
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) {
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth)) {
			err = 3;
			return false;
		}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) {
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) {
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
		err = 7;
		return false;
	}
	if (intMonth == 2) {
		if (intday < 1) {
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true) {
			if (intday > 29) {
				err = 9;
				return false;
			}
		}
		else {
			if (intday > 28) {
				err = 10;
				return false;
			}
		}
	}
/*	if (strDatestyle == "US") {
		datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
	}
	else {
		if (intday < 10)
			datefield.value = "0" + intday + "/" + strMonthArray[intMonth-1] + "/" + strYear;
		else
			datefield.value = intday + "/" + strMonthArray[intMonth-1] + "/" + strYear;
	}
*/
	return true;
	}

function normalizeDate(strDate, type) {
	//var strDatestyle = "US";  //United States date style
	//var strDatestyle = "EU";  //European date style
	var strDatestyle = type;
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var strSeparatorArray = new Array("-"," ","/",".",":");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "01";
	strMonthArray[1] = "02";
	strMonthArray[2] = "03";
	strMonthArray[3] = "04";
	strMonthArray[4] = "05";
	strMonthArray[5] = "06";
	strMonthArray[6] = "07";
	strMonthArray[7] = "08";
	strMonthArray[8] = "09";
	strMonthArray[9] = "10";
	strMonthArray[10] = "11";
	strMonthArray[11] = "12";

	if (strDate.length < 6) 
	{
		return "";
	}

	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 
		{
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) 
			{
				err = 1;
				return false;
			}
			else 
			{
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			
			booFound = true;
	  }
	}
	
	if (booFound == false) {
		return "";
	}
	
	// Checks YEAR
	if (strYear.length == 2) {
		if (strYear < 20)
			strYear = '20' + strYear;
		else
			strYear = '19' + strYear;
	}
	if (strYear.length == 3) {
		return "";
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear) || intYear<1900) {
		return "";
	}
	
	// Checks Month
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth) || intMonth<1 || intMonth>12 ) 
	{
		return "";
	}
	strMonth = strMonthArray[intMonth-1];

	// Checks DAY
	intDay = parseInt(strDay, 10);
	if (isNaN(intDay) || intDay<1 || intDay>31 ) {
		return "";
	}
	if (intDay<10 && strDay.length<2)
		strDay="0"+strDay;

	var strDate=strDay+"/"+strMonth+"/"+strYear;
	return strDate;
}

function getYear(strDate) {
	var strDatestyle = "EU";
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var strSeparatorArray = new Array("-"," ","/",".",":");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "01";
	strMonthArray[1] = "02";
	strMonthArray[2] = "03";
	strMonthArray[3] = "04";
	strMonthArray[4] = "05";
	strMonthArray[5] = "06";
	strMonthArray[6] = "07";
	strMonthArray[7] = "08";
	strMonthArray[8] = "09";
	strMonthArray[9] = "10";
	strMonthArray[10] = "11";
	strMonthArray[11] = "12";

	if (strDate.length < 6) 
	{
		return "";
	}

	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 
		{
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) 
			{
				err = 1;
				return false;
			}
			else 
			{
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			
			booFound = true;
	  }
	}
	
	if (booFound == false) {
		return "";
	}
	
	// Checks YEAR
	if (strYear.length == 2) {
		if (strYear < 20)
			strYear = '20' + strYear;
		else
			strYear = '19' + strYear;
	}
	if (strYear.length == 3) {
		return "";
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear) || intYear<1900) {
		return "";
	}
	
	// Checks Month
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth) || intMonth<1 || intMonth>12 ) 
	{
		return "";
	}
	strMonth = strMonthArray[intMonth-1];

	// Checks DAY
	intDay = parseInt(strDay, 10);
	if (isNaN(intDay) || intDay<1 || intDay>31 ) {
		return "";
	}
	if (intDay<10 && strDay.length<2)
		strDay="0"+strDay;

	var strDate=strYear;
	return strDate;
}


	
//**********************************************************//
//															//
//		LeapYear(year) - return true or false				//
//															//
//	Funzione che verifica se l'anno <year> (int) e'			//
//	bisestile												//
//															//
//**********************************************************//

function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) {
			return true;
		}
	}
	else {
		if ((intYear % 4) == 0) {
			return true;
		}
	}
	return false;
}

//**********************************************************//
//															//
//		doDateCheck(from, to) - return true or false		//
//															//
//	Funzione che verifica che l'intervallo fra una data		//
//	inizio <from> e una data fine <to> sia esatto			//
//															//
//**********************************************************//

function doDateCheck(from_gg,from_mm,from_aaaa,
					 to_gg,to_mm,to_aaaa) {
    if (from_mm < 10 && from_mm.length<2)
        from_mm = "0" + from_mm;
    if (from_gg < 10 && from_gg.length<2)
        from_gg = "0" + from_gg;
    if (to_mm < 10  && to_mm.length<2)
        to_mm = "0" + to_mm;
    if (to_gg < 10 && to_gg.length<2)
        to_gg = "0" + to_gg;
	var datafrom = new Number(from_aaaa+from_mm+from_gg);
	var datato = new Number(to_aaaa+to_mm+to_gg);

	if (datafrom < datato)
		return true;
	else
		return false;
}

function getDateValue(aStrDate)
{
	var strDateArray;
	strDateArray = aStrDate.split("/");
	
	if (strDateArray.length != 3) {
		return 0;
	}
	else {
		if (parseInt(strDateArray[2], 10)<100) 
			strDateArray[2]="20"+parseInt(strDateArray[2], 10);
		if (parseInt(strDateArray[1], 10)<10) 
			strDateArray[1]="0"+parseInt(strDateArray[1], 10);
		if (parseInt(strDateArray[0], 10)<10) 
			strDateArray[0]="0"+parseInt(strDateArray[0], 10);
		return (new Number(strDateArray[2]+strDateArray[1]+strDateArray[0]) );
	}
}

function getToday()
{
    return normalizeDate((new Date()).getDate()+'/'+((new Date()).getMonth()+1)+'/'+(new Date()).getYear(),'EU');
}

function unFormatCurrency(field,valuta)
{
 var decimalPart;
 var integerPart;
 var i;
 
 decimalPart = "";
 
 i = field.value.indexOf(",");
 if ( valuta == "E" && i == -1)
 {
  i = 0;
  for(i=field.value.length; i >= 0 && field.value.charAt(i) != "."; i--);
 } 
 decimalPart = (i>0 ? "." + field.value.substring(i+1): "");
 i = (i == -1 ? field.value.length : i);
 integerPart = replaceDots(field.value.substring(0,i));
 field.value = integerPart + decimalPart;
 return false; 
}

function formatCurrency(field,valuta)
{
 var sep;
 unFormatCurrency(field,valuta);
 sep =(valuta=="E" ? true : false);
 formatStringToNumber(field, sep);
}

function replaceDots(aString)
{
    s = "";
    for (i = 0; i < aString.length; i++)
    {
        if (aString.charAt(i) != '.')
            s = s + aString.charAt(i);
    }
	return s;
}


//**********************************************************//
//															//
//  formatStringToNumber(field) - return true or false		//
//															//
//	Convert a text field value to a formatted number  		//
//	field a valid text object                    			//
//	Modificata da Favata il 29/08/02														//
//**********************************************************//

function formatStringToNumber(field, acceptDecimalSep)
{
    str2format = field.value;
    str2format = str2format.replace(/\./, ",");
    // remove leading zeroes
    zeroIdx = 0;
    for (; zeroIdx < str2format.length && str2format.charAt(zeroIdx) == "0"; ++zeroIdx)
        ;
    if (zeroIdx > 0)
        str2format = str2format.substring(zeroIdx);
    if (str2format == "")
    {
        field.value = "0";
        return false;
    }

    sepPos = str2format.indexOf(",");
    foundSep = sepPos != -1;
    decimalPart = "";
    if (foundSep)
    {
        decimalPart = str2format.substring(sepPos + 1);
        decimalPart = "," + decimalPart;
        /*if (decimalPart.length = 2)
            decimalPart = decimalPart + "0";*/
        --sepPos;
    }
    else
    {
        sepPos = str2format.length - 1;
        if (acceptDecimalSep)
            decimalPart = ",00";
    }

    pos = 0;
    s = "";
    for (i = sepPos; i >= 0; i--)
    {
        if (pos++ == 3)
        {
            s = "." + s;
            pos = 1;
        }
        s = str2format.charAt(i) + s;
    }

    if (s.charAt(0) == ".")
        s = s.substring(1);
    if (s == "")
        s = "0";
    field.value = s+decimalPart.substring(0,3);
    return false;
}

// --------------------------------------------------------------------------
// Gestione dei campi number
// --------------------------------------------------------------------------

function FormatNumber(num,dec) { 
    if (!isNaN(num) && num.length>0)
    {
        dec= (dec)?dec:0; 
        ee = Math.pow(10,dec); 
        nn = Math.round(num*ee); 
        //alert("nn="+nn);
        vv = String(nn/ee); 
        vv += (vv.indexOf(".")>=0)?"":"."; 
        while (vv.indexOf(".")>vv.length-dec-1) { vv += "0" } 
        if (dec==0)
            vv=vv.substring(0, vv.length-1);
        return vv; 
    }
    else
        return "";
} 

function onKeyPressNumber() {
  if (event.keyCode >= 48 && event.keyCode <= 57){event.returnValue = true;}// numerico
  //else if (event.keyCode == 44){event.returnValue = true;}// virgola
  else if (event.keyCode == 46){event.returnValue = true;}// punto
  else if (event.keyCode == 45){event.returnValue = true;}// segno 'meno'
  else {event.returnValue = false;}// alfanumerico
 }

// --------------------------------------------------------------------------
// Controlla che un determinato campo non contenga caratteri speciali
// --------------------------------------------------------------------------
function isValidString(str) {
 var valore=Trim(str.value);
 var negati='_-+*/\\#?=;,.:!|$€£<>^%&([])§"';
 for (i=0; i<valore.length; i++)
  for (j=0; j<negati.length; j++)
   if (valore.charAt(i)==negati.charAt(j)) {
       alert('Impossibile inserire questi caratteri: _-+*/\\#?=;,.:!|$€£<>^%&([])§"');
       return false;
   }
 return true;
}

// --------------------------------------------------------------------------
// Rimuove gli spazi iniziali dalla nostra stringa
// --------------------------------------------------------------------------
function LTrim(str)
{
  var whitespace = new String(" \t\n\r");

  var s = new String(str);

  if (whitespace.indexOf(s.charAt(0)) != -1) {
    // We have a string with leading blank(s)...

    var j=0, i = s.length;

    // Iterate from the far left of string until we
    // don't have any more whitespace...
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
    j++;


    // Get the substring from the first non-whitespace
    // character to the end of the string...
    s = s.substring(j, i);
  }

  return s;
}

// --------------------------------------------------------------------------
// Rimuove gli spazi finali dalla nostra stringa
// --------------------------------------------------------------------------
function RTrim(str)
{
  var whitespace = new String(" \t\n\r");

  var s = new String(str);

  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
    // We have a string with trailing blank(s)...

    var i = s.length - 1;       // Get length of string

    // Iterate from the far right of string until we
    // don't have any more whitespace...
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
      i--;

    // Get the substring from the front of the string to
    // where the last non-whitespace character is...
    s = s.substring(0, i+1);
  }

  return s;
}

// --------------------------------------------------------------------------
// Rimuove gli spazi iniziali e finali dalla nostra stringa
// --------------------------------------------------------------------------
function Trim(str)
{
  return RTrim(LTrim(str));
}

function rpad(num, max_length,pad)
{
   var strNum=new String(num);
   while (strNum.length<max_length)
        strNum=pad+strNum;

   return strNum;
}

// --------------------------------------------------------------------------
// Apre la form di inoltro email dal web
// --------------------------------------------------------------------------
function sendToAFriendForm(url,newsTitle) {
		var testo=escape("Ti consiglio di visionare questa URL:\n"+window.location.href+"\n\n");
		var oggetto=escape("Segnalazione notizia: "+newsTitle);
		prop = "menubar=no,status=no,titlebar=no,toolbar=no,width=600,height=450,scrollbars=yes"
		window.open(url+"?sEmailText="+testo+"&sEmailSubject="+oggetto, "InviaPagina", prop);
}

// --------------------------------------------------------------------------
// Apre la notizia in versione stampabile
// --------------------------------------------------------------------------
function openPrintable(url) {
		prop = "menubar=yes,status=no,titlebar=no,toolbar=no,width=600,height=450,scrollbars=yes"
		window.open(url, "Notizia", prop);
}
// EOF


