// ONLOAD
$('document').ready(load);
        // Funcao LOAD
        function load(){

                try{
                       // TIPS (BALOES)
                        $('.fireHelpPOP').bind('mouseover',showHelpPop);

                        $('.popHelp').bind('mouseover',hideHelpPop);

                        $('.fireHelpPOP').bind('mouseout',hideHelpPop);

                        // ==============================================================================
                }catch(err){
                }
                


                /**
                 * Pedido 14742
                 */
                $('.btVisualizar').bind('click', function () {
                    
                    var curId = this.id.match(/(\d+)/)[1];
                    
                    var curDesc = $('#div5_' + curId);
                    
                    if ( curDesc.css('display') == 'none' || !curDesc.css('display') ) {
                        
                        curDesc.css('display', 'block');
                        
                    } else {
                        
                        curDesc.css('display', 'none');
                        
                    }
                    
                });

                
        }



        function showHelpPop(e){
                var pop = $('#'+$(this).attr('rel'));
                $(this).addClass('underline');
                //pop.show();
                pop.css('display','block');
        }

        function hideHelpPop(e){
                var pop = $('#'+$(this).attr('rel'));
                $(this).removeClass('underline');
                //pop.hide();
                pop.css('display','none');
        }


var cur_array = new Array;
var openBusca = 0;
var statusUsr = 0;

function setStatus(newStatus){
	if( Number( newStatus ) > 0 ){
		statusUsr = newStatus;
	}
}

function return_value(pos){
	var id = 'cur'+cur_array[pos];
	if( document.getElementById(id) ){
	    
         
//        globalFunc.setObjClass('div1_'+cur_array[pos],'resultadoItemV');
//        globalFunc.setObjClass('div2_'+cur_array[pos],'resultadoItemTituloV formTexto azulEscuro');
//        globalFunc.setObjClass('div3_'+cur_array[pos],'resultadoItemDataV formTexto azulEscuro');
//        globalFunc.setObjClass('div4_'+cur_array[pos],'resultadoItemLocalV preto');
//        globalFunc.setObjClass('div5_'+cur_array[pos],'resultadoItemInfoV');
//        var imgView = eval("document.getElementById('imgView"+cur_array[pos]+"')");
//        imgView.src = "http://img.catho.com.br/site/vag/icoVisualizado0.gif";

        $('#imgViewed_'+cur_array[pos]).css('display', 'block');
        $('#imgNotViewed_'+cur_array[pos]).css('display', 'none');
        
        $('#cur'+cur_array[pos]).removeClass('box-Curriculo').addClass('box-Curriculo-View');
        $('#cur_'+cur_array[pos]).removeClass('color-Blue-Link').addClass('txtRoxo');
        $('ul li.box-Curriculo-Name', '#cur'+cur_array[pos]).removeClass('box-Curriculo-Name').addClass('box-Curriculo-View-Name');
        $('ul li.box-Curriculo-Date', '#cur'+cur_array[pos]).removeClass('box-Curriculo-Date').addClass('box-Curriculo-View-Date');
        $('div.box-Curriculo-City', '#cur'+cur_array[pos]).removeClass('box-Curriculo-City').addClass('box-Curriculo-View-City');
        $('table.box-Actions-table', '#cur'+cur_array[pos]).removeClass('box-Actions-table').addClass('box-Actions-View-table');
	$('ul li.box-Curriculo-PretenSal', '#cur'+cur_array[0]).removeClass('box-Curriculo-PretenSal').addClass('box-Curriculo-View-PretenSal');
	$('ul li.box-Curriculo-PretenSal2', '#cur'+cur_array[0]).removeClass('box-Curriculo-PretenSal2').addClass('box-Curriculo-View-PretenSal2');
		
	}

        return(cur_array[pos]);
}

function setCurPos(posArg, curIdArg) {
        cur_array[posArg] = curIdArg;
}

function liga(idArg) {
        if (document.getElementById(idArg).style.display == 'none') {
                document.getElementById(idArg).style.display = '';
                                }
        else {
                document.getElementById(idArg).style.display = 'none';
                }
}


function openClosePerfis(flag){
	var info   = document.getElementById('boxProfInfo1');
	var perfis = document.getElementById('boxPerfisOutros');
	if( flag == 'open' ){
		info.style.display = 'none';
		perfis.style.display = '';

		changeFormLayers(1,'Profissional');
		selectFunc.updateSelect('perfil',1);
		changeAba('1');
		document.getElementById('boxProfRadio1').checked=true;
	}
	else{
		info.style.display = '';
		perfis.style.display = 'none';
	}
}

function novaBusca(){
	document.getElementById('filtersBusca').style.display='';

	if( openBusca == 0 ){
		var urlParans = facetClass.getUrlParans();
		var xmlhttp = globalFunc.ajax();

		xmlhttp.open("GET", "index.php?State=back_form&tipoBusca=busca_old"+urlParans+"&logBuscaId="+document.logBuscaId.value);
		xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4){
				var retorno = xmlhttp.responseText;
				document.getElementById('filtersBusca').style.display='none';
				document.getElementById('filtersBusca').innerHTML = retorno;
				setTimeout(function(){document.getElementById('filtersBusca').style.display='block';hiddeResult(0);},500);
				openBusca=1;
			}
		}
		xmlhttp.send(null);
	}
	else{
		document.getElementById('filtersBusca').style.display='block';
		hiddeResult(200);
	}
}

function showHelp(id){
	document.getElementById(id).style.display='';
}
function hideHelp(id){
	document.getElementById(id).style.display='none';
}

