﻿
var arrelrelativa = "/"; 
var imgrelpath = arrelrelativa + "images/";    

// estructura que suporta la informacio previa per posteriorment generar els DIVS dins la pagina

var menus = [];
var submenus = [];
var menudiv = [];

function crear_menu_interior(id, desc, estil1, link, amplada, alcfila)
{
    var width = ((typeof amplada=='undefined' || amplada=='' || amplada==null)?'':Number(amplada));
    var tdheight = ((typeof alcfila=='undefined' || alcfila=='' || alcfila==null)?16:Number(alcfila));
    var dy = 0
    
    // estils = 'textGriOn/textgriOff/b9d/tg9d'
    // menu02/menuintoff/menulink/menutext
    estils = estil1 + "/menuintoff/menucolorlink/menucolortext"

    var i = menus.length;
    menus[i] = {'id':id, 'desc':escape(desc), 'estils':estils, 'link':link, 
                'dx':0, 'width':width, 'extra':0, 'tdheight':tdheight, 'dy':dy,
                'menu':0, 'tipusmenu':'i'};
    if(id!=null && id!='') {submenus[id] = []; }
    
    xControlMen(id,id+'Kapa',estils,500);
}

function crear_menu_historic(id, desc, link, despldx, amplada, extra, alcfila, vertical)
{
    var dx    = ((typeof despldx=='undefined' || despldx=='' || despldx==null)?0:Number(despldx)); //valor per defecte
    var width = ((typeof amplada=='undefined' || amplada=='' || amplada==null)?'':Number(amplada));
    var extra = ((typeof extra=='undefined' || extra=='' || extra==null)?0:Number(extra));
    var tdheight = ((typeof alcfila=='undefined' || alcfila=='' || alcfila==null)?16:Number(alcfila));
    var dy = 5

    estils = 'historicmenu/historicmenuoff/historiclink/historictext'
	
    var i = menus.length;
    menus[i] = {'id':id, 'desc':desc, 'estils':estils, 'link':link, 
                'dx':dx, 'width':width, 'extra':extra, 'tdheight':tdheight, 'dy':dy,
                'menu':1, 'tipusmenu':'h'};
    if(id!=null && id!='') {submenus[id] = [];}
    
    xControlMen(id,id+'Kapa',estils,200);
}


function crear_menu(id, desc, nummenu, link, despldx, amplada, extra, alcfila, vertical)
{
    var dx    = ((typeof despldx=='undefined' || despldx=='' || despldx==null)?0:Number(despldx)); //valor per defecte
    var width = ((typeof amplada=='undefined' || amplada=='' || amplada==null)?92:Number(amplada));
    var extra = ((typeof extra=='undefined' || extra=='' || extra==null)?0:Number(extra));
    var tdheight = ((typeof alcfila=='undefined' || alcfila=='' || alcfila==null)?16:Number(alcfila));
    var dy = 5

    estils = 'menu' + nummenu + '/menuoff/menulink/menutext'
	        // 'textAzuOnFixe/textAzuOffFixe/b10Fixe/tg10Fixe'
	        // 'textRojOnFixe/textRojOffFixe/b10Fixe/tg10Fixe'
	        // 'textVerOnFixe/textVerOffFixe/b10Fixe/tg10Fixe'    
  
    var i = menus.length;
    menus[i] = {'id':id, 'desc':desc, 'estils':estils, 'link':link, 
                'dx':dx, 'width':width, 'extra':extra, 'tdheight':tdheight, 'dy':dy, 
                'menu':1, 'tipusmenu':'g'};
    if(id!=null && id!='') {submenus[id] = [];}
    
    xControlMen(id,id+'Kapa',estils,200);
}


function crear_submenu(idmenu, id, desc, link)
{

    if(idmenu == null || idmenu == '') {return;}
    if(typeof submenus[idmenu] == 'undefined') { alert('Menu no definit '+ idmenu); return;}
    if((desc == null || desc == '') && ( link == null || link == '' )) {return;}
 
    var i = submenus[idmenu].length;
    submenus[idmenu][i] = {'id':id, 'desc':escape(desc), 'link':link};
}



// en execucio...

function menu_td_onmouseover(td,id)
{
    onmouseover_menu(td,id,1)
}
function menu_td_onmouseout(td,id)
{
    onmouseout_menu(td,id,1)
}

function menu_link_onmouseover(td,id)
{
    onmouseover_menu(td,id,0)
}
function menu_link_onmouseout(td,id)
{
    onmouseout_menu(td,id,0)
}


