﻿//-----------------------------------------------------------------------

function abre_janela(url,nome,atributos) {
window.open(url,nome,atributos);
}

//--------------- para envio de email-------------------------------------------

 var testresults;
   function check_filter(name){	  
     // var str=document.mensagem.item(name).value;	  only for IE
	  var str=document.getElementById(name).value;
	  
      var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
      if (filter.test(str))
         testresults=true;
      else{
         alert("Endereço de email inválido!")		 		
         testresults=false;
      }
      return (testresults);
   }

   function check_mail(name){
      if (document.layers||document.getElementById||document.all)	  	 
         return check_filter(name);
      else
         return true;
   }
 

 
 
function valida_campos_site(option){
	obj = document.getElementById("form_email");
	obj.target = "iframe_conteudo";	
	obj.method = "POST";
	var x;	
	if (option==1){	
		obj.action = "./php/sendmail.php";
		var vetor= new Array("nome_usuario","email_usuario","comentario");
		var msg= new Array("digitar seu nome","digitar seu email","digitar o comentario");		
	}else{	 	
		obj.action = "./php/enviar_materia_confirma.php";
		var vetor= new Array("nome_usuario","email_usuario","nome_amigo","email_amigo");
		var msg= new Array("nome","seu email","nome do seu amigo","email do seu amigo");			 
	}
	 	
	for (x=0;x<vetor.length;x++){	  					
	   	if(document.getElementById(vetor[x]).value == ""){				
			alert("Faltou "+msg[x] +"!");
			document.getElementById(vetor[x]).focus();	
			return(0);
		}		
   }	 
	if (check_mail(vetor[1])){
		// document.mensagem.submit();  
		document.getElementById("form_email").submit();  
	}	
 } 
//--------------- para envio de email-------------------------------------------


     

function fechar(){
this.close();
}




//Chama flash no site (correção do IE)
function exibeFlash(swf, width, height, wmode, cache){	
noCache = cache || cache == undefined ? "" : "?" + new Date();
wmode == undefined ? "opaque" : "transparent";
monta_swf = "";
monta_swf += "<object type=\"application/x-shockwave-flash\" data=\""+ swf +"\"     width=\""+ width +"\" height=\""+ height +"\" title=\"\">";
monta_swf += "<param name=\"movie\" value=\""+ swf + noCache +"\" />";
monta_swf += "<param name=\"SRC\" value=\""+swf+"\">";

monta_swf += "<param name=\"quality\" value=\"best\" />";

monta_swf += "<param name=\"menu\" value=\"0\" />";
monta_swf += "<param name=\"scale\" value=\"noborder\" />";
monta_swf += "<param name=\"wmode\" value=\""+ wmode +"\" />";
monta_swf += "<param name=\"EmbedMovie\" VALUE=\"0\">";
//monta_swf += "<embed src=\""+ swf + noCache +"\" quality=\"high\" wmode=\""+ wmode +"\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+ width +"\" height=\""+ height +"\" ></embed>";
monta_swf += "</object>";

document.write(monta_swf);
}



//Chama flash no site (correção do IE)
function exibeFlashInObjectId(id, swf, width, height, wmode, cache){	
	noCache = cache || cache == undefined ? "" : "?" + new Date();
	wmode == undefined ? "opaque" : "transparent";
	monta_swf = "";
	monta_swf += "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\""+ width +"\" height=\""+ height +"\" title=\"\">";
	monta_swf += "<param name=\"movie\" value=\""+ swf + noCache +"\" />";
	monta_swf += "<param name=\"quality\" value=\"best\" />";
	monta_swf += "<param name=\"menu\" value=\"0\" />";
	monta_swf += "<param name=\"scale\" value=\"noborder\" />";
	monta_swf += "<param name=\"wmode\" value=\""+ wmode +"\" />";
	monta_swf += "<embed src=\""+ swf + noCache +"\" quality=\"high\" wmode=\""+ wmode +"\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+ width +"\" height=\""+ height +"\"></embed>";
	monta_swf += "</object>";
	document.getElementById(id).innerHTML=monta_swf;
}






function getHTTPObject() {
var req;

try {
        if (window.XMLHttpRequest) {
                req = new XMLHttpRequest();

                if (req.readyState == null) {
                        req.readyState = 1;
                        req.addEventListener("load", function () {
                        req.readyState = 4;
                        if (typeof req.onReadyStateChange == "function")
                        req.onReadyStateChange();
                        }, false);
                }
        return req;
        }

        if (window.ActiveXObject) {
                var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];

                for (var i = 0; i < prefixes.length; i++) {
                        try {
                                req = new ActiveXObject(prefixes[i] + ".XmlHttp");
                                return req;
                                } catch (ex) {};
                }
        }

        } catch (ex) {}
alert("XmlHttp Objects not supported by client browser");
}

var http = getHTTPObject();
// AJAX ********AJAX***********AJAX********AJAX ********AJAX***********AJAX********





