function select(a, changeTo)
{
   a.style.backgroundColor = changeTo;
}


var lampI = 0; 
var lampAColor = new initArray("", "");
var lampTimerId; 
var lampSpeed = 500; 

var g_Oggi;
var g_Giorno;
var g_Mese;
var g_Anno;

g_Oggi = new Date();

g_Giorno = String(g_Oggi.getDate ()); if(g_Giorno.length == 1) { g_Giorno = '0' + g_Giorno; }
g_Mese   = String(g_Oggi.getMonth() + 1); if(g_Mese.length   == 1) { g_Mese   = '0' + g_Mese;   }
g_Anno   = String(g_Oggi.getFullYear());

g_Oggi = g_Giorno + '/' + g_Mese + '/' + g_Anno;

function EvidenziaRiga()
{
	var mybody = document.getElementById("xbrowser_tbody");
	if(mybody == null) return;
	
	var riga = mybody.getElementsByTagName("tr");
	for (var i=0; i<riga.length; i++) {
		riga[i].onmouseover=function()
		{ 
		   eval("select(this, 'CADBE4');");
		};
		
		riga[i].onmouseout=function()
		{ 
		   eval("select(this, '');");
		};
		
	}
}

function trim(stringa)
{
   while (stringa.substring(0,1) == ' ')
   {
      stringa = stringa.substring(1, stringa.length);
   }
   while (stringa.substring(stringa.length-1, stringa.length) == ' ')
   {
      stringa = stringa.substring(0,stringa.length-1);
   }
   return stringa;
}

function TextToFloat(txt_num)
{
   txt_num = ReplaceGlobal(txt_num, ".", "");
   txt_num = ReplaceGlobal(txt_num, ",", ".");
   
   return parseFloat(txt_num);
}

function chiudi() {
   top.self.opener = self;
   window.top.close();
}

function chcolor(oggetto, colore, sfondo)
{
   lampAColor[0] = colore;
   lampAColor[1] = sfondo;
   obj = document.getElementById(oggetto);
   obj.style.color = lampAColor[lampI]; 
   (lampI < lampAColor.length-1) ? (lampI++) : (lampI=0); 
} 

function initArray()
{ 
  this.length = initArray.arguments.length; 
  for (var i = 0; i < this.length; i++) { 
          this[i] = initArray.arguments[i]; 
   } 

} 

function checkData(dataString)
{
   if (/^(\d\d?)\/(\d\d?)\/(\d\d){1,2}$/.test(dataString)) {
      gg = parseInt(RegExp.$1, 10)
      mm = parseInt(RegExp.$2, 10)
      aa = parseInt(RegExp.$3, 10)
      data = new Date(aa,mm-1,gg)
      
      if(data.getDate()==gg && data.getMonth()+1==mm && (data.getYear()==aa||data.getYear()==1900+aa)) {
         return true;
      }
      else {
         return false;
      }
   }
   else {
      return false;
   }
} 

function modifica_div(valore)
{  
   var div = document.getElementById("div1");
   var width_div = div.style.width; 
   var obj = document.getElementById("div_tab");
       
   div.style.overflowY = valore;
   div.style.width = width_div;
   
   if(valore == "visible")
   {
      obj.style.display = "none";
   }
   else
   {
      obj.style.display = "block";
   }
   
   var TopFrame = top.main;
   if(TopFrame != undefined) 
   {
      var url_pag = TopFrame.window.location.href.substr(TopFrame.window.location.href.indexOf("MovimentiArtx"));
      //alert(url_pag);
      if(url_pag > 0)
      {
         var divB = document.getElementById("div2");
         divB.style.overflowY = valore;
         divB.style.width = width_div;
      }
   }
   
}

function Lampeggia()
{
   obj = document.getElementById("temp");
   
   if(obj.style.visibility == "hidden")
   {
      obj.style.visibility = "visible";
   }
   else
   {
      obj.style.visibility = "hidden";
   }
   
   t = setTimeout("Lampeggia()", 500);
}

function StopLamp()
{
   clearTimeout(t);
}

function ControllaData( NewValue , ErrMsg , OldValue , DataNullaAmmessa )
{
   if( ErrMsg           == undefined ) { ErrMsg           = "";           }
   if( OldValue         == undefined ) { OldValue         = "01/01/9999"; }
   if( DataNullaAmmessa == undefined ) { DataNullaAmmessa = true;         }
   
   ok = checkData( NewValue );
   
   if(ok) {
      //formatto i campi in modo da avere 0+num giorno se è minore di 10
      vNewValue = NewValue.split("/");
      if(vNewValue[0].length == 1) { NewValue = "0" + NewValue; }
      if(vNewValue[1].length == 1) { NewValue = NewValue.substr(0, 3) + "0" + NewValue.substr(3); }
      if(vNewValue[2].length == 2) { NewValue = NewValue.substr(0, 6) + "20" + NewValue.substr(6); }
      if( NewValue  == "01/01/9999" ) {
         ok = DataNullaAmmessa;
      }
   }
   
   if (!ok) {
      if(ErrMsg != "") {
         alert( ErrMsg );
      }
      NewValue = OldValue;
   }
   
   return NewValue;
}

