var http_request = false;
var cbDeducRespCivilSel = null;
var cbDeducPerdTotDanosSel = null;
var cbDeducPerdParDanosSel = null;
var cbDeducPerdParHurtoSel = null;
var cbDeducPerdTotHurtoSel = null;
var cbOpcRespCivilSel = null;
var cbOpcTranspDanosSel = null;
var cbOpcTranspHurtoSel = null;
var cbOpcionAsistViajeSel = null;
var cbOpcAccConductorSel = null;
var cbOpcVehReemplazoTotalSel = null;
var cbOpcVehReemplazoParcialSel = null;

var excDedPerdTotDanos = null;
var excDedPerdParDanos = null;
var excDedPerdParHurto = null;
var excDedPerdTotHurto = null;


function makeRequest_Marca(url) {
    http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }

    var selector = document.getElementById("marca").value;
    var cdfasecolda = document.getElementById("cdfasecolda").value;
    var modelo = document.getElementById("modelo").value;
    var cdmunicipio = document.getElementById("cdCiudad").value;
    
    //alert ("cdFasecolda "+cdfasecolda);
    http_request.onreadystatechange = alertContents;
    http_request.open('GET', url+"?marca="+selector+"&linea="+cdfasecolda+"&modelo="+modelo+"&cdmunicipio="+cdmunicipio, true);
    http_request.send(null);

}

function alertContents() 
{
    if (http_request.readyState == 4) 
    {   
        if (http_request.status == 200) 
        {
            var xmldoc = http_request.responseXML;
            var valorSug = 0;
            valorSug = xmldoc.getElementsByTagName('valorS')[0].childNodes[0].data;
            var cdzona = xmldoc.getElementsByTagName('zona')[0].childNodes[0].data;
            if(valorSug != -1){
                    document.Paso2.cdZona.value = cdzona;
                    document.Paso2.valorAsegurado.value = valorSug;
                    document.Paso2.valorSugerido.value  = valorSug;
                    document.Paso2.valorAseguradoMascara.value = valorSug;
                    document.Paso2.valorSugeridoMascara.value  = valorSug;
                    format(null, document.Paso2.valorAseguradoMascara);
                    format(null, document.Paso2.valorSugeridoMascara);
            }else{
                 alert("Ocurrio un error al realizar la consulta");
            }
        } else {
            alert('Hubo un problema con el request. Alert contents');
        }        
    }
}

function alertContentsClase (){
    if (http_request.readyState == 4) 
    {   
        if (http_request.status == 200) 
        {
            var xmldoc = http_request.responseXML;
            var opciones = xmldoc.getElementsByTagName('clase');

            var comboSize = document.Paso2.cbClase.length;
            
            for (i = 0; i < comboSize; i++){
                document.Paso2.cbClase.options[0] = null;
            }

            for (loopIndex = 0; loopIndex < opciones.length; loopIndex++) {            
                var valClase = opciones[loopIndex].childNodes[1].childNodes[0].data;
                var valCdClase = opciones[loopIndex].childNodes[0].childNodes[0].data;

                document.Paso2.cbClase.options[loopIndex] = new Option (valClase+"           ", valCdClase);
            }

            if (document.Paso2.cbClase.options[0] != null ){
                document.Paso2.clase.value = document.Paso2.cbClase.options[0].text;
            }
            else
                document.Paso2.cbClase.options[0] = new Option ("Seleccionar...", -1);

            getVal_Clase();            

        } else {
            alert('Hubo un problema con el request. Clase');
        }
    }
}

function alertContentsLinea (){
    
    if (http_request.readyState == 4) 
    {   
        if (http_request.status == 200) 
        {
            var xmldoc = http_request.responseXML;
            var opciones = xmldoc.getElementsByTagName('linea');
            var comboSize = document.Paso2.linea.length;
            
            for (i = 0; i < comboSize; i++){
                document.Paso2.linea.options[0] = null;
            }

            for (loopIndex = 0; loopIndex < opciones.length; loopIndex++) {            
                var valLinea = opciones[loopIndex].childNodes[1].childNodes[0].data;
                var valCdLinea = opciones[loopIndex].childNodes[0].childNodes[0].data;
                var dsMarca = opciones[loopIndex].childNodes[2].childNodes[0].data;
                var dsClaseFasecolda = opciones[loopIndex].childNodes[3].childNodes[0].data;
                var dsImportado = opciones[loopIndex].childNodes[4].childNodes[0].data;
                var snAsimilaCampero = opciones[loopIndex].childNodes[5].childNodes[0].data;
                var snPesoCapacidad = opciones[loopIndex].childNodes[6].childNodes[0].data;

                var value = valCdLinea+";"+dsMarca+";"+dsClaseFasecolda+";"+dsImportado+";"+valLinea
                            +";"+snAsimilaCampero+";"+snPesoCapacidad;
                
                document.Paso2.linea.options[loopIndex] = new Option (valLinea, value);
            }

            if (document.Paso2.linea.options[0] == null ){
                document.Paso2.linea.options[0] = new Option ("Seleccionar...", -1);
            }
            //else
               // document.Paso2.linea.value = document.Paso2.linea.options[0].text;

            getVal_Linea();

        } else {
            alert('Hubo un problema con el request. Linea');
        }
    }
}

