
$(document).ready(function() {
	
	///MENU
	$("ul.menu li").mouseenter(function(){
		var image = path+"img/"+$(this).find("a").attr("rel")+"_over.png";
		$(this).find("a img").attr("src",image);
	}).mouseleave(function(){
		var image = path+"img/"+$(this).find("a").attr("rel")+".png"; 
		$(this).find("a img").attr("src",image);
	});
	
	//VERIFICA QUAL PÁGINA E O QUE DEVE EXECUTAR		
	switch(pagina){
		case "vagas":
			$("a.expand_button").live("click",expandImoveis);
		break
		case "servicos":
			$("a.expand_button").live("click",expandImoveis);
		break
	}
});




/******************************************************************************/
// ÂNCORA TOPO PÁGINA
/******************************************************************************/

$.easing.easeInOutCubic = function (x, t, b, c, d) {
	if ((t/=d/2) < 1) return c/2*t*t*t + b;
	return c/2*((t-=2)*t*t + 2) + b;
}

function topoPagina(){
	$("body").scrollTo($('body'), 800,  { easing:'easeInOutCubic'})
}



//******************************************************************************/
//CONTROLE DO IMOVEIS DETALHES
/******************************************************************************/

function expandImoveis(){
	var ref = $(this).parents(".lista_vagas");
	var id = $(this).parent().find("a.expand_button").attr("rel");
	if($(".txt:visible").length > 0){
		$(this).parent().find("a.expand_button").text("[ + ]");
		$(".txt:visible").slideUp(function(){
			var id_compara = $(this).parents(".lista_vagas").find("a.expand_button").attr("rel");
			$(this).parent().find("a.expand_button").text("[ + ]");
			if(id_compara != id){
				$(ref).find(".txt").slideDown(function(){
					$(this).parent().find("a.expand_button").text("[ - ]");
					$("body").scrollTo($(this).parents(".lista_vagas"), 400,  { easing:'easeInOutCubic'});
				});
			}
		});
	}else{
		$(this).parent().find("a.expand_button").text("[ - ]");
		$(this).parents(".lista_vagas").find(".txt").slideDown();
	}
}




//******************************************************************************/
//ABRE POPUP GALERIA DE FOTOS
/******************************************************************************/
function openpopup(settings){
	
	config = {
		width:550,
		height:450,
		url:""
	};
	$.extend(config, settings);
	halfWidth = Math.floor(config.width/-2);
	halfHeight = Math.floor(config.height/-2);
	
	$("<div id=\"bg_black\" onClick=\"javascript:fecharpopup1();\" style=\"display:none;\"></div>").appendTo("body");
	
	
	if($.browser.safari){
		scrollPosition = document.body.scrollTop;
	}else{
		scrollPosition = document.documentElement.scrollTop;
	}	
	
	$.browser.msie ? $("body").attr("scroll", "no") : $("body").css("overflow", "hidden");
	
	$("#bg_black").fadeTo(01, 0).css({width:"100%",height:"100%",cursor:"pointer",top:scrollPosition,position:"absolute",background:"#000",zIndex:"999"});
	$("#bg_black").fadeTo("slow", 0.7);	
	
	$("<div class='popupbox' style='width:"+config.width+"px; height:"+config.height+"px; position:absolute; z-index:2000; left:50%; margin-left:"+halfWidth+"px;'></div>").prependTo("body");
	
	$(".popupbox").load(config.url);
	
	if($.browser.safari){
		scrollPosition = document.body.scrollTop;
	}else{
		scrollPosition = document.documentElement.scrollTop;
	}

	$(".popupbox").css({marginTop:(halfHeight+scrollPosition)+"px", top:"50%"});
	

}

function fecharpopup1(){
	
	$(".popupbox").remove();
	$("#bg_black").fadeOut(function(){$(this).remove();});
	$.browser.msie ? $("body").removeAttr("scroll") : $("body").css("overflow", "auto");	
	if($.browser.msie){
		if($.browser.version=="7.0"){
			$("body").removeAttr("scroll");
		}else{
			$("body").css("overflow", "auto");
		}
	}else{
		$("body").css("overflow", "auto");
	}
	
}




/******************************************************************************/
// MASCARAS FORMULARIO
/******************************************************************************/

function txtBoxFormat(objeto, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
	if(document.all) { // Internet Explorer
		nTecla = evtKeyPress.keyCode;
	} else if(document.layers) { // Nestcape
		nTecla = evtKeyPress.which;
	} else {
		nTecla = evtKeyPress.which;
		if (nTecla == 8 || nTecla == 0) {
			return true;
		}
	}
    sValue = objeto.value;
    // Limpa todos os caracteres de formatação que
    // já estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
        sCod += sMask.charAt(i);
        mskLen++;
	  }else{
        sCod += sValue.charAt(nCount);
        nCount++;
      }
      i++;
    }
    objeto.value = sCod;

	if (nTecla != 8) { // backspace ou tab
		if(sMask.charAt(i-1) == "9"){ // apenas números...
			return ((nTecla > 47) && (nTecla < 58));
		}else{ // qualquer caracter...
			return true;
		} 
	}else{
		return true;
	}
}

