



var j = 9;
var m = 0;
var setado = 0;
var ativado = 0;
var div_sombra = 'sombra';
if(navigator.userAgent.search(/msie/i)!= -1) {
	var browser = "ie";
} else {
	var browser = "other";
} 
loadLiLink = function(page){

	$Aja("Pages/"+page+"?","GET",null,"content_text","temas/Tema_Principal/ImgCss/loading2.gif",null);
}

loadAJAXLink = function(page){

	$Aja("ajax_portal/"+page+"?","GET",null,"content_text","temas/Tema_Principal/ImgCss/loading2.gif",null);
}

loadGrupLink = function(page){

	$Aja2("blocosgrup/"+page+"?","GET",null,"content_text","temas/Tema_Principal/ImgCss/loading2.gif",null);
}

loadCurrLink = function(page){

	$Aja("modulos/sgicurriculogeralservice/"+page+"?","GET",null,"content_text","temas/Tema_Principal/ImgCss/loading2.gif",null);
}

submitEnter = function(evento,form){

	var key=evento.keyCode || evento.which;
	if(key==13){ submitForm(4,form); }
}

loadLogin = function(type){

	if(type=='open'){
		$Nig("container_login",1);
	}
	else{
		$Nag("container_login",10);
	}
}

loadNotiLink = function(page){
	$Aja("Pages/Noticias/"+page+"?","GET",null,"Noti_div","temas/Tema_Principal/ImgCss/loading2.gif",null);
}

loadTema = function(type){

	if(type=='open'){
		$Nig("container_login",1);
	}
	else{
		$Nag("container_login",10);
	}
}



function ativadiv(div){

	/*if($Peg(div).style.display=='none' || $Peg(div).style.display==""){ $Nig(div,1); }
	else
	{ $Nag(div,10); }*/
	$Tog(div);
}

function submitFormNew(nome_tipo,form){

	if($Peg(nome_tipo).value.length>1){ eval("document."+form+"."+nome_tipo+".value='on';document."+form+".submit();"); }	
	
}

function submitForm(tipo,form){
	if(tipo==1){ eval("document."+form+".bottao_novo_form.value='on';document."+form+".submit();"); }
	if(tipo==2){ eval("document."+form+".bottao_pesquisa_form.value='on';document."+form+".submit();"); }
	if(tipo==4){ eval("document."+form+".bottao_pesquisa_parametro.value='on';document."+form+".submit();"); }
	if(tipo==6){ eval("document."+form+".bottao_relatorio_doc_form.value='on';document."+form+".submit();"); }
}

function submitFormGenerico(tipo,form){

	if(tipo==1){ eval("$Peg('bottao_apl').value='bottao_novo_form';document."+form+".submit();"); }
	if(tipo==2){ eval("$Peg('bottao_apl').value='bottao_pesquisa_form';document."+form+".submit();"); }
	if(tipo==4){ eval("$Peg('bottao_apl').value='bottao_pesquisa_parametro';document."+form+".submit();"); }
}

function submitFormGeneric2(form_name,campo,valor){
	//alert(form_name);
	$Peg(campo).value = valor;
	//$Peg("bottao_seleciona_cliente").value="on";
	eval("document."+form_name+".submit();");
}

function escondeMenu(id)
{
	var obj = $Peg('menu_'+id);
	if(obj.style.display=="none"){
		obj.style.display="";
		$Peg('img_'+id).src = 'img/minus.gif';
	}else{
		obj.style.display="none";
		$Peg('img_'+id).src = 'img/plus.gif';
	}
}