function alertContentsDeptos (){
    if (http_request.readyState == 4) 
    {
        if (http_request.status == 200) 
        {
            var xmldoc = http_request.responseXML;
            var opciones = xmldoc.getElementsByTagName('Deptos');

            //var comboSize = document.Paso1.cdCiudadPer_COMBO.length;
            var comboSize = document.getElementById('cdCiudadPer_COMBO').length;
            
            for (i = 0; i < comboSize; i++){
                document.getElementById('cdCiudadPer_COMBO').options[0] = null;
            }

            for (loopIndex = 0; loopIndex < opciones.length; loopIndex++) {            
                var valDepto = opciones[loopIndex].childNodes[1].childNodes[0].data;
                var valCdDepto = opciones[loopIndex].childNodes[0].childNodes[0].data;

                document.getElementById('cdCiudadPer_COMBO').options[loopIndex] = new Option (valDepto, valCdDepto);
            }

            if (document.getElementById('cdCiudadPer_COMBO').options[0] == null ){
                document.getElementById('cdCiudadPer_COMBO').options[0] = new Option ("Seleccionar...", -1);
            }               
             //getVal_Depto();

            if (document.getElementById('cdCiudadPer_COMBO').length != 0){
                 getVal_Depto();
            }
            
        } else {
            alert('Hubo un problema con el request. Deptos');
        }
    }
}

function alertContentsDeptos_Autos (){
    if (http_request.readyState == 4) 
    {   
        if (http_request.status == 200) 
        {
            var xmldoc = http_request.responseXML;
            var opciones = xmldoc.getElementsByTagName('Deptos');

            var comboSize = document.Paso2.cdCiudad_COMBO.length;
            
            for (i = 0; i < comboSize; i++){
                document.Paso2.cdCiudad_COMBO.options[0] = null;
            }

            for (loopIndex = 0; loopIndex < opciones.length; loopIndex++) {            
                var valDepto = opciones[loopIndex].childNodes[1].childNodes[0].data;
                var valCdDepto = opciones[loopIndex].childNodes[0].childNodes[0].data;

                document.Paso2.cdCiudad_COMBO.options[loopIndex] = new Option (valDepto, valCdDepto);
            }

            if (document.Paso2.cdCiudad_COMBO.options[0] == null ){
                document.Paso2.cdCiudad_COMBO.options[0] = new Option ("Seleccionar...", -1);
            }
            
            // getVal_Depto_Auto();
            
        } else {
            alert('Hubo un problema con el request. Deptos');
        }
    }
}

function parametersDeptos_Autos(){
    var selector = document.getElementById("cdDepAuto").value;
    var step = document.getElementById("actualStep").value;
    return "?cdDepPer="+selector+"&actualStep="+step;
}

function parametersDeptos(){
    var selector = document.getElementById("cdDepPer").value;
    var step = document.getElementById("actualStep").value;
    //return "?cdDepPer="+selector;
    return "?cdDepPer="+selector+"&actualStep="+step;
}

function parametersLineas(){
    var selector = document.getElementById("marca").value;
    var selectorClase = document.getElementById("cbClase").value;
    return "?marca="+selector+"&clase="+selectorClase;
}

function parametersClases(){
    var selector = document.getElementById("marca").value;
    return "?marca="+selector;
}

function keepHidenClass(){
    document.Paso2.linea.value = "";
    document.Paso2.cdfasecolda.value = "";
    document.Paso2.valorAsegurado.value = "";
    document.Paso2.valorSugerido.value = "";

    var val = document.Paso2.cbClase.options[document.Paso2.cbClase.selectedIndex].value;
    document.Paso2.clase.value = document.Paso2.cbClase.options[document.Paso2.cbClase.selectedIndex].text;
}

//***********************************************************************
function validarComponentes(cambio, request){
    if(cambio == 'si'){
        document.Paso2.linea.value = "";
        document.Paso2.cdfasecolda.value = "";
        document.Paso2.valorAsegurado.value = "";
        document.Paso2.valorSugerido.value = "";
    }else{
        if(document.Paso2.marca.value != "" && document.Paso2.linea.value != "" && 
           document.Paso2.modelo.value != "" && document.Paso2.cdCiudad_COMBO.value != "" 
            && document.Paso2.cdCiudad_COMBO.value != "-1"){
           
            if(document.Paso2.cdCiudad_COMBO.value == "otra"){
                if(document.Paso2.ciudad_TEXT != ""){
                    document.Paso2.valorAsegurado.value = "";
                    document.Paso2.valorSugerido.value = "";
                    makeRequest_Marca(request);
                }
            }else{
                document.Paso2.valorAsegurado.value = "";
                document.Paso2.valorSugerido.value = "";
                makeRequest_Marca(request);
            }
        }else{
            document.Paso2.valorAsegurado.value = "";
            document.Paso2.valorSugerido.value = "";
        }
    }
    return;
}
//***********************************************************************
function asistirBusqueda (comboMarca, request) {
    var codMarca = comboMarca.options[document.Paso2.marca.selectedIndex].value;
    var dsMarca = comboMarca.options[document.Paso2.marca.selectedIndex].text;
    var codClase = document.Paso2.cbClase.options[document.Paso2.cbClase.selectedIndex].value;
    //var dsClase = comboClase.options[document.Paso2.clase.selectedIndex].text;

    if (comboMarca.selectedIndex == 0) {
        mensajeError("Debe seleccionar una marca");
        return;
    }
    url = "/cotizadores/html/cotizadores/navegantes/Autos/buscarLinea.jsp?marca=" + codMarca + "&cdClase="+ codClase +"&nombreMarca=" + dsMarca + "&desde=0&hasta=25&buscar=0&desc=null&request="+request;
    window.open(url, "asist_busqueda_linea", 
                    "scrollbars=no, resizeable=no, top=100, left=200, width=800, height=550");
}

//----------------------------------------------------------------------------------

