var AuthImage = new Class.create();
AuthImage.prototype = {
	initialize: function(auth_img_div, auth_img_link, prefix){
		//alert('foo');
		this.auth_img_div = $(auth_img_div);
		this.auth_img_link = $(auth_img_link);
		this.prefix = prefix;
		this.auth_img_link.onclick = this.get.bindAsEventListener(this);
		this.get();
	},
	get: function(e){
		new Ajax.Updater(
			this.auth_img_div,
			"/scripts/ajax-antibot.php?p=" + this.prefix
			);
	}
};

/*
 * trim funcs
 */
Object.extend(String.prototype, {
	LTrim: function(){
		return this.replace(/\s*((\S+\s*)*)/, "$1");
	},
	RTrim: function(){
		return this.replace(/((\s*\S+)*)\s*/, "$1");
	},
	trim: function(){
		return this.LTrim(this.RTrim());
	}
});

/*
 * we need win1251, not that utf stuff
 */
window.encodeURIComponent = function(str){
	var trans = [];
	for (var i = 0x410; i <= 0x44F; i++) trans[i] = i - 0x350; // А-Яа-я
	trans[0x401] = 0xA8; // Ё
	trans[0x451] = 0xB8; // ё
	var ret = [];
	for (var i = 0; i < str.length; i++){
		var n = str.charCodeAt(i);
		if (typeof trans[n] != 'undefined') n = trans[n];
		if (n <= 0xFF) ret.push(n);
	}
	return escape(String.fromCharCode.apply(null, ret)).replace(/\+/g, '%2B'); // +
}
window.decodeURIComponent = function(str){
	return unescape(str);
}

// from WO
/*+ =h2<isCookie()>*/
function isCookie()
/*-
  Функция проверяет, можно ли устанавливать куки (т.е. включены ли куки в браузере).
*/
{//DEBUG FuncListAdd('isCookie();\n');
  var d = new Date();
  d.setTime(d.getTime() + 2000); // устанавливаем тестовую куки на 2 секунды
  setCookie('isCookie', 'yes', d.toGMTString(), '/');
  return (getCookie('isCookie') == 'yes');
};

/*+ =h2<getCookie()>*/
function getCookie(name)
/*-
  Функция получает куки.
*/
{//DEBUG FuncListAdd('getCookie();\n');
  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 = unescape(cookie.substring(offset, end));
    };
  };
  return(setStr);
};

/*+ =h2<setCookie()>*/
function setCookie (name, value, expires, path, domain, secure)
/*-
  Функция устанавливает куки.
*/
{//DEBUG FuncListAdd('setCookie();\n');
  document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
};

/*+ =h2<OkIfIsCookie()>*/
function OkIfIsCookie()
/*-
  Функция отображает сайт, если куки включены, иначе сообщение о необходимости их включения.
*/
{
  if (!isCookie())
  {
    document.getElementById('noCookie').style.display = '';
    document.getElementById('affs_content').style.display = 'none';
  }
};