 $(function() {
		   // tooltop
	$('#principal *').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		fade: 250
	});


});


function id( id ){ 
        return document.getElementById( id );
}


function campanha(local,alvo)
{
	var url = 'tipo=campanha&local='+local;
	enviaAjaxCampanha(url,alvo);	
}


function enviaAjaxCampanha(url,div)
{
 
var alvo = '#alvo_principal';
$(div).append('Carregando');
document.getElementById('alvo_principal').innerHTML ="<img src='arquivos/images/loading.png' border='0' align='center' />";
 
		$.ajax({
			type: 'GET',
			url: 'arquivos/pages/ajax.php',
			data: url,
				success: function( data )
					{
						$(div).html(data);
						//$(alvo).hide();
						}
					});

}





function cupomEmail(cupom)
{
	erro = new String;
	var cidade = document.getElementById('cidade_');
	var uf = document.getElementById('uf');
	var instrumento = document.getElementById('instrumento_');
	var nivel = document.getElementById('nivel_');
	var data = document.getElementById('data_');
	var sexo = document.getElementById('sexo_');
	
	if(cidade.value=="" || cidade.value=="CIDADE:" || cidade.value.length < 3)
	{
	erro += "Sua CIDADE! \n";
	}

	if(uf.value=="")
	{
	erro += "Seu ESTADO! \n";
	}

	if(instrumento.value=="")
	{
	erro += "Seu INSTRUMENTO! \n";
	}
	
	if(nivel.value=="Selecione")
	{
	erro += "Seu NIVEL! \n";
	}

	if(data.value=="DATA DE ANIVERSÁRIO:" || data.value=="DATA DE ANIVERSÁRIO:" || data.value=="00/00/0000" || data.value.length<9)
	{
	erro += "Sua DATA DE ANIVERSARIO:! \n";
	}

	if(nivel.value=="")
	{
	erro += "Seu SEXO! \n";
	}
	
	if (erro.length > 0){
			alert("Para participar preencha corretamente:\n\n"+erro);
	}else
	{
		completaCadastro3();
		var url = 'tipo=cupomEmail&cupom='+cupom;
		enviaAjax(url,'#alvo',"2");	
	}
}

function mascaraData(){
              var data = document.getElementById('data_').value;

			 // alert(data);
              if (data.length == 2){
                  data = data + '/';
                  data = data;
				  document.getElementById('data_').value = data ;
      return true;              
              }
              if (data.length == 5){
                  data = data + '/';
                  document.getElementById('data_').value = data ;
                  return true;
              }
         }

function limpaForm()
{
document.getElementById('nome_').value = 'NOME:';
document.getElementById('email_').value = 'E-MAIL:';
document.getElementById('assunto_').value = 'ASSUNTO:';
document.getElementById('mensagem_').value = 'MENSAGEM:';
}


function campo(valor)
{
	var retorno;
	var campo = document.getElementById(valor).value;
	switch(valor)
	{
	case 'nome_':
	  retorno = campo==''?'NOME:':campo;
	  break;
	case 'email_':
	  retorno = campo==''?'E-MAIL:':campo;
	  break;
	case 'lg_email_':
	  retorno = campo==''?'E-MAIL:':campo;
	  break;
	case 're_lg_email_':
	  retorno = campo==''?'E-MAIL:':campo;
	  break;	
	case 'codigo_':
	  retorno = campo=='CÓDIGO DA PROMOÇÃO:'?'':campo;
	  break;	  
	case 'indique_':
	  retorno = campo==''?'E-MAIL:':campo;
	  break;	 
	 case 'cidade_':
	  retorno = campo==''?'CIDADE:':campo;
	  break;
	case 'data_':
		retorno = campo==''?'DATA DE ANIVERSARIO:':campo;
		break; 
	case 'assunto_':
	  retorno = campo==''?'ASSUNTO:':campo;
	  break;	 
	case 'mensagem_':
	  retorno = campo==''?'MENSAGEM:':campo;
	  break;	 	  
	default:
	}
document.getElementById(valor).value = retorno;

}

