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";
	}

	setTimeout("limitText("+limitField+", "+limitCount+", "+limitNum+")", 100);
}


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");
}
