// *******************************************************************************************************************
// Funções de DreamWeaver
	function MM_openBrWindow(theURL,winName,features) { //v2.0
	  window.open(theURL,winName,features);
	}
	
	function MM_swapImgRestore() { //v3.0
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
	
	function MM_preloadImages() { //v3.0
	  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}
	
	function MM_findObj(n, d) { //v4.01
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	
	function MM_swapImage() { //v3.0
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}



// *******************************************************************************************************************
// Função para Checar inverter seleção de check
	function MudaStatus()
	{
		for (i=0; i<document.forms[0].chk.length; i++)
		{
			document.forms[0].chk[i].checked = !(document.forms[0].chk[i].checked);
		}
	}



// *******************************************************************************************************************
//Funções para Ativar ou Desativar selecionados
	function ExisteCheck()
	{
		achou = false;
		for (i=0; i<document.forms[0].chk.length; i++)
		{
			if (document.forms[0].chk[i].checked)
			{
				achou = true;
				i=document.forms[0].chk.length+10;
			}
		}
		// Somente um check
			if (i==0)achou = document.forms[0].chk.checked;
		
		if(achou==false)
		{
			alert("Por favor, selecione pelo menos um registro para Ativar ou Desativar.")
		}
		return achou;
	}
	function AT_DESAT(ativa)
	{
		if(ExisteCheck()){
			if(ativa==true)
			{
				document.forms[0].acao.value="ativa"
			}else
			{
				document.forms[0].acao.value="desativa"
			}
			document.forms[0].submit()
		}
	}
	function Ativa()
	{
		AT_DESAT(true)
	}
	function Desativa()
	{
		AT_DESAT(false)
	}



// *******************************************************************************************************************
//Funções para Excluit Registro
	function Excluir(reg,id)
	{
		if(confirm("Voce tem certeza que deseja excluir o registro: " + reg + "?"))
		{
			document.forms[0].id_excluir.value=id
			document.forms[0].acao.value="exclui"
			document.forms[0].submit()
		}
	}



// *******************************************************************************************************************
//Função de Validar form
	function ValidaForm(frm)
	{
		for (i=0; i<frm.length; i++)
		{
			// Se for o ultimo campo submete o form
				if (i==frm.length-1){frm.submit();return true;}	
			// Se o campo atual é texto e o campo proximo é com nome obr*
			if ((frm[i].type).toUpperCase()=="TEXT" && (frm[i+1].name).indexOf("obr*")!=-1)
			{
				if(Trim(frm[i].value)=="")
				{
					alert("Por favor, preencha todos os campos.");
					frm[i].focus();
					return false;
				}
			}
		}
	}



// *******************************************************************************************************************
// Retira espaços em branco
		function LTrim(str)
		{ var whitespace = new String(" \t\n\r");
		  var s = new String(str);
		  if (whitespace.indexOf(s.charAt(0)) != -1)
		  {  var j=0, i = s.length;
			 while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
				   j++;
			 s = s.substring(j, i); }
		  return s;
		}
		function RTrim(str)
		{ var whitespace = new String(" \t\n\r");
		  var s = new String(str);
		  if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
		  {  var i = s.length - 1;       // Get length of string
			 while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
					i--;
			 s = s.substring(0, i+1);  }
		  return s;
		}
		function Trim(str) {return RTrim(LTrim(str)); }



// *******************************************************************************************************************
// Valida email
		function isEmail(str) 
		{ 
		var bolOk = false;
		if ((str != "") &&
		(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)) &&
		str.substring(0, 4) != "www." && str.substring(0, 7) != "http://")
		{
		bolOk = true;
		}
		else
		{
		return false;
		}
		return (bolOk);
		} 

		function valida_email(obj)
		{
		  if (Trim(obj.value) != "" && !isEmail(Trim(obj.value)))
		 {   
			 obj.select();
			 obj.focus();
			alert("Por favor, digite corretamente o e-mail.");
			 return(false);  }
		  return true;
		}



// *******************************************************************************************************************
// Aceita somente numero
	function validationKey(e,strCheck)
	{ var key = '';
	  var whichCode = (window.Event) ? e.which : e.keyCode;
	  if (whichCode == 13 || whichCode == 8 || whichCode == 9 || whichCode == 0) return true;  // Enter
	  key = String.fromCharCode(whichCode);  // Get key value from key code
	  if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	  return true
	}



// *******************************************************************************************************************
// Valida Data DD/MM/AAAA
		function valida_data(obj)
		{
			if ((!verificaData(obj.value) || (Trim(obj.value)).length<10) && (Trim(obj.value)).length>0)
			{
				obj.focus();
				obj.select();
				alert("Por favor, preencha corretamente a data (DD/MM/AAAA).");
				return false;
			}
		  return true;
		}
		function colocaBarra(obj)
		{
			if((Trim((obj.value).toString())).length==2 || (Trim((obj.value).toString())).length==5){
				obj.value=(obj.value).toString() + "/";
			}
		}
		function verificaData(Data)
		 {
		  var dma = -1;
		  var data = Array(3);
		  var ch = Data.charAt(0);
		  for(i=0; i < Data.length && (( ch >= '0' && ch <= '9' ) || ( ch == '/' && i != 0 ) ); ){
		   data[++dma] = '';
		   if(ch!='/' && i != 0) return false;
		   if(i != 0 ) ch = Data.charAt(++i);
		   if(ch=='0') ch = Data.charAt(++i);
		   while( ch >= '0' && ch <= '9' ){
			data[dma] += ch;
			ch = Data.charAt(++i);
		   }
		  }
		  if(ch!='') return false;
		  if(data[0] == '' || isNaN(data[0]) || parseInt(data[0]) < 1) return false;
		  if(data[1] == '' || isNaN(data[1]) || parseInt(data[1]) < 1 || parseInt(data[1]) > 12) return false;
		  if(data[2] == '' || isNaN(data[2]) || ((parseInt(data[2]) < 0 || parseInt(data[2]) > 99 ) && (parseInt(data[2]) < 1900 || parseInt(data[2]) > 9999))) return false;
		  if(data[2] < 50) data[2] = parseInt(data[2]) + 2000;
		  else if(data[2] < 100) data[2] = parseInt(data[2]) + 1900;
		  switch(parseInt(data[1])){
		   case 2: { if(((parseInt(data[2])%4!=0 || (parseInt(data[2])%100==0 && parseInt(data[2])%400!=0)) && parseInt(data[0]) > 28) || parseInt(data[0]) > 29 ) return false; break; }
		   case 4: case 6: case 9: case 11: { if(parseInt(data[0]) > 30) return false; break;}
		   default: { if(parseInt(data[0]) > 31) return false;}
		  }
		  return true;
		 }



// *******************************************************************************************************************
// Função de string de conexão
function BuscaStr(obj,cp)
{
	if(obj.value=="A")
	{
		cp.value=""
		cp.disabled=true;
		document.getElementById("gerabd").style.display="";
	}else
	{
		cp.value="Provider=sqloledb;Server=IP_Do_Servisor;Database=Nome_Do_Banco;UID=Usuario;PWD=Senha;"
		cp.disabled=false;
		document.getElementById("gerabd").style.display="none";
	}
}


// *******************************************************************************************************************
// Função de mudar a image
function NovaImage(image,novaimagem)
{
	image.src = "images/" +  novaimagem;
	if(novaimagem.indexOf("vermelho")!=-1)
	{
		alert("Houve erro na sincronização, verifique o passo que deu problema.")
	}
}

// *******************************************************************************************************************
//Funções para Verificar se checou pre-selecionado
	function ExisteSelecionado(msg,msg1)
	{
		achou = false;
		for (i=0; i<document.forms[0].selecao.length; i++)
		{
			if (document.forms[0].selecao[i].checked)
			{
				achou = true;
				i=document.forms[0].selecao.length+10;
			}
		}
		// Somente um check
			if (i==0)achou = document.forms[0].selecao.checked;
		
		if(achou==false)
		{
			alert(msg)
			return achou;
		}
		return confirm(msg1);
	}

// *******************************************************************************************************************
//Funções para Votar na Enquete
function Votar()
{
	var selecionado = false;
	for (i=0; i<document.enquete.resposta.length ; i++)
	{
		if(document.enquete.resposta[i].checked) 
		{
			selecionado = true;
			j=i;
			i=document.enquete.resposta.length+1;
		}
	}
	if (!selecionado)
	{
		alert("Selecione uma opção para votar.")
	}else{
		MM_openBrWindow("","resultado","width=310,height=450")
		document.enquete.submit();
	}
}
function EnqueteAnterior(id)
{
	MM_openBrWindow("resultado.asp?id_enquete=" + id,"resultado","width=310,height=450")
}

function Aumenta() {
    if (document.getElementById("noticiatitulo").style.fontSize == "") {
        document.getElementById("noticiatitulo").style.fontSize = "12px";
    } else if (document.getElementById("noticiatitulo").style.fontSize == "12px") {
        document.getElementById("noticiatitulo").style.fontSize = "14px";
    } else if (document.getElementById("noticiatitulo").style.fontSize == "14px") {
        document.getElementById("noticiatitulo").style.fontSize = "16px";
    }
    if (document.getElementById("noticiatexto").style.fontSize == "") {
        document.getElementById("noticiatexto").style.fontSize = "12px";
    } else if (document.getElementById("noticiatexto").style.fontSize == "12px") {
        document.getElementById("noticiatexto").style.fontSize = "14px";
    } else if (document.getElementById("noticiatexto").style.fontSize == "14px") {
        document.getElementById("noticiatexto").style.fontSize = "16px";
    }
}
function Diminui() {
    if (document.getElementById("noticiatitulo").style.fontSize == "12px") {
        document.getElementById("noticiatitulo").style.fontSize = "10px";
    } else if (document.getElementById("noticiatitulo").style.fontSize == "14px") {
        document.getElementById("noticiatitulo").style.fontSize = "12px";
    } else if (document.getElementById("noticiatitulo").style.fontSize == "16px") {
        document.getElementById("noticiatitulo").style.fontSize = "14px";
    }
    if (document.getElementById("noticiatexto").style.fontSize == "12px") {
        document.getElementById("noticiatexto").style.fontSize = "10px";
    } else if (document.getElementById("noticiatexto").style.fontSize == "14px") {
        document.getElementById("noticiatexto").style.fontSize = "12px";
    } else if (document.getElementById("noticiatexto").style.fontSize == "16px") {
        document.getElementById("noticiatexto").style.fontSize = "14px";
    }
}

function MostraDetalhe(id,obj) {
    if (document.getElementById("conteudo" + id).style.display == "") {
        document.getElementById("conteudo" + id).style.display = "none";
    } else {
        document.getElementById("conteudo" + id).style.display = "";
    }
}