// a funcao abaixo pega a versao mais nova do xmlhttp do ie.
function createXMLHTTP()
{
	try
	{
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
			alert(ajax);
		}
		catch(ex)
		{
			try
			{
				ajax = new XMLHttpRequest();
			}
			catch(exc)
			{
				alert("Esse browser não tem recursos para uso do Ajax");
				ajax = null;
			}
		}
		return ajax;
	}

	var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
	for (var i=0; i < arrSignatures.length; i++)
	{
		try
		{
			var oRequest = new ActiveXObject(arrSignatures[i]);
			return oRequest;
		}
		catch (oError)
		{
		}
	}
	throw new Error("MSXML is not installed on your system.");
}

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_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_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];}
}

function validaEquipe(objFrm) {
	if (objFrm.mensagem.value == '') {
		alert("Preencha com sua mensagem.");
		return false;
	}
	else {
		return true;
	}
}

function validaContato(objFrm) {
	if (objFrm.nome.value == '') {
		alert("Preencha o campo Nome.");
		objFrm.nome.focus();
		return false;
	}
	if (objFrm.email.value == '') {
		alert("Preencha o campo E-mail.");
		objFrm.email.focus();
		return false;
	}
	if (objFrm.mensagem.value == '') {
		alert("Preencha com sua mensagem.");
		objFrm.mensagem.focus();
		return false;
	}
	else {
		return true;
	}
}

function validaContatoEditor(objFrm) {
	if (objFrm.nome.value == '') {
		alert("Preencha o campo Nome.");
		objFrm.nome.focus();
		return false;
	}
	if (objFrm.email.value == '') {
		alert("Preencha o campo E-mail.");
		objFrm.email.focus();
		return false;
	}
	if (objFrm.mensagem.value == '') {
		alert("Preencha com sua mensagem.");
		objFrm.mensagem.focus();
		return false;
	}
	else {
		return true;
	}
}

function validaPeca(objFrm) {
	if (objFrm.nome.value == '') {
		alert("Preencha o campo Nome.");
		objFrm.nome.focus();
		return false;
	}
	if (objFrm.email.value == '') {
		alert("Preencha o campo E-mail.");
		objFrm.email.focus();
		return false;
	}
	if (objFrm.bandaartista.value == '') {
		alert("Preencha o campo Banda / Artista.");
		objFrm.bandaartista.focus();
		return false;
	}
	if (objFrm.musica.value == '') {
		alert("Preencha o campo Música.");
		objFrm.musica.focus();
		return false;
	}
	else {
		return true;
	}
}

