
function createGreyCover()
{
	var isIE6 = jQuery.browser.msie && jQuery.browser.version < 7;
	
	//creo el gray cover
	var greycover = document.createElement('div');
	greycover.id = 'greycover';		
	greycover.style.position = isIE6 ? 'absolute' : 'fixed';
	greycover.style.top = '0px';
	greycover.style.left = '0px';	
	greycover.style.background = '#666666';
	greycover.style.zIndex = 2;
	greycover.style.width = '100%';
	greycover.style.height = isIE6 ? document.body.clientHeight : '100%' ;
	greycover.style.opacity = 0.5;
	greycover.style.filter = 'alpha(opacity=50)'; // IE6 requires this + greycover to have layout, which it does.								
	
	$('body').append( greycover );		
	
}

function removeGreyCover()
{
	$('#greycover').remove();	
}

function removeGreyCoverSlow()
{
	$('#greycover').fadeOut( 'slow', function() { jQuery('#greycover').remove() } );
}


function IsNumeric(valor)
{
	var log=valor.length; var sw="S";
	for (x=0; x<log; x++)
		{
			v1=valor.substr(x,1);
			v2 = parseInt(v1);
			//Compruebo si es un valor numï¿½rico
			if (isNaN(v2)) { sw= "N";}
			}
				if (sw=="S") {
					return true;
				} else {
					return false; }
}


