
	//Mascaramentos padrão
	function remask() {
		$('.maskFone').mask('(99) 9999.9999')
		$('.maskCpf').mask('999.999.999-99')
		$('.maskCnpj').mask('99.999.999/9999-99')
		$('.maskCep').mask('99999-999')
		$('.maskData').mask('99/99/9999')
		$('.maskHora').mask('99:99:99')
		$('.maskHoraSimples').mask('99:99')

		$('.maskCep').keyup(function() {

			if ($(this).attr('rel') != '') {
				var cep = formataSoNumeros ($(this).val());
				if (cep.length == 8) {
					//alert (cep + ' ' + $(this).attr('rel'));
					buscaCep(cep,$(this).attr('rel'));
				}
			}
		});

	}


	//Busca genérica de CEP
	function buscaCep(cep,campos) {

		var res = campos.split(',');
		blockUi();

		$.getJSON(
			'gen/fnCepJSON.asp?cep=' + cep,
			function(data) {
				unblockUi();
				if (data.ERRO == '0') {
					$('#' + res[0]).val(data.LOGRADOURO);
					$('#' + res[3]).val(data.BAIRRO);
					$('#' + res[4]).val(data.CIDADE);
					$('#' + res[5]).val(data.UF);

					$('#' + res[1]).focus();
				} else {
				}
			}
		);


	}



	//Criação de validação de CNPJ no validate
	jQuery.validator.addMethod("cnpj", function(cnpj, element) {
		cnpj = jQuery.trim(cnpj);

		cnpj = cnpj.replace('/','');
		cnpj = cnpj.replace('.','');
		cnpj = cnpj.replace('.','');
		cnpj = cnpj.replace('-','');

		var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
		digitos_iguais = 1;

		if (cnpj.length < 14){
			return false;
		}
		for (i = 0; i < cnpj.length - 1; i++){
			if (cnpj.charAt(i) != cnpj.charAt(i + 1)){
				digitos_iguais = 0;
				break;
			}
		}

		if (!digitos_iguais){
			tamanho = cnpj.length - 2
			numeros = cnpj.substring(0,tamanho);
			digitos = cnpj.substring(tamanho);
			soma = 0;
			pos = tamanho - 7;
	 
			for (i = tamanho; i >= 1; i--){
				soma += numeros.charAt(tamanho - i) * pos--;
				if (pos < 2){
					pos = 9;
				}
			}
			resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
			if (resultado != digitos.charAt(0)){
				return false;
			}
			tamanho = tamanho + 1;
			numeros = cnpj.substring(0,tamanho);
			soma = 0;
			pos = tamanho - 7;
			for (i = tamanho; i >= 1; i--){
				soma += numeros.charAt(tamanho - i) * pos--;
				if (pos < 2){
					pos = 9;
				}
			}
			resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
			if (resultado != digitos.charAt(1)){
				return false;
			}
			return true;
		}else{
			return false;
		}
	}, "Informe um CNPJ válido."); // Mensagem padrão 



	function corrigeAltura() {

		if ($('#intSidebar').css('height') && $('#intContent').css('height')) {
	
			var h1 = eval($('#intSidebar').css('height').replace('px',''));
			var h2 = eval($('#intContent').css('height').replace('px',''));

			if (h1 < h2) {
				$('#intSidebar').css('height', $('#intContent').css('height'));
			}
		}

		window.setTimeout(corrigeAltura,1000);

	}



	$(document).ready(function() {

		//Corner
		//$('.roundCorner').corner();

		//Slideshow
		$('#homeSlideShow').coinslider({
			width: 580,
			height: 170,
			navigation: false,
			delay: 4000,
			links: true
		});

		remask();

		corrigeAltura();


		if ($("a[rel='galeria']").attr('href')) {

			$("a[rel='galeria']").colorbox({
				current: 'imagem {current} de {total}',
				transition:'fade'
			});
		}

		if ($('.lnkInfo').attr('alt')) {
			$('div.info').css('display','none');
			$('div#ingresso').css('display','inline');
		}

		$('.lnkInfo').click(function() {
			$('div.info').slideUp();
			$('div#' + $(this).attr('alt')).slideDown();

		});

	});






