// JavaScript Document

// limpa os campos de texto onfocus

function limpaCampo(id)
{
  var elemento = document.getElementById(id);
   if (elemento.value != "")
          {elemento.value = "";}

}

// seta acao nos formularios de conteudos da admin
function setaAcao(valor)
{
	var acao = document.getElementById("acao");

	try
	{
		acao.value = valor;
	}
	catch(e)
	{
		acao.value = 0;
	}

}


// conta caracteres

function contacaractere(elem1,elem2,quant){
    var elemento1 = document.getElementById(elem1);
    var elemento2 = document.getElementById(elem2);
    numCaracteres = quant-elemento1.value.length-1;
    if (numCaracteres < 0){
      elemento1.value = elemento1.value.substring(0,elemento1.value.length + numCaracteres);
      numCaracteres = 0;
      alert('A mensagem ultrapassou o limite de ' + quant + ' caracteres!');
      return false;
    }
    elemento2.value = numCaracteres;
    return true;
}


// alerta

function mostraAlerta(sms)
{
 alert(sms);

}

// abre popups

function cs(page) 
{
window.open(page,'janela','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=290,height=112,top=25,left=50')
}
function cs1(page) 
{
window.open(page,'janela','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=305,height=185,top=25,left=50')
}
function cs2(page) 
{
window.open(page,'janela','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=220,height=220,top=25,left=50')
}
function cs3(page) 
{
window.open(page,'janela','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=220,height=240,top=25,left=50')
}
function cs4(page) 
{
window.open(page,'janela','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=310,height=370,top=25,left=50')
}

// estrela amarela onmouseover

function votastar(id)
{
  var elemen = document.getElementById(id);
  elemen.src = "imagens/star3.gif";
}

// estrela original onmouseout

function votastar1(img,hidden)
{
  var elemen = document.getElementById(img);
  var nemele = document.getElementById(hidden);
  var imgorg = nemele.value;
  elemen.src = imgorg;
}

// conta caracteres nos forms de comentarios

function contacaractere(id)
{
 var elemento = document.getElementById(id);
 elemento.value--;
}

// mostra os tops mp3, poli e jogos

// function selecionaElemento(id1,id2,tipo)
// {
// var elemento1 = document.getElementById(id1);
// var elemento2 = document.getElementById(id2);

// if (tipo == '1')
// {
// elemento1.style.visibility = "visible";
// elemento2.style.visibility = "hidden";
// }
// if (tipo == '2')
// {
// elemento1.style.visibility = "hidden";
// elemento2.style.visibility = "visible";
// }
// if (tipo == '3')
// {
// elemento1.style.visibility = "hidden";
// elemento2.style.visibility = "hidden";
// }
// }

// mostrar top

function selecionaelemento(id,tipo,id1,id2,tipo1)
{
var varia1 = document.getElementById(id);

if (tipo == '1')
{
varia1.style.visibility = "hidden";
}
if (tipo == '2')
{
varia1.style.visibility = "visible";
}

// sublinha

var varia1 = document.getElementById(id1);
var varia2 = document.getElementById(id2);

if (tipo1 == '1')
{
varia1.color = "red";
varia2.color = "";
}
if (tipo1 == '2')
{
varia1.color = "";
varia2.color = "red";
}
}


// valida os fomulários

function validaForm(id)
{
    var elemento = document.getElementById(id);
        
  	if (elemento.value == "")
		{

		alert("Valor invalido");
		elemento.focus();
		return false;
		}
	else {
		if (elemento.getAttribute("tipo") == "texto")
		{		
		//elemento.value=="";
		if ((elemento.value.length)<3)
           {
           alert("Texto de no minimo 3 caracteres")
           return false;
           }
        else{return true;}

		}
		else {if (elemento.getAttribute("tipo") == "email")
					{
					validacao = elemento.value.indexOf("@",0)
                                        validacao2 = elemento.value.indexOf(".",0)
					if ((validacao > 0)&&(validacao2 > 0))
						return true;
					else{
						alert("e-mail invalido");
						elemento.focus();
						return false;
						}
		     }
	     }
	     }
    

}

