// forzo bordi arrotondati per le classi "listaTestualeNew" e "listaTestualeBig"
$(document).ready(function () {
    $(".listaTestualeNew").each(function (i) {
        $("li:first-child").addClass("nobordo");
        $(this).prepend('<span class="bor"><img src="files/images/aperturaLista.gif" alt="" /></span>');
        $(this).append('<span class="bor"><img src="files/images/chiusuraLista.gif" alt="" /></span>');
    });

    $(".listaTestualeBig").each(function (i) {
        $("li:first-child").addClass("nobordo");
        $(this).prepend('<span class="bor"><img src="files/images/aperturaListaBig.gif" alt="" /></span>');
        $(this).append('<span class="bor"><img src="files/images/chiusuraListaBig.gif" alt="" /></span>');
    });

});
/* riposizionamento overlay in caso di ridimensionamneto finestra */
$(window).resize(function () {
    if (flagClose == 1) {
        apriOverlay(OLD_xDivOver);
    }
});

// HTML PER PLAYER FLASH
function getFlashHTML(xMovie, xWidth, xHeight, xTitolo) {
    var xSWF = '<object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + xWidth + '" height="' + xHeight + '"';
    if (String(xTitolo) !== 'undefined') { xSWF += 'title="' + xTitolo + '"'; }
    xSWF += '><param name="movie" value="' + xMovie + '" />';
    xSWF += '<param name="quality" value="high" />';
    xSWF += '<param name="wmode" value="opaque" />';
    xSWF += '<param name="swfversion" value="6.0.65.0" />';
    xSWF += '<param name="expressinstall" value="files/Flash/expressInstall.swf" />';
    xSWF += '<!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->';
    xSWF += '<!--[if !IE]>-->';
    xSWF += '<object type="application/x-shockwave-flash" data="' + xMovie + '" width="' + xWidth + '" height="' + xHeight + '">';
    xSWF += '<!--<![endif]-->';
    xSWF += '<param name="quality" value="high" />';
    xSWF += '<param name="wmode" value="opaque" />';
    xSWF += '<param name="swfversion" value="6.0.65.0" />';
    xSWF += '<param name="expressinstall" value="files/Flash/expressInstall.swf" />';
    xSWF += '<div class="no-flash">Il contenuto di questa pagine richiede l\'utilizzo di una versione aggiornata di Adobe Flash Player.';
    xSWF += ' Clicca sull\'icona per scaricarlo.<br /><a href="http://www.adobe.com/go/getflashplayer">';
    xSWF += '<img src="files/images/get_adobe_flash_player.png" alt="Get Adobe Flash player" width="158" height="39" /></a></div>';
    xSWF += '<!--[if !IE]>-->';
    xSWF += '</object>';
    xSWF += '<!--<![endif]-->';
    xSWF += '</object>';
    return xSWF;
}

/* convenzioni (luca) */
function convenzioni_SwapAutoMoto(tipo) {
    if (tipo == "auto" && $("#tipo").val() == "moto") {
        $('#autoOFF').addClass('conv-hide');
        $('#autoON').removeClass('conv-hide');
        $("#motoOFF").removeClass('conv-hide');
        $("#motoON").addClass('conv-hide');
        $("#tipo").val('auto');
    } else if (tipo == "moto" && $("#tipo").val() == "auto") {
        $('#autoON').addClass('conv-hide');
        $('#autoOFF').removeClass('conv-hide');
        $("#motoON").removeClass('conv-hide');
        $("#motoOFF").addClass('conv-hide');
        $("#tipo").val('moto');
    }
}
/* fine convenzioni */

// apre un indirizzo web
function gotoURL(pag) {
    document.location = pag;
}

/* overlay home (luca) */
/* overlay home (luca) */
// I° prametro= nome del div da utilizzare epr overlay, 
// II° parametro= stringa contenente eventuali nomi dei div da nascondere durante overlay (nome1,nome2,...)
var flagClose = 0;
var OLD_xDivOver = "";
function apriOverlay(xDivOver, xNascondi) {
    if (xNascondi) {
        var aNas = xNascondi.split(",");
        for (var x = 0; x < aNas.length; x++) {
            $("#" + aNas[x]).css("z-index", 3000 + Number(x));
        }
    }
    var winLeft = ($(window).width() / 2) - ($("#" + xDivOver).width() / 2);
    var winTop = (($(window).height() - $("#" + xDivOver).height()) / 2) + $(document).scrollTop();
    var winH = $(document).height();
    var winW = $(document).width();
    $("#scudoPagina").css({ height: winH, width: winW }).show().fadeTo('fast', 0.4);
    $("#" + xDivOver).css({ top: winTop, left: winLeft }).fadeIn("slow");
    flagClose = 1;
    OLD_xDivOver = xDivOver;
}
function chiudiOverlay(xDivOver, xRipristina) {
    $("#" + xDivOver).fadeOut("slow");
    $("#scudoPagina").fadeOut("fast");
    flagClose = 0;
}
// I°   prametro= nome del div da utilizzare epr overlay, 
// II°  prametro= html contenente swf di xDivOver
// III° prametro= titolo che appare al top di xDivOver
// IV°  parametro= stringa contenente eventuali nomi dei div da nascondere durante overlay (nome1,nome2,...)
function apriOverlaySWF(xDivOver, xHTML, xTit, xNascondi) {
    if (xNascondi) {
        var aNas = xNascondi.split(",");
        for (var x = 0; x < aNas.length; x++) {
            $("#" + aNas[x]).css("z-index", 3000 + Number(x));
        }
    }
    if (xTit) {
        $("#video-top").html(xTit);
    }
    var winLeft = ($(window).width() / 2) - ($("#" + xDivOver).width() / 2);
    var winTop = (($(window).height() - $("#" + xDivOver).height()) / 2) + $(document).scrollTop();
    var winH = $(document).height();
    var winW = $(document).width();
    //alert($("#scudoPagina").css("height"));
    $("#scudoPagina").css({ height: winH, width: winW }).show().fadeTo('fast', 0.4);
    $("#" + xDivOver).css({ top: winTop, left: winLeft }).fadeIn("slow", function () { $("#video-cx").html(xHTML) });
    flagClose = 1;
    OLD_xDivOver = xDivOver;
    //apriOverlay(xDivOver);
    //$("#video-cx").html(xHTML);

}
// I°   prametro= nome del div da utilizzare epr overlay, 
// II°  parametro= stringa contenente eventuali nomi dei div da ripristinare dopo averli nascosti durante overlay (nome1,nome2,...)
function chiudiOverlaySWF(xDivOver, xRipristina) {
    $("#video-cx").html('');
    $("#" + xDivOver).fadeOut("slow");
    $("#scudoPagina").fadeOut("fast");
    flagClose = 0;
}
/* fine overlay */

