//SCRIPTS 1  Funciones basicas
var nav4 = window.Event ? true : false;

function confirmar( mensaje, destino) {
    if (confirm(mensaje)) {
        document.location = destino ;
        setTimeout("close();",1500);
        window.opener.history.go(0);
    }
}
function confirmar2( mensaje, destino) {
    if (confirm(mensaje)) {
        document.location = destino ;
    }
}

function acceptNum(evt){
     // NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57
     var key = nav4 ? evt.which : evt.keyCode;
     return (key <= 13 || (key >= 48 && key <= 57));
}

function ventana (URL,ANCHO,ALTO){
     ventana1 = window.open(URL,"ventana1","width="+ANCHO+", height="+ALTO+", scrollbars=yes, menubar=no, location=no, resizable=no")
     ventana1.focus();
}
function devuelveMunicipio(cp,mun,pro){
         //Se encarga de escribir en el formulario adecuado los valores seleccionados
         //también debe cerrar la ventana del calendario
         var formulario_destino = 'act'

         //meto el municipio
         eval ("opener.document.act.cod.value='" + cp + "'")
         eval ("opener.document.act.mun.value='" + mun + "'")
         eval ("opener.document.act.pro.value='" + pro + "'")
         window.close()
}

function devuelveCentro(idc,nomc,ide){
         //Se encarga de escribir en el formulario adecuado los valores seleccionados
         //también debe cerrar la ventana
         var formulario_destino = 'act'

         //meto el municipio
         eval ("opener.document.act.idc.value='" + idc + "'")
         eval ("opener.document.act.nomc.value='" + nomc + "'")
         eval ("opener.document.act.ide.value='" + ide + "'")
         window.close()
}

function devuelveCliente(idc,ap1,ap2,nom,nif,ccc,emp,m35){
         //Se encarga de escribir en el formulario adecuado los valores seleccionados
         //también debe cerrar la ventana
         var formulario_destino = 'm01'

         //meto el cliente
         eval ("opener.document.m01.idc.value='" + idc + "'")
         eval ("opener.document.m01.ap1.value='" + ap1 + "'")
         eval ("opener.document.m01.ap2.value='" + ap2 + "'")
         eval ("opener.document.m01.noc.value='" + nom + "'")
         eval ("opener.document.m01.nif.value='" + nif + "'")
         eval ("opener.document.m01.ccc.value='" + ccc + "'")
         eval ("opener.document.m01.emp.value='" + emp + "'")
         eval ("opener.document.m01.m35.value='" + m35 + "'")
         window.close()
}

//Validacion de email
function vemail(form) {

        if (form.value == "" || form.value.indexOf ('@', 0) == -1) {
                alert ("Email no válido");
                return (false);
        } else
                return (true);
}

//Validacion de Codigo Postal
function vcp(form) {

        if (form.value.length != 5) {
                alert ("Código Postal incorrecto");
                return (false);
        } else
                return (true);

}

//Validacion de campo obligatorio
function vobligatorio(form,nombre) {

        if (form.value.length < 1) {
                alert("El campo " + nombre + " NO puede estar vacío");
                return (false);
        } else
                return (true);
}
//Validacion de campo no obligatorio
function vvacio(form,nombre) {

        if (form.value.length < 1) {
                return (true);
        } else {
                alert ("El campo " + nombre + " DEBE estar vacío");
                return (false);
        }

}

//Validacion de NIF
function validar(abc) {

   dni=abc.substring(0,abc.length-1)
   let=abc.charAt(abc.length-1)
   if (!isNaN(let))
    {
     alert('Falta la letra del NIF')
     return (false);
    }
   else
    {
     cadena="TRWAGMYFPDXBNJZSQVHLCKET"
     posicion = dni % 23
     letra = cadena.substring(posicion,posicion+1)
     if (letra!=let.toUpperCase())
      {
       alert("NIF no válido")
       return (false);
      }
    }
    return (true);
}

//Validacion de CIF
function vcif(texto){

        var pares = 0;
        var impares = 0;
        var suma;
        var ultima;
        var unumero;
        var uletra = new Array("J", "A", "B", "C", "D", "E", "F", "G", "H", "I");
        var xxx;

        let=texto.charAt(0)

        if (!isNaN(let))
        {
         nif=texto;
         return validar(nif);
        }

        texto = texto.toUpperCase();

        var regular =/^[ABCDEFGHKLMNPQS]\d\d\d\d\d\d\d[0-9,A-J]$/g;
         if (!regular.exec(texto)){
          alert ("El campo CIF no es correcto");
          return (false);
         }

         ultima = texto.substr(8,1);

         for (var cont = 1 ; cont < 7 ; cont ++){
             xxx = (2 * parseInt(texto.substr(cont++,1))).toString() + 0;
             impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
             pares += parseInt(texto.substr(cont,1));
         }
         xxx = (2 * parseInt(texto.substr(cont,1))).toString();
         impares += parseInt(xxx.substr(0,1)) + parseInt(0 + xxx.substr(1,1));

         suma = (pares + impares).toString();
         unumero = parseInt(suma.substr(suma.length - 1, 1));
         unumero = (10 - unumero).toString();
         if(unumero == 10) unumero = 0;

         if ((ultima == unumero) || (ultima == uletra[unumero]))
             return (true);
         else {
             alert ("El campo CIF no es correcto");
             return (false);
         }

}

