 function KeyPress() 
    { 
        if (window.event.keyCode == 13) window.event.keyCode =9; 
    } 
    
function PosicionaMonto()
{
    objImporte = document.form1.txtImporte;
    objImporte.value='';
    objImporte.focus();
}

function fncInputNumericValuesOnly()	
{		
    if(!(event.keyCode==45||event.keyCode==46||event.keyCode==48||event.keyCode==49||event.keyCode==50||event.keyCode==51||event.keyCode==52||event.keyCode==53||event.keyCode==54||event.keyCode==55||event.keyCode==56||event.keyCode==57))		
		event.returnValue=false;
}		


function validar_siguiente_internacional()
{
    objNombre = document.form1.txtNombreInt
	objApellidoPaterno = document.form1.txtApellidoPaternoInt
	objPais = document.form1.cbxPais
	objEstado = document.form1.cbxEstado
	objCiudad = document.form1.cbxCiudad
	objPregunta = document.form1.txtPregunta
    objRespuesta = document.form1.txtRespuesta
	objImporte = document.form1.txtImporte
	objExistePregunta = document.form1.hdfPregunta
	objConsideraciones = document.form1.hdfConsideraciones
	objImporteInternacional = document.form1.hdfMontoInternacional

	
	if (Trim(objNombre.value) == '')
	    {
		    alert('Debe ingresar el nombre.')
		    objNombre.value='';
		    objNombre.focus();
		    return false;
	    }
    	
	    if (Trim(objApellidoPaterno.value) == '')
	    {
		    alert('Debe ingresar el apellido paterno.')
		    objApellidoPaterno.value='';
		    objApellidoPaterno.focus()
		    return false;
	    }
	    
	if (objPais.value == '0')
    {
	    alert('Debe seleccionar el pais.')
	    objPais.focus()
	    return false;
    }
    
    if(objPais.value=='US')
    {
        if (objEstado.value == '0')
        {
	        alert('Debe seleccionar el estado.')
	        objEstado.focus();
	        return false;
        }
        if (objCiudad.value == '0')
        {
	        alert('Debe seleccionar la ciudad.')
	        objCiudad.focus();
	        return false;
        }        
    }
    
    if (objImporte.value != '')
	{   
	var monto = objImporte.value;
	var monto_internacional = objImporteInternacional.value;
	
	monto = monto.replace(/[.]/gi,"");
	
		if (parseInt(monto) > parseInt(monto_internacional))
		{
		  alert('El monto del giro no puede ser superior a $' + FjsFormato_miles(monto_internacional));
		  objImporte.style.color = "red";
		  objImporte.focus()
		  return false;
		}
		if (monto < 5000)
		{
		  alert('El monto no puede ser inferior a $5.000');
		  objImporte.style.color = "red";
		  objImporte.focus()
		  return false;
		}		
	}
	else
	{
        alert('Debe ingresar el monto que desea enviar.')
		objImporte.focus()
		return false;
	}
	
	if (Trim(objExistePregunta.value) == '1')
	{
	    if (Trim(objPregunta.value) == '')
	        {
		        alert('Debe ingresar la pregunta de validación.')
		        objPregunta.value='';
		        return false;
	        } 
    	    
	    if (Trim(objRespuesta.value) == '')
	        {
		        alert('Debe ingresar la respuesta de validación.')
		        objRespuesta.value='';
		        return false;
	        } 
	}
	
	if(objConsideraciones.value=="0")
	{
	    alert('Debe leer las consideraciones para el país seleccionado.')
        return false;
	}
    
    return true;
    
}

