// menu v1 site behaviors, Mike Foster, Cross-Browser.com

// Frame breaker

if (top.location != document.location) top.location = document.location;

// Page Object : costruttore

//variabile ke rappresenta se una pagina è la home o una pagina interna
var interna = false;
var xDivContents = new Array();
var xSoloTesto;
links_arr        = "global_testo.css";
links_arr2       = "global_zoom.css";
links_arr3       = "global_contrasto.css";
links_label_arr  = "vers. testuale";

function xPage()
{
  // Properties
  this.left = true;
  // Methods

} // end xPage

//variabile ke segna se il div elastico è in percentuale o di dimensione fissa
var newsperc = true;

function vaiaPagina(l) {
		top.location.href = l;
}

function vaiaPaginaIF(l) {
	top.location.href = l;
}

function tierMenu(index) {
  var isW3C = false;
  var isNS = false;
  var isIE = false;
  if (document.layers) {  // NS 4 DOM
    isNS = true;
  }
  else if (document.all && !document.getElementById) { // IE 4 DOM
    isIE = true;
  }
  else if (document.getElementById) { // W3C standards-compliant DOM
    isW3C = true;
  }
  if (isW3C) {
    isNS = (navigator.appVersion.charAt(0)>=4 && (navigator.appName).indexOf("Netscape") != -1);
    isIE = (navigator.appVersion.charAt(0)>=4 && (navigator.appVersion).indexOf("MSIE") != -1);
  }
   var divName='menu'+index; //DIV ID
   var imName='img'+index; //IMG ID
   if (isW3C == true) { // W3C standards-compliant DOM
      if (document.getElementById(divName).style.display == 'none')
      {
         document.getElementById(imName).src = '/como_files/images/interfaccia/icone/meno.gif';
      }
      else
      {
         document.getElementById(imName).src = '/como_files/images/interfaccia/icone/piu.gif';
      }

      if (document.getElementById(divName).style.display == 'none')
      {
         document.getElementById(divName).style.display = 'block';
      }
      else
      {
         document.getElementById(divName).style.display = 'none';
      }
   }
}

function textMod (e)
{
  xChangeFontColor(e, '');
  e.value = '';
}

function debug (st)
{
  //se abbiamo una casella di testo dentro un form "mod" questo fa da feedback
  document.mod.feedback.value= st;
}

// Collapsible elements
function clpsInit(parentId, bMin, rollOutC, rollOverC, selImg)
{
  //inizializzazione del menu
  var h, i, c, tempC, aL;
  var aC = new Array();
  var aH = xGetElementsByTagName('H1', xGetElementById(parentId));
  for (var t = 0; t < 7; t++) {
    tempC = xGetElementsByClassName('collapsible' + t, xGetElementById(parentId));
    //aL = xGetElementsByClassName('sel', tempC[0], 'LI'); //xGetElementsByTagName('LI', tempC[0])
    //if (aL.length > 0)
    aC[t] = tempC[0];
  }
  //alert(aC.length);

  //assegna a ogni elemento h1 del menu le azioni del mouse e i colori di rollover e rollout
  for (i = 0; i < aC.length; ++i) {
    h = aH[i]; // sTag element (trigger)
    c = aC[i]; // collapsible element (target)
    var aI = xGetElementsByTagName('IMG', h);

    if (h && c) {

      h.idMenu = i;
      if (aI[0])
      {
        h.srcRestore = aI[0].src;
        h.srcSel = selImg;
      }
      v_usercss   = getCookie("css_style");
      h.onmouseover = clpsOnMouseover;
      h.onmouseout = clpsOnMouseout;
      h.clpsRolloutColor = rollOutC;
      h.clpsRolloverColor = rollOverC;
      h.clpsEle = c;
      h.collapsed = !bMin;
      h.onclick = clpsOnClick;
    }
  }
  //chiudo tutto il menu
  chiudiTutto(parentId);
  //se c'è un nodo aperto lo apro
  var elOp = findOpen(parentId);
  //guarda se c'è un elemento ke deve essere aperto onLoad
  if (elOp)
  {
    interna = false;
    //rimuovo le proprietà appena messe ke lo rendevano un link
    elOp.onmouseover = "";
    elOp.onmouseout = "";
    elOp.onclick = "";
    elOp.style.cursor = 'default';
    clpsDoClick(elOp, true);
    interna = true;
  }
}

