// JavaScript Document
var openCad = 0;

$(document).ready(function() {
	/* floater ronaldo */
	$("a.um").bind("mouseover", function(){ $('#balaoUm').fadeIn(300);
		$('#balaoDois').fadeOut(150);
		$('#balaoTres').fadeOut(150); 																 
	});

	$("a.um").bind("mouseleave", function(){ $('#balaoUm').fadeOut(150); });
	

	$("a.dois").bind("mouseover", function(){ $('#balaoDois').fadeIn(300);
		$('#balaoUm').fadeOut(150);
		$('#balaoTres').fadeOut(150); 																 
	});

	$("a.dois").bind("mouseleave", function(){ $('#balaoDois').fadeOut(150); });
	
	
	$("a.tres").bind("mouseover", function(){ $('#balaoTres').fadeIn(300);
		$('#balaoUm').fadeOut(150);
		$('#balaoDois').fadeOut(150); 																 
	});

	$("a.tres").bind("mouseleave", function(){ $('#balaoTres').fadeOut(150); });
	
   if(screen.width <= 800) {
		$("#divConteinerGeral").width($(document).width());
		$("#containerDireitos").width($(document).width());
		$("#divRodape").width($(document).width());
   }
   $('#promo-camisa-lightbox').hide();
	/*if($('#divMascaraDestaque').flash){
		$('#divMascaraDestaque').flash({
			src: 'Util/swf/DestaqueEventos.swf',
			width: 525,
			height: 360,
			version: 9,
			expressInstall: true,
			wMode: 'transparent',
			id: 'swfEventos',
			allowScriptAccess: 'sameDomain',
			swliveconnect: "true"
		});
	}*/
	

	/*if($('#divMascaraDestaquePromocao').flash){
		$('#divMascaraDestaquePromocao').flash({
			src: 'Util/swf/DestaquePromocoes.swf',
			width: 525,
			height: 360,
			version: 9,
			expressInstall: true,
			wMode: 'transparent',
			id: 'swfPromocoes',
			allowScriptAccess: 'sameDomain',
			swliveconnect: "true"
		});
	}*/
							
    //Funcões Básicas

    /* Target hack - para Strict */
    $('a.blank').click(function() {
        $(this).attr("target", "_blank");
    });

    $('a.self').click(function() {
        $(this).attr("target", "_self");
    });

    $('a.parent').click(function() {
        $(this).attr("target", "_parent");
    });

    /* Limpa o Input ao clicar */
    $('input:text').focus(function() {
        if ($(this).val() == $(this).attr("title")) {
            $(this).val("");
            if ($(this).hasClass("password")) {
                $(this).attr("type", "password");
            }
            $(this).bind("blur", function() {
                if ($(this).val() == '') {
                    if ($(this).hasClass("password")) {
                        $(this).attr("type", "text");
                    }
                    $(this).val($(this).attr("title"));
                }
            });
        }
    });

    // Ancoras
    $("#divAncoras a").click(function() {
        var e = $(this).attr("href");
        $(window).scrollTop($(e).offset().top + 30);
        return false;
    });
	
	//Scroll Personalizado
	$(".divScrollTexto").jScrollPane({
	   scrollbarWidth:17,
	   scrollbarMargin:10,
	   showArrows:true,
	   animateTo:true,
	   wheelSpeed:20
	});
	
	$("#containerScroll").jScrollPane({
	   scrollbarWidth:8,
	   scrollbarMargin:10,
	   showArrows:true,
	   animateTo:true,
	   wheelSpeed:20
	});
	
	$("#termos-scroll").jScrollPane({
		scrollbarWidth:8,
		scrollbarMargin:10,
		showArrows:true,
		animateTo:true,
		wheelSpeed:20
	});
	
	$("#conteudoScroll").jScrollPane({
		scrollbarWidth:20,
		scrollbarMargin:10,
		showArrows:true,
		animateTo:true,
		wheelSpeed:20
	});
	
	$("#boxRegulamento").jScrollPane({
		scrollbarWidth:20,
		scrollbarMargin:10,
		showArrows:true,
		animateTo:true,
		wheelSpeed:20
	});
		
	/*$('.listaEventos a').click(function(e){
		var flash = getFlashMovieObject('swfEventos');
		var p = $(this).parent().parent();
		var titulo = $('h4 a', p).text();
		var data = $('p:eq(0) a', p).text();
		var local = $('p:eq(1) a', p).text();
		var desc = $('p.descricao', p).text();
		var imagem = $('span.imagem', p).text();
		var urlink = $('span.link', p).text();
		var descricao = data +" - "+ local +" - "+ desc;

		flash.novoDestaque("http://guarananovoportal.tv1.com.br"+imagem, titulo, descricao, urlink);
		e.preventDefault();
	});

	$('.listaPromocoes a').click(function(e){
		var flash = getFlashMovieObject('swfPromocoes');
		var p = $(this).parent().parent();
		var titulo = $('h4 a', p).text();
		var data = $('p:eq(0) a', p).text();
		var local = $('p:eq(1) a', p).text();
		var desc = $('p.descricao', p).text();
		var imagem = $('span.imagem', p).text();
		var urlink = $('span.link', p).text();
		var descricao = data +" - "+ local +" - "+ desc;
		flash.novoDestaque("http://guarananovoportal.tv1.com.br"+imagem, titulo, descricao, urlink);
		e.preventDefault();
	});*/
	
	/* AUMENTAR COLUNA GUARANAUTAS */
	var alturaEsquerda = $(".divLadoEsquerdo").height();
	var alturaDireita = $('.divLadoDireito').height();
	if(alturaEsquerda > alturaDireita)
	{
		$(".divLadoDireito .overlay").css("height", alturaEsquerda);
	}
	else if(alturaDireita > alturaEsquerda)
	{
		$(".divLadoEsquerdo .overlay").css("height", alturaDireita);	
	}	
	
	/* FORMULA SECRETA - EXPANDIR BOX */
	$('a.expande').click(function(){
		bloco = $(this).parent().parent().find('div.quadro_aviso');
		novaAltura =  $(this).parent().parent().find('div.quadro_aviso').height();
		marginElemento = $(this).parent().css('top').replace('px', '');
		
		teste = parseInt(marginElemento)
		novaMarginElemento = (parseInt(novaAltura) + parseInt(marginElemento)+ 25);
		imagem = $(this).find('img')
		imagemSrc = $(this).find('img').attr('src');
		
		if(bloco.css("display") == "none"){
			$(bloco).slideToggle("slow");
			//$(bloco).show();
			$(this).parent().css('top', novaMarginElemento + 'px');
			novaImagem = imagemSrc.replace('mais' , 'menos');
			imagem.attr('src', novaImagem);
		}
		else{
			$(bloco).slideToggle("slow");
			//$(bloco).hide();
			$(this).parent().css('top', '192px');
			novaImagem = imagemSrc.replace('menos' , 'mais');
			imagem.attr('src', novaImagem);
		}
	});
	
	
	$(".boxInfograficos").click(function(){
		openInfo2($('div a',this).attr('href'));
	});
	
	$(".boxInfograficos").click(function(){
		openInfo2($('div a',this).attr('href'));
	});

	$("a.tipbalao").hover(
		function () {
			$(this).parent().siblings().css("z-index","1");
			$(this).parent().css("z-index","9999");
		}
	);
	
	//GA MUNDO
    $('a.openModal').click(function() {
	    var idDiv = $(this).attr('rel');
	    openLightBoxCentered(idDiv);
	    
	    if (idDiv == "#divSegundoCadastro") {
	        initializeCadastro();
	    }    		
    });
    
    $('a.openRegulamento').click(function() {
        closeLightBox();	        
        openLightBoxCentered("#divRegulamento");
    });
    
    $('img.fechaRegulamento').click(function() {	        
        closeLightBox();	        
        openLightBoxCentered("#divSegundoCadastro");
    });
    
    $('a.openDuvidasCadastro').click(function() {
        closeLightBox();
        openLightBoxCentered("#divDuvidas");
        openCad = 1;
    });
    
    $('#lkFechaDuvidas').click(function() { 
        closeLightBox();
        if (openCad == 1) {
            openLightBoxCentered("#divSegundoCadastro");
            openCad = 0;
        }
    });
    
    // END - SIMPLE MODAL JQUERY
	
    $('.close').click(function(){
	    closeLightBox();
   });
		
    $('.window').hide();
    
    $(document).keydown(function(e) {
        // ESCAPE key pressed
        if (e.keyCode == 27) {
            closeLightBox();
            openCad = 0;
        }
    });

    // FIM GA MUNDO
});