function checkNIF(texto){

    var letras=0;

    if(texto.length!=9)
        return ("-> El Nº Documento NO es correcto. Solo se permiten 9 caracteres\n");

    for (var i=0; i<texto.length; i++)
    {
      var ch = texto.substring (i, i+1);
      if ( (ch < "0" || ch > "9") && (ch < "a" || ch > "z") && (ch < "A" || ch > "Z") )
      {
        return ("-> El Nº Documento NO es correcto. Solo se admiten dígitos y letras\n");
      }
      if ( (ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z") )
      {
        letras++;
      }
    }
    if (letras>2 || letras<1)
    {
      return ("-> El Nº Documento NO es correcto\n");
    }
    return ("");
  }

//Obtencion Digito Control de CCC
function digitocontrol(cadena){
    var cifras = new Array(1,2,4,8,5,10,9,7,3,6);
    var chequeo = 0;
    for (var i=0; i < cifras.length; i++){
                chequeo += parseInt(cadena.charAt(i)) * cifras[i];
        }
    chequeo = 11 - (chequeo % 11);
        if (chequeo == 11) {chequeo = 0;}
        if (chequeo == 10) {chequeo = 1;}
    return chequeo;
}

//Validacion de CCC
function vccc(ccc) {

   var primer_control = "00" + ccc.value.substr(0,4) + ccc.value.substr(4,4);
   var segundo_control= ccc.value.substr(10,10);
   var dc= ccc.value.substr(8,1) + ccc.value.substr(9,1);


   if (ccc.value == "")
         alert("El campo CCC no puede estar vacío");
   else {
        if (ccc.value.length != 20)
           alert("El campo CCC está incompleto");
        else {
            if (!(digitocontrol("00" + ccc.value.substr(0,4) + ccc.value.substr(4,4)) == parseInt(ccc.value.substr(8,1))) ||
                  !(digitocontrol(ccc.value.substr(10,10)) == parseInt(ccc.value.substr(9,1)))){
                  alert("El campo CCC es incorrecto");
                  return (false);
            }
            else return (true);
        }
   }
}
function prestamo(num) {
   var cuenta = num.value;
   var total = 0;
   var suma1 = 0;
   var suma2 = 0;

   if(cuenta.length != 10)
      return ("-> El Nº Préstamo es incorrecto\n");

   else{
      var n1=parseInt(cuenta.charAt(0));
      var n2=parseInt(cuenta.charAt(1));
      var n3=parseInt(cuenta.charAt(2));
      var n4=parseInt(cuenta.charAt(3));
      var n5=parseInt(cuenta.charAt(4));
      var n6=parseInt(cuenta.charAt(5));
      var n7=parseInt(cuenta.charAt(6));
      var n8=parseInt(cuenta.charAt(7));
      var n9=parseInt(cuenta.charAt(8));
      var n10=parseInt(cuenta.charAt(9));

      var cn1=(n1*2)-9;
      if(cn1 <= 0)
         cn1 = n1*2;
      var cn3=(n3*2)-9;
      if(cn3 <= 0)
         cn3 = n3*2;
      var cn5=(n5*2)-9;
      if(cn5 <= 0)
         cn5 = n5*2;
      var cn7=(n7*2)-9;
      if(cn7 <= 0)
         cn7 = n7*2;
      var cn9=(n9*2)-9;
      if(cn9 <= 0)
         cn9 = n9*2;

      suma1 = cn1 + cn3 + cn5 + cn7 + cn9;

      suma2 = n2 + n4 + n6 + n8;

      total = suma1 + suma2;

      total = total.toString();

      control=total.charAt(total.length-1)

      if (control==0)
          digito = 0;
      else digito = 10-parseInt(control);

      if(n10==digito)
         return ("");
      else return ("-> El Nº Préstamo es incorrecto\n");
   }

}

function vfecha(input, nombre)
{
   if (input.length != 10) {
      alert("El campo " + nombre + " es incorrecto");
      return false;
   }
   for (j=0; j<input.length; j++) {
   //all figures and spacers in place?
     if ((j == 2) || (j == 5)) {
       if (input.charAt(j) != "/") {
         alert("El campo " + nombre + " es incorrecto");
         return false;
       }
     } else if ((input.charAt(j)<"0") || (input.charAt(j)>"9")) {
       alert("El campo " + nombre + " es incorrecto");
       return false;
     }
   }

//using right format dd/mm/yyyy and year 1900 or more? Change this for diff formats...

   bits = input.split("/");
   days = Number(bits[0]);
   month = Number(bits[1]);
   year=Number(bits[2]);
   if (days > 31 || month > 12 || year < 1900) {
       alert("El campo " + nombre + " es incorrecto");
       return false;
   }
   else return true;

}

//FUNCIONES DE VALIDACION PARA MODELO 01
//Validacion de campo obligatorio
function vobligatorio2(form,nombre) {

        if (form.value.length < 1) {
                return ("-> El campo " + nombre + " NO puede estar vacío\n");
                form.focus();
        } else
                return ("");
}
//Validacion de campo no obligatorio
function vvacio2(form,nombre) {

        if (form.value.length < 1) {
                return ("");
        } else {
                return ("-> El campo " + nombre + " DEBE estar vacío\n");
                form.focus();
        }

}

//Validacion de NIF
function validar2(abc) {

   dni=abc.substring(0,abc.length-1)
   let=abc.charAt(abc.length-1)
   if (!isNaN(let))
    {
     return ('-> Falta la letra del NIF\n');
    }
   else
    {
     cadena="TRWAGMYFPDXBNJZSQVHLCKET"
     posicion = dni % 23
     letra = cadena.substring(posicion,posicion+1)
     if (letra!=let.toUpperCase())
      {
       return ("-> NIF no válido\n");
      }
    }
    return ("");
}

//Validacion de CIF
function vcif2(texto){

        var pares = 0;
        var impares = 0;
        var suma;
        var ultima;
        var unumero;
        var uletra = new Array("J", "A", "B", "C", "D", "E", "F", "G", "H", "I");
        var xxx;

        let=texto.charAt(0)

        if (!isNaN(let))
        {
         nif=texto;
         return validar2(nif);
        }

        texto = texto.toUpperCase();

        var regular =/^[ABCDEFGHKLMNPQS]\d\d\d\d\d\d\d[0-9,A-J]$/g;
         if (!regular.exec(texto)){
          return ("-> El campo CIF no es correcto\n");
         }

         ultima = texto.substr(8,1);

         for (var cont = 1 ; cont < 7 ; cont ++){
             xxx = (2 * parseInt(texto.substr(cont++,1))).toString() + 0;
             impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
             pares += parseInt(texto.substr(cont,1));
         }
         xxx = (2 * parseInt(texto.substr(cont,1))).toString();
         impares += parseInt(xxx.substr(0,1)) + parseInt(0 + xxx.substr(1,1));

         suma = (pares + impares).toString();
         unumero = parseInt(suma.substr(suma.length - 1, 1));
         unumero = (10 - unumero).toString();
         if(unumero == 10) unumero = 0;

         if ((ultima == unumero) || (ultima == uletra[unumero]))
             return ("");
         else {
             return ("-> El campo CIF no es correcto\n");
         }

}

//Obtencion Digito Control de CCC
function digitocontrol2(cadena){
    var cifras = new Array(1,2,4,8,5,10,9,7,3,6);
    var chequeo = 0;
    for (var i=0; i < cifras.length; i++){
                chequeo += parseInt(cadena.charAt(i)) * cifras[i];
        }
    chequeo = 11 - (chequeo % 11);
        if (chequeo == 11) {chequeo = 0;}
        if (chequeo == 10) {chequeo = 1;}
    return chequeo;
}

//Validacion de CCC
function vccc2(ccc) {

   var primer_control = "00" + ccc.value.substr(0,4) + ccc.value.substr(4,4);
   var segundo_control= ccc.value.substr(10,10);
   var dc= ccc.value.substr(8,1) + ccc.value.substr(9,1);


   if (ccc.value == "")
         return ("-> El campo CCC no puede estar vacío\n");

   else if (ccc.value == "30230118005164673005")
         return ("-> El campo CCC no es válido\n");

   else if(ccc.value.substr(0,4) != "3023")
         return ("-> El campo CCC no pertenece a 3023\n");

   else {
        if (ccc.value.length != 20)
             return ("-> El campo CCC está incompleto\n");
        else {
            if (!(digitocontrol2("00" + ccc.value.substr(0,4) + ccc.value.substr(4,4)) == parseInt(ccc.value.substr(8,1))) ||
                  !(digitocontrol2(ccc.value.substr(10,10)) == parseInt(ccc.value.substr(9,1)))){
                  return ("-> El campo CCC es incorrecto\n");
            }
            else return ("");
        }
   }
}

function vfecha2(input, nombre)
{
   if (input.length != 10) {
      return ("-> El campo " + nombre + " es incorrecto (dd/mm/aaaa)\n");
   }
   for (j=0; j<input.length; j++) {
   //all figures and spacers in place?
     if ((j == 2) || (j == 5)) {
       if (input.charAt(j) != "/") {
         return ("-> El campo " + nombre + " es incorrecto (dd/mm/aaaa)\n");
       }
     } else if ((input.charAt(j)<"0") || (input.charAt(j)>"9")) {
       return ("-> El campo " + nombre + " es incorrecto (dd/mm/aaaa)\n");
     }
   }

//using right format dd/mm/yyyy and year 1900 or more? Change this for diff formats...

   bits = input.split("/");
   days = Number(bits[0]);
   month = Number(bits[1]);
   year=Number(bits[2]);
   if (days > 31 || month > 12 || year < 1900) {
       return ("-> El campo " + nombre + " es incorrecto\n");
   }
   else return ("");

}

// FUNCIONES VALIDACION CAMPOS DECIMALES
function formateo2(fld, milSep, decSep, e) {
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true; // Enter
    key = String.fromCharCode(whichCode); // Get key value from key code
    if (strCheck.indexOf(key) == -1) return false; // Not a valid key
    len = fld.value.length;
    for(i = 0; i < len; i++)
     if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
    aux = '';
    for(; i < len; i++)
     if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) fld.value = '';
    if (len == 1) fld.value = '0'+ decSep + '0' + aux;
    if (len == 2) fld.value = '0'+ decSep + aux;
    if (len > 2) {
     aux2 = '';
     for (j = 0, i = len - 3; i >= 0; i--) {
      if (j == 3) {
       aux2 += milSep;
       j = 0;
      }
      aux2 += aux.charAt(i);
      j++;
     }
     fld.value = '';
     len2 = aux2.length;
     for (i = len2 - 1; i >= 0; i--)
      fld.value += aux2.charAt(i);
     fld.value += decSep + aux.substr(len - 2, len);
    }
    return false;
}

function formateo(fld, milSep, decSep, e) {
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true; // Enter
    key = String.fromCharCode(whichCode); // Get key value from key code
    if (strCheck.indexOf(key) == -1) return false; // Not a valid key
    len = fld.value.length;
    for(i = 0; i < len; i++)
     if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
    aux = '';
    for(; i < len; i++)
     if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) fld.value = '';
    if (len == 1) fld.value = '0'+ decSep + '0' + aux;
    if (len == 2) fld.value = '0'+ decSep + aux;
    if (len > 2) {
     aux2 = '';
     for (j = 0, i = len - 3; i >= 0; i--) {
      if (j == 3) {
       aux2 += milSep;
       j = 0;
      }
      aux2 += aux.charAt(i);
      j++;
     }
     fld.value = '';
     len2 = aux2.length;
     for (i = len2 - 1; i >= 0; i--)
      fld.value += aux2.charAt(i);
     fld.value += decSep + aux.substr(len - 2, len);
    }
    return false;
}