function validar_siguiente_nacional()
{
    objNombre = document.form1.txtNombre
	objApellidoPaterno = document.form1.txtApellidoPaterno
	objRegion = document.form1.cbxRegion
	objOficina = document.form1.cbxOficina
	
	objImporte = document.form1.txtImporte
	
	
	
	objRut = document.form1.txtRut
	rut = objRut.value
    rut = rut.replace(/[.]/gi,"");
    
    var arrRut = rut.split('-');
    
    if(arrRut[0] > 50000000)
    {
    	if (Trim(objNombre.value) == '')
	    {
		    alert('Debe ingresar la razón social.')
		    objNombre.value='';
		    objNombre.focus();
		    return false;
	    }
    }
    else
    {
        if (Trim(objNombre.value) == '')
	    {
		    alert('Debe ingresar el nombre.')
		    objNombre.value='';
		    objNombre.focus();
		    return false;
	    }
    	
	    if (Trim(objApellidoPaterno.value) == '')
	    {
		    alert('Debe ingresar el apellido paterno.')
		    objApellidoPaterno.value='';
		    objApellidoPaterno.focus()
		    return false;
	    }
    }
	    
	
	if (objRegion.value == '-1')
    {
	    alert('Debe seleccionar la región.')
	    objRegion.focus()
	    return false;
    }
    
    if (objOficina.value == 'x|x')
    {
	    alert('Debe seleccionar la oficina chilexpress.')
	    objOficina.focus()
	    return false;
    }
	   
	if (objImporte.value != '')
	{   
	var monto = objImporte.value;
	monto = monto.replace(/[.]/gi,"");
		if (monto > 3500000)
		{
		  alert('El monto no puede ser superior a $3.500.000');
		  objImporte.style.color = "red";
		  objImporte.focus()
		  return false;
		}
		if (monto < 5000)
		{
		  alert('El monto no puede ser inferior a $5.000');
		  objImporte.style.color = "red";
		  objImporte.focus()
		  return false;
		}		
	}
	else
	{
        alert('Debe ingresar el monto que desea enviar.')
		objImporte.focus()
		return false;
	}
    
	return true;
}

function validar_siguiente()
{
	objNacional= document.form1.rdbNacional
	
	if (objNacional.checked)
	    return validar_siguiente_nacional();
	else
	    return validar_siguiente_internacional();
}

function FormatoMilesMonto(objeto)
{
    objMonto = objeto.value;
    var valor;
    valor=FjsFormato_miles(objMonto);
    objeto.value = valor
}

function setearOnLoad()
{   
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_pageLoaded(DeshabilitaNombreClienteUol);
    prm.add_pageLoaded(muestra_persona);
    prm.add_pageLoaded(muestra_tipo_destino_giro); 
}

function muestra_persona()
{
    objRut = document.form1.txtRut;
    rut = objRut.value
    rut = rut.replace(/[.]/gi,"");
    
    var arrRut = rut.split('-');
    
    if(arrRut[0] > 50000000)
    {
        document.getElementById('divNombre').style.display='none';
        document.getElementById('divRazonSocial').style.display='';
        document.getElementById('divPaterno').style.display='none';
        document.getElementById('divMaterno').style.display='none';
        document.getElementById('divPaternoTextBox').style.display='none';
        document.getElementById('divMaternoTextBox').style.display='none';
        
    }
    else
    {
        document.getElementById('divNombre').style.display='';
        document.getElementById('divRazonSocial').style.display='none';
        document.getElementById('divPaterno').style.display='';
        document.getElementById('divMaterno').style.display='';
        document.getElementById('divPaternoTextBox').style.display='';
        document.getElementById('divMaternoTextBox').style.display='';
    }
}

function muestra_tipo_destino_giro()
{
    objRdbNacional = document.form1.rdbNacional;
    objRdbInrenacional = document.form1.rdbInternacional;
    objRutNacional = document.form1.txtRut
    objRutInternacional = document.form1.txtRutInt
    objTipoGiro = document.form1.hdfTipoGiro
    
    if (objRdbNacional.checked == true)
        {
            document.getElementById('monto_internacional').style.display='none';            
            document.getElementById('panNacional').style.display='';
            document.getElementById('panInternacional').style.display='none';
            LimpiaControlesInternacional()
            objTipoGiro.value="1";
            //objRutNacional.focus();
        }
    else
        { 
            document.getElementById('monto_internacional').style.display='';
            document.getElementById('panNacional').style.display='none';
            document.getElementById('panInternacional').style.display='';
            LimpiaControlesNacional();
            objTipoGiro.value="2";
            //objRutInternacional.focus();
        }        
}

function LimpiaControlesNacional()
{
    document.getElementById('txtRut').value='';
    document.getElementById('txtNombre').value='';
    document.getElementById('txtApellidoPaterno').value='';
    document.getElementById('txtApellidoMaterno').value='';
    document.getElementById('cbxRegion').selectedIndex=0;
    document.getElementById('cbxOficina').selectedIndex=0;
}

function LimpiaControlesInternacional()
{
    document.getElementById('txtRutInt').value='';
    document.getElementById('txtNombreInt').value='';
    document.getElementById('txtApellidoPaternoInt').value='';
    document.getElementById('txtApellidoMaternoInt').value='';
    document.getElementById('cbxPais').selectedIndex=0;
    //document.getElementById('cbxEstado').selectedIndex=0;
    //document.getElementById('cbxCiudad').selectedIndex=0;
}