var executeQueue = function() {
	
	Ajax = getHTTPObject();
	
	
	 var myDate = new Date();
	// Realizando a solicitacao
	Ajax.open("GET", './admin/ajax_home_call.php?codpages=CAPA&time='+myDate.getTime(), true);
		
	// Verificando o estado da solicitacao	
	Ajax.onreadystatechange = function() {
		// 1=carregando
		if(Ajax.readyState == 1){
			//document.getElementById(current[0]).innerHTML = "Aguarde...";
		}
		// 4=concluido
		if(Ajax.readyState == 4){
			// HTTP ok
			if(Ajax.status == 200) {		
				// Carrega o elemento indicado po id com a resposta da solicitacao	
				Ajax_call=Ajax.responseText.split("###ajax_split###");	
			
				var conteudo = document.createElement('div')								
				conteudo.innerHTML=Ajax_call[0];				
				var scripts = conteudo.getElementsByTagName("img");						
				
				var href_link = '<a href="javascript:carrega_breadcrumb(\'capa\');atualiza_conteudo(\'./php/detalhes.php\',\'id='+Ajax_call[2]+'&amp;page='+Ajax_call[3]+'\',\'GET\',\'handleHttp_carrega_pagina\');" ';	
				var href_link2  = href_link + ' style="cursor:pointer;color:#900;">';	
				  href_link  +=  ' style="cursor:pointer;">';				
				
				/*
				//retira tamanho fixo das tabelas
				var table = conteudo.getElementsByTagName("table");	
				for (t=0;t<table.length;t++){
					table[t].width = "";
				}			
				*/
				
				var texto_noticia = Ajax_call[4];
				if (scripts.length > 0){					
					s = scripts[0].src;							
					var image_text = href_link+'<img src="'+s+'" width="180px" height="150px" style="border:0"/></a>';	
				//	var texto_noticia = conteudo.innerHTML.replace(/<IMG.*>/gi,"").substring(0,489)+"...";						
					document.getElementById("capa_story").innerHTML='<h2 class="titulo" >'+href_link2+Ajax_call[1]+'</a></h2><table style="width:420px;margin-top:5px;"><tr><td style="width:180px;height:150px;vertical-align:top;">'+image_text+'</td><td style="width:220px;vertical-align:top;" >'+href_link+texto_noticia+'</a></td></tr></table>'						
				}else{			
				//	var texto_noticia = conteudo.innerHTML.substring(0,580)+"...";						
					document.getElementById("capa_story").innerHTML='<h2 class="titulo" >'+href_link2+Ajax_call[1]+'</a></h2><table style="width:420px;margin-top:5px;"><tr><td style="width:405px;vertical-align:top;" >'+href_link+texto_noticia+'</a></td></tr></table>'				
				}  			
				
				
				
			} else {
			   alert("Houve um problema ao obter os dados:\n" + Ajax.statusText);			  
			}
		}
	}
	Ajax.send(null);
}




function atualiza_conteudo(url,params,method,handleHttpResponse){
	
if (url.search(/http:/gi) >= 0) return "acesso proibido";
 var myDate = new Date();
// Realizando a solicitacao
http.open(method, url+"?"+params+'&time='+myDate.getTime(), true);
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
http.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
http.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
http.setRequestHeader("Pragma", "no-cache");
eval('http.onreadystatechange = '+handleHttpResponse+';');
http.send(params); //passagem por post

}


function handleHttp_start_home(){ //para retornar texto
        if(http.readyState < 4) {
            //document.getElementById("").innerHTML= "Loading...";
        }
        if (http.readyState == 4) {
                if (http.status ==200) {					
					var conteudo=document.getElementById("conteudo");
					conteudo.innerHTML=http.responseText;
					var scripts = conteudo.getElementsByTagName("script");
					for(i = 0; i < scripts.length; i++){
						s = scripts[i].innerHTML;
						eval(s);
					}		
					executeQueue();
                } else {
                   alert("Houve um problema ao obter os dados:\n" + http.statusText);
                   parent.setMessageStatus('Houve um problema ao obter os dados!','f00');
                }
        }
}



function handleHttp_carrega_pagina(){ //para retornar texto
        if(http.readyState < 4) {
            //document.getElementById("").innerHTML= "Loading...";
        }
        if (http.readyState == 4) {
                if (http.status ==200) {					
					var conteudo=document.getElementById("conteudo");
					conteudo.innerHTML=http.responseText;
					var scripts = conteudo.getElementsByTagName("script");
					for(i = 0; i < scripts.length; i++){
						s = scripts[i].innerHTML;
						eval(s);
					}				   
                } else {
                   alert("Houve um problema ao obter os dados:\n" + http.statusText);
                   parent.setMessageStatus('Houve um problema ao obter os dados!','f00');
                }
        }
}

function carrega_breadcrumb(page){
  open('./php/breadcrumb.php?page='+page, 'iframe_conteudo', '');	
}


function toggle_pmc(obj){
// Jquery
	var state = document.getElementById("pmc").style.display;
	if  ((state == "") || (state == "none")){
		document.getElementById('img_pmc').src='./img/page_up.gif';		
		$("#pmc").animate({ height: 'show', opacity: 'show' }, 'slow');
	}else{
		document.getElementById('img_pmc').src='./img/page_down.gif';		
		$("#pmc").animate({ height: 'hide', opacity: 'hide' }, 'slow');
	}
}

 function imprimir_noticias(){
	var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,resizable=yes,scrollbars=yes,statusbar=yes"; 
	disp_setting+="scrollbars=yes,width=1, height=1, left=0, top=0"; 
	var docprint=window.open("","iframe_conteudo",disp_setting);   
	//docprint.document.open(); 
	docprint.document.write("<html><head><title></title></head>"); 
	docprint.document.write('</head><body onLoad="self.print();"  leftmargin=0 topmargin=0 scrollbars=yes marginwidth=0 marginheigth=0 >');          
	docprint.document.write(document.getElementById("conteudo").innerHTML);   
	docprint.document.write("</body></html>"); 
	docprint.document.close(); 
	docprint.focus(); 
	//alert(docprint.document.body.innerHTML);
	//docprint.print();
 }
 


function mkt(params,obj){	
	  switch (params){
		  case "hide":
				 document.getElementById("mkt").style.display='none';
				  break;
		  default:
				  break	
	  }
	clearTimeout(obj);
}