//-------------------------------------------------------------------------------------------------------------------------//
//__________________________________________TESTES ________________________________________________________________________// 
var acertos;
/************************Resultado do Teste Certo ou Errado*****************************************************************/	
	function resultadoVerdFal(){
		var respVerd = 0;
		var respFalse = 0;
			
		frm=document.forms['formulario'];
		for(i=0 ; i < frm.elements.length; i++){		
			if(frm.elements[i].checked){		
				if(frm.elements[i].value == 1){
					respVerd+=(24 / (frm.elements.length / 2));
				}
				else{
					respFalse+=(24 / (frm.elements.length / 2));
				}
			}
		}
		acertos=respVerd; 
		exibir('popup');
		document.getElementById('disp_acertos').innerHTML = "Você fez "+acertos+" pontos";
		if(acertos <= 8 ){
			exibir('resposta1');
		}		
		else{
			if(acertos <= 15 ){
				exibir('resposta2');
			}
			else{
				exibir('resposta3');
			}
		}
	}
	
	
/************************Resultado do Teste ABC******************************************************************************/	
	function resultadoMaior(){
		var resA = 0;
		var resB = 0;
		var resC = 0;		
			
		frm=document.forms['formulario'];		
		for(i=0 ; i < frm.elements.length; i++){		
			if(frm.elements[i].checked){		
				if(frm.elements[i].value == 'A'){
					resA+=(24 / (frm.elements.length / 3));
				}
				else{
					if(frm.elements[i].value == 'B'){
						resB+=(24 / (frm.elements.length / 3));
					}
					else{
					resC+=(24 / (frm.elements.length / 3));
					}
				}
			}
		}
		exibir('popup');
		if(resA > resB && resA > resC){		
			exibir('resposta1');//Resposta A;
		}
		else{
			if(resB > resC){				
				exibir('resposta2');//Resposta B;	
			}
			else{
				exibir('resposta3');//Resposta C;	
			}
		}
	}
/***************************Exibir******************************************************************************************/
	function exibir(id){
		document.getElementById('popup').style.top=document.body.offsetHeight-500 +'px';
		document.getElementById('popup').style.left=(document.body.offsetWidth-477)/2 +'px';
		document.getElementById(id).style.display = "block";		
		
	}	
	
/***************************Window Close************************************************************************************/
	function wClose(popup){
		document.getElementById(popup).style.display = "none";
		document.getElementById('resposta1').style.display = "none";
		document.getElementById('resposta2').style.display = "none";
		document.getElementById('resposta3').style.display = "none";		
	}
//-------------------------------------------------------------------------------------------------------------------------//
//__________________________________________Galeria Album _________________________________________________________________// 
var fotos=new Array()
var legendas=new Array()
var creditos=new Array()
var imgAtual=0;
var cont = 0;
var slide = 0;
var timer ;

function CarregaTbs(){
	htm = "<ul>";
	for(i=0; i<fotos.length; i++){
		htm += '<li><a href="javascript:alteraImg('+i+');pararSlide();"><img src="'+fotos[i]+'" /></a></li>';
	}
	htm += "</ul>";
	document.getElementById('slide_miolo').innerHTML = htm;
	document.imgCentro.src=fotos[imgAtual];
	alteraImg(0);
}

function alteraImg(indx){
	imgAtual=indx;	
	if(imgAtual>=0 && imgAtual<cont){
		document.getElementById("imgCredito").innerHTML = (creditos[imgAtual])?creditos[imgAtual]:"";		
		document.getElementById("imgLegenda").innerHTML = (legendas[imgAtual])?legendas[imgAtual]:"";	
		document.imgCentro.src=fotos[imgAtual];
	}
	if(imgAtual == 0){
		document.getElementById("esq").style.display = "none";
		document.getElementById("borda").style.display = "none";
	}
	else{
		document.getElementById("esq").style.display = "block";
		document.getElementById("borda").style.display = "block";
	}
	
	if(imgAtual == (cont-1)){
		document.getElementById("dir").style.display = "none";
		document.getElementById("proximo").style.display = "none";
	}
	else{
		document.getElementById("dir").style.display = "block";
		document.getElementById("proximo").style.display = "block";
	}
}

function proximo(){
	imgAtual++;	
	alteraImg(imgAtual);
	pararSlide();
}

function anterior(){
	imgAtual--;
	alteraImg(imgAtual);
	pararSlide();
}

