function validarFormulario(formName) {
	erro = false;
	switch (formName) {
		case 'contratar':
			Campos = {
				'enderecoloja': {
					'tipo':'string',
					'regexp':'^[a-z0-9]+?$',
					'tamanho':'4,12',
					'nome':'Endere&ccedil;o da Loja'
				},
				'responsavel': {
					'tipo':'string',
					'regexp':'.*',
					'tamanho':'10,-',
					'nome':'Nome'
				},
				'dia_data_nasc': {
					'tipo':'int[1-31]',
					'tamanho':'1,2',
					'nome':'Dia de nascimento'
				},
				'mes_data_nasc': {
					'tipo':'int[1-12]',
					'tamanho':'1,2',
					'nome':'M&ecirc;s de nascimento'
				},
				'ano_data_nasc': {
					'tipo':'int[1900-1992]',
					'tamanho':'4',
					'nome':'Ano de nascimento'
				},
				'cpf': {
					'tipo':'string',
					'regexp':'^[0-9]{3}\.[0-9]{3}\.[0-9]{3}\-[0-9]{2}$',
					'tamanho':'14',
					'nome':'CPF'
				},
				'rg': {
					'tipo':'string',
					'regexp':'^[0-9]{2}\.[0-9]{3}\.[0-9]{3}\-[0-9]{1}$',
					'tamanho':'12',
					'nome':'RG'
				},
				'razao_social': {
					'tipo':'string',
					'regexp':'^(.+)$',
					'tamanho':'6,-',
					'nome':'Raz&atilde;o social'
				},
				'cnpj': {
					'tipo':'string',
					'regexp':'^[0-9]{2}\.[0-9]{3}\.[0-9]{3}\/[0-9]{4}\-[0-9]{2}$',
					'tamanho':'18',
					'nome':'CNPJ'
				},
				'endereco': {
					'tipo':'string',
					'regexp':'^(.+)$',
					'tamanho':'6,-',
					'nome':'Endere&ccedil;o'
				},
				'bairro': {
					'tipo':'string',
					'regexp':'^(.+)$',
					'tamanho':'3,-',
					'nome':'Bairro'
				},
				'cidade': {
					'tipo':'string',
					'regexp':'^(.+)$',
					'tamanho':'3,-',
					'nome':'Cidade'
				},
				'estado': {
					'tipo':'string',
					'regexp':'^[A-Z]+$',
					'tamanho':'2',
					'nome':'Estado'
				},
				'cep_1': {
					'tipo':'int',
					'tamanho':'5',
					'nome':'CEP'
				},
				'cep_2': {
					'tipo':'int',
					'tamanho':'3',
					'nome':'CEP'
				},
				'tel_1_ddd': {
					'tipo':'int',
					'tamanho':'2',
					'nome':'DDD'
				},
				'tel_1_1': {
					'tipo':'int',
					'tamanho':'4',
					'nome':'Telefone'
				},
				'tel_1_2': {
					'tipo':'int',
					'tamanho':'4',
					'nome':'Telefone'
				},
				'email': {
					'tipo':'string',
					'regexp':'^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$',
					'tamanho':'-',
					'nome':'E-mail'
				},
				'conheceu': {
					'tipo':'string',
					'regexp':'[^Selecione]',
					'tamanho':'-',
					'nome':'Como nos conheceu'
				}
			}
			if ($('id_plano').getValue() == '') {
				erro = 'none||Voc&ecirc; deve escolher um plano!';
			}
			$each(Campos, function(inf, id) {
				skipThisOne = false;
				/*
				if ((id == 'razao_social' || id == 'cnpj') && !$('pessoa_2').checked) {
					skipThisOne = true;
				}
				*/
				if (!skipThisOne) {
					if ($chk($(id)) && inf.regexp !== false && erro === false) {
						V = $(id).getProperty('value').clean();
						if (!inf.tipo.test('int')) {
							if (!V.test(inf.regexp)) {
								erro = id + '||' + inf.nome;
							}
						} else {
							if (inf.tipo.test('int\[(\d+\-\d+)]')) {
								Raio = inf.tipo.replace('int[', '').replace(']','');
								Raio = Raio.split('-');
								if (V.toInt() < Raio[0].toInt() || V.toInt() > Raio[1].toInt()) {
									erro = id + '||' + inf.nome;
								}
							}
							else if (V != V.toInt() || V == '') {
								erro = id + '||' + inf.nome;
							}
						}
						if (erro === false) {
							avisoTamanho = '';
							if (inf.tamanho.test(',')) {
								T = inf.tamanho.split(',');
								tamanhoMinimo = T[0].replace('-', 0);
								tamanhoMaximo = T[1].replace('-', 99999999999);
								if ((T[0] == '-' && T[1] != '-') || (V.length > tamanhoMinimo)) {
									avisoTamanho = 'no m&aacute;ximo '+ T[1] +' caracteres';
								}
								if ((T[0] != '-' && T[1] == '-') || (V.length < tamanhoMinimo)) {
									avisoTamanho = 'no m&iacute;nimo '+ T[0] +' caracteres';
								}
							}
							if (inf.tamanho == inf.tamanho.toInt()) {
								tamanhoMinimo = inf.tamanho.toInt();
								tamanhoMaximo = inf.tamanho.toInt();
								avisoTamanho = inf.tamanho.toInt() + ' caracteres';
							}
							if (inf.tamanho == '-') {
								tamanhoMinimo = 0;
								tamanhoMaximo = 99999999999;
							}
							if (V.length < tamanhoMinimo || V.length > tamanhoMaximo) {
								erro = id + '||[msg]O campo "' + inf.nome + '" deve conter ' + avisoTamanho + '.';
							}
						}
					}
				}
			});
			if (!erro && !$('termouso').checked) {
				erro = 'none||Voc&ecirc; precisa aceitar os termos de utiliza&ccedil;&atilde;o';
			}
		break;
	}
	if (erro === false) {
		return true;
	} else {
		erro = erro.split('||');
		if (erro[0] != 'none') {
			$(erro[0]).focus();
			if (erro[1].substr(0, 5) == '[msg]') {
				new flatAlert(erro[1].substr(5, erro[1].length - 5));
			} else {
				new flatAlert('Por favor, preencha corretamente o campo "' + erro[1] + '"');
			}
			$(erro[0]).focus();
		}
		else {
			new flatAlert(erro[1]);
		}
		return false;
	}
}