// SCROLL ORIZZONTALE AUTO (luca)
var flagFX = 0;
function xScroll(xDir) {
    if (flagFX == 0) {
        flagFX = 1;
        var xStep = 535; // step dello scroll corrispondente alla larghezza di ogni fotogramma
        var xLimSX = -535; // limite sinistro del nastro (=attributo left del css di boxH-scroll)
        var xLimDX = -3745; // limite destro del nastro (= larghezza totale nastro - xStep)
        var xLeft = parseFloat($("#boxH-scroll").css("left"));
        if (xDir == 'dx') {
            if (xLeft == xLimSX) {
                $('#boxH-scroll').css("left", xLimDX);
                xLeft = xLimDX + xStep;
            } else {
                xLeft += xStep;
            }
        } else if (!xDir || xDir == 'sx') {
            if (xLeft == xLimDX) {
                $('#boxH-scroll').css("left", xLimSX);
                xLeft = xLimSX - xStep;
            } else {
                xLeft -= xStep;
            }
        }
        $("#boxH-scroll").animate({ left: xLeft }, "slow", function () { flagFX = 0; });
    }
}
// fine scroll orizz

// auto slide tasti (luca)
var xAutoSlide = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
function xDivSlide(xInd, xMin, xMax, xGrp) {
    if (xAutoSlide[xInd] == 0) {
        $("#AS-" + xInd).slideDown("slow");
        $("#AI-" + xInd).attr("src", "files/images/b_contrai.gif");
        xAutoSlide[xInd] = 1;
    } else {
        $("#AS-" + xInd).slideUp("slow");
        $("#AI-" + xInd).attr("src", "files/images/b_espandi.gif");
        xAutoSlide[xInd] = 0;
    }
    var xTot = 0;
    var xDif = xMax - xMin + 1;
    for (var x = xMin; x <= xMax; x++) {
        xTot += xAutoSlide[x];
    }
    if (xTot == xDif) {
        xAZ[xGrp] = "C";
        $("#espcon" + xGrp).html('CONTRAI TUTTI <img src="files/images/b_contrai.gif" alt="espandi/contrai tutte le informazioni" />');
    } else if (xTot == 0) {
        xAZ[xGrp] = "E";
        $("#espcon" + xGrp).html('ESPANDI TUTTI <img src="files/images/b_espandi.gif" alt="espandi/contrai tutte le informazioni" />');
    }
}
var xAZ = new Array("E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E");
function xDivSlideALL(nmin, nmax, ind) {
    if (xAZ[ind] == 'E') {
        for (var c = nmin; c <= nmax; c++) {
            $("#AS-" + c).slideDown("slow");
            $("#AI-" + c).attr("src", "files/images/b_contrai.gif");
            xAutoSlide[c] = 1;
        }
        xAZ[ind] = "C";
        $("#espcon" + ind).html('CONTRAI TUTTI <img src="files/images/b_contrai.gif" alt="espandi/contrai tutte le informazioni" />');

    } else {
        for (var c = nmin; c <= nmax; c++) {
            $("#AS-" + c).slideUp("slow");
            $("#AI-" + c).attr("src", "files/images/b_espandi.gif");
            xAutoSlide[c] = 0;
        }
        xAZ[ind] = "E";
        $("#espcon" + ind).html('ESPANDI TUTTI <img src="files/images/b_espandi.gif" alt="espandi/contrai tutte le informazioni" />');

    }
}
// fine slide tasti

var objPopup = "";
var imgInfo = "";
var _offsetX = 0;
var _offsetY = 0;


function selectRow(row, divName) {
    if ((!divName && objPopup) || (divName && objPopup && objPopup != divName)) {
        closeNewPopupArea(objPopup)
    }

    var qxFormTables = document.getElementsByTagName("table");

    for (var t = 0; t < qxFormTables.length; t++) {
        var qxFormTabl = qxFormTables[t];
        if (qxFormTabl.className == "qxFormTable" || qxFormTabl.className == "qxRiepilogoTable") {
            //var tBody = row.parentNode;
            var tBody = qxFormTabl.tBodies[0];
            for (var i = 0; i < tBody.rows.length; i++) {
                tBody.rows[i].style.backgroundColor = "#ffffff";
            }
            row.style.backgroundColor = "#e8ebf1";
        }
    }
}


function selectRowById(rowId, divName) {
    selectRow(document.getElementById(rowId), divName);
}



function newPopupArea(event, divName) {
    if (objPopup && objPopup == divName) {
        closeNewPopupArea(objPopup)
    } else {
        if (objPopup) {
            closeNewPopupArea(objPopup)
        }
        objPopup = divName;
        PopupArea(event, divName);

        if (event.srcElement != null)
            imgInfo = event.srcElement;
        else
            imgInfo = event.currentTarget;

        _offsetX = -10;
        _offsetY = 5;
    }
}