function cliqueCampo(valor)
{
	
	var retorno;
	var campo = document.getElementById(valor).value;
	switch(valor)
	{
	case 'nome_':
	  retorno = campo=='NOME:'?'':campo;
	  break;
	case 'email_':
	  retorno = campo=='E-MAIL:'?'':campo;
	  break;
	case 'lg_email_':
	  retorno = campo=='E-MAIL:'?'':campo;
	  break;
	case 're_lg_email_':
	  retorno = campo=='E-MAIL:'?'':campo;
	  break;	
	case 'codigo_':
	  retorno = campo=='CÓDIGO DA PROMOÇÃO:'?'':campo;
	  break;		  
	case 'indique_':
	  retorno = campo=='E-MAIL:'?'':campo;
	  break;
	  case 'cidade_':
	  retorno = campo==''?'CIDADE:':campo;
	  break;	  
	case 'data_':
	if(campo.length>11)
	 {
		  campo = '';
		}else{
		campo = campo;
		}
			  
	retorno = campo;
	break;
	case 'assunto_':
	  retorno = campo=='ASSUNTO:'?'':campo;
	  break;	 
	case 'mensagem_':
	  retorno = campo=='MENSAGEM:'?'':campo;
	  break;	 	  
	default:
	}
document.getElementById(valor).value = retorno;

}

function completaCadastro()
{
 
	var cidade = document.getElementById('cidade_').value;
	var estado = document.getElementById('uf').value;
	var nivel = document.getElementById('nivel_').value;
	var data = document.getElementById('data_').value;
	var sexo = document.getElementById('sexo_').value;
	var instrumento = document.getElementById('instrumento_').value;
	
	erro = new String;	
	
	if(cidade =='' || cidade =='CIDADE:' )
	{
		erro += "DIGITE SUA CIDADE! \n";	
	}
	
	if(estado =='')
	{
		erro += "ESCOLHA SEU ESTADO! \n";	
	}
	if(nivel=='')
	{
		erro += "ESCOLHA SEU NIVEL! \n";	
	}
	if(sexo=='')
	{
		erro += "ESCOLHA O SEXO! \n";	
	}
	if(instrumento=='')
	{
		erro += "ESCOLHA SEU INSTRUMENTO! \n";	
	}	
	if(data=='')
	{
		erro += "DIGITE SEU DATA DE NASCIMENTO \n";
	}
	if(data.length>10)
	{
		erro += "DATA DE NASCIMENTO INCORRETA\n";
	}
	
	if (erro.length > 0)
	{
		alert('Preencha os campos abaixo:\n\n'+erro);
	}else{
		
		var url = 'tipo=completaCadastro&cidade='+cidade+'&estado='+estado+'&nivel='+nivel+'&instrumento='+instrumento+'&data='+data+'&sexo='+sexo
		enviaAjax(url,'#cadastroUser',"2");
 
	}
	
}

function completaCadastro2()
{
 
	var cidade = document.getElementById('cidade_').value;
	var estado = document.getElementById('uf').value;
	var nivel = document.getElementById('nivel_').value;
	var data = document.getElementById('data_').value;
	var sexo = document.getElementById('sexo_').value;
	var cupom = document.getElementById('codigo_').value;
	var instrumento = document.getElementById('instrumento_').value;
	
	erro = new String;	
	
	if(cidade =='' || cidade =='CIDADE:' )
	{
		erro += "DIGITE SUA CIDADE! \n";	
	}
	
	if(estado =='')
	{
		erro += "ESCOLHA SEU ESTADO! \n";	
	}
	if(nivel=='')
	{
		erro += "ESCOLHA SEU NIVEL! \n";	
	}
	if(sexo=='')
	{
		erro += "ESCOLHA O SEXO! \n";	
	}
	if(instrumento=='')
	{
		erro += "ESCOLHA SEU INSTRUMENTO! \n";	
	}	
	if(data=='')
	{
		erro += "DIGITE SEU DATA DE NASCIMENTO \n";
	}
	if(data.length>10)
	{
		erro += "DATA DE NASCIMENTO INCORRETA\n";
	}
	
	if (erro.length > 0)
	{
		alert('Preencha os campos abaixo:\n\n'+erro);
	}else{
		
		var url = 'tipo=completaCadastro2&cidade='+cidade+'&estado='+estado+'&nivel='+nivel+'&instrumento='+instrumento+'&data='+data+'&sexo='+sexo+'&cupom='+cupom
		enviaAjax(url,'#alvo',"2");
 
	}
	
}


