scrollTop			= 0; //rolagem to topo
modalOpen			= ""; //modal open name
end_opacity 		= 0; //end opacity, 25 = 25%, 50 = 50%, 100 = 100%, etc.
increase_opacity_by = 10; //how much to increase by each time the timeout ends
timeout 			= 50; //timeout in milliseconds, 0 = instant fade-out
winbackground 		= document.getElementById('thewindowcontent');

cur_opacity = 100;
var timer = null;
function hide_thewindowcontent() {
	winbackground 		= document.getElementById('thewindowcontent');
	
	if(timeout > 0) {
		cur_opacity = 100;
	
		winbackground.style.opacity = cur_opacity / 100;
		winbackground.style.filter 	= "alpha(opacity=" + cur_opacity + ")";
		timer = setTimeout("hide_increase_opacity()",timeout);
	}else {
		winbackground.style.opacity = end_opacity / 100;
		winbackground.style.filter 	= "alpha(opacity=" + end_opacity + ")";
	}
}
function hide_increase_opacity() {
	cur_opacity -= increase_opacity_by;

	winbackground.style.opacity = cur_opacity / 100;
	winbackground.style.filter = "alpha(opacity=" + cur_opacity + ")";
	
	if(cur_opacity >= end_opacity) {
		timer = setTimeout("hide_increase_opacity()",timeout);
	}else {
		winbackground.style.display = 'none';
		document.getElementById(modalOpen).style.top = scrollTop +"px";
	}
}



function hideWindow() {
	winbackground.style.display = 'none';
}

/* Janela Modal */
/* ------------ 
i = ID da janela modal
colocar o iframe <iframe src="modal_grade.htm" frameborder="0" id="modal_grade"></iframe>
------------ */	
function n_abreModal(i) {
	$('#FRAME_MODAL_CLOSE_BUTTON').hide();
	var largDiv = 0;
	var altDiv = 0;
	var _iframe=false;
	var _url = ""
	if (n_abreModal.arguments.length>1){
		_url = n_abreModal.arguments[1];
	}
	if (i.toLowerCase()=='cadastrese'){
		_iframe=true;
		largDiv=790;
		altDiv=410;
		$('#FRAME_MODAL_CLOSE_BUTTON').show();
		
	}else if (i.toLowerCase()=='emailold'){
		_iframe=true;
		largDiv=320;
		altDiv=85;
	}else if (i.toLowerCase()=='login'){
		_iframe=true;
		largDiv=310;
		altDiv=160;
	}else if (i.toLowerCase()=='logout'){
		_iframe=true;
		largDiv=310;
		altDiv=140;
	}else if (i.toLowerCase()=='novocadastro'){
		_iframe=true;
		largDiv=480;
		altDiv=220;
	}else {
		_iframe=false;
		document.getElementById(i).style.display="block";
		largDiv = Math.floor(document.getElementById(i).offsetWidth);
		altDiv = Math.floor(document.getElementById(i).offsetHeight);
	}
	
	if (_iframe && _url!=''){
		i = "modal_container"	
		document.getElementById("modal_iframe").src=_url;
		document.getElementById(i).style.width=largDiv+"px";
		document.getElementById(i).style.height=altDiv+"px";
		document.getElementById(i).style.display="block";
	}

	var altTela 	=	Math.floor(document.body.offsetHeight);
	var largTela 	=  	Math.floor(document.body.offsetWidth);
	document.getElementById(i).style.left=((largTela/2)-(largDiv/2))+"px";
	document.getElementById("modalGrade").style.display="block";
	document.getElementById("modalGrade").style.height=altTela+"px";
	document.getElementById("modalGrade").style.width=largTela+"px";

	var vScrollY = 0;
	if (document.all) {
		if (!document.documentElement.scrollTop){
			vScrollY = document.body.scrollTop;
		}else{
			vScrollY = document.documentElement.scrollTop;
		}
	}else{
		vScrollY = window.pageYOffset;
	}
	
	
	//alert(vScrollY);
	document.getElementById(i).style.top	= ((screen.availHeight/2) + vScrollY - (altDiv/2)) +"px";
	//document.getElementById(i).style.top	= ((screen.availHeight/2)  			  - (altDiv/2))+"px";

	
	
	if (!_iframe){					   
		for (j=0;j<document.getElementById(i).getElementsByTagName('input').length;j++) {            
			if (document.getElementById(i).getElementsByTagName('input')[j].type == 'text') {
				document.getElementById(i).getElementsByTagName('input')[j].focus();
				break;
			}
		}	   
	}
	
	modalOpen	= i;
	scrollTop 	= ((screen.availHeight/2) - (altDiv/2));
	hide_thewindowcontent();
}