function closeNewPopupArea(divName) {
    jsAreaClose(divName)
    objPopup = "";
    imgInfo = "";
    _offsetX = 0;
    _offsetY = 0;
}



function newIndirectPopupArea(e, areaId, offsetX, offsetY) {
    if (objPopup) {
        closeNewPopupArea(objPopup)
    }

    try {
        var theId;

        if (e.srcElement != null) {
            theId = e.srcElement.id;
            imgInfo = e.srcElement;
        } else {
            theId = e.currentTarget.id;
            imgInfo = e.currentTarget;
        }

        _offsetX = offsetX;
        _offsetY = offsetY;

        var theElement = document.getElementById(theId);

        var theX = findPosX(theElement);

        if (theX != '' && theX != null)
            theX = theX + theElement.offsetWidth + 5;   //  Get control width plus an extra offset

        var theY = findPosY(theElement);

        var iframe = document.getElementById("HelpShim");

        if (iframe.style.display == "none") {
            if (document.layers) {
                posx = theX;    //  e.pageX;
                posy = theY;    //  e.pageY;
                xMousePosMax = window.innerWidth + window.pageXOffset;
                yMousePosMax = window.innerHeight + window.pageYOffset;
            }
            else
                if (document.all) {
                    posx = theX + document.body.scrollLeft;      //   window.event.x + document.documentElement.scrollLeft;
                    posy = theY + document.body.scrollTop;       //   window.event.y + document.documentElement.scrollTop;
                    xMousePosMax = document.body.clientWidth + document.body.scrollLeft;
                    yMousePosMax = document.body.clientHeight + document.body.scrollTop;
                }
                else {
                    posx = theX; //   e.pageX;
                    posy = theY; //   e.pageY;
                    xMousePosMax = window.innerWidth + window.pageXOffset;
                    yMousePosMax = window.innerHeight + window.pageYOffset;
                }

            posx = posx + offsetX;
            posy = posy + offsetY;

            if ((posx * 1) + 309 > xMousePosMax * 1) {
                posx = (xMousePosMax * 1) - 329;
            }

            var area = GetArea(areaId);

            area.popareaup(posx, posy);

            var oBody = document.getElementById(areaId);

            iframe.style.height = oBody.scrollHeight + (oBody.offsetHeight - oBody.clientHeight);
            iframe.style.width = oBody.scrollWidth + (oBody.offsetWidth - oBody.clientWidth) - 20;

            objPopup = areaId;
        }
        else {
            this.document.focus();
        }
    }
    //An error is raised if the IFrame domain != its container's domain
    catch (e) {
        //alert('Error: ' + e.number + '; ' + e.description);
    }
}






function resizeQuixa() {
    moveInfo();
    if (typeof (resizePriv) != "undefined") resizePriv();
}



function moveInfo() {
    if (objPopup) {
        var areaId = objPopup;
        var theElement = imgInfo;

        var theX = findPosX(theElement);
        if (theX != '' && theX != null)
            theX = theX + theElement.offsetWidth + 5;   //  Get control width plus an extra offset

        var theY = findPosY(theElement);

        if (document.layers) {
            posx = theX;    //  e.pageX;
            posy = theY;    //  e.pageY;
            xMousePosMax = window.innerWidth + window.pageXOffset;
            yMousePosMax = window.innerHeight + window.pageYOffset;
        }
        else
            if (document.all) {
                posx = theX + document.body.scrollLeft;      //   window.event.x + document.documentElement.scrollLeft;
                posy = theY + document.body.scrollTop;       //   window.event.y + document.documentElement.scrollTop;
                xMousePosMax = document.body.clientWidth + document.body.scrollLeft;
                yMousePosMax = document.body.clientHeight + document.body.scrollTop;
            }
            else {
                posx = theX; //   e.pageX;
                posy = theY; //   e.pageY;
                xMousePosMax = window.innerWidth + window.pageXOffset;
                yMousePosMax = window.innerHeight + window.pageYOffset;
            }

        posx = posx + _offsetX;
        posy = posy + _offsetY;

        var area = GetArea(areaId);
        area.popareaup(posx, posy);
    }
}




// FUNZIONI PER L'ESPANSIONE E LA CONTRAZIONE DELLE SEZIONI DELLA PAGINA DI RECUPERO PREVENTIVO
var arrSezioniRecuperoPrev = ["sezCaratteristicheVeicolo", "ctl00_ContentPlaceHolderMainArea_SimulatorContentPlaceHolderMainArea1_ucQuoteSave_trTableContr", "ctl00_ctl00_ContentPlaceHolderMain_ContentPlaceHolderMain_SimulatorContentPlaceHolderMain1_ucQuoteSave_trTableContr", "ctl00_ContentPlaceHolderMainArea_SimulatorContentPlaceHolderMainArea1_ucVehicleData_sezCaratteristicheVeicolo", "ctl00_ContentPlaceHolderMainArea_SimulatorContentPlaceHolderMainArea1_ucMotoData_sezCaratteristicheMoto", "ctl00_ctl00_ContentPlaceHolderMain_ContentPlaceHolderMain_SimulatorContentPlaceHolderMain1_ucMotoData_sezCaratteristicheMoto", "sezLocanteVincolante", "sezDatiProprietarioVeicolo", "sezSituazioneAssicurativa", "sezSituazioneAssProp", "sezDatiContrPolizza", "sezDatiPropVeicolo", "sezDatiEnteLocVinc", "sezGaranzModPag", "sezGaranzie1", "blocco1", "blocco2", "blocco3", "blocco4", "blocco5", "blocco6", "blocco7", "blocco8", "blocco9", "blocco10", "blocco11", "blocco12", "blocco13", "blocco14", "blocco15", "blocco16", "blocco17", "blocco18", "blocco19", "blocco20"];