function validaCadastro(form, idUser)
{
	statusEmailPromo(form.email.value);
	var msgErro = "";
	var recuperar = false;
	var nomes = form.nome.value.split(" ");

	if(form.nome.value == "" || form.nome.value == "Nome")
	{
		msgErro += " - Preencha o campo Nome \n";
	}
	else if(form.nome.value.length < 5)
	{
		msgErro += " - Informe seu Nome e Sobrenome\n";
	}
	else if(nomes.length < 2)
	{
		msgErro += " - Informe seu Nome e Sobrenome\n";
	}

	if(form.email.value == "" || form.email.value == "Email")
	{
		msgErro += " - Preencha o campo Email\n";
	}
	else if(!isEmail(form.email.value))
	{
		msgErro += " - Email inválido\n";
	}

	if(form.idade[0].checked)
	{
		if(isCPF(form.cpf) == false)
		{
			msgErro += " - CPF inválido, verifique o número digitado\n";
		}
	}
	/*else if(form.existeEmail.value == "true" && idUser == '')
	{
		if(confirm("O Email que voce informou já existe. Deseja recuperar sua senha? \n"))
		{
			recuperar = true;
			window.location='esqueceu_senha.php?email=' +  form.email.value;
			return false;
		}
		else
		{
			recuperar = false;
			return false;
		}
	}*/

	/*if(!form.idade[0].checked && !form.idade[1].checked)
	{
		msgErro += " - Informe se é maior ou menor de 18 anos\n";
	}
	else if(!form.idade[1].checked)
	{
		if(isCPF(form.cpf) == false)
		{
			msgErro += " - CPF inválido, verifique o número digitado\n";
		}
	}
	else */if(!form.idade[0].checked)
	{
		var nomeSnome = form.nome_responsavel.value.split(" ");
		if(form.nome_responsavel.value == "" || form.nome_responsavel.value == "Nome")
		{
			msgErro += " - Preencha o campo Nome do responsável \n";
		}
		else if(form.nome_responsavel.value.length < 5)
		{
			msgErro += " - Informe o Nome e Sobrenome do responsável\n";
		}
		else if(nomeSnome.length < 2)
		{
			msgErro += " - Informe o Nome e Sobrenome do responsável\n";
		}

		if(isCPF(form.cpf_responsavel) == false)
		{
			msgErro += " - CPF do responsável inválido, verifique o número digitado\n";
		}

		if(form.rg_responsavel.value == "" || form.rg_responsavel.value.length < 5)
		{
			msgErro += " - RG do responsável inválido, verifique o número digitado\n";
		}
	}

	/*else if(form.existeCPF.value == "true" && idUser == '')
	{
		if(confirm("CPF informado já cadastrado. Deseja recuperar os dados de acesso para este CPF? \n"))
		{
			recuperar = true;
			window.location='esqueceu_senha.php?email=' +  form.cpf.value;
			return false;
		}
		else
		{
			recuperar = false;
			return false;
		}
	}*/

	var nascimento = form.nascimento.value.split("/");
	var dataAtual = new Date();
	var ano = parseInt(dataAtual.getYear())+"";
	ano = ano.substring(parseInt(ano.length-1),ano.length);
	ano = parseInt("200"+ano);
	result = ano - parseInt(nascimento[2]);
	
	if(form.nascimento.value == "")
	{
		msgErro += " - Preencha a Data de nascimento\n";
	}
	else if((result < 6 || result > 120) || form.nascimento.value.length < 10 || nascimento[0] > 31 || nascimento[1] > 12 || (nascimento[2] < 1900 && nascimento[2] > 2099))
	{
		msgErro += " - Data de nascimento inválida, o formato correto é dd/mm/aaaa\n";
	}

	/*if(form.sexo.value=="")
	{
		msgErro += " - Informe o Sexo\n";
	}

	if(form.profissao.value=="")
	{
		msgErro += " - Preencha o campo Profissao\n";
	}*/

	if(form.cep.value != "" && form.cep.value.length < 6)
	{
		msgErro += " - CEP inválido\n";
	}

	/*if(document.getElementById("cpfResponsavel").style.display == "block")
	{
		if(form.nome_responsavel.value=="")
		{
			msgErro += " - Informe o nome do seu Responsável \n";
		}
	}*/

	if(form.tel.value == "" && form.cel.value == "")
	{
		msgErro += " - Informe algum telefone para contato\n";
	}
	if(form.tel.value != "" && form.tel.value != "Telefone" && form.tel.value.length < 9)
	{
		msgErro += " - Telefone inválido\n";
	}
	if(form.cel.value != "" && form.cel.value != "Celular" && form.cel.value.length < 9)
	{
		msgErro += " - Celular inválido\n";
	}
	/*if(form.endereco.value!="" && form.endereco.value.length<5){
		msgErro += " - Informe o endereço\n";}
	if(form.n.value!="" &&  form.n.value.length<1){
		msgErro += " - Informe o número\n";}
	if(form.bairro.value!="" &&  form.bairro.value.length<1){
		msgErro += " - Informe o Bairro\n";}
	if(form.cidade.value!="" &&  form.cidade.value.length<8){
		msgErro += " - Informe a Cidade\n";}
	if(form.estado.value!="" &&  form.estado.value.length<8){
		msgErro += " - Informe o Estado\n";}
	if(form.cep.value!="" && form.cep.value.length<8){
		msgErro += " - Informe o CEP\n";}
		*/

	if(form.senha.value == "" || form.senha.value == "Senha")
	{
		msgErro += " - Preencha o campo Senha\n";
	}
	else if(form.rsenha.value == "" || form.rsenha.value == "Repetir senha")
	{
		msgErro += " - Preencha o campo Repetir Senha\n";
	}
	else if(form.rsenha.value != "Repetir senha" && form.senha.value != "Senha" && form.senha.value != form.rsenha.value)
	{
		msgErro += " - As senhas não conferem\n";
	}
	else if(form.senha.value.length < 6 || form.rsenha.value.length < 6)
	{
		msgErro += " - Mínimo de 6 caracteres na senha\n";
	}
	
	if(recuperar == true)
	{
		window.location='esqueceu_senha.php';
	}
	else if(msgErro != "")
	{
		alert("Alguns erros foram encontrados:\n\n" + msgErro);
		return false;
	}
	else
	{
		return true;
	}
	
}

function validaCadastroInicio(form){
	var msgErro ="";
	
	statusEmailPromo(form.email.value)
 
	var nomes = form.nome.value.split(" ")
	if(form.nome.value==""){
		msgErro += " - Preencha o campo Nome \n";}else if(form.nome.value.length<5){
		msgErro += " - Informe seu Nome e Sobrenome\n";}else if(nomes.length<2){
		msgErro += " - Informe seu Nome e Sobrenome\n";}
	if(form.email.value==""){
		msgErro += " - Preencha o campo Email\n";}else if(isEmail(form.email.value)==false){
		msgErro += " - Email inválido\n";} else if (form.existeEmail.value=="true"){
		msgErro += " - O email informado já foi cadastrado.\n";}
	if(msgErro!=""){
		alert("Verifique os erros encontrados:\n\n" +msgErro );
		return false;}else{
		return true;}
	
}
 
