//
// wt_js.js
//
//
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);
if (navigator.appName=="Netscape")
  {
  window.scrollbars.visible=false;
  }

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+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function EV_validCasForm() {
  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 número 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_validCatForm() {
  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 nombre ha d´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_validEngForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=EV_validEngForm.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+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.EV_valor = (errors == '');
}

function EV_validFraForm() {
  var i,p,q,nm,test,num,min,max,errors='',args=EV_validFraForm.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+' il faut e-mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' il faut numero.\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+' le numero il faut entre '+min+' et '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' obligatoire.\n'; }
  } if (errors) alert('Erreurs suivantes détectées:\n'+errors);
  document.EV_valor = (errors == '');
}


function EV_validItaForm() {
  var i,p,q,nm,test,num,min,max,errors='',args=EV_validItaForm.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+' indicare indirizzo di e-mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' introdurre un valore numerico.\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+' è obbligatorio.\n'; }
  } if (errors) alert('Errori:\n'+errors);
  document.EV_valor = (errors == '');
}

function EV_validPorForm() {
  var i,p,q,nm,test,num,min,max,errors='',args=EV_validPorForm.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+' deve ser um correio e-mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' deve 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+' o numero deve estar entre '+min+' y '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' é obrigatório.\n'; }
  } if (errors) alert('Há os seguintes erros:\n'+errors);
  else document.formu.submit();
  document.EV_valor = (errors == '');
}

function EV_aviso(msg)
  {
  alert(msg);
  }

function EV_foco(entrada)
  {
  entrada.focus()
  entrada.select()
  }

function EV_ventana(direc,nombre,parametros)
  {
  window.open(direc,nombre,parametros);
  }

function EV_iraURL()
  {
  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)
  {
  return eval(jsStr)
  }

function EV_cierra()
  {
  window.close()
  }

function EV_imprime()
  {
  window.print()
  }

function EV_confirma(frase,lugar,url) {
if (confirm(frase))
  {
  EV_iraURL(lugar,url); return document.EV_valor
  }
}

