var isLoaded = false;
Membros = {
	SelectAllCidade:function(config){
			
		var e = document.getElementById('sltEstado');
		var idEstado = e.options[e.selectedIndex].value;		
		var combo = document.getElementById('sltCidade');
		var idCidade = config.idCidade;
		var caminho = config.caminho;
		
		combo.length = 0;
			
		this.acao = 'acao=SelectAllCidade';
		this.acao += '&idEstado='+idEstado;
		this.caminho = caminho;
		Membros.DoAction(function(retorno){				
			if(retorno.length){
				for(i=0;i<retorno.length;i++){
					var opt = document.createElement('option');
					opt.value = retorno[i].idCidade;
					opt.text = retorno[i].cidade;
					
					if(retorno[i].idCidade == idCidade){
						opt.selected = true;
					}
					
					try{
						combo.add(opt, null);
					}catch(e){
						combo.add(opt);
					}
				}
			}else{
			}

		});	
		
	},
	ValidarConvite:function(){
		 $('#formConviteAmigo').validate({
			rules:{
					txtEmail:{
						required: true,
						email: true
					}
			},
	        messages:{	               
					txtEmail:{
						required: "*",
						email: "*"
					}
	            }						
		 });	
	}
	,
	EnviarConvite:function(config){
			
		$forms = $('#formConviteAmigo');  
		$forms.bind('submit', function(){									   
			var $button = $('button',this).attr('disabled',true);
			var params = $(this.elements).serialize();
			
			var self = this;
			$.ajax({	
				type: 'POST',
				url: this.action,
				data: params,
				beforeSend: function(){
					$('#resp-convite').show();
					$('#resp-convite').html("Enviando...");
				},
				success: function(txt){
					$button.attr('disabled',false);
					$('#resp-convite').html('');
					$('#resp-convite').html(txt);
					self.reset();
				},
				error: function(txt){
					$('#loading').html(txt);
				}
			})
			return false;
		});		
	}
	,
	DoAction : function(callBack){
		caminho = this.caminho + 'includes/ajax/membros.php?'+this.acao;
		jQuery.ajax({
			type: "GET",
			url: caminho,
			cache: false,
			success: function(msg){callBack(eval(msg));}
		});
		
	}
}