function mostrarSiguientes(url) {
    //.buscarLinea.pageNumber.value = document.buscarLinea.pageNumber.value + 1;
    document.buscarLinea.oper.value = 'sig';
    location.href = url+'&desc='+document.buscarLinea.linea.value;
}

function mostrarAnteriores(url) {        
    //document.buscarLinea.pageNumber.value = document.buscarLinea.pageNumber.value - 1;
    document.buscarLinea.oper.value = 'ant';
    location.href = url+'&desc='+document.buscarLinea.linea.value;
}
function iniciarBusqueda(url){
    /*if(document.buscarLinea.linea.value=="")
    {
        alert("Debe ingresar una descripcin de la linea");
        return;
    }*/
    
    document.buscarLinea.buscar.value = 1;
    document.buscarLinea.desc.value = document.buscarLinea.linea.value;
    location.href = url+'&desc='+document.buscarLinea.linea.value;
}

function guardarDatos(cdfasecolda, dsfasecolda, dsMarca, clasefasecolda, snimportado, snAsimilaCampero, cdPesoCapacidad, request){
    //var valor = cdfasecolda+" - "+dsfasecolda;
    var valor = dsfasecolda;
    
    var valCdfasecolda = cdfasecolda+";"+dsMarca+";"+clasefasecolda+";"+snimportado+";"+dsfasecolda
                            +";"+snAsimilaCampero+";"+cdPesoCapacidad;
    window.opener.document.Paso2.dsfasecolda.value = dsfasecolda;
    //window.opener.document.Paso2.linea.value = valor;
    window.opener.document.Paso2.dsVehiculo.value = dsMarca;
    window.opener.document.Paso2.snImportado.value = snimportado;
    window.opener.document.Paso2.snAsimilaCampero.value = snAsimilaCampero;
    
    window.opener.document.Paso2.claseFasecolda.value = clasefasecolda;
    //window.opener.document.Paso2.linea.select();
    indice = getIndexByValue2(valCdfasecolda, window.opener.document.Paso2.linea);
    window.opener.document.Paso2.linea.selectedIndex = indice;
    window.opener.document.Paso2.cdfasecolda.value = cdfasecolda;

    var cdPesoCapacidadSura = getPesoCapacidad(cdPesoCapacidad, clasefasecolda, snAsimilaCampero);
    window.opener.document.Paso2.cdPesoCapacidad.value = cdPesoCapacidadSura;
    window.close();
}

function getPesoCapacidad(pesoEnTabla, claseFasecolda, snCampero) {    
    if (claseFasecolda != null) {
        if ( (  claseFasecolda == "1" || 
                claseFasecolda == "6" || 
                claseFasecolda == "8" ||
                claseFasecolda == "9" || 
                claseFasecolda == "17" || 
                claseFasecolda == "18" ||
                claseFasecolda == "19" || 
                claseFasecolda == "20" || 
                claseFasecolda == "21" ) ||
             ( snCampero == "S" ) || (claseFasecolda == "02" && pesoEnTabla == "1") ) {
                return "1";
        } else {
            return "2";
        }
    }
}

function getIndexByValue2(info, selector) {
    for (var i = 0; i <= selector.length; i++) {        
        if (selector.options[i].value == info) {
            return i;
        }
    }
    return 0;
}

//-----------------------------------------------------------------------------------

function llamarServicioMunicipio() {
    var urlRedireccion = '/cotizadores/servlet/suramericana.cotizadores.conectado.LogonServicioMunicipios?receptor=suramericana.cotizadores.navegantes.ReceptorMunicipiosPasos';
    window.open(urlRedireccion,'Servicio_municipios','dependant=yes,height=600,width=800');
    
}

function llamarServicioMunicipio2() {
    var urlRedireccion = '/cotizadores/servlet/suramericana.cotizadores.conectado.LogonServicioMunicipios?receptor=suramericana.cotizadores.navegantes.ReceptorMunicipiosPasos2';
    window.open(urlRedireccion,'Servicio_municipios','dependant=yes,height=600,width=800');
    
}

function llamarServicioMunicipio3() {
    var urlRedireccion = '/cotizadores/servlet/suramericana.cotizadores.conectado.LogonServicioMunicipios?receptor=suramericana.cotizadores.navegantes.ReceptorMunicipiosPasos3';
    window.open(urlRedireccion,'Servicio_municipios','dependant=yes,height=600,width=800');
    
}

//------------------------------------------------------------------------------------
//autor: Pablo Moreno
//funcion que restringe valores en un campo text
//parametros de entrada:
//campo, se debe enviar el campo como objeto
//tipo, puede ser num o text_and_num
//ex, cadena de excepciones para permitirlas
//ejemplo:   onkeyup="restriccion(this, 'text_and_num', '/-_.')"
function restriccion(campo, tipo, ex)
{
    var valor = campo.value;
    var newValor = '';
    var existe = 0;
    var iLista = '';
    if(tipo == 'num')
    {
        var posibles = '1234567890'+ex;
    }else{
        if(tipo == 'text_and_num')
        {
            var posibles = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'+ex;
        }else{
            if(tipo == 'text')
            {
                var posibles = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '+ex;
            }
        }
    }
    var i;
    var j;
    var k;
    for(i = 0; i  < valor.length; i++){
        existe = 0;
        for(k=0;k<posibles.length;k++)
        {
            if(valor.charAt(i) == posibles.charAt(k)){
                existe = 1;
            }
        }
        if(existe == 0)
        {
            iLista = iLista + valor.charAt(i);
        }
    }
    for(i = 0; i < valor.length; i++)
    {
        existe = 0;
        for(k = 0; k < iLista.length; k++)
        {
            if(valor.charAt(i) == iLista.charAt(k)){
                existe = 1;
            }
        }
        if(existe == 0){
            newValor = newValor + valor.charAt(i);
        }
    }
    if(newValor != valor)
        campo.value = newValor;
    return false;
}


