String.prototype.trim = function()
{
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function AbreJanela(URL,Nome,Opts){
	window.open(URL,Nome,Opts);
}

var Ac = {
	size:14,
	letraMaior:function() {
		if ( this.size < 17 ) {
			this.size++;
createCookie("fs", this.size, 365);
			document.getElementById('texto_noticia').style.fontSize = this.size+'px';
		}
	},
	letraMenor:function() {
		if ( this.size > 11 ) {
			this.size--;
createCookie("fs", this.size, 365);
			document.getElementById('texto_noticia').style.fontSize = this.size+'px';
		}
	},
	contraste:function() {
		setActiveStyleSheet('Acessível')
	},
	normal:function() {
		setActiveStyleSheet('Padrão');

	}
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  var fs = readCookie("fs");
  var div_not = document.getElementById('texto_noticia');
  if(div_not != null)
  {
    if ( !isNaN(parseInt(fs)) ) {
      div_not.style.fontSize = parseInt(fs)+"px";
      Ac.size = parseInt(fs);
    }
  }
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  if (title != 'Impressão') {
	  createCookie("style", title, 365);
  }
}

function fadeIn(id, time) {
	target = document.getElementById(id);
	alpha = 0;
	timer = (time*1000)/50;
	var i = setInterval(
			function() {
				if (alpha >= 100)
					clearInterval(i);
				setAlpha(target, alpha);
				alpha += 3;
			}, timer);
}

function setAlpha(target, alpha) {
	target.style.filter = "alpha(opacity="+ alpha +")";
	target.style.opacity = alpha/100;
}

//Comenta uma notícia
function comentar(frm)
{
	var nome = frm.nome.value;
	var email = frm.email.value;
	var comentario = frm.comentario.value;
	var reEmail = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	
	if (nome == ''){
	  alert('Informe seu nome!');
	  frm.nome.focus();
	  return;
	}
	if (email == ''){
	  alert('Informe um e-mail!');
	  frm.email.focus();
	  return;
	}
	if (!reEmail.test(email)) {
	  alert("Informe um endereço de e-mail válido!");
	  frm.email.focus();
	  return;
	}
	if (comentario == ''){
	  alert('Informe o comentário!');
	  frm.comentario.focus();
	  return;
	}
	frm.submit();
}

// calcula o numero de caracteres de um text area
function contaCaracterC(maxChar, texto)
{
	var numChar = texto.length;
	if (numChar <= maxChar)
	{
		var restante = maxChar - numChar;
		document.getElementById('num_char_c').innerHTML = restante;
	}
	else
	{
	    alert('Limite de caracteres atingido!');
		document.getElementById('txt_c').value = texto.substr(0,maxChar);
	}
	
}

function ampliarFoto1(foto, l, a)
{
	document.getElementById('img_ampliada').innerHTML = '<img src="../../img/noticias/'+foto+'" width="'+l+'" height="'+a+'" />';
	document.getElementById('img_grande').className = 'show';
	document.getElementById('img_grande').style.width = l+'px';
	document.getElementById('img_grande').style.left = (((document.documentElement.clientWidth-l)/2)+document.documentElement.scrollLeft)+'px';
	document.getElementById('img_grande').style.top = (((document.documentElement.clientHeight-a)/2)+document.documentElement.scrollTop)+'px';
	//alert(document.documentElement.scrollTop);
	//alert(document.documentElement.scrollHeight);
	//alert(document.documentElement.clientHeight);
	centralizaImg = false;
	//ft = foto; larg = l; altura = a;
	//centralizaImg = setTimeout("ampliarFoto(ft, larg, altura);", 1);
}

function ampliarFoto(num, foto, l, a)
{
	document.getElementById('img_amp'+num).innerHTML = '<img src="../../img/noticias/'+foto+'" width="'+l+'" height="'+a+'" />';
	document.getElementById('img_g'+num).className = 'show';
	document.getElementById('img_g'+num).style.width = l+'px';
	document.getElementById('img_g'+num).style.left = (((document.documentElement.clientWidth-l)/2)+document.documentElement.scrollLeft)+'px';
	document.getElementById('img_g'+num).style.top = (((document.documentElement.clientHeight-a)/2)+document.documentElement.scrollTop)+'px';
	//alert(document.documentElement.scrollTop);
	//alert(document.documentElement.scrollHeight);
	//alert(document.documentElement.clientHeight);
	centralizaImg = false;
	//ft = foto; larg = l; altura = a;
	//centralizaImg = setTimeout("ampliarFoto(ft, larg, altura);", 1);
}

function comentarios(cod)
{
	URL = '../../editorias/comentarios2.php?cod='+cod;
	janela = 'comentarios';
	opts = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,top=0,left='+(screen.availWidth-510)+',width=500,height=600';
	AbreJanela(URL, janela, opts);
}