// FUNZIONI PER L'ESPANSIONE E LA CONTRAZIONE DELLE SEZIONI DELLA PAGINA DI RECUPERO PREVENTIVO
//"sezDatiVeicolo",
//var arrSezioniRecuperoPrev = ["sezSituazioneAssicurativa","ctl00_ContentPlaceHolderMainArea_SimulatorContentPlaceHolderMainArea1_ucQuoteSave_trTableContr","sezLocanteVincolante","ctl00_ContentPlaceHolderMainArea_SimulatorContentPlaceHolderMainArea1_ucMotoData_sezCaratteristicheMoto", 						  "sezDatiProprietarioVeicolo","ctl00_ContentPlaceHolderMainArea_SimulatorContentPlaceHolderMainArea1_ucVehicleData_sezCaratteristicheVeicolo","sezGaranzie1"];

function contraiEspandiDiv(idDiv) {

    var div = document.getElementById(idDiv);

    if (div.style.display == "none") {
        //espandiSez(idSez);
        div.style.display = "";
    }
    else {
        ///contraiSez(idSez);
        div.style.display = "none";
    }

}

function contraiEspandi(idSez) {
    var sez;
    var newURL = window.location.href;

    //  20101221 DR
    //if (newURL.toLowerCase().indexOf('/simulator.aspx?recuperar=') != -1 || newURL.toLowerCase().indexOf('_resume.aspx') != -1)
    //{
           
        document.getElementById("img_" + idSez).style.display = "block";       
        sez = document.getElementById(idSez);
        if (!sez) { return; } else

            if (sez.style.display == "none") {
                espandiSez(idSez);
            }
            else {
                contraiSez(idSez);
            }

    //	}
    //	else
    //	{
    //	   // document.getElementById("img_" + idSez).style.display = "none";
    //	}	
}


function espandiSez(idSez) {
    var sez = document.getElementById(idSez);
    if (!sez) return;
    sez.style.display = "";

    var img = document.getElementById("img_" + idSez);
    var srcImg = img.getAttribute("src");
    srcImg = srcImg.replace(/b_espandi.gif/, "b_contrai.gif");
    img.setAttribute("src", srcImg);
}


function contraiSez(idSez) {
    var sez = document.getElementById(idSez);
    if (!sez) return;
    sez.style.display = "none";

    var img = document.getElementById("img_" + idSez);
    var srcImg = img.getAttribute("src");
    srcImg = srcImg.replace(/b_contrai.gif/, "b_espandi.gif");
    img.setAttribute("src", srcImg);
}


function contraiEspandiTutto(exceptVehicle, exceptGarantias) {

    var textAnchor = document.getElementById("a_contraiEspandiTutto");

    var img = document.getElementById("img_contraiEspandiTutto");
    var srcImg = img.getAttribute("src");
    if (srcImg.indexOf("b_espandi.gif") >= 0) {
        srcImg = srcImg.replace(/b_espandi.gif/, "b_contrai.gif");
        img.setAttribute("src", srcImg);

        textAnchor.innerHTML = "Contrai tutte le voci";

        espandiTutto(exceptVehicle, exceptGarantias);
    } else {
        srcImg = srcImg.replace(/b_contrai.gif/, "b_espandi.gif");
        img.setAttribute("src", srcImg);

        textAnchor.innerHTML = "Espandi tutte le voci";

        contraiTutto(exceptVehicle, exceptGarantias);
    }
}


function espandiTutto(exceptVehicle, exceptGarantias) {    //  20091125 DRIBEIRO Correcção (em caso de Leasing...)

    for (var i = 0; i < arrSezioniRecuperoPrev.length; i++) {
        try {
            if (exceptVehicle != null && exceptVehicle && arrSezioniRecuperoPrev[i] == 'sezCaratteristicheVeicolo')
            { }
            else if (exceptGarantias != null && exceptGarantias && arrSezioniRecuperoPrev[i] == 'sezGaranzie1')
            { }
            else
                espandiSez(arrSezioniRecuperoPrev[i]);

        } catch (e) { }
    }
}


function contraiTutto(exceptVehicle, exceptGarantias) {    //  20091125 DRIBEIRO Correcção (em caso de Leasing...)

    for (var i = 0; i < arrSezioniRecuperoPrev.length; i++) {
        try {
            if (exceptVehicle != null && exceptVehicle && arrSezioniRecuperoPrev[i] == 'sezCaratteristicheVeicolo')
            { }
            else if (exceptGarantias != null && exceptGarantias && arrSezioniRecuperoPrev[i] == 'sezGaranzie1')
            { }
            else
                contraiSez(arrSezioniRecuperoPrev[i]);
        } catch (e) { }
    }
}



/*
Yetii - Yetii - Yet (E)Another Tab Interface Implementation
http://www.kminek.pl/lab/yetii/
(c) 2007 Grzegorz Wojcik
It is up to You to leave or remove this copyright notice
---
Slightly modified for IE5.x support by Alessandro Fulciniti - http://www.html.it
*/


function Yetii(obj, active, titoli) {

    this.active = (active) ? active : 1,
	this.titoli = (titoli) ? titoli : "",
	this.timeout = null,
	this.tabclass = 'tab',
	this.activeclass = 'active',

	this.getTabs = function () {

	    var retnode = [];
	    var elem = document.getElementById(obj).childNodes;     //modified for IE 5.x support
	    for (var i = 0; i < elem.length; i++) {
	        if (elem[i].className == this.tabclass) retnode[retnode.length] = elem[i];
	    }

	    return retnode;

	},

	this.links = document.getElementById(obj + '-nav').getElementsByTagName('a'),
	this.tabs = this.getTabs();

    this.show = function (number) {

        for (var i = 0; i < this.tabs.length; i++) {
            this.tabs[i].style.display = ((i + 1) == number) ? 'block' : 'none';
            this.links[i].className = ((i + 1) == number) ? this.activeclass : '';
        }
        if (this.titoli.length > 0) {
            $("#titolopagina").html(this.titoli[number - 1]);
        }

    },

	this.rotate = function (interval) {

	    this.show(this.active);
	    this.active++;

	    if (this.active > this.tabs.length) this.active = 1;

	    var self = this;
	    this.timeout = setTimeout(function () { self.rotate(interval); }, interval * 1000);

	},

	this.init = function (interval) {

	    this.show(this.active);

	    var self = this;
	    for (var i = 0; i < this.links.length; i++) {
	        this.links[i].customindex = i + 1;
	        this.links[i].onclick = function () { if (self.timeout) clearTimeout(self.timeout); self.show(this.customindex); return false; };
	    }

	    if (interval) this.rotate(interval);

	};

};

