// JavaScript Document

function change_ingressos(change){
	var obj1 = w("ingressos_saiba_mais");
	var obj2 = w("ingressos_img");
	if(change){
		obj1.setClass("alpha_07");
		obj2.setClass("alpha_07");
	}else{
		obj1.setClass("");
		obj2.setClass("");
	}
}

var font = 11;

function f_menos(){
	if(font >= 9){
		font--;
	}
	if(document.getElementById("container_content")){
		w("container_content").style.font = font+"px Arial";
	}else if(document.getElementById("contexto")){
		w("contexto").style.font = font+"px Arial";
	}
}
function f_mais(){
	if(font <= 15){
		font++;
	}
	if(document.getElementById("container_content")){
		w("container_content").style.font = font+"px Arial";
	}else if(document.getElementById("contexto")){
		w("contexto").style.font = font+"px Arial";
	}
}


/*!
 * CooQuery v3
 * http://lenonmarcel.com.br/code/cooquery
 *
 * Copyright 2009, 2010 Lenon Marcel
 * Licensed under the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Date: 07-12-2010 (July 12, 2010)
 */

var cookie = {

    _date : function( duration )
    {
        var date = new Date();
        // 86400000 = 24 * 60 * 60 * 1000, or 1 day
        date.setTime( date.getTime() + ( duration * 86400000 ) );
        return date.toGMTString();
    },

    set : function( name, val, opts )
    {
        if (!opts) opts = {};

        var line = name + '=' + encodeURIComponent(val) +
                     ( opts.domain ? '; domain=' + opts.domain : '') +
                     ( opts.path ? '; path=' + opts.path : '' ) +
                     ( opts.duration ? '; expires=' + cookie._date(opts.duration) : '' ) +
                     ( opts.secure ? '; secure' : '' );

        return document.cookie = line;
    },

    del : function( name )
    {
        return cookie.set( name, '', { duration: -1 } );
    },

    // Based on Mootools Cookie.read function (http://mootools.net/docs/core/Utilities/Cookie#Cookie:read)
    get : function( name )
    {
        var search = document.cookie.match(
            '(?:^|;)\\s*' + name.replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1') + '=([^;]*)'
        );
        return (search) ? decodeURIComponent(search[1]) : null;
    }
};