function validaLogin(form){
	var msgErro ="";
	if(form.email.value=="" || form.email.value=="login"){
		msgErro += " - Preencha o campo Email\n";}else if(isEmail(form.email.value)==false){
		msgErro += " - Email inválido\n";}
	if(form.senha.value=="" || form.senha.value=="senha"){
		msgErro += " - Preencha o campo Senha \n";}else if(form.senha.value.length<6){
		msgErro += " - Senha muito pequena\n";}
	if(msgErro!=""){
		alert("Verifique os erros encontrados:\n\n" +msgErro );
		return false;}else{
		return true;}
}
 
function isCPF(campo){
	teste = new Array();
	obj = eval(campo).value.replace("-",""); 
	obj = obj.replace("/","")
	var D1,D2,D1calc,D2calc,aux;
	var j = 0;
	var counter = 0;
	for(i=0;i<obj.length;i++){
	 if(!isNaN(obj.substring(i,i+1))){
	  teste[j] = obj.substring(i,i+1);
	  j++;}
	}
	aux = teste[0];
	for(i=0;i<teste.length;i++){
	 if(teste[i] == aux){
	  counter++;}
	}
 
	if(counter == teste.length){
	 return false;}
 
	D1 = teste[j-2];
	D2 = teste[j-1];
	D1calc = 0;
	D2calc = 0;
	var loop = j-2;
	for(i=0;i<loop;i++){
	 D1calc += Number(teste[i])*(10-i); 
	 D2calc += Number(teste[i])*(11-i);}
 
	D1calc = (D1calc*10)%11;
	if(D1calc == 10){D1calc=0};
	D2calc = ((D2calc+(2*D1calc))*10)%11;
		if(D2calc == 10){D2calc=0};
	
	if(D1 == D1calc && D2 == D2calc){
	 return true;}
	else{
	 return false;}
}
 
 
function isEmail(email)
{
	var emailRE = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");
	if(emailRE.test(email))
	{
		return true;
	}
	else
	{
		return false;
	}
}
 
function limitaTextarea(campo,tamanho){
 
	
	if(!campo.value.length<tamanho){
		campo.value = campo.value.substring(0,tamanho)
	}
	
		// Exibe o tamanho do texto digitado
	if(document.getElementById('tamanhoTxt')!=null){
		document.getElementById('tamanhoTxt').innerHTML = campo.value.length;}
}

function validaEsqueciSenha(form){
		var msgErro="";
		
		if(form[0].value=="" && form[1].value==""){
			alert('Informe seu Email ou CPF para recuperar sua senha')
			return false;
		}
 
		if(form[0].value!=""){
			if(!isEmail(form[0].value)){
			msgErro += " - Email não informado ou inválido\n";}
			else{
			campo = form[0].value;
		}
		}
		
		if(form[1].value!=""){
			if(isCPF(form[1])==false){
			msgErro += " - CPF não informado ou inválido\n";}
			else{
			campo = form[1].value;
		}
		}
 
		if(msgErro!=""){
		alert("Verifique os erros encontrados:\n\n" +msgErro );
		return false;}else{
		form.campo.value = campo;
			
		return true;}
}
 
// Verifica se o email existe | PAGINA DE CADASTRO
function statusEmailCadastro(valor){
	
	if(valor!=""){
		var oHTTPRequest = createXMLHTTP(); 
		oHTTPRequest.open("post", "admin/getStatusEmail.php", true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					eval("document.form.existeEmail.value="+oHTTPRequest.responseText);
				}
			}
		oHTTPRequest.send("email=" + valor);
	}
}
 
function statusEmailReturn(valor){
	
	if(valor!=""){
		var oHTTPRequest = createXMLHTTP(); 
		oHTTPRequest.open("post", "admin/getStatusEmail.php", true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					return oHTTPRequest.responseText;
				}
			}
		oHTTPRequest.send("email=" + valor);
	}
}
 
// Verifica se o cpf existe
function statusCPF(valor){
	
	if(valor!=""){
		var oHTTPRequest = createXMLHTTP(); 
		oHTTPRequest.open("post", "admin/getStatusCPF.php", true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					eval("document.form.existeCPF.value="+oHTTPRequest.responseText);
				}
			}
		oHTTPRequest.send("cpf=" + valor);
	}
}
 
 
function player(acao){
	switch(acao){

		case "play":
		document.MP1.Play();
		break;

		case "stop":
		document.MP1.Stop();
		if (navigator.appName.indexOf('Netscape') != -1)
            document.MP1.SetCurrentPosition(0);
        else
            document.MP1.CurrentPosition = 0;
		break;

		case "aumenta":
		if (document.MP1.Volume <= -300) 
        	document.MP1.Volume = document.MP1.Volume + 300;
		break;

		case "diminui":
		if ( document.MP1.Volume >= -8000) 
        	document.MP1.Volume = document.MP1.Volume - 300;
		break;
 
	}
}
 