function validar_estudios(accion,codigo)
{
	var error=0;
	var errores='';

    if(document.getElementById('edu_pais').value==0){
        errores = errores + "<p>Debe seleccionar un pais.</p> ";
        error=1;
    }

    if (document.getElementById('edu_tipo').value==0){
        errores = errores + "<p>Debe seleccionar un nivel de estudios.</p> ";
        error=1;
    }

    if (document.getElementById('edu_sinstitucion').value == 0 && document.getElementById('edu_tinstitucion').value=='') {
        errores = errores + "<p>Debe seleccionar una institucion en el caso de encontrarla tipeala en el campo otra.</p> ";
        error=1;
    }

    if (document.getElementById('edu_sinstitucion').value != 0 && document.getElementById('edu_tinstitucion').value!='') {
        errores = errores + "<p>Solo debe indicar otra institucion en el caso de no poder indicar la institucion desde el combo.</p> ";
        error=1;
    }

    if (document.getElementById('Area_Estudio').value==0){
        errores = errores + "<p>Debe seleccionar un area de estudios.</p> ";
        error=1;
    }

    if (document.getElementById('edu_titulo').value==''){
        errores = errores + "<p>Debe indicar un titulo.</p> ";
        error=1;
    }

    if(document.getElementById('edufecha_anio_start').value=='0' || document.getElementById('edufecha_mes_start').value=='0'){
        errores = errores + "<p>La fecha de inicio no es valida.</p>";
        error=1;
    }

    if(document.getElementById('edufecha_anio_start').value=='0' && document.getElementById('edufecha_mes_start').value!='0' || document.getElementById('edufecha_anio_start').value!='0' && document.getElementById('edufecha_mes_start').value=='0'){
        errores = errores + "<p>La fecha de inicio no es valida.</p>";
        error=1;
    }

    if(document.getElementById('edufecha_anio_end').value=='0' && document.getElementById('edufecha_mes_end').value!='0' || document.getElementById('edufecha_anio_end').value!='0' && document.getElementById('edufecha_mes_end').value=='0'){
        errores = errores + "<p>La fecha de fin no es valida.</p>";
        error=1;
    }

    if (document.getElementById('Cant_Materias').value==''){
        errores = errores + "<p>Debe indicar la cantidad de materias de la carrera.</p> ";
        error=1;
    }

    if (!IsNumeric(document.getElementById('Cant_Materias').value)){
        errores = errores + "<p>El campo cantidad de materias de la carrera solo debe contener n&uacute;meros.</p> ";
        error=1;
    }

    if (!IsNumeric(document.getElementById('Cant_Aprobadas').value)){
        errores = errores + "<p>El campo cantidad de materias aprobadas solo debe contener n&uacute;meros.</p> ";
        error=1;
    }

    if (document.getElementById('Cant_Aprobadas').value==''){
        errores = errores + "<p>Debe indicar la cantidad de materias aprobadas de la carrera.</p> ";
        error=1;
    }

    if (document.getElementById('Promedio').value!='' && document.getElementById('Rango_Promedio').value==0){
        errores = errores + "<p>Al indicar un promedio debe especificar un rango para ese promedio.</p> ";
        error=1;
    }
    if (document.getElementById('Promedio').value=='' && document.getElementById('Rango_Promedio').value!=0){
        errores = errores + "<p>Debe indicar el promedio para ese rango.</p> ";
        error=1;
    }

    if (document.getElementById('Promedio').value!='' && document.getElementById('Rango_Promedio').value!=0)
		{
            switch(document.getElementById('Rango_Promedio').value)
            {
                case "10":
                    if (!IsNumeric(document.getElementById('Promedio').value)) {
                        errores = errores + "<p>Debe ingresar un numero en promedio para ese rango.</p> ";
                        error=1;
                    } else {
                        if (document.getElementById('Promedio').value<0 || document.getElementById('Promedio').value>10) {
                            errores = errores + "<p>Debe ingresar un numero en promedio en el rango de 1 a 10.</p> ";
                            error=1;
                        }
                    }
                break;
                case "11":
                    if (!IsNumeric(document.getElementById('Promedio').value)) {
                        errores = errores + "<p>Debe ingresar un numero en promedio para ese rango.</p> ";
                        error=1;
                    } else {
                        if (document.getElementById('Promedio').value<0 || document.getElementById('Promedio').value >100) {
                            errores = errores + "<p>Debe ingresar un numero en promedio en el rango de 1 a 100.</p> ";
                            error=1;
                        }
                    }
                break;
                case "12":
                    var PROMEDIO_MAYUSCULA;
                    PROMEDIO_MAYUSCULA = document.getElementById('Promedio').value.toUpperCase();
                    switch(PROMEDIO_MAYUSCULA) {
                        case 'A':   break;
                        case 'A+':  break;
                        case 'A-':  break;
                        case 'B':   break;
                        case 'B+':  break;
                        case 'B-':  break;
                        case 'C':   break;
                        case 'C+':  break;
                        case 'C-':  break;
                        case 'D':   break;
                        case 'D+':  break;
                        case 'D-':  break;
                        case 'E':   break;
                        case 'E+':  break;
                        case 'E-':  break;
                        case 'F':   break;
                        case 'F+':  break;
                        case 'F-':  break;
                        default:
                            errores = errores + "<p>Debe ingresar una letra en promedio en el rango de A a F.</p> ";
                            error=1;
                    }
                break;
                case "13":
                    if (!IsNumeric(document.getElementById('Promedio').value)) {
                        errores = errores + "<p>Debe ingresar un numero en promedio para ese rango.</p> ";
                        error=1;
                    } else {
                        if (document.getElementById('Promedio').value<0 || document.getElementById('Promedio').value >7) {
                            errores = errores + "<p>Debe ingresar un numero en promedio en el rango de 1 a 7.</p> ";
                            error=1;
                        }
                    }
                break;
                case "14":
                    if (!IsNumeric(document.getElementById('Promedio').value)) {
                        errores = errores + "<p>Debe ingresar un numero en promedio para ese rango.</p> ";
                        error=1;
                    } else {
                        if (document.getElementById('Promedio').value<0 || document.getElementById('Promedio').value >5) {
                            errores = errores + "<p>Debe ingresar un numero en promedio en el rango de 1 a 5.</p> ";
                            error=1;
                        }
                    }
                break;
                case "15":
                    if (!IsNumeric(document.getElementById('Promedio').value)) {
                        errores = errores + "<p>Debe ingresar un numero en promedio para ese rango.</p> ";
                        error=1;
                    } else {
                        if (document.getElementById('Promedio').value<0 || document.getElementById('Promedio').value >20) {
                            errores = errores + "<p>Debe ingresar un numero en promedio en el rango de 1 a 20.</p> ";
                            error=1;
                        }
                    }
                break;
            }

        }

        if (error){
            document.getElementById('erroresEstudios').innerHTML = errores;

        }
        else
        {

            OTRAINSTITUCION = document.getElementById('edu_tinstitucion').value.replace(/&/g, "%26");
            OTROTITULO = document.getElementById('edu_titulo').value.replace(/&/g, "%26");

            var campos=document.getElementById('edu_pais').value;
				campos=campos +'|'+ document.getElementById('edu_tipo').value +'|'+document.getElementById('edu_sinstitucion').value;
				campos=campos +'|'+ OTRAINSTITUCION;
				campos=campos +'|'+ document.getElementById('Area_Estudio').value +'|'+OTROTITULO;
				campos=campos +'|'+ document.getElementById('edufecha_anio_start').value +'|'+document.getElementById('edufecha_mes_start').value+'|'+document.getElementById('edufecha_anio_end').value+'|'+document.getElementById('edufecha_mes_end').value;
				campos=campos +'|'+ document.getElementById('Cant_Materias').value +'|'+document.getElementById('Cant_Aprobadas').value;
				campos=campos +'|'+ document.getElementById('Promedio').value+'|'+document.getElementById('Rango_Promedio').value;

                accion_ajax ("POST","../../carga_cv/estudios_ajax.ngmf","callback_guardar_estudios","campos="+campos+"&accion="+accion+"&codigo=" + codigo);
        }
}
function validar_preferencias (accion, codigo){
	var error=0;
	var errores='';
	document.getElementById('erroresPreferencias').innerHTML ='';

		if (document.getElementById('objetivos').value==''){
			errores = errores + "<p>Debe indicar objetivos laborales.</p> ";
	        error=1;
		}

		if (document.getElementById('PuestoAspiras').value==''){
			errores = errores + "<p>Debe indicar el puesto al que aspira.</p> ";
	        error=1;
		}

//Valida las industrias

    	var seleccion = false;
	        var select_industrias = document.getElementById('INDUSTRIAS').options;
	        for(f = 0; f < select_industrias.length; f++){
	            if (select_industrias[f].selected){
	                seleccion = true;
	            }
	       }


	    if(!seleccion){
			errores = errores + "<p>Debe seleccionar al menos un Area de Actividad.</p> ";
	        error=1;
		}

//Valida las areas

    	var seleccion = false;
	        var select_areas = document.getElementById('AREAS').options;
	        for(f = 0; f < select_areas.length; f++){
	            if (select_areas[f].selected){
	                seleccion = true;
	            }
	        }


	    if(!seleccion){
			errores = errores + "<p>Debe seleccionar al menos un Area Funcional.</p> ";
	        error=1;
		}
//Fin Valida Areas

		if (document.getElementById('PUESTOCOMBO').value==0){
			errores = errores + "<p>Debe indicar el tipo de trabajo al que aspira.</p> ";
	        error=1;
		}

		if (!document.reubicarForm.REUBICAR[0].checked && !document.reubicarForm.REUBICAR[1].checked){
			errores = errores + "<p>Debe indicar si esta trabajaría en otro país o no.</p> ";
	        error=1;
		}

        if (error){
            document.getElementById('erroresPreferencias').innerHTML = errores;

        }else
        	{
		    	var areas_seleccionadas = '';
			        var select_areas = document.getElementById('AREAS').options;
			        for(f = 0; f < select_areas.length; f++){
			            if (select_areas[f].selected){
			            	if (areas_seleccionadas==''){
				                areas_seleccionadas = select_areas[f].value;
				            }else{
					            	areas_seleccionadas = areas_seleccionadas + ',' + select_areas[f].value;
				            }
			            }
			        }
		    	var industrias_seleccionadas = '';
			        var select_industrias = document.getElementById('INDUSTRIAS').options;
			        for(f = 0; f < select_industrias.length; f++){
			            if (select_industrias[f].selected){
			                if (industrias_seleccionadas==''){
			                	industrias_seleccionadas = select_industrias[f].value;
			                }else{
			                	industrias_seleccionadas = industrias_seleccionadas + ',' + select_industrias[f].value;
			            	}
			            }
			        }

	            OBJETIVOS = document.getElementById('objetivos').value.replace(/&/g, "%26");
	            PUESTO = document.getElementById('PuestoAspiras').value.replace(/&/g, "%26");

				if (!document.reubicarForm.REUBICAR[0].checked){
					var REUBICAR=document.reubicarForm.REUBICAR[1].value;
				}else{
					var REUBICAR=document.reubicarForm.REUBICAR[0].value;
				}

	            var campos=OBJETIVOS;
					campos=campos +'|'+ PUESTO;
					campos=campos +'|'+ areas_seleccionadas +'|'+industrias_seleccionadas + '|' + document.getElementById('PUESTOCOMBO').value;
					campos=campos +'|'+ REUBICAR ;
	                accion_ajax ("POST","../../carga_cv/preferencias_ajax.ngmf","callback_guardar_preferencias","campos="+campos+"&accion="+accion+"&codigo=" + codigo);
           }

}