function EV_cambio() {
    window.moveTo(0,0);
    if (document.all) {
    top.window.resizeTo(778,547); //800 x 600
    }
    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 EV_vercapa(capa)
  // mostrar una capa si está oculta y ocultar si está visible
  {
  estado=document.getElementById(capa).style.visibility;
  if (estado=="visible") EV_oculta(capa);
  else EV_muestra(capa);
  }

function EV_muestra(capa){
document.getElementById(capa).style.visibility="visible";
}

function EV_oculta(capa){
document.getElementById(capa).style.visibility="hidden";
}

function EV_ocul_comarc()
  // ocultar todas las capas de las comarcas (hay 41)
  {
  var cap1,obj;
  for (i=1; i<50; i++)
    {
    if (i<10) cap1='co0'+i;
    else cap1='co'+i;
    if ((obj=document.getElementById(cap1))!=null) document.getElementById(cap1).style.visibility="hidden";
    }
}

function EV_ocul_entita()
  // ocultar todas las capas de las entidades (hay 40)
  {
  var cap1,cap2,obj;
  for (i=1; i<50; i++)
   {
    if (i<10) cap1='en0'+i;
    else cap1='en'+i;
    cap2=cap1+'s';
    if ((obj=document.getElementById(cap1))!=null) document.getElementById(cap1).style.visibility="hidden";
    if ((obj=document.getElementById(cap2))!=null) document.getElementById(cap2).style.visibility="hidden";
    }
}

function EV_ocul_botiga()
  // ocultar todas las capas de las botigues (hay 40)
  {
  var cap1,obj;
  for (i=1; i<50; i++)
    {
    if (i<10) cap1='bo0'+i;
    else cap1='bo'+i;
    if ((obj=document.getElementById(cap1))!=null) document.getElementById(cap1).style.visibility="hidden";
    }
}

function EV_ocul_deixal()
  // ocultar todas las capas de las deixallerias (hay xx)
  {
  var cap1,obj;
  for (i=1; i<100; i++)
    {
    cap1='de'+i;
    if (i<10) cap1='de0'+i;
    if ((obj=document.getElementById(cap1))!=null) document.getElementById(cap1).style.visibility="hidden";
    }
}

function EV_ocul_locala()
  // ocultar todas las capas de las localidades (hay 999)
  {
  var cap1,obj;
  for (i=1; i<1000; i++)
    {
    cap1='po'+i;
    if (i<10) cap1='po00'+i;
    else
      {
      if(i<100) cap1='po0'+i;
      }
    if ((obj=document.getElementById(cap1))!=null) document.getElementById(cap1).style.visibility="hidden";
    }
}

function EV_ocul_sector()
  // ocultar todas las capas de los sectores (hay 10)
  {
  var cap1,obj;
  for (i=0; i<10; i++)
    {
    cap1='sc0'+i;
    if ((obj=document.getElementById(cap1))!=null) document.getElementById(cap1).style.visibility="hidden";
    }
}

function EV_ocul_servei()
  // ocultar todas las capas de los servicios (hay < 100)
  {
  var cap1,obj;
  for (i=0; i<100; i++)
    {
    cap1='sv'+i;
    if (i<10) cap1='sv00'+i;
    else
      {
      if(i<100) cap1='sv0'+i;
      }
    if ((obj=document.getElementById(cap1))!=null) document.getElementById(cap1).style.visibility="hidden";
    }
}

function EV_sel_comba()
  // mostrar una capa por medio de un combo en botigues
  {
  var a = document.formu.comarca.options[document.formu.comarca.selectedIndex].value;
  EV_ocul_comarc();
  EV_ocul_botiga();
  MM_showHideLayers(a,'','show');
}

function EV_sel_combb()
  // mostrar una capa por medio de un combo en botigues roba amiga
  {
  var a = document.formu.botiga.options[document.formu.botiga.selectedIndex].value;
  EV_ocul_botiga();
  MM_showHideLayers(a,'','show');
}

function EV_sel_combe()
  // mostrar una capa por medio de un combo en entidades
  {
  var a = document.formu.entita.options[document.formu.entita.selectedIndex].value;
  var b = a+'s'
  EV_ocul_entita();
  MM_showHideLayers(a,'','show',b,'','show');
}

function EV_sel_deixa(elemen)
  // mostrar una capa por medio de un combo en deixalleries
  {
  var a = elemen.options[elemen.selectedIndex].value;
  EV_ocul_deixal();
  MM_showHideLayers(a,'','show');
}

function EV_sel_combi(elemen)
  // mostrar una capa por medio de un combo en botigues
  {
  var a = elemen.options[elemen.selectedIndex].value;
  //EV_ocul_comarc();
  EV_ocul_botiga();
  EV_ocul_locala();
  MM_showHideLayers(a,'','show');
}

function EV_sel_combo()
  // mostrar una capa por medio de un combo en localidad
  {
  var a = document.formu.comarca.options[document.formu.comarca.selectedIndex].value;
  EV_ocul_comarc();
  MM_showHideLayers(a,'','show');
}

function EV_sel_combs(elemen)
  // mostrar una capa por medio de un combo en sectors
  {
  var a = elemen.options[elemen.selectedIndex].value;
  EV_servei_cero();
  EV_ocul_sector();
  EV_ocul_servei();
  EV_ocul_entita();
  MM_showHideLayers(a,'','show');
}

function EV_sel_combt(elemen)
  // mostrar una capa por medio de un combo en serveis
  {
  var a = elemen.options[elemen.selectedIndex].value;
  EV_ocul_servei();
  EV_ocul_entita();
  MM_showHideLayers(a,'','show');
}


function EV_sel_combu()
  // mostrar la capa de comarca por medio de un combo
  {
  var a = document.formu.comarca.options[document.formu.comarca.selectedIndex].value;
  EV_ocul_comarc();
  EV_ocul_locala();
  EV_ocul_botiga();
  MM_showHideLayers(a,'','show');
}

function EV_selcombo(a,b)
  // poner la selección en combo box del formulario
  {
  eval(a+".selectedIndex="+b);
  }

function EV_NO_selcomba()
  // quitar la selección en los otros combo box del formulario
  {
  var i, args=EV_NO_selcombo.arguments;
  for (i=0;i<(args.length);i++)
    {
    eval(args[i]+".selectedIndex=0")
    }
  }

function EV_concapa(cap1,cap2)
  // mostrar una capa, cap1, si está visible otra, cap2
  {
  estado=document.getElementById(cap2).style.visibility;
  if (estado=="visible") document.getElementById(cap1).style.visibility="visible";
  }

function EV_servei_cero()
  // quitar la selección de un servicio en el combo (hay 8)
  {
  var cap1,sel1,sel2,obj;
  for (i=0; i<9; i++)
    {
    sel1 = 'for0'+i;
    sel2 = 'ser0'+i;
    cap1= "document."+sel1+"."+sel2;
    //if ((typeof eval(cap1) != 'undefined') && (typeof eval(cap1)!='null')) eval(cap1+".selectedIndex=0");
    eval(cap1+".selectedIndex=0");
    }
}

function EV_ver_pdf(elemen)
  // abrir ventana nueva con pdf en lista de combo
  {
  var a = '../docs/' + elemen.options[elemen.selectedIndex].value;
  if (a!='../docs/0') window.open(a,'acta','resizable=yes,width=600,height=420,top=0,left=0');
  }

function EnlaceVisitado(enlace,accion)
  {
  enlace.value="1";
  var a = accion;
  document.formu.action=a;
  document.formu.submit();
  }

function NO_selCB()
  // quitar la selección en los otros combo box del formulario
  {
  var i, args=NO_selCB.arguments;
  for (i=0;i<(args.length);i++)
    {
    eval(args[i]+".selectedIndex=0")
    }
  }

function Situa_Campo(campo,mensa)
  {
  alert(mensa);
  campo.focus();
  campo.select;
  }

function mailAnt1()
  {
  var usua = "wuto"
  var domi = "wuto.com"
  document.write("<a href=\"mailto:"+usua+"@"+domi+"\"")
  }

function mailAnt2()
  {
  var usua = "wuto"
  var domi = "wuto.com"
  document.write(usua+"@"+domi)
  }

function Ver_DadesFormEs()
  {
  var d = document.dades;
  var a01 = d.empres;
  var a02 = d.contac;
  var a03 = d.telefo;
  var a04 = d.emilio;
  // validar datos
  if (a01.value=='')
    {
    Situa_Campo(a01,'Es obligatorio informar nombre de la empresa');
    return document.EV_valor;
    }
  if (a02.value=='')
    {
    Situa_Campo(a02,'Es obligatorio informar persona de contacto');
    return document.EV_valor;
    }
  if ((a03.value=='')||(isNaN(a03.value))||(a03.value.length < 5))
    {
    Situa_Campo(a03,'Es obligatorio informar teléfono con números');
    return document.EV_valor;
    }
  if (a04.value=='')
    {
    Situa_Campo(a04,'Es obligatorio informar correo electrónico');
    return document.EV_valor;
    }
  if ((a04.value != "") & ((a04.value.indexOf('@',0)==-1)||(a04.value.length < 5)))
    {
    Situa_Campo(a04,'El correo no se ajusta al estandar');
    return document.EV_valor;
    }
  // envio si todo ha ido bien
  d.submit();
  }

function Ver_DadesFormCa()
  {
  var d = document.dades;
  var a01 = d.empres;
  var a02 = d.contac;
  var a03 = d.telefo;
  var a04 = d.emilio;
  // validar datos
  if (a01.value=='')
    {
    Situa_Campo(a01,'És obligatori informar nom de l´empresa');
    return document.EV_valor;
    }
  if (a02.value=='')
    {
    Situa_Campo(a02,'És obligatori informar persona de contacte');
    return document.EV_valor;
    }
  if ((a03.value=='')||(isNaN(a03.value))||(a03.value.length < 5))
    {
    Situa_Campo(a03,'És obligatori informar telèfon amb nombres');
    return document.EV_valor;
    }
  if (a04.value=='')
    {
    Situa_Campo(a04,'És obligatori informar correu electrònic');
    return document.EV_valor;
    }
  if ((a04.value != "") & ((a04.value.indexOf('@',0)==-1)||(a04.value.length < 5)))
    {
    Situa_Campo(a04,'El correu no s´ajusta al estandar');
    return document.EV_valor;
    }
  // envio si todo ha ido bien
  d.submit();
  }

function Ver_DadesFormEn()
  {
  var d = document.dades;
  var a01 = d.empres;
  var a02 = d.contac;
  var a03 = d.telefo;
  var a04 = d.emilio;
  // validar datos
  if (a01.value=='')
    {
    Situa_Campo(a01,'It is compulsory to inform company name');
    return document.EV_valor;
    }
  if (a02.value=='')
    {
    Situa_Campo(a02,'It is compulsory to inform contact person');
    return document.EV_valor;
    }
  if ((a03.value=='')||(isNaN(a03.value))||(a03.value.length < 5))
    {
    Situa_Campo(a03,'It is compulsory to inform telephone with numbers');
    return document.EV_valor;
    }
  if (a04.value=='')
    {
    Situa_Campo(a04,'It is compulsory to inform electronic mail');
    return document.EV_valor;
    }
  if ((a04.value != "") & ((a04.value.indexOf('@',0)==-1)||(a04.value.length < 5)))
    {
    Situa_Campo(a04,'It is compulsory to inform electronic mail');
    return document.EV_valor;
    }
  // envio si todo ha ido bien
  d.submit();
  }

function Ver_DadesFormFr()
  {
  var d = document.dades;
  var a01 = d.empres;
  var a02 = d.contac;
  var a03 = d.telefo;
  var a04 = d.emilio;
  // validar datos
  if (a01.value=='')
    {
    Situa_Campo(a01,'Il est obligatoire d´informer du nom de l´entreprise');
    return document.EV_valor;
    }
  if (a02.value=='')
    {
    Situa_Campo(a02,'Il est obligatoire d´informer sur la personne de contact');
    return document.EV_valor;
    }
  if ((a03.value=='')||(isNaN(a03.value))||(a03.value.length < 5))
    {
    Situa_Campo(a03,'Il est obligatoire d´informer du téléphone avec des números');
    return document.EV_valor;
    }
  if (a04.value=='')
    {
    Situa_Campo(a04,'Il est obligatoire d´informer sur le courrier électronique');
    return document.EV_valor;
    }
  if ((a04.value != "") & ((a04.value.indexOf('@',0)==-1)||(a04.value.length < 5)))
    {
    Situa_Campo(a04,'Il est obligatoire d´informer sur le courrier électronique');
    return document.EV_valor;
    }
  // envio si todo ha ido bien
  d.submit();
  }