function mudarPessoa(el) {
	estado = true;
	if (el.value == 'juridica') {
		estado = false;
	}
	$('razao_social').set({
		'styles': {
			'background-color':(estado ? '#D4D0C8' : '#FFFFFF')
		},
		'disabled':estado
	});
	$('cnpj').set({
		'styles': {
			'background-color':(estado ? '#D4D0C8' : '#FFFFFF')
		},
		'disabled':estado
	});
}

function pular(el, n, id) {
	if (el.value.length == n) {
		$(id).focus();
	}
}

function calculaPlano() {
	idPlano = thisLocation.split('/');
	idPlano = idPlano[idPlano.length - 1].replace(/[^0-9]/g, '');
	if (idPlano.toInt() != idPlano) {
		// Nenhum plano selecionado
		$('tblValores').setStyle('display', 'none');
		mostraPlanos(false);
	} else {
		idPlano = idPlano.toInt();
		$('nome_plano').setHTML($('nome_' + idPlano).innerHTML);
		$('itens_plano').setHTML($('itens_' + idPlano).innerHTML);
		$('transferencia_plano').setHTML($('transferencia_' + idPlano).innerHTML);
		$('valor_plano').setHTML($('mensal_' + idPlano).innerHTML);
		mensalidade = $('mensal_' + idPlano).innerHTML.replace(',', '.').replace(/[^0-9.]/g, '').toFloat();
		$('instalacao_plano').setHTML($('instalacao_' + idPlano).innerHTML.replace('ISENTO', 'R$ 0,00'));
		instalacao = $('instalacao_' + idPlano).innerHTML.replace('ISENTO', 'R$ 0,00').replace(',', '.').replace(/[^0-9.]/g, '').toFloat();
		total = (mensalidade + instalacao).toString();
		if (total.contains('.')) {
			total = total.replace('.', ',');
			total_ = total.split(',');
			total += total_[1].length == 1 ? '0' : '';
		} else {
			total += ',00';
		}
		$('totalGeral').setHTML(total);
		$('id_plano').setProperty('value', idPlano)
	}
}

function mudarPlano(id) {
	thisLocation = "http://sislojafacil.com/contratar/" + id + ".html";
	calculaPlano();
	FxPlanos.slideOut();
	(function() {
		new Fx.Scroll(window).toTop();
	}).delay(FxPlanos.options.duration * 0.75);
	$('tblValores').setStyle('display', 'block');
}

function mostraPlanos(autoScroll) {
	if (autoScroll) {
		FxPlanos.slideIn();
		(function() {
			new Fx.Scroll(window).toElement('tbl_planos');
		}).delay(FxPlanos.options.duration * 0.75);
	} else {
		FxPlanos.show();
	}
}