function menu_onmouseover(td, id, istd)
{
    // validacio si existeix
    var i;
    for(i=0;i<menus.length;i++) {
        if(menus[i]['id'] == id) { break; }
    }
    if(i>=menus.length) { return; }

    
    if(typeof istd == "undefined") {
        // comparem td, imatges i links
        istd = (typeof td.align!="undefined") && (typeof td.src=="undefined")
    } 
    if(!istd) {
        // intentem determinar el TD pare del pare
        
    }
    
    dx = menus[i]['dx']
    if(!istd) { if(menus[i]['tipusmenu']=='i') {dx+=6;} }
    
    setLyr(td,id+'Kapa',-dx);
    if(!istd) {
        s = 'xCM'+id+'.showOpc(\'opc1'+id+'\',\'opc1'+id+'Enc\',0)'
    } else {
        s = 'xCM'+id+'.actvOpc(\'opc1'+id+'\',\'opc1'+id+'Enc\',0)'
    }
    eval(s)
    
    // sample:
    //   setLyr(this,'TreballarKapa',-65);
    //   xCMpc4.actvOpc('opc1Treballar','opc1TreballarEnc',0)
}

function menu_onmouseout(td, id, istd)
{
    // validacio si existeix
    var i;
    for(i=0;i<menus.length;i++) {
        if(menus[i]['id'] == id) { break; }
    }
    if(i>=menus.length) { return; }
    
    if(typeof istd == "undefined") {
        // comparem td, imatges i links
        istd = (typeof td.align!="undefined") && (typeof td.src=="undefined")
    }

    if(!istd) {
        s = 'xCM'+id+'.showOpc(\'opc1'+id+'\',\'opc1'+id+'Enc\',1)'    
    } else {
        s = 'xCM'+id+'.actvOpc(\'opc1'+id+'\',\'opc1'+id+'Enc\',1)'
    }
    eval(s)
    
    // sample:
    //   xCMpc4.actvOpc('opc1Treballar','opc1TreballarEnc',1)
}


function inserir_menus()
{
    set_arrelrelativa();
    
    var i, is, dv;
    // per cada menu inserim un DIV amb les opcions del submenu
    for(i=0;i<menus.length;i++) {
        if(menus[i]['menu']) {
            dv = genera_div(i);
        } else {
            dv = genera_div(i); //_interior
        }
        menudiv[i] = dv
        document.write(dv + "\n");
    }
}

// //xivato on line
//javascript:void(document.formalvi.ta.value=menudiv[0]);<br>
//<form name=formalvi>
//<textarea name=ta cols=80 rows=7></textarea><br>
//</form>

// ********************************* //
// ****   FUNCIONS AUXILIARS    **** //
// ********************************* //

