﻿// © SuporteOn


// User Agent (Browser)

var ua = null;
if (window.navigator.userAgent.toLowerCase().indexOf("msie") != -1)
{
	ua = "ie";
}
else if (window.navigator.userAgent.toLowerCase().indexOf("firefox") != -1)
{
	ua = "ff";
}
else if (window.navigator.userAgent.toLowerCase().indexOf("chrome") != -1)
{
	ua = "cr";
}
else if (window.navigator.userAgent.toLowerCase().indexOf("safari") != -1)
{
	ua = "sf";
}
else if (window.navigator.userAgent.toLowerCase().indexOf("opera") != -1)
{
	ua = "op";
}
else if (window.navigator.userAgent.toLowerCase().indexOf("blackberry") != -1)
{
	ua = "bb";
}
else if (window.navigator.userAgent.toLowerCase().indexOf("iphone") != -1)
{
	ua = "ih";
}
else if (window.navigator.userAgent.toLowerCase().indexOf("ipad") != -1)
{
	ua = "ip";
}

// User methods
Array.prototype.count = function(p)
{
	var o = 0;
	for (var i = 0; i < this.length; i++)
	{
		if (this[i] == p)
		{
			o++;
		}
	}
	return(o);
}

Array.prototype.exists = function(p)
{
	for (var i = 0; i < this.length; i++)
	{
		if (this[i] == p)
		{
			return(true);
		}
	}
	return(false);
}

Array.prototype.index = function(p)
{
	for (var i = 0; i < this.length; i++)
	{
		if (this[i] == p)
		{
			return(i);
		}
	}
	return(-1);
}

Array.prototype.not_exists = function(p)
{
	for (var i = 0; i < this.length; i++)
	{
		if (this[i] == p)
		{
			return(false);
		}
	}
	return(true);
}

Number.prototype.chr = function() {
	var o = this;
	return(String.fromCharCode(o));
}

Number.prototype.int = function() {
	var o = this;
	if (isNaN(parseInt(o, 10)))
	{
		return(null);
	}
	return(parseInt(o, 10));
}

Number.prototype.round = function(d) {
	if (d == undefined)
	{
		var d = 0;
	}
	var f = Math.pow(10, d);
	return(Math.round(this * f) / f);
}

String.prototype.asc = function() {
	var o = this;
	return(o.charCodeAt(0));
}

