// JavaScript Document

function openpop(pag) {
	window.open(pag, 'janela','scrollbars=yes,resizable=yes,width=850,height=720');
}


$(document).ready(function() {
						   
	// fix for target="_blank"
	$("a[rel='external']").click(function(){
		window.open($(this).attr("href"), 'janela','scrollbars=yes,resizable=yes,width=880,height=720');
		return false;
	});
	
	function limpaform(){
		var arg="#"+idform + " :input";
		$(arg).each(function() { // Pega os campos do form
			if(this.type=='text' || this.type=='hidden' || this.type=='password')
				this.value='';
		});
	}
	
	// fix for target="_blank" de form
	$("form").submit(function(){
		idform = $(this).attr('id');
		otarg = $(this).attr('target');
		if(otarg!='') {
			window.open('', 'janela','scrollbars=yes,resizable=yes,width=850,height=720');
			setTimeout(limpaform, 2000);
		}
		return true;
	});
	
	//focus no primeiro campo
	$("#f_contato :input:visible:enabled:first").focus();
	
	if($("#tabela").length > 0) {
		var Wwid = $(window).width();
		var Whei = $(window).height();
		if(Wwid<1000) {
			$("#tabela").css({'display':'block','position':'static'});
			$("#celula").css({'display':'block','position':'static','verticalAlign':'top'});
			$("#index_corpo").css("top","10px");
		}
	}

	$('.backtotop').click(function(event){
		$('html, body').animate({scrollTop:0}, 'slow');
		event.preventDefault();
	});
	
	// Idade da empresa
	var aidade = function() {
		var hoje = new Date();
		var fund = new Date("1991, jan, 1")  // Data da fundação
		var anoH = hoje.getFullYear();
		var anoF = fund.getFullYear();
		var idade = parseInt((((((hoje - fund)/1000)/60)/60)/24)/365);
		$('#bx_idade').html(idade);
	}
	if($('#bx_idade').length>0) aidade();
	
	// Over de imagens
	$('.over').hover(
		function() { this.src = this.src.replace("_off","_on");  },
		function() {  this.src = this.src.replace("_on","_off"); }  
	)


});