function findOpen (parentId)
{
 //trova l'elemento di classe 'sel' nel menu
 //selezionato di secondo livello
  var aH = xGetElementsByClassName('sel', xGetElementById(parentId), 'LI');
  var aK = xGetElementById('h1sel');

  h = aH[0];
  if (h) {
    var xP = xParent(h,true);
    var selectedclass = xP.className;
    xP = xParent(xP,true);
    xP = xParent(xP,true);
    xP = xGetElementsByClassName(selectedclass, xP, 'H1');
    interna = true;
    return xP[0];
  } else if (aK){
    interna = true;
    return (aK);
  }
}

function chiudiTutto(parentId)
{
  //chiude tutti gli elementi del menu
  var h, i, c, tempC;
  var aC = new Array();
  var aH = xGetElementsByTagName('H1', xGetElementById(parentId));
  for (var t = 0; t < 7; t++) {
    tempC = xGetElementsByClassName('collapsible' + t, xGetElementById(parentId));
    aC[t] = tempC[0];
  }
  for (i = 0; i < aC.length; ++i) {
    h = aH[i]; // sTag element (trigger)
    c = aC[i]; // collapsible element (target)
    //esegue l'azione solo se esiste anke l'elemento collapsible
    if (h && c && h != findOpen(parentId)) {
      clpsDoClick(h, false);
      //switchImage(h);
    }
  }
}

function clpsOnClick()
{
  //l'azione onClick assegnata a ogni h1 ke c'è nel menu
  var xP = xParent(this,true);
  //se l'elemento è chiuso, prima di tutto chiude tutti gli altri elementi
  if (this.collapsed) chiudiTutto(xP);
  //parte la funzione di click
  clpsDoClick(this, this.collapsed);
  //cambia l'immagine a lato
  //switchImage(this);
  //resizeContMenu (xParent(xParent(xParent(xP, true), true), true));
}
function clpsDoClick(thisEle, bShow)
{
  var d, t, w, h;
  //cambia il title del tooltip dell'h1 e la visualizzazione
  v_usercss   = getCookie("css_style");
  if (!interna && !(v_usercss == links_arr))// || v_usercss == links_arr2 || v_usercss == links_arr3))
  {
    if (bShow) { // show
      d = 'block';
      t = 'Chiudi';
      if (!xSoloTesto || (v_usercss == links_arr2 || v_usercss == links_arr3))
	xBackground (thisEle, "#697694", "");
    }
    else {                // hide
      d = 'none';
      t = 'Apri';
      if (!xSoloTesto || (v_usercss == links_arr2 || v_usercss == links_arr3))
        xBackground (thisEle, "", "");
    }
    if (thisEle.tagName == 'H1') {
      t += ' sezione'
      thisEle.clpsEle.style.display = d;
      xTop(thisEle.clpsEle, 0);
      if (xFF1)
        xLeft (thisEle.clpsEle, -128);
      if (xNN7)
        xLeft (thisEle.clpsEle, -128);
    }
  thisEle.setAttribute('title', t);
  thisEle.collapsed = !bShow;
  }
    //resizeContMenu();
}
function clpsOnMouseover()
{
  //da semplicemente un colore di rollover al campo
  if (this.tagName == 'H1') {
    var aC = xGetElementsByTagName('a', this);
    xChangeFontColor(aC[0], this.clpsRolloverColor);
  }
}

