utl = {}
// verifica DOM
utl.dom = (document.getElementById && document.createTextNode && document.getElementsByTagName)? true : false;
// st = standardbody - create reference to common "body" across doctypes
utl.std = ( document.compatMode=="CSS1Compat")? document.documentElement : document.body;
//show hide
utl.swh = function(o)
{
	var ob=document.getElementById(o);
	if(!ob){return;}
// if the object display setting is 'none',
// set it to 'block' and vice versa
	ob.style.display=ob.style.display=='none'?'block':'none';
}
//test elements by id
utl.tei = function(e)
{
	return (utl.dom && document.getElementById(e))?true:false;
}
// get elements by id alias
utl.gei = function(e)
{
	if(utl.tei(e))
	return document.getElementById(e);
}
//get elements by tag name
utl.get = function(t)
{
	if(utl.dom)
	return document.getElementsByTagName(t);
}
/**
 * Função de busca por tags com determinada classe CSS
 *
 * @param {String} c a Classe e ser pesquisada
 * @param {String} t a Tag container da classe, um refinamento da pesquisa, use "*" para todos os elementos
 * @param {Object} n o O Nodo inicial da árvore DOM a ser pesquisada
 *
 * @return {Array} ce Array contendo os elementos com a classe pesquisada
 *
 * :c = class
 * :t = tag
 * :n = node
 * :gec = get element by class
 * :ce = class elements
 * :e = elements
 * :el = elements length
 * :p = pattern
 */
utl.gec = function (c,t,n)
{
	var ce = new Array();
	if(!n) n = document.body;
	var e = n.getElementsByTagName(t);
	var el = e.length;
	var p = new RegExp("\\b"+c+"\\b");
	for (i = 0, j = 0; i < el; i++)
	{
 		if ( p.test(e[i].className) )
		{
 			ce[j] = e[i];
 			j++;
 		}
	}
	return ce;
}
/**
 * Função de alterar, adicionar, remover e checar as classes css de determinando(s) elementos
 *
 * @param {String} a O nome da opeação (s = swap (troca), a = add (adicionar), r = remove (remover), c = check (checar) )
 * @param {String} o O objeto a ser alterado
 * @param {String} c1 A primeira classe
 * @param {String} o A segunda classe
 *
 * @return {Boolean}  Boleano caso a operação seja checar
 *
 * :c = class
 * :t = tag
 * :n = node
 * :gec = get element by class
 * :ce = class elements
 * :e = elements
 * :el = elements length
 * :p = pattern
 */
