$(document).ready(function(){
	formValidate();
	formCalendar();
	inputTextActive();
	inputTextInactive();
	
	textAreaActive();
	textAreaInactive();
	
	btContinuar();
	btVoltar();
	//btEtapas();
	
	mostrarEmpresas();
  
  mascaraCampo();
  
  selecionaEstadoHotel();
	
	ocultarEstados();
  
  showqTip();
	
	$("#area_empresa_1").css("display","block");
	$("#area_empresa_1").addClass("hide_this_div");
	$("#area_empresa_2").css("display","none");
	$("#area_empresa_2").addClass("show_this_div");
	$("#area_empresa_3").css("display","none");	
	$("#area_empresa_3").addClass("show_this_div");
	$("#area_empresa_4").css("display","none");	
	$("#area_empresa_4").addClass("show_this_div");
});

function showqTip() {
  $('.qinfo').qtip({
   content: $(this).attr("title"),
   show: 'mouseover',
   hide: 'mouseout',
   style: { 
      padding: 5,
      background: '#F0F0F0',
      color: '#666666',
      textAlign: 'left',
      fontSize: '12px',
      border: {
         width: 0,
         radius: 2,
         color: '#CCCCCC'
      },
      tip: 'topLeft'
   }
})
}

function formCalendar(){
	//$(".datepicker").datepicker();
}

function formValidate(){
	$("#registerForm").validate();
}

function selecionaEstadoHotel() {
  $("#seleciona_estado_hotel").change(function () {
    
    var str = "";
    var show_select = "";
    
    $("#seleciona_estado_hotel option:selected").each(function () {
      str += $(this).val();
    });
    
    switch(str)
    {
      case "ES" : 
        $("#hoteis_ES").slideDown();
        $("#hoteis_ES").attr({name : "obj_hotel"});
        $("#hoteis_GO").slideUp();
        $("#hoteis_GO").removeAttr("name")
        $("#hoteis_MG").slideUp();
        $("#hoteis_MG").removeAttr("name")
        $("#hoteis_IN").slideUp();
        $("#hoteis_IN").removeAttr("name")
      break;
      
      case "GO" : 
        $("#hoteis_GO").slideDown();
        $("#hoteis_GO").attr({name : "obj_hotel"});
        $("#hoteis_ES").slideUp();
        $("#hoteis_ES").removeAttr("name")
        $("#hoteis_MG").slideUp();
        $("#hoteis_MG").removeAttr("name")
        $("#hoteis_IN").slideUp();
        $("#hoteis_IN").removeAttr("name")
      break;
      
      case "MG" : 
        $("#hoteis_MG").slideDown();
        $("#hoteis_MG").attr({name : "obj_hotel"});
        $("#hoteis_ES").slideUp();
        $("#hoteis_ES").removeAttr("name")
        $("#hoteis_GO").slideUp();
        $("#hoteis_GO").removeAttr("name")
        $("#hoteis_IN").slideUp();
        $("#hoteis_IN").removeAttr("name")
      break;
			
			case "IN" : 
        $("#hoteis_IN").slideDown();
        $("#hoteis_IN").attr({name : "obj_hotel"});
        $("#hoteis_MG").slideUp();
        $("#hoteis_MG").removeAttr("name")
        $("#hoteis_ES").slideUp();
        $("#hoteis_ES").removeAttr("name")
        $("#hoteis_GO").slideUp();
        $("#hoteis_GO").removeAttr("name")
      break;
    }
  });
}

function mascaraCampo() {
  $(".telefone").mask("9999-9999");
  $(".cep").mask("99999-999");
  $(".ddd").mask("99");
	$(".data_ano").mask("9999");
  
  $(".valor").maskMoney({symbol:"",decimal:",",thousands:"."});
}