function checkDecimals(fieldName, fieldValue, nombre) {

     decallowed = 6;  // how many decimals are allowed?

     if (isNaN(fieldValue) || fieldValue == "") {
         alert("Campo "+ nombre +" está vacío o contiene una cifra NO válida\nIntroduzca las cifras sin separadores de miles\n");
         return (false);
     }
     else {
         if (fieldValue.indexOf('.') == -1) fieldValue += ".";
         dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);

         if (dectext.length > decallowed)
         {
             alert ("No se permiten cifras con más de " + decallowed + " números decimales.");
             return (false);
         }
         else {
             return (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];}}
}


//Validacion de Formulario de Liquidacion
function runLiquidacion (form)  {

        if (!vobligatorio(form.ent,"Entidad")){
             form.ent.focus();
             return (false);
        }
        if (!vobligatorio(form.anio,"Año")){
             form.anio.focus();
             return (false);
        }
}


//Habilitar-Deshabilitar campos de cliente 2
function Cliente2(valor){

  if(document.m01.tid2.disabled == false ){
        document.m01.tid2.disabled = true
        document.m01.nif2.disabled = true
        document.m01.ap12.disabled = true
        document.m01.ap22.disabled = true
        document.m01.noc2.disabled = true
        document.m01.ccc2.disabled = true

        document.m01.tid2.value = ""
        document.m01.nif2.value = ""
        document.m01.ap12.value = ""
        document.m01.ap22.value = ""
        document.m01.noc2.value = ""
        document.m01.ccc2.value = ""
  }
  else {
        document.m01.tid2.disabled = false
        document.m01.nif2.disabled = false
        document.m01.ap12.disabled = false
        document.m01.ap22.disabled = false
        document.m01.noc2.disabled = false
        document.m01.ccc2.disabled = false
  }
}

