try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}
function imprimir() {
	if (window.print){
		window.print();
	}else{
		alert("Para imprimir pressione Crtl+P.");
	}
}
function TrocaClasse(id, NomeDaClasse)
{
document.getElementById(id).className = NomeDaClasse;
}
function fecharID(cam) {
	var cam = document.getElementById(cam);
 	$j(cam).animate({ height: 'hide', opacity: 'hide' }, 'slow');
}
function abre_pagina(pagina, largura, altura, esquerda, linha, targetName ) {
var width = largura;
var height = altura;
var left = esquerda;
var top = linha;
var rolagem = '2';
if( targetName == null ){
	targetName = 'pagina';
}
window.open(pagina, targetName,'width='+width+' , height='+height+', top='+top+', left='+left+', scrollbars='+rolagem+',fullscreen=no');
}
function popup(cam, largura, altura){
  cam = document.getElementById(cam);
  e = e ? e : window.event;
  cam.style.left    = e.clientX+"px";
  cam.style.top     = e.clientY+"px";
  cam.style.height  = altura;
  cam.style.width   = largura;
  cam.style.display = 'block';
}
function atualiza_conteudo(){
    window.parent.conteudo.location="frm_conteudo.php";
}
//Aumentar e diminuir fonte
var tgs = new Array( 'div','td','tr', 'p', 'span');
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 2;
function ts( trgt,inc ) {
  if (!document.getElementById) return
  var d = document,cEl = null,sz = startSz,i,j,cTags;
  sz += inc;
  if ( sz < 0 ) sz = 0;
  if ( sz > 6 ) sz = 6;
  startSz = sz;
  if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];
  cEl.style.fontSize = szs[ sz ];
  for ( i = 0 ; i < tgs.length ; i++ ) {
   cTags = cEl.getElementsByTagName( tgs[ i ] );
   for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
  }
}
function UserLog( CodL, Cod, Tabela, urlPrincipal ){
  var url = urlPrincipal + "userlog.php?NumLog=" + CodL + "&cod=" + Cod + "&tabela=" + Tabela;
  xmlhttp.open("GET", url, true);
  xmlhttp.onreadystatechange=function() {
	if (xmlhttp.readyState==4){
		result = xmlhttp.responseText;
		if( result != "" ){
			document.getElementById("erro").style.display = 'block';
			document.getElementById("erro").innerHTML = result;
		}
	}
  }
  xmlhttp.send(null);
}
function ExibeConteudo( urlQuery, gotoID, idBotao, acao ){

	var $j = jQuery.noConflict();
	var url = urlQuery;
	var cam = document.getElementById(gotoID);
	var cam_idBotao = document.getElementById(idBotao);
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4){
			result = xmlhttp.responseText;
			//$j('#caixa_total').fadeTo(1000,0.4).css('display','block');
			if( acao==0){
				$j(cam_idBotao).attr("onclick","ExibeConteudo('"+urlQuery+"', '"+gotoID+"', '"+idBotao+"', 1 )");
				$j(cam).html(result).animate({ height: 'hide', opacity: 'hide' }, 'fast');
			}else{
				$j(cam_idBotao).attr("onclick","ExibeConteudo('"+urlQuery+"', '"+gotoID+"', '"+idBotao+"', 0 )");
				$j(cam).html(result).animate({ height: 'show', opacity: 'show' }, 'fast');
			}
	    }
	}
	xmlhttp.send(null)
}
function Trim(str){return str.replace(/^\s+|\s+$/g,"");}
function idShow( id, bg ){
	var $j = jQuery.noConflict();
	var opct = '0.5';
	if( bg != undefined ){ 
		var bg = "#fff";
		var opct = '0.0';
	}
	overlayBox( bg, opct, id);
	$j(id).css({'z-index' : '10000'}).animate({ height: 'show', opacity: 'show' }, 'slow'); 
}
function overlayBox(bg, opct, id){
	// Get page sizes
	var arrPageSizes = PageSize();
	var id = instanceId(id);
	
	if( $j("#overlayBox").length > 0 ){
		$j("#overlayBox").remove();
	}
	$j('embed, object, select').css({ 'visibility' : 'hidden' });
	$j('body').append('<div id="overlayBox"></div>');
	$j('#overlayBox').css({
		backgroundColor:	bg,
		opacity:			opct,
		width:				arrPageSizes[0],
		height:				arrPageSizes[1]
	}).fadeIn();
	$j(id).css({'z-index' : '101'});
	$j("#overlayBox").click(function() { 
		finishBox(id);
	})

}
function PageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};
function PageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
};
function finishBox(id) {
	$j('.aguarde').remove();
	$j(id).remove();
	$j('#overlayBox').fadeOut(function() { $j('#overlayBox').remove(); });
	$j('embed, object, select').css({ 'visibility' : 'visible' });
	$j('body').css('overflow','auto');
}
function idHide( id ){
	var $j = jQuery.noConflict();
	$j(id).animate({ height: 'hide', opacity: 'hide' }, 'slow');
	$j("#overlayBox").animate({ opacity: 'hide' }, 'fast');
}
function AjaxPHP( url, msg ){
	var $j = jQuery.noConflict();
	var msg = (msg == undefined) ? "Executando a tarefa solicitada, aguarde..." : msg;
	var aguarde = "<div class='aguarde'><img alt='loading' src='http://www.transitobrasil.org/img/loading.gif' /><br /><br />"+msg+"</div>";
	if( $j(".aguarde").length > 0 ){
		$j(".aguarde").show();
	}else{
		$j(aguarde).appendTo("body").hide();
	}
	$j('.aguarde').ajaxStart(function(){
    	$j('.aguarde').show();
	});
	$j('.aguarde').ajaxStop(function(){
		$j('.aguarde').hide();   
	});
	$j.post( url );
}
function numdias(mes,ano) {
    if((mes<8 && mes%2==1) || (mes>7 && mes%2==0)) return 31;
    if(mes!=2) return 30;
    if(ano%4==0) return 29;
    return 28;
}
function somadias(data, dias) {
    data=data.split('/');
    diafuturo=parseInt(data[0])+dias;
    mes=parseInt(data[1]);
    ano=parseInt(data[2]);
    while(diafuturo>numdias(mes,ano)) {
        diafuturo-=numdias(mes,ano);
        mes++;
        if(mes>12) {
            mes=1;
            ano++;
        }
    }
    return diafuturo+"/"+mes+"/"+ano;
}
function allScreenBox(restoreBox,restoreParams) {
	var _ie = navigator.appVersion.indexOf("MSIE");
	var id = "#toDiviFrame";
	var arrPageSizes = PageSize();
	var arrPageScroll = PageScroll();
	if( restoreBox > 0 ){
		var arrBoxSizes = Array($j(id).css('top'),$j(id).css('left'),$j(id).css('width'),$j(id).css('height'));
		var restoreParams = "{top: '"+arrBoxSizes[0]+"',left: '"+arrBoxSizes[1]+"',width: '"+arrBoxSizes[2]+"',height: '"+arrBoxSizes[3]+"',padding: '5px'}";
		if( _ie != -1 ){
			$j(id).css({top: arrPageScroll[1]+22, left: '0', width: '100%', height: '100%', padding: '0'});
			$j('#allScreen').remove();
		}else{
			$j(id).css({top: arrPageScroll[1]+22, left: '0', width: '100%', height: '96%', padding: '0 20px 0 0'});
			$j('#allScreen').attr('src',PATH+"img/barra_loadiframe_restaurar.gif").attr('onclick',"allScreenBox(0,"+restoreParams+")");
		}
	}else{
		$j('body').css('overflow','auto');
		$j("#allScreen").attr('src',PATH+"img/barra_loadiframe_telacheia.gif").attr('onclick',"allScreenBox(1)");
		$j(id).css(restoreParams);
	}
}
function LoadiFrame( url, id ){
	var versao = navigator.appVersion.indexOf("MSIE 6.0");
	var _ie = navigator.appVersion.indexOf("MSIE");
	if( versao != -1 && versao <= 18){
		abre_pagina(url,700,600,200,70);
	}else{
		var id = instanceId(id);
		$j('body').css('overflow','hidden');
		overlayBox( '#000', 0.8, '#toDiviFrame');
		if( $j("#toDiviFrame").length > 0 ){
			$j("#toDiviFrame").remove();
		}
		$j('body').append("<div id='toDiviFrame' class='iFrameDiv'><div class='idBarra'><img id='allScreen' src='"+PATH+"img/barra_loadiframe_telacheia.gif' onclick=allScreenBox(1) /><img src='"+PATH+"img/barra_loadiframe_link.gif' onclick=abre_pagina('"+url+"',700,600,200,70) /><img src='"+PATH+"img/barra_loadiframe_fechar.gif' onclick=finishBox('#toDiviFrame') /></div><iframe name='ifrm_anexo' scrolling='auto'  allowtransparency='true' src='" + url + "' frameborder='0' height='100%' width='100%' style='background-color: #fff;'></iframe></div>");
		$j('body').append("<div class='aguarde'><img alt='loading' src='"+PATH+"img/loading.gif' /><br />Aguarde Carregando...</div>");
	
		var arrPageSizes = PageSize();
		var arrPageScroll = PageScroll();

		$j('.aguarde').css( 'top',	arrPageScroll[1] + (arrPageSizes[3] / 10) + 200 );
		$j('#toDiviFrame').css( 'top',	arrPageScroll[1] + (arrPageSizes[3] / 10) );
		$j('.iFrameDiv').css('display','block');
		$j('.idBarra').css('top', '-22px' );
		$j('iframe').load(function(){ $j(".aguarde").remove(); });
		$j('.iFrameDiv,.aguarde').click(function() { $j(".aguarde").remove(); });
	}
}
function LoadPopUp( url, h, w, param ){
	var url = (url == undefined || url == "") ? PATH+"_blank.html" : url;
	$j('body').css('overflow','hidden');
	overlayBox( '#000', 0.8, '#toDivPopUP');
	if( $j('#toDivPopUP').length > 0 ){
		$j('#toDivPopUP').remove();
	}
	$j('body').append("<div id='toDivPopUP' class='PopUp'></div>");
	var arrPageSizes = PageSize();
	var arrPageScroll = PageScroll();
	var aw = ( (arrPageSizes[2] - w ) / 2 );
	$j('#toDivPopUP').css( 'top',	arrPageScroll[1] + (arrPageSizes[3] / 5) ).css( 'left', aw);
	$j('#toDivPopUP').animate({ height: h+"px", width: w+"px" }, 'slow');
	if( param == undefined || param == "" ){
		$j('#toDivPopUP').load(url);
	}else{
		$j('#toDivPopUP').load(url, param);
	}
}

