//
// funciones de JavaScript mas comunes
// EV_js.js
//
// funciones del dreamweaver
//
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

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;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

function MM_popupMsg(msg) { //v1.0
  alert(msg);
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe ser dirección e-mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' debe ser numérico.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' el numero debe estar entre '+min+' y '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es obligatorio.\n'; }
  } if (errors) alert('Hay los siguientes errores:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function EV_tiempo(tmLnName, myID) { //v1.2
  //Copyright 1997 Macromedia, Inc. All rights reserved.
  var i,j,tmLn,props,keyFrm,sprite,numKeyFr,firstKeyFr,propNum,theObj,firstTime=false;
  if (document.MM_Time == null) MM_initTimelines(); //if *very* 1st time
  tmLn = document.MM_Time[tmLnName];
  if (myID == null) { myID = ++tmLn.ID; firstTime=true;}//if new call, incr ID
  if (myID == tmLn.ID) { //if Im newest
    setTimeout('EV_tiempo("'+tmLnName+'",'+myID+')',tmLn.delay);
    fNew = ++tmLn.curFrame;
    for (i=0; i<tmLn.length; i++) {
      sprite = tmLn[i];
      if (sprite.charAt(0) == 's') {
        if (sprite.obj) {
          numKeyFr = sprite.keyFrames.length; firstKeyFr = sprite.keyFrames[0];
          if (fNew >= firstKeyFr && fNew <= sprite.keyFrames[numKeyFr-1]) {//in range
            keyFrm=1;
            for (j=0; j<sprite.values.length; j++) {
              props = sprite.values[j];
              if (numKeyFr != props.length) {
                if (props.prop2 == null) sprite.obj[props.prop] = props[fNew-firstKeyFr];
                else        sprite.obj[props.prop2][props.prop] = props[fNew-firstKeyFr];
              } else {
                while (keyFrm<numKeyFr && fNew>=sprite.keyFrames[keyFrm]) keyFrm++;
                if (firstTime || fNew==sprite.keyFrames[keyFrm-1]) {
                  if (props.prop2 == null) sprite.obj[props.prop] = props[keyFrm-1];
                  else        sprite.obj[props.prop2][props.prop] = props[keyFrm-1];
        } } } } }
      } else if (sprite.charAt(0)=='b' && fNew == sprite.frame) eval(sprite.value);
      if (fNew > tmLn.lastFrame) tmLn.ID = 0;
  } }
}

function MM_initTimelines() { //v4.0
    //MM_initTimelines() Copyright 1997 Macromedia, Inc. All rights reserved.
    var ns = navigator.appName == "Netscape";
    var ns4 = (ns && parseInt(navigator.appVersion) == 4);
    var ns5 = (ns && parseInt(navigator.appVersion) > 4);
    document.MM_Time = new Array(1);
    document.MM_Time[0] = new Array(1);
    document.MM_Time["trabajo"] = document.MM_Time[0];
    document.MM_Time[0].MM_Name = "trabajo";
    document.MM_Time[0].fps = 15;
    document.MM_Time[0][0] = new String("sprite");
    document.MM_Time[0][0].slot = 1;
    if (ns4)
        document.MM_Time[0][0].obj = document["blanco"];
    else if (ns5)
        document.MM_Time[0][0].obj = document.getElementById("blanco");
    else
        document.MM_Time[0][0].obj = document.all ? document.all["blanco"] : null;
    document.MM_Time[0][0].keyFrames = new Array(90, 104);
    document.MM_Time[0][0].values = new Array(4);
    if (ns5)
        document.MM_Time[0][0].values[0] = new Array("2px", "2px", "2px", "2px", "2px", "2px", "2px", "2px", "2px", "2px", "2px", "2px", "2px", "2px", "2px");
    else
        document.MM_Time[0][0].values[0] = new Array(2,2,2,2,2,2,2,2,2,2,2,2,2,2,2);
    document.MM_Time[0][0].values[0].prop = "left";
    if (ns5)
        document.MM_Time[0][0].values[1] = new Array("390px", "387px", "384px", "381px", "378px", "375px", "372px", "369px", "366px", "363px", "360px", "357px", "354px", "351px", "348px");
    else
        document.MM_Time[0][0].values[1] = new Array(390,387,384,381,378,375,372,369,366,363,360,357,354,351,348);
    document.MM_Time[0][0].values[1].prop = "top";
    if (!ns4) {
        document.MM_Time[0][0].values[0].prop2 = "style";
        document.MM_Time[0][0].values[1].prop2 = "style";
    }
    document.MM_Time[0][0].values[2] = new Array("100","3");
    document.MM_Time[0][0].values[2].prop = "zIndex";
    if (!ns4)
        document.MM_Time[0][0].values[2].prop2 = "style";
    if (ns5)
        document.MM_Time[0][0].values[3] = new Array("10px", "12px", "14px", "16px", "18px", "20px", "22px", "25px", "27px", "29px", "31px", "33px", "35px", "37px", "40px");
    else
        document.MM_Time[0][0].values[3] = new Array(10,12,14,16,18,20,22,25,27,29,31,33,35,37,40);
    document.MM_Time[0][0].values[3].prop = "height";
    if (!ns4)
        document.MM_Time[0][0].values[3].prop2 = "style";
    document.MM_Time[0].lastFrame = 104;
    for (i=0; i<document.MM_Time.length; i++) {
        document.MM_Time[i].ID = null;
        document.MM_Time[i].curFrame = 0;
        document.MM_Time[i].delay = 1000/document.MM_Time[i].fps;
    }
}