function fechaModal(i){
	document.getElementById("modalGrade").style.display="none";
	document.getElementById(i).style.display="none";
	winbackground.style.display = '';
}

function if_fechaModal(i){
	document.getElementById("modal_iframe").src=document.getElementById("_blankPage").value;
	document.getElementById("modalGrade").style.display="none";
	document.getElementById("modal_container").style.display="none";
	document.getElementById("thewindowcontent").style.display="";
	document.getElementById("thewindowcontent").style.opacity=100;
	document.getElementById("thewindowcontent").style.filter="";	
}

function AbreModalRegiao(url){
	document.getElementById("_if_localLogin").src=document.getElementById("_blankPage").value;
	if (document.getElementById("divLocalizacao").style.display=="none"){
		document.getElementById("_if_localLogin").src=document.getElementById("_redirURL").value+"?"+url;
		fechaDivs();
		document.getElementById("divLocalizacao").style.display="";
		try{
			document.getElementById("im_local").src="/images/bar-fechar.gif";
		}
		catch(e){
		}				
	}else {
		document.getElementById("divLocalizacao").style.display="none";
		try{
			document.getElementById("im_local").src="/images/bar-setinha.gif";
		}catch(e){
		}				
	}			
}
function reloadModalRegiao(url){
	document.getElementById("_if_localLogin").src=document.getElementById("_blankPage").value;
	document.getElementById("_if_localLogin").src=document.getElementById("_redirURL").value+"?"+url;
	document.getElementById("divLocalizacao").style.display="";
		
}
function AbreLogin(){
	fechaDivs();
	document.getElementById("ctl00_header_divLogin").style.display="";
	try{
		document.getElementById("ctl00_header_txtLoginH").focus();
	}catch(e){}
	
}
function fechaDivs(){
	document.getElementById("divLocalizacao").style.display="none";
}

function abreModal(i){
	if (i.toLowerCase()=='login'){
		n_abreModal('login','/jobs/pt_br/skin2.include.modal.login.user.page');
	}else if (i.toLowerCase()=='logout'){
		window.open('/jobs/pt_br/logout.do','_self');
		
	}else if (i.toLowerCase()=='cadastrese'){
		Cadastro();
	}			
	else if (i.toLowerCase()=='emailold'){
		Esqueci();
	}
	else {
		n_abreModal(i);
	}
}



function Logout(){
	abreModal('logout');
}
function Cadastro(){
	n_abreModal('cadastrese','/jobs/pt_br/register.do');
}
function CadastroRedir(e){
	n_abreModal('cadastrese','/jobs/pt_br/register.do?redir='+e);
}
function LoginRedirUser(e){
	n_abreModal('login','/jobs/pt_br/skin2.include.modal.login.user.page?redir='+e);
}
function LoginRedirEmp(e){
	n_abreModal('login','/jobs/pt_br/skin2.include.modal.login.emp.page?redir='+e);
}
function Esqueci(e){
	if(e=='undefined')
		e='';
	n_abreModal('emailold','/jobs/pt_br/skin2.include.modal.esqueci.senha.page?email='+e);
}
function AbreModalEmail() {
	fechaModal('login');
	abreModal('emailold');
}
function AbreModalLogin() {
	fechaModal('cadastrese');
	abreModal('login');
}
function AbreModalCadastro() {
	fechaModal('login');
	abreModal('cadastrese');
}
function abreModalLog(i,url){
	n_abreModal(i,'/jobs/pt_br/skin2.include.modal.msg.novo.cadastro.page');
}
function ValidaLoginHead()
{
	var MsgErro;
	MsgErro="";
	if (document.getElementById('ctl00_header_txtLoginH').value.indexOf("<")>-1 || document.getElementById('ctl00_header_txtLoginH').value.indexOf(">")>-1 || document.getElementById('ctl00_header_txtSenhaLoginH').value.indexOf("<")>-1 || document.getElementById('ctl00_header_txtSenhaLoginH').value.indexOf(">")>-1){
		alert("Conteúdo inválido. Código HTML não é permitido nesse campo ('<', '>')");
		document.getElementById('ctl00_header_txtLoginH').focus();
		return false;
	}
	if (document.getElementById("ctl00_header_txtLoginH").value == ""){
		MsgErro="- Login não informado";
		alert(MsgErro);
		document.getElementById("ctl00_header_txtLoginH").focus();
		return false;
	}
	else
	{
		if (document.getElementById("ctl00_header_txtSenhaLoginH").value == ""){
			MsgErro="- Senha não informada";
			alert(MsgErro);
			document.getElementById("ctl00_header_txtSenhaLoginH").focus();
			return false;
		}
	}
	return true;
}
function URLencode(sStr){
	return escape(sStr).replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27').replace(/\//g,'%2F');
}

