<!--  *** NETSCAPE RESIZE ****  --------------------------------------------------------------------------->

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) 
  	{if ((appName=="Netscape")&&(parseInt(appVersion)==4)) 
		{document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }
	}
  	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH)
		location.reload();
}
MM_reloadPage(true);


<!--  *** popup ****  --------------------------------------------------------------------------->
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
<!--  *** favorites ****  --------------------------------------------------------------------------->
function addToFavorite(favTitle){if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) {
window.external.AddFavorite(location.href, unescape(favTitle));}}

<!--  *** IMAGES ****  --------------------------------------------------------------------------->

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->


<!-- *******************  --------------------------------------------------------------------------->

function wo(url,nome,w,h,s){
	var ww;
	s = typeof(s)=="undefined"?"0":"1";
	ww = window.open(url,nome,
					"top=" + (screen.height - h)/2 + 
					",left=" + (screen.width - w)/2 + 
					",fullscreen=0" +
					",height=" + h + 
					",width=" + w + 
					",status=0 " +
					",toolbar=no" +
					",menubar=no" +
					",location=0" +
					",resizable=no" +
					",statusbar=0" +
					",scrollbars=" + s);
	ww.resizeTo(w,h);
	ww.moveTo((screen.width - w)/2,(screen.height - h)/2);
	ww.focus();
	return ww;
}


function strReverse(st){
	var i,s="";
	for(i=st.length-1;i>=0;i--)
	s += st.charAt(i);
		
	return s;
}
	
function strLeftTrim(t){
	var i,st=t;
	while(st.length>0 && st.charAt(0)==" ")
	st = st.substring(1,255)
		
	return(st);
}
	
function strTrim(st){
	var t = strReverse(st), i;
	t =strLeftTrim(t);
		
	t = strReverse(t);
		
	return(strLeftTrim(t));
}

function strRightDif(st,n){
	// Funzione che restituisce la stringa st diminuita a destra di n caratteri
	// ex: strRigthDif("pippo",2) restituisce "pip"
	
	var t = strReverse(st);
	t = t.substring(n,255);
	return(strReverse(t));
}
function strLeftDif(st,n){
	// Funzione che restituisce la stringa st diminuita a sinistra di n caratteri
	// ex: strLeftDif("pippo",2) restituisce "ppo"
	return(st.substring(n,255));
}

function hasValue(objType, obj, objValue)
{
    if (objType == "TEXT" || objType == "PASSWORD")
	{
    	if (obj.value.length == 0) 
      		return false;
    	else 
      		return true;
    }
    else if (objType == "SELECT")
	{
        for (i=0; i < obj.length; i++)			
	    	{
		if (obj.options[i].selected)
			return true;
	}
       	return false;	
	}
    else if (objType == "SINGLE_VALUE_RADIO" || objType == "SINGLE_VALUE_CHECKBOX")
	{
		if (obj.checked)
			return true;
		else
       		return false;	
	}
    else if (objType == "RADIO" || objType == "CHECKBOX")
	{
        for (i=0; i < obj.length; i++)
    	{
		   if (obj[i].checked)
			 return true;
		}
       	return false;	
	}
}
function checkInteger(objValue)
{
    //Returns true if value is a number or is NULL
    //otherwise returns false	
    if (objValue.length == 0)
        return true;
    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
	var decimal_format = ".";
	var check_char;
    //The first character can be + -  blank or a digit.
	check_char = objValue.indexOf(decimal_format)
    //Was it a decimal?
    if (check_char < 1)
	   return checkNumber(objValue);
    else
	   return false;
}
function checkRange(objValue, minValue, maxValue)
{
    // check minimum
    if (minValue != null)
	{
        if (objValue < minValue)
		  return false;
	}
    // check maximum
    if (maxValue != null)
	{
	    if (objValue > maxValue)
		  return false;
	}
	
    //All tests passed, so...
    return true;
}
function checkNumber(objValue)
{
    //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;
    //The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(objValue.charAt(0))
    //Was it a decimal?
	if (check_char == 1)
	    decimal = true;
	else if (check_char < 1)
		return false;
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < objValue.length; i++)
	{
		check_char = number_format.indexOf(objValue.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	
				trailing_blank = true;
        // ignore leading blanks
		}
	    else if (trailing_blank)
		     return false;
		else
			digits = true;
	}	
    //All tests passed, so...
    return true
}