utl.css = function (a,o,c1,c2)
{
	switch (a)
	{
		case 's':
			o.className=!utl.css('c',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
			break;
		case 'a':
			if(!utl.css('c',o,c1))
			{
				o.className+=o.className?' '+c1:c1;
			}
			break;
		case 'r':
			var r=o.className.match(' '+c1)?' '+c1:c1;
			o.className=o.className.replace(r,'');
			break;
		case 'c':
			return new RegExp("(^|\\s)" + c1 + "(\\s|$)").test(o.className)
			break;
	}
}
/**
 * Função de adicionar eventos ao navegador
 *
 * @param {Object} o O objeto a ser anexado o evento
 * @param {Object} t Tipo de evento em a convenção "on". Ex: onload = load
 * @param {Object} f A função a ser disparada com o evento
 * @param {Object} c A função de callback disparada
 *
 * :o = object
 * :t = type
 * :f = function
 * :c = callback
 */
utl.ade = function(o,t,f,c)
{
	if (o.addEventListener)
	{
		o.addEventListener(t, f, c);
		return true;
	}
	else if (o.attachEvent)
	{
		var r = o.attachEvent('on' + t, f);
		return r;
	}
	else
	{
		o['on' + t] = f;
	}
}
/**
 * Função de chamada de dados ajax
 *
 * @param {String} u A URL onde deve ser enviada a consulta ajax
 * @param {String} t O ID do elemento onde será inserido o resultado
 *
 * :u = url
 * :t = target
 * :c = callback
 */
utl.ajx = function(u,t,c)
{
	document.getElementById(t).innerHTML = "<p><strong>Carregando...</strong></p>";
	// função nativa ajax
	if (window.XMLHttpRequest)
	{
		r = new XMLHttpRequest();
		r.onreadystatechange = function() {utl.ajd(t,c);};
		r.open("GET", u, true);
		r.send(null);
	}
	// função IE
	else if (window.ActiveXObject)
	{
		r = new ActiveXObject("Microsoft.XMLHTTP");
		if (r)
		{
			r.onreadystatechange = function() {utl.ajd(t,c);};
			r.open("GET", u, true);
			r.send();
		}
	}
}
/**
 * Função de insersão quando retornado os dados ajax
 *
 * @param {String} t O ID do elemento onde será inserido o resultado
 *
 * :t = target
 * :r = requisition
 * :re = resposta
 */
utl.ajd = function(t,c) {
	// teste se a requisição obteve sucesso
	if (r.readyState == 4)
	{
		// verifica o status
		if (r.status == 200)
		{
			re = r.responseText;
			document.getElementById(t).innerHTML = re;
			if (c)
			c();
		}
		else
		{
			document.getElementById(t).innerHTML="Erro ajax:\n" +
			r.statusText;
		}
	}
}
/**
 * Função de Popup aprimorada
 *
 * @param {String} p A URL da página a ser aberta
 * @param {Object} n O nome da janela
 * @param {String} w A largura da janela acompanhada dos pixels
 * @param {String} h A altura da janela acompanhada dos pixels
 * @param {Boolean} s Verdadeiro se a janela deve mostrar o scrool
 *
 * :p = page
 * :n = name
 * :w = width
 * :h = height
 * :s = scroll
 * :l = left position
 * :t = top position
 * :st = settings
 */
var win = null;
utl.nwd = function(p,n,w,h,s)
{
	var l = (screen.width) ? (screen.width-w)/2 : 0;
	var t = (screen.height) ? (screen.height-h)/2 : 0;
	var st = 'height='+h+',width='+w+',top='+t+',left='+l+',scrollbars='+s+',resizable'
	win = window.open(p,n,st)
}
// centraliza elementos
utl.cen = function(o)
{
	var ie = document.all && !window.opera;
	var dom = document.getElementById;
	var st = (ie) ? utl.std.scrollTop : window.pageYOffset; // st = scroll top
	var sl = (ie) ? utl.std.scrollLeft : window.pageXOffset; // sl = scroll left
	var dw = (ie) ? utl.std.clientWidth : window.innerWidth - 16; // dw = doc width
	var dh = (ie) ? utl.std.clientHeight: window.innerHeight; // dh = doc height
	var ow = o.offsetWidth; // ow = obj width - width of div element
	var oh = o.offsetHeight; // oh = obj height -  height of div element
	var tp = (dh > oh)? st + dh / 2 - oh / 2 + "px" : st + 10 + "px" //tp = top position - Vertical position of div element: Either centered, or if element height larger than viewpoint height, 10px from top of viewpoint
	o.style.left = dw / 2 - ow / 2 + "px" //Center div element horizontally
	o.style.top = Math.floor(parseInt(tp)) + "px";
}
utl.opa = function(o,v,b)
{
	ob = document.getElementById(o);
	ob.style.opacity = v/10;
	ob.style.filter = 'alpha(opacity=' + v*10 + ')';
	if (b) ob.style.backgroundColor = b;
	ob.style.MozOpacity=v/10
	ob.style.KhtmlOpacity=v/10

}
utl.pnf = function()
{
	function fnLoadPngs() {
		var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
		var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
		for (var i = document.all.length - 1, obj = null; (obj = document.all[i]); i--) {
			if (itsAllGood && obj.currentStyle.backgroundImage.match(/\.png/i) != null) {
				fnFixPng(obj);
				obj.attachEvent("onpropertychange", fnPropertyChanged);
			}
		}
	}

	function fnPropertyChanged() {
		if (window.event.propertyName == "style.backgroundImage") {
			var el = window.event.srcElement;
			if (!el.currentStyle.backgroundImage.match(/x\.gif/i)) {
				var bg	= el.currentStyle.backgroundImage;
				var src = bg.substring(5,bg.length-2);
				el.filters.item(0).src = src;
				el.style.backgroundImage = "url(x.gif)";
			}
		}
	}

	function fnFixPng(obj) {
		var bg	= obj.currentStyle.backgroundImage;
		var src = bg.substring(5,bg.length-2);
		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
		obj.style.backgroundImage = "url(x.gif)";
	}




	return {

		init: function() {

			if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
				utl.ade(window,"load",fnLoadPngs);
			}

		}
	}

}();
utl.gck = function(n)
{
	var re=new RegExp(n+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
	return document.cookie.match(re)[0].split("=")[1] //return its value
	return ""
}
utl.sck = function(n,v)
{
	document.cookie = n+"="+v //cookie value is domain wide (path=/)
}