function guardar_salarios(accion, codigo)
{
	var cant= document.getElementById('cant_rangos').value;
	var rangos='';
    if(cant>0){
        for(f = 0; f < cant; f++){
            if (document.getElementById('Rangos'+f).checked ){
				if (rangos==''){
					rangos=document.getElementById('Rangos'+f).value;
				}else{
						rangos= rangos + ',' + document.getElementById('Rangos'+f).value;
                }
            }
        }
	}

	if (rangos){

		accion_ajax ("POST","../../carga_cv/preferencias_salariales_ajax.ngmf","callback_guardar_preferencias_salariales","campos="+rangos+"&accion="+accion+"&codigo=" + codigo);
	}
}

function cargarEditarEstudios(id)
{
	document.getElementById('erroresEstudios').innerHTML = '';	
	document.getElementById('btnAgregarEstudio').onclick = function(){validar_estudios('M',id)};
	$('#textoAgregarEducacion').attr('innerHTML','Modificar Educación');
	$('#btnCancelarEstudio').css('display','inline-block');	
	$('#cargaIdiomas').fadeOut('slow');		
	$('#cargaHabilidades').fadeOut('slow');	
	$('#resumen_educativo').fadeOut('slow');						
	accion_ajax ("POST","../../carga_cv/estudios_ajax.ngmf","callback_estudio_cargar","codigo="+id+"&cargar=1");
}

function sacarEditarEstudios()
{
	
	$('#resumen_educativo').fadeIn('slow');		
	$('#cargaIdiomas').fadeIn('slow');		
	$('#cargaHabilidades').fadeIn('slow');			
	$('#textoAgregarEducacion').attr('innerHTML','Agregar Educación');
	$('#btnCancelarEstudio').hide();
	document.getElementById('btnAgregarEstudio').onclick = function(){validar_estudios('A','')};

}

function callback_estudio_cargar()
{
	if (xml.readyState==1)
	{
    
    }
    if (xml.readyState==4 && xml.status==200)
    {
        var arrEstudio = xml.responseText.split('|');
        document.getElementById('edu_pais').value = arrEstudio[0];
		document.getElementById('edu_tipo').value = arrEstudio[1];
		document.getElementById('edu_sinstitucion').value = arrEstudio[2];
		document.getElementById('edu_tinstitucion').value = arrEstudio[3];
		document.getElementById('edufecha_mes_start').value = arrEstudio[4];
		document.getElementById('edufecha_anio_start').value = arrEstudio[5];
		document.getElementById('edufecha_mes_end').value = arrEstudio[6];
		document.getElementById('edufecha_anio_end').value = arrEstudio[7];
		document.getElementById('Area_Estudio').value = arrEstudio[8];
		document.getElementById('edu_titulo').value = arrEstudio[9];
		document.getElementById('Cant_Materias').value = arrEstudio[10];
		document.getElementById('Cant_Aprobadas').value = arrEstudio[11];
		document.getElementById('Promedio').value = arrEstudio[12];
		document.getElementById('Rango_Promedio').value = arrEstudio[13];


    }
}