/* 
FUNZIONE DI APERTURA E CHIUSURA DI UN DIV CON EFFETTO SLIDE
*/
var oldNomeId = "";
function showDivSlide(nomeId) {

    /*$("#div" + oldNomeId).slideUp(); 
	
    oldNomeId = nomeId;
	
    $("#div" + nomeId).slideDown("slow");*/



    if (nomeId == oldNomeId) {
        $("#div" + nomeId).slideToggle("slow");
    } else {
        $("#div" + nomeId).slideToggle("slow");
        $("#div" + oldNomeId).slideToggle("slow");
    }
    oldNomeId = nomeId;



}

/*FUNZIONE SLIDE
function effettoSlide(id) {
$("#" + id).slideToggle("slow");
}*/

/* FUNZIONE DI APERTURA E CHIUSURA DI UN DIV SENZA EFFETTO SLIDE */
var oldDivEx = "";
var oldDivIn = "";

function showDivEx(nomeID) {
    var _obj = document.getElementById("divEx" + nomeID);
    if ((oldDivIn != "")) {
        document.getElementById("divIn" + oldDivIn).style.display = "none";
        oldDivIn = "";
    }

    if ((oldDivEx != "") && (oldDivEx != nomeID)) {
        document.getElementById("divEx" + oldDivEx).style.display = "none";
    }

    oldDivEx = nomeID;

    if (_obj.style.display == "block") {
        _obj.style.display = "none";
    } else {
        _obj.style.display = "block";
    }
}

function showDivIn(nomeID) {
    var _obj = document.getElementById("divIn" + nomeID);

    if ((oldDivIn != "") && (oldDivIn != nomeID)) {
        document.getElementById("divIn" + oldDivIn).style.display = "none";
    }

    oldDivIn = nomeID;

    if (_obj.style.display == "block") {
        _obj.style.display = "none";
    } else {
        _obj.style.display = "block";
    }
}
// FUNZIONE PER LA STAMPA DELLE PAGINE
function printPage(classe) {

    $(".bor").remove();

    //ridefinita la variabile per togliere il punto davanti al nome della classe		
    classe = classe.substr(1);

    var siOption = "toolbar=no,location=no,directories=no,menubar=no,";
    siOption += "scrollbars=auto,width=800,height=600,left=100,top=25";

    var contenutoStampa = "<div class='" + classe + "'>" + $('.' + classe).html() + "</div>";

    var winprint = window.open("", "", siOption);

    winprint.document.open();
    winprint.document.write("<html><head><title>Quixa - Diretta Personale AXA</title><link href='css/printPage.css' rel='stylesheet' type='text/css' /></head><body bgcolor='#FFFFFF' >");


    winprint.document.write("<div class='wrapperHeader'> ");
    winprint.document.write("<div class='header'> ");
    winprint.document.write("<div class='logo'><a href='http://www.quixa.it'><img src='files/images/common/quixaLogo.gif' width='149' height='100' alt='Quixa - Diretta Personale AXA' /></a></div>");
    winprint.document.write("<div class='axaLogo'><a href='http://www.axa-italia.it/' target='_blank'><img src='files/images/common/axaLogo.gif' alt='L\'assicurazione online del Gruppo AXA' width='201' height='26'/></a></div>");


    winprint.document.write("</div>");
    winprint.document.write("</div>");
    winprint.document.write("<div class='wrapperMain'><div class='main'>");
    winprint.document.write(contenutoStampa);
    winprint.document.write("</div></div>");

    winprint.document.write("<div class='clearboth'>&nbsp;</div>");
    winprint.document.write("<div class='link_copyright'>Copyright 2010 © Quixa S.p.A");
    winprint.document.write("</div>");

    winprint.document.write("</body></html>");
    winprint.document.close();
    winprint.print();
    winprint.focus();
    winprint.close();
}
/* FUNZIONE PER APRIRE I BOTTONI DEI PREVENTIVI */
function apriBox() {

    if ($("#boxOneClick").is(":hidden")) {
        $("#boxOneClick").slideDown("fast");
    } else {
        $("#boxOneClick").hide();
    }
}

/* FUNZIONE CHE CONTROLLA I PARAMETRI IMPOSTATI PER VEDERE UNA GOOGLE MAPS*/
function initialize() {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(45.42675374556261, 9.200448989868164), 16);

        var point = new GLatLng(45.42675374556261, 9.200448989868164);
        map.addOverlay(new GMarker(point));

        map.openInfoWindow(map.getCenter(),
		document.createTextNode("Via Muzio detto Attendolo Sforza, 11 - ed.9 (zona Ripamonti) - Milano"));

        map.setMapType(G_NORMAL_MAP);
        map.setUIToDefault();
    }
}

/* INIZIO PER ANCILLARY */
var BRIE = jQuery.browser.msie;

$(document).ready(function () {

});

jQuery.fn.fadeTo = function (speed, to, callback) {
    return this.animate({ opacity: to }, speed, function () {
        if (to == 1 && BRIE)
            this.style.removeAttribute('filter');
        if (jQuery.isFunction(callback))
            callback();
    });
};

