// JavaScript Document

function vld_anular()
{ 
	return confirm('¿Comfirma que desea ANULAR el documento?');
} 

function vld_eliminacion()
{ 
	return confirm('¿Comfirma que desea ELIMINAR el elemento seleccionado?');
} 

function if_tecla_13(e,texto)
{
	var tecla = e.keyCode;
	if( !tecla ) {tecla = e.which;}

	if( tecla == 13 ) return confirm(texto);
	
	return true;
}

function es_tecla_13(e)
{
	var tecla = e.keyCode;
	if( !tecla ) {tecla = e.which;}

	if(tecla == 13) {return true;}
	return false;
}

function vld_numeros_enteros(e)
{
	var tecla = e.keyCode;
	if( !tecla ) {tecla = e.which;}

	if (tecla == 8){ return true; }
	if (tecla == 37){ return true; }
	if (tecla == 38){ return true; }
	if (tecla == 39){ return true; }
	if (tecla == 40){ return true; }
	if(tecla == 13) {return true;}
	if ( tecla > 47 && tecla < 58 ){ return true; }
	else {
		if (tecla == 8){ return true; }
		if (tecla == 0){ return true; }
		return false;
	}
}

function vld_numeros_cuit(e)
{
	var tecla = e.keyCode;
	if( !tecla ) {tecla = e.which;}
	
	if (tecla == 8){ return true; }
	if (tecla == 37){ return true; }
	if (tecla == 38){ return true; }
	if (tecla == 39){ return true; }
	if (tecla == 40){ return true; }
	if (tecla == 45) {return true;}
	if (tecla == 13) {return true;}
	if ( tecla > 47 && tecla < 58 ){ return true; }
	else {
		if (tecla == 8){ return true; }
		if (tecla == 0){ return true; }
		return false;
	}
}

function vld_numeros_double(e)
{
	var tecla = e.keyCode;
	if( !tecla ) {tecla = e.which;}

	if (tecla == 8){ return true; }
	if (tecla == 46){ return true; }
	if (tecla == 45){ return true; }
	if (tecla == 37){ return true; }
	if (tecla == 38){ return true; }
	if (tecla == 39){ return true; }
	if (tecla == 40){ return true; }
	if(tecla == 13) {return true;}
	if ( tecla > 47 && tecla < 58 ){ return true; }
	else {
		if (tecla == 8){ return true; }
		if (tecla == 0){ return true; }
		return false;
	}
}

function vld_caracteres_fecha(e)
{
	var tecla = e.keyCode;
	if( !tecla ) {tecla = e.which;}

	if (tecla == 8){ return true; }
	if (tecla == 37){ return true; }
	if (tecla == 38){ return true; }
	if (tecla == 39){ return true; }
	if (tecla == 40){ return true; }
	if (tecla == 0){ return true; }
	if(tecla == 13) {return true;}
	if(tecla == 47) {return true;}
	if ( tecla > 47 && tecla < 58 ){ return true; }
	else {
		return false;
	}
}

function vld_fecha(e)
{
	 var Cadena = e.value;
     var Fecha= new String(Cadena);
     var RealFecha= new Date();

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

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

     var Dia= new String(Fecha.substring(0,Fecha.indexOf("/")))  ;
 
	if( Ano == "" || Mes == ""  || Dia == "" )
	{
         alert('La fecha ingresada no posee el formato: DD/MM/AAAA') ;
         e.focus();
         return false ; 		
	}

     if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31){  
         alert('Día inválido') ;
         e.focus();
         return false  ;
     }  
     	
     if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){  
         alert('Mes inválido') ;
         e.focus();
         e.select();
         return false;
     }       
     
     if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){  
         alert('Año inválido') ;
         e.focus();
         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');
             e.focus();
             return false;  
         }  
     }  

   return true;  
}


function vld_no_vacio(e)
{
	
	if( !e || e.value == "" || e.value == e.alt ||  e.value == e.title )
	{
		if( e.alt || e.title ) 
		{
			if( e.alt ) alert('Olvidaste completar el campo: ' + e.alt );
			if( e.title ) alert('Olvidaste completar el campo: ' + e.title );
			if( !e.alt && !e.title ) alert('Olvidaste completar el campo.' );	
		}
		else alert('Olvidaste completar el campo.');

		if( e && e.type != 'hidden' ) e.focus();
		return false;
		
	} else {
		return true;
	}
	
}

function vld_mail(mail)
{
	var filter=/^[A-Za-z0-9][A-Za-z0-9_.-]*@[A-Za-z0-9_.-]+\.[A-Za-z0-9]+[A-za-z]$/;
	if ( mail.value == "" ) {return true;}	
	if (!filter.test(mail.value))	
	{
		alert("El formato de la direccion de mail no es válido.");
		mail.focus();
		return false;
	}

	return true;

}   