//GA MUNDO
function openLightBoxCentered(idDiv)
{
    var maskHeight = $('#divConteinerGeral').height() + $('#containerApoio').height() + $('#containerTags').height() + $('#containerDireitos').height();
    var maskWidth = $('#divConteinerGeral').width();
    
    $('#mask').css({
        'width':maskWidth,
        'height':maskHeight,
        'background' : '#000',
        'opacity' : 0.6,
        'cursor' : 'pointer'
    });

    $('#mask').fadeIn();

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();
      
    $(idDiv).css('top', '100'+'px');
    $(idDiv).css('left', winW/2-$(idDiv).width()/2);

    $(idDiv).fadeIn(); 
}

function closeLightBox()
{
    $('.window').fadeOut();	
    $('#mask').fadeOut();
}

function openLightBoxArquivo(idL, imagem)
{
    $("#tituloArquivo").text(locations[idL].titulo);
    $("#nomeArquivo").text(locations[idL].nome);
    $("#imgFoto").attr("style", "display:none");
    $("#embedVideo").attr("style", "display:none");
    if (locations[idL].comentarios.length > 0) { 
        $("#comentariosArquivo").html(textToHtml(locations[idL].comentarios)).attr("style", "display:block"); 
    }
    
    if (imagem) {
        $("#imgFoto").attr("src", locations[idL].foto).attr("alt", locations[idL].titulo).attr("style", "display:block");
        
    } else {
		$("#embedVideo").html(textToHtml(locations[idL].video)).attr("style", "display:block");
    }
    
    openLightBoxCentered("#lightBoxLista");    
}

