// JavaScript Document
function abreJanela(janela) 
{     	
	var largura    = 800;
    var altura     = 600;
    var adicionais = 'toolbar = no, location = no, status = no, menubar = no, scrollbars = yes, resizable = yes';
    var topo       = (screen.height-altura)/2;
    var esquerda   = (screen.width-largura)/2;

    novaJanela = window.open(janela);
	novaJanela.focus();
}


function Contar(Campo, textAreaField, limit)
{
    var ta = document.getElementById(textAreaField);
	if (ta.value.length >= limit) 
	{
 	    ta.value = ta.value.substring(0, limit-1);
 	}
	
	if(Campo.value.length > 400)
	{
        alert('Atenção, você atingiu o limite máximo de caracteres!');
        frmCadastrar.mensagem.value=frmCadastrar.mensagem.value.substring(0,400);
    }
    document.getElementById("qtd").innerText = 400 - Campo.value.length;
	
}

function replaceChars(entry) 
{
    out  = "<"; // se digitar está letra 
    add  = ""; // troca por essa
    temp = "" + entry; 

    while (temp.indexOf(out)>-1) 
	{
        pos  = temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add + 
        temp.substring((pos + out.length), temp.length));
    }
	
	out  = ">"; // se digitar está letra 
    add  = "";
	while (temp.indexOf(out)>-1) 
	{
        pos  = temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add + 
        temp.substring((pos + out.length), temp.length));
    }
	
	out  = "'"; // se digitar está letra 
    add  = "";
	while (temp.indexOf(out)>-1) 
	{
        pos  = temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add + 
        temp.substring((pos + out.length), temp.length));
    }
	
	out  = "="; // se digitar está letra 
    add  = "";
	while (temp.indexOf(out)>-1) 
	{
        pos  = temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add + 
        temp.substring((pos + out.length), temp.length));
    }
	
	out  = "/"; // se digitar está letra 
    add  = "";
	while (temp.indexOf(out)>-1) 
	{
        pos  = temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add + 
        temp.substring((pos + out.length), temp.length));
    }
	
	out  = "\\"; // se digitar está letra 
    add  = "";
	while (temp.indexOf(out)>-1) 
	{
        pos  = temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add + 
        temp.substring((pos + out.length), temp.length));
    }
	
	out  = "\""; // se digitar está letra 
    add  = "";
	while (temp.indexOf(out)>-1) 
	{
        pos  = temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add + 
        temp.substring((pos + out.length), temp.length));
    }
	
	out  = "."; // se digitar está letra 
    add  = "";
	while (temp.indexOf(out)>-1) 
	{
        pos  = temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add + 
        temp.substring((pos + out.length), temp.length));
    }
	
	out  = ":"; // se digitar está letra 
    add  = "";
	while (temp.indexOf(out)>-1) 
	{
        pos  = temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add + 
        temp.substring((pos + out.length), temp.length));
    }
    
	out  = ";"; // se digitar está letra 
    add  = "";
	while (temp.indexOf(out)>-1) 
	{
        pos  = temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add + 
        temp.substring((pos + out.length), temp.length));
    }
	
	out  = "http"; // se digitar está letra 
    add  = "";
	while (temp.indexOf(out)>-1) 
	{
        pos  = temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add + 
        temp.substring((pos + out.length), temp.length));
    }
	
	out  = "www"; // se digitar está letra 
    add  = "";
	while (temp.indexOf(out)>-1) 
	{
        pos  = temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add + 
        temp.substring((pos + out.length), temp.length));
    }
	
	document.comentario.nome.value = temp;
}

//Função que valida dados do formulário de contato
function validaDados(form){	
  if(form.nome.value == ""){
	   alert("Por favor digite seu codenome.");
	   return false;
   }
   if(form.mensagem.value == ""){
	   alert("Por favor comente a notícia.");
	   return false;
   }
   return true;
}