//Funcion auxiliar para redondear decimales de un numero float
function redondear(num, dec){
    num = parseFloat(num);
    dec = parseFloat(dec);
    dec = (!dec ? 2 : dec);
    return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
}

function redireccion(url) {

       document.location.href=url;

}

function elegir_fecha(){
    alert ("Introduzca la fecha pulsando en Calendario");
}

function cambia(oCntrl,array,actual,valor){

   var indice;
   while (oCntrl.length) oCntrl.remove(0);
   for (var i=0;i<array[actual.value].length;i++){
        var selOpcion=new Option(array[actual.value][i][1], array[actual.value][i][0]);
        if (array[actual.value][i][0]==valor) indice=i;
        eval(oCntrl.options[i]=selOpcion);
   }
   oCntrl.selectedIndex=indice;
}

//Validacion Intros Provisiones, Devoluciones, Recibos, Recibos Col
function Intros (form)  {

         //Desactivamos boton del submit
        for (var b=0;b<form.elements.length;b++){ // por cada elemento del form
             var formEl = form.elements[b];
             // si el elemento es un botón de submit
             if ((formEl.tagName == "INPUT") && (formEl.getAttribute("type") != null) && ((formEl.getAttribute("type").toLowerCase() == "submit") )) {
                  var boton = form.elements[b];
                  boton.disabled = true; // desactivar botón
                  setTimeout(function(){boton.disabled = false;},3*1000);
             }
        }

        if (!vobligatorio(form.importe,"Importe")){
             form.importe.focus();
             return (false);
        }
        if (!vobligatorio(form.ide,"IdExpediente")){
             form.ide.focus();
             return (false);
        }
        if (!vobligatorio(form.fecha,"Fecha")){
             form.fecha.focus();
             return (false);
        }
        return (true);
}

