﻿function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }

    var newArray = new Array(scrOfX, scrOfY);
    return newArray;
}

function GetWindowSize() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    var newArray = new Array(myWidth, myHeight);
    return newArray;
}

function autoResize(id) {
    // Solo para probar Exploradores
    var objDiv = parent.document.getElementById('frame');
    var objAviso = parent.document.getElementById('aviso');

    var wiw = window.innerWidth;
    var wih = window.innerHeigh;
    var dbow = document.body.offsetWidth;
    var dboh = window.innerHeight;
    var dbsw = document.body.scrollWidth;
    var dbsh = document.body.scrollHeight;
    var sh = screen.height;
    var sw = screen.width;
    var dbch = document.body.clientHeight;
    var dbcw = document.body.clientWidth;

    var scrOfY = document.documentElement.scrollTop;
    var scrOfX = document.documentElement.scrollLeft;

    //Funciona en ambos Expl.
    var ddeh = document.documentElement.clientHeight;
    var ddew = document.documentElement.clientWidth;


    if (parseInt(navigator.appVersion) > 3) {
        if (navigator.appName == "Netscape") {
            objDiv.width = ddew;
            objDiv.height = ddeh;
        }
        if (navigator.appName.indexOf("Microsoft") != -1) {
            objDiv.width = ddew;
            objDiv.height = ddeh;
        }
    }
}



function cambiarEstado(idProceso) {

    var nombreDiv = "divEstadoBusqueda" + idProceso;
    var nombreImagen = "btnCambiarEstado" + idProceso;
    var divInfoDetalle = "divInfoDetalle" + idProceso;
    var hidden = document.getElementById('HFResultados');

    var estiloActual = document.getElementById(nombreDiv).className;

    if (document.getElementById(nombreImagen).className == "btn_menos" || document.getElementById(nombreImagen).className == "btn_menos_b") {
        //Validar si se trata de un empleo destacado para no cambiar el header
        if (estiloActual == "empleo_destacado") {

            document.getElementById(nombreImagen).className = "btn_mas_b";
        }
        else {
            document.getElementById(nombreDiv).className = "tabla_inactive";
            document.getElementById(nombreImagen).className = "btn_mas";
        }

        document.getElementById(divInfoDetalle).style.display = "none";
    }
    else {
        //Validar si se trata de un empleo destacado para no cambiar el header 
        if (estiloActual == "empleo_destacado") {
            document.getElementById(nombreImagen).className = "btn_menos_b";
        }
        else {
            document.getElementById(nombreDiv).className = "tabla_active";
            document.getElementById(nombreImagen).className = "btn_menos";
        }
        document.getElementById(divInfoDetalle).style.display = "block";
    }


    if (document.getElementById(divInfoDetalle).style.display == 'none') {
        agregarPestana(idProceso, 0);
    }
    else {
        agregarPestana(idProceso, 1);
    }


}

function relocatedivwin(width, heigh) {
    document.getElementById("frame").height = heigh;
    document.getElementById("frame").width = width;
}

function bloquear() {
    try {
        var ifra = document.getElementById("frame");
        var ancho;
        var alto;
        var top;

        document.getElementById("fondoOpaco").style.display = "block";
        document.getElementById("aviso").style.display = "block";
        document.getElementById("BodyMaster").setAttribute("scroll", "yes");

        ancho = GetWindowSize()[0] - 20;
        alto = GetWindowSize()[1] - 15;
        top = getScrollXY()[1] - 10;

        ifra.height = alto + "px";
        ifra.width = ancho + "px";
        document.getElementById("aviso").style.top = top + "px";
    }
    catch (err) { }
}


function bloquearDimencionar(ancho, alto) {
    try {
        var ifra = document.getElementById("frame");
        var top;
        document.getElementById("fondoOpaco").style.display = "block";
        document.getElementById("aviso").style.display = "block";
        document.getElementById("BodyMaster").setAttribute("scroll", "yes");
        top = getScrollXY()[1] - 10;
        ifra.height = alto + "px";
        ifra.width = ancho + "px";
        document.getElementById("aviso").style.top = top + "px";
    }
    catch (err) { }
}


