var totalaba = 0
var chamadoatual="";


 setInterval ( function() {document.title = "Festa Supra Sumo"; }, 2000 );

	function pageload(hash) {
		
		
		
		if (chamadoatual==hash) { $('.carregando').fadeOut(); return false; }
		
		chamadoatual = hash;
		
		
		if(hash) {
			if(hash.indexOf('=')==-1){
				hash = hash+".php";
			} else {
				hash = hash.replace('?', '.php?');
				hash = hash.replace('.php.php?', '.php?')
			}
			

			

			$('.inferior').load(hash, function() {
				
				$('.carregando').fadeOut();
				$('.inferior').corner("top 10px");
				
				Shadowbox.clearCache(); // <= clear Shadowbox's cache 
				Shadowbox.setup()

				var _gaq = _gaq || [];
			  _gaq.push(['_setAccount', 'UA-2765444-1']);
			  _gaq.push(['_trackPageview']);
			
			  (function() {
				var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
				ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
				var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
			  })();
						
				$(".linkhome").click(function(){
							$('.carregando').fadeIn();
							var hash = this.href;
							hash = hash.replace(/^.*#/, '');
							$.historyLoad(hash);
							return false;
						});

				
			});
			
			/*
			$.ajax({
			  url: hash,
			  cache: false,
			  async: true,
			  queue: "carregamento",
			  cancelExisting: true,
			  success: function(data) {
				  
				 	$('.carregando').fadeOut();
					$('.inferior').html(data);
				

				Shadowbox.clearCache(); // <= clear Shadowbox's cache 
				Shadowbox.setup()
				$jScroller.add("#sn","#sn2","up",2);
				$jScroller.start();
				
				
				
				
						$(".linkhome").click(function(){

							$('.carregando').fadeIn();

							var hash = this.href;
							
							hash = hash.replace(/^.*#/, '');
							$.historyLoad(hash);
							return false;
						});
				
				
			  }
			});
		*/
	}}
	
	
	$(document).ready(function(){
		
		$.historyInit(pageload);
		
		
		$(".linkhome").click(function(){

			$('.carregando').fadeIn();
			var hash = this.href;
			
			hash = hash.replace(/^.*#/, '');
			$.historyLoad(hash);
			return false;
		});
		
		
		$(".abaevento").click(function(){

			$('.carregando').fadeIn();
			var hash = this.title;
			hash = hash.replace(/^.*#/, '');
			$.historyLoad(hash);
			return false;
		});
		
	});
	
	
function flash(nome,WIDTH,HEIGHT)
{

var nome = nome
var WIDTH = WIDTH
var HEIGHT = HEIGHT
var texto = texto

    document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0' WIDTH='" + WIDTH + "' HEIGHT='" + HEIGHT + "' id='site novo' ALIGN=''>\n");
    document.write("<param name='movie' value='" + nome + "' />\n");
    document.write("<param name='wmode' value='transparent' />\n");
    document.write("<param name='scale' value='ExactFit' />\n");   
    document.write("<embed src='" + nome + "' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' name='obj1' width='" + WIDTH + "' height='" + HEIGHT + "'/>\n")
    
    
    
    document.write("</object>\n");
}

function cadastro(cod,id,precoporta) {
	


if (precoporta=="SD") {
	$.scrollTo('500',{duration:1000});
} else {


	$('#formcadastrodiv').show();
	$('#aguarde').hide();
	$(".cadastro").fadeIn('slow');
	$("#retnome").html(nomes[cod]);
	$("#id").val(id);
	$('.abas .abaevento').dumbCrossFade('stop')
}


//puxar dados da festa

//$('.inferior').load('evento.php?id='+id)
	
}

function fecharcadastro() {
	$('.abas .abaevento').dumbCrossFade('start');
	$('.cadastro').fadeOut('slow');
	
}

function mudaraba(aba) {
	
	for (i=0;i<totalaba;i++) {
		
		if (i==aba) {
			$('#aba_'+i).addClass('lingueta_sel')
			$('.abas .abaevento').dumbCrossFade('jump',i)
		} else {
			$('#aba_'+i).removeClass('lingueta_sel')	
		}
		
	}
	
	
	
}

function validar_email(str){
	
	
    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if(filter.test(str))
      valido = true;
    else{
      valido = false;
    }
    return valido;
  }

function Mascara(tipo, campo, teclaPress) {
        if (window.event)
        {
                var tecla = teclaPress.keyCode;
        } else {
                tecla = teclaPress.which;
        }
 
        var s = new String(campo.value);
        // Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
        s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
 
        tam = s.length + 1;
 
        if ( tecla != 9 && tecla != 8 ) {
                switch (tipo)
                {
                case 'CPF' :
                        if (tam > 3 && tam < 7)
                                campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
                        if (tam >= 7 && tam < 10)
                                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
                        if (tam >= 10 && tam < 12)
                                campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
                break;
 
                case 'CNPJ' :
 
                        if (tam > 2 && tam < 6)
                                campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
                        if (tam >= 6 && tam < 9)
                                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
                        if (tam >= 9 && tam < 13)
                                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
                        if (tam >= 13 && tam < 15)
                                campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
                break;
 
                case 'TEL' :
                        if (tam > 2 && tam < 4)
                                campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
                        if (tam >= 7 && tam < 11)
                                campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
                break;
 
                case 'DATA' :
                        if (tam > 2 && tam < 4)
                                campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
                        if (tam > 4 && tam < 11)
                                campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
                break;
                
                case 'CEP' :
                        if (tam > 5 && tam < 7)
                                campo.value = s.substr(0,5) + '-' + s.substr(5, tam);
                break;
                }
        }
}

function SomenteNumero(e){

    var tecla=(window.event)?event.keyCode:e.which;
    
		    if (tecla > 47 && tecla < 58) return true;
			if (tecla > 95 && tecla < 105) return true;
		    if (tecla != 8) return false;

}

 function validaDat(valor) {
	var date=valor;
	var ardt=new Array;
	var ExpReg=new RegExp("(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/[12][0-9]{3}");
	ardt=date.split("/");
	erro=false;
	if ( date.search(ExpReg)==-1){
		erro = true;
		}
	else if (((ardt[1]==4)||(ardt[1]==6)||(ardt[1]==9)||(ardt[1]==11))&&(ardt[0]>30))
		erro = true;
	else if ( ardt[1]==2) {
		if ((ardt[0]>28)&&((ardt[2]%4)!=0))
			erro = true;
		if ((ardt[0]>29)&&((ardt[2]%4)==0))
			erro = true;
	}
	if (erro) {
		return false;
	}
	return true;
}

function cadastrar() {
	
			if($("#nome").val()=="") { Alert("Informe o nome!"); return false; }
			if (validar_email($("#email").val())==false)  { alert('Entre com um e-mail válido!'); return false; }
	
			if ($("#aniversario").val() != "") {
				
				if (validaDat($("#aniversario").val())==false) {
						 alert('Data de nascimento inválida!'); return false;
				}
				
				
			}
		
			$('#formcadastrodiv').slideUp('fast');
			$('#aguarde').slideDown('fast');
			
			
			
			
			$.post("http://www.suprasumo.net/cadastro.php", $("#formcadastro").serialize(), function(data){ 
						if (data=="OK"){ alert('Cadastro realizado com sucesso', 'Cadastro'); $('#cadastro').slideUp();$('#dados').slideDown(); fecharcadastro(); $.scrollTo('500',{duration:1000}); 
						
						$('#nome').val('');
						$('#telefone').val('');
						$('#email').val('');
						$('#aniversario').val('');
						
						} else if(data=='duplo') { 
						
							alert('Este e-mail já está cadastrado para este evento', 'Cadastro');
							$('#formcadastrodiv').slideDown('fast');
							$('#aguarde').slideUp('fast');
						
						
						 }
						
						
			 });
	
	
}
//formsupranews


function cadastrarsn() {
	
			if($("#nome2").val()=="") { Alert("Informe o nome!"); return false; }
			if (validar_email($("#email2").val())==false)  { alert('Entre com um e-mail válido!'); return false; }
			if ($("#aniversario2").val() != "") {
				
				if (validaDat($("#aniversario2").val())==false) {
						 alert('Data de nascimento inválida!'); return false;
				}
				
				
			}
			$('#cadastrarbtn').hide();
			
			$.post("cadastro.php", $("#formsupranews").serialize(), function(data){ 
						if (data=="OK"){ alert('Cadastro realizado com sucesso', 'Cadastro');
						
						$('#nome').val('');
						$('#telefone').val('');
						$('#email').val('');
						$('#aniversario').val('');
						$('#cadastrarbtn').show(); 
						
						} else if(data=='duplo') { alert('Este e-mail já está cadastrado no supra news', 'Cadastro');  $('#cadastrarbtn').show(); }
			 });
	
	
}

function descadastrarsn() {
	
			if($("#nome2").val()=="") { Alert("Informe o nome!"); return false; }
			if (validar_email($("#email2").val())==false)  { alert('Entre com um e-mail válido!'); return false; }

			
			$.post("cadastro.php?acao=remover", $("#formsupranews").serialize(), function(data){ 
						if (data=="OK"){ alert('E-mail removido com sucesso', 'Cadastro'); $('.inferior').load('home.php'); } else { alert(data); }
			 });
	
	
}