var ASTATIBT = new Array();
var ASTATI = new Array();
var XOLD = 0;
function xApri(ID, IMG) {

    var indbt = IMG.substr(4);
    if (ASTATIBT[indbt] != 2) {
        var xdiv = "#" + ID;
        var ind = ID.substr(2);
        if (!ASTATI[ind]) {
            ASTATI[ind] = 1;
        }
        if (ID.substr(0, 1) == "S") {
            if (ASTATI[ind] == 2) {
                ASTATI[ind] = 1;
                $(xdiv).slideUp(300);
                $("#" + IMG).attr("src", "files/images/common/Simulator/butapri.png");
                xEventi("#" + IMG, 1);
            } else {
                xEventi("#" + IMG, 0);
                ASTATI[ind] = 2;
                $(xdiv).slideDown(500);
                $("#" + IMG).attr("src", "files/images/common/Simulator/butchiudi.png");
            }
        } else if (ID.substr(0, 1) == "G") {
            if (XOLD != ind) {
                ASTATI[ind] = 1;
                ASTATI[XOLD] = 2;

                if (XOLD != 0) {    //  DR
                    $("#G-" + XOLD).slideUp(300, function () { $(xdiv).slideDown(500); });
                } else {
                    $(xdiv).slideDown(500);
                }

                $("#IMG-" + XOLD).attr("src", "files/images/common/Simulator/piu.png");
                $("#" + IMG).attr("src", "files/images/common/Simulator/butchiudi.png");
            } else {
                if (ASTATI[ind] == 2) {
                    ASTATI[ind] = 1;
                    $(xdiv).slideDown(500);
                    $("#" + IMG).attr("src", "files/images/common/Simulator/butchiudi.png");
                } else {
                    ASTATI[ind] = 2;
                    $(xdiv).slideUp(300);
                    $("#" + IMG).attr("src", "files/images/common/Simulator/piu.png");
                }
                ASTATI[XOLD] = ASTATI[ind];
            }
            XOLD = ind;
        }
    }
}

function xEventi(IMG, AZ) {
    if (AZ == 1) {
        $(IMG).bind("mouseover", function () {
            $(IMG).attr("src", "files/images/common/Simulator/butleggi.png");
        })
        $(IMG).bind("mouseout", function () {
            $(IMG).attr("src", "files/images/common/Simulator/butapri.png");
        })
    } else {
        $(IMG).unbind();
    }
}

// ----------------------------------------------------------------------------
// AddClassName
//
// Description : adds a class to the class attribute of a DOM element
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to add
//
function AddClassName(objElement, strClass, blnMayAlreadyExist) {

    if (objElement != undefined) {  //  DR
        if (objElement.className) {
            var arrList = objElement.className.split(' ');
            if (blnMayAlreadyExist) {
                var strClassUpper = strClass.toUpperCase();
                for (var i = 0; i < arrList.length; i++) {
                    if (arrList[i].toUpperCase() == strClassUpper) {
                        arrList.splice(i, 1);
                        i--;
                    }
                }
            }
            arrList[arrList.length] = strClass;
            objElement.className = arrList.join(' ');
        }
        else {
            objElement.className = strClass;
        }
    }
}
// 
// AddClassName
// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
// RemoveClassName
//
// Description : removes a class from the class attribute of a DOM element
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to remove
//
function RemoveClassName(objElement, strClass) {


    if (objElement != undefined) {  //  DR

        if (objElement.className) {
            var arrList = objElement.className.split(' ');

            var strClassUpper = strClass.toUpperCase();

            for (var i = 0; i < arrList.length; i++) {
                if (arrList[i].toUpperCase() == strClassUpper) {
                    arrList.splice(i, 1);
                    i--;
                }
            }

            objElement.className = arrList.join(' ');
        }
    }
}
// RemoveClassName
// ----------------------------------------------------------------------------
/* FINE PER ANCILLARY */


function SelectCoverage(chkId, lbDescId, ddlValueId, ddlCoinsuranceId, lbPriceId, imgId, divId) {

    var chk;
    var lbDesc;
    var ddlValue;
    var ddlCoinsurance;
    var lbPrice;
    var img;
    var div;

    if (chkId != undefined && chkId != '')
        chk = document.getElementById(chkId);

    if (lbDescId != undefined && lbDescId != '')
        lbDesc = document.getElementById(lbDescId);

    if (ddlValueId != undefined && ddlValueId != '')
        ddlValue = (ddlValueId != undefined && ddlValueId != '') ? document.getElementById(ddlValueId) : null;

    if (ddlCoinsuranceId != undefined && ddlCoinsuranceId != '')
        ddlCoinsurance = (ddlCoinsuranceId != undefined && ddlCoinsuranceId != '') ? document.getElementById(ddlCoinsuranceId) : null;

    if (lbPriceId != undefined && lbPriceId != '')
        lbPrice = document.getElementById(lbPriceId);

    if (imgId != undefined && imgId != '')
        img = document.getElementById(imgId);

    if (divId != undefined && divId != '')
        div = document.getElementById(divId);

    if (chk != undefined) {

        if (chk.checked) {

            if (div != undefined)
                AddClassName(div, 'classe15');

            if (lbDesc != undefined)
                lbDesc.style.fontWeight = 'bold';

            if (ddlValue != undefined)
                ddlValue.disabled = false;

            if (ddlCoinsurance != undefined)
                ddlCoinsurance.disabled = false;

            if (lbPrice != undefined)
                lbPrice.style.fontWeight = 'bold';

            if (img != undefined)
                img.src = imgRoot + '/common/oki.gif';

        } else {


            if (div != undefined)
                RemoveClassName(div, 'classe15');

            if (lbDesc != undefined)
                lbDesc.style.fontWeight = 'normal';

            if (ddlValue != undefined)
                ddlValue.disabled = true;

            if (ddlCoinsurance != undefined)
                ddlCoinsurance.disabled = true;

            if (lbPrice != undefined)
                lbPrice.style.fontWeight = 'normal';

            if (img != undefined)
                img.src = imgRoot + '/common/false.gif';

        }
    }
}



