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 - 536);
		$('div.container').height(this.h + "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;
	},
	setItem: function(c) {
		if ($(c) != null) {
			if (document.forms[0].rdbItem != null && document.forms[0].rdbItem.length != null) {
				for (i = 0; i < document.forms[0].rdbItem.length; i++) {
					if (document.forms[0].rdbItem[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;
	},
	showBlock: function(block) {
		var ctl = document.getElementById(block);

		if (ctl.style.display == 'block') {
			ctl.style.display = 'none'
		}
		else {
			ctl.style.display = 'block';
		}
	},
	setLabel: function(c, v, clear) {
		if (clear) {
			if (c.value == v)
				c.value = "";
		}
		else {
			if (c.value == "")
				c.value = v;
		}
    },
	setMenuStyle: function(li, link, over)
	{
	    if (over)
	    {
	        li.style.backgroundImage='url(../theme/webtree/img/Site/menu-selected-bg.gif)';
	        li.style.cursor='pointer';
	        link.style.color='#ffffff';
	    }
	    else
	    {
	        li.style.backgroundImage='url(../theme/webtree/img/Site/menu-bg.png)';
	        li.style.cursor='';
	        link.style.color='#808080';
	    }
	},
	setBackground: function(c, i) {
		var on = "this.style.backgroundImage='url(../theme/webtree/img/Site/bg-selection-on.png)';";
		var off = "this.style.backgroundImage='url(../theme/webtree/img/Site/bg-selection-off.png)';";
		var con = document.getElementById(c);
		for (j = 1; j <= 3; j++) {
			var div = "ctl00_Header1_divItem" + j;
			var image = "'url(../theme/webtree/img/Site/header-image-home" + j + ".jpg)';";
			document.getElementById(div).setAttribute("onMouseOver", on);
			document.getElementById(div).setAttribute("onMouseOut", off);
			//document.getElementById(div).setAttribute("onClick", "alert(con.style.backgroundImage);");
		}
		con.style.backgroundImage = image;
	}
}

$(window).load(function() { webtree.setBodyHeight(); });
$(window).resize(function() { webtree.setBodyHeight(); });
