var tablespace,fileload,pg;
function carrega(tablespace,fileload)
{
	$.ajax({
			type: "POST",
			url: fileload,
			data: "pg="+pg,
			beforeSend: function(){
			height = $("div#"+tablespace).height();
			$("div#"+tablespace).html("<div class='carregando'></div>");
			$(".carregando").css("height",height+"px");
			},
			success: function(e){
				$("div#"+tablespace).html(e);
			}
		});
}
function Message(titulo,message,botoes,width)
	{
		box_h = $('body').height() + $('body').offset().top;
		$('.blockbg').css("height",box_h+"px");
		defaultfunc = '<div class="btn"> <input type="button" onclick="CloseWin(true)" value="OK" /> </div>';
		if(empty(botoes))
			message += defaultfunc;
		else
			message += botoes;
		titulo +='<div class="closewin"> </div>';
		$('.windowin h3').html(titulo);
		$('.contentout .content').html(message);
		if(width)
		{
			mleft = width/2;
			$('#window').css("width",width+"px");
			$('#window').css("margin-left","-"+mleft+"px");
		}
		height = $('#window').height();
		margin = height/2;
		$('#window').css("margin-top","-"+margin+"px");
		$('#window').show("slow");
	}
function Refresh()
{
	document.location.reload();
}
function CloseWin()
	{
		$('.blockbg').css("height","0px");
		$('#window').hide("slow");
	}
/*
function toogle(element)
	{
		element.slideToggle('slow');
	}
*/
function empty(mixed_var)
	{
		if (mixed_var === "" ||
    	    mixed_var === 0 ||
    	    mixed_var === "0" ||
    	    mixed_var === null ||
    	    mixed_var === false ||
    	    mixed_var === undefined
    	){
        	return true;
    	}
		else
		return false;
	}

function replaceAll(mixed_var,mixed_search,mixed_replace)
{
	mixed_search = '/'+mixed_search+'/ig';
	mixed_var = mixed_var.replace(eval(mixed_search),mixed_replace);
return mixed_var;
}
	
//// Filial
function LoadSelect(baseUrl,table,selfield,field)
	{
		$.ajax({
			type: "POST",
			data: "id="+field,
			dataType: "json",
			//url: "pages/adm/ajax/post/"+table+".select.ajax.php",
			url: baseUrl+table+".select.ajax.php",
			success: function(e){
				$('.'+selfield).replaceWith(e.seletion);
				$('.'+selfield).val(e.fieldval);
				if(table=="filiais")
				{
					$('.'+e.campo).val(e.fieldval);
					LoadSelect(baseUrl,"setor","ssetor",e.fieldval);
					$("#setores").css("display","block");
					$(".setormsg").css("display","none");
				}
				else if(table=="setor")
				{
					$(".id_setor").val($('.ssetor').val());	
				}
			ldsel=1;
			}
			});
	}

function resetForm(id) {
	$('#'+id).each(function(){
	        this.reset();
	});
}

function HideFilial(baseUrl)
	{
	$(".addfilial").show();
	$(".filial").hide("slow");
	LoadSelect(baseUrl,"filiais","sfilial","");
	}
function HideSetor(baseUrl)
	{
	$(".addsetor").show();
	$(".setor").hide("slow");
	LoadSelect(baseUrl,"setor","ssetor",$('.setor .id_filial').val());
	}
function HidePessoa(titulo,message)
	{
	//tb_remove();
	$("#pessoas #nome").val("");
	$("#pessoas #email").val("");
	Message(titulo,message);	
	}

$(function(){
$('.blockbg .blockbg').css("opacity","0.6");
	
	$('.closewin').live("click",function(){
		CloseWin();
	});	
});


