function foco(){
	  document.form.wFechaCarga.focus();
	}
if (document.images) {
  var boton1_off = new Image();
  boton1_off.src = "imagenes/Cancelarblanco.bmp";
  var boton1_on = new Image();
  boton1_on.src = "imagenes/Grabarblanco.bmp";
}

/*function entra(boton, id) {
  var encontro = false;  
  objeto = document.getElementById(id);   
  if (document.images) {    
  if (boton == 'boton1'){
       for ( i = 0; i < objeto.value.length;  i++ ) {  
                 if (objeto.value.charAt(i) != " " ) {  
					document.images[boton].src = boton1_on.src;
					encontro = true;                         
                 }  
	  if (!encontro){	  
	    document.images[boton].src = boton1_off.src;   
		}	 
   }
  }
  }
}
*/
function valida(boton, id) {  
         objeto = document.getElementById(id);      
         if( vacio(objeto.value) == false ) {                   
                 document.images[boton].src = boton1_off.src;
         } else {                   
                 document.images[boton].src = boton1_on.src;   
         }  
           
 } 
 function vacio(q) {  
         for ( i = 0; i < q.length; i++ ) {  
                 if ( q.charAt(i) != " " ) {  
                         return true  
                 }  
         }  
         return false  
 }  


function validaNumerico(boton, id) {  
         objeto = document.getElementById(id);
		 var cadena = "";
		 var j = 0;
         if( vacioNumerico(objeto.value)) {                   
				 for ( i = 0; i < objeto.value.length;  i++ ) { 				   
				   j = i;
				   if (i != objeto.value.length-1){
         			cadena = cadena + objeto.value.charAt(i) ;
				   }
				 }
				 if(isNaN(objeto.value)){				 
				   objeto.value = cadena;				   
				 }else{
				  //document.images[boton].src = boton1_on.src;
				 }
         } else {                                    				 
				 //document.images[boton].src = boton1_off.src;   
         }  
           
 }
 function validaNumericoConImagen(boton, id) {  
         objeto = document.getElementById(id);
		 var cadena = "";
		 var j = 0;
         if( vacioNumerico(objeto.value)) {                   
				 for ( i = 0; i < objeto.value.length;  i++ ) { 				   
				   j = i;
				   if (i != objeto.value.length-1){
         			cadena = cadena + objeto.value.charAt(i) ;
				   }
				 }
				 if(isNaN(objeto.value)){				 
				   objeto.value = cadena;				   
				 }else{
				  document.images[boton].src = boton1_on.src;
				 }
         } else {                                    				 
				 document.images[boton].src = boton1_off.src;   
         }  
           
 }
 function vacioNumerico(q) {  
         for ( i = 0; i < q.length; i++ ) {  
				 if ( q.charAt(i) != " " ) {  
                         return true 				
                 }  				 
         }  		 
         return false  
 }  
function validar(form){
	 mensajeError = "";
	/*if (document.form.wCtgNro.value == ""){
      mensajeError = mensajeError + " CTG NRO, ";
	}   */
	sele = document.getElementById("wCheck");
    if(!sele.checked){
	if (document.form.wPesoBruto.value == ""){
	  mensajeError = mensajeError + " ,PESO BRUTO, ";	
	}
	if (document.form.wPesoNeto.value == ""){
	  mensajeError = mensajeError + " ,PESO NETO ";	  		
	}
	if (document.form.wPesoTara.value == ""){
	  mensajeError = mensajeError + " ,PESO TARA ";
	}
	}else{
		 if (document.form.wKgsEst.value == ""){
			 mensajeError = mensajeError + " , KGS ESTIMADOS ";
		 }
	}
	if (document.form.wCorredorLista.value == 0){
	  if (document.form.wCorredor.value == ""){
	    mensajeError = mensajeError + " ,NOMBRE CORREDOR ";
	  }
	  if (document.form.wCuitCorredor.value == ""){
	    mensajeError = mensajeError + " ,CUIT CORREDOR ";
	  }
	 }
	 
	 
	/* if (document.form.wIdPersona.value == 0){
	  if (document.form.wRepEnt.value == ""){
	    mensajeError = mensajeError + " ,REPRESENTANTE/ENTREGADOR ";
	  }
	  if (document.form.wCuitRrpEnt.value == ""){
	    mensajeError = mensajeError + " ,CUIT REPRESENTANTE ";
	  }
	 }		    		    */
	 
	 if (document.form.wDestinatario.value == 0){
	  if (document.form.wNomRSocial.value == ""){
	    mensajeError = mensajeError + " ,DESTINATARIO ";
	  }
	  if (document.form.wCuit.value == ""){
	    mensajeError = mensajeError + " ,CUIT DESTINATARIO ";
	  }
	 }		    		    
	 
	 if (document.form.wIdDestinoRZCuit.value == 0){
	  if (document.form.wDescDestino.value == ""){
	    mensajeError = mensajeError + " ,DESTINO ";
	  }
	  if (document.form.wCuitDestino.value == ""){
	    mensajeError = mensajeError + " ,CUIT DESTINO ";
	  }
	 }		    		    
	 
	 if (document.form.wDestino.value == 0){
	  
	  if (document.form.wGranosLoc.value == ""){
	    mensajeError = mensajeError + " ,LOCALIDAD DESTINO ";
	  }
	  if (document.form.wGranosProv.value == ""){
	    mensajeError = mensajeError + " ,PROVINCIA DESTINO ";
	  }
	 }		    		    

	 objeto = document.getElementById("wObservaciones");
	 caracteres = objeto.value.length;
	  cadena = "";
	  if (caracteres > 159){		  	  
	      for ( i = 0; i < 159;  i++ ) {		   
		    cadena = cadena + cont.value.charAt(i);
			}
		  cont.value = cadena.trim();
		  mensajeError = mensajeError + " ,El CAMPO OBSERVACIONES FUE REDUCIDO A 160 CARACTERES ";
		}   
	if (mensajeError == ""){
	    var nombreArchivo = document.getElementById('attach1');			
	    var nombreArchivo2 = document.getElementById('attach2');
	    nombreArchivo2.value = nombreArchivo.value;
		if (nombreArchivo2.value != ""){
			document.form.target = '_blank';
			document.form.submit();
		}else{
			alert("Debe ingresar una carta de porte en blanco" + mensajeError);
	        return 0;	
		}
	}else{
	    alert("Debe ingresar los siguientes campos" + mensajeError);
	    return 0;
	}
	}