function checkDate(objValue)
{
    //Returns true if value is a eurodate format or is NULL
    //otherwise returns false	
    if (objValue.length == 0)
        return true;
    //Returns true if value is a date in the dd/mm/yyyy format
	isplit = objValue.indexOf('/');
	if (isplit == -1)
	{
		isplit = objValue.indexOf('.');
	}
	if (isplit == -1 || isplit == objValue.length)
		return false;
    sDay = objValue.substring(0, isplit);
	monthSplit = isplit + 1;
	isplit = objValue.indexOf('/', monthSplit);
	if (isplit == -1)
	{
		isplit = objValue.indexOf('.', monthSplit);
	}
	if (isplit == -1 ||  (isplit + 1 )  == objValue.length)
		return false;
    sMonth = objValue.substring((sDay.length + 1), isplit);
	sYear = objValue.substring(isplit + 1);
	if (!checkInteger(sMonth)) //check month
		return false;
	else
	if (!checkRange(sMonth, 1, 12)) // check month
		return false;
	else
	if (!checkInteger(sYear)) //check year
		return false;
	else
	if (!checkRange(sYear, 1970, 2020)) //check year
		return false;
	else
	if (!checkInteger(sDay)) //check day
		return false;
	else
	if (!checkDay(sYear, sMonth, sDay)) //check day
		return false;
	else
		return true;
}
function checkDay(checkYear, checkMonth, checkDay)
{
	maxDay = 31;
	if (checkMonth == 4 || checkMonth == 6 ||
			checkMonth == 9 || checkMonth == 11)
		maxDay = 30;
	else
	if (checkMonth == 2)
	{
		if (checkYear % 4 > 0)
			maxDay =28;
		else
		if (checkYear % 100 == 0 && checkYear % 400 > 0)
			maxDay = 28;
		else
			maxDay = 29;
	}
	return checkRange(checkDay, 1, maxDay); //check day
}
/*
function checkEMail(objValue)
{
	  ------ CONTROLLO: MAIL -------- 
	// Verifica la presenza dei caratteri '@' e '.' 
	// e che il '@' venga prima del '.'
	   var offsetAt, offsetDot;
	
	if ((offsetAt = objValue.indexOf('@')) == -1)
	     return false;
		
	subEMail = objValue.substr(offsetAt)
	
	if ((offsetDot = subEMail.indexOf('.')) == -1)
	  return false;
    return true;
}
*/
//----- CONTROLLO: MAIL -------- 
function checkEMail(objValue)
{
	apos=objValue.indexOf("@");
	dotpos=objValue.lastIndexOf(".");
	lastpos=objValue.length-1;
	if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
	{return false;}
	else {return true;}
}
function check(objForm, objType, objValidate, objRequired, objName, obj, objValue, minValue, maxValue)
// objForm: oggetto form
// objType: tipo dell'oggetto ( TEXT )
// objValidate: controllo di sintassi per STRING, INTEGER, FLOAT, DATE, EMAIL
// objRequired: oggetto richiesto
// objName: nome dell'oggetto da visualizzare in caso di errore
// obj: oggetto
// objValue: valore dell'oggetto
// minValue: valore minimo consentito, se impostato a null non viene considerato
// maxValue: valore massimo consentito, se impostato a null non viene considerato
{
  var err = 0;
  var strErr = "";
  var decimal_format = ".";
  var check_char;
  // Controllo se obj ha un valore
  if (objRequired)
  {
     if (!hasValue(objType, obj, objValue))
	 {
        strErr = objName + " obbligatorio/a" + "\n";
		return strErr;
	 }
  }
	
  // Controllo il tipo di dato inserito in obj
  switch (objValidate)
  {
  case "INTEGER":
     if (!checkInteger(objValue))
	 {
	    strErr = objName + " non valido" + "\n";
	    return strErr;
	 }
	 break;
  case "FLOAT":
	 if (!checkNumber(objValue))
	 {
	   if (objValue != '') 
	   {
	   strErr = objName + " non valido" + "\n";
	   return strErr;
	   }
	 }
	 break;
  case "DATE":
	 if (!checkDate(objValue))
	 {
	   strErr = objName + " non valido" + "\n";
	   return strErr;
	 }
	 break;
  case "EMAIL":
	 if (!checkEMail(objValue))
	 //if (!emailvalidation(objValue))
	 {
	   strErr = objName + " non valido" + "\n";
	   return strErr;
	 }
	 break;
  }
  // Controllo il range del objValue
  if ((minValue != null) || (maxValue != null))
  {
	 if (!checkRange(objValue, minValue, maxValue))
	 {
	   if ((minValue == null) && (maxValue != null))
	   {
	      strErr = objName + " deve essere <= " + maxValue + "\n"      
	   }	
	   else if ((minValue != null) && (maxValue == null))
	   {
	      strErr = objName + " deve essere >= " + minValue + "\n"
	   }	 
	   else //((minValue != null) && (maxValue != null))
	   {
	      strErr = objName + " non compreso nell'intervallo da " + minValue + " a " + maxValue + "\n";
	   }	  
	   return strErr;
	 }
  }
  
  return strErr;
}

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function compareDate(data1,op,data2) {
 	datepart = data1.split("/");
    myDay = datepart[0];
    myMonth = datepart[1];
    myYear = datepart[2];
    data1=new Date(myMonth+"/"+myDay+"/"+myYear);
    
    datepart = data2.split("/");
    myDay = datepart[0];
    myMonth = datepart[1];
    myYear = datepart[2];
    data2=new Date(myMonth+"/"+myDay+"/"+myYear);
 	r=0;
 	eval("if (data1.getTime()"+op+"data2.getTime()){r=1}");	
 	if (r) return true;
 	else return false;
}