function mostrarEmpresas() {
	$("#acao_empresa_1").click(function(){
		if($("#area_empresa_1").is(".hide_this_div")) {
			$("#area_empresa_1").slideUp();
			$("#area_empresa_1").addClass("show_this_div").removeClass("hide_this_div");
			$(this).text("mostrar");
		} else if($("#area_empresa_1").is(".show_this_div")) {
			$("#area_empresa_1").slideDown();
			$("#area_empresa_1").addClass("hide_this_div").removeClass("show_this_div");
			$(this).text("ocultar");
		}
	});
	
	$("#acao_empresa_2").click(function(){
		if($("#area_empresa_2").is(".hide_this_div")) {
			$("#area_empresa_2").slideUp();
			$("#area_empresa_2").addClass("show_this_div").removeClass("hide_this_div");
			$(this).text("mostrar");
		} else if($("#area_empresa_2").is(".show_this_div")) {
			$("#area_empresa_2").slideDown();
			$("#area_empresa_2").addClass("hide_this_div").removeClass("show_this_div");
			$(this).text("ocultar");
		}
	});
	
	$("#acao_empresa_3").click(function(){
		if($("#area_empresa_3").is(".hide_this_div")) {
			$("#area_empresa_3").slideUp();
			$("#area_empresa_3").addClass("show_this_div").removeClass("hide_this_div");
			$(this).text("mostrar");
		} else if($("#area_empresa_3").is(".show_this_div")) {
			$("#area_empresa_3").slideDown();
			$("#area_empresa_3").addClass("hide_this_div").removeClass("show_this_div");
			$(this).text("ocultar");
		}
	});
	
	$("#acao_empresa_4").click(function(){
		if($("#area_empresa_4").is(".hide_this_div")) {
			$("#area_empresa_4").slideUp();
			$("#area_empresa_4").addClass("show_this_div").removeClass("hide_this_div");
			$(this).text("mostrar");
		} else if($("#area_empresa_4").is(".show_this_div")) {
			$("#area_empresa_4").slideDown();
			$("#area_empresa_4").addClass("hide_this_div").removeClass("show_this_div");
			$(this).text("ocultar");
		}
	});
}

function btEtapas() {
	$("#bt_etapa_1").mouseover(function(){
		if($(this).is(".item_etapa_1_off")) {
			$(this).addClass("item_etapa_1_on jquery_tmp").removeClass("item_etapa_1_off");
		}
	});
	
	$("#bt_etapa_1").mouseout(function(){
		if($(this).is(".jquery_tmp")) {
			$(this).addClass("item_etapa_1_off").removeClass("item_etapa_1_on .jquery_tmp");
		}
	});

	$("#bt_etapa_2").mouseover(function(){
		if($(this).is(".item_etapa_2_off")) {
			$(this).addClass("item_etapa_2_on jquery_tmp").removeClass("item_etapa_2_off");
		}
	});
	
	$("#bt_etapa_2").mouseout(function(){
		if($(this).is(".jquery_tmp")) {
			$(this).addClass("item_etapa_2_off").removeClass("item_etapa_2_on jquery_tmp");
		}
	});
	
	$("#bt_etapa_3").mouseover(function(){
		if($(this).is(".item_etapa_3_off")) {
			$(this).addClass("item_etapa_3_on jquery_tmp").removeClass("item_etapa_3_off");
		}
	});
	
	$("#bt_etapa_3").mouseout(function(){
		if($(this).is(".jquery_tmp")) {
			$(this).addClass("item_etapa_3_off").removeClass("item_etapa_3_on jquery_tmp");
		}
	});
	
	$("#bt_etapa_4").mouseover(function(){
		if($(this).is(".item_etapa_4_off")) {
			$(this).addClass("item_etapa_4_on jquery_tmp").removeClass("item_etapa_4_off");
		}
	});
	
	$("#bt_etapa_4").mouseout(function(){
		if($(this).is(".jquery_tmp")) {
			$(this).addClass("item_etapa_4_off").removeClass("item_etapa_4_on jquery_tmp");
		}
	});
}

function inputTextActive() {
	$(".text_field").focus(function () {
		  if ($(this).is(".text_field_off")) {
				$(this).css("background","url(tema/imagens/bg_input_text.jpg) repeat-x");
				$(this).css("border","1px solid #814239");
		  }
	});
}

function inputTextInactive() {
	$(".text_field").blur(function () {
		  if ($(this).is(".text_field_off")) {
				$(this).css("background","#ffffff");
				$(this).css("border","1px solid #e1e0e0");
		  }
	});
}