function limpiarEstudios()
{
	document.getElementById('edu_tipo').selectedIndex=0;
	document.getElementById('edu_sinstitucion').selectedIndex= 0;
	document.getElementById('edu_tinstitucion').value='';
	document.getElementById('Area_Estudio').selectedIndex=0;
	document.getElementById('edu_titulo').value='';
	document.getElementById('edufecha_anio_start').selectedIndex=0;
	document.getElementById('edufecha_mes_start').selectedIndex=0;
	document.getElementById('edufecha_anio_end').selectedIndex=0;
	document.getElementById('edufecha_mes_end').selectedIndex=0;
	document.getElementById('Cant_Materias').value='';
	document.getElementById('Cant_Aprobadas').value='';
	document.getElementById('Promedio').value='';
	document.getElementById('Rango_Promedio').selectedIndex=0;
	document.getElementById('erroresEstudios').innerHTML = '';
}

function eliminar_estudios(id){
	accion_ajax ("POST","../../carga_cv/estudios_ajax.ngmf","callback_estudios_eliminar","codigo="+id+"&accion=E");
}

function accion_ajax(metodo,url,funcion,valores){

        if (window.XMLHttpRequest){
            xml= new XMLHttpRequest();
        }
        else if(window.ActiveXObject){
                xml = new ActiveXObject("Microsoft.XMLHTTP");
        }

		if (metodo=="GET" ){
            xml.open("GET",url,true);
            xml.onreadystatechange =eval(funcion);
            xml.send(null);
		}
		if (metodo=='POST')
		{
            xml.open('POST',url,true);
            xml.onreadystatechange = eval(funcion);
            xml.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			xml.send(valores);
		}
}

function removeGreyCoverEstudios()
{
	limpiarEstudios();            
	removeGreyCover();
    sacarEditarEstudios();                    
}

function callback_guardar_estudios(){

    if (xml.readyState==1){                        
        createGreyCover();                                    
    }
    if (xml.readyState==4 && xml.status==200){            
    	document.getElementById('resumen_educativo').innerHTML= xml.responseText;                                    
        jAlert('Los datos se guardaron con exito ', '',removeGreyCoverEstudios);                        
        
    }
}
function callback_guardar_preferencias(){

        if (xml.readyState==1){
            createGreyCover();            
        }
        if (xml.readyState==4 && xml.status==200){

        	if (xml.responseText!=0){
	        	jAlert('Los datos se guardaron con exito ', '',removeGreyCover);
			}else{
            	document.getElementById('rta').innerHTML= xml.responseText;
			}

        }
}
function callback_guardar_preferencias_salariales(){

        if (xml.readyState==1){
			createGreyCover();            
        }
        if (xml.readyState==4 && xml.status==200){

        	if (xml.responseText!=false){
	        	jAlert('Los datos se guardaron con exito ', '',removeGreyCover);
			}else{
            	document.getElementById('rta').innerHTML= xml.responseText;
			}

        }

}
function callback_estudios_eliminar(){

    if (xml.readyState==1){
		createGreyCover();       

    }
    if (xml.readyState==4 && xml.status==200){
		document.getElementById('resumen_educativo').innerHTML= xml.responseText;
		removeGreyCoverSlow();
    }
}

function popup_foto(){
    var strWindowFeatures = "descent top=0, left = 0,width=580,height=500,location=no,directories=no,status=no,menubar=no,scrollbars=no,noresize,resize=no";
    open("../../procesar_foto.ngmf","Agradecimiento",strWindowFeatures);
}

function recuperar_pass(){
    var strWindowFeatures = "descent top=0, left = 0,width=580,height=500,location=no,directories=no,status=no,menubar=no,scrollbars=no,noresize,resize=no";
    open("../../procesar_recuperar_pass.ngmf","Agradecimiento",strWindowFeatures);
}

