/* author : FC Service */
/* Creation date : 11 / 12 / 2002 */
var M3H_LTS = 1000 / 60 / 60;
var LTS_M3H = 60 * 60 / 1000;

function CellBlur(obj)
{
   obj.style.background = "#FF9B00";
   return false;
}

function CellFocus(obj)
{
   obj.style.background = "#FFFFFF";
   return false;
}

function CellChange(obj )
{
   obj.style.background = "#013675";
   return false;
}

function ev_right(e)
{
   /* if ((navigator.appName == 'Netscape') && (e.which == 3 || e.which == 2))
   return false; */
   if ((event.button == 2) || (event.button == 3))
   {
      alert("Spiacenti, il tasto destro del mouse e' disabilitato");
      return false;
   }
   return true;
}

function Is()
{
   var agent = navigator.userAgent.toLowerCase();
   this.brOK  = false;
   this.major = parseInt(navigator.appVersion);
   this.minor = parseFloat(navigator.appVersion);
   this.ns  = ((agent.indexOf('mozilla') != - 1) && ((agent.indexOf('spoofer') == - 1) && (agent.indexOf('compatible') == - 1)));
   this.ns2 = (this.ns && (this.major == 3));
   this.ns3 = (this.ns && (this.major == 3));
   this.ns4 = (this.ns && (this.major >= 4));
   this.ns406 = (this.ns && (this.minor == 4.06));
   this.ns407 = (this.ns && (this.minor == 4.07));
   this.ns408 = (this.ns && (this.minor == 4.08));
   this.ns45 = (this.ns && (this.minor == 4.5));
   this.ie   = (agent.indexOf("msie") != - 1);
   this.ie3  = (this.ie && (this.major == 2));
   this.ie4  = (this.ie && (this.major >= 4));
   this.op3  = (agent.indexOf("opera") != - 1);
   this.win   = (agent.indexOf("win") != - 1);
   this.mac   = (agent.indexOf("mac") != - 1);
   this.unix  = (agent.indexOf("x11") != - 1);
   if((this.major >= 4) && (this.ns || this.ie))
   {
      //    	this.brOK  = true;
      this.brOK  = navigator.javaEnabled();
   }
}

var g0;
var g1;
var g2;
var g3;
var g4;
var g5;
var g6;
var g7;
var g8;
var g9;
var gb;

var focusDay;
var startingPos;
var daysOfMonth;
var is = new Is();
var	finestraW = (is.ns4) ? "window.innerWidth" : "document.body.clientWidth";
var blank = "images_rstyle/nullpix.gif";

topedge = 25;
// location of news box from top of page
leftedge = 140;
// location of news box from left edge
boxheight = 90;
// height of news box
boxwidth = 320;
// width of news box
scrollheight = 280;
// total height of all data to be scrolled
winwidth = 1024;

function PreloadImage(imageup, imagedown, width, height)
{
   this.up = new Image(width, height);
   this.up.src = imageup;
   this.dn = new Image(width, height);
   this.dn.src = imagedown;
}

function CambiaImg(nomeImg, src)
{
   var oggettoImage = eval('document.' + nomeImg);
   oggettoImage.src = src;
}

function TogliPunto(valore)
{
   var strNumber = new String;
   strNumber = valore.toString();
   strNumber = strNumber.replace(".", ",");
   return strNumber;
}

function CheckNumberOfObject(ObjTxT)
{

   var valore;
   valore = ObjTxT.value;

   if (isNaN(valore))
   {
      valore = valore.replace(",", ".");
      if (isNaN(valore))
      {
         alert("Inserire un valore valido");
         valore = valore.substr(0, valore.length - 1);
         ObjTxT.value = valore;
         return false;
      }

   }
}

function CheckNumber(valore)
{

   if (isNaN(valore))
   {
      valore = valore.replace(",", ".");
      if (isNaN(valore))
      {
         alert("Inserire un valore numerico valido");
         valore = valore.substr(0, valore.length - 1);
         return false;
      }

   }
}

function Stampa(Messaggio, action, frm, button)
{

   if (window.confirm(Messaggio))
   {
      var objForm = eval('document.' + frm);
      objForm.action = action;
      if(button != null)
      AvviaElaborazione(button);
      objForm.submit();
   }
   else alert("Generazione stampa annullata");

}