function classe(idArg, idClasse) {
	document.getElementById(idArg).className = idClasse;
}

function changeFormLayers( perfil_id, perfil_name ){
	var title   = document.getElementById('perfilAtual');
	var area    = document.getElementById('areaPerfil');
	var nivel   = document.getElementById('nivelPerfil');
	var subArea = document.getElementById('subareapBox');

	selectFunc.setUnsetAll('areapId');
	selectFunc.setUnsetAll('subareap');
	selectFunc.setUnsetAll('nivelhId');

	subArea.style.display='none';

	if( perfil_id == 9 ){
		document.getElementById('areapIdBox').style.display = "";
		document.getElementById('areaPaiIdBox').style.display = "none";
		document.getElementById('subareapBox').style.display = "none";
		document.getElementById('nivelhIdBox').style.display = "none";
	}
	document.getElementById('textSelectareapId').innerHTML = 'Carregando...';
	document.getElementById('textSelectsubareap').innerHTML = 'Carregando...';
	document.getElementById('textSelectnivelhId').innerHTML = 'Carregando...';


	var areaTitle = document.getElementById('areaTitle');
	var nivelTitle = document.getElementById('nivelTitle');
	var subAreaTitle = document.getElementById('subAreaText');

	if( document.getElementById('habPerfil') ){
		var hab   = document.getElementById('habPerfil');
		hab.innerHTML   = perfil_name;
	}

	title.innerHTML = perfil_name;
	area.innerHTML  = perfil_name;
	nivel.innerHTML = perfil_name;

	document.getElementById('obsRedArea').style.display='';
	document.getElementById('obsRedNivel').style.display='';
	document.getElementById('obsRedMsg').style.display='';

	if( perfil_id == 3 ){
		areaTitle.innerHTML = '&Aacute;rea de forma&ccedil;&atilde;o -';
		subAreaTitle.innerHTML = 'Cursos:';
		document.getElementById('obsRedMsgArea').innerHTML = '&Aacute;rea de forma&ccedil;&atilde;o';
	}
	else{
		areaTitle.innerHTML = '&Aacute;rea profissional -';
		subAreaTitle.innerHTML = '&Aacute;rea Especifica:';
		document.getElementById('obsRedMsgArea').innerHTML = '&Aacute;rea profissional';
	}
	if( perfil_id == 1 || perfil_id == 4 || perfil_id == 11 ){
		document.getElementById('obsRedMsgNivel').style.display='';
	}
	else{
		document.getElementById('obsRedMsgNivel').style.display='none';
	}
	if( document.getElementById('ppdBox') ){
		if( perfil_id == 1 ){
			document.getElementById('ppdBox').style.display='';
		}
		else{
			document.getElementById('ppdBox').style.display='none';
		}
	}
}

function showHideTipe(){
	document.getElementById('obsRedArea').style.display='none';
        document.getElementById('obsRedNivel').style.display='none';
	document.getElementById('obsRedMsg').style.display='none';
}

function changeAba( id ){

	if( id == 9 ){
		document.getElementById('areapIdBox').style.display = "";
		document.getElementById('areaPaiIdBox').style.display = "none";
		document.getElementById('subareapBox').style.display = "none";
		document.getElementById('nivelhIdBox').style.display = "none";
	}
	document.getElementById('textSelectareapId').innerHTML = 'Carregando...';
	document.getElementById('textSelectsubareap').innerHTML = 'Carregando...';
	document.getElementById('textSelectnivelhId').innerHTML = 'Carregando...';

	var boxProf  = document.getElementById('boxProf1');
	var boxEsta  = document.getElementById('boxProf3');
	var boxOper  = document.getElementById('boxProf9');
	var imgProf1 = document.getElementById('imgProf12');
	var imgEsta1 = document.getElementById('imgProf32');
	var imgOper1 = document.getElementById('imgProf92');
	var imgProf2 = document.getElementById('imgProf11');
	var imgEsta2 = document.getElementById('imgProf31');
	var imgOper2 = document.getElementById('imgProf91');

	globalFunc.setObjClass('boxProf1','boxProfissionalAbaOff');
	globalFunc.setObjClass('boxProf3','boxProfissionalAbaOff');
	globalFunc.setObjClass('boxProf9','boxProfissionalAbaOff');
	imgProf1.style.display = 'none';
	imgEsta1.style.display = 'none';
	imgOper1.style.display = 'none';
	imgProf2.style.display = 'none';
	imgEsta2.style.display = 'none';
	imgOper2.style.display = 'none';
	eval( "globalFunc.setObjClass('boxProf"+id+"','boxProfissionalAbaOn');" );
	var defaultImg1 = eval("document.getElementById('imgProf"+id+"1')");
	var defaultImg2 = eval("document.getElementById('imgProf"+id+"2')");
	defaultImg1.style.display='';
	defaultImg2.style.display='';

	if( id == 3 || id == 9 ){
		document.getElementById('boxPerfisOutros').style.display='none';
		document.getElementById('boxProfInfo1').style.display='';
	}
}

function verifyZona(){
	var sels =      $('#listcidade_idTable input[type=checkbox]:checked');
	if( $(sels[0]).val() == 783 && sels.length == 1 ){
		selectFunc.updateSelect('cidade',783);
	}
	else{
		document.getElementById('zonaBox').style.display = 'none';
		selectFunc.cleanList('zona');
	}
}