function validar_experiencias(accion,codigo)
{
		var error=0;
		var errores='';

        if (document.getElementById('exp_pais').value==0){
			errores = errores + "<p>Debe seleccionar un pais</p> ";
			error=1;
		}

		if (document.getElementById('exp_empresa').value==''){
			errores = errores + "<p>Debe indicar el nombre de la empresa</p> ";
			error=1;

		}

		if (document.getElementById('exp_puesto').value==''){
			errores = errores + "<p>Debe indicar el nombre del puesto</p> ";
			error=1;
		}

		if (document.getElementById('exp_puesto_combo').value == 0){
			errores = errores + "<p>Debe seleccionar el tipo de puesto</p> ";
			error=1;
		}

        if (document.getElementById('exp_area').value==0){
			errores = errores + "<p>Debe seleccionar el area de la experiencia</p> ";
			error=1;
		}
		if (document.getElementById('exp_industria').value==0){
			errores = errores + "<p>Debe seleccionar la industria de la experiencia</p> ";
			error=1;
		}
		if(document.getElementById('exp_anio_inicio').value=='0' || document.getElementById('exp_mes_inicio').value=='0'){
			errores = errores + "<p>La fecha de inicio no es valida </p>";
			error=1;
		}

		if(document.getElementById('exp_anio_inicio').value=='0' && document.getElementById('exp_mes_inicio').value!='0' || document.getElementById('exp_anio_inicio').value!='0' && document.getElementById('exp_mes_inicio').value=='0'){
			errores = errores + "<p>La fecha de inicio no es valida </p>";
			error=1;
		}

		if(document.getElementById('exp_anio_termino').value=='0' && document.getElementById('exp_mes_termino').value!='0' || document.getElementById('exp_anio_termino').value!='0' && document.getElementById('exp_mes_termino').value=='0'){
			errores = errores + "<p>La fecha de fin no es valida </p>";
			error=1;

		}
		if(document.getElementById('exp_anio_termino').value=='0' && document.getElementById('exp_mes_termino').value!='0' || document.getElementById('exp_anio_termino').value!='0' && document.getElementById('exp_mes_termino').value=='0'){
			errores = errores + "<p>La fecha de fin no es valida </p>";
			error=1;

		}

        if(document.getElementById('Personas_Cargo').value && !IsNumeric(document.getElementById('Personas_Cargo').value)){
			errores = errores + "<p>El campo de personas a cargo debe ser numerico </p>";
			error=1;
		}
		var str=document.getElementById('responsabilidades').value;
		if (str.search(/<[^>]+>/g) != -1)
		{
			errores = errores + "<p>No se permite ingresar etiquetas HTML en la descripci&oacute;n </p>";
			error=1;
		}
        if (error){

            document.getElementById('erroresExperiencias').innerHTML = errores;
        }
        else
        {

            var campos=document.getElementById('exp_pais').value;

                EMPRESA = document.getElementById('exp_empresa').value.replace(/&/g, "%26");
				PUESTO = document.getElementById('exp_puesto').value.replace(/&/g, "%26");
				DESCRIPCION = document.getElementById('responsabilidades').value.replace(/&/g, "%26");
				if (document.getElementById('Presupuesto_Propio').checked)
				{
					PRESUPUESTO = 1;
				}
				else
				{
					PRESUPUESTO = 0;
				}

				campos=campos +'|'+EMPRESA +'|'+PUESTO;
				campos=campos +'|'+document.getElementById('exp_puesto_combo').value;
				campos=campos +'|'+document.getElementById('exp_area').value+'|'+document.getElementById('exp_industria').value;
				campos=campos +'|'+document.getElementById('exp_anio_inicio').value+'|'+document.getElementById('exp_mes_inicio').value+'|'+document.getElementById('exp_anio_termino').value+'|'+document.getElementById('exp_mes_termino').value;
				campos=campos +'|'+document.getElementById('Personas_Cargo').value+'|'+ PRESUPUESTO;
				campos=campos +'|'+DESCRIPCION;

                accion_ajax ("POST","../../carga_cv/experiencias_ajax.ngmf","callback_guardar_experiencias","campos="+campos+"&accion="+accion+"&codigo=" + codigo);
        }


}

function eliminar_experiencias(id){
	accion_ajax ("POST","../../carga_cv/experiencias_ajax.ngmf","callback_experiencias_eliminar","codigo="+id+"&accion=E");
}

function callback_experiencias_eliminar(){

    if (xml.readyState==1){
        createGreyCover();       
    }
    if (xml.readyState==4 && xml.status==200){
		document.getElementById('resumen_experiencias').innerHTML= xml.responseText;
		removeGreyCoverSlow();       
    }
}


function removeGreyCoverExperiencias()
{
    limpiarExperiencias();
    removeGreyCover();
    sacarEditarExperiencias();   
}



function callback_guardar_experiencias(){

    if (xml.readyState==1)
    {
        createGreyCover();
    }
    if (xml.readyState==4 && xml.status==200){
        document.getElementById('resumen_experiencias').innerHTML= xml.responseText;
        jAlert('Los datos se guardaron con exito ', '',removeGreyCoverExperiencias);                        
        
    }
}

function limpiarExperiencias()
{
	document.getElementById('exp_pais').selectedIndex=0;
	document.getElementById('exp_empresa').value='';
	document.getElementById('exp_puesto').value='';
	document.getElementById('exp_puesto_combo').selectedIndex=0;
	document.getElementById('exp_area').selectedIndex= 0;
	document.getElementById('exp_industria').selectedIndex=0;
	document.getElementById('exp_mes_inicio').selectedIndex=0;
	document.getElementById('exp_anio_inicio').selectedIndex=0;
	document.getElementById('exp_mes_termino').selectedIndex=0;
	document.getElementById('exp_anio_termino').selectedIndex=0;
	document.getElementById('Personas_Cargo').value='';
	document.getElementById('Presupuesto_Propio').checked = false;
	document.getElementById('responsabilidades').value='';
	document.getElementById('erroresExperiencias').innerHTML = '';
}

function cargarEditarExperiencias(id)
{
	document.getElementById('erroresExperiencias').innerHTML = '';
	document.getElementById('btnAgregarExperiencia').onclick = function(){validar_experiencias('M',id)};
	$('#textoAgregarExperiencia').attr('innerHTML','Modificar Experiencia Laboral');
	$('#btnCancelarExperiencia').css('display','inline-block');	
	$('#resumen_experiencias').fadeOut('slow');		
	accion_ajax ("POST","../../carga_cv/experiencias_ajax.ngmf","callback_experiencia_cargar","codigo="+id+"&cargar=1");
}