function doDestacaTexto(Texto, termoBusca){

	/*******************************************************************/
	// CASO QUEIRA MODIFICAR O ESTILO DA MARCAÇÃO ALTERE ESSAS VARIÁVEIS
	/*******************************************************************/
	inicioTag = "<span class='Hightlight'>";
	fimTag = "</span>";
	
	var novoTexto = "";
	var i = -1;
	var lcTermoBusca = termoBusca.toLowerCase();
	var lcTexto = Texto.toLowerCase();

	if( termoBusca.length > 3 ){
		while (Texto.length > 0){
			i = lcTexto.indexOf(lcTermoBusca, i+1);
			if (i < 0){
				novoTexto += Texto;
				Texto = "";
			}
			else{
				if (Texto.lastIndexOf(">", i) >= Texto.lastIndexOf("<", i)){
					if (lcTexto.lastIndexOf("/script>", i) >= lcTexto.lastIndexOf("<script", i)){
						novoTexto += Texto.substring(0, i) + inicioTag + Texto.substr(i, termoBusca.length) + fimTag;
						Texto = Texto.substr(i + termoBusca.length);
						lcTexto = Texto.toLowerCase();
						i = -1;
					}
				}
			}
		}
	}else{
		novoTexto = Texto;
	}
	return novoTexto;
}