function aboutNavegantes (ruta){
    var strFeatures = "dialogWidth=520px; dialogHeight=337px; status=no; center=yes; help=no;";
    window.showModalDialog(ruta+"/about_Navegantes.jsp","Acerca de...",strFeatures);
}

function format(e, input){
    var unicode = null;
    if(e != null){
        unicode=e.keyCode? e.keyCode : e.charCode
    }
    if(unicode == null || (unicode != '35' && unicode != '36' && unicode != '37' && unicode != '39')){
        var num = input.value.replace(/\./g,'');
        if(!isNaN(num)){
            num = num.toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1.');
            num = num.split('').reverse().join('').replace(/^[\.]/,'');
            input.value = num;
        } else {
            alert('Solo se permiten numeros');
            input.value = input.value.replace(/[^\d\.]*/g,'');
        }
    }
}

function asignarValorAsegurado(){
    document.Paso2.valorAsegurado.value = document.Paso2.valorAseguradoMascara.value.replace(/\./g, "")
}

function listarPlanes(){
    var producto = document.frmPaso3.producto.options[document.frmPaso3.producto.selectedIndex].value;
    jQuery.ajax({
        type: "GET",
        dataType: "xml",
        async: false,
        url: solicitud_getContext()+"/Planes",
        data: "producto="+producto,
        success: function(msg){
            var loopIndex = 0;
            for (i = 0; i < document.frmPaso3.plan.length; i++){
                document.frmPaso3.plan.options[i] = null;
            }
            jQuery(msg).find("Plan").each(function(){
                var valCdPlan = jQuery(this).find("cdPlan").text();
                var valDsPlan = jQuery(this).find("dsPlan").text();
                document.frmPaso3.plan.options[loopIndex] = new Option (valDsPlan, valCdPlan);
                if(loopIndex == 0){
                    document.frmPaso3.dsPlan.value = valDsPlan;
                }
                loopIndex++;
            });
            listarDeducibles();
        },
        error: function( event, request, settings ){
            alert( "Error en listarPlanes" );
            alert(event);
            alert(request);
            alert(settings);
            return false;
        }
    });
}