function clpsOnMouseout()
{
  //da un colore di rollout al campo
  if (this.tagName == 'H1') {
    var aC = xGetElementsByTagName('a', this);
    xChangeFontColor(aC[0], this.clpsRolloutColor);
  }
}

/****** start css ****************/

//c_css_folder = "/como_files/css/";
c_js_folder  = "script/";


function mustOpenMenu ()
{
  v_usercss   = getCookie("css_style");
  return (
          (v_usercss.indexOf("_contrasto.css") == -1 )
  	    &&
  	    (v_usercss.indexOf("_testo.css") == -1)
         );

}
function changeStyle(p_css_path)
{
 if(p_css_path == "classica")
   removePersistentCookie("css_style");
 else
   setPersistentCookie("css_style", p_css_path,30);

 document.location.href = document.location;
}
var xVersion='3.15.2',xFF1,xNN7, xNN4,xOp7,xOp5or6,xIE4Up,xIE4,xIE5,xMac,xUA=navigator.userAgent.toLowerCase();

v_br_version = navigator.userAgent.toLowerCase();
br_NS7    = xNN7;
br_OPERA  = xOp7;
br_IE6 = true;
br_IE5 = xIE5;
//br_MOZZ = false;
br_SAFARI = xMac;
br_FIREFOX = xFF1;
l_showdebug = 'n';


function l_debug (msg)
{
 if(l_showdebug=='y')alert("debug message"+msg);
}

function switchCSS(c_css_folder)
{
 v_usercss = getCookie("css_style");
 if(v_usercss != null && v_usercss != "")
 {
 	l_debug("v_usercss : "+v_usercss);
 	document.write ('<link href="'+c_css_folder+v_usercss+'" rel="stylesheet" type="text/css"  title="default" />');
 }
 else
 {
    l_debug(" explorer 6 ");
    document.write ('<link href="'+c_css_folder+'global.css" rel="stylesheet" type="text/css" title="default" />');
 }
}

function writeHeader() {
  v_usercss = getCookie("css_style");
  if (v_usercss == 'global_testo.css') {
     document.write("<a accesskey=\"T\" href=\"#\" onClick=\"javascript:changeStyle('classica')\">vers. grafica</a>");
     xSoloTesto = true;
   } else {
     xSoloTesto = false;
     document.write("<a accesskey=\"T\" href=\"#\" onClick=\"javascript:changeStyle('global_testo.css')\">vers. testuale</a> | ");
     if (v_usercss == 'global_zoom.css') {
        document.write("<a accesskey=\"I\" href=\"#\" onClick=\"javascript:changeStyle('global.css')\">riduci</a> | ");
     } else {
        document.write("<a accesskey=\"I\" href=\"#\" onClick=\"javascript:changeStyle('global_zoom.css')\">ingrandisci</a> | ");
     }
     if (v_usercss == 'global_contrasto.css') {
        document.write("<a accesskey=\"C\" href=\"#\" onClick=\"javascript:changeStyle('global.css')\">contrasto norm.</a> | ");
     } else {
       document.write("<a accesskey=\"C\" href=\"#\" onClick=\"javascript:changeStyle('global_contrasto.css')\">alto contrasto</a>");
     }
   }
}
/****** stop css ****************/
window.onload = function() {
  MM_preloadImages('/como_files/images/interfaccia/button/b_mappa_on.gif','/como_files/images/bannerlink/ban_stradario_on.gif','/como_files/images/bannerlink/ban_scrivi_on.gif','/como_files/images/bannerlink/ban_urp_on.gif','/como_files/images/bannerlink/ban_sportello_on.gif','/como_files/images/bannerlink/ban_associa_on.gif','/como_files/images/bannerlink/ban_ordini_on.gif','/como_files/images/interfaccia/button/b_cerca_on.gif','/como_files/images/interfaccia/button/b_entra_on.gif','/como_files/images/interfaccia/button/b_registrati_on.gif');
  clpsInit('menujs', false, '', '', '');
}