//
// funciones propias
//

function EV_validCatForm()
  // validar formulario con mensajes en catalan
  { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=EV_validCatForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' ha de ser adreça e-mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' ha de ser numèric.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' el numero ha de estar entre '+min+' i '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' és obligatori.\n'; }
  } if (errors) alert('Hi han els següents errors:\n'+errors);
  document.EV_valor = (errors == '');
}

function EV_validCasForm()
  // validar formulario con mensajes en castellano
  { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=EV_validCasForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe ser dirección e-mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' debe ser numérico.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' el numero debe estar entre '+min+' y '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es obligatorio.\n'; }
  } if (errors) alert('Hay los siguientes errores:\n'+errors);
  document.EV_valor = (errors == '');
}

function EV_aviso(msg)
  // abrir ventana de aviso
  {
  alert(msg);
  }

function EV_foco(entrada)
  // colocar el foco y seleccionar elemento de formulario
  {
  //document.form1.nif.focus()
  //document.form1.nif.select()
  entrada.focus()
  entrada.select()
  }

function EV_ventana(direc,nombre,parametros)
  // abrir nueva ventana de URL con parametros
  {
  window.open(direc,nombre,parametros);
  }

function NO_sele(elemen)
  // quitar la selección en un combo box de formulario
  {
  elemen.selectedIndex=0;
  }

function EV_iraURL()
  // redireccionar a otra URL
  {
  var i, args=EV_iraURL.arguments; document.EV_valor = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
  }

function EV_ejecutaJS(jsStr)
  // ejecutar JvaScript directo
  {
  return eval(jsStr)
  }

function EV_cierra()
  // cerrar ventana
  {
  window.close()
  }

function EV_imprime()
  // imprimir ventana
  {
  window.print()
  }

function EV_cambio() {
    window.moveTo(0,0);
    if (document.all) {
    top.window.resizeTo(screen.availWidth,screen.availHeight);
    }
    else if (document.layers||document.getElementById) {
    if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
    top.window.outerHeight = screen.availHeight;
    top.window.outerWidth = screen.availWidth;
    }
    }
  var i, args=EV_cambio.arguments; document.EV_valor = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function EV_fecha() {
    var hoy = new Date();
    eldia = hoy.getDate();
    elmes = hoy.getMonth();
    elano = hoy.getYear();
    if (eldia < "10") dia = "0" + eldia;
    else dia = eldia;
    if (elmes < "9") mes = "0" + (elmes + 1);
    else mes = elmes + 1;
    ano = elano.toString();
    document.write (dia);
    document.write ("/");
    document.write (mes);
    document.write ("/");
    document.write (ano.substring(4,2));
}

function mailAnti()
  {
  var usua = "info"
  var domi = "xarxaecosol.org"
  document.write("<a href=\"mailto:"+usua+"@"+domi+"\"")
  }