function sacarEditarExperiencias()
{
	$('#resumen_experiencias').fadeIn('slow');
	$('#textoAgregarExperiencia').attr('innerHTML','Agregar Experiencia Laboral');
	$('#btnCancelarExperiencia').hide();
	document.getElementById('btnAgregarExperiencia').onclick = function(){validar_experiencias('A','')};

}


function callback_experiencia_cargar()
{
	if (xml.readyState==1)
	{
            
    }
    if (xml.readyState==4 && xml.status==200)
    {
        var arrExperiencia = xml.responseText.split('|');

        document.getElementById('exp_pais').value= arrExperiencia[0];
		document.getElementById('exp_empresa').value=arrExperiencia[1];
		document.getElementById('exp_puesto').value=arrExperiencia[2];
		document.getElementById('exp_puesto_combo').value=arrExperiencia[3];
		document.getElementById('exp_area').value= arrExperiencia[4];
		document.getElementById('exp_industria').value=arrExperiencia[5];
		document.getElementById('exp_mes_inicio').value=arrExperiencia[6];
		document.getElementById('exp_anio_inicio').value=arrExperiencia[7];
		document.getElementById('exp_mes_termino').value=arrExperiencia[8];
		document.getElementById('exp_anio_termino').value=arrExperiencia[9];
		document.getElementById('Personas_Cargo').value=arrExperiencia[10];
		document.getElementById('Presupuesto_Propio').checked = (arrExperiencia[11]==1);
		document.getElementById('responsabilidades').value=arrExperiencia[12];
		document.getElementById('erroresExperiencias').innerHTML = '';				
    }
}



function validar_habilidades(accion,codigo)
{
	var error=0;
	var errores='';

	if (document.getElementById('habilidad_titulo').value==''){
		errores = errores + "<p>Debe indicar una habilidad.</p> ";
		error=1;

	}

	if (document.getElementById('habilidad_detalle').value==''){
		errores = errores + "<p>Debe indicar el detalle de la habilidad.</p> ";
		error=1;
	}

    if (error){

        document.getElementById('erroresHabilidades').innerHTML = errores;
    }
    else
    {
        var campos;

        titulo = document.getElementById('habilidad_titulo').value.replace(/&/g, "%26");
		detalle = document.getElementById('habilidad_detalle').value.replace(/&/g, "%26");
		campos = titulo + '|' + detalle;

        accion_ajax ("POST","../../carga_cv/habilidades_ajax.ngmf","callback_guardar_habilidades","campos="+campos+"&accion="+accion+"&codigo=" + codigo);
    }
}



function removeGreyCoverHabilidades()
{		
	limpiarHabilidades();            
	removeGreyCover();
    sacarEditarHabilidades();
}
function callback_guardar_habilidades()
{

        if (xml.readyState==1){
        	createGreyCover();                                                
        }
        if (xml.readyState==4 && xml.status==200){
            document.getElementById('resumen_habilidades').innerHTML= xml.responseText;
            jAlert('Los datos se guardaron con exito ', '',removeGreyCoverHabilidades);                                    
        }
}

function limpiarHabilidades()
{
	document.getElementById('habilidad_titulo').value='';
	document.getElementById('habilidad_detalle').value='';
	document.getElementById('erroresHabilidades').innerHTML = '';
}


function cargarEditarHabilidades(id)
{			
	document.getElementById('erroresHabilidades').innerHTML = '';
	document.getElementById('btnAgregarHabilidad').onclick = function(){validar_habilidades('M',id)};
	$('#textoAgregarHabilidad').attr('innerHTML','Modificar Habilidad');	
	$('#btnCancelarHabilidad').css('display','inline-block');
	$('#cargaIdiomas').fadeOut('slow');
	$('#resumen_educativo').fadeOut('slow');
	$('#cargaEstudio').fadeOut('slow');	
	$('#resumen_habilidades').fadeOut('slow');	
		
	accion_ajax ("POST","../../carga_cv/habilidades_ajax.ngmf","callback_habilidad_cargar","codigo="+id+"&cargar=1");
}

function sacarEditarHabilidades()
{				
	$('#cargaIdiomas').fadeIn('slow');
	$('#resumen_educativo').fadeIn('slow');
	$('#cargaEstudio').fadeIn('slow');
	$('#resumen_habilidades').fadeIn('slow');
	$('#textoAgregarHabilidad').attr('innerHTML','Agregar Habilidad');
	$('#btnCancelarHabilidad').hide();

	document.getElementById('btnAgregarHabilidad').onclick = function(){validar_habilidades('A','')};

}

function eliminar_habilidades(id){
	accion_ajax ("POST","../../carga_cv/habilidades_ajax.ngmf","callback_habilidades_eliminar","codigo="+id+"&accion=E");
}

function callback_habilidades_eliminar(){

    if (xml.readyState==1){
        createGreyCover();       

    }
    if (xml.readyState==4 && xml.status==200){
		document.getElementById('resumen_habilidades').innerHTML= xml.responseText;
		removeGreyCoverSlow();
    }
}

function callback_habilidad_cargar()
{
	 if (xml.readyState==1){           
     }
     if (xml.readyState==4 && xml.status==200){
            var arrHabilidad = xml.responseText.split('|');
            document.getElementById('habilidad_titulo').value = arrHabilidad[0];
			document.getElementById('habilidad_detalle').value = arrHabilidad[1];
        }
}