function asignar_fechas(form, f1, f2){

      form.fec1.value = f1;
      form.fec2.value = f2;
      return;

}


function mayusculas (field){
      field.value = field.value.toUpperCase();
      return;
}

function IsNumeric(valor)
{
   var log=valor.length; var sw="S";
   for (x=0; x<log; x++){
     v1=valor.substr(x,1);
     v2 = parseInt(v1);
     //Compruebo si es un valor numérico
     if (isNaN(v2)) { sw= "N";}
   }
   if (sw=="S") {return true;} else {return false; }
}

var primerslap=false;
var segundoslap=false;

function formateafecha(fecha)
{
  var long = fecha.length;
  var dia;
  var mes;
  var ano;

  if ((long>=2) && (primerslap==false)) {
     dia=fecha.substr(0,2);
     if ((IsNumeric(dia)==true) && (dia<=31) && (dia!="00")) {
        fecha=fecha.substr(0,2)+"/"+fecha.substr(3,7); primerslap=true;
     }
     else { fecha=""; primerslap=false;}
  }
  else{
     dia=fecha.substr(0,1);
     if (IsNumeric(dia)==false) {fecha="";}
     if ((long<=2) && (primerslap=true)) {fecha=fecha.substr(0,1); primerslap=false; }
  }
  if ((long>=5) && (segundoslap==false)){
     mes=fecha.substr(3,2);
     if ((IsNumeric(mes)==true) &&(mes<=12) && (mes!="00")) { fecha=fecha.substr(0,5)+"/"+fecha.substr(6,4); segundoslap=true; }
     else { fecha=fecha.substr(0,3);; segundoslap=false;}
  }
  else { if ((long<=5) && (segundoslap==true)) { fecha=fecha.substr(0,4); segundoslap=false; } }
  if (long>=7){
     ano=fecha.substr(6,4);
     if (IsNumeric(ano)==false) { fecha=fecha.substr(0,6); }
     else { if (long==10){ if ((ano==0) || (ano<1900) || (ano>2100)) { fecha=fecha.substr(0,6); } } }
  }

  if (long>=10){
     fecha=fecha.substr(0,10);
     dia=fecha.substr(0,2);
     mes=fecha.substr(3,2);
     ano=fecha.substr(6,4);
     // Año no viciesto y es febrero y el dia es mayor a 28
     if ( (ano%4 != 0) && (mes ==02) && (dia > 28) ) { fecha=fecha.substr(0,2)+"/"; }
  }
  return (fecha);
}


