function msgbox(mensagem, classe, callback) {
	// alert(mensagem);
	// return false;
	
	callbackModal = callback;
	if (!classe)
		classe = "";
	var html = 
	        '<div class="'
			+ classe
			+ '" style="margin:0"><p align="center">'
			+ mensagem
			+ '</p><div class="clear">&nbsp;</div><p align="center"><button onclick="fecharModal();">OK</button></p><div class="clear">&nbsp;</div></div>';
	$.blockUI( {
		message : html,
		css : {
			cursor : 'default',			
			border : 'none',
			padding : '0',
			padding : '0',
			backgroundColor : '#000'
			// opacity : .9
		}
	});
	
};

function fecharModal() {
	$.unblockUI( {
		onUnblock : callbackModal
	});
};

function inteiro(obj, e) {
	var tecla = (window.event) ? e.keyCode : e.which;
	if (tecla == 8 || tecla == 0)
		return true;
	if (tecla < 48 || tecla > 57)
		return false;
};


$(document).ready(function(){
	$('.botoes').buttonset();
	$('input:button,input:submit,input:reset').addClass("ok");	
});

function makeScrollableHorizontal($outer, $inner){
	var extra 			= 800;
	// Get menu width
	var divWidth = $outer.width();
	// Remove scrollbars
	$outer.css({
		overflow: 'hidden'
	});
	// Find last image in container
	var lastElem = $inner.find('img:last');
	$outer.scrollLeft(0);
	// When user move mouse over menu
	$outer.unbind('mousemove').bind('mousemove',function(e){
		var containerWidth = lastElem[0].offsetLeft + lastElem.outerWidth() + 2*extra;
		var left = (e.pageX - $outer.offset().left) * (containerWidth-divWidth) / divWidth - extra;
		$outer.scrollLeft(left);
	});
}


function makeScrollableVertical($outer, filho){
	var extra 			= 800;
	// Get menu width
	var divHeight= $outer.height();
	// Remove scrollbars
	$outer.css({
		overflow: 'hidden'
	});
	// Find last item in container
	var lastElem = $outer.children(filho+':last');	
	$outer.scrollTop(0);
	// When user move mouse over menu
	$outer.unbind('mousemove').bind('mousemove',function(e){
		var containerHeight = lastElem[0].offsetTop + lastElem.outerHeight() + 2*extra;
		var top = (e.pageY - $outer.offset().top) * (containerHeight-divHeight) / divHeight- extra;
		$outer.scrollTop(top);
	});
}

function in_array(needle, haystack, argStrict) {
	var key = '', strict = !!argStrict;

	if (strict) {
		for (key in haystack) {
			if (haystack[key] === needle) {
				return true;
			}
		}
	} else {
		for (key in haystack) {
			if (haystack[key] == needle) {
				return true;
			}
		}
	}
	return false;
}

function sleep(milliseconds) {
	var start = new Date().getTime();
	for (var i = 0; i < 1e7; i++) {
		if ((new Date().getTime() - start) > milliseconds){
			break;
		}
	}
}

function seleciona_option(select, value) {
	$(select+' option').each(function(){
		if($(this).val() == value){
			$(this).attr('selected',true);
		}
	});
}