function getScrollY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfY;
}

  function submitGetForm(event){ //o evento recebido eh onkeyup

	if (window.XMLHttpRequest){ 
		var key=event.keyCode || event.which;
	}else if (window.ActiveXObject){ 
		var key=window.event.keyCode || window.event.which;
	}
	
	if(key==13){
		$Aja('ajax_portal/ajaxlogin_portal?logi_login='+$Peg('login').value+'&logi_senha='+$Peg('senha').value,'GET',null,'sitc','img/loading2.gif','json');	
	}

}

 function hideWhitemenu(terminacao,img,imgname,path){
 	src   = $Peg(img).src;
	
 	
 	if($Peg('menu_bot_'+terminacao).style.display == "" || $Peg('menu_bot_'+terminacao).style.display == "block"){
 		 	hover = src.replace(".png","");
 			hover = hover+"_up.png";
			$Peg(img).src = hover;
 		
 	}else{  
 		 	hover = src.replace("_up","");
			$Peg(img).src = hover;
 	}
 	
 	
if($Peg('menu_list_'+terminacao).style.display == "" || $Peg('menu_list_'+terminacao).style.display == "block"){
 		$Peg('menu_list_'+terminacao).style.display = "none"; display = "none"}
 	else{
 		$Peg('menu_list_'+terminacao).style.display = "block";display = "block"}
 		
if($Peg('menu_bot_'+terminacao).style.display == "" || $Peg('menu_bot_'+terminacao).style.display == "block")
 		$Peg('menu_bot_'+terminacao).style.display = "none";
 	else
 		$Peg('menu_bot_'+terminacao).style.display = "block";

 		
 		
 		$Aja(path+'/ajax_portal/ajax_controle_menu?imgid=menu_'+terminacao+'&imghover='+hover+'&idmenu=menu_bot_'+terminacao+'&idmenu2=menu_list_'+terminacao+'&tipodisplay='+display,"GET",null,"divlogar_login",null);
}
//FUNCAO REPETIDA
function toogleMenu(){
	
	if($Peg('left').style.display=="inline" || $Peg('left').style.display.length==0){

		$Aja("ajax_modulos/AjaxModuloSetaEstadoLeft?display=none","GET",null,null,null,"json");
		$Ine("toogle_left","[+] abrir abas");
		$Peg('left').style.display = "none";
		$Peg('left').style.width = 0+"%";
		$Peg('content').style.width = 100+"%";
	}else{

		$Aja("ajax_modulos/AjaxModuloSetaEstadoLeft?display=inline","GET",null,null,null,"json");
		$Ine("toogle_left","[-] fechar abas");
		$Peg('left').style.width = 25+"%";
		$Peg('content').style.width = 74.5+"%";
		$Peg('left').style.display = "inline"; 
		
	}
}

function rollOverUp(x,b,c,par)
{	
	x-=6;
	b-=10;
	c-=10;
	$Peg('corpo').style.height='40px';
	$Peg('table').style.top = b+"px";
	$Peg('line').style.top = c+"px";
	$Peg('cabecalho').style.top = x+"px";
	$Peg('copyright').style.display='none';
	$Peg('termos_privacidade').style.display='none';

	if(x<=100){
	$Peg('corpo_novo').style.display='block';	
	$Aja2(par,'GET',null,'corpo_novo','img/loading4.gif',null);	
	return false;
	}
	
	t = setTimeout("rollOverUp('"+x+"','"+b+"','"+c+"','"+par+"')",1);
}

function rollOverDown(x,b,c)
{	
	x=parseFloat(10.3)+parseFloat(x);
	b=parseFloat(15.32)+parseFloat(b);
	c=parseFloat(22.1)+parseFloat(c);
	
	$Peg('corpo').style.height='450px';
	$Peg('table').style.top = b+"px";
	$Peg('line').style.top = c+"px";
	$Peg('cabecalho').style.top = x+"px";
	$Peg('copyright').style.display='block';
	$Peg('termos_privacidade').style.display='block';

	if(x>=195){
	$Peg('corpo_novo').style.display='none';	
	return false;
	}
	
	t = setTimeout("rollOverDown('"+x+"','"+b+"','"+c+"')",1);
}