//  DR

function StopPropagation(e) {

    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();

}

function SetClassName(element, strClass) {

    if (element != undefined) {

        try {

            if (element.className) {

                element.className = strClass;
            }
        }
        catch (e) { }
    }
}




/* START SEMPLA - 18/04/2011 PAMELA GAVIGLIO */
function xDivSlideSemplice(xInd, xMin, xMax, xGrp, tipoTasto) {

    var apri = "";
    var chiudi = "";

    if (tipoTasto == "scuro") {
        apri = "files/images/espandiUp.gif";
        chiudi = "files/images/contraiUp.gif";
    } else {
        apri = "files/images/piu.gif";
        chiudi = "files/images/meno.gif";
    }

    if (xAutoSlide[xInd] == 0) {
        $("#AS-" + xInd).slideDown("slow");
        $("#AI-" + xInd).attr("src", chiudi);
        xAutoSlide[xInd] = 1;
    } else {
        $("#AS-" + xInd).slideUp("slow");
        $("#AI-" + xInd).attr("src", apri);
        xAutoSlide[xInd] = 0;
    }
    var xTot = 0;
    var xDif = xMax - xMin + 1;
    for (var x = xMin; x <= xMax; x++) {
        xTot += xAutoSlide[x];
    }
    if (xTot == xDif) {
        xAZ[xGrp] = "C";
        $("#espcon" + xGrp).html('CONTRAI TUTTI <img src="files/images/b_contrai.gif" alt="espandi/contrai tutte le informazioni" />');
    } else if (xTot == 0) {
        xAZ[xGrp] = "E";
        $("#espcon" + xGrp).html('ESPANDI TUTTI <img src="files/images/b_espandi.gif" alt="espandi/contrai tutte le informazioni" />');
    }
}
/* END SEMPLA - 18/04/2011 PAMELA GAVIGLIO */

/* START SEMPLA - 18/04/2011 SCROLL ORIZZONTALE GARANZIE (LUCA ONORI)*/
function xScrollGaranzie(xDir) {
    if (flagFX == 0) {
        flagFX = 1;
        var stepItem = parseFloat($(".boxH-item:first").css("width"));
        if (xDir == 'dx') {
            var xDiv = $(".boxH-item:last");
            $(".boxH-item:last").remove();
            $("#boxH-scroll-Garanzie").prepend(xDiv);
            $("#boxH-scroll-Garanzie").css({ left: (stepItem * -1) });
            $("#boxH-scroll-Garanzie").animate({ left: 0 }, "slow", function () {
                flagFX = 0;
            });
        } else {
            $("#boxH-scroll-Garanzie").animate({ left: (stepItem * -1) }, "slow", function () {
                var xDiv = $(".boxH-item:first");
                $(".boxH-item:first").remove();
                $("#boxH-scroll-Garanzie").css({ left: 0 });
                $("#boxH-scroll-Garanzie").append(xDiv);
                flagFX = 0;
            });
        }
    }
}
/* END SEMPLA - 18/04/2011 SCROLL ORIZZONTALE GARANZIE (LUCA ONORI)*/

/* START SEMPLA - DAVIDE GIORGIO - 18-04-2011  */

/* FUNZIONE OVER GRIGLIA POLIZZE E GARANZIE */
function garanzieOver() {
    $(".garanzieGrid > li > a").bind('mouseover', function () {
        var thumbOver = $(this).find("img").attr("src");
        if ($(this).hasClass('proteggiTe')) {
            $(this).find("img").attr("src", "files/images/garanzieTipo1_1.gif");
        }
        if ($(this).hasClass('assistenzaViaggio')) {
            $(this).find("img").attr("src", "files/images/garanzieTipo1_2.gif");
        }
        if ($(this).hasClass('proteggiAuto')) {
            $(this).find("img").attr("src", "files/images/garanzieTipo1_3.gif");
        }
        if ($(this).hasClass('proteggiMoto')) {
            $(this).find("img").attr("src", "files/images/garanzieTipo1_4.gif");
        }
        $(this).mouseout(function () {
            $(this).find("img").attr("src", thumbOver);
        });
    });
}

/* FUNZIONE MENU GRIGLIA POLIZZE E GARANZIE */
function garanzieMenu() {
    if ($('#garanzieMenu > li').hasClass('selected-0')) {
        $('#garanzieMenu > li.selected-0').find("img").attr("src", "files/images/garanzieFiltro0-sel.gif");
    }
    if ($('#garanzieMenu > li').hasClass('selected-1')) {
        $('#garanzieMenu > li.selected-1').find("img").attr("src", "files/images/garanzieFiltro1-sel.gif");
    }
    if ($('#garanzieMenu > li').hasClass('selected-2')) {
        $('#garanzieMenu > li.selected-2').find("img").attr("src", "files/images/garanzieFiltro2-sel.gif");
    }
    if ($('#garanzieMenu > li').hasClass('selected-3')) {
        $('#garanzieMenu > li.selected-3').find("img").attr("src", "files/images/garanzieFiltro3-sel.gif");
    }
    if ($('#garanzieMenu > li').hasClass('selected-4')) {
        $('#garanzieMenu > li.selected-4').find("img").attr("src", "files/images/garanzieFiltro4-sel.gif");
    }
    $("#garanzieMenu > li > a").bind('mouseover', function () {
        var garanzieNorm = $(this).find("img").attr("src");
        if (!($(this).parent('li').hasClass('selected-0'))) {
            if ($(this).parent('li').hasClass('segment-0')) {
                $(this).find("img").attr("src", "files/images/garanzieFiltro0-over.gif");
                $(this).mouseout(function () {
                    $(this).find("img").attr("src", garanzieNorm);
                });
            }
        }
        if (!($(this).parent('li').hasClass('selected-1'))) {
            if ($(this).parent('li').hasClass('segment-1')) {
                $(this).find("img").attr("src", "files/images/garanzieFiltro1-over.gif");
                $(this).mouseout(function () {
                    $(this).find("img").attr("src", garanzieNorm);
                });
            }
        }
        if (!($(this).parent('li').hasClass('selected-2'))) {
            if ($(this).parent('li').hasClass('segment-2')) {
                $(this).find("img").attr("src", "files/images/garanzieFiltro2-over.gif");
                $(this).mouseout(function () {
                    $(this).find("img").attr("src", garanzieNorm);
                });
            }
        }
        if (!($(this).parent('li').hasClass('selected-3'))) {
            if ($(this).parent('li').hasClass('segment-3')) {
                $(this).find("img").attr("src", "files/images/garanzieFiltro3-over.gif");
                $(this).mouseout(function () {
                    $(this).find("img").attr("src", garanzieNorm);
                });
            }
        }
        if (!($(this).parent('li').hasClass('selected-4'))) {
            if ($(this).parent('li').hasClass('segment-4')) {
                $(this).find("img").attr("src", "files/images/garanzieFiltro4-over.gif");
                $(this).mouseout(function () {
                    $(this).find("img").attr("src", garanzieNorm);
                });
            }
        }
    });
}