function CheckEmail(valore)
{

   if (valore == "")
   {
      alert("E-mail non valida");
      return false;
   }
   if (valore.length < 6)
   {
      alert("E-mail non valida");
      return false;
   }

   var chiocciola = - 1;
   var pos2 = - 1;
   var punto = - 1;

   chiocciola = valore.indexOf("@");

   if (chiocciola == - 1)
   {
      alert("E-mail non valida (Nessuna @ nell'indirizzo email");
      return false;
   }
   pos2 = valore.indexOf("@", chiocciola + 1);
   if (pos2 != - 1)
   {
      alert("E-mail non valida (Più @ nell'indirizzo email)");
      return false;
   }
   punto = valore.indexOf(".", chiocciola + 1);

   if (punto == - 1)
   {
      alert("E-mail non valida (Nessun provider specificato)");
      return false;
   }
   pos2 = valore.indexOf(".", punto + 1);
   if (pos2 != - 1)
   {
      alert("E-mail non valida (Troppi punti dopo la @)");
      return false;
   }

   var tmp = valore.substring(punto, valore.length);

   if (tmp.length <= 1)
   {
      alert("E-mail non valida");
      return false;
   }

   if ( ! isNaN(tmp))
   {
      alert("E-mail non valida");
      return false;
   }

   tmp = valore.substring(chiocciola, punto);
   if (tmp.length == 0)
   {
      alert("E-mail non valida");
      return false;
   }

   tmp = valore.substring(0, chiocciola);
   if (tmp.length == 0)
   {
      alert("E-mail non valida");
      return false;
   }
   return true;
}

function TestData(ladata, anno)
{
   if(ladata.length > 5)
   {
      alert("Errore: " + ladata + "/" + anno);
      return "NULL";
   }
   ob = ladata.split("/");
   if(ob.length == 2)
   {
      gg = "00" + trim(ob[0]);
      mm = "00" + trim(ob[1]);
      gg = gg.substr(gg.length - 2, 2);
      mm = mm.substr(mm.length - 2, 2);
      return ( gg + "/" + mm + "/" + anno);
   }
   else
   alert("Errore: " + ladata + "/" + anno);
   return "NULL";
}

function trim(str)
{
   i = str.length - 1;
   while(i >= 0)
   {
      if(str.substr(i, 1) != " ")
      break;
      i -- ;
   }
   i ++ ;
   str = str.substr(0, i);
   l = str.length;
   i = 0;
   while(i < l)
   {
      if(str.substr(i, 1) != " ")
      break;
      i ++ ;
   }
   return str.substr(i, l - i);
}

function CheckData(gg, mm, aa, messaggio)
{
   if ((gg == "") || (mm == "") || (aa == ""))
   {
      alert("La " + messaggio + " deve essere numerica");
      return false;
   }
   if ((isNaN(gg)) || (isNaN(mm)) || (isNaN(aa)))
   {
      alert("La " + messaggio + " deve essere numerica");
      return false;
   }
   var tmm = 0;
   var tgg = 0;
   var taa = parseInt(aa);
   if (gg.length == 2)
   {
      if (gg.substring(0, 1) == "0") tgg = parseInt(gg.substring(1, 2));
      else tgg = parseInt(gg);
   }
   else tgg = parseInt(gg);
   if (mm.length == 2)
   {
      if (mm.substring(0, 1) == "0") tmm = parseInt(mm.substring(1, 2));
      else tmm = parseInt(mm);
   }
   else tmm = parseInt(mm);

   if ((tgg <= 0) || (tgg > 31))
   {
      alert("Giorno della " + messaggio + " non valido");
      return false;
   }

   if (taa <= 0)
   {
      alert("Anno della " + messaggio + " non valido");
      return false;
   }

   if ((tmm > 12) || (tmm <= 0))
   {
      alert("Mese della " + messaggio + " non valido");
      return false;
   }
   if ((tmm == 4) || (tmm == 6) || (tmm == 9) || (tmm == 11))
   {
      if (tgg > 30)
      {
         alert("Giorno della " + messaggio + " inesistente nel mese");
         return false;
      }
   }
   if (tmm == 2)
   {
      if (tgg > 29)
      {
         alert("Giorno della " + messaggio + "inesistente nel mese");
         return false;
      }
   }
   return true;
}