function RedimensionarHTM() {
    try {
        var ifra = document.getElementById("baseFrame");
        var ancho;
        var alto;
        ancho = GetWindowSize()[0];
        alto = GetWindowSize()[1] + 50;
        ifra.height = alto + "px";
        ifra.width = ancho + "px";
        document.getElementById("DivScroll").style.display = "block";
    }
    catch (err) { }
}

function dimensionar() {
    try {

        window.frames["frame"].document.getElementById("divMensaje").style.height = document.getElementById("frame").height - 50 + "px";
        window.frames["frame"].document.getElementById("TbMensaje").style.height = document.getElementById("frame").height - 60 + "px";
        window.frames["frame"].document.getElementById("TbMensaje").style.width = document.getElementById("frame").width - 30 + "px";
    }
    catch (err) {
    }
}

function ocultar() {
    document.getElementById("fondoOpaco").style.display = "none";
    document.getElementById("aviso").style.display = "none";
    document.getElementById("BodyMaster").setAttribute("scroll", "yes");
    document.getElementById("BodyMaster").style.overflow = "auto";
    HideCombos("visible");
}

function opendivwin(width, heigh, path) {
    try {
        HideCombos("hidden");
        if (document.getElementById("frame") != null) {
            document.getElementById("frame").src = path;
        }
    }
    catch (e) { alert(path); }
}
function HideCombos(State) {
    var objArray = document.getElementsByTagName('SELECT');
    for (i = 0; i < objArray.length; i++) {
        objArray[i].style.visibility = State;
    }
}


/*funciones para mostrar tool tip*/