String.prototype.bool = function() {
	var o = this;
	if ((o.toLowerCase() == "true") || (o == "1"))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

String.prototype.int = function() {
	var o = this;
	if (isNaN(parseInt(o, 10)))
	{
		return(null);
	}
	return(parseInt(o, 10));
}

String.prototype.left = function(p) {
	var o = this;
	o = o.substr(0, p);
	return(o);
}

String.prototype.right = function(p) {
	var o = this;
	o = o.substr(o.length - p);
	return(o);
}

String.prototype.repeat = function(n) {
	return(new Array(n + 1).join(this));
}

String.prototype.trim = function() {
	var o = this;
	o = o.replace(/^\s*(.*)/, "$1");
	o = o.replace(/(.*?)\s*$/, "$1");
	return(o);
}

// Functions

function a(u, p, m, d, f)
{
	var hr= ahr();
	if (hr)
	{
		m = m.toLowerCase();
		switch (m)
		{
			case "get":
			{
				hr.open("get", u + ((p == undefined) ? "" : "?" + p), d);
				break;
			}
			case "post":
			{
				hr.open("post", u, d);
				break;
			}
			default:
			{
				return;
			}
		}
		if (d)
		{
			// O evento "onreadystatechange" só funciona no modo Assíncrono no Firefox.
			hr.onreadystatechange = function()
			{
				if (hr.readyState == 4)
				{
					var o = hr.responseXML;
					var t = hr.responseText;
					if (typeof(f) == "function")
					{
						f(o, t);
					}
					else if (typeof(f) == "string")
					{
						eval(f);
					}
				}
			}
		}
		if (m == "get")
		{
			hr.send(null);
		}
		else if (m == "post")
		{
			hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=utf-8");
			hr.setRequestHeader("Content-length", p.length);
			hr.setRequestHeader("Connection", "close");
			hr.send(p);
		}
		if (!d)
		{
			var o = hr.responseXML;
			var t = hr.responseText;
			f(o, t);
		}
	}
}

function ahr()
{
	var hr;
	try
	{
		hr = new XMLHttpRequest(); // Mozilla, Safari, ...
	}
	catch (e)
	{
		try
		{
			hr = new ActiveXObject("Microsoft.XMLHTTP"); // IE
		}
		catch (e)
		{
			try
			{
				hr = new ActiveXObject("Msxml2.XMLHTTP"); // IE
			}
			catch (e)
			{
				try
				{
					hr = new ActiveXObject("Msxml2.XMLHTTP.3.0"); // IE
				}
				catch (e)
				{
					try
					{
						hr = new ActiveXObject("Msxml2.XMLHTTP.4.0"); // IE
					}
					catch (e)
					{
						try
						{
							hr = new ActiveXObject("Msxml2.XMLHTTP.5.0"); // IE
						}
						catch (e)
						{
							try
							{
								hr = new ActiveXObject("Msxml2.XMLHTTP.6.0"); // IE
							}
							catch (e)
							{
								hr = false;
							}
						}
					}
				}
			}
		}
	}
	return(hr);
}

function cen(o)
{
	if (typeof(o) == "string")
	{
		o = el(o);
	}
	style(o, "left", "50%");
	style(o, "marginLeft", (((o.innerWidth ? o.innerWidth : o.clientWidth) / 2) * -1).toString() + "px");
	style(o, "marginTop", (((o.innerHeight ? o.innerHeight : o.clientHeight) / 2) * -1).toString() + "px");
	style(o, "position", "absolute");
	style(o, "top", "50%");
}

function cls(o, c)
{
	if (typeof(o) == "string")
	{
		o = el(o);
	}
	o.className = c;
}

function clr(o)
{
	if (typeof(o) == "string")
	{
		o = el(o);
	}
	if (o.type != undefined)
	{
		if ((o.type == "text") || (o.type == "password"))
		{
			o.value = "";
		}
		else if (o.type == "checkbox")
		{
			if (o.checked != undefined)
			{
				o.checked = false;
			}
			if (o.defaultChecked != undefined)
			{
				o.defaultChecked = false;
			}
		}
	}
}

function curtain()
{
	var o = el("div_full");
	if (style(o, "display") == "none")
	{
		var p = pos(el("tab_model").tBodies[0].rows[1].cells[0]);
		style(o, "left", p.x.toString() + "px");
		style(o, "height", p.h.toString() + "px");
		style(o, "top", p.y.toString() + "px");
		style(o, "width", p.w.toString() + "px");
		show(o);
		show("img_1sp");
	}
	else
	{
		hide(o);
		hide("img_1sp");
	}
}

function el(o)
{
	if (document.getElementById != undefined)
	{
		el = function(o) { return(document.getElementById(o)); };
	}
	else if (document.all != undefined)
	{
		el = function(o) { return(document.all[o]); };
	}
	else if (document.layers != undefined)
	{
		el = function(o) { return(document.layers[o]); };
	}
	else
	{
		el = function() { return(null); };
	}
	return(el(o));
}

function elv(o)
{
	if (typeof(o) == "string")
	{
		o = el(o);
	}
	if ((o.type != undefined) && ((o.type == "text") || (o.type == "password")))
	{
		return(o.value);
	}
}

function evt(o, e, f)
{
		switch (ua)
		{
			case "ie":
			{
				switch (e)
				{
					case "onclick":
					{
						o.onclick = function() { f(event, this); };
						break;
					}
					case "onmouseout":
					{
						o.onmouseout = function() { f(event, this); };
						break;
					}
					case "onmouseover":
					{
						o.onmouseover = function() { f(event, this); };
						break;
					}
				}
				break;
			}
			case "ff":
			case "cr":
			case "sf":
			case "op":
			case "bb":
			case "ih":
			case "ip":
			case null:
			{
				switch (e)
				{
					case "onclick":
					{
						o.addEventListener("click", function(e) { f(e, this); }, false);
						break;
					}
					case "onmouseout":
					{
						o.addEventListener("mouseout", function(e) { f(e, this); }, false);
						break;
					}
					case "onmouseover":
					{
						o.addEventListener("mouseover", function(e) { f(e, this); }, false);
						break;
					}
				}
				break;
			}
		}
}

function fsk(k)
{
	// Special Keys: http://www.quirksmode.org/js/keys.html
	ask = Array(18, 37, 38, 39, 40, 8, 20, 17, 46, 35, 13, 27, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 36, 45, 144, 33, 34, 16, 9, 91); // alt(18), arrow keys (37-40), backspace (8), caps lock (20), ctrl (17), delete (46), end (35), enter (13), escape (27), f1-f12 (112-123), home (36), insert (45), num lock (144), page up/down (33-34), shift (16), tab (9), windows(start) (91).
	return(ask.indexOf(k.int()) == -1);
}

function hide(o)
{
	if (typeof(o) == "string")
	{
		o = el(o);
	}
	style(o, "display", "none");
}

function nel(t, s)
{
	var el = document.createElement(t);
	if ((t.toLowerCase() == "input") && (s != undefined))
	{
		el.type = s;
	}
	return(el);
}

function off(o)
{
	if (typeof(o) == "string")
	{
		o = el(o);
	}
	o.disabled = true;
}

function on(o)
{
	if (typeof(o) == "string")
	{
		o = el(o);
	}
	o.disabled = false;
}

function pos(o)
{
	if (typeof(o) == "string")
	{
		o = el(o);
	}
	var c = {
		x: 0,
		y: 0,
		w: 0,
		h: 0,
		b: 0
	};
	var oo = o;
	while (o)
	{
		c.x += ((o.offsetLeft == undefined) ? 0 : o.offsetLeft);
		c.y += ((o.offsetTop == undefined) ? 0 : o.offsetTop);
		if (o != oo)
		{
			c.x += parseInt(style(o, "borderLeftWidth"), 10) || 0;
			c.y += parseInt(style(o, "borderTopWidth"), 10) || 0;
		}
		o = o.offsetParent;
	}
	var o = oo;
	while ((o) && (o.tagName.toLowerCase() != "body"))
	{
		c.x -= o.scrollLeft;
		c.y -= o.scrollTop;
		o = o.parentNode;
	}
	c.w += oo.offsetWidth;
	c.h += oo.offsetHeight;
	c.b = c.top + c.height;
	return(c);
}

function rets(o, re)
{
	if (typeof(re) == "string")
	{
		re = new RegExp(re);
	}
	return(re.test(o));
}

function sel(o)
{
	if (ua == "bb") // BlackBerry
	{
		return;
	}
	if (typeof(o) == "string")
	{
		o = el(o);
	}
	if (((o.type != undefined) && ((o.type == "text") || (o.type == "password"))) || ((o.tagName != undefined) && (o.tagName == "textarea")))
	{
		if (o.createTextRange != undefined)
		{
			var s = o.createTextRange();
			s.collapse(true);
			s.moveEnd("character", elv(o).length);
			s.moveStart("character", 0);
			s.select();
		}
		else if (o.setSelectionRange != undefined)
		{
				o.setSelectionRange(0, elv(o).length);
		}
	}
}

function show(o)
{
	if (typeof(o) == "string")
	{
		o = el(o);
	}
	style(o, "display", "block");
}

function style(o, s, v)
{
	if (typeof(o) == "string")
	{
		o = el(o);
	}
	if (v == null)
	{
		if ((document.defaultView != undefined) && (document.defaultView.getComputedStyle != undefined))
		{
			e = document.defaultView.getComputedStyle(o, null).getPropertyValue(s);
		}
		else if (o.currentStyle != undefined)
		{
			s = s.replace(/-(\w)/g, function(re, p) { return p.toUpperCase(); });
			e = o.currentStyle[s];
		}
		else
		{
			s = s.replace(/-(\w)/g, function(re, p) { return p.toUpperCase(); });
			e = o.style[s];
		}
		return(e);
	}
	else
	{
		s = s.replace(/-(\w)/g, function(re, p) { return p.toUpperCase(); });
		if (o.style)
		{
			o.style[s] = v;
//			eval("o.style." + s + " = v");
		}
		else
		{
			o.style[s] = v;
//			eval("o.style." + s + " = v");
		}
	}
}

function text(o, t)
{
	if (typeof(o) == "string")
	{
		o = el(o);
	}
	if (t == undefined)
	{
		if (o.textContent != undefined)
		{
			return(o.textContent);
		}
		else if (o.innerText != undefined)
		{
			return(o.innerText);
		}
		else if (o.innerHTML != undefined)
		{
			return(o.innerHTML);
		}
	}
	else
	{
		if (o.textContent != undefined)
		{
			o.textContent = t;
		}
		else if (o.innerText != undefined)
		{
			o.innerText = t;
		}
		else if (o.innerHTML != undefined)
		{
			o.innerHTML = t;
		}
	}
}

function title(o, t)
{
	if (typeof(o) == "string")
	{
		o = el(o);
	}
	o.title = t;
}

function u8d(p)
{
	return(decodeURIComponent(escape(p)));
}

function u8e(p)
{
	return(unescape(encodeURIComponent(p)));
}

function ud(p)
{
	p = p.toString();
	p = p.replace(/\+/g, " ");
	p = unescape(p);
	return(p);
}

function ue(p)
{
	p = p.toString();
	p = p.replace(/\+/g, "%2B");
	p = escape(p);
	return(p);
}

function val(o, v)
{
	if (typeof(o) == "string")
	{
		o = el(o);
	}
	if ((o.type != undefined) && ((o.type == "text") || (o.type == "password")))
	{
		o.value = v;
	}
}