function myEscape(str){
	if($.browser.safari){
		if(jQuery.browser.version.substr(0,1)=="5"){
			str 	= encodeURIComponent(str);
		}else{
			str 	= escape(str);
		}
	}else if($.browser.msie){
		str 	= escape(str);
	}else if($.browser.mozilla){
		if(jQuery.browser.version.substr(0,3)=="1.8"){
			str 	= escape(str);
		}else{
			str 	= encodeURIComponent(str);
		}
		//str 	= $('<div/>').text(str).html();//funciona MAC firefox, não funciona no netscape
		//str 	= encodeURIComponent(str);//funciona MAC firefox, não funciona no netscape
		//str 	= escape(str);//Não funciona no MAC firefox, funciona no netscape 
		//str 	= encodeURI(str);//funciona MAC firefox, não funciona no netscape 
	}else if($.browser.opera){
		str 	= escape(str);
	}else{
		str 	= escape(str);
	}
	return str;
}

function addHotListJob(idjob){
	var post_str="/jobs/pt_br/hotlist_add.do?idjob="+idjob;
	$.post(post_str,{}, function(data){
		if(data.length >0) {
			if(data.indexOf("1")!=-1){
				$('#DIV_HOTLIST_NOT_'+idjob).hide();
				$('#DIV_HOTLIST_ADD_'+idjob).show();
			}else{
				$('#DIV_HOTLIST_ADD_'+idjob).hide();
				$('#DIV_HOTLIST_NOT_'+idjob).show();
			}
		}
	});
	return false;
}
function addHotListCV(idcv){
	var post_str="/jobs/pt_br/hotlist_add.do?idcv="+idcv;
	$.post(post_str,{}, function(data){
		if(data.length >0) {
			if(data.indexOf("1")!=-1){
				$('#DIV_HOTLIST_NOT_'+idcv).hide();
				$('#DIV_HOTLIST_ADD_'+idcv).show();
			}else{
				$('#DIV_HOTLIST_ADD_'+idcv).hide();
				$('#DIV_HOTLIST_NOT_'+idcv).show();
			}
		}
	});
	return false;
}