function ControllaEConferma(valore, errore)
{
   // SOSTITUIRE CON LA NUOVA E PIU' COMPLETA   ControllaData
   
   ok = checkData(valore);
   
   if(ok) {
      datanulla = "01/01/9999";
      if (valore  == datanulla) {
         ok = false;
      }
      else {
         if(valore.length == 8) {
            valore = valore.substr(0,6) + '20' + valore.substr(6,2);
         }
      }
   }
   
   if (!ok) {
      alert(errore)
      valore = "01/01/9999";
   }
   
   return valore;
}

function ControllaEConferma2(valore, dataoggi)
{
   // SOSTITUIRE CON LA NUOVA E PIU' COMPLETA   ControllaData
   ok = checkData(valore);
   
   if(ok) {
      datanulla = "01/01/9999";
      if (valore  == datanulla) {
         ok = false;
      }
      else {
         if(valore.length == 8) {
            valore = valore.substr(0,6) + '20' + valore.substr(6,2);
         }
      }
   }
   
   if (!ok) {
      valore = dataoggi;
   }
   
   return valore;
}

function ReplaceGlobal(stringa, oldvalue, newvalue)
{
   if(oldvalue == "." || oldvalue == "*" || oldvalue == "?" || oldvalue == "+" || oldvalue == "(" || oldvalue == ")" || oldvalue == "{" || oldvalue == "}" || oldvalue == "[" || oldvalue == "]" || oldvalue == "^" || oldvalue == "$")
   {
      soldvalue = "\\" + oldvalue;
   }
   else
   {
      soldvalue = oldvalue;
   }
   //document.write(soldvalue);
   return stringa.replace(new RegExp(soldvalue, "g"), newvalue);
}


function ApriFinestra(MyUrl) {
   var x = navigator;
   w = screen.width;
   h = screen.height;
   
   if(x.appName == 'Microsoft Internet Explorer')
   {
      if(x.appVersion.indexOf('MSIE 6.0') != -1)
      {
         // Internet Explorer 6.0
         h = h - 100;
         w = w - 10;
      }
      else if(x.appVersion.indexOf('MSIE 7.0') != -1)
      {
         // Internet Explorer 7.0
         h = h - 100;
      }
   }
   else
   {
      // Non Internet Explorer
   }
   
   strpos = 'top=0px, left=0px,';
   strsiz = 'height=' + h + 'px, width=' + w + 'px';
   window.open(MyUrl, '', 'location=1,' + strpos + strsiz);
}

function LeggiSession(session_name)
{
   /////////////////////////////////////////////////
   //legge una variabile di sessione da javascript//
   /////////////////////////////////////////////////
   
   ret = ajaxpage("/common/funzioni_ajax.asp?Tipo=LeggiSession&SessionName="+session_name, undefined, false);
   return ret;
}

function SettaSession(nome_session, valore_session)
{
   ///////////////////////////////////////////////////////////////
   //Setta una variabile di sessione tramite chiamata javascript//
   ///////////////////////////////////////////////////////////////
   
   ret = ajaxpage("/common/funzioni_ajax.asp?Tipo=SettaSession&Nome="+nome_session+"&Valore="+valore_session, undefined, false);
   //alert(ret);
}

function FormatNumber(num)
{
   ret = ajaxpage("/common/funzioni_ajax.asp?Tipo=FormatNumber&Number="+num, undefined, false);
   return ret;
}

function FormattaNumero(num, decimals)
{
   //uguale alla FormatNumber, ma si possono scegliere i decimali
   
   if(decimals == null)                        { decimals = 2; }
   if(ReplaceGlobal(""+num+"", " ", "") == "") { num      = 0; }
   
   return ajaxpage("/common/funzioni_ajax.asp?Tipo=FormattaNumero&Num="+num+"&Decimals="+decimals, undefined, false);
}

function CountTextareaChrs(txtarea, chrlimit, block_length)
{
   /////////////////////////////////////////////////////////////////////////////////
   //Conta i caratteri di una textarea, eventualmente bloccando futuri inserimenti//
   //di caratteri. Restituisce una stringa in questo formato:                     //
   //'<caratteri_inseriti>|<limite_caratteri>'                                    //
   /////////////////////////////////////////////////////////////////////////////////
   
   if(block_length == null) { block_length = false; }
   
   if(chrlimit == null)
   {
      //non ho posto limiti nella textarea, conto solo i caratteri
      return "" + txtarea.value.length + "|";
   }
   else
   {
      //la textarea è limitata a N caratteri
      if(block_length)
      {
         //la textarea ha un limite, gestisco qui il blocco della textarea
         if(txtarea.value.length > chrlimit)
         {
            txtarea.value = txtarea.value.substr(0, chrlimit);
         }
      }
      return "" + txtarea.value.length + "|" + chrlimit;
   }
}

