window.defaultUrl = "";

$(function(){	
	
	if(!empty(s = $(document).find("SCRIPT")))
	{
		window.defaultUrl = s.get(0).src.toString().split("js/")[0];
	}
	
	$("#conteudo form fieldset select option:odd").addClass("odd");	

	$("ul li:last-child").addClass("last");
	
	showAguarde.create();
	
	$("#activity").ajaxStart(function(){
		window.showAguarde();
	}).ajaxComplete(function(){
		window.hideAguarde();
	});
	
	/* IE6 */
	if($.browser.msie && $.browser.version < 7)
	{
		$("#menu").FixSFMenu();
	}
	
	/* SWF */
	$("#topo-flash").flash({
		src: window.defaultUrl + "swf/topo.swf",
		height: "100%",
		width: "100%",
		wmode: "opaque",
		scale: "noscale"
	});
	
	$("#fatura_flash").flash({
		src: window.defaultUrl + "swf/fatura_cooperalianca.swf",
		height: "100%",
		width: "100%",
		wmode: "opaque",
		scale: "noscale"
	});
	
	$('#banner-capa').flash({
		src: defaultUrl+'swf/banner.swf?1',
		height: "100%",
		width: "100%",
		wmode: 'transparent'
	});
	
	$("#topo h1, #topo form").hide();
	
	$('a[rel~=blank],a[rel~=external]').each(function(){
		$(this).attr('target','_blank');
	});
	
	/*acesso a area restrita*/
	$('#conta, #cnpj, #digito, #conta1, #cnpj1, #digito1').keyup(function(){
		var val = $(this).val();
		val = val.replace(/[^0-9]/g,'');
		$(this).val(val);
	});
	
});

$(window).load(function(){
	if($("#conteudo").height()+30 > $("#lateral").height())
	{
		$("#lateral").height( $("#conteudo").height()+70 );
	}

});

function doSearch(q)
{
	$("#formBusca").find("#q").val(q);
	$("#formBusca").submit();
}

function showAguarde()
{
	$("#activity").remClass("disabled");
	
	//fixed activity...
	window.onscroll = showAguarde.fixed;
	window.onscroll();
	
	showAguarde.inProcess = true;	
}
showAguarde.create = function()
{
	var d = $('<div id="activity" class="disabled">Carregando Dados...</div>');
	$(document.body).append(d);
}
showAguarde.fixed = function()
{
	var a = $("#activity");
	if(!empty(a))
	{
		var y1 = document.documentElement.scrollTop || 0;
		var y2 = document.body.scrollTop || 0;
		var y3 = window.scrollY || 0;
		
		var y = Math.max(y1, Math.max(y2, y3));
			
		a.css({"top": (y + 200) + "px"});
	}
	else
	{
		window.onscroll = function(){};
		delete window.onscroll;
	}
		
}
showAguarde.inProcess = false;

function hideAguarde(){ $("#activity").addClass("disabled"); showAguarde.inProcess = false; }

function $cake(s)
{
	s = s.split("_").join("/")
	s = s.split("/");
	for(var i=0; i<s.length; i++)
	{
		s[i] = s[i].substr(0, 1).toUpperCase() + s[i].substr(1);
	}
	s = s.join("");
	return "#" + s;
}