function Refresh_forms(valor_combo,name_combo){


    switch(name_combo){
        case "cmbNacionalidad":
            accion_ajax ("POST","../../carga_cv/refresh_forms_ajax.ngmf","callback_refresh_cmbNacionalidad","valor_combo="+valor_combo+"&name_combo="+name_combo);
        break;
        case "cmbPais":
            accion_ajax ("POST","../../carga_cv/refresh_forms_ajax.ngmf","callback_refresh_cmbPais","valor_combo="+valor_combo+"&name_combo="+name_combo);
        break;
        case "edu_pais":
            accion_ajax ("POST","../../carga_cv/refresh_forms_ajax.ngmf","callback_refresh_edu_pais","valor_combo="+valor_combo+"&name_combo="+name_combo);
        break;
        case "edu_sinstitucion":
            accion_ajax ("POST","../../carga_cv/refresh_forms_ajax.ngmf","callback_refresh_edu_sinstitucion","valor_combo="+valor_combo+"&name_combo="+name_combo);
        break;
    }

}



function callback_refresh_cmbNacionalidad(){
    if (xml.readyState==1){
         document.getElementById('refresh_TiposDocumentos').innerHTML='<img style="" src="../../templates/images/ajax-loader.gif" />';
         document.getElementById('refresh_EstadoCivil').innerHTML='<img style="" src="../../templates/images/ajax-loader.gif" />';
         document.getElementById('refresh_TipoLicencias').innerHTML='<img style="" src="../../templates/images/ajax-loader.gif" />';
         document.getElementById('refresh_TipoDiscapacidades').innerHTML='<img style="" src="../../templates/images/ajax-loader.gif" />';
    }
    if (xml.readyState==4 && xml.status==200){
        var arrCombos = xml.responseText.split('|||');

        document.getElementById('refresh_TiposDocumentos').innerHTML = arrCombos[0];
		document.getElementById('refresh_EstadoCivil').innerHTML = arrCombos[1];
        document.getElementById('refresh_TipoLicencias').innerHTML = arrCombos[2];
        document.getElementById('refresh_TipoDiscapacidades').innerHTML = arrCombos[3];
        mostrarOcultarCombos();
    }
}

function mostrarOcultarCombos()
{
		childsTipoLicencias = $("#tipoLicencia").children();
        childsTiposDiscapacidades = $("#tipoDiscapacidad").children();

        if(childsTipoLicencias.length <= 1){
            $("#dl_TipoLicencia").hide();
        }else{
            $("#dl_TipoLicencia").show();
        }

        if(childsTiposDiscapacidades.length <= 1){
            $("#div_TiposDiscapacidades").hide();
        }else{
            $("#div_TiposDiscapacidades").show();
        }
}

function callback_refresh_cmbPais(){

	 if (xml.readyState==1){
           document.getElementById('refresh_Provincias').innerHTML='<img style="" src="../../templates/images/ajax-loader.gif" />';
     }
     if (xml.readyState==4 && xml.status==200){
        document.getElementById('refresh_Provincias').innerHTML = xml.responseText;
	}
}

function validar_idiomas()
{
	var error=0;
	var errores='';

	if (document.getElementById('cmb_Idioma').value == 0){
		errores = errores + "<p>Debe indicar un idioma.</p> ";
		error=1;

	}

	if (document.getElementById('cmb_calificadorIdioma').value == 0){
		errores = errores + "<p>Debe indicar si es oral o escrito.</p> ";
		error=1;
	}

	if (document.getElementById('cmb_nivelIdioma').value == 0){
		errores = errores + "<p>Debe indicar el nivel del idioma.</p> ";
		error=1;
	}

    if (error){

        document.getElementById('erroresIdiomas').innerHTML = errores;
    }
    else
    {
		idconocimiento = document.getElementById('cmb_Idioma').value;
		idcalificador = document.getElementById('cmb_calificadorIdioma').value;
		idnivel = document.getElementById('cmb_nivelIdioma').value;
        accion_ajax ("POST","../../carga_cv/idiomas_ajax.ngmf","callback_guardar_idiomas","idconocimiento=" + idconocimiento + "&idcalificador=" + idcalificador + "&idnivel=" + idnivel + "&accion=A");
    }
}

function callback_guardar_idiomas(){

        if (xml.readyState==1){
            /*document.getElementById('CargandoEstudios').innerHTML='<img style="margin-left:40%;" src="/images/ajax/ajax-loader3.gif" /><p style="margin-left:40%; font-size:14px;">Cargando Estudios</p>';*/
        }
        if (xml.readyState==4 && xml.status==200){
            document.getElementById('resumen_idiomas').innerHTML= xml.responseText;
            limpiarIdiomas();
        }
}

function limpiarIdiomas()
{
	document.getElementById('cmb_Idioma').selectedIndex=0;
	document.getElementById('cmb_nivelIdioma').selectedIndex=0;
	document.getElementById('cmb_calificadorIdioma').selectedIndex= 0;
	document.getElementById('erroresIdiomas').innerHTML = '';
}

function eliminar_idiomas(idconocimiento,idcalificador,idnivel){
	accion_ajax ("POST","../../carga_cv/idiomas_ajax.ngmf","callback_idiomas_eliminar","idconocimiento=" + idconocimiento + "&idcalificador=" + idcalificador + "&idnivel=" + idnivel + "&accion=E");
}

function callback_idiomas_eliminar(){

    if (xml.readyState==1){        
		createGreyCover();
    }
    if (xml.readyState==4 && xml.status==200){
		document.getElementById('resumen_idiomas').innerHTML= xml.responseText;
		removeGreyCoverSlow();
    }
}


