$(document).ready(function(){
            
            $("#rut_raspe").keypress(function(event){
				   if ( event.which == 13 ) {
				     event.preventDefault();
				     monto_preaprobado_new(document.form_raspe.rut_raspe);
				   }
            });
            $("#rut_raspe").blur(function(event){
				     checkRutField(document.form_raspe.rut_raspe,true)
            });

			
		$("#btn_ingresar a").click(function(evento){
			evento.preventDefault();
			monto_preaprobado_new(document.form_raspe.rut_raspe);
		});
			
        });

function envio_raspe(){
	if (Vclave(document.form_raspe.pin_raspe.value)==true){
		document.form1.Op_campana.value="177";
		document.form1.rut.value=document.form_raspe.rut_raspe.value
		document.form1.pin.value=document.form_raspe.pin_raspe.value
		document.form1.submit();
	}
	
}

 function monto_preaprobado_new(rut){
		$("#Op_campana").attr("value","");
		if (checkRutField(rut,true) == true)
			{
				$.ajax({
					   type:"POST",
					   url:"/serv_raspe.asp",
					   data:"d_rut="+rut.value,
					   success:function(msg){

						   if((msg.indexOf('No es Cliente')>= 0) ||(msg.indexOf("Cliente Sin")>=0))
								{
									$("#caja").hide();	
									$("#caja3").show();									
								}
							else
								{
									var monto_ar = msg.split("|");
									var monto_final = 0;
									for(x=0; x < monto_ar.length; x++){
										if (monto_final < monto_ar[x])
											monto_final = monto_ar[x];
									}
									$("#caja").hide();
									$("#caja2").show();
									$("#caja_variable").html(formatNumber(monto_final,'$ '));
									
									/*
									$("#caja_monto").html(formatNumber(monto_final,'$ '));
									$("#f_rut").val(rut);
									$("#mensaje1").fadeIn();	
									$("#mensaje2").hide();
									*/
								}
						},
						error:function(msg){
							$("#caja").hide();	
							$("#caja3").show();
						}
				});
			}
	}

	function formatNumber(num,prefix){
		prefix = prefix || '';
		num += '';
		var splitStr = num.split('.');
		var splitLeft = splitStr[0];
		var splitRight = splitStr.length > 1 ? '.' + splitStr[1] : '';
		var regx = /(\d+)(\d{3})/;
		while (regx.test(splitLeft)) {
			splitLeft = splitLeft.replace(regx, '$1' + '.' + '$2');
		}
		return prefix + splitLeft + splitRight;
	}


