function somegqr(){
	document.getElementById("gqr").style.visibility = "hidden";
}

function APM(produto){
	document.location = "#top";
	document.getElementById("gqr").style.visibility = "visible";
	document.getElementById("fapm").src = "ACC.php?idprodutos="+produto;
}


function valorde(obj){
  return document.getElementById(obj).value;
}


    function listacidades(url, poost) {
        var httpRequest;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/html');
            }
        } 
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) {}
            }
        }


        if (!httpRequest) {
            return false;
        }

        httpRequest.open('GET', url+"?"+poost, true);
        httpRequest.send("");
                
        httpRequest.onreadystatechange = function() {
	       	 enviacidades(httpRequest, ""); 
      	};
        
        

	return true;
    }
    
    
      function enviacidades(httpRequest, Erro) {
        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
                eval(httpRequest.responseText);
            } else {
		if(Erro != "")
                	alert(Erro);
            }
        }

    }





function mostra_grafico(grafico, pasta){
	var imagem = new Image();

	if(pasta=="")
		imagem.src = "/adm/gerencia/excel_graficos.php/mostra_imagem_grafico.php?idGraficos="+grafico;
	else
		imagem.src = "/adm/gerencia/excel_graficos.php/mostra_imagem_grafico.php?idGraficos="+grafico+"&Pasta="+pasta;

	

	var intervalo = setInterval(function(){	
		if(imagem.complete){
			document.getElementById("imagem_grafico_"+grafico).src = imagem.src;	
			document.getElementById("select_"+grafico).style.display='block';
			clearInterval(intervalo);
		}
	}, 1000);
			
}

function muda_pasta_grafico(id, quem){
	var valor = document.getElementById("select_grafico_"+id).options[document.getElementById("select_grafico_"+id).selectedIndex].value;
	
	var x = y = 0;

	x = document.getElementById('imagem_grafico_'+id).width;
	y = document.getElementById('imagem_grafico_'+id).height;	

	document.getElementById('imagem_grafico_'+id).src="/Imagens/loading.gif";
	document.getElementById('imagem_grafico_'+id).width=x;
	document.getElementById('imagem_grafico_'+id).height=y;

	mostra_grafico(id, valor);

	if(quem=="usuario"){

		//Muda o select da tabela
		for(i=1; i<=500; i++)
			if(Lista_De_Graficos[i][1] == id ){
				document.getElementById('pasta_' + Lista_De_Graficos[i][2]).selectedIndex = document.getElementById('select_grafico_' + Lista_De_Graficos[i][1]).selectedIndex;
				muda_pasta(Lista_De_Graficos[i][2], "funcao");

				tabela = Lista_De_Graficos[i][2];
			}



		for(i=1; i<=500; i++)
			if(Lista_De_Graficos[i][2] == tabela ){
				document.getElementById('select_grafico_' + Lista_De_Graficos[i][1]).selectedIndex = document.getElementById('pasta_'+tabela).selectedIndex;
				muda_pasta_grafico(Lista_De_Graficos[i][1], "funcao");
			}



	}	


}


function muda_pasta(tabela, quem){
 	      var valor = document.getElementById('pasta_'+tabela).options[document.getElementById('pasta_'+tabela).selectedIndex].value;
	      RequestTabela(tabela, valor);


	if(quem=="usuario")
		for(i=1; i<=500; i++)
			if(Lista_De_Graficos[i][2] == tabela ){
				document.getElementById('select_grafico_' + Lista_De_Graficos[i][1]).selectedIndex = document.getElementById('pasta_'+tabela).selectedIndex;
				muda_pasta_grafico(Lista_De_Graficos[i][1], "funcao");
			}



}



function mostra_tabela(tabela){
	RequestTabela(tabela, "");
}

    function RequestTabela(tabela, pasta) {
        var httpRequest;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/html');
            }
        } 
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) {}
            }
        }

        if (!httpRequest) {
            alert('Não foi possível criar uma instância XML. Tente novamente mais tarde.');
            return false;
        }
        httpRequest.onreadystatechange = function() { 
		tabelaContents(httpRequest, tabela); 
	};
	
	if(pasta == "")
        	httpRequest.open('GET', "/Meios/loadtabela.php?id="+tabela, true);
	else
        	httpRequest.open('GET', "/Meios/loadtabela.php?id="+tabela+"&pasta="+pasta, true);


	httpRequest.setRequestHeader("Accept-Charset", "iso-8859-1");
        httpRequest.send("");
    }




    function tabelaContents(httpRequest, tabela) {
        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {

                //alert(httpRequest.responseText);

		document.getElementById("tabeladiv_"+tabela).innerHTML = httpRequest.responseText;



            } else {
                	alert("Erro a pegar tabela.");
            }
        }

    }









































function agmprint(id){
	         jainfoprint = window.open("imprimir_informacao.php?pid="+id, 'jainfoprint', "scrollbars=yes,width=640,height=300");
}