// genera el DIV del menu i (segons estructura, podem accedir a submenus)
function genera_div(i)
{
    var id = menus[i]['id'];
    var desc = unescape(imgrelatiu(menus[i]['desc']));    // &nbsp;&nbsp;Viure&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    var link = linkrelatiu(menus[i]['link'])
    var dy = menus[i]['dy']
    var width = menus[i]['width']
    var dx = menus[i]['dx']
    var extra = menus[i]['extra']
    var tdheight = menus[i]['tdheight']
    var estils = menus[i]['estils'].split('/');
    var td1nowrap = ""
    
    if(width == "nowrap") {width=''; td1nowrap=" nowrap ";}
    var width2 = width + dx
    var width3 = width + extra
    var colspan = 1
    
    var s = "",tr1="",td1="",td2="", td3="",td4="",td5="",td6="";
    
    s = ""
    var layers = (document.layers?1:0)
    if(layers) {
        s += "<LAYER id=\"" + id + "Kapa\"  visibility=hide >" + "\n"
    } else {
        s += "<DIV id=\"" + id + "Kapa\" " + " style=\"LEFT: 0px; TOP: 0px; VISIBILITY: hidden; " + (width!=""?"WIDTH: " + width2 + "px;":"") + " POSITION: absolute\">" + "\n"
    }


    // MAXIM DE MAXIM D'AMPLADA DELS MENUS
    s += "<TABLE width=300 cellSpacing=0 cellPadding=0 summary=\"\" border=0><TR><TD>" + "\n"

    s += " <TABLE cellSpacing=0 cellPadding=0 summary=\"\" border=0 " + (width!=""?" width=" + (dx+width+extra):"") + ">" + "\n"
    s += "  <TR>" + "\n"

    if(dx>0) {
    s += "    <TD width=" + dx + "><IMG height=5 alt=\"\"" + "\n"
    s += "         src=\"" + imgrelpath + "sp.gif\" width=" + dx + " border=0></TD>" + "\n"
    colspan++
    }    
    s += "    <TD" + (width!=""?" width=" + (width):"") + ">" + "\n"

    s += "      <table " + (width!=""?" width=" + (width):"") + " cellSpacing=0 cellPadding=0 border=0>" + "\n"
    if(dy>0) {
    s += "        <tr>" + "\n"
    s += "          <TD colspan=2 bgColor=#ffffff><IMG height=" + dy + " alt=\" \"" + "\n"
    s += "              src=\"" + imgrelpath + "sp.gif\" border=0></TD>" + "\n"
    s += "        </tr>" + "\n"
    }
    s += "        <tr>" + "\n"
    s += "          <TD class=" + estils[0] + " width=6><IMG height=1 alt=\"\" src=\"" + imgrelpath + "sp.gif\" width=6 border=0></TD> " + "\n" 
    s += "          <TD class=" + estils[0] + " id=opc1" + id + " " + td1nowrap + " " + "\n" 
    s += "           onmouseover=\"xCM" + id + ".actvOpc('opc1" + id + "','opc1" + id + "Enc',0)\" " + "\n"
    s += "           onmouseout=\"xCM" + id + ".actvOpc('opc1" + id + "Enc','opc1" + id + "Enc',1)\" " + "\n"
    s += "           height=16 " + (width!=""?" width=" + (width-6):"") + "><A class=" + estils[2] + " id=opc1" + id + "Enc"  + "\n"
    s += "              onmouseover=\"xCM" + id + ".showOpc('opc1" + id + "','opc1" + id + "Enc',0)\" " + "\n"
    s += "              onmouseout=\"xCM" + id + ".showOpc('opc1" + id + "Enc','opc1" + id + "Enc',1)\" " + "\n"
    s += "              href=\"" + link + "\">" + desc + "</A></TD>" + "\n"
    s += "        </tr>" + "\n"
    s += "      </table>" + "\n"

    s += "    </TD>" + "\n"
    if(extra>0) {
    s += "    <TD width=" + extra + "><IMG height=5 alt=\"\"" + "\n"
    s += "         src=\"" + imgrelpath + "sp.gif\" width=" + extra + " border=0></TD>" + "\n"
    colspan++
    }
    s += "  </TR>" + "\n"
    
    if(typeof submenus[id] == 'undefined') {
    } else {
    
        var subj;
        for(subj=0;subj<submenus[id].length;subj++) {
            //s += "subopcion(" + (subj+2) + ",'" + id + "','" + id + "','" +  estils[1] + "','" +  estils[3] + "','" +  submenus[id][subj]['desc'] + "','" +  submenus[id][subj]['link'] + "',true,null,"+ colspan + ","+ tdheight + ");" + "\n"
            indice = (subj+2)
            numCapa = id
            nomCapa = id
            stTD = estils[1]
            stA = estils[3]
            nomOp = imgrelatiu(submenus[id][subj]['desc'])
            url = linkrelatiu(submenus[id][subj]['link']) + ""
            
            onmouse = ''
            trheight = tdheight
        
            strfila = ""; onmouse = "";
            if ((document.getElementById || document.all)) {
                onmouse = ' onmouseover=xCM'+numCapa+'.actvOpc("opc'+indice+nomCapa+'","opc'+indice+nomCapa+'Enc",0) onmouseout=xCM'+numCapa+'.actvOpc("opc'+indice+nomCapa+'","opc'+indice+nomCapa+'Enc",1)'
                
                strfila += '  <tr><td height=' + trheight + ' ' + (colspan>1?'colspan=' + colspan:'') + onmouse + ' id="opc'+indice+nomCapa+'" class="'+stTD+'">' + "\n"
                strfila += '    <table ' + (width!="" && colspan==1?" width=" + (width+dx+extra):"") + ' border="0" cellspacing="0" cellpadding="0" class="'+stA+'">' + "\n"
                strfila += '      <tr>' + "\n"
                strfila += '        <td width="6">' + "<IMG height=1 alt=\"\" src=\"" + imgrelpath + "sp.gif\" width=6 border=0>" + '</td>' + "\n"
                strfila += '        <td ' + (width!="" && colspan==1?" width=" + (width+dx+extra-6):"") + ' class="'+stA+'"><a href="'+url+'" id="opc'+indice+nomCapa+'Enc" class="'+stA+'">'+ unescape(nomOp)+'</a></td>' + "\n"
                strfila += '      </tr>' + "\n"
                strfila += '    </table>' + "\n"
                strfila += '</td></tr>' + "\n"
            } else if (document.layers) {
                onmouse = 'onmouseover=xCM'+numCapa+'.showOpc("opc'+indice+nomCapa+'","opc'+indice+nomCapa+'Enc",0) onmouseout=xCM'+numCapa+'.showOpc("opc'+indice+nomCapa+'","opc'+indice+nomCapa+'Enc",1)'
                
                strfila += '  <tr><td height=' + trheight + ' ' + (colspan>1?'colspan=' + colspan:'') + ' id="opc'+indice+nomCapa+'" class="'+stTD+'">'  + "\n"
                strfila += '    <table ' + (width!="" && colspan==1?" width=" + (width+dx+extra):"") + ' border="0" cellspacing="0" cellpadding="0" class="'+stA+'">' + "\n"
                strfila += '      <tr>' + "\n"
                strfila += '        <td width="6">' + "<IMG height=1 alt=\"\" src=\"" + imgrelpath + "sp.gif\" width=6 border=0>" + '</td>' + "\n"
                strfila += '        <td ' + (width!="" && colspan==1?" width=" + (width+dx+extra-6):"") + ' class="'+stA+'"><a href="'+url+'" id="opc'+indice+nomCapa+'Enc" class="'+stA+'"' + onmouse + '>'+unescape(nomOp)+'</a></td>' + "\n"
                strfila += '      </tr>' + "\n"
                strfila += '    </table>' + "\n"
                strfila += '  </td></tr>' + "\n"
            }
            s += strfila;
    
        }
        
        // sample:
        //   opcion(2,'Viure',3,'textVerOff','tg10',"Índex Viure",'http://www.gencat.cat/viure/index.htm',true);
    }

    s += " </TABLE>" + "\n"
    s += "</TD></TR></TABLE>" + "\n"

    if(layers) {
        s += "</LAYER>" + "\n"
    } else {
        s += "</DIV>" + "\n"
    }
    
    return s;
}