function XBrowser_Events(EventName, ColumnName, PrimaryKey)
{
   retclk = false;
   
   try
   {
      switch(EventName)
      {
         case "OnClick":
            retclk = XBrowser_OnClick(ColumnName, PrimaryKey);
            break;
         case "OnBlur":
            retclk = XBrowser_OnBlur(ColumnName, PrimaryKey);
            break;
         case "OnKeyDown":
            retclk = XBrowser_OnKeyDown(ColumnName, PrimaryKey);
            break;
         default:
            alert("ERRORE!\n\nDESCRIZIONE:\nEvento non gestito.");
      }
   }
   catch(Errore)
   {
      /*testo = "ERRORE!\n\n"
            + "DESCRIZIONE:\nFallita la chiamata alla function "
            + "XBrowser_"+EventName+"(\""+ColumnName+"\", \""+PrimaryKey+"\").\n\n"
            + "DETTAGLI:\n"+Errore.description+".";
      alert(testo);*/
   }
   
   if(!retclk)
   {
      SelezionaCodice(PrimaryKey);
   }
}

/*function CreaCodiceJs(Code)
{
   ret = ajaxpage("/common/funzioni_ajax.asp?Tipo=CreaCodiceJs&Code="+encodeURIComponent(Code), undefined, false);
   return ret;
}*/

function DateDiff(d_ini, d_fine)
{  
   chkdate = ajaxpage("/common/funzioni_ajax.asp?Tipo=DateDiff&d_ini="+d_ini+"&d_fine="+d_fine, undefined, false);
   
   return chkdate;
}

function CallXBrowser(sql, view, elesrc, parametri, div, testo, testototale, eval_func, SearchCol, OrderCol, divTotals)
{
   if(testo       == null) { testo       = '';                                             }
   if(testototale == null) { testototale = ''; parametri = parametri + '&NoThTotale=True'; }
   if(eval_func   == null) { eval_func   = '';                                             }
   if(SearchCol   == null) { SearchCol   = '';                                             }
   if(OrderCol    == null) { OrderCol    = '';                                             }
   if(divTotals   == null) { divTotals   = '';                                             }
   
   prima = "/common/XBrowser.asp?Sql=";
   sql   = encodeURIComponent( sql );
   dopo  = "&EleSrc=" + elesrc + "&View=" + view + parametri;
   memo  = "&div=" + div + "&testo=" + testo;
   if(SearchCol != '')
   {
      memo += '&SearchCol=' + SearchCol;
   }
   if(OrderCol != '')
   {
      memo += '&OrderCol=' + OrderCol;
   }
   s     = prima + sql + dopo + memo;
   //document.write(s); return;
   
   if(div != "")
   {
      document.getElementById(div).innerHTML = testo;
      ajaxpage(s, div, true, 'XBrowser_SetTotale("' + testototale + '");EvidenziaRiga();'+eval_func);
   }
   else
   {
      return ajaxpage(s, undefined, false);
   }
   //ret = ajaxpage(s, undefined, false);
   //wdw = window.open();
   //wdw.document.write(ret);
   
   if(divTotals != "")
   {
      CallXBrowser("", "", "", "&Span=no&showtot=1", divTotals, 'Attendere, calcolo totali in corso...');
   }
}

function CallXBrowserPost(sql, view, elesrc, parametri, div, testo, testototale, eval_func)
{
   ////////////////////////////////////////////////////////////////////
   //Versione della CallXBrowser che passa i parametri tramite post. //
   //I parametri vanno passati nel seguente formato:                 //
   //- "Parametro1=Valore1&Parametro2=Valore2&...&ParametroN=ValoreN"//
   ////////////////////////////////////////////////////////////////////
   
   if(testo == null) { testo = ''; }
   if(parametri == null || trim(parametri) == "")
   {
      parametri = "";
   }
   else
   {
      parametri = "&" + parametri;
   }
   if(testototale == null) 
   { 
      testototale = ''; 
      parametri   = '&NoThTotale=True' + parametri;
   }
   if(eval_func == null) { eval_func = ""; }
   
   addr  = "/common/XBrowser.asp?";
   sql   = encodeURIComponent( sql );
   params = "Sql=" + sql + "&View=" + view + "&EleSrc=" + elesrc + parametri ;
   //document.write(s); return;
   
   if(div != "")
   {
      document.getElementById(div).innerHTML = testo;
      ajaxpost(addr, params, div, true, 'XBrowser_SetTotale("' + testototale + '");EvidenziaRiga();'+eval_func);
   }
   else
   {
      return ajaxpost(addr, params, undefined, false);
   }
   //ret = ajaxpage(s, undefined, false);
   //alert(ret);
}