function deactive(id,resposta){
		at=$Peg(id).getAttribute("onclick");
		
		if(resposta=="send")
			par = "&atributo="+at;
		else
			par="";
			
			$Aja2("ajax_portal/ajax_setaAtributo?id=gray_btn2&resposta="+resposta+""+par,"GET",null,null,null,"json");
}
function rolldown(id,x,spanid,par){
	
	x=x+30;
	$Peg(id).style.height=x+"px";
		
	if(x>=610){
		$Peg(spanid).style.display="none";
		$Peg(spanid+"_up").style.display="inline";
		$Peg(id).style.display="block";
		
		if(par!=""){
			$Aja2(par,"GET",null,id,"img/loading4.gif",null);
		}	
		return false;
	}
	
	setTimeout("rolldown('"+id+"',"+x+",'"+spanid+"','"+par+"')",1);	
	//$Aja(par,"GET",id,null,null,null);
}

function rollup(id,x,spanid){
	
	x=x-50;
	$Peg(id).innerHTML="";
	$Peg(id).style.height=x+"px";
		
	if(x<=0){
		$Peg(spanid).style.display="inline";
		$Peg(spanid+"_up").style.display="none";
		return false;
	}
	
	setTimeout("rollup('"+id+"',"+x+",'"+spanid+"')",1);	
	//$Aja(par,"GET",id,null,null,null);
}

  function setStatus(id,diff)
  {		if($Peg(id).style)
  		{
  			$Peg(id).style.height = diff+getHeight()+'px';
  			$Peg(id).style.Width =  getWidth()+'px';
  		}
  		
  	
  	
  }
  
    function getWidth()  
  {  

       return window.innerWidth ? window.innerWidth : /* For non-IE */  
              document.documentElement ? document.documentElement.clientWidth : /* IE 6+ (Standards Compilant Mode) */  
              document.body ? document.body.clientWidth : /* IE 4 Compatible */  
              window.screen.width; /* Others (It is not browser window size, but screen size) */  
  }  
   
  function getHeight()  
  {  

       return window.innerHeight ? window.innerHeight : /* For non-IE */  
              document.documentElement ? document.documentElement.clientHeight : /* IE 6+ (Standards Compilant Mode) */  
              document.body ? document.body.clientHeight : /* IE 4 Compatible */  
              window.screen.height; /* Others (It is not browser window size, but screen size) */  
  } 
  
  	function acompanhaTela2(div)
	{		
		if($Peg(div).style)
		{
			$Peg(div).style.top = getScrollY()+296+"px";
		}
		
	}
		
function buscaCEP2(id,div_uf,div_cidade,div_bairro,div_rua){

	var cep = $Peg(id).value;

	if(cep.length == 8){ $Aja('ajax_portal/AjaxBuscaCep?div_uf='+div_uf+'&div_cidade='+div_cidade+'&div_bairro='+div_bairro+'&div_rua='+div_rua+'&cep='+cep,'GET',null,null,null,'json'); }
	
	else{
		alert("CEP invalido");
	}
}

function buscaCEPKey2(id){

	var cep = $Peg(id).value;

	if(cep.length == 8){ $Aja('ajax_comercial/AjaxComercialBuscaCep?cep='+cep,'GET',null,null,null,'json'); }
}

