function open_windows_m(openfile,openwindow)
{
  window.open(openfile,openwindow,'directories=no,resizable=yes,scrollbars=no,width=430,height=230,hotkeys=yes,top=0,left=0');
}

function open_windows_mts(openfile,openwindow)
{
  fecha  = new Date();
  tstamp = fecha.getTime();
  window.open(openfile+'&ts='+tstamp,openwindow,'directories=no,resizable=yes,scrollbars=no,width=440,height=230,hotkeys=yes,top=0,left=0');
}

function open_windows_a(page)
{
  window.open(page,"","directories=no,resizable=no,scrollbars=yes,width=600,height=530,top=10,left=10");
}

function open_windows_mu(openfile,openwindow)
{
  window.open(openfile,openwindow,'menubar=yes,directories=no,resizable=yes,scrollbars=yes,width=695,height=650,hotkeys=yes,top=0,left=0');
}

function open_windows_mb(page)
{
  window.open(page,"","directories=no,resizable=no,scrollbars=yes,width=600,height=520,top=10,left=10");
}

function open_windows_mbs(page)
{
  window.open(page,"","directories=no,resizable=no,scrollbars=yes,status=yes,width=600,height=520,top=10,left=10");
}

function open_windows_cc(page)
{
  window.open(page,"","directories=no,resizable=no,scrollbars=no,width=600,height=310,top=10,left=10");
}

function open_windows_s(openfile)
{
  nombre=parseInt(Math.random()*1000)
  window.open(openfile,nombre);
}

function open_windows_avsizes(page)
{
  window.open(page,"","directories=no,resizable=no,scrollbars=no,width=370,height=235,top=10,left=10");
}

function open_windows_media(openfile,openwindow,ancho,alto){
  //mitges de ba necessiten scroll bars (verticals, generalment)
  var myscrolls = '0'; var myancho=ancho; var myalto=alto;
  if (self.screen.availHeight<myalto){myancho+=15; myalto=self.screen.availHeight; myscrolls='1';}
  else {if (self.screen.availWidth<myancho){myalto+=15; myancho=self.screen.availWidth; myscrolls='1';}}
  window.open(openfile,openwindow,'directories=no,resizable=yes,scrollbars='+ myscrolls +',width='+myancho+',height='+myalto+',hotkeys=yes,top=0,left=0');
}

function open_windows_price(openfile,openwindow)
{
  window.open(openfile,openwindow,"directories=no,status=yes,resizable=yes,scrollbars=yes,width=725,height=535,top=10,left=10");
}

function saltarURL()
{
	box = document.formsalto.navi;
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = destination;
}

function open_windows_fac(openfile,openwindow)
{
window.open(openfile,openwindow,'menubar=yes,status=no,toolbar=no,location=no,directories=no,resizable=yes,scrollbars=yes,hotkeys=yes,width=820,height=475,top=0,left=0');
}

function open_windows_h(openfile,openwindow)
{
  window.open(openfile,openwindow,'directories=no,resizable=yes,scrollbars=no,width=505,height=527,hotkeys=yes,top=0,left=0');
}

function open_windows_v(openfile,openwindow)
{
  window.open(openfile,openwindow,'directories=no,resizable=yes,scrollbars=no,width=505,height=547,hotkeys=yes,top=0,left=0');
}

function open_windows_bah(openfile,openwindow)
{
  window.open(openfile,openwindow,'directories=no,resizable=yes,scrollbars=no,width=802,height=570,hotkeys=yes,top=0,left=0');
}

function open_windows_bav(openfile,openwindow)
{
  window.open(openfile,openwindow,'directories=no,resizable=yes,scrollbars=no,width=524,height=850,hotkeys=yes,top=0,left=0');
}

function goform(myurl)
{
  document.forms[0].action = myurl;
  document.forms[0].submit();
}

function selecc()
{
  window.open('selecc01b.asp','','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,width=600,height=500');
}

function open_windows_resizable(openfile, openwindow, width, height){
  window.open(openfile, openwindow, 'directories=no,resizable=yes,directories=0,status=0,menubar=0,scrollbars=1,width='+width+',height='+height)
}