var pathabsolut_pag = '', arrelabsoluta = '';
var arrelrelativa_inicial = "";
var idlogo = "logogencat";
var imgpath = "images/logotip.gif";

function set_arrelrelativa()
{
    if(arrelrelativa_inicial=="") {arrelrelativa_inicial = arrelrelativa;}

    var logo = eval("document." + idlogo)
    if(typeof logo == "undefined") { 
	    //alert(' no logo '); 
	    //window.status = "no logo";
	    return; 
	} else {
	        //window.status=''
	}
    var srclogo = logo.src.toLowerCase();
    arrelabsoluta = srclogo.substr(0,srclogo.indexOf(imgpath))
    
    var loc = document.location.href;
    loc = unescape(loc)
    loc = loc.toLowerCase()
    
    if(loc.indexOf(arrelabsoluta)>=0) {
        // ATENCIO: no podem retallar abans de mirar si la nostra arrel esta dins la url

        loc = loc.substr(loc.indexOf(arrelabsoluta))    // http://c.g.net/agenda/index.asp

        // retalla la url per la dreta si troba les seguents marques: ? # &
        i = loc.indexOf("?");
        if(i>=0) {loc = loc.substring(0,i); }
        i = loc.indexOf("#");
        if(i>=0) {loc = loc.substring(0,i); }
        i = loc.indexOf("&");
        if(i>=0) {loc = loc.substring(0,i); }
    

        // busquem la ruta absoluta al directori -> busquem ultima barra
        if(loc.charAt(loc.length-1) == "/") {
            // si la url acaba en barra sera directament path de directori
            pathabsolut_pag = loc
        } else {
            // busquem ultima barra
            var i = loc.lastIndexOf("/")
            if(i<arrelabsoluta.length) {
                // la ultima barra esta abans de l'arrel (inclou barra)
                pathabsolut_pag = arrelabsoluta
            } else {
                // anem a mirar si l'ultim tros es directori o pagina
                var pag = loc.substr(i+1)
                
                if(pag.indexOf(".") >= 0) {
                    // es una pagina => fins ultima barra es el path
                    pathabsolut_pag = loc.substr(0,i+1)
                } else {
                    // ultim nom es ultim de la ruta
                    pathabsolut_pag = loc + "/"
                }
            }
        }
        
    } else {
        // no podem referenciar respecte src de la imatge. Deixem en blanc per fer relatiu
        pathabsolut_pag = ''
        
    }

    // retalla la url per la dreta si troba les seguents marques: ? # &
    i = loc.indexOf("?")
    if(i>=0) {loc = loc.substring(0,i); }
    i = loc.indexOf("#")
    if(i>=0) {loc = loc.substring(0,i); }
    i = loc.indexOf("&")
    if(i>=0) {loc = loc.substring(0,i); }
    
    // path relatiu segons la font de la imatge
    loc = loc.substr(srclogo.indexOf(imgpath))

    res = ""
    while( (i = loc.indexOf("/")) >=0) {
        res += "../"
        loc = loc.substr(i+1)
    }
    arrelrelativa = res    
    imgrelpath = arrelrelativa + "images/"; 
    

    // refresca relatiu a precarrega d'imatges per fer el rollover de gencat
    if (document.images) {
    	tamany_11_Off = new Image(17,16); tamany_11_Off.src= imgrelpath + "mt11_0.gif";
    	tamany_11_On = new Image(17,16); tamany_11_On.src= imgrelpath + "mt11_1.gif";
    	tamany_14_Off = new Image(17,16); tamany_14_Off.src= imgrelpath + "mt14_0.gif";
    	tamany_14_On = new Image(17,16); tamany_14_On.src= imgrelpath + "mt14_1.gif";
    	tamany_17_Off = new Image(17,16); tamany_17_Off.src= imgrelpath + "mt17_0.gif";
    	tamany_17_On = new Image(17,16); tamany_17_On.src= imgrelpath + "mt17_1.gif";
    }
              
}