function completaCadastro3()
{
 

	var cidade = document.getElementById('cidade_').value;
	var estado = document.getElementById('uf').value;
	var nivel = document.getElementById('nivel_').value;
	var data = document.getElementById('data_').value;
	var sexo = document.getElementById('sexo_').value;
	var ativa_codigo = document.getElementById('ativa_codigo_').value;
	var instrumento = document.getElementById('instrumento_').value;

	erro = new String;	
	if(cidade =='' || cidade =='CIDADE:' )
	{
		erro += "DIGITE SUA CIDADE! \n";	
	}
	
	if(ativa_codigo=='s')
	{
		var cupom = document.getElementById('codigo_').value;
	}else{
		var cupom = 'nada';
	}
	
	if(estado=='')
	{
		erro += "ESCOLHA SEU ESTADO! \n";	
	}
	if(nivel=='')
	{
		erro += "ESCOLHA SEU NIVEL! \n";	
	}
	if(sexo=='')
	{
		erro += "ESCOLHA O SEXO! \n";	
	}
	if(instrumento=='')
	{
		erro += "ESCOLHA SEU INSTRUMENTO! \n";	
	}	
	if(data=='')
	{
		erro += "DIGITE SEU DATA DE NASCIMENTO \n";
	}
	if(data.length>10)
	{
		erro += "DATA DE NASCIMENTO INCORRETA\n";
	}
	
	if (erro.length > 0)
	{
		alert('Preencha os campos abaixo:\n\n'+erro);
	}else{
 
		var url = 'tipo=completaCadastro2&cidade='+cidade+'&estado='+estado+'&nivel='+nivel+'&instrumento='+instrumento+'&data='+data+'&sexo='+sexo+'&cupom='+cupom
		enviaAjax(url,'#alvo',"2");
 
	}
 
}


function indicar()
{
	var email_1 = id('indique_1').value;
	var email_2 = id('indique_2').value;
	var email_3 = id('indique_3').value;
	erro = new String;
	
	if(email_1!='E-MAIL:')
	{
		if(email_1!='')
		{
			if (email_1.indexOf('@', 0) == -1 || email_1.indexOf('.', 0) == -1)
			{ 
				erro += 'PRIMEIRO CAMPO DE E-MAIL PARECE SER INVALIDO!\n';
			}
		}else{
			erro += 'PREENCHA O PRIMEIRO CAMPO E-MAIL!\n';
		}
	}
	
	if(email_2!='E-MAIL:')
	{
		if(email_2!='')
		{
			if (email_2.indexOf('@', 0) == -1 || email_2.indexOf('.', 0) == -1)
			{ 
			erro += 'SEGUNDO CAMPO DE E-MAIL PARECE SER INVALIDO!\n';
			}
		}else{
			erro += 'PREENCHA O SEGUNDO CAMPO E-MAIL!\n';
		}
		
	}
	
	if(email_3!='E-MAIL:')
	{
		if(email_3!='')
		{
			if (email_3.indexOf('@', 0) == -1 || email_3.indexOf('.', 0) == -1)
			{ 
			erro += 'TERCEIRO CAMPO DE E-MAIL PARECE SER INVALIDO!\n';
			}
		}else{
			erro += 'PREENCHA O TERCEIRO CAMPO DE E-MAIL!\n';
		}
	}
	
	if(email_1=='' && email_2=='' && email_3=='')
	{
		erro += 'PREENCHA PELO MENOS 1 CAMPO!\n';
	}

	if(email_1=='E-MAIL:' && email_2=='E-MAIL:' && email_3=='E-MAIL:')
	{
		erro += 'PREENCHA PELO MENOS 1 CAMPO!\n';
	}
	
	
	if (erro.length > 0)
	{
		alert(erro);
	}
	else
	{
		var url = 'tipo=indicar&email[]='+email_1+'&email[]='+email_2+'&email[]='+email_3;
		enviaAjax(url,'#alvo',"2");	
	}
}


