//formulario de contato
$(document).ready(function(){
	// Form de orcamento
	$("div.form_orcamento").show();
	$("div.form_orcamento form input[type=submit]").before("<a href=\"#\" style=\"color: darkred; margin-right: 20px; display: none;\" class=\"form_informacoes_incorretas\">As informações não estão corretas. Quero alterar.</a>");
	
	var mostraVerificacao = false;
	$("div.form_orcamento form").submit(function() {
		if(mostraVerificacao==false) {
			$("div.form_orcamento").slideUp("slow", function() {

				alert("Antes de enviar o orçamento, por favor verifique novamente se as informações estão corretas.");
				mostraVerificacao = true;
				
				$("div.form_orcamento form input[type=submit]").val("Verifiquei as informações. Solicitar orçamento.");
				$("div.form_orcamento form input").each(function() {
					if($(this).attr("type")!="submit") {
						$(this).attr("disabled","disabled");
					}
				});
				
				$("div.form_orcamento form select").each(function() {
					$(this).attr("disabled","disabled");
				});
				$("a.form_informacoes_incorretas").show();
				$("div.form_orcamento").slideDown("fast");
			});
			return false;
		} else {
			$("div.form_orcamento form input").each(function() {
				if($(this).attr("type")!="submit") {
					$(this).attr("disabled","");
					$(this).attr("readonly","readonly");
				}
			});
			
			$("div.form_orcamento form select").each(function() {
				$(this).attr("disabled","");
				$(this).attr("readonly","readonly");
			});
		}
	});
	
	$("a.form_informacoes_incorretas").click(function() {
		mostraVerificacao = false;
		$("div.form_orcamento").slideUp("slow", function() {
			$("div.form_orcamento form input[type=submit]").val("Solicitar orçamento.");
			$("div.form_orcamento form input").each(function() {
				if($(this).attr("type")!="submit") {
					$(this).attr("disabled","");
				}
			});
			
			$("div.form_orcamento form select").each(function() {
				$(this).attr("disabled","");
			});
			
			//$(this).hide();
			$("div.form_orcamento").slideDown("fast");
		});
		
		return false;
	});
	
		/*
	
	$("div.form_orcamento form").submit(function() {
		
		if(mostraVerificacao==false) {
			div.form_orcamento.slideUp(function() {
				$("div.form_orcamento form input").css("border","none");
				div.form_orcamento.slideDown();
			});
			mostraVerificacao = true;
			return false;
		}
	});
	*/

	var erro = "";
	// ao enviar o formulario
	$('#formulario_contato').bind('submit',function(){

		if (! $('#nome').val() || $('#nome').val()=="Nome *" ) {
			erro = erro + '- Nome\n';
		}
		if ((! $('#email').val()   )||($('#email').val().indexOf("@")==-1)) {
			erro = erro + '- E-mail\n';
		}		
		if (! $('#mensagem').val() || $('#mensagem').val() == "Mensagem *" ) {
			erro = erro + '- Mensagem\n';
		}
		if (erro != "") {
			alert("Os seguintes campos devem ser preenchidos:\n"+erro);
			erro="";
		return false;
	  }
	});
});
//adicionar aos favoritos
function addFav(){
	var url="http://hbrarcomprimido.com.br/";
	var title="HBR";
	if (window.sidebar) window.sidebar.addPanel(title, url,"");
	else if(window.opera && window.print){
	var mbm = document.createElement('a');
	mbm.setAttribute('rel','sidebar');
	mbm.setAttribute('href',url);
	mbm.setAttribute('title',title);
	mbm.click();
	}
	else if(document.all){window.external.AddFavorite(url, title);}
}
//buscar
var buscaValorOriginal="";
$(document).ready(function(){
	$('div#buscar #s').focus(function() {
		if(this.value=='Buscar'||this.value=='Search'){
			buscaValorOriginal = this.value;
			this.value='';
		}
	});
	$('div#buscar #s').blur(function() {
		if(this.value==''){this.value=buscaValorOriginal;}
	});		
	
	
	
	////////////////
	// Cadastre-se
	////////////////
	$("div.cadastrese form select#ocupacao").change(function() {
		var selecionado = $(this).val();
		if(selecionado!="") {
			$("div.cadastrese form li.empresa_faculdade").slideDown("normal");
			if(selecionado=="estudante") {
				$("div.cadastrese form li.empresa_faculdade label.empresa").css("display","none");
				$("div.cadastrese form li.empresa_faculdade label.faculdade").show();
			} else if(selecionado=="profissional") {
				$("div.cadastrese form li.empresa_faculdade label.faculdade").css("display","none");
				$("div.cadastrese form li.empresa_faculdade label.empresa").show();	
			}
		} else {
			if($("div.cadastrese form li.empresa_faculdade").css("display")!="none") {
				$("div.cadastrese form li.empresa_faculdade").slideUp();
							}
		}
	});
	
	$("div.cadastrese a.sim_criarsenha").click(function(){
		$("div.cadastrese ul.formulario").slideDown();
		$("div.cadastrese div.info_newsletter").slideUp();
	});
	

	/////////////////////////
	// Abre e fecha cursos //
	/////////////////////////
	$("#content.cursos ul.cursos li div.titulo a").click(function() {
		var curso_id = $(this).attr("href").substr(1);
		$("#content.cursos ul.cursos li div.conteudo").slideUp();	
		$("#content.cursos ul.cursos li div.conteudo.curso"+curso_id).slideDown();	
	});


	/////////////////
	// Ver no mapa //
	/////////////////
	$("#content.contato a.mapa").click(function() {
		var mapa_clicado = $(this).attr("href").substr(1);
		var mapa_display = $("#content.contato div.mapa."+mapa_clicado).css("display");
		if(mapa_display=="none") {
			$("#content.contato div.mapa").fadeOut("fast",function() {
				$("#content.contato div.mapa."+mapa_clicado).fadeIn();
			});
		}
	});
	
	
	/////////////////////////////
	// Mousehover Compressores
	/////////////////////////////
	$("div.orcamento div.compressores table tr").mouseover(function() {
		$(this).addClass("hover");
	});
	
	$("div.orcamento div.compressores table tr").mouseout(function() {
		$(this).removeClass("hover");
	});
	
	$("div.orcamento div.compressores table tbody tr").click(function() {
		$("div.orcamento div.compressores table tbody tr td").removeClass("ativo");
		$(this).children("td.checkbox").children().attr("checked",true);
		$(this).children("td").addClass("ativo");
		orcCheckboxResfriamentoSoAgua($(this).children("td.checkbox").children());
	});
	
	function orcCheckboxResfriamentoSoAgua(cb) {
		var irsa_arr = idResfriamentoSoAgua.split(",");
		var val_atual = $(cb).attr("value");
		var tem = false;
		for(x=0;x<irsa_arr.length;x++) {
			if(val_atual==irsa_arr[x]) {
				tem=true;
			}
		}

		if(tem==true) {
			$("div.resfriamento input.ar").attr("disabled",true);
			$("div.resfriamento input.ar").attr("checked",false);
			$("div.resfriamento input.agua").attr("checked",true);
		} else {
			$("div.resfriamento input.ar").attr("disabled",false);
			$("div.resfriamento input.ar").attr("checked",false);
			$("div.resfriamento input.agua").attr("checked",false);
		}
	}
	
	
	
	
	//////////////////////////////
	// compressores_nirvana 
	//////////////////////////////
	$("div.orcamento table.compressores_nirvana").mouseover(function() {
		$(this).addClass("hover");
	});
	
	$("div.orcamento table.compressores_nirvana").mouseout(function() {
		$(this).removeClass("hover");
	});
	
	$("div.orcamento table.compressores_nirvana").click(function() {
		$("div.orcamento table.compressores_nirvana td").removeClass("ativo");
		$(this).children("thead").children("tr").children("th").children("input").attr("checked",true)
		//$(this).children("thead tr th").children("input").attr("checked",true);
		$(this).children("tbody").children("tr").children("td").addClass("ativo");
		//orcCheckboxResfriamentoSoAgua($(this).children("td.checkbox").children());
	});
	
	/////////////////
	// Carrega RSS //
	/////////////////
	$.get(posts_url, function(data) {
		//alert("Data Loaded: " + data);
		$("div#inicio_blog_posts").html(data);
	});

});