/* -------------------------------------------------------------------------------------------------- */
function BuscarNombreCliente(sRutDestinatario)
{
    objRdbNacional = document.form1.rdbNacional;
    if (objRdbNacional.checked == true)
        {
            objRut = document.form1.txtRut;
	        objNombre = document.form1.txtNombre;
	        objPaterno = document.form1.txtApellidoPaterno;
	        objMaterno = document.form1.txtApellidoMaterno;
        }
    else
        {
            objRut = document.form1.txtRutInt;
	        objNombre = document.form1.txtNombreInt;
	        objPaterno = document.form1.txtApellidoPaternoInt;
	        objMaterno = document.form1.txtApellidoMaternoInt;        
        }
        
        
	objNombre.disabled=false; 
    objPaterno.disabled=false;
    objMaterno.disabled=false;
    objPps = document.form1.hdfPps;
    objPps.value='N';
 
    
    muestra_persona();
    
    respuesta = Prepara.BuscarNombreDestinatario(sRutDestinatario.value);
    if (respuesta.value != "")
        {
            var remitente = respuesta.value.split('&t*');
            var NombreCompleto = remitente[1];
            if(Trim(NombreCompleto)=='')
                {
                    objNombre.value='';  
                    objPaterno.value=''; 
                    objMaterno.value=''; 
                    objNombre.focus();            
                }
            else
                {
                    whichKey = String.fromCharCode(179).toLowerCase();
                    var ArrNombre = NombreCompleto.split(whichKey);
                    var elementos = ArrNombre.length;
                    
                    switch(elementos)
                        {
                        case 1:
                        objNombre.value = ArrNombre[0];
                        
                        case 2:
                        objNombre.value = ArrNombre[0];
                        objPaterno.value = ArrNombre[1];
                        
                        case 3:
                        objNombre.value = ArrNombre[0];
                        objPaterno.value = ArrNombre[1];    
                        objMaterno.value = ArrNombre[2];        
                        }
                        
                    if (objPaterno.value == 'undefined')
                    {
                        if(document.getElementById('divPaterno').style.display=='')
                        {
                            objPaterno.value="";  
                            //objPaterno.focus();
                        }
                    
                    }
                    else if (objMaterno.value == 'undefined' || objMaterno.value=='')
                    {
                        if(document.getElementById('divMaterno').style.display == '')
                        {
                            objMaterno.value="";
                            //objMaterno.focus();
                        }
                    }
                    //else 
                        //document.form1.cbxRegion.focus();
                  }      
    }
    else
        {
            objNombre.value = '';
            objPaterno.value = '';
            objMaterno.value = '';
            objNombre.focus();
        }
}


function BuscarNombreClienteUol(sRutDestinatario)
{
    objRut = document.form1.txtRut;
	objNombre = document.form1.txtNombre;
	objPaterno = document.form1.txtApellidoPaterno;
	objMaterno = document.form1.txtApellidoMaterno;
	objPps = document.form1.hdfPps;
	objRegion = document.form1.cbxRegion;
    

    respuesta = Prepara.BuscarNombreDestinatarioUol(sRutDestinatario.value);
    if (respuesta.value != "")
        {
            var persona = respuesta.value.split('&t*');

            objNombre.value = persona[1];
            objPaterno.value = persona[2];    
            objMaterno.value = persona[3];  
            
            if(persona[4]=="S")
            {
                objNombre.disabled=true; 
                objPaterno.disabled=true;
                objMaterno.disabled=true; 
                objPps.value=persona[4]
                objRegion.focus();    
            }
            else
            {
                objNombre.disabled=false; 
                objPaterno.disabled=false;
                objMaterno.disabled=false;
                objPps.value='N';
                objNombre.focus();
            }
            
        }

}

function DeshabilitaNombreClienteUol()
{

    objRut = document.form1.txtRut;
	objNombre = document.form1.txtNombre;
	objPaterno = document.form1.txtApellidoPaterno;
	objMaterno = document.form1.txtApellidoMaterno;
	objRegion = document.form1.cbxRegion;

    respuesta = Prepara.BuscarNombreDestinatarioUol(objRut.value);
    if (respuesta.value != "")
        {
            var persona = respuesta.value.split('&t*');

            if(persona[4]=="S")
            {
                objNombre.disabled=true; 
                objPaterno.disabled=true;
                objMaterno.disabled=true; 
                objRegion.focus();
            }
            else
            {
                objNombre.disabled=false; 
                objPaterno.disabled=false;
                objMaterno.disabled=false;
                objNombre.focus();
            }
            
        }
}