function ativarSlide(){
	slide++;
	if(slide == 1){
		slideShow();
		document.getElementById("txtSlide").innerHTML = "parar slideshow";		
	}
	else{
	 	pararSlide();		
				
	}
}

function pararSlide(){
	document.getElementById("txtSlide").innerHTML = "ver slideshow";
	clearTimeout(timer);
	slide = 0;
}

function slideShow(){
	alteraImg(imgAtual);		
	timer=setTimeout("slideShow()",7 * 1000);
	imgAtual++;
	if(imgAtual==cont){	
		imgAtual=0;		
	}
}

function addFav(){
    var url      = window.location;
    var title    = document.getElementsByTagName("META").title.content;
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}
//-------------------------------------------------------------------------------------------------------------------------//
//__________________________________________wOpen_________________________________________________________________// 
function wopen(page,nwin,larg,altu, scroll){
    window.open(page,nwin,'width='+larg+',height='+altu+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scroll+',resizable=no,menubar=no,top=80,left=100');
}

//-------------------------------------------------------------------------------------------------------------------------//
//__________________________________________DHTML Scroll_________________________________________________________________// 
var speed=25;
var inter=5;
var loop, timer;

function ConstructObject(obj,nest, Container){ 
	nest=(!nest) ? '':'document.'+nest+'.';
	this.el=document.getElementById(obj); 
	this.css=document.getElementById(obj).style; 
	this.scrollHeight = this.el.offsetHeight;
	this.clipHeight = this.el.offsetHeight;
	this.scrollWidth = this.el.offsetWidth;
	this.clipWidth = this.el.offsetWidth;
	this.up=MoveAreaUp;
	this.down=MoveAreaDown; 
	this.left=MoveAreaLeft;
	this.right=MoveAreaRight; 
	this.MoveArea=MoveArea;
	this.objContainer = (!Container)? this : eval(Container);
	this.x;
	this.y;
	this.obj = obj + "Object";
	eval(this.obj + "=this");
	return this;
} 

function MoveArea(x,y){ 
	this.x = x;
	this.y = y; 
	this.css.left=this.x + "px";
	this.css.top=this.y + "px";
} 

function MoveAreaDown(move){ 
	if(this.y>-this.scrollHeight+this.objContainer.clipHeight){ 
		this.MoveArea(0,this.y-move);
		if(loop){
			setTimeout(this.obj+".down("+move+")",speed);
		} 
	}
}

function MoveAreaUp(move){ 
	if(this.y<0){ 
		this.MoveArea(0,this.y-move);
		if(loop){
			setTimeout(this.obj+".up("+move+")",speed);
		}
	}
}
function PerformScroll(speed, objA, objB){ 
	if(initialised){ 
		loop=true; 
		if(speed>0){
			objB.down(speed);
		}
		else{
			objB.up(speed);
		}
	} 
} 

function CeaseScroll(){ 
	loop=false 
	if(timer){
		clearTimeout(timer);
	}
} 

function MoveAreaRight(move){ 
	if(this.x>-this.scrollWidth+this.objContainer.scrollWidth){ 
		this.MoveArea(this.x-move,0);
		if(loop){
			setTimeout(this.obj+".right("+move+")",speed);
		} 
	}
}

function MoveAreaLeft(move){ 
	if(this.x<0){ 
		this.MoveArea(this.x-move,0);
		if(loop){
			setTimeout(this.obj+".left("+move+")",speed);
		}
	}
}

function LateralScroll(speed, objA, objB){ 
	if(initialised){ 
		loop=true; 
		if(speed>0){
			objB.right(speed);
		}
		else{
			objB.left(speed);
		}
	} 
}

function InitialiseScrollableArea(){
	var strLocation = document.location.toString();
	objContainer=new ConstructObject('divContainer');
	objScroller=new ConstructObject('divContent','divContainer', 'objContainer');
	objScroller.MoveArea(0,0);
	objContainer.css.visibility='visible';
	initialised=true;  
}

var initialised;

//--------- // 
function createPlayer(theFile, theImg, icons,idObj) {
	var so = new SWFObject('/planetinha/includes/flvplayer.swf','jwplayer','320','260','8');
	so.addParam("allowfullscreen","true"); 
	so.addVariable("enablejs","true");
	so.addVariable('file',theFile); 
	so.addVariable('usekeys','true'); 
	//so.addVariable('width','425');
	//so.addVariable('height','338');
	so.addVariable('backcolor','0x4fa88f');
	so.addVariable('frontcolor','0Xffffff');
	so.addVariable('lightcolor','0x225500');				
	so.addVariable('autostart','false');
	so.addVariable("javascriptid","mpl"); 
	so.addVariable('linkfromdisplay','true');
	
	if (! icons) so.addVariable("showicons", "false");
	if (theImg != "") so.addVariable("image", theImg);
		
	so.write(idObj);
}