function validaEmail(email){
	ER = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]{2,64}(\.[a-z0-9-]{2,64})*\.[a-z]{2,4}$");
	if (ER.test(email)){
		return true;
	}else{
		return false;
	}
}

/******************************************************************************/
// ENVIA CONTATO
/******************************************************************************/
function Envia_Contato(form){
var nome=form.txtNome.value;
var email=form.txtEmail.value;
var ddd=form.txtDDD.value;
var telefone=form.txtFone.value;
var dddcel=form.txtDDDCel.value;
var celular=form.txtCelular.value;
var assunto=form.txtAssunto.value;
var mensagem=form.txtMensagem.value;
	if (nome=="" || nome=="Nome"){
		$(".resposta").html("Digite o Nome.");											
		return false;
	}else if (email=="" || email=="E-mail"){
		$(".resposta").html("Digite o Email.");													
		return false;
	}else if(!validaEmail(email)){
		$(".resposta").html("Formato do Email Incorreto.");													
		return false;
	} else if (ddd=="" || ddd=="DDD"){
		$(".resposta").html("Digite o DDD do Telefone.");													
		return false;
	}else if (telefone=="" || telefone=="Fone"){
		$(".resposta").html("Digite o Telefone.");													
		return false;
	}else if (dddcel=="" || dddcel=="DDD"){
		$(".resposta").html("Digite o DDD do Celular.");													
		return false;
	}else if (celular=="" || celular=="Celular"){
		$(".resposta").html("Digite o Celular.");													
		return false;
	}else if (assunto=="" || assunto=="Assunto"){
		$(".resposta").html("Digite o Assunto.");													
		return false;
	}else if (mensagem=="" || mensagem == "Mensagem"){
		$(".resposta").html("Digite a Mensagem.");													
		return false;
	} else {
		$.post('scripts/envia_contato.php',$(form).serialize(),function(data){
			$(".resposta").html(data);
			_gaq.push(['_trackPageview', '/envioucontato']);
			form.reset();
		});
	}
}

//---------------------PRÓXIMO CAMPO---------------------------------------------------------
function jrs_Valida(campo, prox, total)
{
	if(campo.value.length>total-1)document.getElementById(prox).focus();
}

/******************************************************************************/
// ENVIA SERVIÇO
/******************************************************************************/
function Envia_Servico(form){
var servico=form.servico.value;
var nome=form.txtNome.value;
var email=form.txtEmail.value;
var ddd=form.txtDDD.value;
var telefone=form.txtFone.value;
var dddcel=form.txtDDDCel.value;
var celular=form.txtCelular.value;
	if (servico==""){
		$(".resposta").html("Informe Servi&ccedil;o.");											
		return false;
	}else if (nome=="" || nome=="Nome"){
		$(".resposta").html("Digite o Nome.");											
		return false;
	}else if (email=="" || email=="E-mail"){
		$(".resposta").html("Digite o Email.");													
		return false;
	}else if(!validaEmail(email)){
		$(".resposta").html("Formato do Email Incorreto.");													
		return false;
	} else if (ddd=="" || ddd=="DDD"){
		$(".resposta").html("Digite o DDD do Telefone.");													
		return false;
	}else if (telefone=="" || telefone=="Fone"){
		$(".resposta").html("Digite o Telefone.");													
		return false;
	}else if (dddcel=="" || dddcel=="DDD"){
		$(".resposta").html("Digite o DDD do Celular.");													
		return false;
	}else if (celular=="" || celular=="Celular"){
		$(".resposta").html("Digite o Celular.");													
		return false;
	} else if (document.Form_Servico.telefone.checked==false && document.Form_Servico.email.checked==false) {	
		$(".resposta").html("Marque pelo menos uma forma de ser contactado");													
		return false;
	} else {
		$.post('scripts/envia_servico.php',$(form).serialize(),function(data){
			$(".resposta").html(data);
			_gaq.push(['_trackPageview', '/agendou']);
			form.reset();
		});
	}
}

/******************************************************************************/
// ESQUECI A SENHA
/******************************************************************************/
function Esqueci_Senha(form){
	var cpf=form.cpf.value;
	if (cpf=="" || cpf=="CPF"){
		$("#mensagem").html("Digite o CPF.");											
		return false;
	} else {
		$.post('scripts/envia_senha.php',$(form).serialize(),function(data){
			if(data != "ok") {
				$("#mensagem").html(data);				
			} else {
				$("#mensagem").html('Sua senha foi encaminhada para o email');
				form.reset();
			}
		});
	}
}