function addSWF (URL, WIDTH, HEIGHT, TRANSPARENT)
{
document.write (' <object classid="clsid:27CDB6E-AE6D-11cf-96B8-444553540000" ');
document.write (' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" ');
document.write (' width="'+ WIDTH +'" height="'+ HEIGHT +'">');
document.write (' <param name="movie" value="'+ URL +'" />');
document.write (' <param name="quality" value="high" />');

if ( TRANSPARENT ) {
  document.write (' <param name="Wmode" value="Transparent" />'); 
}

document.write (' <embed src="'+ URL +'" quality="high" ');

if ( TRANSPARENT ) {
document.write (' Wmode = "transparent" ');
}

document.write (' pluginspage="http://www.macromedia.com/go/getflashplayer" ');
document.write (' type="application/x-shockwave-flash" width="'+ WIDTH +'" height="'+ HEIGHT +'"></embed> ');
document.write (' </object>');
}



function teste()
{
	var indico = document.getElementById("indico").value;
	erroE = new String;
 
                var arrayPrincipal = indico.split(';');
                var content = '';
                var array = new Array(new Array(4), new Array(4), new Array(4), new Array(4), new Array(4), new Array(4));
                for (i = 0; i < arrayPrincipal.length; i++) {
                        subArray = arrayPrincipal[i].split(',');                         
                        for (t = 0; t < subArray.length; t++) {
                                array[t][i] = subArray[t];
                                content += array[t][i]+'\n'; 
 
										if (array[t][i].indexOf('@', 0) == -1 || array[t][i].indexOf('.', 0) == -1){ 
										erroE += array[t][i]+'\n';
										}
 

                        }
                }
				
				if (erroE.length > 0)
				{
					if(confirm("Os Seguintes, emails estão errados\n\nDeseja Enviar assim mesmo?\n\n"+erroE)==true)
					{
						alert('ok confirmado');
					} 
				} 

}

function logMe(campo)
{
	var email = id(campo).value;
	if (email.indexOf('@', 0) == -1 || email.indexOf('.', 0) == -1){ 
		alert("E-MAIL INVALIDO\nINSIRA SEU E-MAIL DE CADASTRO!");	
	}else{
		var url = 'tipo=logMe&email='+email;
		enviaAjax(url,'#alvo',"2");
	}	

}

function cadastro()
{
	var nome = document.getElementById('nome_').value;
	var email = document.getElementById('email_').value;
	var outro = document.getElementById('copia_email').value;
 
	erro = new String;
	if(nome=='' || nome=='Nome')
	{
		erro += "NOME! \n";
	}else if(nome.length<4)
	{
		erro += "CAMPO NOME MINIMO 4 CARACTERES! \n";
	}else if(email!=outro)
	{
	erro += "E-MAILS NAO CONFEREM! \n";
	}
	
	if(email !=""){
		if (email.indexOf('@', 0) == -1 || email.indexOf('.', 0) == -1){ 
		erro += "DIGITE UM EMAIL VALIDO! \n";	
		}
	}
	
	if (erro.length > 0)
	{
		alert('Preencha os campos abaixo:\n\n'+erro);
	}
	else
	{
		var url = 'tipo=novoCadastro&nome='+nome+'&email='+email;
		enviaAjax(url,'#alvo_principal');
		 
	}
	

}


