var okPergunta = false;
$(function() {
	$('.menu a[href="' + window.location + '"]').addClass('ativo');
	
	var valorCampo;
	var camposPadroes  = {'nome':'Nome Completo', 'email':'Email', 'mensagem':'Sua Mensagem'};
	$('#formContatoRodape input,textarea').focus(function(){
		valorCampo = $(this).val();
		for(i in camposPadroes){
			if($(this).val() == camposPadroes[i]){
				$(this).val('');
			}	
		}
	});
	$('#formContatoRodape input,textarea').blur(function(){
		for(i in camposPadroes){
			if($(this).val() == ''){
				$(this).val(camposPadroes[$(this).attr('name')]);
			}	
		}
	});
	
	//adiciona um metodo ao validate em que o valor do campo não pode ser igual 
    jQuery.validator.addMethod("notEquals", function(value, element, config){  
        return value!=config;  
    }, 'Digite um valor'); 
	
	$('#formLogin').validate({
		errorClass:"boxErro",
		validClass:"boxSucesso",
		wrapper: "#erros",
		rules: {
			txtIdentificacao: {
				required: true
			},
			txtSenha: {
				required: true
			}
		},
		messages: {
			txtIdentificacao: {
			required: ''
		},
		txtSenha: {
			required: ''
		}
			
		}
	});
    
    // Valida antes de enviar
	$('#formContatoRodape').validate({
		errorClass:"boxErro",
		validClass:"boxSucesso",
		errorElement: '',
		rules: {
			nome: {
				required: true,
				notEquals: 'Nome Completo'
			},
			email: {
				required: true,
				email: true,
				notEquals: 'Email'
			},
			mensagem: {
				required: true,
				notEquals: 'Sua Mensagem'
			}
		},
		submitHandler: function(form) {
			okPergunta = true;
		},
		invalidHandler: function(e) {
			okPergunta = false;
		}
	});
	
	
	// Evita o submit se a pergunta estiver em branca
	$('#formContatoRodape').submit(function (e) {
		if (!okPergunta) {
			$('input').show();
			$('textarea').show();
			e.stopImmediatePropagation();
		}
	});

	// Se o form estiver ok, manda o email
	// TODO: retirar meu email daqui!
	$('#formContatoRodape').ajaxMail('simone@smfomento.com.br, bianca@smfomento.com.br', {
		titulo: 'Contato - Grupo SM',
		assunto: 'Grupo SM - Fale Conosco',
		nome: 'Grupo SM Site',
		msgSucesso: 'Sua mensagem foi enviada com sucesso.',
		classePadrao: 'notification2'
	});
	
});

$('#formLogin').live('submit', function() {
	var empresa = $('#empresa').val();
	if (!empresa) {
		alert('Por favor selecione uma empresa antes.');
		return false;
	}
	this.action = empresa;
	$('#tbCodi').val($('#txtIdentificacao').val());
	$('#tbSenha').val($('#txtSenha').val());
});

function aumentaFonte() {
	mudaTamanho('_conteudo', +1);
	mudaTamanho('_rodape', +1);
}
function diminuiFonte() {
	mudaTamanho('_conteudo', -1);
	mudaTamanho('_rodape', -1);
}

//Início do código de Aumentar/ Diminuir a letra

//Para usar coloque o comando: "javascript:mudaTamanho('tag_ou_id_alvo', -1);" para diminuir
//e o comando "javascript:mudaTamanho('tag_ou_id_alvo', +1);" para aumentar

var tagAlvo = new Array('p'); //pega todas as tags p//

//Especificando os possíveis tamanhos de fontes, poderia ser: x-small, small...
var tamanhos = new Array( '9px','10px','11px','12px','13px','14px','15px', '16px', '17px', '18px', '19px', '20px' );
var tamanhoInicial = 2;

function mudaTamanho( idAlvo,acao ){
if (!document.getElementById) return
var selecionados = null,tamanho = tamanhoInicial,i,j,tagsAlvo;
tamanho += acao;
if ( tamanho < 0 ) tamanho = 0;
if ( tamanho > 10 ) tamanho = 10;
tamanhoInicial = tamanho;
if ( !( selecionados = document.getElementById( idAlvo ) ) ) selecionados = document.getElementsByTagName( idAlvo )[ 0 ];

selecionados.style.fontSize = tamanhos[ tamanho ];

for ( i = 0; i < tagAlvo.length; i++ ){
 tagsAlvo = selecionados.getElementsByTagName( tagAlvo[ i ] );
 for ( j = 0; j < tagsAlvo.length; j++ ) tagsAlvo[ j ].style.fontSize = tamanhos[ tamanho ];
}
}
//Fim do código de Aumentar/ Diminuir a letra