/* FUNZIONE ANIMAZIONE POLIZZE E GARANZIE */
(function ($) {
    $.fn.sorted = function (customOptions) {
        var options = {
            reversed: false,
            by: function (a) {
                return a.text();
            }
        };
        $.extend(options, customOptions);

        $data = $(this);
        arr = $data.get();
        arr.sort(function (a, b) {

            var valA = options.by($(a));
            var valB = options.by($(b));
            if (options.reversed) {
                return (valA < valB) ? 1 : (valA > valB) ? -1 : 0;
            } else {
                return (valA < valB) ? -1 : (valA > valB) ? 1 : 0;
            }
        });
        return $(arr);
    };

})(jQuery);

$(function () {
    var read_button = function (class_names) {
        var r = {
            selected: false,
            type: 0
        };
        for (var i = 0; i < class_names.length; i++) {
            if (class_names[i].indexOf('selected-') == 0) {
                r.selected = true;
            }
            if (class_names[i].indexOf('segment-') == 0) {
                r.segment = class_names[i].split('-')[1];
            }
        };
        return r;
    };

    var determine_sort = function ($buttons) {
        var $selected = $buttons.parent().filter('[class*="selected-"]');
        return $selected.find('a').attr('data-value');
    };

    var determine_kind = function ($buttons) {
        var $selected = $buttons.parent().filter('[class*="selected-"]');
        return $selected.find('a').attr('data-value');
    };

    var $preferences = {
        duration: 800,
        easing: 'easeInOutQuad',
        adjustHeight: 'dynamic'
    };

    var $list = $('.garanzieGrid');
    var $data = $list.clone();

    var $controls = $('#garanzieMenu');

    $controls.each(function (i) {

        var $control = $(this);
        var $buttons = $control.find('a');

        $buttons.bind('click', function (e) {

            var $button = $(this);
            var $button_container = $button.parent();
            var button_properties = read_button($button_container.attr('class').split(' '));
            var selected = button_properties.selected;
            var button_segment = button_properties.segment;

            if (!selected) {

                $buttons.parent().removeClass('selected-0').removeClass('selected-1').removeClass('selected-2').removeClass('selected-3').removeClass('selected-4');
                $button_container.addClass('selected-' + button_segment);
                $button_container.find("img").attr("src", "files/images/garanzieFiltro" + button_segment + "-sel.gif");
                if ($('#garanzieMenu > li').hasClass('segment-0') && !$('#garanzieMenu > li').hasClass('selected-0')) {
                    $('#garanzieMenu > li.segment-0').find("img").attr("src", "files/images/garanzieFiltro0.gif");
                }
                if ($('#garanzieMenu > li').hasClass('segment-1') && !$('#garanzieMenu > li').hasClass('selected-1')) {
                    $('#garanzieMenu > li.segment-1').find("img").attr("src", "files/images/garanzieFiltro1.gif");
                }
                if ($('#garanzieMenu > li').hasClass('segment-2') && !$('#garanzieMenu > li').hasClass('selected-2')) {
                    $('#garanzieMenu > li.segment-2').find("img").attr("src", "files/images/garanzieFiltro2.gif");
                }
                if ($('#garanzieMenu > li').hasClass('segment-3') && !$('#garanzieMenu > li').hasClass('selected-3')) {
                    $('#garanzieMenu > li.segment-3').find("img").attr("src", "files/images/garanzieFiltro3.gif");
                }
                if ($('#garanzieMenu > li').hasClass('segment-4') && !$('#garanzieMenu > li').hasClass('selected-4')) {
                    $('#garanzieMenu > li.segment-4').find("img").attr("src", "files/images/garanzieFiltro4.gif");
                }
                $button.unbind('mouseout');

                var sorting_type = determine_sort($controls.eq(1).find('a'));
                var sorting_kind = determine_kind($controls.eq(0).find('a'));

                if (sorting_kind == 'all') {
                    var $filtered_data = $data.find('li');
                } else {
                    var $filtered_data = $data.find('li.' + sorting_kind);
                }

                if (sorting_type == 'size') {
                    var $sorted_data = $filtered_data.sorted({
                        by: function (v) {
                            return parseFloat($(v).find('span').text());
                        }
                    });
                } else {
                    var $sorted_data = $filtered_data.sorted({
                        by: function (v) {
                            return $(v).find('span').text().toLowerCase();
                        }
                    });
                }

                $list.quicksand($sorted_data, $preferences);
                setTimeout(garanzieOver, 900);
            }
            e.preventDefault();

        });
        garanzieOver();
    });

});
/* END SEMPLA - DAVIDE GIORGIO - 18-04-2011  */
