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); };

function mostraFlash(id, swf, width, height){
	var so = new SWFObject(swf, id+"movie", width, height, "8", "transparent", true);
	so.addParam("scale", "noscale");
	so.addParam("wmode", "transparent");
	so.write(id);
}

// Retorna o tamanho total do documento
getDocSize = function () {
	return {x:document.body.offsetWidth, y:document.body.offsetHeight};
};

// Retorna o tamanho de um objeto
getSize = function(e) {
	if (typeof e == 'string') e = $(e);
	return {w:e.offsetWidth, h:e.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};	
};
// 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};
};
// 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};
};

/* 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;
};

String.prototype.toCurrency = function() {
	var ret = new String('');
	var fim = new String(',00');
	var exe = new String(this);
	var isNotFirst = null;
	if (this.indexOf('.')>0) {
		var arr = exe.split('.');
		exe = arr[0];
		while (arr[1].length<2) {
			arr[1] += '0';
		}
		if (arr[1].length>2) {
			arr[1] = arr[1].substr(0, 2);
		}
		fim = ','+arr[1];
	}
	while (exe.length>3) {
		if (isNotFirst) {
			ret = '.'+ret;
		}
		isNotFirst = true;
		ret = exe.substr(exe.length-3, 3)+ret;
		exe = exe.substr(0, exe.length-3);
	}
	if (exe.length>0) {
		if (ret.length>0) {
			ret = exe+'.'+ret;
		} else {
			ret = exe;
		}
	}
	return ret+fim;
};

