//-------------------------------------------------------//
// Author:Rodolfo Machon
// Company:WebSoft, SA de CV 
// Nombre del archivo: expediente_comm.js
// Created: 2016-03-26
// Updates: 2016-03-26
// Copyright - All Rights Reserved
//-------------------------------------------------------//
//-------------------------------------------------------//
var client = new XMLHttpRequest();
//-------------------------------------------------------//
window.onload = function(){

};
//-------------------------------------------------------//
// LEVEL 1
function Go(){
    var field   = "";
    var pago    = document.getElementsByName('pago');
    for(var i = 0; i < pago.length; i++){
        if(pago[i].checked){
            field = pago[i].value;
        }
    }
    if(field===""){alert("Ingrese informacion en el campo seleccionado");}
    switch (field) {
        case "i8_inmueble_id":
            getNucInmueble(field);
            break;
        case "i8_empresa_id":
            getNucEmpresa(field);
            break;
        case "i8_nis_id":
            getNucNis(field);
            break;
        case "i8_nic_id":
            getNucNic(field);
            break;
        case "c8_cuenta_rct_id":
            getNucCodigo(field);
            break;
        case "c16_codigo_catastral_id":
            getNucParcela(field);
            break;
        default:
           alert('Opcion No Existe');
    }
}
//-------------------------------------------------------//
// LEVEL 2
function getNucInmueble(fld) {
    var clase   = parent.list.document.linkl.clase.value;
    var val     = document.getElementById(fld).value;
    var url   	= "../pl/nuc.inmueble.get.pl?clase="+clase+"&id="+val;
    client.onreadystatechange = function () {
        if (client.readyState == 4 && client.status == 200) {
            var id = client.responseText;
            //alert(client.responseText);
            document.linkf.i8_nuc_id.value = id;
            parent.list.GetOptions();
            LoadFrame();
        }
    };
    client.open("GET",url,true);
    client.setRequestHeader("Content-Type", "multipart/form-data");
    client.send(null);
}
function getNucEmpresa(fld) {
    var clase   = parent.list.document.linkl.clase.value;
    var val     = document.getElementById(fld).value;
    var url   	= "../pl/nuc.empresa.get.pl?clase="+clase+"&id="+val;
    client.onreadystatechange = function () {
        if (client.readyState == 4 && client.status == 200) {
            var id = client.responseText;
            //alert(client.responseText);
            document.linkf.i8_nuc_id.value = id;
            parent.list.GetOptions();
            LoadFrame();
        }
    };
    client.open("GET",url,true);
    client.setRequestHeader("Content-Type", "multipart/form-data");
    client.send(null);
}
function getNucNis(fld) {
    var clase   = parent.list.document.linkl.clase.value;
    var val     = document.getElementById(fld).value;
    var url   	= "../pl/nuc.nis.get.pl?clase="+clase+"&id="+val;
    client.onreadystatechange = function () {
        if (client.readyState == 4 && client.status == 200) {
            var id = client.responseText;
            document.linkf.i8_nuc_id.value = id;
            parent.list.GetOptions();
            LoadFrame();
        }
    };
    client.open("GET",url,true);
    client.setRequestHeader("Content-Type", "multipart/form-data");
    client.send(null);
}
function getNucNic(fld) {
    var clase   = parent.list.document.linkl.clase.value;
    var val     = document.getElementById(fld).value;
    var url   	= "../pl/nuc.nic.get.pl?clase="+clase+"&id="+val;
    client.onreadystatechange = function () {
        if (client.readyState == 4 && client.status == 200) {
            var id = client.responseText;
            document.linkf.i8_nuc_id.value = id;
            parent.list.GetOptions();
            LoadFrame();
        }
    };
    client.open("GET",url,true);
    client.setRequestHeader("Content-Type", "multipart/form-data");
    client.send(null);
}
function getNucCodigo(fld) {
    var clase   = parent.list.document.linkl.clase.value;
    var val     = document.getElementById(fld).value;
    var url   	= "../pl/nuc.codigo.get.pl?clase="+clase+"&id="+val;
    client.onreadystatechange = function () {
        if (client.readyState == 4 && client.status == 200) {
            var id = client.responseText;
            document.linkf.i8_nuc_id.value = id;
            parent.list.GetOptions();
            LoadFrame();
        }
    };
    client.open("GET",url,true);
    client.setRequestHeader("Content-Type", "multipart/form-data");
    client.send(null);
}
function getNucParcela(fld) {
    var clase   = parent.list.document.linkl.clase.value;
    var val     = document.getElementById(fld).value;
    var url   	= "../pl/nuc.parcela.get.pl?clase="+clase+"&id="+val;
    client.onreadystatechange = function () {
        if (client.readyState == 4 && client.status == 200) {
            var id = client.responseText;
            document.linkf.i8_nuc_id.value = id;
            parent.list.GetOptions();
            LoadFrame();
        }
    };
    client.open("GET",url,true);
    client.setRequestHeader("Content-Type", "multipart/form-data");
    client.send(null);
}
function buscarContribuyente() {
    parent.list.GetBack('srch','contribuyentes','i8_contribuyente_id','contribuyente.expedientes.get|contribuyente.expedientes|i8_expediente_id|parent.opener.parent.opener.parent.form.document.linkf|200|100||i8_expediente_id||',300,100,'','i8_contribuyente_id',1);
}
function buscarUbicacion() {
    alert("EN CONSTRUCCION......");
}
function buscarNuc() {
    alert("EN CONSTRUCCION......");
}
function LoadFrame(){
    if(document.linkf.i8_nuc_id.value!=""){
        parent.list.OpenFrameNABS('VerRegistro','nuc_repts,nuc')    
    }
}