// JavaScript Document

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}



/*****************************************/
/*  Elements de Flash                    */
/*****************************************/

function flash_element(titol,arxiu,x,y)
{
document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='" + x + "' height='" + y +  "' title='" + titol + "'><param name='movie' value='" + arxiu + "'><param name='quality' value='high'><param name='menu' value='false'><embed src='" + arxiu + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + x + "' height='" + y + "'></embed></object>");
}

function flash_element_trans(titol,arxiu,x,y)
{
document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='" + x + "' height='" + y +  "' title='" + titol + "'><param name='movie' value='" + arxiu + "'><param name='quality' value='high'><param name='menu' value='false'><param name='wmode' value='transparent'><embed src='" + arxiu + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + x + "' height='" + y + "' wmode='transparent'></embed></object>");
}


/******************************************************************/
/******************************************************************/

//      POSA IMATGES !!!!!

/******************************************************************/
/******************************************************************/

function posaImg(obj,src)
{
    if (obj){
        obj.src = src;
    }else{
        document.getElementById(obj).src = src;
    }
}


/******************************************************************/
/******************************************************************/

//      ENQUESTES !!!!!

/******************************************************************/
/******************************************************************/

function quinRadioValor(aradio)
{
    var i;
    for (i=0;i<aradio.length;i++)
    {
        if (aradio[i].checked)
        {
            return  aradio[i].value;
        }
    }
    return null;   
}
//query string
function creaQS()
{
    var cadena;
    cadena = "n=" + document.getElementById('nopcions').value;
    cadena += "&o=" + quinRadioValor(document.getElementsByName('opcions'));
    cadena += "&e=" + document.getElementById('idenquesta').value;
    return cadena;
}


//ull !!! galeta.js ha d'estar inclós abans que aquest lib.js
function selecciona(radio,idenquesta)
{
    //posem la cookie
    createCookie("enquesta",idenquesta,"366");
    //votem i mostrem els resultats
    radio.checked = true;
    cridaiposa_post('enquesta_resultats.asp','resultat',creaQS());
    var obj = document.getElementById('opcions_tr');
    obj.style.visibility = 'hidden';
    obj.parentNode.removeChild(obj);
    document.getElementById('resultat').style.visibility = 'visible';
}

//aquesta és la que usava abans de les cookies, ull !! que té menys arguments !!
function selecciona_no_cookies(radio)
{
    radio.checked = true;
    cridaiposa_post('enquesta_resultats.asp','resultat',creaQS());
    var obj = document.getElementById('opcions_tr');
    obj.style.visibility = 'hidden';
    obj.parentNode.removeChild(obj);
    document.getElementById('resultat').style.visibility = 'visible';
}

/************************************************************

UTILS 

*************************************************************/

/*

Obre POPUPS

*/

function pop_up(img)
{
    var ruta = img.src;
    
    ruta = ruta.replace('petites','grans');
    //alert(ruta);
    window.open('funcions/popup.asp?r=' + ruta,'popup_img','resizable=no');
}


/******************************************************************

Posa la div a l'index amb alló dels "No t'ho perdis"


- Has d'incluir ajax.js abans que aquest !!!!!

*******************************************************************/

/******************************************************************

Posa la div a l'index amb alló dels "No t'ho perdis"


- Has d'incluir ajax.js abans que aquest !!!!!
- esta també a lib.js

*******************************************************************/

function posaDiv()
{
   // window.toolbars = 0;
    if (!document.getElementById("tapador"))
    {
        var ndiv = document.createElement('div');
        //ndiv.setAttribute('id','tapador');
        //ndiv.setAttribute('class','transparent');
        ndiv.id = 'tapador';
        //ndiv.style.height = '100%';
        ndiv.style.height = '1040';
        ndiv.style.width = '100%';
        
        
        //seria gran algo així
        //ndiv.style.height = document.body.height;
        //ndiv.style.width = document.body.width;
        
        
        ndiv.style.position = 'absolute';
        ndiv.style.top = '0';
        ndiv.style.left = '0';
        ndiv.style.backgroundColor = '#ffffff';
        
            ndiv.style.opacity = '0.6';
            ndiv.style.MozOpacity = '0.6';
            ndiv.style.filter = "alpha(opacity = 60";
            //ndiv.setAttribute('style','filters:alpha(opacity=60)');
        document.body.appendChild(ndiv);   
        //ndiv.className = 'transparent';
        //alert('hi és'); 
    }
   
    if (!document.getElementById("contenidor_missatge"))
    {
        var pdiv = document.createElement('div');
        pdiv.id = 'contenidor_missatge';
        pdiv.style.height = '100%';
        pdiv.style.width = '100%';
        pdiv.style.top = '0';
        pdiv.style.left = '0';
        pdiv.style.position = 'absolute';
        document.body.appendChild(pdiv);
    } 
        
        cridaiposa('plantilles/div.asp','contenidor_missatge');
    
    
}


function posaDivAdvertencia()
{
    //window.toolbars = false;
    if (!document.getElementById("tapador"))
    {
        var ndiv = document.createElement('div');
        //ndiv.setAttribute('id','tapador');
        //ndiv.setAttribute('class','transparent');
        ndiv.id = 'tapador';
        ndiv.style.height = '100%';
        ndiv.style.width = '100%';
        ndiv.style.position = 'absolute';
        ndiv.style.top = '0';
        ndiv.style.left = '0';
        ndiv.style.backgroundColor = '#ec6e00';
        
            ndiv.style.opacity = '0.6';
            ndiv.style.MozOpacity = '0.6';
            ndiv.style.filter = "alpha(opacity = 60";
            //ndiv.setAttribute('style','filters:alpha(opacity=60)');
        document.body.appendChild(ndiv);   
        //ndiv.className = 'transparent';
        //alert('hi és'); 
    }
   
    if (!document.getElementById("contenidor_missatge"))
    {
        var pdiv = document.createElement('div');
        pdiv.id = 'contenidor_missatge';
        pdiv.style.height = '100%';
        pdiv.style.width = '100%';
        pdiv.style.top = '0';
        pdiv.style.left = '0';
        pdiv.style.position = 'absolute';
        document.body.appendChild(pdiv);
    } 
        
        cridaiposa('plantilles/advertencia.asp','contenidor_missatge');
    
    
}


function tancaDiv()
{
    var obj = document.getElementById('contenidor_missatge');
    document.body.removeChild(obj);
    var obj = document.getElementById('tapador');
    document.body.removeChild(obj);
    //window.toolbars = 1;
}

/**************************************************************************

// Per canviar la imartge i el text d'mp3 i pdf amb el mouseover

***************************************************************************/

function canviaOver(img_name,img_src,id_text,class_text)
{
        MM_swapImage(img_name,'',img_src,1);  
        document.getElementById(id_text).className = class_text;
}

function canviaOut(img_name,id_text,class_text)
{
    MM_swapImgRestore();
    document.getElementById(id_text).className=class_text;
}