var objPlanos = {};

function inicializarForm(){	    
	xajax_obterArrayPlanos();
	$(function() {
		$('.password').pstrength();
	});
	$("#cidade").tipsy({gravity: $.fn.tipsy.autoWE});
}

function setarArrayPlanos(planos){	
	objPlanos = planos;	
	ajustarFormIncricao($("#plano").val(), $("#produto").val());
	setarValorPlano($('#plano').val());	
}

function ajustarFormIncricao(plano, produto){
	//alert(objPlanos[plano].valorMensal);
	$("#slot_plano").html(objPlanos[plano].descricao);
	if(objPlanos[plano].valorMensal > 0){		
		$("#slot_inf_assinatura").show();
	}else{
		$("#slot_inf_assinatura").hide();
	}
}

function setarValorPlano(nomePlano){	
	var periodicidade = $("#periodicidade").val();
	$.each(objPlanos,
		function(nome,dadosPlano){
			if(nome == nomePlano){				
				$("#slot_valor").html("R$ "+nroBra(dadosPlano[periodicidade]));
			}			
		}
	);
	//$("#idPlano").val(idPlano);
}


function mostraTermos(){
	$('#termos').show();
}

function formatarCpfCnpj(campo,event){
	if(document.getElementById('tipo').value == 'J'){
		return txtBoxFormat(campo.form, campo.name, '99.999.999/9999-99', event);
	}else if(document.getElementById('tipo').value == 'F'){	
		return txtBoxFormat(campo.form, campo.name, '999.999.999-99', event);
	}
} 

function autoTabCpfCnpj(campo,event){
	if(document.getElementById('tipo').value == 'J'){
		return autoTab(campo, 18, event);
	}else if(document.getElementById('tipo').value == 'F'){
		return autoTab(campo, 14, event);
	}
}

function enviarInscricao(dados){
	displayWait('waitInscricao');	
	xajax_enviarInscricao(dados);
}

function enviarInscricaoTinyMed(dados){
	displayWait('waitInscricao');	
	xajax_enviarInscricaoTinyMed(dados);
}

function verificarDisponibilidadeLogin(login){
	xajax_verificarDisponibilidadeLogin(login);
}

function ativarConta(id){	
	displayWait('waitInscricao');
	xajax_ativarConta(id);
}

function ativarSegmentos(selecao){
	switch (selecao) {
		case "me":
			setarSegmentosMicroEmpresa();
			setarLabels("J");
			break;
						
		case "pl":
			setarSegmentosProfissionalLiberal();
			setarLabels("F");
			break;
			
		case "pf":
			setarLabels("F");
			$("#slot_segmento").css({display:"none"});
			$("#slot_select_segmento").html("");
			$("#cnpj").focus();
			break;

		default:
			desabilitarSlotSegmentos();
			break;
	}	
}

function setarLabels(valor) {
	$("#tipo").val(valor);
	if (valor == "F") {
		$("#label_cnpj").html("CPF");
		$("#lbl-nome").html("Nome");
		$("#td_nome_responsavel").hide();
		$("#lbl-crm").html("CRM");
	} else {
		$("#label_cnpj").html("CNPJ");
		$("#lbl-nome").html("Razão Social");
		$("#td_nome_responsavel").show();
		$("#lbl-crm").html("CRM do Responsável");
	}
	$("#slot_cnpj_cpf").css({display:"block"});
}

function setarSegmentosMicroEmpresa(){
	var tpl;
	$("#slot_segmento").css({display:"block"});
	tpl = "<select name='segmento' id='segmento'>";
	tpl += "<option value='com'> Comércio</option>";
	tpl += "<option value='ind'> Indústria</option>";
	tpl += "<option value='ser'> Serviços</option>";
	tpl += "</select>";
	$("#slot_select_segmento").html(tpl);
	$("#segmento").focus();
}

function setarSegmentosProfissionalLiberal(){
	var tpl;
	$("#slot_segmento").css({display:"block"});
	tpl = "<select name='segmento' id='segmento'>";
	tpl += "<option value='adm'> Administrador</option>";
	tpl += "<option value='adv'> Advogado</option>";
	tpl += "<option value='arq'> Arquiteto</option>";
	tpl += "<option value='con'> Contabilista</option>";
	tpl += "<option value='den'> Dentista</option>";
	tpl += "<option value='des'> Designer</option>";	
	tpl += "<option value='eng'> Engenheiro</option>";
	tpl += "<option value='med'> Médico</option>";
	tpl += "<option value='pre'> Prestador de serviços</option>";
	tpl += "<option value='out'> Outro</option>";	
	tpl += "</select>";
	$("#slot_select_segmento").html(tpl);
	$("#segmento").focus();
}

function desabilitarSlotSegmentos(){
	$("#slot_segmento").css({display:"none"});
}

function setIdMunicipio(param){
	$("#idMunicipio").val(param[1]);
	$("#uf").val(param[2]);
	$("#cidade").val($("#cidade").val().substr(0, $("#cidade").val().length - 5));
	$("#cidade").focus();
	$('#cidade').removeClass("ac_error");
	$('#cidade').addClass("tipsyOff");	
	$('#cidade').removeAttr("title");
}