function ApriFinestra(nome, action, width, heigth, srbar,resize)
{
   var puntoX = (screen.availWidth - width) / 2;
   var puntoY = (screen.availHeight - heigth) / 2;
   var stile = "toolbar=0,location=0,directories=0,menuBar=0";
	if(resize && (resize != ""))   
   		stile = (stile + ",resizable="+resize);
	stile = (stile + ",width=" + width + ",height=" + heigth + ",left=" + 
   		puntoX + ",top=" + puntoY);
	if(srbar && (srbar != ""))   
		stile = (stile + ",scrollbars=" + srbar);
	stile = (stile + ",titlebar=0");
   return window.open(action, nome, stile);
}

function AvviaElaborazione(button)
{
   if(button != null)
   {
      if(button.disabled == true) button.disabled = false;
      else button.disabled = true;
   }
   AvviaClessidra();
   // script per muovere la clessidra
}

function AvviadaOpener(button)
{
   if(button != null)
   {
      if(button.disabled == true) button.disabled = false;
      else button.disabled = true;
   }
   window.opener.AvviaClessidra();
   // script per muovere la clessidra
}

function AvviaClessidra()
{
   if(top.logo)
   top.AvviaClessidra();
   else
   if(window.opener)
   window.opener.AvviaClessidra();
}

function StopClessidra()
{
   if(top.logo)
   top.Stop();
   else
   if(window.opener)
   window.opener.StopClessidra();
}


strSelect = "<HTML><HEAD><SCRIPT LANGUAGE='JScript'>" +
"function clickPopup(){alert(event.srcElement.tagName);if (event.srcElement.tagName == 'TD'){" +
"parent.inputid.innerText = event.srcElement.id;	parent.oPopup.hide();}}" +
"</SCRIPT></HEAD>" +
"<BODY onclick='clickPopup();' style='border:solid 1; " +
"background-color:darkblue; overflow:hidden; margin-top:2px; margin-right:2px; " +
"margin-left: 2px; margin-bottom:2px'>" +
"<table border=0 >" +
"<tr><td>cacio cavallo</td></tr>" +
"<tr><td>pecorino</td></tr>" +
"<tr><td>parmiggiano</td></tr>" +
"<tr><td>mozzarella</td></tr>" +
"</table>" +
"</body></html>";

function ImageSelector(srcout, srcover)
{
   this.out = new Image();
   this.out.src = srcout;
   this.over = new Image();
   this.over.src = srcover;
}


function FormattaNumero(valore, num)
{
   var tmpval = valore;
   var resPow = 0, moltip = 10,
   resPow = Math.pow(moltip, num);
   moltip = tmpval;
   moltip *= resPow;
   moltip += 0.49;
   var tmp = parseInt(moltip);
   var totale =  (tmp / resPow);
   return totale;
}

function FormattaData(gg, mm, aa)
{
   var Data = "";
   var tmm = mm;
   var tgg = gg;

   if (gg.length == 1)
   {
      tgg = "0" + gg;
   }
   if (mm.length == 1)
   {
      tmm = "0" + mm;
   }

   Data = tgg + "/" + tmm + "-" + aa;
   return Data;
}

function FormattaDataMySQL(gg, mm, aa)
{
   var Data = "";
   var tmm = mm;
   var tgg = gg;

   if (gg.length == 1)
   {
      tgg = "0" + gg;
   }
   if (mm.length == 1)
   {
      tmm = "0" + mm;
   }

   Data = aa + "-" + tmm + "-" + tgg;
   return Data;
}

function ScanElementForm(obj)
{
   for (i = 0; i < obj.elements.length; i ++ )
   obj.elements[i].value = ReplaceString(obj.elements[i].value, "€", "&euro;");
}

function ReplaceString(stringa, valoreIniziale, valoreFinale)
{
   var pos = - 1;
   var inizio = 0;
   pos = stringa.indexOf(valoreIniziale);
   var strReturn = "";

   while(pos > - 1)
   {
      var temp = stringa.substring(inizio, pos);
      inizio = pos + valoreIniziale.length;
      strReturn += temp + valoreFinale;
      pos = stringa.indexOf(valoreIniziale, pos + 1);
   }

   strReturn += stringa.substring(inizio);
   return strReturn;
}