function listarDeducibles(){
    var plan = document.frmPaso3.plan.options[document.frmPaso3.plan.selectedIndex].value;
    document.frmPaso3.dsPlan.value = document.frmPaso3.plan.options[document.frmPaso3.plan.selectedIndex].text;
    var producto = document.frmPaso3.producto.options[document.frmPaso3.producto.selectedIndex].value;
    document.frmPaso3.dsProducto.value = document.frmPaso3.producto.options[document.frmPaso3.producto.selectedIndex].text;
    jQuery.ajax({
        type: "GET",
        dataType: "xml",
        async: false,
        url: solicitud_getContext()+"/Deducibles",
        data: "plan="+plan +"&producto="+producto,
        success: function(msg){

            var loopIndex = 0;
            for (i = 0; i < document.frmPaso3.cbDeducRespCivil.length; i++){
                document.frmPaso3.cbDeducRespCivil.options[i] = null;
            }
            jQuery(msg).find("Deducible_respCivil").each(function(){
                var deducible = jQuery(this).find("getDeducible").text();
                var descuento = jQuery(this).find("getDescuento").text();
                var numSalarios = jQuery(this).find("getNumSalarios").text();
                var descripcion = jQuery(this).find("descripcion").text();
                document.frmPaso3.cbDeducRespCivil.options[loopIndex] = new Option( descripcion, deducible+";"+descuento+";"+numSalarios);
                if(deducible+";"+descuento+";"+numSalarios == cbDeducRespCivilSel){
                    document.frmPaso3.cbDeducRespCivil.options[loopIndex].selected = true;
                }
                if(loopIndex == 0 || deducible+";"+descuento+";"+numSalarios == cbDeducRespCivilSel){
                    document.frmPaso3.deducRespCivil.value = deducible;
                    document.frmPaso3.deducRespCivilSal.value = numSalarios;
                    document.frmPaso3.deducRespCivilDes.value = descuento;
                }
                loopIndex++;
            });
            loopIndex = 0;
            for (i = 0; i < document.frmPaso3.cbDeducPerdTotDanos.length; i++){
                document.frmPaso3.cbDeducPerdTotDanos.options[i] = null;
            }
            jQuery(msg).find("Deducible_perdTotDanos").each(function(){
                var deducible = jQuery(this).find("getDeducible").text();
                var descuento = jQuery(this).find("getDescuento").text();
                var numSalarios = jQuery(this).find("getNumSalarios").text();
                var descripcion = jQuery(this).find("descripcion").text();
                document.frmPaso3.cbDeducPerdTotDanos.options[loopIndex] = new Option( descripcion, deducible+";"+descuento+";"+numSalarios);
                if(deducible+";"+descuento+";"+numSalarios == cbDeducPerdTotDanosSel){
                    document.frmPaso3.cbDeducPerdTotDanos.options[loopIndex].selected = true;
                }
                if(loopIndex == 0 || deducible+";"+descuento+";"+numSalarios == cbDeducPerdTotDanosSel){
                    document.frmPaso3.deducPerdTotDanos.value = deducible;
                    document.frmPaso3.deducPerdTotDanosSal.value = numSalarios;
                    document.frmPaso3.deducPerdTotDanosDes.value = descuento;
                }
                loopIndex++;
            });
            loopIndex = 0;
            for (i = 0; i < document.frmPaso3.cbDeducPerdParDanos.length; i++){
                document.frmPaso3.cbDeducPerdParDanos.options[i] = null;
            }
            jQuery(msg).find("Deducible_perdParDanos").each(function(){
                var deducible = jQuery(this).find("getDeducible").text();
                var descuento = jQuery(this).find("getDescuento").text();
                var numSalarios = jQuery(this).find("getNumSalarios").text();
                var descripcion = jQuery(this).find("descripcion").text();
                document.frmPaso3.cbDeducPerdParDanos.options[loopIndex] = new Option( descripcion, deducible+";"+descuento+";"+numSalarios);
                if(deducible+";"+descuento+";"+numSalarios == cbDeducPerdParDanosSel){
                    document.frmPaso3.cbDeducPerdParDanos.options[loopIndex].selected = true;
                }
                if(loopIndex == 0 || deducible+";"+descuento+";"+numSalarios == cbDeducPerdParDanosSel){
                    document.frmPaso3.deducPerdParDanos.value = deducible;
                    document.frmPaso3.deducPerdParDanosSal.value = numSalarios;
                    document.frmPaso3.deducPerdParDanosDes.value = descuento;
                }
                loopIndex++;
            });
            loopIndex = 0;
            for (i = 0; i < document.frmPaso3.cbDeducPerdParHurto.length; i++){
                document.frmPaso3.cbDeducPerdParHurto.options[i] = null;
            }
            jQuery(msg).find("Deducible_perdParHurto").each(function(){
                var deducible = jQuery(this).find("getDeducible").text();
                var descuento = jQuery(this).find("getDescuento").text();
                var numSalarios = jQuery(this).find("getNumSalarios").text();
                var descripcion = jQuery(this).find("descripcion").text();
                document.frmPaso3.cbDeducPerdParHurto.options[loopIndex] = new Option( descripcion, deducible+";"+descuento+";"+numSalarios);
                if(deducible+";"+descuento+";"+numSalarios == cbDeducPerdParHurtoSel){
                    document.frmPaso3.cbDeducPerdParHurto.options[loopIndex].selected = true;
                }
                if(loopIndex == 0 || deducible+";"+descuento+";"+numSalarios == cbDeducPerdParHurtoSel){
                    document.frmPaso3.deducPerdParHurto.value = deducible;
                    document.frmPaso3.deducPerdParHurtoSal.value = numSalarios;
                    document.frmPaso3.deducPerdParHurtoDes.value = descuento;
                }
                loopIndex++;
            });
            loopIndex = 0;
            for (i = 0; i < document.frmPaso3.cbDeducPerdTotHurto.length; i++){
                document.frmPaso3.cbDeducPerdTotHurto.options[i] = null;
            }
            jQuery(msg).find("Deducible_perdTotHurto").each(function(){
                var deducible = jQuery(this).find("getDeducible").text();
                var descuento = jQuery(this).find("getDescuento").text();
                var numSalarios = jQuery(this).find("getNumSalarios").text();
                var descripcion = jQuery(this).find("descripcion").text();
                document.frmPaso3.cbDeducPerdTotHurto.options[loopIndex] = new Option( descripcion, deducible+";"+descuento+";"+numSalarios);
                if(deducible+";"+descuento+";"+numSalarios == cbDeducPerdTotHurtoSel){
                    document.frmPaso3.cbDeducPerdTotHurto.options[loopIndex].selected = true;
                }
                if(loopIndex == 0 || deducible+";"+descuento+";"+numSalarios == cbDeducPerdTotHurtoSel){
                    document.frmPaso3.deducPerdTotHurto.value = deducible;
                    document.frmPaso3.deducPerdTotHurtoSal.value = numSalarios;
                    document.frmPaso3.deducPerdTotHurtoDes.value = descuento;
                }
                loopIndex++;
            });
            loopIndex = 0;
            for (i = 0; i < document.frmPaso3.cbOpcRespCivil.length; i++){
                document.frmPaso3.cbOpcRespCivil.options[i] = null;
            }
            jQuery(msg).find("Opcion_respCivil").each(function(){
                var opcion = jQuery(this).find("getOpcion").text();
                var dsOpcion = jQuery(this).find("getDescripcion").text();
                var numSalarios = jQuery(this).find("getNumSalarios").text();
                var descripcion = jQuery(this).find("descripcion").text();
                document.frmPaso3.cbOpcRespCivil.options[loopIndex] = new Option( descripcion, opcion+";"+dsOpcion+";"+numSalarios);
                if(opcion+";"+dsOpcion+";"+numSalarios == cbOpcRespCivilSel){
                    document.frmPaso3.cbOpcRespCivil.options[loopIndex].selected = true;
                }
                if(loopIndex == 0 || opcion+";"+dsOpcion+";"+numSalarios == cbOpcRespCivilSel){
                    document.frmPaso3.opcionRespCivil.value = opcion;
                    document.frmPaso3.opcionRespCivilSal.value = numSalarios;
                    document.frmPaso3.opcionRespCivilDsOpcion.value = dsOpcion;
                }
                loopIndex++;
            });
            loopIndex = 0;
            for (i = 0; i < document.frmPaso3.cbOpcTranspDanos.length; i++){
                document.frmPaso3.cbOpcTranspDanos.options[i] = null;
            }
            jQuery(msg).find("Opcion_transpDano").each(function(){
                var opcion = jQuery(this).find("getOpcion").text();
                var dsOpcion = jQuery(this).find("getDescripcion").text();
                var numSalarios = jQuery(this).find("getNumSalarios").text();
                var descripcion = jQuery(this).find("descripcion").text();
                document.frmPaso3.cbOpcTranspDanos.options[loopIndex] = new Option( descripcion, opcion+";"+dsOpcion+";"+numSalarios);
                if(opcion+";"+dsOpcion+";"+numSalarios == cbOpcTranspDanosSel){
                    document.frmPaso3.cbOpcTranspDanos.options[loopIndex].selected = true;
                }
                if(loopIndex == 0 || opcion+";"+dsOpcion+";"+numSalarios == cbOpcTranspDanosSel){
                    document.frmPaso3.opcionTranspDanos.value = opcion;
                    document.frmPaso3.opcionTranspDanosSal.value = numSalarios;
                    document.frmPaso3.opcionTranspDanosDsOpcion.value = dsOpcion;
                }
                loopIndex++;
            });
            loopIndex = 0;
            for (i = 0; i < document.frmPaso3.cbOpcTranspHurto.length; i++){
                document.frmPaso3.cbOpcTranspHurto.options[i] = null;
            }
            jQuery(msg).find("Opcion_transpHurto").each(function(){
                var opcion = jQuery(this).find("getOpcion").text();
                var dsOpcion = jQuery(this).find("getDescripcion").text();
                var numSalarios = jQuery(this).find("getNumSalarios").text();
                var descripcion = jQuery(this).find("descripcion").text();
                document.frmPaso3.cbOpcTranspHurto.options[loopIndex] = new Option( descripcion, opcion+";"+dsOpcion+";"+numSalarios);
                if(opcion+";"+dsOpcion+";"+numSalarios == cbOpcTranspHurtoSel){
                    document.frmPaso3.cbOpcTranspHurto.options[loopIndex].selected = true;
                }
                if(loopIndex == 0 || opcion+";"+dsOpcion+";"+numSalarios == cbOpcTranspHurtoSel){
                    document.frmPaso3.opcionTranspHurto.value = opcion;
                    document.frmPaso3.opcionTranspHurtoSal.value = numSalarios;
                    document.frmPaso3.opcionTranspHurtoDsOpcion.value = dsOpcion;
                }
                loopIndex++;
            });
            loopIndex = 0;
            for (i = 0; i < document.frmPaso3.cbOpcionAsistViaje.length; i++){
                document.frmPaso3.cbOpcionAsistViaje.options[i] = null;
            }
            jQuery(msg).find("Asistencia").each(function(){
                var subGarantia = jQuery(this).find("getSubGarantia").text();
                var getDescripcion = jQuery(this).find("getDescripcion").text();
                var getDsalias = jQuery(this).find("getDsalias").text();
                var descripcion = jQuery(this).find("descripcion").text();
                document.frmPaso3.cbOpcionAsistViaje.options[loopIndex] = new Option( descripcion, subGarantia+";"+getDescripcion+";"+getDsalias);
                if(subGarantia+";"+getDescripcion+";"+getDsalias == cbOpcionAsistViajeSel){
                    document.frmPaso3.cbOpcionAsistViaje.options[loopIndex].selected = true;
                }
                if(loopIndex == 0 || subGarantia+";"+getDescripcion+";"+getDsalias == cbOpcionAsistViajeSel){
                    document.frmPaso3.opcionAsistenciaViajeSubGarantia.value = subGarantia;
                    document.frmPaso3.opcionAsistenciaViajeDescripcion.value = getDescripcion;
                    document.frmPaso3.opcionAsistenciaViajeDsAlias.value = getDsalias;
                }
                loopIndex++;
            });
            loopIndex = 0;
            for (i = 0; i < document.frmPaso3.cbOpcAccConductor.length; i++){
                document.frmPaso3.cbOpcAccConductor.options[i] = null;
            }
            jQuery(msg).find("Opcion_accConductor").each(function(){
                var opcion = jQuery(this).find("getOpcion").text();
                var dsOpcion = jQuery(this).find("getDescripcion").text();
                var numSalarios = jQuery(this).find("getNumSalarios").text();
                var descripcion = jQuery(this).find("descripcion").text();
                document.frmPaso3.cbOpcAccConductor.options[loopIndex] = new Option( descripcion, opcion+";"+dsOpcion+";"+numSalarios);
                if( opcion+";"+dsOpcion+";"+numSalarios == cbOpcAccConductorSel){
                    document.frmPaso3.cbOpcAccConductor.options[loopIndex].selected = true;
                }
                if(loopIndex == 0 || opcion+";"+dsOpcion+";"+numSalarios == cbOpcAccConductorSel){
                    document.frmPaso3.opcionAccConductor.value = opcion;
                    document.frmPaso3.opcionAccConductorDsOpcion.value = dsOpcion;
                    document.frmPaso3.opcionAccConductorSal.value = numSalarios;
                }
                loopIndex++;
            });
            loopIndex = 0;
            for (i = 0; i < document.frmPaso3.cbOpcVehReemplazoTotal.length; i++){
                document.frmPaso3.cbOpcVehReemplazoTotal.options[i] = null;
            }
            jQuery(msg).find("Opcion_vehReempTotal").each(function(){
                var opcion = jQuery(this).find("getOpcion").text();
                var dsOpcion = jQuery(this).find("getDescripcion").text();
                var numSalarios = jQuery(this).find("getNumSalarios").text();
                var descripcion = jQuery(this).find("descripcion").text();
                document.frmPaso3.cbOpcVehReemplazoTotal.options[loopIndex] = new Option( descripcion, opcion+";"+dsOpcion+";"+numSalarios);
                if( opcion+";"+dsOpcion+";"+numSalarios == cbOpcVehReemplazoTotalSel){
                    document.frmPaso3.cbOpcVehReemplazoTotal.options[loopIndex].selected = true;
                }
                if(loopIndex == 0 || opcion+";"+dsOpcion+";"+numSalarios == cbOpcVehReemplazoTotalSel){
                    document.frmPaso3.opcionVehReemplazoTotal.value = opcion;
                    document.frmPaso3.opcionVehReemplazoTotalSal.value = numSalarios;
                    document.frmPaso3.opcionVehReemplazoTotalDsOpcion.value = dsOpcion;
                }
                loopIndex++;
            });
            loopIndex = 0;
            for (i = 0; i < document.frmPaso3.cbOpcVehReemplazoParcial.length; i++){
                document.frmPaso3.cbOpcVehReemplazoParcial.options[i] = null;
            }
            jQuery(msg).find("Opcion_vehReempParcial").each(function(){
                var opcion = jQuery(this).find("getOpcion").text();
                var dsOpcion = jQuery(this).find("getDescripcion").text();
                var numSalarios = jQuery(this).find("getNumSalarios").text();
                var descripcion = jQuery(this).find("descripcion").text();
                document.frmPaso3.cbOpcVehReemplazoParcial.options[loopIndex] = new Option( descripcion, opcion+";"+dsOpcion+";"+numSalarios);
                if( opcion+";"+dsOpcion+";"+numSalarios == cbOpcVehReemplazoParcialSel){
                    document.frmPaso3.cbOpcVehReemplazoParcial.options[loopIndex].selected = true;
                }
                if(loopIndex == 0 || opcion+";"+dsOpcion+";"+numSalarios == cbOpcVehReemplazoParcialSel){
                    document.frmPaso3.opcionVehReemplazoParcial.value = opcion;
                    document.frmPaso3.opcionVehReemplazoParcialSal.value = numSalarios;
                    document.frmPaso3.opcionVehReemplazoParcialDsOpcion.value = dsOpcion;
                }
                loopIndex++;
            });
            jQuery(msg).find("Excepcion_deducibles").each(function(){
                excDedPerdTotDanos = jQuery(this).find("excDedPerdTotDanos").text();
                excDedPerdParDanos = jQuery(this).find("excDedPerdParDanos").text();
                excDedPerdParHurto = jQuery(this).find("excDedPerdParHurto").text();
                excDedPerdTotHurto = jQuery(this).find("excDedPerdTotHurto").text();
            });
        },
        error: function( event, request, settings ){
            alert( "Error en listarDeducibles" );
            alert(event);
            alert(request);
            alert(settings);
            return false;
        }
    });
}