function cadastro2()
{
	var nome = document.getElementById('2nome_').value;
	var email = document.getElementById('2email_').value;
 
 
	erro = new String;
	if(nome=='' || nome=='Nome')
	{
		erro += "NOME! \n";
	}else if(nome.length<4)
	{
		erro += "CAMPO NOME MINIMO 4 CARACTERES! \n";
	}
	
	if(email !=""){
		if (email.indexOf('@', 0) == -1 || email.indexOf('.', 0) == -1){ 
		erro += "DIGITE UM EMAIL VALIDO! \n";	
		}
	}
	
	if (erro.length > 0)
	{
		alert('Preencha os campos abaixo:\n\n'+erro);
	}
	else
	{
		var url = 'tipo=novoCadastro&nome='+nome+'&email='+email;
		enviaAjax(url,'#dival');
		 
	}
	

}

function download(chave,key)
{
	document.postando.c.value = chave+'||'+key;
	document.postando.action = './baixa';
	document.postando.submit();
}

function baixarEdicao(chave,key)
{
	document.forms["postando"].c.value= chave+'||'+key;
	document.forms["postando"].action= "./baixa";
    document.forms["postando"].submit();
}


function twitter()
{
var url = 'tipo=twitter';
enviaAjax(url,'#loadTwitter',"3");
}









function enviaAjaxx(url,div,tipo)
{
	
if(tipo=='1')
{
	$(div).ajaxStart(function(){
	  $(div).append("<center><img src='arquivos/images/loading.png' border='0' align='center' />");
	});
	
}else if(tipo=='2'){
$().ajaxStart(function() { $('#alvo').show(); });
 
}else{
$(div).append("aguarde verificando...");
}

		$.ajax({
			type: 'GET',
			url: 'arquivos/pages/ajax.php',
			data: url,
				success: function( data )
					{
						$(div).html(data);
						$().ajaxStop(function() { $('#alvo').hide(); });
						}
					});

}

function entreContato(frm)
{
	erro = new String;
	
	var nome = document.getElementById('nome_').value;
	var email = document.getElementById('email_').value;
	var assunto = document.getElementById('assunto_').value;
	var mensagem = document.getElementById('mensagem_').value;

	if(nome=='' || nome=='NOME:')
	{
		erro += "SEU NOME! \n";
	}
	
	if(email !=""){
		if (email.indexOf('@', 0) == -1 || email.indexOf('.', 0) == -1){ 
		erro += "DIGITE UM EMAIL VALIDO! \n";	
		}
	}
	if(assunto=='' || assunto=='ASSUNTO:')
	{
		erro += "O ASSUNTO! \n";
	}
	
	if(mensagem=='' || mensagem=='MENSAGEM:')
	{
		erro += "SUA MENSAGEM! \n";
	}
	
	if (erro.length > 0)
	{
		alert('Preencha os campos abaixo:\n\n'+erro);
	}else{
		var tipo = frm =='contato'?'contato':'suporte';
		var url = 'tipo=entreContato&nome='+nome+'&email='+email+'&assunto='+assunto+'&mensagem='+mensagem+'&form='+tipo;
		enviaAjax(url,'#cadastro',"2");
 
	}
	
	
}

