/*

Este arquivo contem a classe para tratamento de cookies

Pre-requisito: nao possui

*/

function cookie() {

	this.criar = function (nome, valor) {

		if (arguments.length > 2) {

			var diasExpiracao = arguments[2];

			var data = new Date();
			data.setTime(data.getTime() + (diasExpiracao * 24 * 60 * 60 * 1000));
			var expiracao = "; expires=" + data.toGMTString();

		}
		else {

			var expiracao = "";

		}

		document.cookie = nome + "=" + valor + expiracao + "; path=/";

		if (this.ler(nome) !== false) {

			return true;

		}
		else {

			return false;

		}

	}

	this.ler = function (nome) {

		var cookies = document.cookie.split(";");

		for (var i = 0; i < cookies.length; i++) {

			var cookieAtual = cookies[i];

			while (cookieAtual.charAt(0) == " ") {

				cookieAtual = cookieAtual.substr(1);

			}

			if (cookieAtual.indexOf(nome + "=") == 0) {

				return cookieAtual.substring(nome.length + 1,cookieAtual.length);

			}

		}

		return false;

	}

	this.apagar = function (nome) {

		this.criar(nome,"",-1);

		if (this.ler(nome) === false) {

			return true;

		}
		else {

			return false;

		}

	}

	this.listar = function () {

		var cookies = document.cookie.split(";");
		var listaCookies = new Array();

		for (var i = 0; i < cookies.length; i++) {

			listaCookies[listaCookies.length] = cookies[i].substr(0,cookies[i].indexOf("="));

		}

		return listaCookies;

	}

}