var isIE =(/\bmsie\b/i.test(navigator.userAgent)&& document.all&&!(/\bopera\b/i.test(navigator.userAgent)));
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 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};
};
/* PEGA O VALOR DO RADIO SELECIONADO*/
radio = function(object) {
	if(typeof object == 'object'){
		strChek = object.name;
	}else{
		strChek = object;
	}
	obj = document.getElementsByTagName('input');
	for (var i = 0; i< obj.length; i++){
	    if (obj[i].type == 'radio' && obj[i].name == strChek  && obj[i].checked){
			return obj[i].value;
		}
	}
	return null
}
/* Prorotypes */
String.prototype.format = function(casas) {
	var ret = new String('');
	while (ret.length < (casas-this.toString().length)) ret += '0';
	return ret+this;
};
Date.prototype.getString = function() {
	return this.getDate().toString().format(2)+'/'+(this.getMonth()+1).toString().format(2)+'/'+this.getFullYear();
};
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;
	}
};
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));
};
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;
};
String.prototype.isCPF = function() {
	var cpf = filter2(this,'0123456789');
	var rrValida = new Array(00000000000,11111111111,2222222222,3333333333,44444444444,5555555555,6666666666,7777777777,8888888888,9999999999);
	for (i=0;i<11;i++) if (cpf == rrValida[i]) return null;
	var i;
	var c = cpf.substr(0,9);
	var dv = cpf.substr(9,2);
	var d1 = 0;   
	for (i = 0; i < 9; i++) d1 += c.charAt(i)*(10-i);
	if (d1 == 0) return null;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1) return null;
	d1 *= 2;
	for (i = 0; i < 9; i++) d1 += c.charAt(i)*(11-i);
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1) return null;
	return true;
};