var isIE =(/\bmsie\b/i.test(navigator.userAgent)&& document.all&&!(/\bopera\b/i.test(navigator.userAgent)));
//var isIE =(/MSIE (\d+\.\d+);/.test(navigator.userAgent) && document.all&&!(/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)));
//var ieversion=new Number(RegExp.$1)
//if (ieversion>=6) var isIE6 = true
//var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
//var isIE  = (navigator.appVersion.indexOf("MSIE") != -1 && isOpera == false) ? true : false;
var isIE6 =(/\bmsie 6.0\b/i.test(navigator.userAgent));

$ = function (a) {
	return document.getElementById(a);
};

$_ = getFlashObject = getFlash = function(n) {
	if (navigator.appName.indexOf("Microsoft")!=-1) return window[n]; else return document[n];
};
// Aplica um valor alpha de 0 a 100
setAlpha = function (e, a) {
	a = Math.round(a);
	if (typeof e == 'string') e = $(e);
	with (e.style) {
		if (isIE) {
			filter = 'alpha(opacity='+a+')';
		} else {
			opacity = a/100;
		}
	}
};
// Aplica a posição x e y a um objeto
setPosition = function (obj, x, y) {
	with (obj.style) {
		top = x+'px';
		left = y+'px';
	}
};
// Retorna a posição de um objeto
getPos = function (e) {
	if (typeof e == 'string') e = $(e);
	var left = 0;
	var top = 0;
	while (e.offsetParent) {
		left += e.offsetLeft;
		top += e.offsetTop;
		e = e.offsetParent;
	}
	left += e.offsetLeft;
	top += e.offsetTop;
	return {x:left, y:top};
};
// Retorna o tamanho de um objeto
getSize = function (e) {
	if (typeof e == 'string') e = $(e);
	return {x:e.offsetWidth, y:e.offsetHeight};
};
// Retorna o tamanho total do documento
getDocSize = function () {
	return {x:document.body.offsetWidth, y:document.body.offsetHeight};
};
// Retorna o tamanho da área visivel
getDocVisibleSize = function () {
	var _x, _y;
	if (window.innerWidth) {
		_x = window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		_x = document.documentElement.clientWidth;
	} else if (document.body) {
		_x = document.body.clientWidth;
	}
	if (window.innerHeight) {
		_y = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		_y = document.documentElement.clientHeight;
	} else if (document.body) {
		_y = document.body.clientHeight;
	}
	return {x:_x, y:_y};
};
/* Função para gerar um valor unico */
nocache = function (nivel) {
	nivel = nivel || 6;
	var data = new Date();
	var s = data.getFullYear();
	if (nivel>0) {
		s += '.'+(data.getMonth()+1);
	}
	if (nivel>1) {
		s += '.'+data.getDate();
	}
	if (nivel>2) {
		s += '.'+data.getHours();
	}
	if (nivel>3) {
		s += '.'+data.getMinutes();
	}
	if (nivel>4) {
		s += '.'+data.getSeconds();
	}
	if (nivel>5) {
		s += '.'+data.getMilliseconds();
	}
	return s;
};
// Retorna um Ponto
_point = function (_x, _y) {
	_x = _x || 0;
	_y = _y || 0;
	return {x:_x, y:_y};
};
// Retorna o scroll da página
getScroll = function () {
	if (self.pageXOffset) {
		sX = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollLeft) {
		sX = document.documentElement.scrollLeft;
	} else if (document.body) {
		sX = document.body.scrollLeft;
	}
	if (self.pageYOffset) {
		sY = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
		sY = document.documentElement.scrollTop;
	} else if (document.body) {
		sY = document.body.scrollTop;
	}
	return {x:sX, y:sY};
};
// Retorna a posição do mouse no documento
getMousePos = function (ev) {
	if (ev.pageX || ev.pageY) return {x:ev.pageX, y:ev.pageY};
	var SC = getScroll();
	return {x:ev.clientX+SC.x-document.body.clientLeft, y:ev.clientY+SC.y-document.body.clientTop};
};
String.prototype.isMail = function() {
	var ER = new RegExp(/^[A-Za-z0-9]+(([\.\_\-]{1}[A-Za-z0-9]+)+)?@[A-Za-z0-9]+(([\.\_\-]{1}[A-Za-z0-9]+)+)?\.[A-Za-z]{2,4}$/);
	return (ER.test(this));
};
String.prototype.isDate = function() {
	try {
		var arrData = new Array();
		arrData = this.split('/');
		var dia = arrData[0];
		var mes = arrData[1]-1;
		var ano = arrData[2];
		var dataEntrada = (arrData[0]*1)+'/'+(arrData[1]*1)+'/'+arrData[2];
		var minhaData = new Date(ano, mes, dia);
		var dataRetorno = minhaData.getDate()+'/'+(minhaData.getMonth()+1)+'/'+minhaData.getFullYear();
		return (dataEntrada == dataRetorno);
	} catch (e) {
		return false;
	}
};

/* Máscara */
filter2 = function(txtEntrada, strValidos) {
	var txtSaida = '';
	for (var a = 0; a<txtEntrada.length; a++) {
		if (strValidos.indexOf(txtEntrada.substr(a, 1)) != -1) {
			txtSaida = txtSaida+txtEntrada.substr(a, 1);
		}
	}
	return txtSaida;
};
mask = function(strMask, ev, objData) {
	ev = ev || event;
	var key = getKey(ev);
	if (isNum(key, '%\'#$.') == true) return true;
	if (!(key>=37 && key<=40)) {
		var valor = filter2(objData.value, '0123456789');
		var tam = valor.length;
		var tamMask = strMask.length;
		var strOut = '';
		var intCont = 0;
		for (var a = 0; a<tamMask && intCont<=tam; a++) if (strMask.substr(a, 1) == '#') strOut += valor.substr(intCont++, 1); else strOut += strMask.substr(a, 1);
		objData.value = strOut;
		return true;
	}
};
isNum = function(code, strValidos) {
	var strCode = String.fromCharCode(code);
	strValidos = strValidos || '%\'#$.0123456789`abcdefghi	';
	return (strValidos.indexOf(strCode)>=0);
};
getKey = function (e) {
	try {
		return event ? (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode)) : null;
	} catch (f) {
		return e.keyCode;
	}
};