var lbCorretorOnline = new LightBox("lbCorretorOnline", "lbCorretorOnline");
lbCorretorOnline.setOverFlow(false, false, "585px", "230px");
lbCorretorOnline.setBorderDiv("2px solid #efefef");


/* **************************************************************************************** *
* Seta os parametros necessários e abre o lightbox para preencher os dados					*
* ***************************************************************************************** */
function initCorretorOnline(idImovel, idFilial){
	zerarFormCorretor();
	document.getElementById("corretor-idImovel").value 	= idImovel;
	document.getElementById("corretor-idFilial").value 	= idFilial;
	lbCorretorOnline.show();
}



/* **************************************************************************************** *
* Zera o formulario de corretor online														*
* ***************************************************************************************** */
function zerarFormCorretor(){
	document.getElementById("corretor-nome").value 		= "";
	document.getElementById("corretor-email").value 	= "";
	document.getElementById("corretor-telefone").value 	= "";
	document.getElementById("corretor-idImovel").value 	= "";
	document.getElementById("corretor-idFilial").value 	= "";
}


/* **************************************************************************************** *
* entrar no Corretor Online																	*
* ***************************************************************************************** */
function entrarCorretorOnline(){
	
	var nome 		= document.getElementById("corretor-nome");
	var email		= document.getElementById("corretor-email");
	var telefone	= document.getElementById("corretor-telefone");
	var idImovel	= document.getElementById("corretor-idImovel");
	var idFilial	= document.getElementById("corretor-idFilial");
	var params		= "";
	
	if( checkValues(nome, email, telefone, idImovel, idFilial) ){
		
		params+= "nome="+nome.value;
		params+= "&email="+email.value;
		params+= "&telefone="+telefone.value;
		params+= "&idImovel="+idImovel.value;
		params+= "&idFilial="+idFilial.value;
		
		lbCorretorOnline.close();
		popUp(SITE+"corretor_online/corretor-online-entrar.php?"+params, "Corretor Online", "500", "500");
	}
		
}


/* **************************************************************************************** *
* Verifica se todos os campos estão preenchidos corretamente								*
* ***************************************************************************************** */
function checkValues(nome, email, telefone, idImovel, idFilial){
	
	var bool		= true;
	var msg			= "";
	
	if( (nome==undefined) || (nome.value.length < 3) ){
		bool 	= false;
		msg		+= "\n- Nome";
	}
	if( (email==undefined) || (email.value.length < 5) ){
		bool	= false;
		msg		+= "\n- E-mail";
	}
	else {
		if( !is_mail(email.value) ){
			bool = false;
			msg	+= "\n- E-mail inválido.";
		}
	}
	if( (telefone==undefined) || (telefone.value.length < 14) ){
		bool	= false;
		msg		+= "\n- Telefone";
	}
	if( (idImovel==undefined) || (idImovel.value=="") )
		bool	= false;
	if( (idFilial==undefined) || (idFilial.value=="") )
		bool	= false;
	
	
	if( !bool && msg!="" )
		alert("Preencha corretamente os campos: \n\n"+msg);
		
	return bool;
}