//Funcion obtener la posicion X y Y 
function getPosition(e) {
    e = e || window.event;
    var cursor = { x: 0, y: 0 };
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    }
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX +
                (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY +
                (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}

function showDiv(divNombre, strTexto) {
    var isIE = (window.navigator.userAgent.indexOf("MSIE") > 0);
    if (!isIE) {
        HTMLElement.prototype.__defineGetter__("innerText", function () { return (this.textContent); });
        HTMLElement.prototype.__defineSetter__("innerText", function (txt) { this.textContent = txt; });
    }

    var objDiv = document.getElementById(divNombre);
    objDiv.style.display = "block";
    objDiv.style.left = getPosition().x + 5 + "px";
    objDiv.style.top = getPosition().y - 5 + "px";
    document.getElementById("textoInterno").innerText = strTexto;
}

function showDivFlotante(nomDiv) {

    var isIE = (window.navigator.userAgent.indexOf("MSIE") > 0);
    if (!isIE) {
        HTMLElement.prototype.__defineGetter__("innerText", function () { return (this.textContent); });
        HTMLElement.prototype.__defineSetter__("innerText", function (txt) { this.textContent = txt; });
    }

    var objDiv = document.getElementById(nomDiv);
    objDiv.style.display = "block";
}


/*Funciones para los globos de ayuda*/
function getPositionLeft(This) {
    var el = This; var pL = 0;
    while (el) { pL += el.offsetLeft; el = el.offsetParent; }
    return pL
}

function getPositionTop(This) {
    var el = This; var pT = 0;
    while (el) { pT += el.offsetTop; el = el.offsetParent; }
    return pT
}

function mostrarGlobo(nombreControl, anchoControl, textoIlustrar) {
    var objFlotante = document.getElementById("divFlotante");
    if (textoIlustrar != "") {
        var isIE = (window.navigator.userAgent.indexOf("MSIE") > 0);
        if (!isIE) {
            HTMLElement.prototype.__defineGetter__("innerText", function () { return (this.textContent); });
            HTMLElement.prototype.__defineSetter__("innerText", function (txt) { this.textContent = txt; });
        }

        var objControlPosicionar = document.getElementById(nombreControl);

        var leftPosition = getPositionLeft(objControlPosicionar) + anchoControl;
        var topPosition = getPositionTop(objControlPosicionar);

        objFlotante.style.top = topPosition + 'px';
        objFlotante.style.left = leftPosition + 'px';
        document.getElementById("textoInterno").innerText = textoIlustrar;
        objFlotante.style.display = "block";
    }
    else {
        hideDivFlotante("divFlotante");
    }
}



function hideDivFlotante(nomDiv) {
    var isIE = (window.navigator.userAgent.indexOf("MSIE") > 0);
    if (!isIE) {
        HTMLElement.prototype.__defineGetter__("innerText", function () { return (this.textContent); });
        HTMLElement.prototype.__defineSetter__("innerText", function (txt) { this.textContent = txt; });
    }

    var objDiv = document.getElementById(nomDiv);
    objDiv.style.display = "none";
}

function ocultarDiv(divBoton, divOcultar) {

    var objBoton = document.getElementById(divBoton);
    var objOcultar = document.getElementById(divOcultar);

    if (objBoton.className == "btn_mas2") {
        objBoton.className = "btn_menos2";
        objOcultar.style.display = "block";
    }
    else {
        objBoton.className = "btn_mas2";
        objOcultar.style.display = "none";
    }
}

//Imprimir IFrame de HV
function iprint() {
    var objFramePrint = window.frames["printHv"];
    objFramePrint.focus();
    objFramePrint.print();

}


//Validacion de los datos personales
function validarInfoPersonalBasico(boolValidarFoco) {
    var boolValidar = true;
    var boolValidarFoco = true;

    //Controles a validar registro general
    var arrayControlValidate = new Array(6)
    arrayControlValidate[0] = "txtNombre";
    arrayControlValidate[1] = "txtApellido";
    arrayControlValidate[2] = "txtNumeroDocumento";
    arrayControlValidate[3] = "txtClave";
    arrayControlValidate[4] = "txtCelular";
    arrayControlValidate[5] = "txtTelefono";
    arrayControlValidate[6] = "txtValidacionCaptcha";

    for (i = 0; i < arrayControlValidate.length; i++) {
        if (document.getElementById(arrayControlValidate[i]) != null) {
            var ctlValidar = document.getElementById(arrayControlValidate[i]);
            if (ctlValidar.value == "") {
                ctlValidar.style.backgroundColor = "#FFDBC4";
                ctlValidar.style.border = "1px solid #FF6F0F";
                boolValidar = false;

                //Valida que el foco quede en el primer objeto invalido
                if (boolValidarFoco == true) {
                    boolValidarFoco = false;
                    ctlValidar.focus();
                }
            }
            else {
                ctlValidar.style.backgroundColor = "";
                if (arrayControlValidate[i] == "txtCorreoElectronico") {
                    ctlValidar.style.border = "3px solid #96B5DA";
                }
                else {
                    ctlValidar.style.border = "1px solid #CCCCCC";
                }
            }
        }
    }

    //Validar lugar de residencia, si es positivo quiere decir que el control esta vacio
    if (document.getElementById("txtLugarResidencia").value == "Escribe tu ciudad, país o departamento") {
        document.getElementById("txtLugarResidencia").style.backgroundColor = "#FFDBC4";
        document.getElementById("txtLugarResidencia").style.border = "1px solid #FF6F0F";
        boolValidar = false;
    }
    else {
        document.getElementById("txtLugarResidencia").style.backgroundColor = "";
        document.getElementById("txtLugarResidencia").style.border = "1px solid #CCCCCC";
    }

    //Validar tipo de documento
    if (document.getElementById("ddlTipoDocumento").value == "0") {
        boolValidar = false;
        document.getElementById("ddlTipoDocumento").style.backgroundColor = "#FFDBC4";
    }
    else {
        document.getElementById("ddlTipoDocumento").style.backgroundColor = "";
    }

    //Validar correo electronico
    var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    strCorreo = document.getElementById("txtCorreoElectronico").value;

    if (strCorreo != "") {
        if (strCorreo.match(emailRegEx)) {
            document.getElementById("txtCorreoElectronico").style.backgroundColor = "";
            document.getElementById("txtCorreoElectronico").style.border = "3px solid #96B5DA";
        }
        else {
            document.getElementById("txtCorreoElectronico").style.backgroundColor = "#FFDBC4";
            document.getElementById("txtCorreoElectronico").style.border = "1px solid #FF6F0F";
            boolValidar = false;

            //Valida que el foco quede en el primer objeto invalido
            if (boolValidarFoco == true) {
                boolValidarFoco = false;
                document.getElementById("txtCorreoElectronico").focus();
            }
        }
    }

    return boolValidar;
}


//Validacion de los datos personales
function validarInfoPersonal(boolValidarFoco) {
    var boolValidar = true;
    var boolValidarFoco = true;

    //Controles a validar registro general
    var arrayControlValidate = new Array(8)
    arrayControlValidate[0] = "txtNombre";
    arrayControlValidate[1] = "txtApellido";
    arrayControlValidate[2] = "txtNumeroDocumento";
    arrayControlValidate[3] = "txtClave";
    arrayControlValidate[4] = "txtCorreoElectronico";
    arrayControlValidate[5] = "txtTelefono";
    arrayControlValidate[6] = "txtValidacionCaptcha";
    arrayControlValidate[7] = "txtDireccionResidencia";
    arrayControlValidate[8] = "txtNick";


    for (i = 0; i < arrayControlValidate.length; i++) {
        if (document.getElementById(arrayControlValidate[i]) != null) {
            var ctlValidar = document.getElementById(arrayControlValidate[i]);
            if (ctlValidar.value == "") {
                ctlValidar.style.backgroundColor = "#FFDBC4";
                ctlValidar.style.border = "1px solid #FF6F0F";
                boolValidar = false;

                //Valida que el foco quede en el primer objeto invalido
                if (boolValidarFoco == true) {
                    boolValidarFoco = false;
                    if (ctlValidar.disabled == false) {
                        ctlValidar.focus();
                    }
                }
            }
            else {
                ctlValidar.style.backgroundColor = "";
                ctlValidar.style.border = "1px solid #CCCCCC";
            }
        }
    }

    //Validar sexo
    var objCheckMasculino = document.getElementById("rbtnMasculino");
    var objCheckFemenino = document.getElementById("rbtnFemenino");
    if (objCheckMasculino != null && objCheckFemenino != null) {
        var objTableGenero = document.getElementById("tableGenero");
        if (objTableGenero != null) {
            if (objCheckMasculino.checked == false && objCheckFemenino.checked == false) {
                boolValidar = false;
                objTableGenero.style.backgroundColor = "#FFDBC4";
                objTableGenero.style.border = "1px solid #FF6F0F";
            }
            else {
                objTableGenero.style.backgroundColor = "";
                objTableGenero.style.border = "";
            }
        }
    }

    //Validar tipo de documento
    if (document.getElementById("ddlTipoDocumento").value == "0") {
        boolValidar = false;
        document.getElementById("ddlTipoDocumento").style.backgroundColor = "#FFDBC4";
    }
    else {
        document.getElementById("ddlTipoDocumento").style.backgroundColor = "";
    }

    //Validar correo electronico
    var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    strCorreo = document.getElementById("txtCorreoElectronico").value;
    if (strCorreo != "") {
        if (strCorreo.match(emailRegEx)) {
            document.getElementById("txtCorreoElectronico").style.backgroundColor = "";
            document.getElementById("txtCorreoElectronico").style.border = "3px solid #96B5DA";
        }
        else {
            document.getElementById("txtCorreoElectronico").style.backgroundColor = "#FFDBC4";
            document.getElementById("txtCorreoElectronico").style.border = "1px solid #FF6F0F";
            boolValidar = false;

            //Valida que el foco quede en el primer objeto invalido
            if (boolValidarFoco == true) {
                boolValidarFoco = false;
                document.getElementById("txtCorreoElectronico").focus();
            }
        }
    }

    //Mostrar mensaje con campos invalidos
    if (boolValidar == false) {
        opendivwin('500', '280', 'mensajeGenerico.aspx?titulo=Confirmacio*n datos&detalle=Revisa la informacio*n sombreada antes de continuar.&boton=Aceptar'); bloquear();
    }

    return boolValidar;
}


function IsNumeric(sText) {
    var ValidChars = "0123456789";
    var IsNumber = true;
    var Char;


    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}

function IsDecimal(sText) {
    var ValidChars = "0123456789,.";
    var IsNumber = true;
    var Char;


    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}



//Validar estudios
function validarEstudiosRegistro() {
    var boolValidar = true;
    var boolValidarFoco = true;

    //Validar listas
    var arrayListasValidate = new Array(4);
    arrayListasValidate[0] = "ddlNivelEstudios";
    arrayListasValidate[1] = "ddlTipoDuracion";
    arrayListasValidate[2] = "ddlInicioMesEstudio";
    arrayListasValidate[3] = "ddlAnoInicioEstudio";
    arrayListasValidate[4] = "ddlAnoFinEstudio";

    for (i = 0; i < arrayListasValidate.length; i++) {
        var ctlValidarListas = document.getElementById(arrayListasValidate[i]);
        if (ctlValidarListas != null) {
            if (ctlValidarListas.value == "0") {
                ctlValidarListas.style.backgroundColor = "#FFDBC4";
                boolValidar = false;
            }
            else {
                ctlValidarListas.style.backgroundColor = "";
            }
        }
    }

    //Validar input text
    //Controles a validar registro general
    var arrayControlValidate = new Array(1)
    arrayControlValidate[0] = "txtTituloObtenido";
    arrayControlValidate[1] = "txtInstitucion";

    for (i = 0; i < arrayControlValidate.length; i++) {
        if (document.getElementById(arrayControlValidate[i]) != null) {
            var ctlValidar = document.getElementById(arrayControlValidate[i]);
            if (ctlValidar.value == "") {
                ctlValidar.style.backgroundColor = "#FFDBC4";
                ctlValidar.style.border = "1px solid #FF6F0F";
                boolValidar = false;

                //Valida que el foco quede en el primer objeto invalido
                if (boolValidarFoco == true) {
                    boolValidarFoco = false;
                    ctlValidar.focus();
                }
            }
            else {
                ctlValidar.style.backgroundColor = "";
                ctlValidar.style.border = "1px solid #CCCCCC";
            }
        }
    }

    //Validar duracion que sea numerico
    var ctlValidarDuracion = document.getElementById("txtDuracion");
    if (IsDecimal(ctlValidarDuracion.value) == false || ctlValidarDuracion.value == "") {
        ctlValidarDuracion.style.backgroundColor = "#FFDBC4";
        ctlValidarDuracion.style.border = "1px solid #FF6F0F";
        boolValidar = false;

        //Valida que el foco quede en el primer objeto invalido
        if (boolValidarFoco == true) {
            boolValidarFoco = false;
            ctlValidarDuracion.focus();
        }
    }
    else {
        ctlValidarDuracion.style.backgroundColor = "";
        ctlValidarDuracion.style.border = "1px solid #CCCCCC";
    }


    //********** Validadar Fechas

    var mi = document.getElementById("ddlInicioMesEstudio").value
    var mf = document.getElementById("ddlFinMesEstudio").value
    var ai = document.getElementById("ddlAnoInicioEstudio").value
    var af = document.getElementById("ddlAnoFinEstudio").value


    var di = new Date(ai, mi, 1);  // creates a new Date for the 1st June 2005
    var df = new Date(af, mf, 1); // creates a new Date representing today

    var milli_d1 = di.getTime();
    var milli_d2 = df.getTime();
    var diff = milli_d1 - milli_d2;

    if (mf != -1 && af != -1) {
        if (diff > 0) {
            boolValidar = false;
            document.getElementById("ddlInicioMesEstudio").style.backgroundColor = "#FFDBC4";
            document.getElementById("ddlInicioMesEstudio").style.border = "1px solid #FF6F0F";

            document.getElementById("ddlAnoInicioEstudio").style.backgroundColor = "#FFDBC4";
            document.getElementById("ddlAnoInicioEstudio").style.border = "1px solid #FF6F0F";

            //Mostrar mensaje con campos invalidos
            if (boolValidar == false) {
                opendivwin('500', '280', 'mensajeGenerico.aspx?titulo=Confirmacio*n datos de estudios&detalle=La fecha de inicio debe ser menor a la fecha de finalizacio*n&boton=Aceptar'); bloquear();
            }
            return false;
        }
    }


    //Mostrar mensaje con campos invalidos
    if (boolValidar == false) {
        opendivwin('500', '280', 'mensajeGenerico.aspx?titulo=Confirmacio*n datos de estudios&detalle=Revisa la informacio*n sombreada antes de continuar.&boton=Aceptar'); bloquear();
    }

    return boolValidar;
}

//Validar experiencia
function validarExperienciaRegistro() {
    var boolValidar = true;
    var boolValidarFoco = true;


    //Validar listas
    var arrayListasValidate = new Array(3);
    arrayListasValidate[0] = "ddlSectorEmpresa";
    arrayListasValidate[1] = "ddlInicioMesExperiencia";
    arrayListasValidate[2] = "ddlAnoInicioExperiencia";
    arrayListasValidate[3] = "ddlAnoFinExperiencia";

    for (i = 0; i < arrayListasValidate.length; i++) {
        var ctlValidarListas = document.getElementById(arrayListasValidate[i]);
        if (ctlValidarListas != null) {
            if (ctlValidarListas.value == "0") {
                ctlValidarListas.style.backgroundColor = "#FFDBC4";
                boolValidar = false;
            }
            else {
                ctlValidarListas.style.backgroundColor = "";
            }
        }
    }

    //Validar input text
    //Controles a validar registro general
    var arrayControlValidate = new Array(1)
    arrayControlValidate[0] = "txtEmpresa";
    arrayControlValidate[1] = "txtNombreCargo";

    for (i = 0; i < arrayControlValidate.length; i++) {
        if (document.getElementById(arrayControlValidate[i]) != null) {
            var ctlValidar = document.getElementById(arrayControlValidate[i]);
            if (ctlValidar.value == "") {
                ctlValidar.style.backgroundColor = "#FFDBC4";
                ctlValidar.style.border = "1px solid #FF6F0F";
                boolValidar = false;

                //Valida que el foco quede en el primer objeto invalido
                if (boolValidarFoco == true) {
                    boolValidarFoco = false;
                    ctlValidar.focus();
                }
            }
            else {
                ctlValidar.style.backgroundColor = "";
                ctlValidar.style.border = "1px solid #CCCCCC";
            }
        }
    }

    if (document.getElementById("ddlInicioMesExperiencia") != null) {
        var mi = document.getElementById("ddlInicioMesExperiencia").value;
        var mf = document.getElementById("ddlFinMesExperiencia").value;
        var ai = document.getElementById("ddlAnoInicioExperiencia").value;
        var af = document.getElementById("ddlAnoFinExperiencia").value;


        var di = new Date(ai, mi, 1);  // creates a new Date for the 1st June 2005
        var df = new Date(af, mf, 1); // creates a new Date representing today

        var milli_d1 = di.getTime();
        var milli_d2 = df.getTime();
        var diff = milli_d1 - milli_d2;

        if (mf != -1 && af != -1) {
            if (diff > 0) {
                boolValidar = false;
                document.getElementById("ddlInicioMesExperiencia").style.backgroundColor = "#FFDBC4";
                document.getElementById("ddlInicioMesExperiencia").style.border = "1px solid #FF6F0F";

                document.getElementById("ddlAnoInicioExperiencia").style.backgroundColor = "#FFDBC4";
                document.getElementById("ddlAnoInicioExperiencia").style.border = "1px solid #FF6F0F";

                //Mostrar mensaje con campos invalidos
                if (boolValidar == false) {
                    opendivwin('500', '280', 'mensajeGenerico.aspx?titulo=Confirmacio*n datos de experiencia&detalle=La fecha de inicio debe ser menor a la fecha de finalizacio*n&boton=Aceptar'); bloquear();
                }
                return false;
            }
        }
    }
    //Mostrar mensaje con campos invalidos
    if (boolValidar == false) {
        opendivwin('500', '280', 'mensajeGenerico.aspx?titulo=Confirmacio*n datos de experiencia&detalle=Revisa la informacio*n sombreada antes de continuar.&boton=Aceptar'); bloquear();
    }


    return boolValidar;

}
//Validar preferencias
function validarPreferencias() {
    var boolValidar = true;
    var txtValidar = document.getElementById("txtPerfil");

    if (txtValidar.value == "") {
        txtValidar.style.backgroundColor = "#FFDBC4";
        txtValidar.style.border = "1px solid #FF6F0F";
        boolValidar = false;
    }
    else {
        txtValidar.style.backgroundColor = "";
        txtValidar.style.border = "1px solid #CCCCCC";
    }


    var ddlValidar = document.getElementById("ddlRangoSalarial");
    if (ddlValidar.value == "0") {
        ddlValidar.style.backgroundColor = "#FFDBC4";
        boolValidar = false;
    }
    else {
        ddlValidar.style.backgroundColor = "";
    }

    return boolValidar;
}

//Asociar el evento de un boton a un control runar server
function asociarBoton(evento, btnAsociar) {
    try {

        if (evento.keyCode != 13) {
            var ctlbtnAsociar = document.getElementById(btnAsociar);

            if (ctlbtnAsociar != null) {
                var Divpwd = document.getElementById('Divpwd');
                var DivPwdTxt = document.getElementById('DivPwdTxt');
                if (btnAsociar == 'TxtClave') {
                    var TxtClave = document.getElementById('TxtClave');
                    var Password = document.getElementById('Password');
                    TxtClave.value = TxtClave.value.replace('Contraseña', '')
                    Password.value = TxtClave.value;
                }

                DivPwdTxt.style.display = 'none';
                Divpwd.style.display = 'block';
                Password.focus();
            }
        }
        else {
            var ctlbtnAsociar = document.getElementById(btnAsociar);
            if (ctlbtnAsociar != null) {
                var Divpwd = document.getElementById('Divpwd');
                var DivPwdTxt = document.getElementById('DivPwdTxt');

                DivPwdTxt.style.display = 'none';
                Divpwd.style.display = 'block';
                Password.focus();
            }
        }
    }
    catch (err)
    { }
}

//Funcion que simula el click en un boton cuando se da enter en una caja de texto
function Enter(evento, btn) {
    var boton = document.getElementById(btn);
    if (boton != null) {
        ac = teclaEvento(evento);
        if (ac == 13) {
            try {
                boton.click();
            }
            catch (er) {
                window.location = boton.href;
            }
        }
    }
}

function foo() {
    //do something
    alert("Executed Click Event");
    //button.click();
}

function ClaveOnFocus(TxtClave, Password) {
    var TxtClave = document.getElementById(TxtClave);
    var Password = document.getElementById(Password);
    var Divpwd = document.getElementById('Divpwd');
    var DivPwdTxt = document.getElementById('DivPwdTxt');

    DivPwdTxt.style.display = 'none';
    Divpwd.style.display = 'block';
    Password.focus();

}

function PassWordOnBlur(TxtClave1) {

    try {
        var Divpwd = document.getElementById('Divpwd');
        var DivPwdTxt = document.getElementById('DivPwdTxt');
        var pass = document.getElementById('Password');
        var clave = document.getElementById('TxtClave');

        if (pass.value.length > 0) {
            if (DivPwdTxt != null) {
                DivPwdTxt.style.display = 'none';
                Divpwd.style.display = 'block';
            }
        }
        else {
            if (DivPwdTxt != null) {

                DivPwdTxt.style.display = 'block';
                Divpwd.style.display = 'none';
                clave.value = "contraseña";
            }
        }
    }
    catch (err) {

    }

}

//Cerrar modal
function closeModal(strNombreModal) {
    var mpu = $find(strNombreModal);
    mpu.hide();
}

//Cambiar estado para el control enviado
function asignarInvalidoControl(strNombreControl) {
    var objElement = document.getElementById(strNombreControl);
    objElement.style.backgroundColor = "#FFDBC4";
    objElement.style.border = "1px solid #FF6F0F";
    objElement.focus();
}

//Validar caracteres especiales nick
function validarTextNick(evento) {
    //39=',38=&,241=ñ,32=space,62= >, 60 = <,37=%
    if (evento.keyCode != 39 && evento.keyCode != 38
            && evento.keyCode != 241 && evento.keyCode != 32
                && evento.keyCode != 37) {
        MM_returnValue = true;
    }
    else {
        MM_returnValue = false;
    }
}

//Validar numeros textBox
function fncInputNumericValuesOnly() {
    //46 Dot
    if (!(event.keyCode == 44 || 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 OcualtarCombosOnTabOrEnter() {
    if (event.keyCode == 13 || event.keyCode == 9) {
        HideCombos("visible");
    }
    else {
        HideCombos("hidden");
    }
}

//Validar que TODOS los campos de experiencia esten vacios
function CamposExperienciaVacios() {
    if (document.getElementById("txtEmpresa").value == "" &&
            document.getElementById("txtNombreCargo").value == "" &&
            document.getElementById("ddlSectorEmpresa").value == "0" &&
            document.getElementById("ddlInicioMesExperiencia").value == "0" &&
            document.getElementById("ddlAnoInicioExperiencia").value == "0" &&
            document.getElementById("ddlFinMesExperiencia").value == "-1" &&
            document.getElementById("ddlAnoFinExperiencia").value == "-1") {
        return true;
    }
    else {
        return false;
    }
}


//Validar que TODOS los campos de Estudios esten vacios
function CamposEstudioVacios() {
    if (document.getElementById("txtTituloObtenido").value == "" &&
            document.getElementById("txtInstitucion").value == "" &&
            document.getElementById("ddlInicioMesEstudio").value == "0" &&
            document.getElementById("ddlAnoInicioEstudio").value == "0" &&
            document.getElementById("ddlFinMesEstudio").value == "-1" &&
            document.getElementById("ddlAnoFinEstudio").value == "-1" &&
            document.getElementById("txtDuracion").value == "0" &&
            document.getElementById("ddlTipoDuracion").value == "0") {
        return true;
    }
    else {
        return false;
    }
}

function TerminosCondiciones(url) {
    urlRef = url ? url : 'terminosCondiciones.aspx';

    window.open(urlRef, '_blank', 'width=800,scrollbars=YES,Toolbar=YES,Status=YES,Menubar=YES,Location=YES')
}


function MascaraContraseña() {
    var txtclave = document.getElementById("Password");
    txtclave.TextMode = TextBoxMode.Password;
    //txtclave.type='SingleLine';
    if (txtclave.value == "") {
        txtclave.value = "cdñlfkalsñ";
    }
    //document.getElementById("Password").value=document.getElementById("Password").value;

    alert(txtclave.value);
}


function formatNumber(input, textValidate) {
    var num = input.value.replace(/\,/g, '');
    if (!isNaN(num)) {
        if (num.indexOf('.') > -1) {
            num = num.split('.');
            num[0] = num[0].toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g, '$1,').split('').reverse().join('').replace(/^[\,]/, '');
            if (num[1].length > 2) {
                alert('Sólo puede introducir dos decimales');
                num[1] = num[1].substring(0, num[1].length - 1);
            } input.value = num[0] + '.' + num[1];
        } else { input.value = num.toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g, '$1,').split('').reverse().join('').replace(/^[\,]/, '') };
    }
    else {
        //Debe validar caracteres numericos
        if (textValidate) {
            alert('Puede introducir sólo números en este campo');
            input.value = input.value.substring(0, input.value.length - 1);
        }
    }
}

function teclaEvento(evento) {
    if (evento.keyCode)
        return evento.keyCode;
    else
        return evento.which;
}

function continuarEvento(evento, continuar) {
    if (evento.preventDefault && !continuar) {
        evento.preventDefault();
        evento.stopPropagation();
    }
    return continuar;
}

function cambiarURL(strURL) {
    window.location.href = strURL;
}

function Foco() {
    document.getElementById("tbConocimientos").focus();
}

function tabs(boton) {
    try {
        var divoficios = document.getElementById('oficios');
        var divprofesiones = document.getElementById('profesiones');
        var divPestana1 = document.getElementById('divPestana1');
        var divPestana2 = document.getElementById('divPestana2');
        var hdPestanaSeleccionada = document.getElementById(hdPestanaSeleccionadaID);


        if (divoficios != null && divprofesiones != null && hdPestanaSeleccionada != null && divPestana1 != null && divPestana2 != null) {
            if (boton == 1) {
                divoficios.style.display = "none";
                divprofesiones.style.display = "block";
                hdPestanaSeleccionada.value = "profesiones";
                divPestana2.style.display = "block";
                divPestana1.style.display = "none";
            }
            else {
                divoficios.style.display = "block";
                divprofesiones.style.display = "none";
                hdPestanaSeleccionada.value = "oficios";
                divPestana2.style.display = "none";
                divPestana1.style.display = "block";
            }
        }
    }
    catch (err)
      { }
}

//Funcion usada en los controles de usuario 
function minLenght(control, mensaje) {
    if (document.getElementById(control).value.length < 3) {
        document.getElementById(control).style.backgroundColor = "#FFDBC4";
        document.getElementById(control).focus();
        document.getElementById(mensaje).style.display = "block"
        return false;
    }
    else {
        document.getElementById(control).style.backgroundColor = "";
        document.getElementById(control).style.border = "";
        document.getElementById(mensaje).style.display = "none"
        return true;
    }
}

//Obtener la URL y validar el parametro por request   
function requestJavascript(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return ""; else
        return results[1];
}


function CountHv(text, long, spanTextId) {
    var maxlength = new Number(long); // Change number to your max length.
    if (text.value.length > maxlength) {
        text.value = text.value.substring(0, maxlength);
    }
    //Obtener caracteres disponibles
    spanDisponibles = document.getElementById(spanTextId);
    spanDisponibles.innerHTML = long - text.value.length;
}
