function Cookie() {
}

Cookie.prototype.setCookie = function (key, value) {
	document.cookie = key + "=" + escape(value) + "; path=/";
}

Cookie.prototype.getCookie = function (key) {
	var cookies = document.cookie;
	if (cookies) {
		var start = cookies.indexOf(' ' + key + '=');
		if (start == -1) { 
			// check if cookie starts with key
		 	start = cookies.indexOf(key + '=');
			if (start != 0)
				return null; 
		}
		var end = cookies.indexOf(";", start);
		if (end == -1) { end = cookies.length; }
		end -= start;
		var cookie = cookies.substr(start,end);
		return unescape(cookie.substr(cookie.indexOf('=') + 1, cookie.length - cookie.indexOf('=') + 1));
	}
	else { return null; }
}


	function toCookie(value)
	{
		return "val_hex1:" + bin2hex(value);
	}

	function fromCookie(value)
	{
		if( value.indexOf("val_hex1:") !== 0 ){
			return "";
		}
		var result = "";
		var input = value.substring(9, value.length);
		for(i = 0; i < input.length; i += 2)
		{
			var hex = input.substring(i, i+2);
			var chVal = unescape("%" +hex);
			result += chVal;
		}
		return result;
	}

var _it=new Array();
_it[0]="0";_it[1]="1";_it[2]="2";_it[3]="3";
_it[4]="4";_it[5]="5";_it[6]="6";_it[7]="7";
_it[8]="8";_it[9]="9";_it[10]="A";_it[11]="B";
_it[12]="C";_it[13]="D";_it[14]="E";_it[15]="F";
function bin2hex(str)
{
	var c, c2;
    var res="";
  	for( i = 0; i < str.length; i++ ){
	    c=str.charCodeAt(i);
		res+=_it[c>>4];
        res+=_it[c & 0xf];
	}
    return res;
}