//-------------------------------------------------------------------------------------------------------------------------//
//__________________________________________DESTAQUES DA HOME _________________________________________________________________// 
//************************************Destaque de materias com fotos********************************************************//
var destAtual=0;
var aux = 0;
var numDest = null;
	function mudarDestaque(numdestaque){
		destAtual=numdestaque;
		if(destAtual<0){
			destAtual=(numDest-1);			
		}
		if(destAtual>(numDest-1)){
			destAtual=0;			
		}
		lmpDest();
		document.getElementById('blocoDestaque'+destAtual).style.display='block';
		document.getElementById('bloco'+destAtual).style.background='#AFCFFE';
		//alert('lim: '+(numDest-1)+' ; '+destAtual)
		
	}
	
	function proxDest(){
		destAtual++;
		mudarDestaque(destAtual);
	}
	
	function antDest(){
		destAtual--;
		mudarDestaque(destAtual);
	}
	
	function lmpDest(){
		for(i=0;i<numDest;i++){			
			document.getElementById("blocoDestaque"+i).style.display='none';	
			document.getElementById("bloco"+i).style.background='white';
		}
			//alert(numDest);
	}
	
	function recarrDestaque(){
		destAtual=0;
		mudarDestaque(destAtual);
		mudarVideo('video1');
		numDest = document.getElementById('destaques').getElementsByTagName('div').length;
	
		
	}
	

	
//*********************************Videos********************************************************************************//	
	function mudarVideo(numVideo){
		limparVideo();
		document.getElementById(numVideo).style.display='block';
			
	}
	function limparVideo(){
		document.getElementById("video1").style.display='none';	
		document.getElementById("video2").style.display='none';
		document.getElementById("video3").style.display='none';	
	}	
	
	var posx=0;
	var posy=0;
	
	/*function moveMouse(e){
	ns = document.layers;
	ie = document.all;
	ns6 = (document.getElementById && !document.all);
	document.captureEvents(Event.MOUSEMOVE);
		if(ie){
			posx = window.pageXOffset;
			posy = window.pageYOffset;
		} else if (ns){
			posx = e.x;
			posy = e.y;
		} else if (ns6){
			posx = e.clientX;
			posy = e.clientY;
		}
		posx = window.document.body.clientTop ;
		posy = window.pageYOffset;
		alert("x = "+posx+" - "+"y ="+posy);
		
	}*/
	
	function moveMouse(e){
		if (e) {
			MousePos(e); 
		}else{ 
			MousePos();
		}
	}

	function MousePos(e) {
		if (!document.all){
			posy = e.pageY-320;
			//posx = e.pageX-50;
//alert(posx);			
		}
		else{
			posy = (event.y);
			//posx = (event.x)-10;	
	
//alert(posy);			
		}
	}
	
	function iniciaMouseMove(idObj){
		document.getElementById(idObj).onmousemove = moveMouse;
	}
	
	function exibeBlocoCompartilhe(idObj,idBotao){
		exibeObj(idObj);
		var obj = document.getElementById(idObj);
		obj.style.top = posy+"px";
		obj.style.left = (90)+"px";
		//alert("x = "+posx+" - "+"y ="+posy);
	}
	
	function exibeObj(idObj){		
		var obj = document.getElementById(idObj);
		if(obj.style.display == 'none' || obj.style.display.length == 0){
			obj.style.display = 'block';
		}else{
			obj.style.display = 'none';
		}
		
		/*if(obj.style.display == 'block' || obj.style.display.length == 0){
			obj.style.display='none';
		}else{
			obj.style.display='block';						
		}*/
	}
	
	function centralizaobj(idObj){		
		document.getElementById(idObj).style.top=document.body.offsetHeight-378 +'px';
		document.getElementById(idObj).style.left=(document.body.offsetWidth-933)/2 +'px';
	}

//-----------------------------------------------------------------------------------------------------------------------//	

function Buscar(){
	if(document.frmBusca.qu.value == ""){
		alert("Você precisa preencher o campo com uma palavra");
	}
	else{
		document.frmBusca.submit();
	}
}