function Seg_Central (form)  {

         //Desactivamos boton del submit
        for (var b=0;b<form.elements.length;b++){ // por cada elemento del form
             var formEl = form.elements[b];
             // si el elemento es un botón de submit
             if ((formEl.tagName == "INPUT") && (formEl.getAttribute("type") != null) && ((formEl.getAttribute("type").toLowerCase() == "submit") )) {
                  var boton = form.elements[b];
                  boton.disabled = true; // desactivar botón
                  setTimeout(function(){boton.disabled = false;},3*1000);
             }
        }

        if (!vobligatorio(form.rem,"Remitente")){
             form.rem.focus();
             return (false);
        }
        if (!vobligatorio(form.tipo,"Tipo Seguimiento")){
             form.tipo.focus();
             return (false);
        }
        if (!vobligatorio(form.fecha1,"Fecha Entrada")){
             form.fecha1.focus();
             return (false);
        }
        if (!vobligatorio(form.fecha2,"Fecha Vencimiento")){
             form.fecha2.focus();
             return (false);
        }
        if (!vobligatorio(form.des,"Descripcion")){
             form.des.focus();
             return (false);
        }
        return (true);
}
function irA(url){
   location.href = url;
}

//FIN FUNCIONES BASICAS
function Form_Caducada(form){
            if(form.passnew.value.length < 6){
               alert("La nueva clave debe tener como mínimo 6 caracteres");
               return (false);
            }
            else if(form.passact.value == form.passnew.value){
               alert("Las claves nueva y actual no pueden ser iguales");
               return (false);
            }
            else if(form.passnew.value != form.passnew2.value){
               alert("Las claves nueva y su repetición no coinciden");
               return (false);
            }
            return (true);
}

function accion(accion)
{
   document.anot.action = 'seguimiento.php?op='+accion;
   document.anot.submit();
}

function accion2(accion)
{
   document.anot.action = 'seguimiento_central.php?op='+accion;
   document.anot.submit();
}
function accion3(accion)
{
   document.anot.action = 'seguimiento_sscc.php?op='+accion;
   document.anot.submit();
}

function runSegSSCC(form){
        //Desactivamos boton del submit
        for (var b=0;b<form.elements.length;b++){ // por cada elemento del form
             var formEl = form.elements[b];
             // si el elemento es un botón de submit
             if ((formEl.tagName == "INPUT") && (formEl.getAttribute("type") != null) && ((formEl.getAttribute("type").toLowerCase() == "submit") )) {
                  var boton = form.elements[b];
                  boton.disabled = true; // desactivar botón
                  setTimeout(function(){boton.disabled = false;},3*1000);
             }
        }

        if (!vobligatorio(form.rem,"Remitente")){
           form.rem.focus();
           return (false);
        }

        if (!vobligatorio(form.fecha2,"Fecha Vencimiento")){
           form.fecha2.focus();
           return (false);
        }

        // Get the editor instance that we want to interact with.
        var oEditor = FCKeditorAPI.GetInstance( 'des' ) ;
        if (oEditor.GetHTML()==""){
             alert ('El campo Descripción NO puede estar vacío');
             return (false);
        }

        return (true);

}

