var webtree = {
	name: "webtree",
	/** @id webtree_Object */
	Object: function(name) {
		this.name = name;
		this.core = webtree;
		this.toString = webtree.toString;
		this.Object = function(name) {
			this.name = name;
			this.core = webtree;
			this.toString = webtree.toString;
			this.Object.prototype = this;
		};
		this.Object.prototype = this;
	},
	setBodyHeight: function() {
		this.h = (document.body.clientHeight - 207);
		$('div.body').height(this.h + "px").show();
		$('div.corner').height(this.h + 114 + "px").show();
	},
	mask_cep: function(CAMPO) {
		if (CAMPO.value.length == 5) { CAMPO.value += '-'; }
	},
	mask_cpf: function(CAMPO) {
		if (CAMPO.value.length == 3 || CAMPO.value.length == 7) { CAMPO.value += '.'; }
		if (CAMPO.value.length == 11) { CAMPO.value += '-'; }
	},
	mask_phone: function(CAMPO) {
		valor = CAMPO.value.length;
		if (valor == 0) { CAMPO.value += '('; }
		if (valor == 3) { CAMPO.value += ') '; }
		if (valor == 9) { CAMPO.value += '-'; }
	},
	setStuff: function(o, i, e) {
		if ($(o).hasClass("coltrol-tab-opened")) {
			var h = true;
		}
		else {
			var h = false;
		}

		if ($('div.control-content-opened').length > 0) {
			$('div.control-content-opened').removeClass("control-content-opened");
		}
		if ($('a.coltrol-tab-opened').length > 0) {
			$('a.coltrol-tab-opened').removeClass("coltrol-tab-opened");
		}

		$('div.body').removeClass('body-stuff-opened');

		if (!h) {
			$(o).addClass('coltrol-tab-opened');
			$('#' + i).addClass('control-content-opened');
			$('div.body').addClass('body-stuff-opened');
		}
	},
	setControl: function(d, v) {
	    if ($(d).length > 0)
	        $(d).value = value;
	},
	checkItem: function(list, index, hidden) {
	    if (index >= 0) {
	        var items = document.getElementsByName(list);

	        if (items.length > 0)
	            items[index].checked = true;
	        else
	            items.checked = true;

	        this.setItem(list, hidden);
	    }
	},
	setItem: function(list, c) {
	    if ($(c) != null) {
	        var items = document.getElementsByName(list);

	        if (items != null && items.length != null) {
	            for (i = 0; i < items.length; i++) {
	                if (items[i].checked) {
	                    document.getElementById(c).value = i;
	                    break;
	                }
	            }
	        }
	        else
	            document.getElementById(c).value = 0;
	    }
	},
	formatCurrency: function(component, groupSeparator, decimalSeparator, keyPressed) {
		var sep = 0;
		var key = '';
		var i = j = 0;
		var len = len2 = 0;
		var strCheck = '0123456789';
		var aux = aux2 = '';
		var whichCode = (window.Event) ? keyPressed.which : keyPressed.keyCode;

		if (whichCode == 13)
			return true;
		if (whichCode == 8)
			return true;
		key = String.fromCharCode(whichCode);
		if (strCheck.indexOf(key) == -1)
			return false;
		len = component.value.length;
		for (i = 0; i < len; i++)
			if ((component.value.charAt(i) != '0') && (component.value.charAt(i) != decimalSeparator))
			break;
		aux = '';
		for (; i < len; i++)
			if (strCheck.indexOf(component.value.charAt(i)) != -1)
			aux += component.value.charAt(i);
		aux += key;
		len = aux.length;
		if (len == 0)
			component.value = '';
		if (len == 1)
			component.value = '0' + decimalSeparator + '0' + aux;
		if (len == 2)
			component.value = '0' + decimalSeparator + aux;
		if (len > 2) {
			aux2 = '';
			for (j = 0, i = len - 3; i >= 0; i--) {
				if (j == 3) {
					aux2 += groupSeparator;
					j = 0;
				}
				aux2 += aux.charAt(i);
				j++;
			}
			component.value = '';
			len2 = aux2.length;
			for (i = len2 - 1; i >= 0; i--)
				component.value += aux2.charAt(i);
			component.value += decimalSeparator + aux.substr(len - 2, len);
		}
		return false;
	}
}

$(window).load(function() { webtree.setBodyHeight(); });
$(window).resize(function() { webtree.setBodyHeight(); });