function substituir(s, sfind, sreplace)
{
    if(s == null) {return "";}
    if(s.length == 0) {return "";}
    if(sfind == null) {return s;}
    if(sfind.length == 0) {return s;}
    
    if(sreplace == null) {sreplace="";}
    
    var i, s1=s, s2="";
    
    while(1) {
        i = s1.indexOf(sfind)
        
        if(i>=0) {
            s2 += s1.substr(0,i) + sreplace 
            s1 = s1.substr(i + sfind.length)
        } else {
            s2 += s1
            return s2;
            break;
        }
    }
}

function imgrelatiu(html)
{
    return substituir(html,"=\""+arrelrelativa_inicial, "=\""+arrelrelativa);
}

function linkrelatiu(url)
{
    if(arrelrelativa_inicial.length == 0) { return url; }
    
    i = url.indexOf(arrelrelativa_inicial)
    if(i==0) {
        //if(url != "#" && url != "") {alert("rel " + url + "  " + url.substr(arrelrelativa_inicial.length))}
        return arrelrelativa + url.substr(arrelrelativa_inicial.length)
    } else {
        return url;
    }
}

function obrirajuda(fitxer,proves)
{
  
  if(fitxer != "" && fitxer != "#") {
    var loc = unescape(document.location.href)
    loc = loc.toLowerCase()

    var fileurl = fitxer
    if(pathabsolut_pag.length > 0 && loc.indexOf(pathabsolut_pag) > 0) {
        fileurl = pathabsolut_pag + fitxer
    }
    //status = fileurl + ' ' + document.location.href.indexOf(pathabsolut_pag) + ' ' + pathabsolut_pag
    var w2 = window.open(fileurl,'obrirajuda','width=700,height=400,top=100,left=139,scrollbars=yes,resizable=yes');
    if(w2) {w2.focus();}
  }
}


// si dibuixem les imatges dins del modul alvimenu.js podem fer ruta relativa de les imatges...

// precarrega d'imatges per fer el rollover de gencat
if (document.images) {
	tamany_11_Off = new Image(17,16); tamany_11_Off.src= imgrelpath + "mt11_0.gif";
	tamany_11_On = new Image(17,16); tamany_11_On.src= imgrelpath + "mt11_1.gif";
	tamany_14_Off = new Image(17,16); tamany_14_Off.src= imgrelpath + "mt14_0.gif";
	tamany_14_On = new Image(17,16); tamany_14_On.src= imgrelpath + "mt14_1.gif";
	tamany_17_Off = new Image(17,16); tamany_17_Off.src= imgrelpath + "mt17_0.gif";
	tamany_17_On = new Image(17,16); tamany_17_On.src= imgrelpath + "mt17_1.gif";
}