function des_op_otras(valor){

         if(valor==65){
            var alerta1 = "Está dando de alta una Ampliación de plazo para vivienda habitual.\n";
            var alerta2 = "Esta operación ha sido bonificada hasta el 22 de Abril de 2010.\n";
         /*   var alerta3 = "1.- Los beneficiarios deben ser personas físicas.\n";
            var alerta4 = "2.- Los beneficiarios deben ser titulares de un préstamo con garantía hipotecaria para la construcción, rehabilitación o adquisición de su vivienda habitual. Esta medida no se aplica respecto de los créditos con garantía hipotecaria.\n";
            var alerta5 = "3.- La hipoteca ha de recaer sobre su vivienda habitual.\n";
            var alerta6 = "4.- La escritura pública que documente exclusivamente la ampliación de plazo se expida en papel común (no en papel timbrado).\n";
            var alerta7 = "5.- Si, junto a la ampliación del plazo, acordase con su entidad de crédito otras modificaciones de su préstamo hipotecario (alteración de tipo de interés, ampliación del capital, etc.), no podrá beneficiarse de la gratuidad de los costes notariales y registrales.\n";
            var alerta8 = "\nULTIMA HORA (15/8/09).- Los registros actualmente cobran un 10% de la factura real. Incrementamos la provisión de esta operación hasta los 100 euros.\n";
           */
            var alerta9 = "\nPara más información véase --> Ayuda --> Ampliaciones Plazo Bonificadas";
           // document.m01.iot.value = "100,00";
            alert(alerta1+alerta2+alerta9);
         }
         else
            document.m01.iot.value = ""
            

         if(valor==65 || valor==30 || valor==44 || valor==21) //OPeraciones para las que tienen que darnos Nominal préstamo
            document.getElementById('inot').style.display='block';
         else {
            document.getElementById('inot').style.display='none';
            document.m01.inot.value = "";
         }

         if(valor==16){ //Cálculo aprox. ACTA FINAL OBRA
            var alerta9 = "Ha seleccionado ACTA FINAL DE OBRA.\nCalculamos que los gastos de NOTARÍA pueden ser 500 euros, ";
            var alerta10 = "los de REGISTRO 90 euros por finca, y 150 euros como HONORARIOS de gestión.\n";
            var alerta11 = "Recuerde que estos cálculos son aproximados, para mayor seguridad consúltelo con su gestor.";
            var base = 90 * document.m01.nfi.value;
            document.m01.iot.value = 500 + base + 150;
            alert(alerta9+alerta10+alerta11);
         }

         if(valor==68){//operacion ANTICRESIS
            var alerta1 = "Ha seleccionado Anticresis, por lo que conviene lea la siguiente información:\n\n";
            var alerta2 = "Definición Anticresis: es un derecho real de garantía de carácter accesorio, en virtud del cual, el deudor ";
            var alerta3 = "cede al acreedor los frutos de la casa para aplicárselos al pago de la deuda y sus intereses.\n\n";
            var alerta4 = "Tributación: no tribura siempre y cuando su constitución sea simultánea a la constitución del Derecho ";
            var alerta5 = "Real de Hipoteca (ello por su carácter accesorio). ";
            var alerta6 = "En el caso de constitución independiente o sobre finca distinta de la que se hipoteca tributaría al 1% ";
            var alerta7 = "sobre el total de la responsabilidad del deudor, es decir, lo que se garantiza con el Derecho Real.\n\n";
            var alerta8 = "Para más información consulte con su gestoría.";
            alert(alerta1+alerta2+alerta3+alerta4+alerta5+alerta6+alerta7+alerta8);
         }

         if(valor==48){//operacion PIGNORACION
            var alerta1 = "Ha seleccionado PIGNORACION en protocolo independiente, por lo que conviene lea la siguiente información:\n\n";
            var alerta2 = "Definición PIGNORACION: Es un préstamo que tiene como garantía bienes muebles o valores bursátiles de fácil realización.\n\n";
            var alerta3 = "Tributaría al 1% sobre el total de la responsabilidad, además de los gastos de Notaría y Gestión.\n\n";
            var alerta4 = "El importe total sería el cálculo del impuesto más 500 euros aproximadamente.\n\n";
            var alerta5 = "Para más información consulte con su gestoría.";
            alert(alerta1+alerta2+alerta3+alerta4+alerta5);
         }

         return true;
}

function des_tipo_enlace(valor){
         if(valor=="Archivo"){
            document.enl.urlweb.value = "";
            document.enl.urlweb.disabled = true;
            document.enl.urlanexo.disabled = false;
         }
         else if(valor=="Web"){
            document.enl.urlanexo.value = "";
            document.enl.urlweb.value = "http://www..com";
            document.enl.urlanexo.disabled = true;
            document.enl.urlweb.disabled = false;
         }
         return true;
}

function Form_Enlaces(form){
        //Desactivamos boton del submit
        for (var b=0;b<form.elements.length;b++){ // por cada elemento del form
             var formEl = form.elements[b];
             // si el elemento es un botón de submit
             if ((formEl.tagName == "INPUT") && (formEl.getAttribute("type") != null) && ((formEl.getAttribute("type").toLowerCase() == "submit") )) {
                  var boton = form.elements[b];
                  boton.disabled = true; // desactivar botón
                  setTimeout(function(){boton.disabled = false;},3*1000);
             }
        }

        if (!vobligatorio(form.tipo,"Tipo")){
           form.tipo.focus();
           return (false);
        }

        if(form.tipo.value=="Archivo"){
           if (!vobligatorio(form.urlanexo,"Archivo")){
                form.urlanexo.focus();
                return (false);
           }
        }
        else if (form.tipo.value=="Web"){
           if (!vobligatorio(form.urlweb,"Web")){
                form.urlweb.focus();
                return (false);
           }
        }

        if (!vobligatorio(form.desc,"Descripción")){
           form.desc.focus();
           return (false);
        }
        return (true);
}

//Introduccion de pagos y cobros
function des_tipo_pago(valor,exp){
         if(valor=='Liquidacion a Cliente')
             document.fm.con.value = "N/PAGO LIQUIDACION A CLIENTE EXP: " + exp;
         else if(valor=='Liquidacion a Colaborador')
             document.fm.con.value = "N/PAGO LIQUIDACION A COLABORADOR EXP: " + exp;
         else if(valor=='Honorarios a Colaborador')
             document.fm.con.value = "N/PAGO HONORARIOS A COLABORADOR EXP: " + exp;
}