function doDestacaTextoBusca(textoBusca, textoObj, ehFrase){
	
	$(textoObj).find('.Hightlight').removeClass('Hightlight');
	
	if (ehFrase){arrayBusca=[textoBusca];}
	else{arrayBusca = textoBusca.split(" ");}

	var Texto = textoObj.innerHTML;

	for (var i = 0; i < arrayBusca.length; i++){Texto = doDestacaTexto(Texto, arrayBusca[i]);}
	textoObj.innerHTML = Texto;
	return true;
}
function aguarde(msg){
	if( msg.indexOf("#") == 0 && $j(msg).length > 0 ){
		var aguarde = "<div id='aguarde'><img alt='loading' src='"+PATH+"img/loading.gif' /></div>";
		$j(msg).empty().prepend(aguarde);
		var h_msg = $j(msg).css('height');
		var h_msg = h_msg.replace(/\D/g,"");
		var h_msg = (h_msg / 2) - 20;
		$j("#aguarde").css({'text-align':'center', 'padding-top': h_msg}).hide();

		$j(msg).ajaxStart(function(){
			$j('#aguarde').show();
		});
		$j(msg).ajaxStop(function(){
			$j('#aguarde').remove();
		});
	}else{
		var msg = (msg == "" || msg == undefined) ? "Tarefa sendo executada, aguarde..." : msg;
		var aguarde = "<div class='aguarde'><img alt='loading' src='http://www.transitobrasil.org/img/loading.gif' /><br /><br />"+msg+"</div>";
		var arrPageSizes = PageSize();
		var arrPageScroll = PageScroll();
		
		if( $j(".aguarde").length > 0 ){
			$j(".aguarde").remove();
		}
		$j(aguarde).appendTo("body").hide();
		$j('.aguarde').css( 'top',	arrPageScroll[1] + (arrPageSizes[3] / 10) + 200 );
		$j('.aguarde').ajaxStart(function(){
			$j('.aguarde').show();
		});
		$j('.aguarde').ajaxStop(function(){
			$j('.aguarde').remove();
		});
	}
}
function consultaCEP(cep){
	var cepL = cep.length;
	var cep = cep.replace(".","");
	for(i=0; i<=cepL; i++){
		cep = cep.replace("-","");
	}
	if( cep != "" ){
		var cepL = cep.length;
		if( cepL == 8 ){
			$j(".readOnly").attr('readOnly', 'true').css('background','#F8F3DE');
			aguarde("Consultando CEP, aguarde...");
			emptyCEP();
			var url = PATH+"adm/cep.php";
			var param = "cep="+cep;
			$j.ajax({ 
					type: "POST", 
					url: url, 
					cache: true, 
					data: param,
					success: function(msg){
						result = msg.split( "|" );
						var logradouro = result[1];
						var bairro     = result[2];
						var ufStr      = result[3];
						var cidadeStr  = result[4];
						var uf         = result[5];
						var cidade     = result[6];
						var retorno    = result[7];
						$j('#logradouro').val(logradouro);
						$j('#bairro').val(bairro);
						$j('#ufStr').val(ufStr);
						$j('#cidadeStr').val(cidadeStr);
						$j('#uf').val(uf);
						$j('#cidade').val(cidade);
						if (retorno==0 || logradouro==" "){
							$j(".readOnly").removeAttr('readOnly').css('background','');
						}
						sayid(result[0],'cepMsg');
						$j('#cep').removeAttr('readOnly');
						$j("#cep").css('background','');
					},
					error: function(data){
						$j(".aguarde").remove();
						sayid("Ocorreu um erro interno, por favor tente novamente mais tarde.",'cepMsg');
					}
			}).responseText;
		}else{
			sayid(cep+" CEP está incompleto, o correto são 8 dígitos.",'cepMsg');
		}
		$j('#cep').removeAttr('readOnly');
		$j("#cep").css('background','');
	}
}
function emptyCEP(){
	$j(".info").hide();
	//$j('#cep').empty();
	$j('#logradouro').empty();
	$j('#bairro').empty();
	$j('#ufStr').empty();
	$j('#cidadeStr').empty();
	$j('#uf').empty();
	$j('#cidade').empty();
}
function consultaCPF(cpf){
	$j("#cpf").attr('disabled', 'true');
	var url = PATH+"adm/cpf.php";
	var param = "codCpf="+cpf;
	var cpfL = cpf.length;
	if( cpfL == 14 || cpfL == 11 ){
		aguarde("Consultando CPF, aguarde...");
		$j.ajax({ 
				type: "POST", 
				url: url, 
				cache: true, 
				data: param,
				success: function(msg){
					sayid(msg, 'cpfMsg');
					$j('#cpf').removeAttr('disabled');
					$j("#cpf").css('background','#fff');
				}
		}).responseText;
	}else{
		sayid("CPF é um campo obrigatório, verifique se foi informado corretamente.", 'cpfMsg');
	}
	$j("#cpf").css('background','#fff');
	$j('#cpf').removeAttr('disabled');
}
function consultaLOGIN(login){
	$j("#Login").css('background', 'url('+PATH+'img/ajax_preloader.gif) no-repeat top right');
	$j("#Login").attr('disabled', 'true');
	var url = PATH+"adm/login.php";
	var login = RetiraAcentos(login);
	var param = "login="+login;
	var loginL = login.length;
	if( loginL >= 5 ){
		$j.ajax({ 
				type: "POST", 
				url: url, 
				cache: true, 
				data: param,
				success: function(msg){
					sayid(msg, 'loginMsg');
					$j("#Login").removeAttr('disabled');
					$j("#Login").css('background','');
				}
		}).responseText;
	}else{
		sayid("LOGIN com no minimo 05 caracteres.", 'loginMsg');
	}
	$j("#Login").removeAttr('disabled');
	$j("#Login").css('background','');
}
function RetiraAcentos(Campo) {
   var Acentos = "áàãââÁÀÃÂéêÉÊíÍóõôÓÔÕúüÚÜçÇabcdefghijklmnopqrstuvxwyz!@#$%¨&*()+=§/?°`´[]{}ªº^~;:,'"+"\"";
   var Traducao ="AAAAAAAAAEEEEIIOOOOOOUUUUCCABCDEFGHIJKLMNOPQRSTUVXWYZ";
   var Posic, Carac;
   var TempLog = "";
   for (var i=0; i < Campo.length; i++)
   {
   Carac = Campo.charAt (i);
   Posic  = Acentos.indexOf (Carac);
   if (Posic > -1)
	  TempLog += Traducao.charAt (Posic);
   else
      TempLog += Campo.charAt (i);
   }
      return (TempLog);
}
function sayid(texto, id, campo){
	var cam = instanceId(id);
	var nomeClasse = $j(cam).attr("className");
	var status = $j(cam).css('display');
	if( campo != undefined ){
		var campo = instanceId(campo);
		var paddingLeftCam = $j(cam).css("padding-left");
		var paddingLeftCam = paddingLeftCam.replace(/\D/g,"");
		var widthCampo = $j(campo).css("width");
		var widthCampo = widthCampo.replace(/\D/g,"");
		var widthCam = (widthCampo - paddingLeftCam);
		$j(cam).css("width",widthCam+"px");
	}
	if( $j(cam).html() == "" ){
		$j(cam).html(texto).fadeIn();
	}else{
		$j(cam).html(texto);
		if( status == "none" ){
			$j(cam).fadeIn();
		}
	}
	$j('div[class="'+nomeClasse+'"]:not(#'+id+')').fadeOut();
}
function instanceId(id){
	if( id.indexOf(".") == 0 || id.indexOf("#") == 0 ){
		var cam = id;
	}else{
		var cam = document.getElementById(id);
	}
	return cam;
}
function readOnly(campo, id){
	var id = (id == undefined ? "" : ".TDForm");
	if( campo == "remove" ){
		$j(id+" input[type='text']").removeAttr('readOnly').css('background', '');
		$j(id+" input[type='password']").removeAttr('readOnly').css('background', '');
		$j(id+" textarea").removeAttr('readOnly').css('background', '');
	}else{
		$j(id+" input[type='text']").attr('readOnly','true').css('background', '#F8F3DE');
		$j(id+" input[type='password']").attr('readOnly','true').css('background', '#F8F3DE');
		$j(id+" textarea").attr('readOnly','true').css('background', '#F8F3DE');
	}
	if( campo != "" && campo != "remove" ){
		$j(campo).removeAttr('readOnly');
	}
}
function AlertaConfirma(texto){
	var arrPageSizes = PageSize();
	var arrPageScroll = PageScroll();
	$j('body').css('overflow','hidden');
	overlayBox( '#fff', 0.8, '#AlertaConfirmaId');
	if( $j("#AlertaConfirmaId").length > 0 ){
		$j("#AlertaConfirmaId").remove();
	}
	$j('body').append("<div id='AlertaConfirmaId' class='alert'><div id='AlertaConfirmaTexto'>"+texto+"</div><div id='AlertaConfirmaOpt'><a href='javascript:void(0);' id='AlertaConfirmaIdS'><img src='"+PATH+"img/led-icons/accept.png' /><span>SIM</span></a><a href='javascript:void(0);' id='AlertaConfirmaIdN'><img src='"+PATH+"img/led-icons/cancel.png' /><span>NÃO</span></a></div></div>");
	$j('#AlertaConfirmaId').css( 'top',	arrPageScroll[1] + (arrPageSizes[3] / 10) + 80 ).fadeIn();
}
function DataMenor(data_usu) {
	var data=new Date();
	var dia=data.getDate();
	var mes=data.getMonth();
	var ano=data.getFullYear();
	var toda=dia+"/"+mes+"/"+ano;
	if(data_usu<toda) {
		return true;
	}else{
		return false;
	}
}
function textareaFocus(id) {
	var textarea = $j(id);
	textarea.focus();
	textarea.val() = textarea.val();
} 
function disableEnterKey(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     return (key != 13);
}
function loginNow(){
	var value = $j("#nLogin").val();
	var value1 = $j("#nSenha").val();
	if( value != "" && value1 != "" ){
		aguarde("Efetuando Login, aguarde...");
		$j.post(PATH+"login/logar_ajax.php",{login:value, senha:value1},function(data){
			if( data != "" ){
				loginMsg(data);
			}else{
				logado();
				$j().ajaxStop(function(){
					loginMsg("Seja bem vindo, você está logado em nosso Portal.");
				});
			}
		});
	}else{
		loginMsg("Informe o login e senha de usuário.");
	}
}
function logado(){
	$j("#FormLogin").load(PATH+"login/logado.php");
}
function logout(){
	aguarde("Efetuando Logout, aguarde..");
	$j.post(PATH+"login/logout.php",{ ajax: true }, function(data){
		logado();
		$j().ajaxStop(function(){
			loginMsg("Conexão finalizada com sucesso.");
		});
	});
}
function loginMsg(msg){
	$j("#erro_login").html("<p>"+msg+"</p>").slideToggle('slow');
	setTimeout('$j("#erro_login").slideToggle("slow")',6000); 
}
function slideShow() {

	//Set the opacity of all images to 0
	$('#gallery a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#gallery a:first').css({opacity: 1.0});
	
	//Set the caption background to semi-transparent
	$('#gallery .caption').css({opacity: 0.7});

	//Resize the width of the caption according to the image width
	$('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
	
	//Get the caption of the first image from REL attribute and display it
	var caption = $('#gallery a:first').find('img').attr('rel');
	$('#gallery .content').html(caption)
	.animate({opacity: 0.7}, 400);

	if( caption == "sem legenda" ){ 
		$("#gallery .caption").css('visibility','hidden');
	}else{
		$("#gallery .caption").css('visibility','visible');
	}

	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	slideShowIntervalo = setInterval('gallery()',6000);
	$("#gallery a").mouseover(function() {
		var idname = $(this).attr("id");
		ShowGalleryId(idname);
	}).mouseout(function() {
		slideShowIntervalo = setInterval('gallery()',6000);
	});

	$(".nav div").mouseover(function() {
		var idname = $(this).attr("className");
		ShowGalleryId(idname);
	}).mouseout(function() {
		slideShowIntervalo = setInterval('gallery()',6000);
	});
}

function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));
	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));
	
	//Get next image caption
	var caption = next.find('img').attr('rel');
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	var idnext = next.attr("id");

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	var idcurrent = current.attr("id");
	
	//Set the opacity to 0 and height to 1px
	$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#gallery .caption').animate({opacity: 0.7},100 ).animate({height: '55px'},500 );
	
	//Display the content
	$('#gallery .content').html(caption);
	if( caption == "sem legenda" ){ 
		$("#gallery .caption").css('visibility','hidden');
	}else{
		$("#gallery .caption").css('visibility','visible');
	}


	$(".nav div").css({background: "#fff"});
	$("."+idnext).css({background: "#C8E1DC"});
}
function ShowGalleryId(id){
		
	var current = $('#gallery a.show');
	var next = $('#gallery a#'+id);
	clearInterval(slideShowIntervalo);
	if( current.attr("id") != id ){
		//Get next image caption
		var caption = next.find('img').attr('rel');
		
		//Set the fade in effect for the next image, show class has higher z-index
		next.css({opacity: 0.0})
		.addClass('show')
		.animate({opacity: 1.0}, 1000);
	
		//Hide the current image
		current.animate({opacity: 0.0}, 1000)
		.removeClass('show');
		
		//Set the opacity to 0 and height to 1px
		$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
		
		//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
		$('#gallery .caption').animate({opacity: 0.7},100 ).animate({height: '55px'},500 );
		
		//Display the content
		$('#gallery .content').html(caption);
		if( caption == "sem legenda" ){ 
			$("#gallery .caption").css('visibility','hidden');
		}else{
			$("#gallery .caption").css('visibility','visible');
		}
		
		$(".nav div").css({background: "#fff"});
		$("."+id).css({background: "#C8E1DC"});
	}
}
function refreshImgCode(){
	$j('#imgcode').attr('src', PATH+'img/loading.gif');
	var numero = Math.floor(Math.random() * 11);
	$j.post(PATH+'include/imgcode/refresh.php');
	$j('#imgcode').attr('src', PATH+'include/imgcode/imagemgd.php?id='+numero);
}
function template(cor,cod_cor){
	aguarde("Carregando Tema, aguarde...");
	$j.post(PATH+"cookieTemplate.php",{cor:cor},function(data){
		if( data != "" ){
			alert(data);
		}else{
			$j('body').css('background','#fff url('+PATH+'img/layout/v3/bg_header_fine_'+cor+'.png) top left repeat-x');
			$j('#erro_login').css('background','url('+PATH+'img/layout/v3/bg_header_erro_'+cor+'.png) top no-repeat');
			$j('#footer').css('background',cod_cor)
		}
	});
}