function showCur( usr_emp_id, type, statusBusca, vars, querystring ){
	if( statusBusca == 2 ){
		var curVars = vars.split("|");
		if( type == 'cur' ){

            /**
             * PEDIDO 16141 - Melhorar highlight da busca de curriculos
             * Passado parametro "q" para funcao openCur enviar ao arquivo curriculo.php
             */
            q = cE = '';
            qMatch = querystring.match(/q=(([\w\+\sçÇãâáàäÃÂÁÀÄéèêëÉÈÊËíìîïÍÌÎÏóòõôöÓÒÕÔÖúùûüÙÚÛÜ]|%[\dabcdefABCDEF]{2})+)/);
            if ( qMatch ) {
                if ( qMatch[1] ) {
                    q = qMatch[1];
                }
            }
            qMatch = querystring.match(/q_facet=(([\w\+\sçÇãâáàäÃÂÁÀÄéèêëÉÈÊËíìîïÍÌÎÏóòõôöÓÒÕÔÖúùûüÙÚÛÜ]|%[\dabcdefABCDEF]{2})+)/);
            if ( qMatch ) {
                if ( qMatch[1] ) {
                    q += ' ' + qMatch[1];
                }
            }
            qMatch = querystring.match(/q_sinonimos=(([\w\+\sçÇãâáàäÃÂÁÀÄéèêëÉÈÊËíìîïÍÌÎÏóòõôöÓÒÕÔÖúùûüÙÚÛÜ]|%[\dabcdefABCDEF]{2})+)/);
            if ( qMatch ) {
                if ( qMatch[1] ) {
                    q += ' ' + qMatch[1];
                }
            }
            cEMatch = querystring.match(/campos_especificos=(([\w\+\sçÇãâáàäÃÂÁÀÄéèêëÉÈÊËíìîïÍÌÎÏóòõôöÓÒÕÔÖúùûüÙÚÛÜ\,]|%[\dabcdefABCDEF]{2})+)/);
            if ( cEMatch ) {
                if ( cEMatch[1] ) {
                    cE = cEMatch[1];
                }
            }
            openCur( curVars[0] , curVars[1] ,  q.replace(/^\s+|\s+$/g,"") , cE.replace(/^\s+|\s+$/g,"") );

            
            
//			globalFunc.setObjClass('div1_'+curVars[0],'resultadoItemV');
//			globalFunc.setObjClass('div2_'+curVars[0],'resultadoItemTituloV formTexto azulEscuro');
//			globalFunc.setObjClass('div3_'+curVars[0],'resultadoItemDataV formTexto azulEscuro');
//			globalFunc.setObjClass('div4_'+curVars[0],'resultadoItemLocalV preto');
//			globalFunc.setObjClass('div5_'+curVars[0],'resultadoItemInfoV');
//            
//			var imgView = eval("document.getElementById('imgView"+curVars[0]+"')");
//			imgView.style.display = "";



//            $(".bkgVerdeClaro", "#cur"+curVars[0]).removeClass('bkgVerdeClaro').addClass('bkgAzulClaro');
//            $(".fundoVerde", "#cur"+curVars[0]).removeClass('fundoVerde').addClass('fundoAzul');
//            $(".trVerde", "#cur"+curVars[0]).removeClass('trVerde').addClass('trAzul');
//            
            $('#imgViewed_'+curVars[0]).css('display', 'block');
            $('#imgNotViewed_'+curVars[0]).css('display', 'none');

		    /**
		     * Pedido 14742
		     */
//			$("#boxDetalhesCv_" + curVars[0]).css('display', 'none');
//			$('#detalharCv_'+curVars[0]).css('display', 'block');
            
            $('#cur'+curVars[0]).removeClass('box-Curriculo').addClass('box-Curriculo-View');
            $('#cur_'+curVars[0]).removeClass('color-Blue-Link').addClass('txtRoxo');
            $('ul li.box-Curriculo-Name', '#cur'+curVars[0]).removeClass('box-Curriculo-Name').addClass('box-Curriculo-View-Name');
            $('ul li.box-Curriculo-Date', '#cur'+curVars[0]).removeClass('box-Curriculo-Date').addClass('box-Curriculo-View-Date');
            $('div.box-Curriculo-City', '#cur'+curVars[0]).removeClass('box-Curriculo-City').addClass('box-Curriculo-View-City');
            $('table.box-Actions-table', '#cur'+curVars[0]).removeClass('box-Actions-table').addClass('box-Actions-View-table');
            $('ul li.box-Curriculo-PretenSal', '#cur'+curVars[0]).removeClass('box-Curriculo-PretenSal').addClass('box-Curriculo-View-PretenSal');
	    $('ul li.box-Curriculo-PretenSal2', '#cur'+curVars[0]).removeClass('box-Curriculo-PretenSal2').addClass('box-Curriculo-View-PretenSal2');
            

		}
		if( type == 'cestaAdd' ){
			addBasketStep( usr_emp_id,curVars[0],curVars[1],curVars[2],'0')
		}
		if( type == 'cestaRem' ){
			addBasketStep( usr_emp_id,curVars[0],curVars[1],curVars[2],'1')
		}
		if( type == 'email' ){
			showModal('/recrutador/contato.php?arrayContact[]='+vars,450,370,'Enviar Mensagem para candidato',true,true);
		}
		if( type == 'referencia' ){
			showModal('/recrutador/contato.php?arrayContact[]='+vars+"&referencia=1",550,395,'Solicitação de Referências Pessoais',true,true);
		}
		if( type == 'entrevista' ){
			showModal('/cur/gen/interview/interview_new.php?&perfil_id='+curVars[1]+'&usr_id='+curVars[0]+'&from=banco_cv&vag_id=',750,495,'Agendamento de entrevista',true,true);
		}
		if( type == "processo" ){
			showModal('/cur/busca/convite.php?cur_id='+vars,505,205,'Convite para processo seletivo',true,true);
		}
		if( type == "popCesta" ){
		    pop('/cur/busca/cestacv.php');
		}
	}
	else if( statusBusca == 1 ){
		if( navigator.userAgent.indexOf("MSIE") > 0 ){
			showModal('/buscar/curriculos/assinanteLogado.html',497,301,'Assinatura da busca de currículos',true,true);
		}
		else{
			showModal('/buscar/curriculos/assinanteLogado.html',497,301,'Assinatura da busca de currículos',true,true);
		}

//		location.href="/cur/busca/templates/vantagem.php?redir="+globalFunc.url_encode('/buscar/curriculos/?'+querystring);
	}
	else{
		showLoginScr(globalFunc.url_encode("/buscar/curriculos/?"+querystring));
	}
}


