var bottom_controls_always_show = false;

function redireciona_servico(servico){
	
	//servico = servico.toLowerCase();
	//href = '?q=cotacao&tipo='+servico;
	//alert(href);	
	href = servico.toLowerCase();	
	location.href = href;
	
}

function mostra_div(div)
{	
	if(document.getElementById(div).style.display == "none"){
		document.getElementById(div).style.display = "block";

	}
}

function esconde_div(div)
{
	if(document.getElementById(div).style.display == "block")
		document.getElementById(div).style.display = "none";
}

function byId(el) {
	return document.getElementById(el);
}
function popUp(URL)
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=400,height=500');");
}

function always_show_bottom_controls() {
	if(!bottom_controls_always_show && $('div.bottom-controls').css("display")=='none') {
		$('div.bottom-controls').slideDown('fast');
		bottom_controls_always_show = true;
	}
}


// Jason Hunter
	function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}

	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}

	function eraseCookie(name) {
		createCookie(name,"",-1);
	}

	function toggleBox(key,obj) {
		if($('#info_box_'+key).css("display")=='none') {
			$('#info_box_'+key).slideDown("slow");
			$(obj).html("<img src=\"img/btn-collapse.gif\" alt=\"collapse\" />");
		}
		else {
			$('#info_box_'+key).slideUp("slow");
			$(obj).html("<img src=\"img/btn-expand.gif\" alt=\"expand\" />");
		}
		saveAdminState();
	}

	function saveAdminState() {
		createCookie("menustate", getExpandedList());
	}

	function initAdminState() {
		var menuState = readCookie("menustate");
		if(menuState!=null) {
			var menus = menuState.split(",");
			collapseAll(true);
			for(i=0; i < menus.length; i++) {
				$("#"+menus[i]).show();
				x = menus[i].split("_");
				$("#"+x[2]).html("<img src=\"img/btn-collapse.gif\" alt=\"collapse\" />");
			}
		}
	}

	function getExpandedList() {
		var menuState = "";
		$("div.dbx-handle a").contains("collapse").each(function() {
			menuState+="info_box_"+$(this).attr("id")+",";
		});
		return menuState;
	}

	function expandAll() {
		$("div.dbx-handle a").each(function() {
			$('#info_box_'+$(this).attr('id')).slideDown("slow");
			$(this).html("<img src=\"img/btn-collapse.gif\" alt=\"collapse\" />");
		});
		saveAdminState();		
	}
	
	function collapseAll(onInit) {
		$("div.dbx-handle a").each(function() {
			if(onInit==true) {
				$('#info_box_'+$(this).attr('id')).hide();
			}
			else {
				$('#info_box_'+$(this).attr('id')).slideUp("slow");
			}
			$(this).html("<img src=\"img/btn-expand.gif\" alt=\"expand\" />");
		});
		if(onInit==false)
		{
			saveAdminState();
		}
	}

var theTopXF = -10;
var oldXF = theTopXF;

function ajaxLoaderPosition()
{
	if (window.innerHeight)
	{
		  pos = window.pageYOffset
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		pos = document.documentElement.scrollTop
	}
	else if (document.body)
	{
		  pos = document.body.scrollTop
	}
	if (pos < theTopXF) pos = theTopXF;
	else pos += 10;
	if (pos == oldXF)
	{
		$("#ajax-loader").css("top",pos+"px");
	}
	oldXF = pos;
	setTimeout('ajaxLoaderPosition()',1000);
}

function dbxer() {
	//initialise the docking boxes manager
	var manager = new dbxManager('main'); 	//session ID [/-_a-zA-Z0-9/]

	//create new docking boxes group
	var purple = new dbxGroup(
		'menugroup', 		// container ID [/-_a-zA-Z0-9/]
		'vertical', 		// orientation ['vertical'|'horizontal']
		'10', 			// drag threshold ['n' pixels]
		'yes',			// restrict drag movement to container axis ['yes'|'no']
		'7', 			// animate re-ordering [frames per transition, or '0' for no effect]
		'no', 			// include open/close toggle buttons ['yes'|'no']
		'abrir', 		// default state ['open'|'closed']
		'abrir', 		// word for "open", as in "open this box"
		'fechar', 		// word for "close", as in "close this box"
		'clique e segure para mover essa caixa', // sentence for "move this box" by mouse
		'click to %toggle% this box', // pattern-match sentence for "(open|close) this box" by mouse
		'use the arrow keys to move this box', // sentence for "move this box" by keyboard
		', or press the enter key to %toggle% it',  // pattern-match sentence-fragment for "(open|close) this box" by keyboard
		'%mytitle%  [%dbxtitle%]' // pattern-match syntax for title-attribute conflicts
		);
}