function actualizarDeducRespCivil(){
    var valor = document.frmPaso3.cbDeducRespCivil.options[document.frmPaso3.cbDeducRespCivil.selectedIndex].value;
    var dedArray = valor.split(';');
    document.frmPaso3.deducRespCivil.value = dedArray[0];
    document.frmPaso3.deducRespCivilSal.value = dedArray[2];
    document.frmPaso3.deducRespCivilDes.value = dedArray[1];
}
function actualizarDeducPerdTotDanos(){
    ocultarMensajes();
    var valor = document.frmPaso3.cbDeducPerdTotDanos.options[document.frmPaso3.cbDeducPerdTotDanos.selectedIndex].value;
    var dedArray = valor.split(';');
    document.frmPaso3.deducPerdTotDanos.value = dedArray[0];
    document.frmPaso3.deducPerdTotDanosSal.value = dedArray[2];
    document.frmPaso3.deducPerdTotDanosDes.value = dedArray[1];
    if(validarExcepcionDeducible()){
        mensajeAdvertencia("Este vehiculo para esta zona es excepcion de deducible, consulte con su asesor")
    }
}
function actualizarDeducPerdParDanos(){
    ocultarMensajes();
    var valor = document.frmPaso3.cbDeducPerdParDanos.options[document.frmPaso3.cbDeducPerdParDanos.selectedIndex].value;
    var dedArray = valor.split(';');
    document.frmPaso3.deducPerdParDanos.value = dedArray[0];
    document.frmPaso3.deducPerdParDanosSal.value = dedArray[2];
    document.frmPaso3.deducPerdParDanosDes.value = dedArray[1];
    if(validarExcepcionDeducible()){
        mensajeAdvertencia("Este vehiculo para esta zona es excepcion de deducible, consulte con su asesor")
    }
}
function actualizarDeducPerdTotHurto(){
    ocultarMensajes();
    var valor = document.frmPaso3.cbDeducPerdTotHurto.options[document.frmPaso3.cbDeducPerdTotHurto.selectedIndex].value;
    var dedArray = valor.split(';');
    document.frmPaso3.deducPerdTotHurto.value = dedArray[0];
    document.frmPaso3.deducPerdTotHurtoSal.value = dedArray[2];
    document.frmPaso3.deducPerdTotHurtoDes.value = dedArray[1];
    if(validarExcepcionDeducible()){
        mensajeAdvertencia("Este vehiculo para esta zona es excepcion de deducible, consulte con su asesor")
    }
}
function actualizarDeducPerdParHurto(){
    ocultarMensajes();
    var valor = document.frmPaso3.cbDeducPerdParHurto.options[document.frmPaso3.cbDeducPerdParHurto.selectedIndex].value;
    var dedArray = valor.split(';');
    document.frmPaso3.deducPerdParHurto.value = dedArray[0];
    document.frmPaso3.deducPerdParHurtoSal.value = dedArray[2];
    document.frmPaso3.deducPerdParHurtoDes.value = dedArray[1];
    if(validarExcepcionDeducible()){
        mensajeAdvertencia("Este vehiculo para esta zona es excepcion de deducible, consulte con su asesor")
    }
}
function actualizarOpcionRespCivil(){
    var valor = document.frmPaso3.cbOpcRespCivil.options[document.frmPaso3.cbOpcRespCivil.selectedIndex].value;
    var dedArray = valor.split(';');
    document.frmPaso3.opcionRespCivil.value = dedArray[0];
    document.frmPaso3.opcionRespCivilSal.value = dedArray[2];
    document.frmPaso3.opcionRespCivilDsOpcion.value = dedArray[1];
}
function actualizarTranspDanos(){
    var valor = document.frmPaso3.cbOpcTranspDanos.options[document.frmPaso3.cbOpcTranspDanos.selectedIndex].value;
    var dedArray = valor.split(';');
    document.frmPaso3.opcionTranspDanos.value = dedArray[0];
    document.frmPaso3.opcionTranspDanosSal.value = dedArray[2];
    document.frmPaso3.opcionTranspDanosDsOpcion.value = dedArray[1];
}
function actualizarTranspHurto(){
    var valor = document.frmPaso3.cbOpcTranspHurto.options[document.frmPaso3.cbOpcTranspHurto.selectedIndex].value;
    var dedArray = valor.split(';');
    document.frmPaso3.opcionTranspHurto.value = dedArray[0];
    document.frmPaso3.opcionTranspHurtoSal.value = dedArray[2];
    document.frmPaso3.opcionTranspHurtoDsOpcion.value = dedArray[1];
}
function actualizarOpcVehReemplazoTotal(){
    var valor = document.frmPaso3.cbOpcVehReemplazoTotal.options[document.frmPaso3.cbOpcVehReemplazoTotal.selectedIndex].value;
    var dedArray = valor.split(';');
    document.frmPaso3.opcionVehReemplazoTotal.value = dedArray[0];
    document.frmPaso3.opcionVehReemplazoTotalSal.value = dedArray[2];
    document.frmPaso3.opcionVehReemplazoTotalDsOpcion.value = dedArray[1];
}

