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) {
	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=700;
		altDiv=410;
	}
	else if (i.toLowerCase()=='emailold'){
		_iframe=true;
		largDiv=320;
		altDiv=85;
	}
	else if (i.toLowerCase()=='login'){
		_iframe=true;
		largDiv=310;
		altDiv=140;
	}
	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 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.page');
	}else if (i.toLowerCase()=='logout'){
		window.open('/jobs/pt_br/login.html?action=logout','_self');
		
	}else if (i.toLowerCase()=='cadastrese'){
		Cadastro();
	}			
	else if (i.toLowerCase()=='emailold'){
		Esqueci();
	}
	else {
		n_abreModal(i);
	}
}



function Logout(){
	n_abreModal('logout','/jobs/pt_br/login.html?action=logout');
}
function Cadastro(){
	n_abreModal('cadastrese','/jobs/pt_br/skin2.include.modal.cadastrese.page');
}
function CadastroRedir(e){
	n_abreModal('cadastrese','/jobs/pt_br/skin2.include.modal.cadastrese.page?redir='+e);
}
function LoginRedir(e){
	n_abreModal('login','/jobs/pt_br/skin2.include.modal.login.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);//não funciona no Window
	}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.html?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.html?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(){
	$('#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("/jobs/pt_br/login3.html",post_str, function(data){
		if(data.length >0) {
			$('#DIVBOXLOGIN').html(data);
			$('#DIVBOXLOGIN').show(100);
		}else{
			$('#DIVBOXLOGIN').hide(200);
		}
	});
	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);
}