/*
function lib_bwcheck(){ //Browsercheck (needed)
        this.ver=navigator.appVersion
        this.agent=navigator.userAgent
        this.dom=document.getElementById?1:0
        this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
        this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
        this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
        this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
        this.ie=this.ie4||this.ie5||this.ie6
        this.mac=this.agent.indexOf("Mac")>-1
        this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
        this.ns4=(document.layers && !this.dom)?1:0;
        this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
        return this
}
var bw=lib_bwcheck()
*/
/*if(document.layers){ //NS4 resize fix...
        scrX= innerWidth; scrY= innerHeight;
        onresize= function(){if(scrX!= innerWidth || scrY!= innerHeight){history.go(0)} }
}*/

/****
Variables to set
****/
//anterior = -1;
/*
msgFont= "verdana"      // The font for the message
msgFontSize= 10                         // Set the fontSize in px
msgFontColor="#ffffff"          // Set the fontColor
msgWidth= "178"                         // Set the width of the messageblock here for netscape 4
*/
var oMessage = new Array();
var msgFont = new Array();
var msgFontSize = new Array();
var msgFontColor = new Array();
var msgWidth = new Array();


/********************************************************************************
You don't have to change anything below this
********************************************************************************/

//ChangeText object constructor.
function makeChangeTextObj(obj){
        this.css = bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?document.layers[obj]:0;
        //this.writeref = bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?document.layers[obj].document:0;
        this.writeref = bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval('document.'+obj+'.document'):0;
        this.writeIt = b_writeIt;
}

function makeChangeTextObj2(obj,nest){
        nest=(!nest) ? "":'document.'+nest+'.'
        //this.css = bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.layers['+obj+']'):0;
        //this.writeref = bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.layers['+obj+'].document'):0;
        this.css = bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;
        this.writeref = bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj+'.document'):0;
        this.writeIt = b_writeIt;
}

function b_writeIt(text,text2){
        if (bw.ns4){
                this.writeref.write(text)
                this.writeref.close()
        }
    else this.writeref.innerHTML = text2
}

//The mouoseover function. Calls the writeIt method to write the text to the div.
//function changeText(NumCapa,NumFormulari,CampDades,LocalitzacioNN4){
function changeText(NumCapa,Dades){
        if (!bw.ns4)
        {
/*
                if (anterior!=-1)
                {
                        num2 = anterior + 1;  // El +1 es per saltar l'enlla‡ del coac
                        canvi_color = "document.links[" + num2 + "].className=\"titol\"";
                        eval(canvi_color);
                }
                anterior = num;
                num2 = num + 1; // El +1 es per saltar l'enlla‡ del coac
                canvi_color = "document.links[" + num2 + "].className=\"titol_selec\"";
                eval(canvi_color);
*/
                //desc = "document.forms[0].elements[\"camp" + num + "\"].value";
//              desc = "document.forms[" + NumFormulari + "].elements[\"" + CampDades + "\"].value";
//              desc2 = eval(desc);

        }
        else
        {
/*
                if (anterior!=-1)
                {
                        num2 = anterior + 1;  // El +1 es per saltar l'enlla‡ del coac
                        canvi_color = "document.divCont.document.divScroll.document.links[" + num2 + "].className=\"titol\"";
                        //eval(canvi_color);
                }
                anterior = num;
                num2 = num + 1; // El +1 es per saltar l'enlla‡ del coac
                canvi_color = "document.divCont.document.divScroll.document.links[" + num2 + "].className=\"titol_selec\"";
                //eval(canvi_color);
*/
                //desc = "document.divCont.document.divScroll.document.forms[" + NumFormulari + "].elements[\"" + CampDades + "\"].value";
//              desc = LocalitzacioNN4 + "document.forms[" +NumFormulari + "].elements[\"" + CampDades + "\"].value";
//              desc2 = eval(desc);
        }
        //if(bw.bw) oMessage[NumCapa].writeIt('<table width="'+msgWidth[NumCapa]+'" border="0" cellpadding="0" cellspacing="0"><tr><td><span style="font-size:'+msgFontSize[NumCapa]+'px; font-family:'+msgFont[NumCapa]+'; color:'+msgFontColor[NumCapa]+'">'+desc2+'</span></td></tr></table>', desc2)
        //if(bw.bw) oMessage[NumCapa].writeIt('<table width="'+msgWidth[NumCapa]+'" border="0" cellpadding="0" cellspacing="0"><tr><td><span style="font-size:'+msgFontSize[NumCapa]+'px; font-family:'+msgFont[NumCapa]+'; color:'+msgFontColor[NumCapa]+'">'+Dades+'</span></td></tr></table>', Dades)

        if(bw.bw)
        {
                oMessage[NumCapa].writeIt(Dades, Dades);
        }

}

