////////////////////////////DADOS DA FUNCAO//////////////////////////////////
// NOME       : carregaPagina                                             ///
// FINALIDADE : Carregar as páginas via ajax pelo menu		              ///
// PARAMETROS : o nome da página com aspas                             	  ///
// RETORNO    : -                                                 		  ///
/////////////////////////////////////////////////////////////////////////////
function carregaPagina(page)
{	
	$('#main').load(page);			 
}
///////////////////// manipulacao do menu principal //////////////////////////////
function menuativo(id){
	document.getElementById(id).className='style_menuA';
}
function menuinativo(id){
	document.getElementById(id).className='style_menuI';
}
function cormenu(id){
	document.getElementById(id).className='menuselecionado';
}
/////////////////////////////////////////////////////////////////////////////////

///// enviar e-mail do formulario de contato//////////////////////////////
function enviar(){
	var nome       = document.getElementById('nome').value;
	var email      = document.getElementById('email').value;
	var telefone   = document.getElementById('telefone').value;
	var mensagem   = document.getElementById('mensagem').value;
	
	var tam = mensagem.length;
	var tam2 = -1;
	
	if(nome == ""){
		alert('O Nome é necessário');
		return false;
	}
	if(email == "")
	{
		alert('O E-mail é necessário');
		return false;
	}
	else if((email.indexOf("@") == -1) || (email.indexOf('.') == -1) )
	{
		alert('O E-mail está incorreto');
		return false;  
	}
	
	if(telefone == ""){
		alert('O Telefone é necessário');
		return false;
	} 
	if(mensagem == ""){
		alert('Escreva sua mensagem!');
		return false;
	}
	
	/*
	while(tam != tam2)
	{
		tam2 = tam;
		mensagem = mensagem.replace("á","&aacute;");		
		tam  = mensagem.length;
	}*/
	
	var texto  = "Nome = "+nome+"<br>E-mail = "+email+"<br>Telefone = "+telefone+"<br><br>"+mensagem;
	
	$.ajax
	(
	{
		//tipo de método de envio 
		type: 'POST',
		
		//url que receberá os valores
		url: "php/chamada.php",
		
		//os valores
		data: "function=enviar&texto="+texto,
		
		//se o ajax tiver concluído sua requisição com sucesso fará um dos dois casos
		success: function(retorno)
		{
			alert(retorno);
	    }

	}
	);
	
	document.getElementById('nome').value       = "";
	document.getElementById('email').value      = "";
	document.getElementById('telefone').value   = "";
	document.getElementById('mensagem').value = "";
	
}
//////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////
function montaTabelaInscricao(){
	$.ajax
	(
	{
		//tipo de método de envio 
		type: 'POST',
		
		//url que receberá os valores
		url: "php/chamada.php",
		
		//os valores
		data: "function=montaTabelaInscricao",
		
		//se o ajax tiver concluído sua requisição com sucesso fará um dos dois casos
		success: function(retorno)
		{
			document.getElementById('tabela_inscricao').innerHTML = retorno;
	    }

	}
	);
}
/////////////////////////////////////////////////////////
///////adicionar participante na tabela de participantes e acompanhantes ////////////
function adicionarParticipante(){
	var nick     = document.getElementById("nick").value;
	var nome     = document.getElementById("nome").value;
	var cpf      = document.getElementById("cpf").value;
	var uf       = document.getElementById("uf").options[document.getElementById("uf").selectedIndex].value;
	var cidade   = document.getElementById("cidade").value;
	var email    = document.getElementById("email").value;
	var nasc     = document.getElementById("nasc").value;
	var parcelas = document.getElementById("parcelas").options[document.getElementById("parcelas").selectedIndex].value;
	
	$.ajax
	(
	{
		//tipo de método de envio 
		type: 'POST',
		
		//url que receberá os valores
		url: "php/chamada.php",
		
		//os valores
		data: "function=adicionarParticipante&nick="+nick+"&nome="+nome+"&cpf="+cpf+"&uf="+uf+"&cidade="+cidade+"&email="+email+"&nasc="+nasc+"&parcelas="+parcelas,
		
		//se o ajax tiver concluído sua requisição com sucesso fará um dos dois casos
		success: function(retorno)
		{
			document.getElementById('tabela_inscricao').innerHTML = retorno;
	    }

	}
	);
}
		function votarEnquete(){
			//opcao=4872728&id=907120&origem=http%3A%2F%2Fwww.sqllib.com
			var opcao     = document.getElementById("opcao").value;
			var id        = document.getElementById("id").value;
			var origem    = document.getElementById("origem").value;
			
			alert(opcao);
			
			$.ajax
			(
			{
				//tipo de método de envio 
				type: 'GET',
				
				//url que receberá os valores
				url: "http://www.enquetes.com.br/enquete.asp?opcao="+"&id="+"&origem="+origem,
			
				//se o ajax tiver concluído sua requisição com sucesso fará um dos dois casos
				success: function(retorno)
				{
					document.getElementById('main').innerHTML = retorno;
				}

			}
			);
		}	

function formataData(obj,e){
	var tecla=(window.event)?event.keyCode:e.which;
	
	if (obj.value.length ==2){
		obj.value=obj.value+"/";
	}else if (obj.value.length ==5){
		obj.value=obj.value+"/";
	}
	
    if((tecla > 47 && tecla < 58)) return true;
    else{
	    if (tecla != 8 && tecla != 0 && tecla != 13 ) return false;
   	 else return true;
    }
}

function validarData(data)
{
    var formatoValido = new RegExp("^d{2}/d{2}/d{4}$");
    var valido = false;
	 
    if(!formatoValido.test(data.value))
	 {
      alert("A data está no formato errado. Por favor corrija.");
	 } else{
      var dia = data.value.split("/")[0];
      var mes = data.value.split("/")[1];
      var ano = data.value.split("/")[2];
      var MyData = new Date(ano, mes - 1, dia);
      if((MyData.getMonth() + 1 != mes)||
         (MyData.getDate() != dia)||
         (MyData.getFullYear() != ano))
        alert("Valores inválidos para o dia, mês ou ano. Por favor corrija.");
      else
        valido = true;
    }
    if(valido == false){
      data.focus();
      data.select();
    }
    return valido;
}
  
function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}
/////////////////////////////////////////////////