function XBrowser_SetTotale(testototale)
{
   elem = document.getElementById('thtotale');
   if(elem == undefined) return;
   
   if(testototale == '') 
   {
      elem.style.display = "none";
      return;
   }
   
   RC = document.getElementById('hdntotale').value;
   testototale = ReplaceGlobal(testototale, "@RC", RC);
   elem.innerHTML = testototale;
}

function SelectAll()
{
	var vettore = document.getElementsByTagName("input");
	for (i = 0 ; i < vettore.length ; i++ )
	{
	   if(vettore[i].type == 'checkbox')
	   {
	      vettore[i].checked = true;
	   }
   }
}

function UnSelectAll()
{
	var vettore = document.getElementsByTagName("input");
	for (i = 0 ; i < vettore.length ; i++ )
	{
	   if(vettore[i].type == 'checkbox')
	   {
	      vettore[i].checked = false;
	   }
   }
}

function SezioneArrotondata_Ini(inBColor, inSfondoOut, inSfondoIn, inBodyBColor, inBodySfondo, inDivId)
{
   //se non ho selezionato un colore di bordo, non ha senso
   //continuare l'esecuzione
   //if(inBColor == null || inBColor == "") { return; }
   
   
   //preparazione del bordo
   if(inBColor == null || inBColor == "") 
   { 
      BColor = " background: transparent; ";
   }
   else
   {
      BColor = " background: " + inBColor + "; ";
   }
   //controllo sullo sfondo esterno
   if(inSfondoOut == null || inSfondoOut == "") 
   { 
      SfondoOut = " background: transparent; "; 
   }
   else
   {
      SfondoOut = " background: " + inSfondoOut + "; ";
   }
   //controllo sullo sfondo interno
   if(inSfondoIn == null || inSfondoIn == "") 
   { 
      SfondoIn = " background: transparent; "; 
   }
   else
   {
      SfondoIn = " background: " + inSfondoIn + "; ";
   }
   //controllo sullo sfondo del corpo
   if(inBodySfondo == null || inBodySfondo == "") 
   { 
      BodySfondo = " background: transparent; "; 
   }
   else
   {
      BodySfondo = " background: " + inBodySfondo + "; ";
   }
   //preparazione del bordo del corpo
   if(inBodyBColor == null || inBodyBColor == "") 
   { 
      BodyBColor = "transparent";
   }
   else
   {
      BodyBColor = inBodyBColor;
   }
   //preparo l'id del div, se l'ho passato
   if(inDivId != null && inDivId != "") 
   {
      //controllo che non esistano altri elementi con lo stesso id
      if(document.getElementById(inDivId) != null)
      {
         DivId = "";
         alert("Esiste gia' un elemento con id uguale a [" + inDivId + "]!\nId non assegnato.");
      }
      else
      {
         DivId = " id='" + inDivId + "' ";
      }
   }
   else
   {
      DivId = "";
   }
   
   
   ///////////////////////////
   //riproduzione del codice//
   ///////////////////////////
   
   //stile di rtop e rbottom
   Stile1 = " display:block; " + SfondoOut;
   //stili comuni di r1, r2 e r3
   Stile2 = "display: block; height: 1px; overflow: hidden; " + BColor;
   //stile di r1
   StileR1 = Stile1 + Stile2 + " margin: 0 5px;";
   //stile di r2
   StileR2 = Stile1 + Stile2 + " margin: 0 3px;";
   //stile di r3
   StileR3 = Stile1 + Stile2 + " margin: 0 2px;";
   //stile di r4
   StileR4 = Stile1 + Stile2 + " margin: 0 1px; height: 1px; ";
   //stile b inferiori
   StileB = "display:block; overfow:hidden; height:1px; " + SfondoIn;
   //stile recupero 2
   StileRec2 = StileB + " margin: 0 2px; ";
   //stile recupero 3
   StileRec3 = StileB + " margin: 0 1px; ";
   //stile recupero 4
   StileRec4 = StileB + " margin: 0 1px; ";
   
   
   //scrittura
   document.write("<b style='" + Stile1 + "'>");
   document.write("<b style='" + StileR1 + "'></b>");
   document.write("<b style='" + StileR2 + "'><b style='" + StileRec2 + "'></b></b>");
   document.write("<b style='" + StileR3 + "'><b style='" + StileRec3 + "'></b></b>");
   document.write("<b style='" + StileR4 + "'><b style='" + StileRec4 + "'></b></b>");
   document.write("</b>");
   document.write("<div " + DivId + " style='" + BodySfondo + " border-left:1px solid " + BodyBColor + "; border-right:1px solid " + BodyBColor + "; padding-left:5px; padding-right:5px;'>");
}