function showCurDeslogado ( vars , querystring ){
    
    var curVars = vars.split("|");

    /**
     * PEDIDO 16141 - Melhorar highlight da busca de curriculos
     * Passado parametro "q" para funcao openCur enviar ao arquivo curriculo.php
     */
    q = cE = '';
    qMatch = querystring.match(/q=(([\w\+\sçÇãâáàäÃÂÁÀÄéèêëÉÈÊËíìîïÍÌÎÏóòõôöÓÒÕÔÖúùûüÙÚÛÜ]|%[\dabcdefABCDEF]{2})+)/);
    if ( qMatch ) {
        if ( qMatch[1] ) {
            q = qMatch[1];
        }
    }
    qMatch = querystring.match(/q_facet=(([\w\+\sçÇãâáàäÃÂÁÀÄéèêëÉÈÊËíìîïÍÌÎÏóòõôöÓÒÕÔÖúùûüÙÚÛÜ]|%[\dabcdefABCDEF]{2})+)/);
    if ( qMatch ) {
        if ( qMatch[1] ) {
            q += ' ' + qMatch[1];
        }
    }
    qMatch = querystring.match(/q_sinonimos=(([\w\+\sçÇãâáàäÃÂÁÀÄéèêëÉÈÊËíìîïÍÌÎÏóòõôöÓÒÕÔÖúùûüÙÚÛÜ]|%[\dabcdefABCDEF]{2})+)/);
    if ( qMatch ) {
        if ( qMatch[1] ) {
            q += ' ' + qMatch[1];
        }
    }
    cEMatch = querystring.match(/campos_especificos=(([\w\+\sçÇãâáàäÃÂÁÀÄéèêëÉÈÊËíìîïÍÌÎÏóòõôöÓÒÕÔÖúùûüÙÚÛÜ\,]|%[\dabcdefABCDEF]{2})+)/);
    if ( cEMatch ) {
        if ( cEMatch[1] ) {
            cE = cEMatch[1];
        }
    }

    
    $('#cur'+curVars[0]).removeClass('box-Curriculo').addClass('box-Curriculo-View');
    $('#cur_'+curVars[0]).removeClass('color-Blue-Link').addClass('txtRoxo');
    $('ul li.box-Curriculo-Name', '#cur'+curVars[0]).removeClass('box-Curriculo-Name').addClass('box-Curriculo-View-Name');
    $('ul li.box-Curriculo-Date', '#cur'+curVars[0]).removeClass('box-Curriculo-Date').addClass('box-Curriculo-View-Date');
    $('div.box-Curriculo-City', '#cur'+curVars[0]).removeClass('box-Curriculo-City').addClass('box-Curriculo-View-City');
    $('table.box-Actions-table', '#cur'+curVars[0]).removeClass('box-Actions-table').addClass('box-Actions-View-table');
    $('ul li.box-Curriculo-PretenSal', '#cur'+curVars[0]).removeClass('box-Curriculo-PretenSal').addClass('box-Curriculo-View-PretenSal');
    $('ul li.box-Curriculo-PretenSal2', '#cur'+curVars[0]).removeClass('box-Curriculo-PretenSal2').addClass('box-Curriculo-View-PretenSal2'); 
    openCur( curVars[0] , curVars[1] ,  q.replace(/^\s+|\s+$/g,""), cE.replace(/^\s+|\s+$/g,"") );
    
}

function openCur(cur_id,pos,q,cE){
	var limitTmp = document.getElementById('pageReg').value;
	var last     = document.getElementById('lastReg').value;
	var pageNext = document.getElementById('pageAtual').value;
	limitTmp = (Number(pageNext)*20);
	window.open('/cur/gen/curriculo.php?cur_id='+ cur_id + '&pos=' + pos + '&limit='+limitTmp+'&lastReg='+last+'&from=busca_cv&FROM=csearch&q='+q+'&campos_especificos='+cE,'whatever', 'width=700,height=500,scrollbars=1');
}

function openCurOpened(cur_id,pos){
        var limitTmp = document.getElementById('pageReg').value;
        var last     = document.getElementById('lastReg').value;
	var pageNext = document.getElementById('pageAtual').value;
	limitTmp = (Number(pageNext)*20);
	if( window.whatever ){
		whatever.location = '/cur/gen/curriculo.php?cur_id='+ cur_id + '&pos=' + pos + '&limit='+limitTmp+'&lastReg='+last+'&from=busca_cv&FROM=csearch';
	}
	else{
	        window.open('/cur/gen/curriculo.php?cur_id='+ cur_id + '&pos=' + pos + '&limit='+limitTmp+'&lastReg='+last+'&from=busca_cv&FROM=csearch','whatever', 'width=700,height=500,scrollbars=1');
	}
}

