var cadastraBanda = {
	nome_banda		:	null,
	genero			:	null,
	referencia			:	null,
	cache	:	null,
	overlay_wrapper : 	null,
	overlay_panel   : 	null,

	init:function(id){
		this.id	  = 	id;
		table = document.getElementById(id);
		table.style.display="none";
		this.table	  = 	table;
		this.show_overlay();
	},
	
	
	show_overlay:function(){
		if(!this.overlay_wrapper) 
			this.append_overlay();
    	this.overlay_wrapper.fadeIn(700);
		
		this.nome_banda = $j('#nome_banda');
		this.genero  = 	$j('#genero');
		this.referencia  = 	$j('#referencia');
		this.cache   = 	$j('#cache'); 
		this.abilitaBotoes();
	},
	
	append_overlay:function(){
		this.overlay_wrapper = $j('<div id="overlay" class="spaco"></div>').appendTo($j('BODY'));
		this.overlay_panel = $j('<div id="overlay-panel"></div>').appendTo(this.overlay_wrapper);
		this.overlay_panel.html(this.getHTML());
	},
	
	hide_overlay:function() {
		cadastraBanda2.init($j('#nome_banda').val(),$j('#genero').val(),$j('#referencia').val(),$j('#cache').val());
		this.overlay_wrapper.fadeOut(700);
		$j('#mostra').hide();
	},
	
	sair:function() {
		this.overlay_wrapper.fadeOut(700);
		$j('#nome_banda').val("");
		$j('#genero').val("");
		$j('#referencia').val("");
		$j('#cache').val("");
		$j('#mostra').hide();
		table.style.display="block";
	},
	
	limpar:function() {
		$j('#nome_banda').val("");
		$j('#genero').val("");
		$j('#referencia').val("");
		$j('#cache').val("");
		$j('#mostra').hide();
	},
	
	getHTML:function(){
		var flash =  '<div id="corpo">\
		    <div id="container-popup">\
		      <div id="popup-form-contato" class="newsletter">\
					<div class="head">\
						<p class="popup-head-news"><span>1&deg; ETAPA</span> - QUEM &Eacute; A BANDA?<a href="javascript:void(0)" onclick="cadastraBanda.sair()" class="bt-cancel">[ x ]</a></p>\
					</div>\
						<form action="" method="post">\
						<br />\
								<fieldset>\
								<span class="input-title">NOME DA BANDA:</span>\
								<input type="text" name="nome_banda" id="nome_banda" class="entrada" />\
								</fieldset>\
								<fieldset>\
								<span class="input-title">G&Ecirc;NERO:</span>\
								<input type="text" name="genero" id="genero" class="entrada" />\
								</fieldset>\
								<fieldset>\
								<span class="input-title">BANDAS DE REFER&Ecirc;NCIA:</span>\
								<input type="text" name="referencia" id="referencia" class="entrada" />\
								</fieldset>\
								<fieldset>\
								<span class="input-title">CACH&Ecirc;:</span>\
								<input type="text" name="cache" id="cache" onkeypress="return cadastraBanda.testa(event)" class="entrada" />\
								</fieldset>\
							<br />\
							<div class="popup-mess-form">\
								<strong id="mostra"></strong>\
								</p>\
							</div>\
						</form>\
						<div id="mask"></div>\
						<div id="popup-footer-news">\
							<a href="javascript:void(0)" onclick="cadastraBanda.limpar()" class="botao1-form" id="ok"><span> \\\\ LIMPAR</span></a>\
							<a href="javascript:void(0)" onclick="cadastraBanda.validaForm()" id="enviar" class="botao1-form"><span id="bt2">\\\\ AVAN&Ccedil;AR</span></a>\
						</div>\
				</div>\
				</div>\
			</div>';
		return flash;
	},
	
	validaForm:function(){
		$j('#mostra').show();
		
		if(!this.validaCampo(this.nome_banda.val())){
			this.nome_banda.focus();
			$j('#mostra').html('<img src="imagens/img-alert.gif"  height="32" width="48" alt=""/>   Ops! Você não está esquecendo de nada, não? Preencha o campo "nome".');	
			return false;
		}else if(!this.validaCampo(this.genero.val())){
			this.genero.focus();
			$j('#mostra').html('<img src="imagens/img-alert.gif"  height="32" width="48" alt=""/>   Ops! Você não está esquecendo de nada, não? Preencha o campo "gênero".');	
			return false;
		}else if(!this.validaCampo(this.cache.val())){
			this.cache.focus();
			$j('#mostra').html('<img src="imagens/img-alert.gif"  height="32" width="48" alt=""/>   Ops! Você não está esquecendo de nada, não? Preencha o campo "cachê".');	
			return false;
		}else{
			this.hide_overlay();
		}
	},
	
	testa:function(e){
	   //$j('#mostra').show();
	   var tecla=(window.event)?event.keyCode:e.which;
	   if((tecla > 47 && tecla < 58)){
		  return true;
	   }else if(tecla == 46 || tecla == 44){
		   return true;
	   }else{
	      if (tecla != 8){ 
		    return false;
		  }else{
		    return true;
		  }
	   }
	},
	
	desabilitaBotoes:function(){
		$j('#enviar').removeClass("e");
		$j('#enviar').addClass("e-fecha");
		$j('#fechar').removeClass("f");
		$j('#fechar').addClass("f-fecha");
	},
	
	abilitaBotoes:function(){
		$j('#enviar').removeClass("e-fecha");
		$j('#enviar').addClass("e");
		$j('#fechar').removeClass("f-fecha");
		$j('#fechar').addClass("f");
		
	},
	
	validaCampo:function(valor){
		return valor.length>0?true:false;	
	},
	
	validaEmail:function(email){
		var regmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
		return regmail.test(email)?true:false;	
	}
};