function onSubmitCheckLogin(action){
	$('#DIVBOXLOGIN').hide(200);
	var post_str="";
	var formObj = eval('document.form_box_login');
	for (i=0; i<formObj.elements.length; i++) {  
        var fieldValue 	=  formObj.elements[i].value;  
        var fieldName 	=  formObj.elements[i].name; 
        post_str 		+= "&"+fieldName+"="+myEscape(fieldValue);
    }
	$.post(action,post_str, function(data){
		if(data.length >0) {
			$('#DIVBOXLOGIN').html(data);
			$('#DIVBOXLOGIN').show(100);
		}else{
			$('#DIVBOXLOGIN').hide(200);
		}
	});
	return false;
}
function ValidaLoginModal(action){
	var MsgErro;
	MsgErro="";            
	document.getElementById("span_loginmodal").style.display="none";   
	document.getElementById("span_senhaloginmodal").style.display="none";

	if (document.getElementById('email').value.indexOf("<")>-1 || document.getElementById('email').value.indexOf(">")>-1 || document.getElementById('password').value.indexOf("<")>-1 || document.getElementById('password').value.indexOf(">")>-1){
		alert("Conteúdo inválido. Código HTML não é permitido nesse campo ('<', '>')");
		document.getElementById('email').focus();
		return false;
	}



	if (trim(document.getElementById("email").value)==""){
		if (MsgErro!=""){
			MsgErro += "\n"
		}                
		MsgErro += " - Login não informado";
		document.getElementById("span_loginmodal").style.display="";
	}
	else {
		var re = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
		if (!re.test(trim(document.getElementById("email").value))){
			if (MsgErro!="")
			{
				MsgErro += "\n"
			}
			MsgErro += " - Login inválido";
			document.getElementById("span_loginmodal").style.display="";
		}
	}

	if (trim(document.getElementById("password").value) == ""){
		if (MsgErro!="")
		{
			MsgErro += "\n"
		}
		MsgErro+="- Senha não informada";
		document.getElementById("span_senhaloginmodal").style.display="";
	}

	if (MsgErro!=""){
		alert(MsgErro);
		return false;
	}else{
		onSubmitCheckLogin(action);
		return false;
	}
}
var phone_field_length=0;
function TabNext(obj,evento,len,next_field) {
	if (evento == "down") {
	phone_field_length=obj.value.length;
	}else if (evento == "up") {
		if (obj.value.length != phone_field_length) {
			phone_field_length=obj.value.length;
			if (phone_field_length == len) {
				next_field.focus();
			}
		}
	}
}

function Trim(_sValue){
    return _sValue.replace(/^\s*/, "").replace(/\s*$/, "");
}

function trim(_sValue){
    return Trim(_sValue);
}
function replaceAll(string, token, newtoken) {
	while (string.indexOf(token) != -1) {
 		string = string.replace(token, newtoken);
	}
	return string;
}





function lookupTopCV(top_search_kw) {
	if(Trim(top_search_kw).length <= 3) {
		$('#top_suggestions_cv').hide();
	} else {
		$.post("/jobs/pt_br/skin2.include.parameter.suggestion.page", {query: ""+Trim(top_search_kw)+"",limit:"6",callback:"fillTopCV"}, function(data){
			if(data.length >0) {
				$('#top_suggestions_cv').show();
				$('#top_autoSuggestionsList_cv').html(data);
			}else{
				$('#top_suggestions_cv').hide(500);
			}
		});
	}
}
function fillTopCV(thisValue) {
	if(thisValue!='undefined' && thisValue!=null){
		$('#top_search_kw_cv').val(thisValue);
		$('#top_suggestions_cv').hide(500);
	}
}
function lookupTopJob(top_search_kw) {
	if(Trim(top_search_kw).length <= 3) {
		$('#top_suggestions_job').hide();
	} else {
		$.post("/jobs/pt_br/skin2.include.parameter.suggestion.page", {query: ""+Trim(top_search_kw)+"",limit:"6",callback:"fillTopJob"}, function(data){
			if(data.length >0) {
				$('#top_suggestions_job').show();
				$('#top_autoSuggestionsList_job').html(data);
			}else{
				$('#top_suggestions_job').hide(500);
			}
		});
	}
}
function fillTopJob(thisValue) {
	if(thisValue!='undefined' && thisValue!=null){
		$('#top_search_kw_job').val(thisValue);
		$('#top_suggestions_job').hide(500);
	}
}



function mascaraCEP(campo,xEvent) {
	if(xEvent!=null){
	    var strCheck = '0123456789';
	    var key = '';
	    var whichCode = (window.Event) ? xEvent.which : xEvent.keyCode;
	    if (whichCode == undefined) 
		    whichCode = xEvent.keyCode;
	    
	    if (whichCode == 13 || whichCode == 8 || whichCode == 0 || whichCode == 37 || whichCode == 39 || whichCode == 38 || whichCode == 40){
		    //return true;
	    }else{
	    
		    key = String.fromCharCode(whichCode); // Valor para o código da Chave
		    if (strCheck.indexOf(key) == -1){
			    //return false; // Chave inválida 
		    }
	    }
	}
	vr = campo.value;
	vr = replaceAll(vr,'-', '');
	if (vr.length == 9){
		//return false;
	}
	if(vr.length>5){
		
		 campo.value = vr.substring(0,5) + "-" + vr.substring(5);
	}else{ 
		if (vr.length == 5){
			campo.value = vr + "-";
		}
	}
}