function guardar_datos_personales(autenticada)
{
	var error=0;
	var errores='';

	var post;
	if (autenticada == undefined){		
		var autenticada = Boolean(0);
	}

    post = 'txtNombre=' + document.getElementById('txtNombre').value;
    post = post + '&txtApellido=' + document.getElementById('txtApellido').value;
    post = post + '&cmbTipoDocumento=' + document.getElementById('cmbTipoDocumento').value;
    post = post + '&txtDocumento=' + document.getElementById('txtDocumento').value;
    post = post + '&cmbEstadoCivil=' + document.getElementById('cmbEstadoCivil').value;
    post = post + '&txtCalle=' + document.getElementById('txtCalle').value;

    post = post + '&txtNumero=' + document.getElementById('txtNumero').value;
    post = post + '&txtBarrio=' + document.getElementById('txtBarrio').value;
    post = post + '&cmbProvincia=' + document.getElementById('cmbProvincia').value;
    post = post + '&txtCiudad=' + document.getElementById('txtCiudad').value;
    post = post + '&txtTelefonoPrefix=' + document.getElementById('txtTelefonoPrefix').value;
    post = post + '&txtTelefono=' + document.getElementById('txtTelefono').value;
    post = post + '&txtEmail=' + document.getElementById('txtEmail').value;

    post = post + '&cmbFechaNacimiento_D=' + document.getElementById('cmbFechaNacimiento_D').value;
    post = post + '&cmbFechaNacimiento_M=' + document.getElementById('cmbFechaNacimiento_M').value;
    post = post + '&cmbFechaNacimiento_A=' + document.getElementById('cmbFechaNacimiento_A').value;

    post = post + '&radSexo=' + document.getElementById('radSexo').checked;
    post = post + '&txtPiso=' + document.getElementById('txtPiso').value;
    post = post + '&txtDepto=' + document.getElementById('txtDepto').value;
    post = post + '&txtBarrio=' + document.getElementById('txtBarrio').value;
    post = post + '&tipoLicencia=' + document.getElementById('tipoLicencia').value;
    post = post + '&tipoDiscapacidad=' + document.getElementById('tipoDiscapacidad').value;
    post = post + '&txtTelefonoCelularPrefix=' + document.getElementById('txtTelefonoCelularPrefix').value;
    post = post + '&txtTelefonoCelular=' + document.getElementById('txtTelefonoCelular').value;
    post = post + '&cmbNacionalidad=' + document.getElementById('cmbNacionalidad').value;
    post = post + '&cmbPais=' + document.getElementById('cmbPais').value;
    post = post + '&txtCP=' + document.getElementById('txtCP').value;
    post = post + '&pos_idposting=' + document.getElementById('pos_idposting').value;
    post = post + '&ppasword=' + document.getElementById('ppasword').value;
    post = post + '&cppasword=' + document.getElementById('cppasword').value;
    post = post + '&autenticada='+ autenticada;




    accion_ajax ("POST","../../carga_cv/datos_personales_ajax.ngmf","callback_guardar_datos_personales",post +"&accion=A");
}

function callback_guardar_datos_personales()
{
	if (xml.readyState==1){
        createGreyCover();            
    }
    if (xml.readyState==4 && xml.status==200){
    	if (xml.responseText == 0){
    		document.getElementById('errores_perfil').innerHTML= '';
    		jAlert('Los datos se guardaron con exito ', '',removeGreyCover);
    		document.getElementById('tab1').onclick = function(){tab(1)};
    		document.getElementById('tab2').onclick = function(){tab(2)};
    		document.getElementById('tab3').onclick = function(){tab(3)};
    		document.getElementById('tab4').onclick = function(){tab(4)};
    	}
    	else
    	{
    		removeGreyCover();
    		if (xml.responseText == -1)
    		{
    			alert('Hubo un error al intentar guardar los datos. Intente mas tarde.');
    		}
    		else
    		{
    			document.getElementById('errores_perfil').innerHTML= xml.responseText;
    		}
    	}
    }
}

function callback_refresh_edu_pais(){

	 if (xml.readyState==1){
         document.getElementById('refresh_tipoestudio').innerHTML='<img style="" src="../../templates/images/ajax-loader.gif" />';
         document.getElementById('refresh_instituciones').innerHTML='<img style="" src="../../templates/images/ajax-loader.gif" />';
         document.getElementById('refresh_areaestudio').innerHTML='<img style="" src="../../templates/images/ajax-loader.gif" />';
     }
     if (xml.readyState==4 && xml.status==200){
        var arrCombos = xml.responseText.split('|||');
        document.getElementById('refresh_tipoestudio').innerHTML = arrCombos[0];
		document.getElementById('refresh_instituciones').innerHTML = arrCombos[1];
        document.getElementById('refresh_areaestudio').innerHTML = arrCombos[2];

    }
}

function callback_refresh_edu_sinstitucion()
{
	if (xml.readyState==1){
        document.getElementById('refresh_otra_Institucion').innerHTML='';
    }
    if (xml.readyState==4 && xml.status==200){
        document.getElementById('refresh_otra_Institucion').innerHTML= xml.responseText;
    }
}

function mensajeSinCV()
{
	jAlert('Debe completar los datos personales primero ', '',function(r) {});
}