// JavaScript Document

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 muestra(id) {

	var elObj = MM_findObj(id);

	elObj.style.display = '';

}

function oculta(id) {

	var elObj = MM_findObj(id);

	elObj.style.display = 'none';

}

function genCod (campo, long) {

	cod = ""

	RI_chars = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9")

	RILong = RI_chars.length - 1

	if (long == "") {

		long = 12

	}

	for (i=0;i<long;i++) {

		pos = Math.round(RILong * Math.random())

		cod += RI_chars[pos]

	}

	elCampo = MM_findObj(campo)

	elCampo.value = cod

}

function cargaIds() {

	campo = MM_findObj('ids');

	campo.value = "";

	for(i=0;i<2000;i++) {

		elemento = MM_findObj('grupo_'+i);

		if (elemento) {

			if (elemento.checked == true) {

				campo.value += elemento.value+",";

			}

		}

	}

	eti = MM_findObj('etiqueta');

	if (campo.value != "" && eti.value != "") {

		window.document.forms['form2'].submit();

	} else {

		alert("Seleccione al menos un campo y el tipo de papel")	

	}

}

function cargaIds_u() {

	origen = MM_findObj('ids_print');

	destino = MM_findObj('ids');

	destino.value = origen.value

	eti = MM_findObj('etiqueta');

	if (destino.value != "" && eti.value != "") {

		window.document.forms['form2'].submit();

		//alert(destino.value)

	} else {

		alert("No ha seleccionado papel o no hay elementos a imprimir")	

	}

}

function selectAll(nombre) {

	for (i=0;i<2000;i++) {

		elemento = MM_findObj(nombre+"_"+i);

		if (elemento != null) {

			elemento.checked = true

		}

	}

	alert("Tenga en cuenta que generar un informe con todos los elementos seleccionados puede tardar varios minutos y sobrecargar el servidor.")

}



// Valida Fecha By Luciano 1998

// Uso: Simple... se debe pasar la cadena de la fecha y devuelve false si no es válida...

// El Formato es dd-mm-aaaa

// Ejemplo: if (Validar('14-08-1981')==false) { alert('Entrada Incorrecta') }

// Uso en formularios: onSubmit="return Validar(this.fecha.value)"

//

// Este script y otros muchos pueden

// descarse on-line de forma gratuita

// en El Código: www.elcodigo.com



function Validar(Cadena){

	var Fecha= new String(Cadena)	// Crea un string

	var RealFecha= new Date()	// Para sacar la fecha de hoy

	// Cadena Año

	var Ano= new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length))

	

	// Cadena Mes

	var Mes= new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")))

	// Cadena Día

	var Dia= new String(Fecha.substring(0,Fecha.indexOf("/")))



	// Valido el año

	if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){

        	alert('Año inválido')

			

		return false

	}

	// Valido el Mes

	if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){

		alert('Mes inválido')

		return false

	}

	// Valido el Dia

	if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31){

		alert('Día inválido')

		return false

	}

	if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {

		if (Mes==2 && Dia > 28 || Dia>30) {

			alert('Día inválido')

			return false

		}

	}

	

  //para que envie los datos, quitar las  2 lineas siguientes

  //alert("Fecha correcta.")

  return false	

}



function esFechaValida(fecha){

          if (fecha != undefined && fecha.value != "" ){

              if (!/^\d{2}\/\d{2}\/\d{4}$/.test(fecha.value)){

                  alert("formato de fecha no valido (dd/mm/aaaa)");

                  return false;

				  

              }

              var dia  =  parseInt(fecha.value.substring(0,2),10);

              var mes  =  parseInt(fecha.value.substring(3,5),10);

              var anio =  parseInt(fecha.value.substring(6),10);

          switch(mes){

              case 1:

              case 3:

              case 5:

              case 7:

              case 8:

              case 10:

              case 12:

                  numDias=31;

                  break;

              case 4: case 6: case 9: case 11:

                  numDias=30;

                  break;

              case 2:

                  if (comprobarSiBisisesto(anio)){ numDias=29 }else{ numDias=28};

                  break;

              default:

                  alert("Fecha introducida erronea");

                  return false;

				 

         }

              if (dia>numDias || dia==0){

                  alert("Fecha introducida erronea");

                  return false;

				   

              }

              return true;

           }

      }


