function Trim(orgString){
  return LTrim(RTrim(orgString))
}

function LTrim(orgString){
  return orgString.replace(/^\s+/,'')
}

function RTrim(orgString){
  return orgString.replace(/\s+$/,'')
}

// *************** Inizio Controllo Data **************************//

function IsDataOK(dddata) { 
      
var errore = true; 
var desc_err = "";           
gg=dddata.substring(0,2) 
mm=dddata.substring(3,5) 
aa=dddata.substring(6,10) 
d1=dddata.substring(2,3) 
d2=dddata.substring(5,6) 
         
	if (dddata.length!=10) {
	      desc_err = desc_err + "il formato data deve essere (gg/mm/aaaa)\n" 
	}else if ((dddata.indexOf("/")==-1) || (d1 != "/") || (d2 != "/") || (isNaN(gg)) || (isNaN(mm))|| (isNaN(aa))){ 
          desc_err = desc_err + "Formato non corretto\n" 
    }else if ( gg > 31 || gg < 1 || mm > 12 || mm < 1 || aa < 1900 || aa > 2100){ 
		  desc_err = desc_err + "Giorno, Mese o Anno non Corretto\n" 
    }else if (((gg > 30) && (mm == 04 || mm == 06 || mm == 09 || mm == 11)) || ((gg > 29 ) && (mm == 02))){ 
          desc_err = desc_err + "Giorno non permesso per il mese\n" 
    }else if ((mm == 02) && (gg == 29)){        
        if ((mm == 02) && (gg == 29) && isBisestile(aa)){ 
		  errore = false 
        }else{ 
		  desc_err = desc_err + aa + ": Anno non bisestile\n" 
        }
    }else{errore = false}
    x=true;
    if (errore){
		alert(desc_err);
		x=false;
    }  
    return(x);                 
}

//Verifica se anno bisestile      
function isBisestile(anno){ 
var residuo1 = 0; 
var residuo2 = 0; 
var residuo3 = 0; 

residuo1 = anno%4; 
residuo2 = anno%100; 
residuo3 = anno%400; 
                                 
if (residuo1 == 0 && (residuo2 != 0 || residuo3 == 0)) 
           return true; 
     else 
           return false; 
} 
function select(mioOg, changeToColor){
  mioOg.style.backgroundColor = changeToColor;
}
function CaricaWin(parametro,largh,altez){
   MiaWin=window.open(parametro,"Titolo","scrollbars=1,left=5,top=10,height="+altez+",width="+ largh);
   MiaWin.focus()
 }

function FormatoData(DataIta){
var StrData1=DataIta

	g1=StrData1.substring(0,2);
	m1=StrData1.substring(3,5);
	a1=StrData1.substring(6);
	var Data1=new Date(m1+"/"+g1+"/"+a1+ " 00:00:00");
	return (Data1);
}
function datediff(per,d1,d2) {	
   var d = (d2.getTime()-d1.getTime())/1000
   switch(per) {
      case "yyyy": d/=12
      case "m": d*=12*7/365.25
      case "ww": d/=7
      case "d": d/=24
      case "h": d/=60
      case "n": d/=60
   }  
   return Math.round(d);
}
function dateAdd( start, interval, number ) {
	
    // Create 3 error messages, 1 for each argument. 
    var startMsg = "Sorry the start parameter of the dateAdd function\n"
        startMsg += "must be a valid date format.\n\n"
        startMsg += "Please try again." ;
		
    var intervalMsg = "Sorry the dateAdd function only accepts\n"
        intervalMsg += "d, h, m OR s intervals.\n\n"
        intervalMsg += "Please try again." ;

    var numberMsg = "Sorry the number parameter of the dateAdd function\n"
        numberMsg += "must be numeric.\n\n"
        numberMsg += "Please try again." ;
		
    // get the milliseconds for this Date object. 
    var buffer = Date.parse( start ) ;
	
    // check that the start parameter is a valid Date. 
    if ( isNaN (buffer) ) {
        alert( startMsg ) ;
        return null ;
    }
	
    // check that an interval parameter was not numeric. 
    if ( interval.charAt == 'undefined' ) {
        // the user specified an incorrect interval, handle the error. 
        alert( intervalMsg ) ;
        return null ;
    }

    // check that the number parameter is numeric. 
    if ( isNaN ( number ) )	{
        alert( numberMsg ) ;
        return null ;
    }

    // so far, so good...
    //
    // what kind of add to do? 
    switch (interval.charAt(0))
    {
        case 'd': case 'D': 
            number *= 24 ; // days to hours
            // fall through! 
        case 'h': case 'H':
            number *= 60 ; // hours to minutes
            // fall through! 
        case 'm': case 'M':
            number *= 60 ; // minutes to seconds
            // fall through! 
        case 's': case 'S':
            number *= 1000 ; // seconds to milliseconds
            break ;
        default:
        // If we get to here then the interval parameter
        // didn't meet the d,h,m,s criteria.  Handle
        // the error. 		
        alert(intervalMsg) ;
        return null ;
    }
    return new Date( buffer + number ) ;
}
function FormatoDataNoOra(DataIta){
var StrData1=DataIta

	g1=StrData1.substring(0,2);
	m1=StrData1.substring(3,5);
	a1=StrData1.substring(6);
	var Data1=new Date(m1+"/"+g1+"/"+a1);
	return (Data1);
}
function FormatoDataConOra(DataIta,ora){
var StrData1=DataIta

	g1=StrData1.substring(0,2);
	m1=StrData1.substring(3,5);
	a1=StrData1.substring(6);
	var Data1=new Date(m1+"/"+g1+"/"+a1+ " "+ora);
	return (Data1);
}
//**************************************************************************
function ApriFinestra(MioFile,W,H){
    var miafin=window.open(MioFile,"MiaWin","width=" + W + ",height=" + H + ", scrollbars=1")
    miafin.focus();
}
function ApriFinestraFoto(MioFile,W,H){
    var miafinFoto=window.open(MioFile,"MiaWinFoto","width=" + W + ",height=" + H + ", scrollbars=1")
    miafinFoto.focus();
}
// *************** Fine Controllo Data **************************//

// *************** Inizio Controllo Email **************************//
// *** Espressione regolare degli indirizzi di posta elettronica ****//
var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
// *************** Fine Controllo Email **************************//