function imatge_a11()
{
	if(typeof tamanyCSS == "undefined" || tamanyCSS == "") {
		document.write("<img src='" + imgrelpath + "mt11_1.gif' name='img11' width=17 height=16 alt='mitj&agrave; 11' border=0>");
	} else if (tamanyCSS == "tamany11") {
		document.write("<img src='" + imgrelpath + "mt11_1.gif' name='img11' width=17 height=16 alt='mitj&agrave; 11' border=0>");
	} else {
		document.write("<img src='" + imgrelpath + "mt11_0.gif' name='img11' width=17 height=16 alt='mitj&agrave; 11' border=0>");
	}
}				

function imatge_a14() 
{
	if(typeof tamanyCSS == "undefined" || tamanyCSS == "") {
		document.write("<img src='" + imgrelpath + "mt14_0.gif' name='img14'  width=17 height=16 alt='gran 14' border=0>");
	} else if (tamanyCSS == "tamany14"){
		document.write("<img src='" + imgrelpath + "mt14_1.gif' name='img14'  width=17 height=16 alt='gran 14' border=0>");
	} else{
		document.write("<img src='" + imgrelpath + "mt14_0.gif' name='img14'  width=17 height=16 alt='gran 14' border=0>");
	}
}

function imatge_a17()
{
	if(typeof tamanyCSS == "undefined" || tamanyCSS == "") {
		document.write("<img src='" + imgrelpath + "mt17_0.gif' name='img17'  width=17 height=16 alt='m&agrave;xim 17' border=0>");
	} else if (tamanyCSS == "tamany17"){
		document.write("<img src='" + imgrelpath + "mt17_1.gif' name='img17'  width=17 height=16 alt='m&agrave;xim 17' border=0>");
	} else{
		document.write("<img src='" + imgrelpath + "mt17_0.gif' name='img17'  width=17 height=16 alt='m&agrave;xim 17' border=0>");
	}
}


// ESNET //////////////////////////////////////////////

// -- cookies -- //

function set_Cookie (name, value) 
{
  var argv = set_Cookie.arguments;
  var argc = set_Cookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}

//window.name="MAIN_WINDOW";

function get_Cookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    
    // busquem nom de la variable. Diferenciem al mig (;var=x) o principi
    var begin = dc.indexOf("; " + prefix);
    if (begin < 0)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return "";
    }
    else
    {
        begin += 2;
    }
    
    // fins el seguent ; o final
    var end = document.cookie.indexOf(";", begin);
    if (end < 0)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}


function del_Cookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

 /////////////////////////GESTIOPOPUP////////////////////////////////

// --- si la pagina te onload="..." no fara la crida automatica

var nomcookie = 'avispuntnet'
var marcamostratcookie = 'avispuntnetshown'

var nomcookieexpire = 'avispuntnetexpire'

var paginaavis = '/esnet/index.htm'

function gestiopopup_es()
{
    var i, loc = document.location.href;
    loc = loc.toLowerCase();
    i = loc.indexOf("http://cultura.gencat.es")
    var i2 = loc.indexOf("http://cultura.gencat.es/llengcat")
    
    if(i>=0 && i2<0) {
        // nomes ho fa si detecta http://cultura.gencat.es
    	if (get_Cookie(nomcookie) == marcamostratcookie && get_Cookie(nomcookieexpire) == marcamostratcookie) { 
    	        return; 
    	} else {
    	    // mostra popup
            var w2 = window.open(paginaavis,"POPUPCULTURANET","scrollbars=no,width=" + (325) + ",height=" + (175) + ",left=330,top=250");
            if(w2) {
				w2.focus();
            
				// control de cookies: si posem expires al tancar navegador no s'esborra => fem dos cookies
				var d = new Date();
				d.setSeconds(0);
				d.setMinutes(60);
				//d.setHours(d.getHours() + 1);

				set_Cookie(nomcookie, marcamostratcookie)       // no expira
				set_Cookie(nomcookieexpire, marcamostratcookie,d)   // expira una hora
			}
        }

    }
	

}

function canviurlnet()
{
    var es = "es";
    var net = "net";

    var u = document.location.href;
    var u2 = u.toLowerCase() + "/";
    
    var i = u2.indexOf("/",7)
    if(i<3) { return u; }

    if( u2.substr(i-2,es.length) == es ) {
        u2 = u.substr(0,i-es.length) + net + u.substr(i)
        //alert(u2)
        document.location.replace(u2)
    }
        
        
}

window.onload = gestiopopup_es