function ponerFecha(id){
	  objeto = document.getElementById(id);      
	  var fecha = new Date();
	  var dia = fecha.getMonth();
	  dia = dia +1;
	  if (dia <= 9) {
	    dia = "0" + dia;
	  }
	  var mes = fecha.getDate();
	  if (mes <= 9) {
	    mes = "0" + mes;
	  }
	  var ano = fecha.getFullYear();
	  objeto.value = mes + "/" + dia + "/" + ano;
	  objeto.value.select();
}
function cambiaEstadoCheck()
    {
        sel = document.getElementById("wCheck");
        
        kgsEst = document.getElementById("kgsEst");
        
        pesoBruto = document.getElementById("pesoBruto");
        pesoTara = document.getElementById("pesoTara");
        pesoNeto = document.getElementById("pesoNeto");
        
        //alert(sel.checked);
        if(sel.checked)
        {
            //alert("si");      
            document.images['botonKgsEst'].src = boton1_off.src;
			//kgsEst.disabled = false;			
			pesoBruto.value = "1";
			valida('botonPesoBruto', 'pesoBruto');
			pesoBruto.value = "";
			pesoTara.value = "1";
			valida('botonPesoTara', 'pesoTara');
			pesoTara.value = "";
			pesoNeto.value = "1";
			valida('botonPesoNeto', 'pesoNeto');
			pesoNeto.value = "";			
            //pesoBruto.disabled = true;
            //pesoTara.disabled = true;
            //pesoNeto.disabled = true;						
          }
          else
          {
                //alert("no");
			document.images['botonKgsEst'].src = boton1_on.src;
            kgsEst.value = "";
			//kgsEst.disabled = true;
			pesoBruto.value = "";
			valida('botonPesoBruto', 'pesoBruto');
			pesoTara.value = "";
			valida('botonPesoTara', 'pesoTara');
			pesoNeto.value = "";
			valida('botonPesoNeto', 'pesoNeto');
            //pesoBruto.disabled = false;
            //pesoTara.disabled = false;
            //pesoNeto.disabled = false;
          }        
    }
function calcularNeto()
    {                
        pesoBruto1 = document.getElementById("pesoBruto");
        pesoTara1 = document.getElementById("pesoTara");
        pesoNeto1 = document.getElementById("pesoNeto");
		//if ( pesoBruto1.value > pesoTara1.value){		
		  var valor = pesoBruto1.value - pesoTara1.value;
		  pesoNeto1.value = redondeo2decimales(valor);
		  //pesoNeto1.value = pesoBruto1.value - pesoTara1.value;
		//}else{
		//	pesoNeto1.value = "";
		//	document.images['botonPesoNeto'].src = boton1_off.src;
		//}
        if (pesoNeto1.value == ""){
			document.images['botonPesoNeto'].src = boton1_off.src;
		}else{
			document.images['botonPesoNeto'].src = boton1_on.src;
		}
                                            
    }
function redondeo2decimales(numero)
{
	var original=parseFloat(numero);
	var result=Math.round(original*100)/100 ;
	return result;
}
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };
    