//FIM GA MUNDO

$(window).load(function() {
	//$(".listaEventos:eq(0) a:eq(0)").click();	
	//$(".listaPromocoes:eq(0) a:eq(0)").click();	
});

function abreLigthbox(){
	alturaLightboxConteudo = $('#divConteinerGeral').height();
	alturaLightboxRodape = $('#divRodape').height();
	alturaLightbox = alturaLightboxConteudo + alturaLightboxRodape + 82;
	$(".boxOverlay").css('height',alturaLightbox);
	
	$(".boxOverlay, .lightbox").fadeIn('fast');
	$(".boxOverlay").animate({opacity: 0.8}, 100);
	$(".divFrame").append('<iframe frameborder="0" scrolling="no" src="fale-conosco.aspx" class="idFrame" id="frameContato"></iframe>');
	$(".divBoxVideo").css('visibility','hidden');
	
	return false;
}

function abreLigthboxRealidade(){
	alturaLightboxConteudo = $('#divConteinerGeral').height();
	alturaLightboxRodape = $('#divRodape').height();
	alturaLightbox = alturaLightboxConteudo + alturaLightboxRodape + 82;
	$(".boxOverlay").css('height',alturaLightbox);
	
	$(".boxOverlay, .lightboxRealidade").fadeIn('fast');
	$(".boxOverlay").animate({opacity: 0.8}, 100);
	$(".divBoxVideo").css('visibility','hidden');
	
	return false;
}