function textAreaActive() {
	$(".textarea_field").focus(function () {
		  if ($(this).is(".text_field_off")) {
				$(this).css("background","url(tema/imagens/bg_input_text.jpg) repeat-x");
				$(this).css("border","1px solid #814239");
		  }
	});
}

function textAreaInactive() {
	$(".textarea_field").blur(function () {
		  if ($(this).is(".text_field_off")) {
				$(this).css("background","#ffffff");
				$(this).css("border","1px solid #e1e0e0");
		  }
	});
}

function btContinuar(){
	$("#bt_continuar").mouseover(function() {
		$(this).css("cursor","pointer");
	});
}

function btVoltar(){
	$("#bt_voltar").mouseover(function() {
		$(this).css("background","url(tema/imagens/bt_voltar_off.png) no-repeat");
		$(this).css("cursor","pointer");
	});
	
	$("#bt_voltar").mousedown(function() {
		$(this).css("background","url(tema/imagens/bt_voltar_on.png) no-repeat");
		$(this).css("cursor","pointer");
	});
	
	$("#bt_voltar").mouseout(function() {
		$(this).css("background","url(tema/imagens/bt_voltar_on.png) no-repeat");
	});
	
	$("#bt_voltar").mouseup(function() {
		$(this).css("background","url(tema/imagens/bt_voltar_off.png) no-repeat");
		$(this).css("cursor","pointer");
	});
}

function ocultarEstados() {
	$("#pessoal_pais").change(function () {
    var pais = "";
   	$("#pessoal_pais option:selected").each(function () {
				if($(this).attr("value") != "076") {
				  $("#pessoal_estado").css("display","none");
					$("#pessoal_estado_select").removeAttr("name");
					$("#pessoal_estado_input").attr("name","pessoal_estado");
				} else {
				  $("#pessoal_estado").css("display","block");
					$("#pessoal_estado_input").removeAttr("name");
					$("#pessoal_estado_select").attr("name","pessoal_estado");
				}
	  });
	});
	
	$("#form_curso1_pais").change(function () {
    var pais = "";
   	$("#form_curso1_pais option:selected").each(function () {
				if($(this).attr("value") != "076") {
				  $("#form_curso1_estado").css("display","none");
					$("#form_curso1_estado_select").removeAttr("name");
					$("#form_curso1_estado_input").attr("name","form_curso1_estado");
				} else {
				  $("#form_curso1_estado").css("display","block");
					$("#form_curso1_estado_input").removeAttr("name");
					$("#form_curso1_estado_select").attr("name","form_curso1_estado");
				}
	  });
	});
	
	$("#form_curso2_pais").change(function () {
    var pais = "";
   	$("#form_curso2_pais option:selected").each(function () {
				if($(this).attr("value") != "076") {
				  $("#form_curso2_estado").css("display","none");
					$("#form_curso2_estado_select").removeAttr("name");
					$("#form_curso2_estado_input").attr("name","form_curso2_estado");
				} else {
				  $("#form_curso2_estado").css("display","block");
					$("#form_curso2_estado_input").removeAttr("name");
					$("#form_curso2_estado_select").attr("name","form_curso2_estado");
				}
	  });
	});
	
	$("#form_curso3_pais").change(function () {
    var pais = "";
   	$("#form_curso3_pais option:selected").each(function () {
				if($(this).attr("value") != "076") {
				  $("#form_curso3_estado").css("display","none");
					$("#form_curso3_estado_select").removeAttr("name");
					$("#form_curso3_estado_input").attr("name","form_curso3_estado");
				} else {
				  $("#form_curso3_estado").css("display","block");
					$("#form_curso3_estado_input").removeAttr("name");
					$("#form_curso3_estado_select").attr("name","form_curso3_estado");
				}
	  });
	});
	
	$("#form_curso4_pais").change(function () {
    var pais = "";
   	$("#form_curso4_pais option:selected").each(function () {
				if($(this).attr("value") != "076") {
				  $("#form_curso4_estado").css("display","none");
					$("#form_curso4_estado_select").removeAttr("name");
					$("#form_curso4_estado_input").attr("name","form_curso4_estado");
				} else {
				  $("#form_curso4_estado").css("display","block");
					$("#form_curso4_estado_input").removeAttr("name");
					$("#form_curso4_estado_select").attr("name","form_curso4_estado");
				}
	  });
	});
}