/* ------------- */
/* FUNCIONS AJAX */
/* ------------- */

  var http_request = false;
  
  function AJAX_makeRequest (url, funcioAfterRequest ) {
    var data = new Date();
    var url  = url + "&SESSIO=" + data.getYear() + data.getMonth() + data.getDate() + data.getHours() + data.getMinutes() + data.getSeconds();
    http_request = false;
    if (window.XMLHttpRequest) {																// Mozilla, Safari,...
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); }
      } else if (window.ActiveXObject) { 														// IE
         try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); }
		 catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); }
		             catch (e) {}   }
      }
      if (!http_request) {
        alert('ERROR :( No ha estat possible crear una instància XMLHTTP');
        return false;
     }
     http_request.onreadystatechange = funcioAfterRequest;
     http_request.open('GET', url, true);
     http_request.send(null);
  }

/* ------------- */
/* FUNCIONS MENU */
/* ------------- */

  function CridaSubMenus( idpare ) {
    AJAX_makeRequest ("http://www.capgrossos.cat/cpg_AJAXSQL.php?OPCIO=SUBMENU&IDPARE=" + idpare, CridaSubMenus2);
  }
  function CridaSubMenus2() {
    if (http_request.readyState == 4) {
      if (http_request.status == 200) {
        document.getElementById("SUBMENU").innerHTML = http_request.responseText;
	  } else {
        document.getElementById("SUBMENU").innerHTML = "No s'ha pogut carregar el submenú!!";
	  }
	}
  }

  function ActivarUsuari( cami, camiWeb ) {
    var cadena = "<FORM NAME='FormUSUA' ACTION='" + cami + "' METHOD='POST' style='margin:0px;'>" 
           + " <table width='100%'><tr>"
	       + " <td style='padding-left:10px;'>"
	       + "   <INPUT class='Formu' NAME='USUA' TYPE='text' SIZE='8' MAXLENGTH='10' VALUE='Usuari' TITLE='Nom Usuari' onFocus='if(this.value==&quot;Usuari&quot;)this.value=&quot;&quot;;' autocomplete='off'>&nbsp;" 
           + "   <INPUT class='Formu' NAME='PASS' TYPE='password' SIZE='8' MAXLENGTH='10' VALUE='Clau' TITLE='Paraula de Pas' onFocus='if(this.value==&quot;Clau&quot;)this.value=&quot;&quot;;' autocomplete='off'>&nbsp;" 
		   + "   <INPUT class='Formu' NAME='OPCU' TYPE='hidden' VALUE='ACTIVAR'>"
	       + "   <INPUT class='Formu' NAME='BOTO' TYPE='submit' VALUE='Activar' style='background-color:#FFFF99;'>"
           + "   <br>Recordar-me com usuari&nbsp;<INPUT class='Formu' NAME='CONS' TYPE='checkbox' VALUE='1' CHECKED>&nbsp;"
		   + "   <font color='#D0F3FD'><i>( desactivar per ordinadors compartits )</i></font>" 
           + " </td><td align='right'>"
	       + "   <a href='" + camiWeb + "w_privada/privada_usua.php?OPC=NOU'><b><font color='#FFEEFF'>Encara no est&agrave;s registrat??<br>D&Oacute;NA'T D'ALTA!!</font></b></a>"
	       + " </td></tr></table>"
	       + "</FORM>";
    document.getElementById("SUBMENU").innerHTML = cadena;
  }

  var txtIni;
  function MostrarTitol ( text ) {
    if (text!="") {
	  txtIni = document.getElementById("txtTITOL").innerHTML;
      document.getElementById("txtTITOL").innerHTML = text;
	} else {
  	  document.getElementById("txtTITOL").innerHTML = txtIni;
	}
  }
  
/* ---------------- */
/* FUNCIONS DEFAULT */
/* ---------------- */

  function DesplegarVisor ( cami ) {
	if (parent.document.getElementById("VISOR_MARC").style.width == "300px") {
	  parent.document.getElementById("VISOR_MARC").style.width = "700px";
	  document.getElementById("btTancar").src = cami + "fletxa07esquerra.gif";
	  document.getElementById("btTancar").title = "recollir";
	} else {
	  parent.document.getElementById("VISOR_MARC").style.width = "300px";
	  document.getElementById("btTancar").src = cami + "fletxa07dreta.gif";
	  document.getElementById("btTancar").title = "expandir";
	}
  }
  
/* ------------- */
/* FRAMEs I DIVs */
/* ------------- */

  var mousex
  var mousey

  function getMouseXY(e) {												// IE6,FF,Moz,Opera7
    if (!e) e = window.event; 											// IE, (no per NS - we rely on NS passing us the event)
    if (e) { 
      if (e.pageX || e.pageY) { 											// FF,Moz,Opera7 (no per IE6)
        mousex = e.pageX;
        mousey = e.pageY;
        algor = '[e.pageX]';
        if (e.clientX || e.clientY) algor += ' [e.clientX] '
      } else if (e.clientX || e.clientY) { 								// IE6,FF,Moz,Opera7
        mousex = e.clientX + document.body.scrollLeft;
        mousey = e.clientY + document.body.scrollTop;
        algor = '[e.clientX]';
        if (e.pageX || e.pageY) algor += ' [e.pageX] '
      }  
    }
  }

  function MostrarOcultar( element ) {
    var idElement = document.getElementById( element );
    if (idElement.style.display=="none") {
     idElement.style.display="inline";
    } else {
     idElement.style.display="none";
    }
  }

  // ** s'utilitza?????????????????????????????????????????????????????????????????????????
  function MostrarDIV (id, e, origen ) {
    getMouseXY(e);
	if (origen) { mousex = mousex - parseInt(document.getElementById(id).style.width); }
    document.getElementById(id).style.left = mousex; // - 20;
    document.getElementById(id).style.top  = mousey;// - 20;
  }
  // ** s'utilitza?????????????????????????????????????????????????????????????????????????
  function OcultarDIV (id) {
    document.getElementById(id).style.left = -500;
    document.getElementById(id).style.top  = -500;
  }

/* ------------- */
/* LLISTES       */
/* ------------- */

  function lstOver ( obj ) { if (obj.className!="actiu") { obj.className="sobre";} }
  function lstOut  ( obj ) { if (obj.className!="actiu") { obj.className="inactiu"; } }