function mudafundo(hora)
{
	for(var x = 0; x < 24; x++)
	{
		if(document.getElementById('H'+x) != null)
		{
			document.getElementById('H'+x).style.backgroundColor = '';
		}
	}
	if(document.getElementById('H'+hora) != null)
	{
		document.getElementById('H'+hora).style.backgroundColor = '#7183b3';
	}
	setPlayList(hora);
}

function showLogin(){
	document.getElementById('divLogin').style.display='block';
}

function setPlayList(valor)
{
	var randomnumber=Math.floor(Math.random() * 11);
	if(valor != "")
	{
		var oHTTPRequest = createXMLHTTP();
		oHTTPRequest.open("get", "player_playlist.php?r="+randomnumber+"&hora="+valor, true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function()
		{
			if (oHTTPRequest.readyState == 4)
			{
				if(document.getElementById('content') != null)
				{
					document.getElementById('content').innerHTML = oHTTPRequest.responseText;
				}
				teste = setTimeout("myScroll = new ScrollObj(6,115,225,'track','up','down','drag','contentMask','content')",100);
			}
		}
		oHTTPRequest.send("hora=" + valor);
	}
}

function setVagalume(valor)
{
	var randomnumber=Math.floor(Math.random() * 11);
	if(valor != "")
	{
		var oHTTPRequest = createXMLHTTP();
		oHTTPRequest.open("get", "player_playlist.php?r="+randomnumber+"&hora="+valor, true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function()
		{
			if (oHTTPRequest.readyState == 4)
			{
				if(document.getElementById('content2') != null)
				{
					document.getElementById('content2').innerHTML = oHTTPRequest.responseText;
				}
				teste = setTimeout("myScroll2 = new ScrollObj(6,115,225,'track2','up2','down2','drag2','contentMask2','content2')",100);
			}
		}
		oHTTPRequest.send("hora=" + valor);
	}
}


function atualizaMusica(){
	var data = new Date();
	var valor = data.getHours();
	var oHTTPRequest = createXMLHTTP(); 
		oHTTPRequest.open("get", "player_setaMusica.php", true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange=function() {
				if (oHTTPRequest.readyState==4){
					if(document.getElementById('musicaAtual')){
						if(document.getElementById('musicaAtual').innerHTML!=oHTTPRequest.responseText){
							document.getElementById('musicaAtual').innerHTML = oHTTPRequest.responseText;
							mudafundo(valor);
						}
					}
				}
			}
		
		oHTTPRequest.send("hora=" + valor);
}

function impre_pes() {
		if (document.forms['enquete'].qual.value == ""){
			alert("Escolha uma opção");
			return false;
		}else{
				return true;
		}
}

function passarValor(parm1) { 
	document.forms['enquete'].qual.value = parm1; 
} 

function mostraVotacao(){
	document.getElementById("votacao").style.display='block';
	document.getElementById("resultado").style.display='none';
}

function mostraResultado(){
	document.getElementById("votacao").style.display='none';
	document.getElementById("resultado").style.display='block';
}

function dadosPessoais()
{
	document.getElementById("pessoal").style.display='block';
	document.getElementById("responsavel").style.display='none';
}

function dadosResponsavel()
{
	document.getElementById("responsavel").style.display='block';
	document.getElementById("pessoal").style.display='none';
}

function votar(){
	if(impre_pes()){
		var oHTTPRequest = createXMLHTTP(); 
			oHTTPRequest.open("post", "votar.php", true);
			oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			oHTTPRequest.onreadystatechange=function(){
				if (oHTTPRequest.readyState==4){
					//eval("document.cadastro.existeEmail.value="+oHTTPRequest.responseText);
					mostraResultado()
					document.getElementById("verVot").style.display='none';
					}
						
				}
			oHTTPRequest.send("arr=" + document.enquete.id_pergunta.value + "," + document.enquete.qual.value);
		}
}

function abreRegulamento(areaid, id){
	var width = 600;
	var height = 450;
	var x = parseInt((screen.width-width)/2);
	var y = parseInt((screen.height-height)/2);
	window.open( 'promocoes_regulamento.php?areaid='+areaid+'&id='+id, 'pop', 'scrollbars=1,statusbar=1,menubar=0,resizable=1,width='+width+',height='+height+',left='+x+',top='+y+'' ); 

}