function fechaLighBox(){
	$(".boxOverlay, .lightbox").fadeOut('slow');
	$(".divBoxVideo").css('visibility','visible');
	$("#frameContato").attr("src", "fale-conosco.aspx");
	return false;
}

function fechaLighBoxRealidade(){
	$(".boxOverlay, .lightboxRealidade").fadeOut('slow');
	$(".divBoxVideo").css('visibility','visible');
	return false;
}

function getFlashMovieObject(movieName) {
	if (window.document[movieName]) {
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1) {
		if (document.embeds && document.embeds[movieName]) return document.embeds[movieName]; 
	}
	else {
		return document.getElementById(movieName);
	}
}

function toggle(i) {
	if($(i).is(":hidden")) $(i).show();
	else $(i).hide();
}

function flashNovoDestaque(arquivo, titulo, texto, link){
	var flash = getFlashMovieObject('swfPromocoes');
	while(!flash.novoDestaque || flash.novoDestaque == 'undefined'){
		setTimeout(function(){flashNovoDestaque(arquivo, titulo, texto, link)},"1000");
		return;
	}

	flash.novoDestaque(arquivo, titulo, texto, link);

}

function flashNovaMusica(arquivo, musica, artista, disco, autoplay){

	var flash = getFlashMovieObject('PlayerMusica');
	while(!flash.novaMusica || flash.novaMusica == 'undefined'){
		setTimeout(function(){flashNovaMusica(arquivo, musica, artista, disco, autoplay)},"1000");
		return;
	}

	flash.novaMusica(arquivo, musica, artista, disco, autoplay);

}

/* CADASTRO LIGHTBOX */
function abreLigthboxCadastro(){
	alturaLightboxConteudo = $('#divConteinerGeral').height();
	alturaLightboxRodape = $('#divRodape').height();
	alturaLightbox = alturaLightboxConteudo + alturaLightboxRodape + 82;
	$(".boxOverlay").css('height',alturaLightbox);
	
	$(".boxOverlay, .lightboxCadastro").fadeIn('fast');
	$(".boxOverlay").animate({opacity: 0.8}, 100);
	$(".divFrameCadastro").append('<iframe frameborder="0" allowtransparency="true" scrolling="no" src="/cadastro-portal.aspx" height="222" class="idFrameCadastro" id="frameCadastro"></iframe>');
	$(".divBoxVideo").css('visibility','hidden');
	
	return false;
}

function fechaLighBoxCadastro(){
	$(".boxOverlay, .lightboxCadastro").fadeOut('slow');
	$(".divBoxVideo").css('visibility','visible');
	$("#frameCadastro").attr("src", "cadastro-portal.aspx");
	return false;
}

/* light do ronaaaaldo */

function abreLightboxRonaldo(){
	$(".boxOverlay, .lightboxRonaldo").fadeIn('fast');
	$(".boxOverlay").animate({opacity: 0.8}, 100);
	return false;
}

function fechaLighBoxRonaldo(){
	$(".boxOverlay, .lightboxRonaldo").fadeOut('slow');
	return false;
}

function AbrirPopup(url)
{
    window.open(url, 'game', 'status=0, toolbar=1, location=1, menubar=1, width=822, height=531, scrollbars=1, resizable=0');
}

function openInfo(e)
{
	window.open(e.href, "Fase1", "toolbar=no, location=no,status=no, menubar=no,width=984,height=475");
	//alert(e.href);
	return false;
}

function openInfo2(eHref)
{
	window.open(eHref, "Fase1", "toolbar=no, location=no,status=no, menubar=no,width=984,height=475");
	return false;
}
//abrir();

function linkBoxInfograficos() {
	boxInfo = document.getElementsByTagName('div');
}

//INÍCIO: COPA - CADASTRO
jQuery(function($){
	$("#ctl00_ctl00_ctl00_ctl00_ContentPlaceHolderDefault_ConteudoGeral_ConteudoGeralApoio_CadastroCopaDe2010_1_txtDataNascimento").mask("99/99/9999");
});