//The init function. Calls the object constructor and initiates some properties.
function changeTextInit(){
        //Fixing the browsercheck for opera... this can be removed if the browsercheck has been updated!!
        bw.opera5 = (navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?true:false
        if (bw.opera5) bw.ns6 = 0

        oMessage = new makeChangeTextObj('divMessage')
        //oLinks = new makeChangeTextObj('divLinks')
        //Setting the style properties of the text layer.
        if(bw.dom || bw.ie4){
                with(oMessage.writeref.style){fontFamily=msgFont; fontSize=msgFontSize+"px"; color=msgFontColor}
        }
        //Both layers are hidden by default to prevent users from mousing over them and creating errors while the page loads.
        oMessage.css.visibility= "visible"
        //oLinks.css.visibility= "visible"
}


function InicialitzaChangeText()
{
        oMessage = new Array();
        msgFont = new Array();
        msgFontSize = new Array();
        msgFontColor = new Array();
        msgWidth = new Array();
}

function InicialitzaCapa(NumCapa,NomCapa,NomFont,TamanyFont,ColorFont,AmpladaCapa)
{
        //oMessage[NumCapa] = new makeChangeTextObj('divMessage')
        oMessage[NumCapa] = new makeChangeTextObj(NomCapa);

        msgFont[NumCapa]=NomFont;
        msgFontSize[NumCapa]=TamanyFont;
        msgFontColor[NumCapa]=ColorFont;
        msgWidth[NumCapa]=AmpladaCapa;
        if(bw.dom || bw.ie4){
                with(oMessage[NumCapa].writeref.style){fontFamily=msgFont[NumCapa]; fontSize=msgFontSize[NumCapa]+"px"; color=msgFontColor[NumCapa]}
        }

        oMessage[NumCapa].css.visibility= "visible";
}

function InicialitzaCapa2(NumCapa,NomCapa,nest,NomFont,TamanyFont,ColorFont,AmpladaCapa)
{
        //oMessage[NumCapa] = new makeChangeTextObj('divMessage')
        oMessage[NumCapa] = new makeChangeTextObj2(NomCapa,nest);

        msgFont[NumCapa]=NomFont;
        msgFontSize[NumCapa]=TamanyFont;
        msgFontColor[NumCapa]=ColorFont;
        msgWidth[NumCapa]=AmpladaCapa;
        if(bw.dom || bw.ie4){
                with(oMessage[NumCapa].writeref.style){fontFamily=msgFont[NumCapa]; fontSize=msgFontSize[NumCapa]+"px"; color=msgFontColor[NumCapa]}
        }

        oMessage[NumCapa].css.visibility= "visible";
}

//If the browser is ok, the init function is called on pageload.
//if (bw.bw) onload = changeTextInit


function CanviarCursorCapa(Capa)
{
                if (bw.ie)
                {
                        obj = document.all(Capa);
                        obj.style.cursor='hand';
                }
                else if (bw.ns6)
                {
                        obj = document.getElementById(Capa);
                        obj.style.cursor='pointer';
                }
}

function AmagarCapa(Capa)
{
        Obj = bw.dom?document.getElementById(Capa).style:bw.ie4?document.all[Capa].style:bw.ns4?document.layers[Capa]:0;                
        //Obj = eval(Obj);
        Obj.visibility = "hidden";
}

function MostrarCapa(Capa)
{
        Obj = bw.dom?document.getElementById(Capa).style:bw.ie4?document.all[Capa].style:bw.ns4?document.layers[Capa]:0;                
        //Obj = eval(Obj);
        Obj.visibility = "visible";
}

function getClipValues(element){
   // assumes you've already set a clip value
   var clip = element.style.clip 
   var clipVals = clip.split("rect(")[1].split(" ");
   for (var i=0;i<clipVals.length;i++){
     clipVals[i] = parseInt(clipVals[i]);
   }
   return clipVals;
}

function createNewClip(clipVals){
   var newClip = "rect(";
   for (var i=0;i<clipVals.length;i++){
     newClip += clipVals[i] + "px ";
   }
   newClip += ")";
   return newClip;
}

function MoureCapaGraelles(Capa,PathNS4)
{
        if (bw.ie && bw.mac)
        {
                document.all[Capa].style.left = document.all[Capa].offsetLeft - 1;

                if ( document.all[Capa].style.clip != "auto" )
                {
                        var ValorsClip = getClipValues(document.all[Capa]);
                        ValorsClip[3] = ValorsClip[3] + 1; // Clipem 1 pixel per l'esquerra
                        var StringClip = createNewClip(ValorsClip);
                        document.all[Capa].style.clip = StringClip;
                }
        }
        else if (bw.ns6)
        {
                document.getElementById(Capa).style.left = document.getElementById(Capa).offsetLeft - 2;

                if ( document.getElementById(Capa).style.clip != "" )
                {
                        var ValorsClip = getClipValues(document.getElementById(Capa));
                        ValorsClip[3] = ValorsClip[3] + 2; // Clipem 2 pixels per l'esquerra
                        var StringClip = createNewClip(ValorsClip);
                        document.getElementById(Capa).style.clip = StringClip;
                }
        }
        else if (bw.ns4)
        {
                var CapaNS4 = PathNS4 + ".document." + Capa;
                CapaNS4 = eval(CapaNS4);
                CapaNS4.left = CapaNS4.left - 2;
                CapaNS4.clip.left = 2;
        }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// Funcions pel tractament de capes en Netscape Navigator 4.7 ///////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

tempLayer = "";
Punt = "";
Esquerre = 0;
Dreta = 0;
Dalt = 0;
Baix = 0;
Visibilitat = "show";
Profunditat = 0;
ProfunditatMAX = 0;
CapaClicada = "";
CapesClicades = new Array();
CapesCanviEstat = new Array();
LinkClicat = false;

function InicialitzaPropietatsCapa(Element2,Tipus,ClasseCapa)
{
        if (bw.ns4)
        {
                var Element = eval(Element2);
                if (Tipus == "CAPA")
                {
                        Element.EstatAnterior = "OUT";
                        Element.EsLink = false;
                        Element.className = ClasseCapa;
                }
                else if (Tipus == "LINK")
                {
                        Element.EstatAnterior = "OUT";
                        Element.EsLink = true;
                        Element.className = ClasseCapa;
                }
        }
}

function InicialitzaCanviColorCapa(Element3)
{
        if (bw.ns4)
        {
                        var Element = eval(Element3);
                        Element.changeColor = function(Color) { this.bgColor = Color; };
        }
}

function InicialitzaMouseOverCapa(Element2, Codi)
{
        if (bw.ns4)
        {
                var Element = eval(Element2);
                Element.onmouseover = function(evt) { eval(Codi); };
        }
}

function InicialitzaMouseOutCapa(Element2, Codi)
{
        if (bw.ns4)
        {
                var Element = eval(Element2);
                Element.onmouseout = function(evt) { eval(Codi); };
        }
}

function DetectaCapaEvent(e)
{
        if (bw.ns4)
        {
                var mouseX = e.pageX;
                var mouseY = e.pageY;
                var Punt = "";
                var i = 0;
                var obj = "";
                var tempLayer2 = tempLayer;
                var NumCapes = 0;

                var Esquerre2 = Esquerre;
                var Dreta2 = Dreta;
                var Dalt2 = Dalt;
                var Baix2 = Baix;

                var Visibilitat2 = Visibilitat;

                if (Profunditat == 0)
                {
                        CapesCanviEstat = new Array();
                }

                Profunditat++;

                if (tempLayer!="")
                        Punt = ".";
                else
                        Punt = "";
                NumCapes = eval(tempLayer2 + Punt + "document.layers.length");
            for (i=0; i<NumCapes; i++)
            {
                tempLayer = tempLayer2 + Punt + "document.layers[" + i + "]";
                obj = eval(tempLayer);
                Esquerre = Esquerre2 + obj.left + obj.clip.left;
                Dreta = Esquerre + obj.clip.width;
                Dalt = Dalt2 + obj.top+obj.clip.top;
                Baix = Dalt + obj.clip.height;

                         if (obj.visibility=="show")
                                Visibilitat="show";
                         else if (obj.visibility=="hide")
                                Visibilitat="hide";

                if ( obj.document.layers.length > 0)
                {
                        DetectaCapaEvent(e);
                }

                if ( (mouseX > Esquerre) && (mouseX < Dreta) && (mouseY > Dalt) && (mouseY < Baix) )
                {

                        if (e.type=="mouseup")
                        {
                                if (Visibilitat=="show")
                                {
                                        if (Profunditat>ProfunditatMAX)
                                        {
                                                CapesClicades = new Array();
                                                        ProfunditatMAX = Profunditat;
                                                        CapaClicada = tempLayer;
                                                        CapesClicades[CapesClicades.length] = tempLayer;
                                                }
                                        else if (Profunditat==ProfunditatMAX)
                                        {
                                                        CapesClicades[CapesClicades.length] = tempLayer;
                                        }
                                        }
                                }
                                else if (e.type=="mousemove")
                                {
                                        if (obj.EstatAnterior=="OUT")
                                        {
                                                obj.EstatAnterior="IN";
                                                CapesCanviEstat[CapesCanviEstat.length] = tempLayer;
                                        }
                                }
                }
                else
                {
                                if (e.type=="mousemove")
                                {
                                if (obj.EstatAnterior=="IN")
                                {
                                                obj.EstatAnterior="OUT";
                                        CapesCanviEstat[CapesCanviEstat.length] = tempLayer;
                                }
                       }
                }
            }
            tempLayer = tempLayer2;
            Esquerre = Esquerre2;
            Dreta = Dreta2;
            Dalt = Dalt2;
            Baix = Baix2;
            Visibilitat = Visibilitat2;

            Profunditat--;
        }
}

function Clicar(e)
{
        // Aquesta funcio mira si s'ha fet click en alguna capa que no sigui un link i en cas afirmatiu crida a la funcio TractamentClic
        // que estara definida en cada pagina que capturi events i fagi us de la funcio Clicar.
        // El parametre de la funcio TractamentClic es la capa sobre la que s'ha fet clic.
        if (bw.ns4)
        {
                var obj;
                routeEvent(e);
                DetectaCapaEvent(e);
                if (ProfunditatMAX > 0)
                {
                        obj = eval(CapaClicada);
                        if ((!obj.EsLink) && (!LinkClicat))
                                TractamentClic(obj);
                }
           ProfunditatMAX = 0;
           CapaClicada = "";
           CapesClicades = new Array();
        }
}

function CapturarEvents()
{
        if (bw.ns4)
        {
                document.captureEvents(Event.MOUSEUP);
                document.onmouseup = Clicar;
        }
}