function showLoginScr(redirArg) {
        if( navigator.userAgent.indexOf("MSIE") > 0 ){
                showModal('/cur/busca/buscaLogin.php?redir='+globalFunc.url_encode(redirArg), 643, 285,'Login', false, true);
//              showModal('/cur/busca/buscaLogin.php?redir='+redirArg, 605, 195,'Login', false, true);
        }
        else{
                showModal('/cur/busca/buscaLogin.php?redir='+globalFunc.url_encode(redirArg), 605, 253,'Login', false, true);
//              showModal('/cur/busca/buscaLogin.php?redir='+redirArg, 605, 195,'Login', false, true);
        }
}

function hiddenLoginScr() {
        closeModal();
}

function showModal(urlArg, widthArg, heightArg, titleArg, scrollBarArg, showCloseArg) {
//        this.scroll(1,-1000);
        var dmp = document.getElementById('divModalPanel');
        var divModalBorder = document.getElementById('divModalBorder');

        var dm = document.getElementById('divBackground');

        // default is true
        if (scrollBarArg == null || scrollBarArg == undefined) {
                scrollBarArg = true;
        }
        if (scrollBarArg) {
                document.getElementById('divModalPanelFrame').setAttribute('scrolling','auto');
                document.getElementById('divModalPanelFrame').scrolling='auto';
        } else {
                document.getElementById('divModalPanelFrame').setAttribute('scrolling','no');
                document.getElementById('divModalPanelFrame').scrolling='no';
        }

        document.getElementById('divModalTitle').innerHTML = titleArg;

        document.getElementById('divModalPanelFrame').src = urlArg;
        document.getElementById('divModalPanelFrame').width = widthArg;
        document.getElementById('divModalPanelFrame').height = heightArg;
        divModalBorder.width = widthArg;
        divModalBorder.height = heightArg;

        if (showCloseArg == null && showCloseArg == undefined) {
                showCloseArg = true;
        }

        if (showCloseArg) {
                document.getElementById('closeModalEvent').style.display = '';
        } else {
                document.getElementById('closeModalEvent').style.display = 'none';

        }

        dm.style.display='';
        dmp.style.display='';

        var altTela = Math.floor(document.body.offsetHeight);
        var largTela =  Math.floor(document.body.offsetWidth);
        var largDiv = Math.floor(divModalBorder.offsetWidth);
        var altDiv = Math.floor(divModalBorder.offsetHeight);

        dm.style.width=largTela+'px';
	if( document.all ){
		dm.style.height=altTela+'px';
	}
	else{
	        dm.style.height=altTela+'px';
	}

        dmp.style.left=((largTela/2)-(largDiv/2))+'px';
	var posY = 90;
	if( document.all ){
		posY = document.body.scrollTop;
	}
	else{
		posY = window.pageXOffset;
	}
	posY = $(document).scrollTop();
        dmp.style.top= (Number(posY)+50)+'px';

	var t = 0;
    var h = $(document).height();

    var cssArg = {'top':t+'px','height':h+'px', 'visibility':'visible'}

    $('#divBackground').css(cssArg).show();

}

function closeModal(timeArg) {
        if (timeArg != undefined && timeArg != null && timeArg > 0) {
                window.setTimeout(function() {
                        closeModal();
                }, timeArg*1000);
        } else {
                document.getElementById('divModalPanel').style.display='none';
                document.getElementById('divBackground').style.display='none';
                document.getElementById('divModalTitle').innerHTML = '';
                document.getElementById('divModalPanelFrame').src = '';
        }
}

function convidaProcessoSeletivo(textArg) {
        var vag_id = document.getElementById('vagSelect').value;
        showModal('/recrutador/convidar_processo.php?vag_id='+vag_id, 550, 250, textArg);
}

function validaConvite(){
        if( document.getElementById('campoNome').value.length < 3 ){
                document.getElementById('nomeAlert').style.display = "";
                document.getElementById('campoNome').focus();
                return false;
        }
        var strmail = document.getElementById('campoEmail').value;
        var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
        if (!strmail.match(re)) {
                document.getElementById('emailAlert').style.display = "";
                document.getElementById('campoEmail').focus();
                return false;
        }
}

function sendInvite(emp_id,vag_id,cur_id,div){
        if( Number(vag_id) > 0 && Number(cur_id) > 0 ){
                var xmlhttp = globalFunc.ajax();

                if( div != 'nenhum' ){
                        document.getElementById(div).style.display='none';
                }
                var divCarregando = document.getElementById('divCarregando');
                divCarregando.style.display='';
                divCarregando.innerHTML = '<b>Carregando...</b>';
                xmlhttp.open("GET", "dadosBusca.php?action=invite&emp_id="+emp_id+"&vag_id="+vag_id+"&cur_id="+cur_id);
                //Executada quando o navegador obtiver o cÃ³digo
                xmlhttp.onreadystatechange=function(){
                        if (xmlhttp.readyState==4){
                                var retorno = globalFunc.url_decode(xmlhttp.responseText);
                                if( retorno == 1 ){
                                        divCarregando.innerHTML = '<b>Convite enviado com sucesso!</b>';
                                }
                                else{

                                        divCarregando.innerHTML = '<b>O convite não pode ser enviado.</b>';
                                }
                        }
                }
                xmlhttp.send(null);
        }
}

function showAlertBoleto(){
        showModal('/recrutador/pop_boleto.php', 424, 253, 'Alerta de boleto', false, true);
}