function ToolTip(stringa)
{
   var oPopup = window.createPopup();
   var oPopupBody = oPopup.document.body;
   oPopupBody.bgColor = "#ffff99";
   oPopupBody.innerHTML = ("<SPAN style='font-family:verdana; font-size:7pt; color:red; font-weight:bold'>" + stringa + "</SPAN>");
   oPopup.show(80, 0, 250, 15, event.srcElement);
}

function validString(stringa)
{
   if((stringa.length > 0) && (stringa != "") ) return stringa;
   return "&nbsp;";
}

function validNumber(stringa)
{
   valore = stringa;
   if (isNaN(valore))
   {
      valore = valore.replace(",", ".");
      if (isNaN(valore))
      {
         return 0;
      }
   }
   return valore;
}

function validDouble(stringa)
{
   valore = stringa;
   if (isNaN(valore))
   {
      valore = valore.replace(",", ".");
      if (isNaN(valore))
      {
         return 0.0;
      }
   }
   return valore;
}

function SetSatusBar(msg)
{
   window.status = msg;

}

function isLeapYear (Year)
{
   if (((Year % 4) == 0) && ((Year % 100) != 0) || ((Year % 400) == 0))
   {
      return (true);
   }
   else
   {
      return (false);
   }
}

function CambiaStato(nomeChk, NumElement, nomeForm)
{
   var i = 0;
   var strReturn = "";
   var objChk = "";

   for (i = 0; i < NumElement; i ++ )
   {

      objChk = eval('document.' + nomeForm + '.' + nomeChk + (i + 1));
      if (objChk.checked == true)
      strReturn += "1,";
      else
      strReturn += "0,";
   }

   return strReturn;

}

function isEmpty(obj,messaggio)
{
   if (obj && obj.value == "") {
	   	alert("Compilare correttamente il campo " + messaggio + " obbligatorio");
	   	obj.focus();
   		return false;
   } return true;
   

}

// GET NUMBER OF DAYS IN MONTH
function getDaysInMonth(month, year)
{
   var days;
   if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 ||
   month == 10 || month == 12)  days = 31;
   else if (month == 4 || month == 6 || month == 9 || month == 11) days = 30;
   else if (month == 2)
   {
      if (isLeapYear(year))
      {
         days = 29;
      }
      else
      {
         days = 28;
      }
   }
   daysOfMonth = days;
   return (days);
}

// CHECK TO SEE IF YEAR IS A LEAP YEAR

function AssegnaValore(nomeForm, nomeObj, valore)
{
   oggetto = eval('document.' + nomeForm + '.' + nomeObj);
   oggetto.value = valore;
   eval('document.' + nomeForm + '.submit()');

}

	function grassetto() {
		tag = document.selection.createRange().parentElement().tagName;
		if (tag=="TEXTAREA") {
			txtrange = document.selection.createRange().text;
			document.selection.createRange().text =" <b>" + txtrange + "</b> ";
		}
	}
	function corsivo() {
		tag = document.selection.createRange().parentElement().tagName;
		if (tag=="TEXTAREA") {
			txtrange = document.selection.createRange().text;
			document.selection.createRange().text =" <i>" + txtrange + "</i> ";
		}
	}
	function sottolineato() {
		tag = document.selection.createRange().parentElement().tagName;
		if (tag=="TEXTAREA") {
			txtrange = document.selection.createRange().text;
			document.selection.createRange().text =" <u>" + txtrange + "</u> ";
		}
	}
	function sx() {
		tag = document.selection.createRange().parentElement().tagName;
		if (tag=="TEXTAREA") {
			txtrange = document.selection.createRange().text;
			document.selection.createRange().text =" <div align=\"left\">" + txtrange + "</div> ";
		}
	}
	
	function cx() {
		tag = document.selection.createRange().parentElement().tagName;
		if (tag=="TEXTAREA") {
			txtrange = document.selection.createRange().text;
			document.selection.createRange().text =" <div align=\"center\">" + txtrange + "</div> ";
		}
	}
	function dx() {
		tag = document.selection.createRange().parentElement().tagName;
		if (tag=="TEXTAREA") {
			txtrange = document.selection.createRange().text;
			document.selection.createRange().text =" <div align=\"right\">" + txtrange + "</div> ";
		}
	}
	
	function br(obj,frm) {
		txt = eval('document.' + frm + '.' + obj);
		testo = txt.value;
		txt.value = testo + " <br>";		
	
	}
