function msgbox(mensagem, classe, callback) {
	//alert(mensagem);
	// return false;
	
	callbackModal = callback;
	if (!classe)
		classe = "alerta";
	var html = 
	        '<div class="msgbox-' + classe + '" style="margin:0">'
			+ '<p align="center" style="padding: 0 42px 0 0">'
			+ mensagem
			+ '</p>'
			+ '<div class="clear">&nbsp;</div>'
			+ '<p align="center" style="padding: 0 42px 0 0"><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 confirmBox(mensagem, elemento) {
	
	html = '<div id="dialog-confirm" title="" style="display:none">'
		+ '<p style="margin:10px 0px 0px 0px;">'
		+ '<span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>'
		+ mensagem
		+ '</p>'
		+ '</div>';

	el = $(elemento);
	el.before(html);

	$("#dialog-confirm").dialog({ 
		autoOpen: true, 
		resizable:false,
		draggable:false,
		modal: true,
		title: 'Confirmação',
		buttons: {
			"Cancelar": function() {
				$(this).dialog("close"); 
				$("#dialog-confirm").remove();
			},
			"OK": function() {
				$(this).dialog("close"); 
				$("#dialog-confirm").remove();
				window.location = el.attr('href'); 
			}
		}
	});
	
	return false;
};

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);
		}
	});
}

function validaEmail(email) {
	if ( email ) {
		var txt = email;
		if (txt.length > 0 && txt.indexOf("@") >= 1 && txt.indexOf('.') >= 7 ) {
			return true;
		}
	}
	return false;
}

$(document).ready(function(){
	$('a[rel^="prettyPhoto"]').prettyPhoto();
});