function setPaid(id_boleto){
	var xmlhttp = globalFunc.ajax();
	xmlhttp.open("get","funcoesLocais.php?action=setPaid&id_boleto="+id_boleto,false);
	xmlhttp.send(null);
	document.getElementById('alertBoleto').style.display = 'none';
	closeModal(0);
}

function addBasketStep( recrutador_id,cur_id,usr_id,perfil_id,del){
//	var divAdd= eval("document.getElementById('"+cur_id+"_cestaAdd')");
//	var divRem= eval("document.getElementById('"+cur_id+"_cestaRem')");

	if( del == 1 ){
//		divAdd.style.display = '';
//		divRem.style.display = 'none';
	    $('#cestaRem_'+cur_id).parent().attr('title' , $('#cestaAdd_'+cur_id).attr('title')).children().toggle();
	    
	}
	else{
//		divAdd.style.display = 'none';
//		divRem.style.display = '';
	    $('#cestaAdd_'+cur_id).parent().attr('title' , $('#cestaRem_'+cur_id).attr('title')).children().toggle();
	}
    

	var xmlhttp = globalFunc.ajax();
	xmlhttp.open('GET', 'funcoesLocais.php?action=basket&recrutador_id='+recrutador_id+'&del='+del+"&usr_id="+usr_id+"&perfil_id="+perfil_id);
	//Executada quando o navegador obtiver o cÃ³digo
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4){
			var retorno = globalFunc.url_decode(xmlhttp.responseText);
		}
	}
	xmlhttp.send(null);
}

function pop(URL) {
        popupCesta = window.open(URL, '', 'width=700,height=500,scrollbars=1');
}

function saveResearch(){

	var form = $('#formResearch');
	var dados = form.serialize();

	$.ajax({
		type: "POST",
		url: "index.php",
		data: dados+'&State=saveResearch',
		success: updateResearchContent,
		error: updateResearchContent
	});
}

function updateResearchContent(content){
	$('#researchContent').html(content);

}

function changeSearchType(type){

	var boxPalavra = document.getElementById('palavraBox');
	var boxPerfil  = document.getElementById('areaNivelLocBox');
	var boxOutros  = document.getElementById('outrosBox');

	document.getElementById('dicaBusca').style.display = "";

	if(type==2){
		boxPalavra.style.display = 'none';
		boxPerfil.style.display = '';
		boxOutros.style.display = 'none';
		btnBuscar.style.display = '';
	}
	else if(type==1){
		boxPalavra.style.display = '';
		boxPerfil.style.display = 'none';
		boxOutros.style.display = 'none';
		btnBuscar.style.display = '';
		document.getElementById('dicaBusca').style.display = "none";
	}
	else{
		boxPalavra.style.display = '';
		boxPerfil.style.display = '';
		boxOutros.style.display = '';
		btnBuscar.style.display = 'none';
	}

	// RESETA
	document.getElementById("aba1").className = "abaNormal buscaItem color-Green-Dark";
	document.getElementById("aba2").className = "abaNormal buscaItem color-Green-Dark";
	document.getElementById("aba3").className = "abaNormal buscaItem color-Green-Dark";
	document.getElementById("aba11img1").style.display = "none";
	document.getElementById("aba11img2").style.display = "none";
	document.getElementById("aba21img1").style.display = "none";
	document.getElementById("aba21img2").style.display = "none";
	document.getElementById("aba31img1").style.display = "none";
	document.getElementById("aba31img2").style.display = "none";
	document.getElementById("aba12img1").style.display = "block";
	document.getElementById("aba12img2").style.display = "block";
	document.getElementById("aba22img1").style.display = "block";
	document.getElementById("aba22img2").style.display = "block";
	document.getElementById("aba32img1").style.display = "block";
	document.getElementById("aba32img2").style.display = "block";
	document.getElementById("aba1link").className = "txtCinza";
	document.getElementById("aba2link").className = "txtCinza";
	document.getElementById("aba3link").className = "txtCinza";

	// SELECIONA
	var abaSelecionada = "aba"+type;
	var img1Off = abaSelecionada+"2img1";
	var img2Off = abaSelecionada+"2img2";
	var img1On = abaSelecionada+"1img1";
	var img2On = abaSelecionada+"1img2";
	var linkSelecionado = abaSelecionada+"link";

	document.getElementById(img1Off).style.display = "none";
	document.getElementById(img2Off).style.display = "none";
	document.getElementById(img1On).style.display = "block";
	document.getElementById(img2On).style.display = "block";
	document.getElementById(abaSelecionada).className = "abaNormal abaSelecionada buscaItem color-Green-Dark";
	document.getElementById(linkSelecionado).className = "azulClarinho";

	document.getElementById('typeForm').value = type;
}

function zeraTextArea(valor,field){
	if( field.value == valor ){
		field.value = "";
	}
}

function comoFunciona(form){
		if( form == 1 ){
			var modelBusca = document.getElementById('typeForm').value;
			var url = "http://www3.catho.com.br/como-funciona/busca_cv.php?typeBusca="+modelBusca;
		}
		else if( form == 4 ){
			var url = "http://www3.catho.com.br/como-funciona/busca_cv.php?typeBusca=4";
		}
		else{
			var modelBuscaCv = document.getElementById('tipoBusca').value;
			if ( modelBuscaCv == "busca_palavra_chave" ){
				var url = "http://www3.catho.com.br/como-funciona/busca_cv.php?typeBusca=1";
			}
			else if (modelBuscaCv == "busca_area_nivel"){
				var url = "http://www3.catho.com.br/como-funciona/busca_cv.php?typeBusca=2";
			}
			else{
				var url = "http://www3.catho.com.br/como-funciona/busca_cv.php?typeBusca=1";
			}

		}
		window.open(url,'_blank','width=770,height=555,scrollbars=1');

	}