function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.innerHTML = "Limite: " + (limitNum - limitField.value.length) + " caracteres";
	}
}


function emailcheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("E-mail inválido!")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("E-mail inválido!")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("E-mail inválido!")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("E-mail inválido!")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("E-mail inválido!")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("E-mail inválido!")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("E-mail inválido!")
		    return false
		 }

 		 return true					
	}



    function makeRequest(url, poost) {
        var httpRequest;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/html');
            }
        } 
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) {}
            }
        }

        if (!httpRequest) {
            alert('Não foi possível criar uma instância XML. Tente novamente mais tarde.');
            return false;
        }
        httpRequest.onreadystatechange = function() { 
		alertContents(httpRequest, "Problema ao contactar o servidor de newsletter. Por favor, tente cadastrar este e-mail mais tarde."); 
	};
        httpRequest.open('GET', url+"?"+poost, true);
	httpRequest.setRequestHeader("Accept-Charset", "iso-8859-1");
        httpRequest.send("");

    }



    function makeSilentRequest(url, poost) {
        var httpRequest;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/html');
            }
        } 
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) {}
            }
        }


        if (!httpRequest) {
            return false;
        }

        httpRequest.onreadystatechange = function() {
		//' alertContents(httpRequest, ""); 
	};

        httpRequest.open('GET', url+"?"+poost, true);
	httpRequest.setRequestHeader("Accept-Charset", "iso-8859-1");
        httpRequest.send("");

	return true;
    }




    function alertContents(httpRequest, Erro) {
        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
                alert(httpRequest.responseText);
            } else {
		if(Erro != "")
                	alert(Erro);
            }
        }

    }






	function mudaestrela(i, campo){
		
		var estado = document.getElementById("star_"+campo+"_"+i).src;


		for(a=1;a<=5;a++){
			document.getElementById("star_"+campo+"_"+a).src = "/Imagens/star_vazio.gif";
		}	

		for(a=1;a<i;a++){
			document.getElementById("star_"+campo+"_"+a).src = "/Imagens/star_cheio.gif";
		}	

		estado = (estado.substring(estado.length-14));
		a -= 1;


		if(estado == "star_cheio.gif"){
			document.getElementById("star_"+campo+"_"+i).src = "/Imagens/star_vazio.gif";
		}	
		else{
			document.getElementById("star_"+campo+"_"+i).src = "/Imagens/star_cheio.gif";
			a += 1;	

		}	
		
		document.getElementById(campo).value=a;
		
		

	}

//source: http://snipplr.com/view.php?codeview&id=561
// Cross-browser implementation of element.addEventListener()
function addListener(element, type, expression, bubbling)
{
  bubbling = bubbling || false;
  if(window.addEventListener)	{ // Standard
    element.addEventListener(type, expression, bubbling);
    return true;
  } else if(window.attachEvent) { // IE
    element.attachEvent('on' + type, expression);
    return true;
  } else return false;
}

var ImageLoader = function(url){
  this.url = url;
  this.image = null;
  this.loadEvent = null;
};

ImageLoader.prototype = {
  load:function(){
    this.image = document.createElement('img');
    var url = this.url;
    var image = this.image;
    var loadEvent = this.loadEvent;
    addListener(this.image, 'load', function(e){
      if(loadEvent != null){
        loadEvent(url, image);
      }
    }, false);
    this.image.src = this.url;
  },
  getImage:function(){
    return this.image;
  }
};



    function checkEnter(e){ //e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
		
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		document.forms[0].submit() //submit the form
		return false
	}
	else{
		return true
	}

}



function reveal(myvar){
		t=document.getElementById(myvar);
		if(t.style.display=='none'){t.style.display='block';}else{t.style.display='none';}
	}


function nexti(){
	if(confirm("Antes de prosseguir, você deve salvar o novo histórico clicando em \"Salvar este histórico\". Sem isto, não serão salvos as últimas informações sobre seu histórico que você acabou de digitar. Deseja prosseguir?"))
		document.fc.submit();
}

function vota_enquete(id){
         eval("var quen = document.getElementById(\"enquete"+id+"\").value;    ");
         if(quen == "")
           alert("Escolha uma opção antes de votar!");
         else
         janoticia = window.open("vota.php?idenquete="+id+"&P="+quen, 'janoticia', "scrollbars=yes,width=400,height=300");
}

function res_enquete(id){
         janoticia = window.open("res_enquete.php?idenquete="+id, 'janoticia', "scrollbars=yes,width=400,height=300");
}



function mostra_noticia(id){
         janoticia = window.open("mostranoticia.php?idnoticias="+id, 'janoticia', "scrollbars=yes,width=640,height=300");
}



function tabelinha(id){
         janoticia = window.open("/Meios/minitabela.php?id="+id, 'janoticia', "scrollbars=yes,width=700,height=500");
}