/*function load(par,par2,par3,par4,par5,par6){
	par+="&div=divlogar_login"
	$Aja2(par,par2,par3,par4,par5,par6);
	ativadiv('sombra');
	ativadiv('divlogar_login');
	
}
*/
numberValue = 0;
function sgi_carrega_div(par,par2,par3,par4,par5,par6){

	if(document.getElementById(div_sombra).style.display=="none" || document.getElementById(div_sombra).style.display==""){

		document.getElementById(div_sombra).style.display="block";
		document.getElementById(par4).style.display="block";

		if(par!="undefined"){
			par+="&div="+par4
			$Aja2(par,par2,par3,par4,par5,par6);
		}

	}
	else{

		document.getElementById(div_sombra).style.display="none";
		document.getElementById('divlogar_login').style.display="none";
	}
}
function unload(){
	ativadiv(div_sombra);
	ativadiv('divlogar_login');
}


  function mascara(data_obj){
				
  	      var mydata = ""
              mydata = mydata + data_obj.value;

              if (mydata.length == 2){
                  mydata = mydata + ".";
                  data_obj.value = mydata;
              }
              if (mydata.length == 6){
                  mydata = mydata + ".";
                  data_obj.value = mydata;
              }
              if (mydata.length == 10){

                  mydata = mydata + "/";
                  data_obj.value = mydata;
              }
              if (mydata.length == 15){

                  mydata = mydata + "-";
                  data_obj.value = mydata;
              }              
 } 
 function esconde(id){

 		$Peg(id).style.display="none";

 }
 
 function acompanhaTela(div)
{
	if(divAtiva != "")
	{
		$Peg(div).style.top = getScrollY()+25+"px";
		timefolow = setTimeout("acompanhaTela(div)",10);
	}
}

function spriteOver(id,max,dist,none){
if(browser != "ie")	{
	if($Peg(id).style){
		$Peg(id).style.opacity = "0."+j;
		$Peg(id).style.filter = 'alpha(opacity='+j*10+')';
	}
	j--;
	
	if(j==max){
		if(none =='inner'){
			if($Peg(id).style){
				$Peg(id).style.opacity = "0";
			}
			$Peg(id).innerHTML='';
		}else if(none =='display'){
			if($Peg(id).style){
				$Peg(id).style.opacity = "0";
			}	
			$Peg(id).style.display='none';
		}
		j=9;
		clearTimeout(ft);
		return false
	}
	
	var ft = setTimeout("spriteOver('"+id+"',"+max+","+dist+",'"+none+"')",dist);
}	
}
function spriteOut(id,max,dist){
if(browser != "ie")	{
	if($Peg(id).style){
		$Peg(id).style.opacity = "0."+m;
	}
	m++;
	
	if(m==max){
		
		m=0;
		if($Peg(id).style){
			$Peg(id).style.opacity = 1;
		}
		clearTimeout(fto);
		return false
	}
	
	var fto = setTimeout("spriteOut('"+id+"',"+max+","+dist+")",dist);
}	
}

function sgi_chamada_especifica(id,aja){
	
	if(setado==0){
		if($Peg(id).style){	
			$Peg(id).style.opacity = "0."+j;
			$Peg(id).style.filter = 'alpha(opacity='+j*10+')';
		}	
		
		j--;	
		if(j<=0){
			setado = 1 ;
		}
	}else if(setado==1){
		
		if(aja=='comercial'){
			$Aja2('ajax_portal/ajax_solicita_proposta_comercial?','GET',null,'logo_div');
		}else if(aja =='vagas'){
			$Aja2('ajax_portal/ajax_vaga?','GET',null,'logo_div');
		}else if(aja !=undefined){
			$Aja2(aja,'GET',null,'logo_div');
		}
		setado = 2;
	}else if(setado==2){
		if($Peg(id).style){	
			$Peg(id).style.opacity = "0."+m;
			$Peg(id).style.filter = 'alpha(opacity='+m*10+')';
		}
		m++;	
		if(m==9){
			if($Peg(id).style){	
				$Peg(id).style.opacity = 1 ;
				$Peg(id).style.filter = 'alpha(opacity=100)';
			}	
			clearTimeout(chamadaTimeout);
			return false 
		}		
	}
	
	chamadaTimeout = setTimeout("sgi_chamada_especifica('"+id+"','"+aja+"')",50);
}
function marcar(id,color){
	$Peg(id).style.borderColor = $Peg(id).style.borderColor.search('orange') ? 'orange' : color ;
	param_checked = param_checked==1 ? 0 : 1;
}

/*PARAMETROS :
	par1 = header 
	par2 = telacheia
	par3 = retornar tela
*/	
botao_tela = 'retornar';