function changePage(flag){
	var pageNext = document.getElementById('pageAtual').value;
	facetClass.setFacet("page",String((Number(pageNext)+Number(flag))),"page",flag);
}

function getAnchorPosition(anchorname) {
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	var use_gebi=false, use_css=false, use_layers=false;

	if (document.getElementById){
		use_gebi=true;
	}
	else if(document.all){
		use_css=true;
	}
	else if(document.layers){
		use_layers=true;
	}
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
	}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
	}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
	}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname){
				found=1; break;
			}
		}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
		}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
	}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
	}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}

function hiddeResult(modifier){
	var t = $('#resultado').offset().top - Number(modifier) + 2;
	var h = $(document).height() - t + 10;

	var cssArg = {'top':t+'px','height':h+'px', 'visibility':'visible'}

	$('#divBackground').css(cssArg).show();
}

function closeBusca(){
	document.getElementById('filtersBusca').style.display='none';
	document.getElementById('divBackground').style.display = 'none';
	document.getElementById('filtersShow').style.display = '';
}


function updateComboBox(){

                // Cada SelectBox
                $('.generalClassFormComboBox').each(

                        function(){

                                        var ck = $('#'+$(this).attr('id')+' input[type=checkbox]:checked');

                                        if(ck.length > 0){

                                                try{
                                                        var ckH = document.getElementById($(ck[0]).attr('id'));
                                                        var tmp = ckH.onclick;
                                                        tmp();
                                                }catch(e){
                                                        debug(e);
                                                }
                                        }
                                }
                        );
        }

var idiomaPos = 0;
var arrayValuesIdioma = new Array();
function addIdioma(posInit){
	if( idiomaPos == 0 ){
		idiomaPos = posInit;
	}
	var conteudo = $('#idiomasMais').html();
	var modelContent = $('#modelIdioma').html();
	var newContent = modelContent.replace(/checked="checked"/g,"");
	newContent = newContent.replace(/checked/g,"");
	newContent = newContent.replace(/selected="selected"/g,"");
	newContent = newContent.replace(/selected/g,"");
	newContent = newContent.replace('',"");
	newContent = newContent.replace(/idiomaNivel[0]/g,"idiomaNivel"+idiomaPos+"");
	newContent = newContent.replace(/idiomaNivel\[0\]/g,"idiomaNivel["+idiomaPos+"]");
	newContent = newContent.replace(/idioma0/g,"idioma"+idiomaPos);
	conteudo += newContent;
	$('#idiomasMais').html(conteudo);

	var nivelField1 = eval("document.getElementById('idiomaNivel"+idiomaPos+"1')");
	var nivelField2 = eval("document.getElementById('idiomaNivel"+idiomaPos+"2')");
	var nivelField3 = eval("document.getElementById('idiomaNivel"+idiomaPos+"3')");
	nivelField1.checked=false;
	nivelField2.checked=false;
	nivelField3.checked=false;
	nivelField1.disabled = true;
	nivelField2.disabled = true;
	nivelField3.disabled = true;

	idiomaPos++;

	for( var i=0; i < arrayValuesIdioma.length; i++ ){
		if( arrayValuesIdioma[i][2] == 'check' && arrayValuesIdioma[i][1] != '-1' ){
			document.getElementById(arrayValuesIdioma[i][0]).checked=true;
		}
		else if( arrayValuesIdioma[i][2] == 'check' && arrayValuesIdioma[i][1] == '-1' ) {
			document.getElementById(arrayValuesIdioma[i][0]).checked=false;
		}
		else{
			document.getElementById(arrayValuesIdioma[i][0]).value=arrayValuesIdioma[i][1];
		}
	}
}

function setValueIdioma( idField, valueField, type ){
	var ctrlExist = 0;
	var j = 0;

	if( type == 'select' && valueField == '-1' ){
		var numberField = idField.replace('idioma','');
		numberField = numberField.replace('[','');
		numberField = numberField.replace(']','');
		var nivelField1 = eval("document.getElementById('idiomaNivel"+numberField+"1')");
	        var nivelField2 = eval("document.getElementById('idiomaNivel"+numberField+"2')");
	        var nivelField3 = eval("document.getElementById('idiomaNivel"+numberField+"3')");
	        nivelField1.checked=false;
	        nivelField2.checked=false;
	        nivelField3.checked=false;
	        nivelField1.disabled=true;
	        nivelField2.disabled=true;
	        nivelField3.disabled=true;
		setValueIdioma("idiomaNivel"+numberField+"1",'-1','check');
		setValueIdioma("idiomaNivel"+numberField+"2",'-1','check');
		setValueIdioma("idiomaNivel"+numberField+"3",'-1','check');
	}
	else if( type == 'select' && Number(valueField) > 0 ){
		var numberField = idField.replace('idioma','');
		numberField = numberField.replace('[','');
		numberField = numberField.replace(']','');
		var nivelField1 = eval("document.getElementById('idiomaNivel"+numberField+"1')");
	        var nivelField2 = eval("document.getElementById('idiomaNivel"+numberField+"2')");
	        var nivelField3 = eval("document.getElementById('idiomaNivel"+numberField+"3')");
	        nivelField1.disabled=false;
	        nivelField2.disabled=false;
	        nivelField3.disabled=false;
	}


	if( arrayValuesIdioma.length > 0 ){
		for( var i=0; i < arrayValuesIdioma.length; i++ ){
			if( arrayValuesIdioma[i][0] == idField ){
				arrayValuesIdioma[i][1] = valueField;
				ctrlExist = 1;
			}
			j++;
		}
	}
	if( ctrlExist == 0 ){
		arrayValuesIdioma[j] = new Array();
		arrayValuesIdioma[j][0] = idField;
		arrayValuesIdioma[j][1] = valueField;
		arrayValuesIdioma[j][2] = type;
	}
}

