// JavaScript Document
function pega(obj){
	if(obj){
		if(document.getElementById(obj)) return document.getElementById(obj);
		else return document.getElementByName(obj);
	}
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


function enviarFrm(objNome, objEmail, objArtista, objMusica, ip)
{
	var endereco = "actions.asp?a=m&nome="+ objNome.value + "&email=" + objEmail.value + "&banda=" + objArtista.value + "&musica=" +  objMusica.value + "&ip=" + ip;
	ajaxFunction('GET', endereco , 'frm_env_musica');
}

function enviarNewsletter(objNome, objEmail, objDT, objIp){
	
	var endereco = "actions.asp?a=n&nome=" + objNome.value + "&email=" + objEmail.value +  "&DT_NASCIMENTO=" + objDT.value + "&ip=" + objIp ;
	
	if (ValidaNewsletter())
		{
				ajaxFunction("GET", endereco, "newsletter");
		}
}


	
function validacao(){
	if (document.form.nome.value == ""){
	alert("O campo Nome não foi preenchido");
	document.form.nome.focus();
	return false;
	}
	
	if (document.form.email.value == ""){
	alert("O campo Email não foi preenchido");
	document.form.email.focus();
	return false;
	}
	
	//validar email(verificao de endereco eletrônico)
	parte1 = document.form.email.value.indexOf("@");
	//parte2 = document.form.email.value.indexOf(".");
	parte3 = document.form.email.value.length;
	if (!(parte1 >= 3 && parte3 >= 9)) {
	   alert ("O campo E-mail deve ser conter um endereco eletronico!");
	   document.form.email.focus();
	   return false;
	}
	
	
	if (document.form.cidade.value == ""){
	alert("O campo Cidade não foi preenchido");
	document.form.cidade.focus();
	return false;
	}
	if (document.form.pais.value == "NULL"){
	alert("Selecione o País que vive");
	document.form.pais.focus();
	return false;
	}
	if (document.form.pais.value == "1" && document.form.estado.value == "NULL"){
	alert("Selecione o Estado que vive");
	document.form.pais.focus();
	return false;
	}
	if (document.form.dddtelefone.value == ""){
	alert("O campo de DDD do telefone não foi preenchido");
	document.form.dddtelefone.focus();
	return false;
	}/*
	else{
		var dddRegex = /^[0-9]{2}$/;
		if(!(dddRegex.test(document.form.dddtelefone.value)))
		{
			alert('DDD deve conter 2 dígitos e apenas números');
		}
	}*/
	if (document.form.telefone.value == ""){
	alert("O campo Telefone não foi preenchido");
	document.form.telefone.focus();
	return false;
	}/*
	else{
		var telefoneRegex = /^[0-9]{8}$/;
		if(!(telefoneRegex.test(document.form.telefone.value)))
		{
			alert('Telefone deve conter 8 dígitos e apenas números');
			return false;
		}
	}*/
	if (document.form.mensagem.value == ""){
	alert("O campo Mensagem não foi preenchido");
	document.form.mensagem.focus();
	return false;
	}
return true;
}



///' VALIDA FORMUALRIO DA HOME - PEDIDO DE MUSICA ///////////////////////////////////////////////////////////////////////	
function ValidaPerdidoMusica(){
	if (document.enviar_musica.nome.value == ""){
		alert("O campo Nome não foi preenchido");
		document.enviar_musica.nome.focus();
	return false;
	}
	if (document.enviar_musica.email.value == ""){
		alert("O campo Email não foi preenchido");
		document.enviar_musica.email.focus();
	return false;
	}
	
	//validar email(verificao de endereco eletrônico)
	parte1 = document.enviar_musica.email.value.indexOf("@");
	//parte2 = document.enviar_musica.email.value.indexOf(".");
	parte3 = document.enviar_musica.email.value.length;
	if (!(parte1 >= 3 && parte3 >= 9)) {
			alert ("O campo " + document.enviar_musica.email.name + " deve ser conter um endereco eletronico!");
			document.enviar_musica.email.focus();
			return false;
	}
		
	if (document.enviar_musica.banda.value == ""){
		alert("O campo Banda não foi preenchido");
		document.enviar_musica.banda.focus();
	return false;
	}
	if (document.enviar_musica.musica.value == ""){
		alert("Selecione o Musica que vive");
		document.enviar_musica.musica.focus();
	return false;
	}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function enviarPergunta(objCodParticipante, objNome, objEmail, objCidade, objEstado, objPergunta, objIp){
	var endereco = "actions.asp?a=pergunta&cod_participante=" + objCodParticipante.value + "&nome=" + objNome.value + "&email=" + objEmail.value + "&cidade=" + objCidade.value + "&estado=" + objEstado.value + "&pergunta=" + objPergunta.value + "&ip=" + objIp;
	ajaxFunction("GET", endereco, "envia_pegunta");
}



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ValidaEnviaPergunta(){
	if (document.FrmPergunta.nome.value == ""){
	alert("O campo Nome não foi preenchido");
	document.FrmPergunta.nome.focus();
	return false;
	}
	if (document.FrmPergunta.email.value == ""){
	alert("O campo Email não foi preenchido");
	document.FrmPergunta.email.focus();
	return false;
	}
	if (document.FrmPergunta.cidade.value == ""){
	alert("O campo Cidade não foi preenchido");
	document.FrmPergunta.cidade.focus();
	return false;
	}
	if (document.FrmPergunta.estado.value == "1" && document.form.estado.value == "NULL"){
	alert("Selecione o estado que vive");
	document.FrmPergunta.pais.focus();
	return false;
	}
	if (document.FrmPergunta.pergunta.value == ""){
	alert("O campo pergunta não foi preenchido");
	document.FrmPergunta.pergunta.focus();
	return false;
	}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function TwLayer()
{
	  //document.getElementById("mais").style.left  = -50;
	  //document.getElementById("mais").style.top = 10;
	  if (document.getElementById("mais").style.visibility == 'visible')  {
		document.getElementById("mais").style.visibility = 'hidden';
	  } else                {
		document.getElementById("mais").style.visibility = 'visible';
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function enviarParaUmAmigo(obj, lyr)
{
	var nome		= obj.nome1.value;
	var mail		= obj.mail1.value;
	var texto		= obj.txt.value;
	var nomeamigo	= obj.nameamigo.value;
	var emailamigo	= obj.mailamigo.value;
	var endereco	= obj.endereco.value;


	if(nome.toString().length==0) {
		alert('Por favor, preencha seu nome.');
		return false;
		}
	if(mail.toString().length==0){
		alert('Por favor, preencha seu e-mail.');
		return false;		
		} 
		
		
	//validar email(verificao de endereco eletrônico)
	parte1 = mail.indexOf("@");
	//parte2 = mail.indexOf(".");
	parte3 = mail.length;
	if (!(parte1 >= 3 && parte3 >= 9)) {
			alert ("O campo E-mail deve ser conter um endereco eletronico!");
			mail.focus();
			return false;
	}
		


	if(nomeamigo.toString().length==0){
		alert('Por favor, preencha o nome de seu amigo.');
		return false;		
		}

	if(emailamigo.toString().length==0){
		alert('Por favor, preencha o e-mail de seu amigo.');
		return false;		
		}

	//validar email(verificao de endereco eletrônico)
	parte1 = emailamigo.indexOf("@");
	//parte2 = emailamigo.indexOf(".");
	parte3 = emailamigo.length;
	if (!(parte1 >= 3 && parte3 >= 9)) {
			alert ("O campo E-mail deve ser conter um endereco eletronico!");
			emailamigo.focus();
			return false;
	}
		
	var strUrl = "";

	strUrl =  "actions.asp";
	strUrl += "?a=amigo";
	strUrl += "&nome="+nome;
	strUrl += "&mail="+mail;
	strUrl += "&nomeamigo="+nomeamigo;
	strUrl += "&emailamigo="+emailamigo;
	strUrl += "&txt="+texto;
	strUrl += "&endereco="+endereco;

	ajaxFunction('GET', strUrl , lyr);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var max=250;
var ancho=300;
function progreso_tecla(obj) {
  var progreso = document.getElementById("progreso");  
  if (obj.value.length < max) {
    progreso.style.backgroundColor = "#FFFFFF";    
    progreso.style.backgroundImage = "url(_imagens/textarea.png)";    
    progreso.style.color = "#000000";
    var pos = ancho-parseInt((ancho*parseInt(obj.value.length))/300);
    progreso.style.backgroundPosition = "-"+pos+"px 0px";
  } else {
    progreso.style.backgroundColor = "#CC0000";    
    progreso.style.backgroundImage = "url()";    
    progreso.style.color = "#FFFFFF";
  } 
  progreso.innerHTML = "("+obj.value.length+" / "+max+")";
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


///' VALIDA FORMUALRIO DA HOME - PEDIDO DE MUSICA ///////////////////////////////////////////////////////////////////////	
function ValidaNewsletter(){
	if (document.form_newsletter.nome.value == ""){
		alert("O campo Nome não foi preenchido");
		document.form_newsletter.nome.focus();
	return false;
	}
	if (document.form_newsletter.email.value == ""){
		alert("O campo Email não foi preenchido");
		document.form_newsletter.email.focus();
	return false;
	}
	//validar email(verificao de endereco eletrônico)
	parte1 = document.form_newsletter.email.value.indexOf("@");
	//parte2 = document.form_newsletter.email.value.indexOf(".");
	parte3 = document.form_newsletter.email.value.length;
	if (!(parte1 >= 3 && parte3 >= 9)) {
			alert ("O campo E-mail deve ser conter um endereco eletronico!");
			document.form_newsletter.email.focus();
			return false;
	}
	
	if (document.form_newsletter.dt_nascimento.value == ""){
		alert("O campo Data de Anievrsário não foi preenchido");
		document.form_newsletter.dt_nascimento.focus();
	return false;
	}
	
	if (document.form_newsletter.dt_nascimento.value == "Data de aniversário"){
		alert("O campo Data de Anievrsário não foi preenchido corretamente.");
		document.form_newsletter.dt_nascimento.focus();
	return false;
	}


return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function MostraDiv(){ 
        if(document.form.pais.value==1){ 
                document.getElementById('idestado').style.display='block'; 
        } else { 
                document.getElementById('idestado').style.display='none'; 
        } 
} 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 function mascaraData(){
	 var data = document.form_newsletter.dt_nascimento.value;
	 if (data.length == 2){
		 data = data + '/';
		 document.form_newsletter.dt_nascimento.value = data;
		 return true;
		 }
		 if (data.length == 5){
			 data = data + '/';
			 document.form_newsletter.dt_nascimento.value = data;
			 return true;
		 }
	}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FUNÇÃO PARA HABILITAR DIV AO CLICAR EM COMENTAR 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function FunMostraDiv(theId){
var theArray= new Array(theId);
w=document.getElementById(theId)
if(w.style.display=="block"){w.style.display='none';}else{ 
       for(i=0; i<theArray.length; i++){
            if(theArray[i] == theId){
                w.style.display='block';
            }else{
                document.getElementById(theArray[i]).style.display='none';
				return false;      
			}
		  }
	   }
	}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ExecComentarioNoticia(frm, lyr)
	{
	var endereco_params = "_includes/inc_noticias_commentarios.asp?strCAPTCHA="+frm.strCaptcha.value;

	endereco_params += "&txtNome="+frm.txtNome.value;
	endereco_params += "&txtEmail="+frm.txtEmail.value;
	endereco_params += "&txtCidade="+frm.txtCidade.value;
	endereco_params += "&txtUF="+frm.txtUF.options[frm.txtUF.selectedIndex].value;
	endereco_params += "&txtComentarios="+frm.txtComentarios.value;
	endereco_params += "&COD_NOTICIA="+frm.COD_NOTICIA.value;

	ValidaComentario(endereco_params, frm, lyr);

	}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FUNÇÃO PARA VALIDAÇÃO DO FORMULARIO DE COMENTARIOS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ValidaComentario(ENDERECO, frm, lyr) {
	
    if (frm.txtNome.value == ""){
		alert("O campo Nome não foi preenchido.");
		frm.txtNome.focus();
		return false;
    }
   
   	if (frm.txtCidade.value == ""){
		alert("O campo Cidade não foi preenchido.");
		frm.txtCidade.focus();
    return false;
    }
  
  	if (frm.txtComentarios.value == ""){
		alert("O campo Comentário não foi preenchido.");
		frm.txtComentarios.focus();
    return false;
    }

    if (frm.strCaptcha.value == ""){
		alert("O campo Caracteres não foi preenchido.");
		frm.strCaptcha.focus();
    return false;
    }




	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(frm.txtEmail.value))
	{
		if(validaUF(frm)){
			ajaxFunction('GET', ENDERECO, lyr)
		}
	}
	else
	{
		alert("E-mail Invalido, verifique-o e tente novamente.")
		frm.txtEmail.focus();
		return false;
	}
}

function validaUF(frm)
{
	if(frm.txtUF.options[frm.txtUF.selectedIndex].value == "")
	{
		alert("Selecione um estado.");
		return false;
    }
	return true;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FUNÇÃO CONTAGEM DE CARACTERES TEXTAREA
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ContadorCaracteres(field, countfield, maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else 
countfield.value = maxlimit - field.value.length;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