function SezioneArrotondata_End(inBColor, inSfondoOut, inSfondoIn)
{
   //se non ho selezionato un colore di bordo, non ha senso
   //continuare l'esecuzione
   if(inBColor == null || inBColor == "") { return; }
   
   
   //controllo sullo sfondo esterno
   if(inSfondoOut == null || inSfondoOut == "") 
   { 
      SfondoOut = " background: transparent; "; 
   }
   else
   {
      SfondoOut = " background: " + inSfondoOut + "; ";
   }
   //controllo sullo sfondo interno
   if(inSfondoIn == null || inSfondoIn == "") 
   { 
      SfondoIn = " background: transparent; "; 
   }
   else
   {
      SfondoIn = " background: " + inSfondoIn + "; ";
   }
   //preparazione del colore del bordo
   BColor = " background: " + inBColor + "; "
   
   
   ///////////////////////////
   //riproduzione del codice//
   ///////////////////////////
   
   //stile di rtop e rbottom
   Stile1 = " display:block; " + SfondoOut;
   //stili comuni di r1, r2 e r3
   Stile2 = "display: block; height: 1px; overflow: hidden; " + BColor;
   //stile di r1
   StileR1 = Stile1 + Stile2 + " margin: 0 5px;";
   //stile di r2
   StileR2 = Stile1 + Stile2 + " margin: 0 3px;";
   //stile di r3
   StileR3 = Stile1 + Stile2 + " margin: 0 2px;";
   //stile di r4
   StileR4 = Stile1 + Stile2 + " margin: 0 1px; height: 1px; ";
   //stile b inferiori
   StileB = "display:block; overfow:hidden; height:1px; " + SfondoIn;
   //stile recupero 2
   StileRec2 = StileB + " margin: 0 2px; ";
   //stile recupero 3
   StileRec3 = StileB + " margin: 0 1px; ";
   //stile recupero 4
   StileRec4 = StileB + " margin: 0 1px; ";
   
   
   //scrittura
   document.write("</div>");
   document.write("<b style='" + Stile1 + "'>");
   document.write("<b style='" + StileR4 + "'><b style='" + StileRec4 + "'></b></b>");
   document.write("<b style='" + StileR3 + "'><b style='" + StileRec3 + "'></b></b>");
   document.write("<b style='" + StileR2 + "'><b style='" + StileRec2 + "'></b></b>");
   document.write("<b style='" + StileR1 + "'></b>");
   document.write("</b>");
}

function LeggiApplication(application_name)
{
   /////////////////////////////////////////////////
   //legge una variabile di sessione da javascript//
   /////////////////////////////////////////////////
   
   ret = ajaxpage("/common/funzioni_ajax.asp?Tipo=LeggiApplication&ApplicationName="+application_name, undefined, false);
   return ret;
}

function VbCrLf()
{
   return String.fromCharCode("13") + String.fromCharCode("10");
}

function SessionAbandon()
{
   /////////////////////////////////////////////////////////////
   //Tenta di forzare un Session.Abandon tramite chiamata ajax//
   /////////////////////////////////////////////////////////////
   
   ret = ajaxpage("/common/funzioni_ajax.asp?Tipo=AbbandonaSession", undefined, false);
   //return ret;
}

function CreaPopup(nome, view, modo, sigla, cod, siglacont, table, retv, condsupp, formatting, samewindow)
{
   if(sigla != ""){ sigla = "&sigla=" + sigla; }
   if(cod != ""){ cod = "&cod=" + cod; }
   if(siglacont != ""){ siglacont = "&siglacont=" + siglacont; }
   if(condsupp == null || condsupp == ""){ condsupp = ""; } else { condsupp = "&csup=" + condsupp; }
   if(formatting == null){ formatting = ""; } else { formatting = "&f=" + encodeURIComponent(formatting); }
   if(samewindow == null) { samewindow = false; }
   
   s = nome + "?View="+view+"&modo="+modo+sigla+cod+siglacont+"&table="+table+"&retv="+retv+condsupp+formatting;
   //alert(s);
   
   if(document.getElementById("db_log") != null) { document.getElementById("db_log").innerHTML = s; }
   if(!samewindow)
   {
      if(modo == "icustomize")
      {
         ret = window.showModalDialog(s, '','dialogHeight:768px;dialogWidth:1024px;status:yes;');
      }
      else
      {
         ret = window.showModalDialog(s, '','dialogHeight:600px;dialogWidth:700px;status:yes;');
      }
      return ret;
   }
   else
   {
      location.href = s;
   }
}