// LAYER SOLICITE ATENDIMENTO
function abreLayer() {
 document.getElementById('layerFundo').style.display = 'block';
 document.getElementById('layerCaixa').style.visibility = "visible";
}
function fechaLayer() {
 document.getElementById('layerFundo').style.display = 'none';
 document.getElementById('layerCaixa').style.visibility = "hidden";
}

// WRAPPER PARA A FUNÇÃO XAJAX


xajax = new Object();

onBlurAlert = true;

function alertKeyWord( evt ){

 	if(!(false==evt)){
		if(document.all){
			var key = event.keyCode;
		}  else {
			var key = evt.which;
		}

		if(13===key){
			key = true;
		} else {
			return true;
		}

	} else {
		var key = false;
		if(false===onBlurAlert){
			return true;
		}
	}

	var formulario	= document.getElementById('formBusca1');
	var	val			= formulario.q.value;
	var perfil		= "";

	for(var i=0; i < formulario['perfil_id[]'].length; i++){

		if(formulario['perfil_id[]'][i].checked == true){

			switch(i){
				case 0:
					perfil="profissional";
					break;
				case 1:
					perfil="estagiario";
					break;
				default:
					perfil="operacional";
			}

			break;

		}

	}

	xajax_alertKeyWord( val, perfil, key );

	if(key){
		return false;
	}

}



// ADICIONA O EVENTO AO CAMPO CIDADE
function addEventCity(){

	if( document.getElementById('formBusca1') && document.getElementById('formBusca1')['cidade_id[]'] ){

	    if( undefined == document.getElementById('formBusca1')['cidade_id[]']){
	        return;
	    }

		contador = document.getElementsByName('cidade_id[]').length;
		
		for(var i=0; i < contador; i++){
	
			campo = document.getElementById('formBusca1')['cidade_id[]'][i];
	
			if( campo.value.substring(0,1) != "0" ){
	
				break;
	
			}

				tmpId = 'cidade_id_' + campo.value ;

				idTop = tmpId;

				liTop = document.getElementById( idTop );

				idBot = tmpId.replace( 'cidade_id_0', 'cidade_id_' );

				liBot = document.getElementById( idBot );

				if(window.addEventListener){

					liTop.addEventListener( 'click',
						function (){

							ident = idTop;

							val = ident.replace( 'cidade_id_0', '' );

							cont = document.getElementById('formBusca1')['cidade_id[]'].length;

							for( var j=0; j < cont; j++){

								ckB = document.getElementById('formBusca1')['cidade_id[]'][j];

								if( ckB.value == val ){

									ckB.checked = !ckB.checked;
									if(ckB.checked == true){
										document.getElementById( 'cidade_id_' + ckB.value ).className = 'selected';
									} else {
										document.getElementById( 'cidade_id_' + ckB.value ).className = '';
									}
								}

							}

					}, true);

					liBot.addEventListener( 'click',
						function (){

							ident = idBot;

							val = '0' + ident.replace( 'cidade_id_', '' );

							cont = document.getElementById('formBusca1')['cidade_id[]'].length;

							for( var j=0; j < cont; j++){

								ckB = document.getElementById('formBusca1')['cidade_id[]'][j];

								if( ckB.value == val ){

									ckB.checked = !ckB.checked;

									if(ckB.checked == true){
										document.getElementById( 'cidade_id_' + ckB.value ).className = 'selected';
									} else {
										document.getElementById( 'cidade_id_' + ckB.value ).className = '';
									}
								}

							}

					}, true);
				}

				if(window.attachEvent){

					liTop.attachEvent( 'onclick',
						function (){

							ident = idTop;

							val = ident.replace( 'cidade_id_0', '' );

							cont = document.getElementById('formBusca1')['cidade_id[]'].length;

							for( var j=0; j < cont; j++){

								ckB = document.getElementById('formBusca1')['cidade_id[]'][j];

								if( ckB.value == val ){

									ckB.checked = !ckB.checked;

									if(ckB.checked == true){
										document.getElementById( 'cidade_id_' + ckB.value ).className = 'selected';
									} else {
										document.getElementById( 'cidade_id_' + ckB.value ).className = '';
									}
								}

							}

					}, true);

					liBot.attachEvent( 'onclick',
						function (){

							ident = idBot;
							val = '0' + ident.replace( 'cidade_id_', '' );

						cont = document.getElementById('formBusca1')['cidade_id[]'].length;
						for( var j=0; j < cont; j++){

							ckB = document.getElementById('formBusca1')['cidade_id[]'][j];

							if( ckB.value == val ){
								ckB.checked = !ckB.checked;
							if(ckB.checked == true){
								document.getElementById( 'cidade_id_' + ckB.value ).className = 'selected';
							} else {
								document.getElementById( 'cidade_id_' + ckB.value ).className = '';
							}
						}
					}
				}, true);
			}
		}
	}
}



function KeyPressAscCode(objEvent,param) {
        var Code;

        if (navigator.appName == 'Microsoft Internet Explorer') {
                Code = event.keyCode;
                var shift = false;
                if( Code == 16 ){
                        shift = true;
                }
        }
        else if(navigator.appName == 'Netscape'){
                Code = objEvent.keyCode;
                shift = objEvent.shiftKey;
        }

}