function enviar()
{
	
var nome = document.getElementById('nome_').value;
var email = document.getElementById('email_').value;

var chama = "";

erro = new String;

if(nome=='' || nome=='NOME')
{
	erro += "SEU NOME! \n";
}


if(email !=""){
	if (email.indexOf('@', 0) == -1 || email.indexOf('.', 0) == -1){ 
	erro += "DIGITE UM EMAIL VALIDO! \n";	
	}
}


/********************/
 
	erroE = new String;
 	erroErrado = new String;
 	erroCerto = new String;
 	
                var arrayPrincipal = indico.split(';');
                var content = '';
                var array = new Array(new Array(4), new Array(4), new Array(4), new Array(4), new Array(4), new Array(4));
                for (i = 0; i < arrayPrincipal.length; i++) {
                        subArray = arrayPrincipal[i].split(',');                         
                        for (t = 0; t < subArray.length; t++) {
                                array[t][i] = subArray[t];
                                content += array[t][i]+'\n'; 
 
										if (array[t][i].indexOf('@', 0) == -1 || array[t][i].indexOf('.', 0) == -1){ 
										erroE += array[t][i]+'\n';
										erroErrado += array[t][i]+',';
										}else{
										erroCerto += array[t][i]+',';
										}
 

                        }
                }
				
				if (erro.length > 0)
				{
					alert('Preencha os campos abaixo:\n\n'+erro);
				}
				else
				{
					chama = 1;
				}
				 
				 
				if(chama == 1)
				{
					if(indico!='INDICO PARA*')
					{
						if (erroE.length > 0)
						{
							if(confirm("Os Seguintes, emails estão errados\n\nDeseja Enviar assim mesmo?\n\n"+erroE)==true)
							{
								envia(nome,email,erroErrado,erroCerto);
							} 
						}else{
								envia(nome,email,erroErrado,erroCerto);
						}
					}
					else
					{
						envia(nome,email,erroErrado,erroCerto);
					}
					
				}





}

 

function id( id ){ 
        return document.getElementById( id );
} 


function envia(nome,email,erro,certo){
	
	var conteudo = document.getElementById('mostra');
	var url = 'lib/conecta.php?acao=addCadastro2&nome='+nome+'&email='+email+'&erro='+erro+'&certo='+certo;	  
	conteudo.innerHTML='Verificando s';
 					
						conteudo.innerHTML='Buscando dados';
                        x.open('GET',url);
                        x.onreadystatechange=stateChangedC;
                        x.send(null);
						document.getElementById('1').value="";	
						
}
function stateChangedC(){
        if( x.readyState == 4 ){
                //alert( x.responseText );
                id('mostra').innerHTML = x.responseText;
        }
}

function logar(div)
{
	var email = document.getElementById('login').value;

	$.ajax({
	type: 'GET',
	url: 'lib/conecta.php?acao=logar&email='+email,
	data: email,
		success: function(data)
			{
				$("#alvo").html(data);
				//alert('op');
			}
		});	
	

}
function enter2(evento)
{
  tecla = evento.keyCode;
        if(tecla == 0)
        {
                tecla = evento.charCode;
        }
        if(tecla == 13)
        {
               logaMe();
        }
}



/***/
function modal()
{
 		var id = "#dialog";		
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();	
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		$('#mask').fadeIn(500);	
		$('#mask').fadeTo("slow",0.9);		
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();              
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);	
		$(id).fadeIn(500); 

	
	$('.window .close').click(function (e) {
		e.preventDefault();
		window.location = './edicao';		
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
		window.location = './edicao';	
	});			
	
}

function addSWF (URL, WIDTH, HEIGHT, TRANSPARENT)
{
document.write (' <object classid="clsid:27CDB6E-AE6D-11cf-96B8-444553540000" ');
document.write (' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" ');
document.write (' width="'+ WIDTH +'" height="'+ HEIGHT +'">');
document.write (' <param name="movie" value="'+ URL +'" />');
document.write (' <param name="quality" value="high" />');

if ( TRANSPARENT ) {
  document.write (' <param name="Wmode" value="Transparent" />'); 
}

document.write (' <embed src="'+ URL +'" quality="high" ');

if ( TRANSPARENT ) {
document.write (' Wmode = "transparent" ');
}

document.write (' pluginspage="http://www.macromedia.com/go/getflashplayer" ');
document.write (' type="application/x-shockwave-flash" width="'+ WIDTH +'" height="'+ HEIGHT +'"></embed> ');
document.write (' </object>');

}