function Capitalizza(stringa)
{
   return ajaxpage("/common/funzioni_ajax.asp?Tipo=Capitalizza&Stringa="+stringa, undefined, false);
}

function ArrotondaDiv(div_id, testo, borderColor, backColor, customStyle)
{
   //controllo sul testo
   if(testo == null) 
   { 
      testo = document.getElementById(div_id).innerHTML; 
   }
   //controllo sul bordo
   if(borderColor == null || borderColor == "") 
   { 
      borderColor = "transparent";
   }
   else
   {
      //se passo solo il colore, applico un bordo di 1px
      if(borderColor.substr(0, 1) == "#")
      {
         colore       = borderColor;
         borderColor  = "1px solid " + borderColor;
         nBorder      = 1;
         nBorderMedio = 2;
         borderMedio  = nBorderMedio + "px solid " + colore;
      }
      else
      {
         //determino il bordo (numerico)
         nBorder = parseInt(borderColor.substr(0, 1));
         colore  = borderColor.substr(borderColor.indexOf("#")+1);
         nBorderMedio = nBorder * 2;
         borderMedio  = nBorderMedio + "px solid " + colore;
      }
   }
   //controllo sullo sfondo
   if(backColor == null || backColor == "") 
   { 
      backColor   = "transparent";
   }
   //controllo su stili personalizzati
   if(customStyle == null) 
   { 
      customStyle = "";
   }
   
   if(parseInt(document.getElementById(div_id).clientHeight) != 0)
   {
      inner_height = document.getElementById(div_id).clientHeight - (nBorder * 6) + "px";
   }
   else
   {
      inner_height = "90%";
   }
   
   s =    "<div style='width:100%; height:" + nBorder + "px; border:" + borderColor + "; margin-left:" + (4 * nBorder) + "px; margin-right:" + (4 * nBorder) + "px; overflow-y:hidden;'>" + VbCrLf()
     +    "</div>" + VbCrLf()
     +    "<div style='width:100%; height:" + nBorder + "px; border-left:" + borderMedio + "; border-right:" + borderMedio + "; margin-left:" + (2 * nBorder) + "px; margin-right:" + (2 * nBorder) + "px; overflow-y:hidden; background-color:" + backColor + ";'>" + VbCrLf()
     +    "</div>" + VbCrLf()
     +    "<div style='width:100%; height:" + nBorder + "px; border-left:" + borderColor + "; border-right:" + borderColor + "; margin-left:" + nBorder + "px; margin-right:" + nBorder + "px; overflow-y:hidden; background-color:" + backColor + ";'>" + VbCrLf()
     +    "</div>" + VbCrLf()
     +    "<div style='width:100%; height:" + inner_height + "; border-left:" + borderColor + "; border-right:" + borderColor + "; background-color:" + backColor + "; " + customStyle + " '>" + VbCrLf()
     +       testo + VbCrLf()
     +    "</div>" + VbCrLf()
     +    "<div style='width:100%; height:" + nBorder + "px; border-left:" + borderColor + "; border-right:" + borderColor + "; margin-left:" + nBorder + "px; margin-right:" + nBorder + "px; overflow-y:hidden; background-color:" + backColor + ";'>" + VbCrLf()
     +    "</div>" + VbCrLf()
     +    "<div style='width:100%; height:" + nBorder + "px; border-left:" + borderMedio + "; border-right:" + borderMedio + "; margin-left:" + (2 * nBorder) + "px; margin-right:" + (2 * nBorder) + "px; overflow-y:hidden; background-color:" + backColor + ";'>" + VbCrLf()
     +    "</div>" + VbCrLf()
     +    "<div style='width:100%; height:" + nBorder + "px; border:" + borderColor + "; margin-left:" + (4 * nBorder) + "px; margin-right:" + (4 * nBorder) + "px; overflow-y:hidden;'>" + VbCrLf()
     +    "</div>" + VbCrLf();
     //alert(s);
     clipboardData.setData("Text", s);
     document.getElementById(div_id).innerHTML  = s;
}

function GetStile()
{
   /////////////////////////////////////////////////
   //Lista nozze - determina lo stile da applicare//
   /////////////////////////////////////////////////
   
   stili = top.Top.document.getElementsByName("provaSB");
   
   for(i=0; i<stili.length; i++)
   {
      if(stili[i].checked)
      {
         stile = stili[i].value;
      }
   }
   
   return stile;
}

