/**
 * Zapamietywanie informacji w ciasteczkach
 */
function ChessigCookieStorage() {
	/**
	 * Domyslnie ciasteczka zapamietujemy na 100 dni
	 */
	this.days = 100;
	/**
	 * Prefix dla nazw ciasteczek
	 */
	this.prefix = "chessig_";
}

/**
 * Zapisanie w pamieci identyfikatora gracza 
 * 
 * @param phk
 * @return
 */
ChessigCookieStorage.prototype.setPlayerHashKey = function(phk) {
	this._createCookie(this.prefix+"playerHashKey", phk, this.days);
}

/**
 * Wczytanie identyfikatora gracza
 * 
 * @return
 */
ChessigCookieStorage.prototype.getPlayerHashKey = function() {
	return this._readCookie(this.prefix+"playerHashKey");
}


/**
 * Zapisanie w pamieci identyfikatora gracza 
 * 
 * @param phk
 * @return
 */
ChessigCookieStorage.prototype.setGameId = function(gameId) {
	this._createCookie(this.prefix+"gameId", gameId, this.days);
}

/**
 * Wczytanie identyfikatora gracza
 * 
 * @return
 */
ChessigCookieStorage.prototype.getGameId = function() {
	return this._readCookie(this.prefix+"gameId");
}

/**
 * Zapisanie w pamieci identyfikatora gracza 
 * 
 * @param phk
 * @return
 */
ChessigCookieStorage.prototype.setZoomSize = function(size) {
	this._createCookie(this.prefix+"zoomSize", size, this.days);
}

/**
 * Wczytanie identyfikatora gracza
 * 
 * @return
 */
ChessigCookieStorage.prototype.getZoomSize = function() {
	return this._readCookie(this.prefix+"zoomSize");
}




/**
 * Zapisanie ciasteczka
 * 
 * @param name
 * @param value
 * @param days
 * @return
 */
ChessigCookieStorage.prototype._createCookie = function (name,value,days) {
	var expires = "";
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	document.cookie = name+"="+value+expires+"; path=/";
}
/**
 * Wczytanie wartosci ciasteczka
 * 
 * @param name
 * @return
 */
ChessigCookieStorage.prototype._readCookie = function(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
/**
 * Wymazanie ciasteczka
 * 
 * @param name
 * @return
 */
ChessigCookieStorage.prototype._eraseCookie = function(name) {
	this._createCookie(name,"",-1);
}
