/* alterar o valor abaixo para configurar a largura da página*/
var largura = "972px";
var url = document.location.pathname;
function url_decode(str) {
    var n, strCode, strDecode = "";

    for (n = 0; n < str.length; n++) {
            if (str.charAt(n) == "%") {
                    strCode = str.charAt(n + 1) + str.charAt(n + 2);
                    strDecode += String.fromCharCode(parseInt(strCode, 16));
                    n += 2;
            } else if (str.charAt(n) == "+") {
                    strCode = str.charAt(n);
                    strDecode += " ";
            } else {
                    strDecode += str.charAt(n);
            }
    }
    return strDecode;
}

function mycarousel_initCallback(carousel)
{
	// Disable autoscrolling if the user clicks the prev or next button.
	carousel.buttonNext.bind('click', function() {
		carousel.startAuto(0);
	});

	carousel.buttonPrev.bind('click', function() {
		carousel.startAuto(0);
	});

	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
};

function cleanLastSearch(){
	var retorno;

	$.ajax({
		url: "/home2009/funcoesLocais.php",
		type: "POST",
		async: false,
		data: "action=lastSearch",
		dataType: "txt",
		success: function(){
			$("#spanLastSearch").hide();
		}
	});

}

$(document).ready(function(){ 
	if(window.location.hash == "#anunciar"){
		$(".nome").focus();		
	}

	$(".estados, .uf").val("");
	
	$("#head").css("width",largura);
	
	$("#wrapper").css("width",largura);
	
	$(".telefone").mask("99-9999-9999");
	
	$("#textSearchVag, #objetivo").autocomplete(url, {
	        width: 'auto',
	        minChars: 1,		
	        matchSubset: 0,       
	        autoFill:true,
	        extraParams:{
	    		State:'suggestCargos',
    			type:'vag'    	
	    	}
     });
	
	$("#textSearchResumes, #objetivoVag").autocomplete(url, {
        width: 'auto',
        minChars: 1,		
        matchSubset: 0,   
        autoFill:true,
        extraParams:{
			State:'suggestCargos',
    		type:'cur'    	
    	}
	});
	
	$("form").submit(function(){
		if($(".ac_results:visible").length){
			$(".ac_over").click()
			return false
		}
		
	})
	
	$(".estados").change(function(){
		
		var cidadesSelect = ($(this).nextAll("select").length == 0?$(this).parent().parent().find("select.cidades"):$(this).nextAll("select"));
		var cidades = cidadesSelect.empty().attr("disabled",false);

		$.ajax({
			url: url,
			type: "POST",
			data: "State=cidades&id="+$(this).val(),
			dataType: "text",
			success: function(retorno) {
				retorno = url_decode(retorno);
				elemento = document.getElementById(cidades.attr("id"));
				elemento.length = 0;
				elemento.options[0] = new Option("Carregando...", 0, false, false);
				var v = retorno.split(';');
				for(i=0; i < v.length; i++){
					aux = v[i].split('|');
					elemento[i] = new Option(aux[1], aux[0], false, false);
				}
			}
		});
	})
	
	$('.btndicas').click(function(){
	    $(this).parent().find('.dica').toggle();
	    return false;
	});
	
	$('.dica .iconFechar').click(function(){
	    $(this).parents('.dica:first').hide();
	    return false;
	});	
	
	$(".vaga-info a").hover(function() {
		$(this).nextAll("em").css({"display": "block"});
		
		if ($.browser.msie) {
			if($.browser.version<7) {
				$("select").css({"visibility": "hidden"});
			}
		}
		
	}, function() {
		$(this).nextAll("em").css({"display": "none"});
		
		if ($.browser.msie) {
			if($.browser.version<7) {
				$("select").css({"visibility": "visible"});
			}
		}
	});
	
});

function formInclusao(plano){
    if( plano == 'Ope' ){
        document.getElementById('plano_id_inc').value='7';
        document.getElementById('perfil_id_inc').value='9';
        document.getElementById('ppd_id_inc').value='0';
    }
    else if( plano == 'Ppd' ){
        document.getElementById('plano_id_inc').value='1';
        document.getElementById('perfil_id_inc').value='1';
        document.getElementById('ppd_id_inc').value='1';
    }
    else if( plano == 'Est' ){
        document.getElementById('plano_id_inc').value='2';
        document.getElementById('perfil_id_inc').value='3';
        document.getElementById('ppd_id_inc').value='0';
    }
    else{
        document.getElementById('plano_id_inc').value='1';
        document.getElementById('perfil_id_inc').value='1';
        document.getElementById('ppd_id_inc').value='0';
    }
}