function KnowIds(domEv)
{
   /////////////////////////////////////////////////////////////
   //DEBUG: con una combinazione di tasti di tastiera e mouse,//
   //ottengo l'id del campo su cui ho cliccato                //
   /////////////////////////////////////////////////////////////
   
   if(domEv.altKey && domEv.ctrlKey && domEv.shiftKey && domEv.button == 2)
   {
      //alert(domEv.srcElement.id);
      objid    = domEv.srcElement.id;
      objname  = domEv.srcElement.name;
      objvalue = domEv.srcElement.value;
      objtag   = domEv.srcElement.tagName;
      objihtml = domEv.srcElement.innerHTML;
      if(objid != null || objid != undefined)
      {
         if(confirm("id: [" + objid + "]\nname: [" + objname + "]\nvalue: [" + objvalue + "]\ntag: [" + objtag+ "]\ninner html: [" + objihtml +"]\n\nCopiare il messaggio nel clipboard?"))
         {
            clipboardData.setData("Text", "id: [" + objid + "]\nname: [" + objname + "]\nvalue: [" + objvalue + "]\ntag: [" + objtag+ "]\ninner html: [" + objihtml +"]");
         }
      }
   }
}

function GetBrowser()
{
   nome = "";
   versione = -1;
   
   if(navigator.appName == "Netscape" && navigator.userAgent.indexOf("Firefox") >= 0)
   {
      //firefox
      nome = "FF";
      versione = navigator.userAgent.substr(navigator.userAgent.indexOf("Firefox")+8, 1);
   }
   else if(navigator.appName == "Microsoft Internet Explorer")
   {
      //IE
      nome = "IE";
      if(navigator.appVersion.indexOf("MSIE 7.0") >= 0)
      {
         versione = "7";
      }
      else if(navigator.appVersion.indexOf("MSIE 6.0") >= 0)
      {
         versione = "6";
      }
   }
   
   vRet = new Array(nome, versione);
   return vRet;
}
 
 
function AdattaImmagine(_img, _pnode)
{
   //attiva - disattiva il debug
   fdebug = false;
   fdebug = true;
   
   //se il contenitore non è passato, prendo il nodo padre
   if(_pnode == null)
   {
      _pnode = _img.parentNode;
   }
   
   //base ed altezza di immagine e contenitore
   imgH = _img.clientHeight;
   imgW = _img.clientWidth;
   pnH  = _pnode.clientHeight;
   pnW  = _pnode.clientWidth;
   if(fdebug)
   {
      alert("H img: " + imgH + "\nW img: " + imgW + "\nH div: " + pnH + "\nW div: " + pnW);
   }
   
   //rapporto base/altezza di immagine e contenitore
   rapp_img = imgH / imgW;
   rapp_pn  = pnH / pnW;
   if(fdebug)
   {
      alert("rapp_img: " + rapp_img + "\nrapp_pn: " + rapp_pn);
   }
   
   //determinazione del tipo di adattamento / centratura
   centra_H = false;
   centra_W = false;
   if(rapp_pn < 1)
   {
      //contenitore basso e largo
      if(rapp_img < rapp_pn)
      {
         centra_H = true;
      }
      else
      {
         centra_W = true;
      }
   }
   else if(rapp_pn > 1)
   {
      //contenitore alto e stretto
      if(rapp_img > rapp_pn)
      {
         centra_W = true;
      }
      else
      {
         centra_H = true;
      }
   }
   else
   {
      //contenitore quadrato
      if(rapp_img > rapp_pn)
      {
         centra_W = true;
      }
      else
      {
         centra_H = false;
      }
   }
   
   //applicazione dell'adattamento / centratura
   _img.style.position = "absolute";
   if(centra_W)
   {
      _img.style.height = pnH;
      _img.style.width  = pnH / rapp_img;
      _img.style.left   = Math.abs(pnW - parseInt(_img.style.width)) / 2;
      _img.style.top    = 0;
   }
   else
   {
      _img.style.left   = 0;
      _img.style.width  = pnW;
      _img.style.height = rapp_img * pnW;
      _img.style.top    = Math.abs(pnH - parseInt(_img.style.height)) / 2;
   }
   if(fdebug)
   {
      alert("newwidth: " + _img.style.width + "\nnewheight: " + _img.style.height + "\nnewtop: " + _img.style.top + "\nnewleft: " + _img.style.left);
   }
}

function ScrollTableCB()
{
   fDebug = false;
   //fDebug = true;
   
   if(GetBrowser()[0] == "FF")
   {
      tab = document.getElementsByTagName("table");
      if(fDebug)
      {
         alert((tab.length+1) + " tabelle trovate");
      }
      
      for(i=0; i<tab.length; i++)
      {
         if(tab[i].className.indexOf("table-grid") >= 0)
         {
            /*
            ths = tab[i].getElementsByTagName("th");
            if(fDebug)
            {
               alert((ths.length+1) + " colonne d'intestazione trovate");
            }
            
            for(j=0; j<ths.length; j++)
            {
               ths[j].style.top = ths[j].parentNode.parentNode.parentNode.parentNode.scrollTop - 1;
            }
            
            if(fDebug)
            {
               alert("top: " + (ths[0].parentNode.parentNode.parentNode.parentNode.scrollTop - 1));
            }*/
            /*tab[i].parentNode.onscroll = function()
                              {
                                 ths = this.getElementsByTagName("th");
                                 
                                 for(j=0; j<ths.length; j++)
                                 {
                                    ths[j].style.top = this.scrollTop - 1;
                                 }
                              }*/
         }
      }
   }
}