function sgi_direciona_visao(par1,par2,par3){
	//alert(botao_tela);
	if(botao_tela=='fullscreen'){
		botao_tela = 'retornar';
		$Aja2('../../ajax_portal/ajax_DisplayHeader?botao_tela='+botao_tela+'&botao_display=fullscreen','GET','','janela_ajax',null,'json');
		//window.location='index';
		
	}else if(botao_tela=='retornar'){
		botao_tela = 'fullscreen';
		$Aja2('../../ajax_portal/ajax_DisplayHeader?botao_tela='+botao_tela+'&botao_display=retornar','GET','','janela_ajax',null,'json');
		//window.location='index';
		
	}
	
}


function sgi_direciona_visao2(botao_tela2){
	
	if(botao_tela2=='fullscreen'){
		botao_tela = 'retornar';
		$Aja2('../../ajax_portal/ajax_DisplayHeader?botao_tela='+botao_tela2+'&botao_display=fullscreen','GET','','janela_ajax',null,'json');
		//window.location='index';
		
	}else if(botao_tela2=='retornar'){
		botao_tela = 'fullscreen';
		$Aja2('../../ajax_portal/ajax_DisplayHeader?botao_tela='+botao_tela2+'&botao_display=retornar','GET','','janela_ajax',null,'json');		
	}
}
function sgi_fade(id,dist){

	/*if(ativado==0){

		if($Peg(id).style){
			
			$Peg(id).style.MozOpacity = "0."+m;}
		m++;
		if(m==9){
			m=0;
			if($Peg(id).style){
				$Peg(id).style.MozOpacity = 1;}
			return 
		}
	}
	
	setTimeout("sgi_fade('"+id+"',"+dist+")",dist);
	*/
}
	
function AtivaStatusLogin(status,cor,status_label,destino,login){
  	

    $Aja2(""+destino+"/ajax_portal/AjaxInterfaceUsuarioStatusLogin?logi_codlogin="+login+"&logi_ativol="+status+"&cor="+cor+"&status_label="+status_label,"GET",null,null,null,"json");


    
}

var SgiSetCamposHidden = function(obj){
	
	var array = $(obj).attr('title').split(';'); // 0 => numero caixa , 1 => localidade
	
	$('#acao_numero_caixa').val(array[0]);	
	$('#acao_cod_localidade').val(array[1]);

}
SgiBuscaDadosSelectCampos = function(p,obj,callback){
	p +='?caixa_busca='+obj.value
	$.get(p,function(data){
		if(data){
			SgiBuildSelectList(obj,data,callback);
		}
	});
}

var ativo_select = 0 ; 
var SgiBuildSelectList = function(obj,data,callback){
	
	var top = $(obj).position().top +25;
	
	if($('#SgiDyContentDivSelect').length <= 0 ){
		$(document.body).append('<div id="SgiDyContentDivSelect"></div>');
	}
	
	if(top != $('#SgiDyContentDivSelect').css('top')){
		$('#SgiDyContentDivSelect').css('display','block');
		$('#SgiDyContentDivSelect').css({
			top  : $(obj).position().top +28, 
			left : $(obj).position().left,
		});
	}
	
	$('#SgiDyContentDivSelect').mouseenter(function(){
		ativo_select = 1 ;
	});	
	
	$('#SgiDyContentDivSelect').mouseleave(function(){
		$(this).css('display','none');
		ativo_select = 0 ;
	});

	$(obj).blur(function(){
		if(!ativo_select){
			$('#SgiDyContentDivSelect').css('display','none');
			ativo_select = 0 ;
		}
	});
	
	$('#SgiDyContentDivSelect').html(data);
	
	$('#SgiDyContentDivSelect li').click(function(){
		
		$(obj).val($(this).html().trim());
		$('#SgiDyContentDivSelect').css('display','none');
		ativo_select = 0 ;
		
		if(callback)
		callback(this);
	});
}


