/**
* @package			util.js
* @dependence		prototype.js - v1.5.1.1
* @version			0.1
* browser test		FF 2.0.0.x and IE 6.0
* @license			GNU GPL 2.0
* @author			Adenilson dos Santos <denixsi@gmail.com>
* @copyright		Adenilson dos Santos <http://static.com.br>
*/
if(typeof(Prototype) == 'undefined' || parseFloat(Prototype.Version) < 1.5)
	throw("util.js requires the Prototype JavaScript framework >= 1.5.0, get from prototypejs.org");

if (!window.UtilControls)
		var UtilControls = {};

var boxOver		 = null;

UtilControls.Methods = {
	getBaseURL : function() {
		var sub = 'i-card';
		var uri = document.location.href;
		var url = new Array;

		if(uri.indexOf(sub) != -1) {
			uri = uri.split("/");
			uri.each(function(node){
				url.push(node)
				if(node == sub) {
					throw $break;
				}
			});
		}
		return url.join('/');
	},

	redirect : function(json) {
		if(typeof(json.redirect) != 'undefined') {
			return true;
		} else {
			return false;
		}
	},

	modal: function(action, time) {
		var duration = 0;
		if(action) {
			Modal.show(boxOver);
		} else {
			if(typeof(time) != 'undefined') {
				duration = time;
			}
			window.setTimeout('Modal.hide();', duration);
		}
	},

	setBox : function(element) {
		if(typeof(element) == 'undefined') {
			boxOver = $('ajax_overlay');
		} else {
			boxOver = $(element);
		}
	},

	getBox : function() {
		return boxOver;
	},

	setMessage : function(text) {
		if(typeof(boxOver) == 'null') {
			this.setBox();
		}

		if(typeof(text) == 'undefined') {
			text = '';
		}
		boxOver.update(text);
	},

	setOnload : function(element) {
  		window.onload = function(){
  			UtilControls.setBox(element);
  			UtilControls.modal(true);
  		};
	}
}

Object.extend(UtilControls, UtilControls.Methods);