function ImpostaClipboard(testo)
{
   clipboardData.setData("Text", testo);
}

function SessionDict(nome, operazione, colonna, valore)
{
   if(colonna == null) { colonna = ""; }
   if(valore  == null) { valore  = ""; }
   
   retdict = ajaxpage("/common/funzioni_ajax.asp?Tipo=GestisciSessionDict&Nome="+nome+"&Operazione="+operazione+"&Colonna="+colonna+"&Valore="+valore, undefined, false);
   if(operazione == "Read")
   {
      return retdict;
   }
   //alert(retdict);
}

function escapeHTMLEncode(str) 
{
   var div = document.createElement("div");
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
}

function ConfirmCustom(testo, array_bts, css, specifiche, titolo)
{
   if(css        == null) { css        = ""; }
   if(specifiche == null) { specifiche = ""; }
   if(titolo     == null) { titolo     = ""; }
   
   //impostazione array contenente testo e buttons
   var array_params = new Array();
   array_params[0] = testo;
   for(i=0; i<array_bts.length; i++)
   {
      array_params[i+1] = array_bts[i];
   }
   
   ret = window.showModalDialog("/Confirm_CustomBts.asp?Css="+css+"&Specifiche="+specifiche+"&Titolo="+encodeURIComponent(titolo), array_params, specifiche);
   return ret;
}

function SPElettrolama(codice)
{
   ////////////////////////////////////////////////////////////////
   //Apre il popup della scheda prodotto di Elettrolama.         //
   //Realizzata per le ricerche articolo fatte con l'XBrowser    //
   //per ovviare alla mancanza di spazio nel campo dedicato alla //
   //scheda prodotto in WWWArticoli.                             //
   ////////////////////////////////////////////////////////////////
   
   ElePassword = trim(LeggiApplication("ElePassword"));
   Rivenditore = trim(LeggiApplication("Rivenditore"));
      
   if(ElePassword != "" && Rivenditore != "")
   {
      link = "http://www.elettrorama.com/b2b/query_risultati_scheda_tecnica.php?ele_associato=Sede&ele_password=" + ElePassword + "&rivenditore=" + Rivenditore + "&univoco_vendor=" + codice;
      window.open(link,'_blank','height=700,width=800,left=100,top=10,scrollbars=yes');
   }
}

function JsDecode(stringa)
{
   stringa = unescape(stringa);
   stringa = stringa.replace(/\r\n/g,"\n");
	var utftext = "";

	for (var n = 0; n < stringa.length; n++) {

		var c = stringa.charCodeAt(n);

		if (c < 128) {
			utftext += String.fromCharCode(c);
		}
		else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		}
		else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}

	}

	return utftext;

}

function HTMLEncodeDecode(stringa)
{
   var el = document.createElement("div"); 
   el.innerText = stringa; 
   s = el.innerHTML; 
   delete el; 
   return s;
}

function HTMLDecode(stringa)
{
   var el = document.createElement("div"); 
   el.innerHTML = stringa; 
   s = el.innerText; 
   delete el; 
   return s;
}

function SalvaHistory()
{
   crono = LeggiSession("History");
   
   if(crono == "")
   {
      SettaSession("History", location.href);
      //alert(location.href);
   }
   else
   {
      vcrono = crono.split("|");
      trovato = false;
      for(i=0; i<vcrono.length; i++)
      {
         if(vcrono[i] == location.href)
         {
            trovato = true;
            break;
         }
      }
      
      if(!trovato)
      {
         SettaSession("History", crono + "|" + location.href);
      }
      //alert(crono + "|" + location.href);
   }
}

function TornaIndietro()
{
   document.body.onunload = function(){ return; }
   crono = LeggiSession("History");
   if(crono == "") 
   { 
      history.go(-1);
      return; 
   }
   
   vcrono = crono.split("|");
   //alert(crono + "\nLength:" + vcrono.length);
   if(vcrono.length == 1)
   {
      location.href = vcrono[0];
   }
   else
   {
      newval = "";
      sep    = "";
      for(i=0; i<vcrono.length-1; i++)
      {
         newval = newval + sep + vcrono[i];
         sep = "|";
      }
      
      SettaSession("History", newval);
      location.href = vcrono[vcrono.length-1];
   }
}

function Sleep(msec, debugmode)
{
   _Return_Sleep = ajaxpage("/common/Sleep.aspx?MSec="+msec, undefined, false);
   if(debugmode != null)
   {
      return _Return_Sleep;
   }
}