function calcularIdade(dataNasc){
	var dataNasc = dataNasc.split("/");
	var nascDia = dataNasc[0];
	var nascMes = dataNasc[1];
	var nascAno = dataNasc[2];
	
	var dataAtual = new Date();
	var dia = dataAtual.getDate();
	var mes = dataAtual.getMonth()+1;
	var ano = dataAtual.getFullYear();
	
	var idade = ano - nascAno;

	if(dia >= nascDia && mes >= nascMes) {
		return idade;
	}
	else {
		return idade - 1;
	}
}

function verificarIdade(inputDataNasc) {
	var idade = calcularIdade(inputDataNasc.value);
	if(idade < 18) {
		$("#ctl00_ctl00_ctl00_ctl00_ContentPlaceHolderDefault_ConteudoGeral_ConteudoGeralApoio_CadastroCopaDe2010_1_camposparamenores").removeClass("hidden");
	}
	else {
		if(!$("#ctl00_ctl00_ctl00_ctl00_ContentPlaceHolderDefault_ConteudoGeral_ConteudoGeralApoio_CadastroCopaDe2010_1_camposparamenores").hasClass("hidden")) {
			$("#ctl00_ctl00_ctl00_ctl00_ContentPlaceHolderDefault_ConteudoGeral_ConteudoGeralApoio_CadastroCopaDe2010_1_camposparamenores").addClass("hidden");
		}
	}
	return false;
}

//Função para validação de caracteres
function only(t, o, e) {
    if (window.event) {
        key = window.event.keyCode;
    } else if (e) {
        key = e.which;
    } else {
        return true;
    }
    S = o ? o : "";
    if (t == "num" || t == "number" || t == "numeric") {
        S += "0123456789";
    }
    if (t == "data") {
        S += "0123456789/";
    }
    if (t == "tel") {
        S += "0123456789()- ";
    }
    if (t == "valor") {
        S += "0123456789.,";
    }
    if (t == "alnum" || t == "alphanumeric") {
        S += "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\xE1\xE0\xE3\xE2\xE4\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF3\xF2\xF5\xF4\xF6\xFA\xF9\xFB\xFC\xE7\xC1\xC0\xC3\xC2\xC4\xC9\xC8\xCA\xCB\xCD\xCC\xCE\xCF\xD3\xD2\xD5\xD4\xD6\xDA\xD9\xDB\xDC\xC7 0123456789";
    }
    if (t == "let" || t == "letters") {
        S += "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\xE1\xE0\xE3\xE2\xE4\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF3\xF2\xF5\xF4\xF6\xFA\xF9\xFB\xFC\xE7\xC1\xC0\xC3\xC2\xC4\xC9\xC8\xCA\xCB\xCD\xCC\xCE\xCF\xD3\xD2\xD5\xD4\xD6\xDA\xD9\xDB\xDC\xC7 ";
    }
    if (t == "rest" || t == "restrict") {
        S += "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    }
    if (t == "email") {
        S += "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@-_.";
    }
    
    if (key == null || ((t != "nothing") && (key == 0 || key == 8 || key == 9 || key == 13 || key == 27))) {
        return true;
    } else if (S.indexOf(String.fromCharCode(key)) != -1) {
        return true;
    } else {
        return false;
    }
}

function isEmail(email) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(email);
}

function textToHtml(text)
{
    return text.replace(/&lt;{1}/gi,"<").replace(/&amp;lt;{1}/gi,"<").replace(/&gt;{1}/gi,">").replace(/&amp;gt;{1}/gi,">");
}
function htmlToText(text)
{
    return text.replace(/<{1}/gi,"&lt;").replace(/>{1}/gi,"&gt;");
}
function jump(limit, idField, idNextField)
{
    if (document.getElementById(idField) && document.getElementById(idField).value.length == limit)
    {
        if (document.getElementById(idNextField))
        {
            document.getElementById(idNextField).focus();
        }
    }
}

//FIM: COPA - CADASTRO



