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 jsValidaImagem(sImagem, dmTamanho){
	//sImagem: Caminho da imagem que será testada
	//dmTamanho: Domínio do tamanho da imagem. 1 e 2.
	if(xmlhttp){
		//Abre a url
		xmlhttp.open('GET', 'bin/ajax.asp?op=1&img=' + sImagem + '&dmt=' + dmTamanho, true);

		//Executada quando o navegador obtiver o código
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4){
				//Lê o texto
				var texto=xmlhttp.responseText;

				//Desfaz o urlencode
				texto=texto.replace(/\+/g," ");
				texto=unescape(texto);

				//Retorna o resultado;
				document.getElementById('Resultado').value=texto;
			}
		}
		xmlhttp.send(null)
	}
}

function jsAjaxAtividade(cdModulo){
	//sImagem: Caminho da imagem que será testada
	//dmTamanho: Domínio do tamanho da imagem. 1 e 2.
	if(xmlhttp){
		//Abre a url
		xmlhttp.open('GET', 'bin/ajax.asp?op=1&cdm=' + cdModulo, true);

		//Executada quando o navegador obtiver o código
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4){
				//Lê o texto
				var texto=xmlhttp.responseText;

				//Desfaz o urlencode
				texto=texto.replace(/\+/g," ");
				texto=unescape(texto);

				//Retorna o resultado;
				texto = 'Atividade Pai:<br />' + texto;
				document.getElementById('dvAtividadePai').innerHTML=texto;
			}
		}
		xmlhttp.send(null)
	}
}

function jsAjaxImagem(sArquivo){
	//sArquivo: Caminho da imagem
	if(xmlhttp){
		//Abre a url
		xmlhttp.open('GET', 'bin/ajax.asp?op=2&ed=' + sArquivo, true);

		//Executada quando o navegador obtiver o código
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4){
				//Lê o texto
				var texto= new String(xmlhttp.responseText);

				//Desfaz o urlencode
				texto=texto.replace(/\+/g," ");
				texto=unescape(texto);

				//Retorna o resultado;
				var arValores = texto.split("|")
				document.getElementById('nuTamanho').value	= arValores[0];
				document.getElementById('nuAltura').value	= arValores[1];
				document.getElementById('nuLargura').value	= arValores[2];
			}
		}
		xmlhttp.send(null)
	}
}

function jsAjaxProgramacao(opcao, codigo){
	if(xmlhttp){
		//Abre a url
		xmlhttp.open('GET', 'bin/ajax.asp?op=3&opcao=' + opcao + '&codigo=' + codigo, true);

		//Executada quando o navegador obtiver o código
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4){
				//Lê o texto
				var texto= new String(xmlhttp.responseText);

				//Desfaz o urlencode
				texto=texto.replace(/\+/g," ");
				texto=unescape(texto);

				//Retorna o resultado;
				if (texto!='0')
					document.getElementById('tbSelecionados').innerHTML=texto;//Retorna o resultado;
				else
					alert('Limite de "5" programações estourado. \nPara selecionar a opção desejada, remova uma das programações selecionadas anteriormente.')
				jsAlteraCorGer();
			}
		}
		xmlhttp.send(null)
	}
}

function jsAjaxPainel(opcao, codigo){
	if(xmlhttp){
		//Abre a url
		xmlhttp.open('GET', 'bin/ajax.asp?op=4&opcao=' + opcao + '&codigo=' + codigo, true);

		//Executada quando o navegador obtiver o código
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4){
				//Lê o texto
				var texto= new String(xmlhttp.responseText);

				//Desfaz o urlencode
				texto=texto.replace(/\+/g," ");
				texto=unescape(texto);

				//Retorna o resultado;
				if (texto!='0')
					document.getElementById('tbSelecionados').innerHTML=texto;//Retorna o resultado;
				else
					alert('Limite de "5" programações estourado. \nPara selecionar a opção desejada, remova uma das programações selecionadas anteriormente.')
				jsAlteraCorGer();
			}
		}
		xmlhttp.send(null)
	}
}