function actualizarOpcVehReemplazoParcial(){
    var valor = document.frmPaso3.cbOpcVehReemplazoParcial.options[document.frmPaso3.cbOpcVehReemplazoParcial.selectedIndex].value;
    var dedArray = valor.split(';');
    document.frmPaso3.opcionVehReemplazoParcial.value = dedArray[0];
    document.frmPaso3.opcionVehReemplazoParcialSal.value = dedArray[2];
    document.frmPaso3.opcionVehReemplazoParcialDsOpcion.value = dedArray[1];
}

function actualizarOpcAccConductor(){
    var valor = document.frmPaso3.cbOpcAccConductor.options[document.frmPaso3.cbOpcAccConductor.selectedIndex].value;
    var dedArray = valor.split(';');
    document.frmPaso3.opcionAccConductor.value = dedArray[0];
    document.frmPaso3.opcionAccConductorSal.value = dedArray[2];
    document.frmPaso3.opcionAccConductorDsOpcion.value = dedArray[1];
}

function actualizarOpcionAsistViaje(){
    var valor = document.frmPaso3.cbOpcionAsistViaje.options[document.frmPaso3.cbOpcionAsistViaje.selectedIndex].value;
    var dedArray = valor.split(';');
    document.frmPaso3.opcionAsistenciaViajeSubGarantia.value = dedArray[0];
    document.frmPaso3.opcionAsistenciaViajeDsAlias.value = dedArray[2];
    document.frmPaso3.opcionAsistenciaViajeDescripcion.value = dedArray[1];
}