window.onload = function(){
	if(parseInt(getPageSize()[0]) >= 1004){
		w("banners").style.display = "block";
	}

	if(document.getElementById("contato")){
		var fields = new Array("nome_" , "cidade_" , "estado_" , "telefone_" , "email_" , "msg_");

		for(i=0 ; i<w("contato").elements.length ; i++){
			if(w("contato").elements[i].type == "text"){
				w("contato").elements[i].onfocus = function(){
					w(this.id).setClass("input_focus");
				}
				w("contato").elements[i].onblur = function(){
					w(this.id).setClass("input");
				}
			}else if(w("contato").elements[i].type == "textarea"){
				w("contato").elements[i].onfocus = function(){
					w(this.id).setClass("textarea_focus");
				}
				w("contato").elements[i].onblur = function(){
					w(this.id).setClass("textarea");
				}
			}
		}

		w("contato").onsubmit = function(){
			for(i=0 ; i<fields.length ; i++){
				if(w(fields[i]).value == ""){
					w(fields[i]).focus();
					alert("Preencha todos os campos!");
					return false;
				}
			}
		}

		return true;
	}

	var form_cadastro = "cadastro_socio";
	if(document.getElementById(form_cadastro)){
		//var flds = w("form_cadastro").elements;
		var flds = w(form_cadastro).elements;
		for(i=0 ; i<flds.length ; i++){
			if(flds[i].type == 'text'){
				flds[i].onfocus = function(){
					w(this.id).setClass("input_focus");
				}
				flds[i].onblur = function(){
					w(this.id).setClass("input");
				}
			}

			switch(flds[i].id){
				case "cpf":
					w(flds[i].id).mask("999.999.999-99");
				break;

				case "telefone":
				case "celular":
					w(flds[i].id).mask("(99)9999-9999");
				break;

				case "numero":
					w(flds[i].id).mask("999999");
				break;

				case "cep":
					w(flds[i].id).mask("99999-999");
				break;

				case "rg":
					w(flds[i].id).mask("99999999999999");
				break;
			}
		}


		w(form_cadastro).onsubmit = function(){
			for(i=0 ; i<w(form_cadastro).elements.length ; i++){
				if(w(form_cadastro).elements[i].type=="text" && w(form_cadastro).elements[i].value == ""){
					alert("Você deve preencher todos os campos!");
					w(form_cadastro).elements[i].focus();
					return false;
				}
				if(w("termos_ok").checked == false){
					alert('Para concluir seu cadastro, você deve concordar com os termos de contrato!');
					return false;
				}
			}
			return true;
		}
	}


	if(document.getElementById("ingressos_img")){
			w("ingressos_img").onmouseover = w("ingressos_saiba_mais").onmouseover = function(){
				change_ingressos(true);
			}
			w("ingressos_img").onmouseout = w("ingressos_saiba_mais").onmouseout = function(){
				change_ingressos(false);
			}
	}

	if(document.getElementById("img_newsletter")){
		w("img_newsletter").onmouseover = function(){
			this.setClass("img_newsletter_over");
		}

		w("img_newsletter").onmouseout = function(){
			this.setClass("img_newsletter_out");
		}
		/*
		w("img_newsletter").onclick = function(){
			//w("img_newsletter").setVisible(false);
			//w("form_newsletter").setVisible(true);
			//parent.location='?l=13';
		}
		*/
	}
	if(document.getElementById("form_news")){
		w("nome").onfocus = function(){
			if(this.value == "Nome"){
				this.value = "";
			}
		}

		w("nome").onblur = function(){
			if(this.value == ""){
				this.value = "Nome";
			}
		}

		w("email").onfocus = function(){
			if(this.value == "E-mail"){
				this.value = "";
			}
		}

		w("email").onblur = function(){
			if(this.value == ""){
				this.value = "E-mail";
			}
		}


		w("form_news").onsubmit = function(){
			ajax.assincr = false;
			var nome = w("nome").getText();
			var email = w("email").getText();
			if(nome == "" || nome == "Nome"){
				w("msg_newsletter").setClass("msg_2");
				w("msg_newsletter").setHTML("Informe seu nome!");
				w("nome").focus();
				return false;
			}
			if(email == "" || email == "E-mail"){
				w("msg_newsletter").setClass("msg_2");
				w("msg_newsletter").setHTML("Informe um E-mail!");
				w("email").focus();
				return false;
			}
			var response = ajax.loadResponse("cadastro.php?nome="+nome+"&email="+email);

			if(response == "100"){
				w("nome").setText("Nome");
				w("email").setText("E-mail");
				w("msg_newsletter").setClass("msg_1");
				w("msg_newsletter").setHTML("Cadastro efetuado com sucesso!");
				setTimeout(function(){
					w("form_newsletter").setVisible(false);
					w("img_newsletter").setVisible(true);
					w("msg_newsletter").setHTML("");
					} , 5000);
				return false;
			}else if(response == "101"){
				w("nome").focus();
				w("msg_newsletter").setClass("msg_2");
				w("msg_newsletter").setHTML("Nome Inválido");
				return false;
			}else if(response == "102"){
				w("email").focus();
				w("msg_newsletter").setClass("msg_2");
				w("msg_newsletter").setHTML("E-mail Inválido");
				return false;
			}
			return false;
		}
	}

}

function ocultaClube() {
	$('menuClube').style.display = 'none';
}

function abreClube(a) {

	if($('menuClube').style.display == 'block') {
		$('menuClube').style.display = 'none';
	} else {
		$('menuClube').style.display = 'block';
	}

	/*
	alert('o');
	if (a == 0) {

		if (intervalo > 0) {

			clearInterval(intervalo);

		}

		document.getElementById('menuClube').style.display = 'block';

	}

	if (a == 1) {

		intervalo = setInterval (function(){

			document.getElementById('menuClube').style.display = 'none';

			clearInterval(intervalo);

		},1000);
	}
		*/
}

function yfc_popup_close()
{
    cookie.set('yfc_popup', 'true', {duration: 365});
    jQuery('#yfc_popup').remove();
}

jQuery(function($){
    if(!cookie.get('yfc_popup')) {
        $('#yfc_popup').css('display', 'block');
    }
});