var ajax = {
  funcionamento : function(local,pagina){
    mensagens = document.getElementById('msg_ajax');
    abrir_pag = document.getElementById(local);

    xmlhttp.open("GET", pagina, true);
	xmlhttp.onreadystatechange = function(){
	  if(xmlhttp.readyState == 1) {
		mensagens.style.visibility = 'visible';
	    mensagens.innerHTML = 'Aguarde, carregando...';
	  }
	  if(xmlhttp.readyState == 4) {
	    if(xmlhttp.status == 200){
		  abrir_pag.innerHTML = unescape(xmlhttp.responseText.replace(/\+/g," "));

          mensagens.innerHTML = '';
		  mensagens.style.visibility = 'hidden';
		}
	  }
	}
	xmlhttp.send(null);
  },
  
  gravaDatos_cPanel : function(elemento){
  	mensagens  = document.getElementById('msg_ajax');
  	msg        = document.getElementById('msg_dados');
	formulario = document.frm_serv_cad;
	
	for (var i=0 ; i < formulario.length; i++) {
	  if(formulario[i].id == elemento){
	    valor = formulario[i].value;
	  }
	  
	  if(formulario[i].id == 'usuario'){
	    usu = formulario[i].value;
	  }

	}	

    var elemento_novo = elemento.replace("serv_","");
	
	xmlhttp.open('GET', 'recursos/ajax.php?edita_perfil=ok&usuario='+usu+'&dados='+valor+'&campo='+elemento_novo, true);
	xmlhttp.onreadystatechange = function(){
	  if(xmlhttp.readyState == 1){
	    mensagens.style.visibility = 'visible';
		mensagens.innerHTML = 'Aguarde, carregando...';
		msg.innerHTML       = 'Aguarde, carregando...';
		
	    for(var i=0;i<formulario.elements.length;i++){
          formulario.elements[i].disabled=true;
		}
	  }
	  if(xmlhttp.readyState == 4) {
	    if (xmlhttp.responseText == '1'){
		  msg.innerHTML = 'Dados Alterados com Sucesso!';
		  //document.getElementById(elemento).value = 'Dados Alterados com Sucesso!';
		  document.getElementById(elemento).value = valor;
		  if (elemento == 'serv_nome_razao') document.getElementById('usuario_atual').innerHTML = valor;
		  
	      for(var i=0;i<formulario.elements.length;i++){
            formulario.elements[i].disabled=false;
		  }		  
		  
	      mensagens.style.visibility = 'hidden';
		  mensagens.innerHTML = '';
		}else if (xmlhttp.responseText == '0'){
		  msg.innerHTML = 'Erro ao Alterar Dados!';
		  
	      mensagens.style.visibility = 'hidden';
		  mensagens.innerHTML = '';
		}
	  }
    }
	xmlhttp.send(null);
  },

  MudaLocalNoticia_index : function(local,aux){
    mensagens = document.getElementById('msg_ajax');
    abrir_pag = document.getElementById('not_ind');

    xmlhttp.open("GET", "recursos/ajax.php?LINK=mudar_local_noticia_index&local="+local, true);
	xmlhttp.onreadystatechange = function(){
	  if(xmlhttp.readyState == 1) {
		mensagens.style.visibility = 'visible';
	    mensagens.innerHTML = 'Aguarde, carregando...';
	  }
	  if(xmlhttp.readyState == 4) {
	    if(xmlhttp.status == 200){
		  abrir_pag.innerHTML = unescape(xmlhttp.responseText.replace(/\+/g," "));
		  if (aux == 'mudar_select'){
		    document.getElementById('monta_link_Local').className = (local == 'Local')? 'menu_css_select' : 'menu_css';
		    document.getElementById('monta_link_Brasil').className = (local == 'Brasil')? 'menu_css_select' : 'menu_css';
		    document.getElementById('monta_link_Mundo').className = (local == 'Mundo')? 'menu_css_select' : 'menu_css';
		    document.getElementById('monta_link_Informatica').className = (local == 'Informatica')? 'menu_css_select' : 'menu_css';
		    document.getElementById('monta_link_Esporte').className = (local == 'Esporte')? 'menu_css_select' : 'menu_css';
		  }
          mensagens.innerHTML = '';
		  mensagens.style.visibility = 'hidden';
		}
	  }
	}
	xmlhttp.send(null);
  },

  MudaLocalNoticia : function(local,n_pagina,aux){
    mensagens = document.getElementById('msg_ajax');
    abrir_pag = document.getElementById('arquivo');

    xmlhttp.open("GET", "recursos/ajax.php?LINK=mudar_local_noticia&local="+local+"&pagina="+n_pagina, true);
	xmlhttp.onreadystatechange = function(){
	  if(xmlhttp.readyState == 1) {
		mensagens.style.visibility = 'visible';
	    mensagens.innerHTML = 'Aguarde, carregando...';
	  }
	  if(xmlhttp.readyState == 4) {
	    if(xmlhttp.status == 200){
		  abrir_pag.innerHTML = unescape(xmlhttp.responseText.replace(/\+/g," "));
		  if (aux == 'mudar_select'){
		    document.getElementById('monta_link_Local').className = (local == 'Local')? 'menu_css_select' : 'menu_css';
		    document.getElementById('monta_link_Brasil').className = (local == 'Brasil')? 'menu_css_select' : 'menu_css';
		    document.getElementById('monta_link_Mundo').className = (local == 'Mundo')? 'menu_css_select' : 'menu_css';
		    document.getElementById('monta_link_Informatica').className = (local == 'Informatica')? 'menu_css_select' : 'menu_css';
		    document.getElementById('monta_link_Esporte').className = (local == 'Esporte')? 'menu_css_select' : 'menu_css';
		  }
          mensagens.innerHTML = '';
		  mensagens.style.visibility = 'hidden';
		}
	  }
	}
	xmlhttp.send(null);
  },

  buscaNoticia : function(local){
	param     = ajax.BuscaElementosForm('frm_busca_not');
    mensagens = document.getElementById('msg_ajax');
    abrir_pag = document.getElementById('corpo');
	
	//alert(local);

    xmlhttp.open("POST", "recursos/ajax.php?LINK=result_busca_noticia&local="+local, true);
	xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	xmlhttp.onreadystatechange = function(){
	  if(xmlhttp.readyState == 1) {
		mensagens.style.visibility = 'visible';
	    mensagens.innerHTML = 'Aguarde, carregando...';
	  }
	  if(xmlhttp.readyState == 4) {
	    if(xmlhttp.status == 200){
		  abrir_pag.innerHTML = unescape(xmlhttp.responseText.replace(/\+/g," "));

		  document.getElementById('monta_link_Local').className = (local == 'Local')? 'menu_css_select' : 'menu_css';
		  document.getElementById('monta_link_Brasil').className = (local == 'Brasil')? 'menu_css_select' : 'menu_css';
		  document.getElementById('monta_link_Mundo').className = (local == 'Mundo')? 'menu_css_select' : 'menu_css';
		  document.getElementById('monta_link_Informatica').className = (local == 'Informatica')? 'menu_css_select' : 'menu_css';
		  document.getElementById('monta_link_Esporte').className = (local == 'Esporte')? 'menu_css_select' : 'menu_css';
		  
          mensagens.innerHTML = '';
		  mensagens.style.visibility = 'hidden';
		}
	  }
	}
	xmlhttp.send(param);
  },

  AbreNoticia : function(local,cod_noticia){
    mensagens = document.getElementById('msg_ajax');
    abrir_pag = document.getElementById('corpo');

    xmlhttp.open("GET", "recursos/ajax.php?LINK=abre_noticia&local="+local+"&cod_noticia="+cod_noticia, true);
	xmlhttp.onreadystatechange = function(){
	  if(xmlhttp.readyState == 1) {
		mensagens.style.visibility = 'visible';
	    mensagens.innerHTML = 'Aguarde, carregando...';
	  }
	  if(xmlhttp.readyState == 4) {
	    if(xmlhttp.status == 200){
		  abrir_pag.innerHTML = unescape(xmlhttp.responseText.replace(/\+/g," "));
		  ajax.MudaLocalNoticia(local, '1');

          mensagens.innerHTML = '';
		  mensagens.style.visibility = 'hidden';
		}
	  }
	}
	xmlhttp.send(null);
  },

  enviaNotEmail : function(local,cod_noticia) {
	param      = ajax.BuscaElementosForm('frm_email');
	formulario = document.getElementById('frm_email');
    abrir_pag  = document.getElementById('not_email');
	
	validou = true;
	for(var i=0;i<formulario.elements.length;i++){
      formulario.elements[i].className=formulario.elements[i].className.replace(/ marcado/,"")
      if(formulario.elements[i].value==""){
        formulario.elements[i].className+=" marcado"
        validou=false
      }
      if(formulario.elements[i].value=="" || (!emailCheck(formulario.rem_email.value))){
        formulario.rem_email.className+=" marcado"
        validou=false
      }	  
    }

	if (!validou){
      if (formulario.rem_nome.value == ""){
        alert("Campo NOME vazio!");
        formulario.rem_nome.focus();
        return false;
      }else if (formulario.rem_email.value == ""){
        alert("Campo EMAIL vazio!");
        formulario.rem_email.focus();
        return false;
	  }else if (!emailCheck(formulario.rem_email.value)){
		formulario.rem_email.className=" marcado";
        alert("Campo EMAIL inválido!");
        formulario.rem_email.value = '';
        formulario.rem_email.focus();
        return false;
	  }else if (formulario.des_nome.value == ""){
        alert("Campo NOME vazio!");
        formulario.des_nome.focus();
        return false;
	  }else if (formulario.des_email.value == ""){
        alert("Campo EMAIL vazio!");
        formulario.des_email.focus();
        return false;
	  }else if (!emailCheck(formulario.des_email.value)){
		formulario.des_email.className=" marcado";
        alert("Campo EMAIL inválido!");
        formulario.des_email.value = '';
        formulario.des_email.focus();
        return false;
	  }else if (formulario.des_mensagem.value == ""){
        alert("Campo MENSAGEM vazio!");
        formulario.des_mensagem.focus();
        return false;
	  }
    }else{
      xmlhttp.open("POST", "recursos/ajax.php?LINK=enviar_noticia_email&local="+local+"&cod_noticia="+cod_noticia, true);
	  xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	  xmlhttp.onreadystatechange = function(){
	    if(xmlhttp.readyState == 1) {
	      mensagens.style.visibility = 'visible';
	      mensagens.innerHTML = 'Aguarde, carregando...';
	    }
	    if(xmlhttp.readyState == 4) {
	      if(xmlhttp.status == 200){
		    abrir_pag.innerHTML = unescape(xmlhttp.responseText.replace(/\+/g," "));
            mensagens.innerHTML = '';
		    mensagens.style.visibility = 'hidden';
		  }
	    }
	  }
	  xmlhttp.send(param);
    }
  },

  abreNotEmail : function(local,cod_noticia) {
	div = document.getElementById('corpo');
	if(!document.getElementById('not_email')){
	  not_email = document.createElement('div');
	  not_email['id'] = 'not_email';
	  div.appendChild(not_email);
	  anime.appear(not_email, 0, 100, 50);
	  showLightbox();

      abrir_pag = document.getElementById('not_email');
      xmlhttp.open("GET", "recursos/ajax.php?LINK=enviar_noticia_frm&local="+local+"&cod_noticia="+cod_noticia, true);
	  xmlhttp.onreadystatechange = function(){
	    if(xmlhttp.readyState == 1) {
		  mensagens.style.visibility = 'visible';
	      mensagens.innerHTML = 'Aguarde, carregando...';
	    }
	    if(xmlhttp.readyState == 4) {
	      if(xmlhttp.status == 200){
		    abrir_pag.innerHTML = unescape(xmlhttp.responseText.replace(/\+/g," "));
			
            mensagens.innerHTML = '';
		    mensagens.style.visibility = 'hidden';
		  }
	    }
	  }
	  xmlhttp.send(null);
	}else{
	  alert('A tela de "Imprimir Notícia" já se encontra aberta!');
	}
  },

  fechaNotEmail : function() {
	not_email.innerHTML = '';
	anime.fade(not_email, 100, 0, 500);		
	anime.resizeFecha(not_email, 400, 35, 35, 180, 18, 18);
	hideLightbox();
	mensagens.style.visibility = 'hidden';
	mensagens.innerHTML = '';
  },
  
  enviaSuporteOnline : function() {
	param      = ajax.BuscaElementosForm('sup_online');
	formulario = document.getElementById('sup_online');
    
    abrir_pag  = document.getElementById('corpo');
	
	validou = true;
	for(var i=0;i<formulario.elements.length;i++){
      formulario.elements[i].className=formulario.elements[i].className.replace(/ marcado/,"")
      if(formulario.elements[i].value==""){
        formulario.elements[i].className+=" marcado"
        validou=false
      }
      if(formulario.elements[i].value=="" || (!emailCheck(formulario.sup_email.value))){
        formulario.sup_email.className+=" marcado"
        validou=false
      }
    }

	if (!validou){
      if (formulario.sup_nome.value == ""){
		alert('Campo NOME vazio!');
        formulario.sup_nome.focus();
        return false;
      }else if (formulario.sup_email.value == ""){
		alert('Campo E-MAIL vazio!');
        formulario.sup_email.focus();
        return false;
	  }else if (!emailCheck(formulario.sup_email.value)){
		formulario.sup_email.className=" marcado";
		alert('Campo E-MAIL inválido!');
        formulario.sup_email.value = '';
        formulario.sup_email.focus();
        return false;
	  }
    }else{
      xmlhttp.open("POST", "recursos/ajax.php?LINK=envia_suporte_online", true);
	  xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	  xmlhttp.onreadystatechange = function(){
	    if(xmlhttp.readyState == 1) {
	      mensagens.style.visibility = 'visible';
	      mensagens.innerHTML = 'Aguarde, carregando...';
	    }
	    if(xmlhttp.readyState == 4) {
	      if(xmlhttp.status == 200){
            if(xmlhttp.responseText == 0){
			  alert('abrir chat agora');
			  formulario.reset(); 
			}
			
            mensagens.innerHTML = '';
		    mensagens.style.visibility = 'hidden';
		  }
	    }
	  }
	  xmlhttp.send(param);
    }
  },
  
  enviaFaleConosco : function() {
	//param      = ajax.BuscaElementosForm('frm_fale_conosco');
	//formulario = document.getElementById('frm_fale_conosco');
    msg_fcn    = document.getElementById('msg_fale_conosco');
    abrir_pag  = document.getElementById('corpo');
	
	formulario = document.frm_fale_conosco;
    param      = ajax.camposForm(formulario);	
	
	validou = true;
	for(var i=0;i<formulario.elements.length;i++){
      formulario.elements[i].className=formulario.elements[i].className.replace(/ marcado/,"")
      if(formulario.elements[i].value==""){
        formulario.elements[i].className+=" marcado"
        validou=false
      }
      if(formulario.elements[i].value=="" || (!emailCheck(formulario.fcn_email.value))){
        formulario.fcn_email.className+=" marcado"
        validou=false
      }
    }

	if (!validou){
      if (formulario.fcn_nome.value == ""){
		msg_fcn.innerHTML = 'Campo NOME vazio!';
		msg_fcn.style.visibility = 'Visible';
        formulario.fcn_nome.focus();
        return false;
      }else if (formulario.fcn_email.value == ""){
		msg_fcn.innerHTML = 'Campo E-MAIL vazio!';
		msg_fcn.style.visibility = 'Visible';
        formulario.fcn_email.focus();
        return false;
	  }else if (!emailCheck(formulario.fcn_email.value)){
		formulario.fcn_email.className=" marcado";
		msg_fcn.innerHTML = 'Campo E-MAIL inválido!';
		msg_fcn.style.visibility = 'Visible';
        formulario.fcn_email.value = '';
        formulario.fcn_email.focus();
        return false;
	  }else if (formulario.fcn_assunto.value == ""){
		msg_fcn.innerHTML = 'Campo ASSUNTO vazio!';
		msg_fcn.style.visibility = 'Visible';
        formulario.fcn_assunto.focus();
        return false;
	  }else if (formulario.fcn_telefone.value == ""){
		msg_fcn.innerHTML = 'Campo TELEFONE vazio!';
		msg_fcn.style.visibility = 'Visible';
        formulario.fcn_telefone.focus();
        return false;
	  }else if (formulario.fcn_mensagem.value == ""){
		msg_fcn.innerHTML = 'Campo MENSAGEM vazio!';
		msg_fcn.style.visibility = 'Visible';
        formulario.fcn_mensagem.focus();
        return false;
	  }
    }else{
      xmlhttp.open("POST", "recursos/ajax.php?LINK=envia_fale_conosco", true);
	  xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	  xmlhttp.onreadystatechange = function(){
	    if(xmlhttp.readyState == 1) {
	      mensagens.style.visibility = 'visible';
	      mensagens.innerHTML = 'Aguarde, carregando...';
	    }
	    if(xmlhttp.readyState == 4) {
	      if(xmlhttp.status == 200){
		    //abrir_pag.innerHTML = unescape(xmlhttp.responseText.replace(/\+/g," "));
            if(xmlhttp.responseText == 0){ 
		      msg_fcn.innerHTML = 'Erro ao enviar sucesso!';
			}else if(xmlhttp.responseText == 1){
		      msg_fcn.innerHTML = 'Contato enviado com sucesso!';
			  formulario.reset(); 
			}
			
            mensagens.innerHTML = '';
		    mensagens.style.visibility = 'hidden';
		  }
	    }
	  }
	  xmlhttp.send(param);
    }
  },
  
  linkAcidade : function(cidade_meio,timeline){
    mensagens = document.getElementById('msg_ajax');
    abrir_pag = document.getElementById('corpo');

    xmlhttp.open("GET", "recursos/ajax.php?LINK=link_a_cidade&timeline="+timeline+"&cidade_meio="+cidade_meio, true);
	xmlhttp.onreadystatechange = function(){
	  if(xmlhttp.readyState == 1) {
		mensagens.style.visibility = 'visible';
	    mensagens.innerHTML = 'Aguarde, carregando...';
	  }
	  if(xmlhttp.readyState == 4) {
	    if(xmlhttp.status == 200){
		  abrir_pag.innerHTML = unescape(xmlhttp.responseText.replace(/\+/g," "));
			
          mensagens.innerHTML = '';
		  mensagens.style.visibility = 'hidden';
		}
	  }
	}
	xmlhttp.send(null);
  },
  
  linkHistoria : function(historia_meio,timeline){
    mensagens = document.getElementById('msg_ajax');
    abrir_pag = document.getElementById('corpo');

    xmlhttp.open("GET", "recursos/ajax.php?LINK=link_historia&timeline="+timeline+"&historia_meio="+historia_meio, true);
	xmlhttp.onreadystatechange = function(){
	  if(xmlhttp.readyState == 1) {
		mensagens.style.visibility = 'visible';
	    mensagens.innerHTML = 'Aguarde, carregando...';
	  }
	  if(xmlhttp.readyState == 4) {
	    if(xmlhttp.status == 200){
		  abrir_pag.innerHTML = unescape(xmlhttp.responseText.replace(/\+/g," "));
			
          mensagens.innerHTML = '';
		  mensagens.style.visibility = 'hidden';
		}
	  }
	}
	xmlhttp.send(null);
  },
  
  checaImprimir : function(){
	teste_checaImprimir = document.getElementById('overlay');
	not_checaImprimir = document.getElementById('not_imprimir');
	
    if(teste_checaImprimir){
	  alert('Overlay criado!');
	  teste_checaImprimir.className = 'nao_imprimir';
	  alert(teste_checaImprimir.className);
	  //self.print();
	  
	  // Criar um iFrame para imprimir só a noticia...
	  
	}
  },
  
  abreFotoEvento : function(evento,img) {
	div = document.getElementById('eventos_foto');
	div.style.visibility = 'visible';
	div.style.top = evento.clientY;
	div.style.left = evento.clientX;

    div.innerHTML = '<img src="img/eventos/'+img+'" />';
  },
  
  fechaFotoEvento : function() {
	div = document.getElementById('eventos_foto');
	div.style.visibility = 'hidden';
	div.innerHTML = '';
	mensagens.style.visibility = 'hidden';
	mensagens.innerHTML = '';
  },
  
  abreNotImprimir : function(cod_noticia) {
    mensagens = document.getElementById('msg_ajax');
	div       = document.getElementById('corpo');
	
	if(!document.getElementById('not_imprimir')){
	  not_imprimir = document.createElement('div');
	  not_imprimir['id'] = 'not_imprimir';
	  div.appendChild(not_imprimir);
	  anime.appear(not_imprimir, 0, 100, 50);
	  showLightbox();

      abrir_pag = document.getElementById('not_imprimir');
      xmlhttp.open("GET", "recursos/ajax.php?LINK=imprimir_noticia&cod_noticia="+cod_noticia, true);
	  xmlhttp.onreadystatechange = function(){
	    if(xmlhttp.readyState == 1) {
		  mensagens.style.visibility = 'visible';
	      mensagens.innerHTML = 'Aguarde, carregando...';
	    }
	    if(xmlhttp.readyState == 4) {
	      if(xmlhttp.status == 200){
		    abrir_pag.innerHTML = unescape(xmlhttp.responseText.replace(/\+/g," "));

            mensagens.innerHTML = '';
		    mensagens.style.visibility = 'hidden';
		  }
	    }
	  }
	  xmlhttp.send(null);
	}else{
	  alert('A tela de "Imprimir Notícia" já se encontra aberta!');
	}
  },

  fechaNotImprimir : function() {
	not_imprimir.innerHTML = '';
	anime.fade(not_imprimir, 100, 0, 500);		
	anime.resizeFecha(not_imprimir, 580, 35, 35, 180, 18, 18);
	hideLightbox();
	mensagens.style.visibility = 'hidden';
	mensagens.innerHTML = '';
  },
  
  BuscaElementosForm : function(idForm) {
    var elementosFormulario = document.getElementById(idForm).elements;
    var qtdElementos = elementosFormulario.length;
    var queryString = "";
    var elemento;

    //Cria uma funcao interna para concatenar os elementos do form
    this.ConcatenaElemento = function(nome,valor) { 
                                if (queryString.length>0) { 
                                    queryString += "&";
                                }
                                queryString += encodeURIComponent(nome) + "=" + encodeURIComponent(valor);
                             };

    //Loop para percorrer todos os elementos
    for (var i=0; i<qtdElementos; i++) {
        //Pega o elemento
        elemento = elementosFormulario[i];
        if (!elemento.disabled) {
            //Trabalha com o elemento caso ele nao esteja desabilitado
            switch(elemento.type) {
                //Realiza a acao dependendo do tipo de elemento
                case 'text': case 'password': case 'hidden': case 'textarea':
                    this.ConcatenaElemento(elemento.name,elemento.value);
                    break;
                case 'select-one':
                    if (elemento.selectedIndex>=0) {
                        this.ConcatenaElemento(elemento.name,elemento.options[elemento.selectedIndex].value);
                    }
                    break;
                case 'select-multiple':
                    for (var j=0; j<elemento.options.length; j++) {
                        if (elemento.options[j].selected) {
                            this.ConcatenaElemento(elemento.name,elemento.options[j].value);
                        }
                    }
                    break;
                case 'checkbox': case 'radio':
                    if (elemento.checked) {
                        this.ConcatenaElemento(elemento.name,elemento.value);
                    }
                    break;
            }
        }
    }
    return queryString;
  },


  browser : function () {
	var b = navigator.appName;
	var v = this.version = navigator.appVersion;
	var ua = navigator.userAgent.toLowerCase();
	this.v = parseInt(v);
	this.safari = ua.indexOf("safari")>-1;	// always check for safari & opera
	this.opera = ua.indexOf("opera")>-1;	// before ns or ie
	this.ns = !this.opera && !this.safari && (b=="Netscape");
	this.ie = !this.opera && (b=="Microsoft Internet Explorer");
	this.gecko = ua.indexOf('gecko')>-1; // check for gecko engine
	if (this.ns) {
		this.ns4 = (this.v==4);
		this.ns6 = (this.v>=5);
		this.b = "Netscape";
	}else if (this.ie) {
		this.ie4 = this.ie5 = this.ie55 = this.ie6 = false;
		if (v.indexOf('MSIE 4')>0) {this.ie4 = true; this.v = 4;}
		else if (v.indexOf('MSIE 5')>0) {this.ie5 = true; this.v = 5;}
		else if (v.indexOf('MSIE 5.5')>0) {this.ie55 = true; this.v = 5.5;}
		else if (v.indexOf('MSIE 6')>0) {this.ie6 = true; this.v = 6;}
		this.b = "MSIE";
	}else if (this.opera) {
		this.v=parseInt(ua.substr(ua.indexOf("opera")+6,1)); // set opera version
		this.opera6=(this.v>=6);
		this.opera7=(this.v>=7);
		this.b = "Opera";
	}else if (this.safari) {
		this.ns6 = (this.v>=5);	// ns6 compatible correct?
		this.b = "Safari";
	}
	this.dom = (document.createElement && document.appendChild && document.getElementsByTagName)? true : false;
	this.def = (this.ie||this.dom);
	this.win32 = ua.indexOf("win")>-1;
	this.mac = ua.indexOf("mac")>-1;
	this.other = (!this.win32 && !this.mac);
	this.supported = (this.def||this.ns4||this.ns6||this.opera)? true:false;
  },
  
  caracterQTDE : function(campo, max, maxtxt){
	var len = campo.value.length;
	if(len>max){
	  campo.value = campo.value.substring(0, max);
	}	
	
	maxtxt.value=max-campo.value.length;
  },
  
  FormataCampo : function(Campo,teclapres,mascara){
    //pegando o tamanho do texto da caixa de texto com delay de -1 no event
    //ou seja o caractere que foi digitado não será contado.
    strtext = Campo.value
    tamtext = strtext.length
    //pegando o tamanho da mascara
    tammask = mascara.length
    //criando um array para guardar cada caractere da máscara
    arrmask = new Array(tammask)
    //jogando os caracteres para o vetor
    for (var i = 0 ; i < tammask; i++){
      arrmask[i] = mascara.slice(i,i+1)
    }
    //alert (teclapres.keyCode)
    //começando o trabalho sujo
    if (((((arrmask[tamtext] == "#") || (arrmask[tamtext] == "9"))) || (((arrmask[tamtext+1] != "#") || (arrmask[tamtext+1] != "9"))))){
      if ((teclapres.keyCode >= 37 && teclapres.keyCode <= 40)||(teclapres.keyCode >= 48 && teclapres.keyCode <= 57)||(teclapres.keyCode >= 96 && teclapres.keyCode <= 105)||(teclapres.keyCode == 8)||(teclapres.keyCode == 9) ||(teclapres.keyCode == 46) ||(teclapres.keyCode == 13)){
        ajax.Organiza_Casa(Campo,arrmask[tamtext],teclapres.keyCode,strtext)
      }else{
        ajax.Detona_Event(Campo,strtext)
      }
    }else{//Aqui funcionaria a mascara para números mas eu ainda não implementei
      if ((arrmask[tamtext] == "A")) {
        charupper = event.valueOf()
        //charupper = charupper.toUpperCase()
        ajax.Detona_Event(Campo,strtext)
        masktext = strtext + charupper
        Campo.value = masktext
      }
    }
  },
  
  Organiza_Casa : function(Campo,arrpos,teclapres_key,strtext){
    if (((arrpos == "/") || (arrpos == "(") || (arrpos == ")") || (arrpos == ".") || (arrpos == ",") || (arrpos == ":") || (arrpos == " ") || (arrpos == "-")) && !(teclapres_key == 8)){
      separador = arrpos
      masktext = strtext + separador
      Campo.value = masktext
    }
  },
  
  Detona_Event : function(Campo,strtext){
    event.returnValue = false
    if (strtext != "") {
      Campo.value = strtext
    }
  },
  
  hidediv : function(id) {
    if (document.getElementById) { // DOM3 = IE5, NS6
	  document.getElementById(id).style.display = "none";
	}else {
	  if (document.layers) { // Netscape 4
		document.id.display = "none";
	  }else { // IE 4
		document.all.id.style.display = "none";
	  }
	}
  },

  showdiv : function(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
	  document.getElementById(id).style.display = "";
	}else {
	  if (document.layers) { // Netscape 4
		document.id.display = "";
	  }else { // IE 4
		document.all.id.style.display = "";
	  }
	}
  }
  
}