/*
Envia el formulario.
  arguments[0]: numero del formulario
  arguments[1]: texto de confirm
*/
function enviarForm(){
  var numform   =  0;
  var tconfirm  = '';
  var enviar  = true;

  if (!isNaN(arguments[0])) {numform  = arguments[0];} else {enviar=false;}
  if (arguments.length>1)   {tconfirm = arguments[1];}
  if (tconfirm!='')         {if (!confirm(tconfirm)){enviar=false;}}
  if (enviar)               {document.forms[numform].submit();}
}

// Swap de imagenes modo dreamweaver
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_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;
}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.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];}
}

/*
Obtiene la distancia al borde superior de la pagina de un objeto imagen
imgElem : nombre de la capa
*/
function getTop(imgElem) {
  var yPos = 0;
	var imgMenu = document.images[imgElem];
	if(document.layers)	{yPos = imgMenu.y;}
	else if (imgMenu)	{
		if (document.getElementById) { //W3C DOM
			yPos = eval(imgMenu).offsetTop;
			tempEl = eval(imgMenu).offsetParent;
			while (tempEl != null) {
				yPos += tempEl.offsetTop;
				tempEl = tempEl.offsetParent;
			}
		}
		else { //navigator.appVersion.substr(0,3)=="4.0") //IE4 MAC
      yPos=0;
      obj=imgMenu;
      while (obj.tagName != 'HTML') {
        if (obj.parentNode) obj = obj.parentNode;
        else if (obj.parentElement) obj = obj.parentElement;
        if (obj.tagName.indexOf('T') == 0) {
          yPos += obj.offsetTop
        }
      }
      yPos=yPos+4;
	  }
  }
	return yPos;
}

/*
Obtiene la distancia al borde izquierdo de la pagina de un objeto imagen
imgElem : nombre de la capa
*/
function getLeft(imgElem) {
  var xPos = 0;
	var imgMenu = document.images[imgElem];
	if(document.layers)	{xPos = imgMenu.x;}
	else if (imgMenu)
  {
		if (document.getElementById) {//W3C DOM
			xPos = eval(imgMenu).offsetLeft;
			tempEl = eval(imgMenu).offsetParent;
			while (tempEl != null) {
				xPos += tempEl.offsetLeft;
				tempEl = tempEl.offsetParent;
			}
		}
		else { //navigator.appVersion.substr(0,3)=="4.0") //IE4 MAC
      xPos=0;
      obj=imgMenu;
      while (obj.tagName != 'HTML') {
        if (obj.parentNode) obj = obj.parentNode;
        else if (obj.parentElement) obj = obj.parentElement;
        if (obj.tagName.indexOf('T') == 0) {
          xPos += obj.offsetLeft
        }
      }
      //xPos=xPos+4;
	  }
  }
	return xPos;
}

/*
Ensenya una capa posicionantla relativa a una imatge que es passa, indicant distancia x i y
Si se li passa mes d'una capa, s'ha d'indicar totes les variables per cada una:
- nom de la capa
- imatge respecte a la que es vol posicionar (r)
- distancia x (dx)
- distancia y (dy)
*/
var sActiveLayer;
function showLayerRelative(){
  var i,r,v,dx,dy,obj,args=showLayerRelative.arguments;
  for (i=0; i<(args.length-3); i+=4) {
    if ((obj=MM_findObj(args[i]))!=null) {
      v='show';r=args[i+1];dx=args[i+2];dy=args[i+3];
      if (obj.style) { obj=obj.style; v='visible'; }
      obj.left=getLeft(r)+dx; obj.top=getTop(r)+dy;
      obj.visibility=v;
      sActiveLayer=args[i];
    }
  }
}

/*
Comprova si ja s'esta mostrant una capa abans d'ensenyar la capa que es mostra per defecte amb l'event onLoad
*/
function showLayerRelativeOnLoad(lay,ref,x,y){
  if (sActiveLayer==undefined) {
  	showLayerRelative(lay,ref,x,y);
  }
}

