// 
/* инициализировать обязательно после вывода инпутов


<script type='text/javascript' src='/js/scripts.js'></script>
<script type='text/javascript'>
	cookie.get('author','email','url');
//	'author','email','url' - это ID инпутов
</script>
*/
var cookie = {
	// public method for search Cookie
	cut : function (name) {
		return this._cookie_search(name);
	},
	// public method for Get To Input Cookie
	get : function () {
		var arg = this.get.arguments;
		if (!arg[0]) arg=new Array('author','email','url');

		return this._get_to_input(arg);
	},
	// public method for Cookie decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	},
	// privat method for search Cookie
	_cookie_search : function (name) 
	{
		var cookie = " " + document.cookie;
		var search = " " + name;
		var setStr = null;
		var offset = 0;
		var end = 0;
		if (cookie.length > 0) {
			offset = cookie.indexOf(search);
			if (offset != -1) {
				offset += search.length;
				end = cookie.indexOf(";", offset)
				if (end == -1) {
					end = cookie.length;
				}
				setStr = cookie.substring(offset, end);
				begin=setStr.indexOf('=')+1;
				setStr = this._utf8_decode(unescape(setStr.substring(begin,setStr.length)));
			}
		}
		return(setStr);
	},
	// privat method for Get To Input Cookie
	_get_to_input : function (arg) 
	{
		if (document.cookie)
		{ 
			var commData=new Array(this._cookie_search('comment_author'),this._cookie_search('comment_author_email'),this._cookie_search('comment_author_url'));
			if (!commData.join('')) return false;
			for (i=0;i<3;i++)
			{
				obj=document.getElementById(arg[i]);
				if ((obj) && (obj.value=='') && (commData[i]!=null)) obj.value=commData[i];
			}
		}
	}
}