function vld_aCheckbox(aCheckbox,nombre_campo)
{
	var validar; 
	
	for (i=0;i< aCheckbox.length;i++)
	{
		if ( aCheckbox[i].checked) validar = true ;
	}
		
	if ( !validar  )	
	{
		alert("No se seleccionó un valor en: " + nombre_campo);
		aCheckbox[0].focus();
		return false;
	}

	return true;

} 


function vld_iguales(a,b)
{
	
	if(a.value != b.value)
	{
		alert('Los valores ingresados no son iguales.');
		a.focus();
		return false;
	} else {
		return true;
	}
}

function vld_seleccion(campo)
{
    for(ii=0;ii<campo.options.length;ii++)
    {
    	
        if( ii > 0 && campo.options[ii].text != "" && campo.options[ii].selected ){
            return true;
        }
    }	
    
	if( campo.alt || campo.title ) 
	{
		if( campo.alt ) alert('Olvidaste completar el campo: ' + campo.alt );
		if( campo.title ) alert('Olvidaste completar el campo: ' + campo.title );
		if( !campo.alt && !campo.title ) alert('Olvidaste completar el campo.' );	
	}
	else alert('No se completaron todos los campos. Debe seleccionarse un elemento.');
    
	
	campo.focus();
	return false;

}

function mostrar(select,text)
{  
	var valor;
    var indice = select.selectedIndex ; 
    if( indice != 0 ) valor = select.options[indice].text;  
    else valor = "";
	text.value = valor;
} 


function vld_url($url)
{
	var cadena;
	cadena = $url.value;
	if ( $url.value == "" ) {return true;}		
	
	var http = "http://";                
	                                     
	var es_url;                          
	if(cadena.length <= 7)             
	   es_url = false;                 
	else  
	   es_url = http.indexOf(cadena.substring(0, 7)) != - 1; 
	   
	
	if ( !es_url )	
	{
		alert("El formato de URL no es válido. La misma debe comenzar con http://.");
		mail.focus();
		return false;
	}
	
	return true;

}


function vld_2fecha (fechaDesde,fechaHasta)
{
	var cant_dias;
	cant_dias = DiferenciaFechas(fechaHasta,fechaDesde);
	if( cant_dias < 0 )
	{
		alert("Fecha Ingreso no puede ser mayor a Fecha Egreso.");
		fechaDesde.focus();
		return false;
	}
	
}

function DiferenciaFechas (fecha1,fecha2) {  
   
    //Obtiene los datos del formulario  
    CadenaFecha1 = fecha1.value  
    CadenaFecha2 = fecha2.value  
      
    //Obtiene dia, mes y año  
    var fecha1 = new fecha( CadenaFecha1 )     
    var fecha2 = new fecha( CadenaFecha2 )  
      
    //Obtiene objetos Date  
    var miFecha1 = new Date( fecha1.anio, fecha1.mes, fecha1.dia )  
    var miFecha2 = new Date( fecha2.anio, fecha2.mes, fecha2.dia )  

    //Resta fechas y redondea  
    var diferencia = (miFecha1.getTime() - miFecha2.getTime());

    var dias = Math.floor(diferencia / (1000 * 60 * 60 * 24));  
    var segundos = Math.floor(diferencia / 1000);  

    return dias  
 }  
   
 function fecha( cadena ) {  
   
    //Separador para la introduccion de las fechas  
    var separador = "/"  
   
    //Separa por dia, mes y año  
    if ( cadena.indexOf( separador ) != -1 ) {  
         var posi1 = 0  
         var posi2 = cadena.indexOf( separador, posi1 + 1 )  
         var posi3 = cadena.indexOf( separador, posi2 + 1 )  
         this.dia = cadena.substring( posi1, posi2 )  
         this.mes = cadena.substring( posi2 + 1, posi3 )  
         this.anio = cadena.substring( posi3 + 1, cadena.length )  
    } else {  
         this.dia = 0  
         this.mes = 0  
         this.anio = 0     
    }  
 }  
 
 
 function desde_hasta (desde,hasta) 
 {  
   
 	var desde_int = 0;
 	var hasta_int = 0;
 	
 	desde_int = parseFloat(desde.value);
 	hasta_int = parseFloat(hasta.value);
 	
	if( desde.value == ""  )
	{
		alert("El campo Desde no fue completado.");
		hasta.selectedIndex="";
		desde.focus();
		return false;
	}
	
	if( desde_int >= hasta_int  )
	{
		alert("El campo Hasta  no puede ser mayor o igual al campo Desde.");
		hasta.selectedIndex="";
		desde.focus();
		return false;
	}
	
	return true;
 }  
   