function coberturasVisibles(){
    var producto = document.frmPaso3.producto.options[document.frmPaso3.producto.selectedIndex].value;
    if(producto == '003'){
        document.getElementById("accidenteConductor").style.display = 'block';
        document.getElementById("reemplazoParcial").style.display = 'block';
        document.getElementById("reemplazoTotal").style.display = 'block';
    } else {
        document.getElementById("accidenteConductor").style.display = 'none';
        document.getElementById("reemplazoParcial").style.display = 'none';
        document.getElementById("reemplazoTotal").style.display = 'none';
    }
}

function validarExcepcionDeducible(){
    var valor1 = document.frmPaso3.cbDeducPerdTotDanos.options[document.frmPaso3.cbDeducPerdTotDanos.selectedIndex].value;
    var valor2 = document.frmPaso3.cbDeducPerdParDanos.options[document.frmPaso3.cbDeducPerdParDanos.selectedIndex].value;
    var valor3 = document.frmPaso3.cbDeducPerdTotHurto.options[document.frmPaso3.cbDeducPerdTotHurto.selectedIndex].value;
    var valor4 = document.frmPaso3.cbDeducPerdParHurto.options[document.frmPaso3.cbDeducPerdParHurto.selectedIndex].value;
    if((excDedPerdTotDanos != "" && excDedPerdTotDanos != valor1) ||
        (excDedPerdParDanos != "" && excDedPerdParDanos != valor2) ||
        (excDedPerdTotHurto != "" && excDedPerdTotHurto != valor3) ||
        (excDedPerdParHurto != "" && excDedPerdParHurto != valor4)){
        return true;
    } else {
        return false;
    }
}