/*****************************************************************************************************************************/
	function LimitarChar(tag,lim,classe){	
		tagsP = document.getElementsByTagName(tag);
		for(i=0;i<tagsP.length;i++){
			if(tagsP[i].className == classe){
				//alert(tagsP[i].innerHTML.length)
				pai = tagsP[i].parentNode;
				if(pai.getElementsByTagName('b')[0].innerHTML.length >= 33){
					strTxt = tagsP[i].innerHTML.substring(0,(lim/2+40));
				}else{
					if(tagsP[i].innerHTML.length > lim){
						if(tagsP[i].innerHTML.charAt(lim-1) == ' '){
							lim--;
						}
						strTxt = tagsP[i].innerHTML.substring(0,lim);
									
					}else{
						strTxt = tagsP[i].innerHTML;
					}
				}
				tagsP[i].innerHTML = strTxt+'&hellip;';
			}
		}	
	}	
	
//-----------------------------------------------------------------------------------------------------------------------------//

	function wordWrap(classes,limites){
		classes = classes.split(',');
		limites = limites.split(',');
		for(var i=0;i<classes.length;i++){
			comentarios = getElementsByClassName(classes[i]);
			for(var j=0;j<comentarios.length;j++){
				txtTemp = validaPalavras(comentarios[j].innerHTML,parseInt(limites[i]));				
				comentarios[j].innerHTML = txtTemp;
			}
		}
	} 
	
	function validaPalavras(texto,limPalav){
		palavras = texto.split(' '); 
		texto = '';
		for(i=0;i < palavras.length;i++){
			if(palavras[i].length > limPalav){
				ini = 0;
				palavra = palavras[i];
				palavras[i]='';				
				while(ini < palavra.length){									
					palavras[i] += palavra.substring(ini,(ini+limPalav))+' ';
					ini += limPalav;	
				}				
			}
			texto+=palavras[i]+' ';		
		}
		return (texto);	 								
	}
	
	function getElementsByClassName(classe){	
		tagsP = document.getElementsByTagName("*");
		objs = [];
		for(i=0;i<tagsP.length;i++){
			if(tagsP[i].className == classe){
				objs.push(tagsP[i]);				
			}
		}
		return objs;
	}

//////////// Faleconosco////////////////////////////////

		
		qntClick = 0;
		
		function checarClick(){
			qntClick++;
			if(qntClick == 1){
				EnviarForm();								
			}
		}
		

		function retiraAcento(valor){
		//palavra = String.fromCharCode(event.keyCode);  
		var caracteresInvalidos = 'àèìòùâêîôûäëïöüáéíóúãõÀÈÌÒÙÂÊÎÔÛÄËÏÖÜÁÉÍÓÚÃÕ';
		var caracteresValidos =   'aeiouaeiouaeiouaeiouaoAEIOUAEIOUAEIOUAEIOUAO';
		var acento = "´`^¨~"; 
		for(var i= 0; i < caracteresInvalidos.length; i++){
			valor = sapo_replace(caracteresInvalidos[i],caracteresValidos[i],valor);
		}
		
		for(var i= 0; i < acento.length; i++){
			valor = sapo_replace(acento[i],'',valor);
		}
			
			return valor;
		}
	
		function sapo_replace(strFind,newValue,str){
			while(str.indexOf(strFind)!=-1){
					str = str.replace(strFind,newValue); 
				} 
			return str;	
		}


		function setHomepage(){
			if (document.all){
				document.body.style.behavior='url(#default#homepage)';
				document.body.setHomePage('http://planetasustentavel.abril.com.br/planetinha/');			
			}else if (window.sidebar){
				if(window.netscape){
					try{  
						netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
					}catch(e){  
						alert("Esta ação foi barrada pelo seu navegador, se você deseja ativar, digite about:config na sua barra de endereço, e alterar o valor de signed.applets.codebase_principal_support para true");  
					}
				} 
				var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
				prefs.setCharPref('browser.startup.homepage','http://planetasustentavel.abril.com.br/planetinha/');
			}
		}
		
	function centralizaX(idObj){		
		document.getElementById(idObj).style.left=(document.body.offsetWidth-347)/2 +'px';
	}

	function dimensionaFrame(id,w,h){
		frame = document.getElementById(id); 
		w = (w)?w:frame.width;
		h = (h)?h:frame.height;
		frame.setAttribute('height',h);
		frame.setAttribute('width',w);
	}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable){
      return pair[1];
    }
  } 
  return "";
}