function ocultardiv(id) {
 //safe function to hide an element with a specified id
  if (document.getElementById) { // DOM3 = IE5, NS6
    document.getElementById(id).style.display = 'none';
  }
  else {
    if (document.layers) { // Netscape 4
      document.id.display = 'none';
    }
    else { // IE 4
      document.all.id.style.display = 'none';
    }
  }
}

function mostrardiv(id) {
 //safe function to show an element with a specified id

  if (document.getElementById) { // DOM3 = IE5, NS6
    document.getElementById(id).style.display = 'block';
  }
  else {
    if (document.layers) { // Netscape 4
      document.id.display = 'block';
    }
    else { // IE 4
      document.all.id.style.display = 'block';
    }
  }
}

function confirmarBorrado(){
 var agree=confirm("+Estás seguro de que quieres eliminar?");
  if (agree)
    return true ;
  else
    return false ;
}


var mensajeEMail   = "tiene que ser una direccion de e-mail";
var mensajeRellenaCampo = "Por favor rellena el campo";
var mensajeURL     = "tiene que ser una URL valida";
var mensajeFormularioNoExiste  = "El formulario no existe";
var mensajeCampoNoExiste = "El campo no existe";
var mensajeNumero = "El campo ha de ser numérico";


function _trim(str) {
  if(str) {
    str = str.replace(/^\s+/, "");
    str = str.replace(/\s+$/, "");
  }
  return str;
}

function compruebaFormulario() {
  var args = compruebaFormulario.arguments;
  var nombreFormulario = args[0];
  var mensaje = "";
  var arrayArgumento, longMinima, nombreCampo, tituloCampo, valorCampo, tipoComprobacion, campoSeleccionado;
  var contador, contador2, contador3;

  var numero_valido = /^[0-9]{0,8}$/i;

  if(document.forms[nombreFormulario]) {
    for(contador2 = 1; contador2 < args.length; contador2++) {
      arrayArgumento = args[contador2].split(":");
      nombreCampo = _trim(arrayArgumento[0]);
      tituloCampo = _trim(arrayArgumento[1]);

      if(!tituloCampo) tituloCampo = nombreCampo;
      tipoComprobacion = arrayArgumento[2];
      //longMinima = quitaEspacios(arrayArgumento[3]);
      longMinima = arrayArgumento[3];
      campoSeleccionado = document.forms[nombreFormulario].elements[nombreCampo];
      if(campoSeleccionado) {
        //valorCampo = quitaEspacios(campoSeleccionado.value);
        valorCampo = campoSeleccionado.value;

        if(valorCampo != "") {
          if(tipoComprobacion == "numero" && valorCampo.search(numero_valido) == -1) mensaje += '"' + tituloCampo + '" ' + mensajeNumero + "\n";
        }
        if(longMinima) {
          if(campoSeleccionado.length) {
            if(campoSeleccionado.options) {
              for(contador3 = contador = 0; contador3 < campoSeleccionado.options.length; contador3++) {
                if(campoSeleccionado.options[contador3].selected && campoSeleccionado.options[contador3].value != "") contador++;
              }
            }
            else for(contador3 = contador = 0; contador3 < campoSeleccionado.length; contador3++) {
              if(campoSeleccionado[contador3].checked) contador++;
            }
          }
          else if(campoSeleccionado.type == "checkbox") contador = campoSeleccionado.checked ? 1 : 0;
          else if(valorCampo.length < longMinima) mensaje += mensajeRellenaCampo + ' "' + tituloCampo + '"\n';
        }
      }
      else mensaje += mensajeCampoNoExiste + ': "' + nombreCampo + '"\n';
    }

    if(mensaje) alert(mensaje);
    else document.forms[nombreFormulario].submit();
  }
  else alert(mensajeFormularioNoExiste + ': "' + nombreFormulario + '"');
}




function detectarMayusculas(e){
  codigo_tecla=e.keyCode?e.keyCode:e.which;
  shift_pulsado=e.shiftKey?e.shiftKey:((codigo_tecla==16)?true:false);
  if(((codigo_tecla>=65&&codigo_tecla<=90)&&!shift_pulsado)||((codigo_tecla>=97&&codigo_tecla<=122)&&shift_pulsado))
    document.getElementById('avisoMayusculas').style.visibility = 'visible';
  else document.getElementById('avisoMayusculas').style.visibility = 'hidden';
}