function des_estado_pago(valor){
         if(valor=='Procesado')
             document.fm.cont.value = "SI";
         else if(valor=='Pte.Procesar')
             document.fm.cont.value = "NO";
}

function Intro_Pagos (form)  {

         //Desactivamos boton del submit
        for (var b=0;b<form.elements.length;b++){ // por cada elemento del form
             var formEl = form.elements[b];
             // si el elemento es un botón de submit
             if ((formEl.tagName == "INPUT") && (formEl.getAttribute("type") != null) && ((formEl.getAttribute("type").toLowerCase() == "submit") )) {
                  var boton = form.elements[b];
                  boton.disabled = true; // desactivar botón
                  setTimeout(function(){boton.disabled = false;},3*1000);
             }
        }

        if (!vobligatorio(form.tipo,"Tipo Pago")){
             form.tipo.focus();
             return (false);
        }
        if (!vobligatorio(form.imp,"Importe")){
             form.imp.focus();
             return (false);
        }
        if (!vobligatorio(form.fec,"Fecha")){
             form.fec.focus();
             return (false);
        }
        if (!vobligatorio(form.con,"Concepto")){
             form.con.focus();
             return (false);
        }
        if (!vobligatorio(form.est,"Estado")){
             form.est.focus();
             return (false);
        }
        if (!vobligatorio(form.cont,"Contabilizar")){
             form.cont.focus();
             return (false);
        }
        return (true);
}

//////////////////////

function des_tipo_cobro(valor,exp){
         if(valor=='Provision Inicial Total'){
             document.fm.con.value = "S/PAGO PROVISION INICIAL EXP: " + exp;
             document.getElementById("recurso").style.display = "none";
         }
         else if(valor=='Liquidacion a Cliente'){
             document.fm.con.value = "S/PAGO LIQUIDACION A CLIENTE EXP: " + exp;
             document.getElementById("recurso").style.display = "none";
         }
         else if(valor=='Liquidacion a Colaborador'){
             document.fm.con.value = "S/PAGO LIQUIDACION A COLABORADOR EXP: " + exp;
             document.getElementById("recurso").style.display = "none";
         }
         else if(valor=='Liquidacion Recurso'){
             document.fm.con.value = "S/PAGO LIQUIDACION RECURSO EXP: " + exp;
             document.getElementById("recurso").style.display = "block";
         }
}

function des_estado_cobro(valor){
         if(valor=='Procesado')
             document.fm.cont.value = "SI";
         else if(valor=='Pte.Procesar')
             document.fm.cont.value = "NO";
}

function Intro_Cobros (form)  {

         //Desactivamos boton del submit
        for (var b=0;b<form.elements.length;b++){ // por cada elemento del form
             var formEl = form.elements[b];
             // si el elemento es un botón de submit
             if ((formEl.tagName == "INPUT") && (formEl.getAttribute("type") != null) && ((formEl.getAttribute("type").toLowerCase() == "submit") )) {
                  var boton = form.elements[b];
                  boton.disabled = true; // desactivar botón
                  setTimeout(function(){boton.disabled = false;},3*1000);
             }
        }

        if (!vobligatorio(form.tipo,"Tipo Pago")){
             form.tipo.focus();
             return (false);
        }
        if (!vobligatorio(form.imp,"Importe")){
             form.imp.focus();
             return (false);
        }
        if (form.tipo.value=="Liquidacion Recurso"){
            if (!vobligatorio(form.int,"Intereses Recurso")){
                 form.int.focus();
                 return (false);
            }
        }
        if (!vobligatorio(form.fec,"Fecha")){
             form.fec.focus();
             return (false);
        }
        if (!vobligatorio(form.con,"Concepto")){
             form.con.focus();
             return (false);
        }
        if (!vobligatorio(form.est,"Estado")){
             form.est.focus();
             return (false);
        }
        if (!vobligatorio(form.cont,"Contabilizar")){
             form.cont.focus();
             return (false);
        }
        return (true);
}

function ver_des_seg(id){
        if(document.getElementById(id).style.display == "none")
           document.getElementById(id).style.display = "block";
        else
           document.getElementById(id).style.display = "none";
}

//Funciones gestion directorios con js
function getFolder(){
  return showModalDialog("folderDialog.html","","width:400px;height:400px;resizeable:yes;");
}

function expandir_capa(idCapa){
       if(document.getElementById(idCapa).style.display == "block"){
               document.getElementById(idCapa).style.display = "none";
       }else {
               document.getElementById(idCapa).style.display = "block";
       }
}