/*
Amaga una o mes capes que se li passen per parametre
Si el primer parametre es -1, envia les capes a l'esquerra de la pagina per evitar scroll horitzontal
*/
function hideLayer(){
  var i,v,obj,moveLeft,starti,args=hideLayer.arguments;
  if (args[0]==-1){starti=1;moveLeft=true} else {starti=0;moveLeft=false;}
  for (i=starti; i<(args.length); i++) {
    if ((obj=MM_findObj(args[i]))!=null) {
      v='hide';
      if (obj.style) { obj=obj.style; v='hidden'; }
      obj.visibility=v;
      if (moveLeft) { obj.left=0; }
    }
  }
}

/*
Abre una ventana de navegador a pantalla completa.
Si no es explorer, no puede utilizar fullscreen
*/
function openfullscreen(url){
  var params;
  if ((navigator.appName.indexOf('MSIE')!=-1)||(navigator.appName.indexOf('Microsoft')!=-1)){params='fullscreen';}
  else {params='left=0,top=0,screenX=0,screenY=0,width='+ screen.availWidth +',height='+ screen.availHeight;}
  window.open(url,"",params);
}

/*
Dialogo de confirm al que se le esta pasando el texto
*/
function confirmTexto(txt) {
  var agree=confirm(txt);
  if (agree) {return true} else {return false}
}

/*
Funcion para mostar un texto de confirmacion y ir a la URL seleccionada si se da al OK
*/
function onConfirmTextoGoto(confirm_txt, confirm_url){
  if (confirmTexto(confirm_txt)){
  	document.location.href=confirm_url;
  }
}

/*
Checks whether values in the form have been updated since the page was sent to client
myForm : form object we wish to check
*/
function formModified(myForm){
  if (myForm){
    var TheForm=myForm.elements;             //get form elements list
    for(var i=0;i<TheForm.length;i++){
      with (TheForm[i]){
        switch (type){
          case 'checkbox': case 'radio':
            if (checked!=defaultChecked){return(true);}
            break;
          case 'password': case 'text': case 'textarea':
            if (value!=defaultValue){return(true);}
            break;
          case 'select-one':
            if (!options[options.selectedIndex].defaultSelected){return(true);}
            break;
          case 'select-multiple': //check defaultSelected for each option
            break;
        }
      }
    }
  }
  return(false);
}

/*
If myForm was modified, ask for confirmation of mytxt before going to myLocation
myForm      : form object we wish to check
mytxt       : text shown to the user
myLocation  : location we wish to go to
*/
function onUnmodifiedGoTo(myForm, mytxt, myLocation){
  var letsgo=true;
  if (formModified(myForm)){letsgo=confirm(mytxt);}
  if (letsgo){document.location.href=myLocation;}
}


function open_licencia(doclegal)
{
  window.open(doclegal,'','directories=no,resizable=no,scrollbars=yes,width=600,height=530,top=10,left=10');
}

function doBlink() {
  // Blink, Blink, Blink...
  var blink = document.all.tags("BLINK")
  for (var i=0; i < blink.length; i++)
    blink[i].style.visibility = blink[i].style.visibility == '' ? 'hidden' : ''
}
function startBlink() {
  // Make sure it is IE4
  if (document.all)
    setInterval('doBlink()',1000)
}
//window.onload = startBlink;


/*
Amagar-ensenyar una capa.
capa  - div que volem amagar-ensenyar
estat - nou estat; si no es passa, invertim visibilitat
*/
function ExpandCollapse(capa,estat){
  var mycapa = document.getElementById(capa);
  switch (estat){
    case 'none' : case 'block' : case 'inline': break;
    default: estat='';
  }
  if (estat=='')
    {if (mycapa.style.display=='none') {mycapa.style.display='block';} else {mycapa.style.display='none';} /*alert(capa+': '+style.display);*/}
  else
    {mycapa.style.display=estat;}
  return(true)
}


/*
Trobar la posicio real d_un element
*/
function findPos(obj) {
	var curleft = curtop = 0;
  if (obj.offsetParent)
    do {
    			curleft += obj.offsetLeft;
    			curtop += obj.offsetTop;
    		} while (obj = obj.offsetParent); // = (nomes un signe igual) es correcte perque no volem comparar sino assignar.
	//return [curleft,curtop];  //si volem retornar un array
	return {x: curleft, y: curtop}; //si volem retornar un objecte amb propietats x,y
}