// экзсистилка
function exists(tag,text)
{
  for(one in document.getElementsByTagName(tag)) if(/^[0-9]+$/.test(one) && document.getElementsByTagName(tag)[one].innerHTML.toLowerCase() == text.toLowerCase()) return true;
  return false;
}

// кукисилка
function setCookie (name,value,expires,path,domain,secure)
{
  document.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
  return false;
}





function getCookie2(name) {
	var matches = document.cookie.match(new RegExp(
	  "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
	))
	return matches ? decodeURIComponent(matches[1]) : undefined 
}

// уcтанавливает cookie
function setCookie2(name, value, props) {
	props = props || {}
	var exp = props.expires
	if (typeof exp == "number" && exp) {
		var d = new Date()
		d.setTime(d.getTime() + exp*1000)
		exp = props.expires = d
	}
	if(exp && exp.toUTCString) { props.expires = exp.toUTCString() }

	value = encodeURIComponent(value)
	var updatedCookie = name + "=" + value
	for(var propName in props){
		updatedCookie += "; " + propName
		var propValue = props[propName]
		if(propValue !== true){ updatedCookie += "=" + propValue }
	}
	document.cookie = updatedCookie

}

// удаляет cookie
function deleteCookie2(name) {
	setCookie(name, null, { expires: -1 })
}








// добавлялка в избранное
function addToFavorites(page,entry)
{  var newtext = prompt('Описание (не обязательно):','');
  if(newtext == null) return false;
  else location = '/favorites/?group=' + page + '&sortby=date&add=' + page + '&at=' + entry + '&text=' + newtext;
  return false;
}

// вставка ббкодов
function bbCode(id,tag1,tag2,what,def)
{
  var elem = document.getElementById(id);
  elem.focus();
  var scrolled = elem.scrollTop;
  var param = what == undefined ? '' : prompt(what,def==undefined?'':def);
  if(what != undefined && param == null) return false;
  if(typeof(elem.selectionStart)=='number' && typeof(elem.selectionEnd)=='number')
  {
    var selected = elem.value.substr(elem.selectionStart,elem.selectionEnd-elem.selectionStart);
    var caret = elem.selectionEnd;
    var text = tag2 == '' || tag2 == undefined ? selected + (param == '' ? tag1 : tag1.substr(0,(tag1.length-1))+'='+param+tag1.substr(tag1.length-1)) : (param == '' ? tag1 : tag1.substr(0,(tag1.length-1))+'='+param+tag1.substr(tag1.length-1)) + selected + tag2;
    elem.value = elem.value.substr(0,elem.selectionStart) + text + elem.value.substr(elem.selectionEnd);
    elem.setSelectionRange(caret+text.length-selected.length-(tag2 == '' || tag2 == undefined || selected.length > 0 ? 0 : tag2.length),caret+text.length-selected.length-(tag2 == '' || tag2 == undefined || selected.length > 0 ? 0 : tag2.length));
  }
  else if(document.selection)
  {
    var sel1 = document.selection.createRange();
    var sel2 = sel1.duplicate();
    var sel3 = elem.createTextRange();
    var len = sel1.text.length;
    sel1.text = tag2 == '' || tag2 == undefined ? sel1.text + (param == '' ? tag1 : tag1.substr(0,(tag1.length-1))+'='+param+tag1.substr(tag1.length-1)) : (param == '' ? tag1 : tag1.substr(0,(tag1.length-1))+'='+param+tag1.substr(tag1.length-1)) + sel1.text + tag2;
    sel1.collapse(true);
    sel2.moveToElementText(elem);
    sel2.setEndPoint('EndToEnd',sel1);
    sel3.moveStart('character',sel2.text.length - (tag2 == '' || tag2 == undefined || len > 0 ? 0 : tag2.length));
    sel3.collapse(true);
    sel1.select();
    sel3.select();
  }
  else { alert('Ваш браузер не поддерживает эту функцию.'); return false; }
  elem.scrollTop = scrolled;
  return false;
}

// фейдилка
function fade(id,from,to,step,delay,code)
{
  var elem = document.getElementById(id)
  var seed = Math.floor(Math.random()*(9999-1000+1))+1000;
  elem.style.opacity = from/100;
  if(elem.filters) { elem.style.filter = 'alpha(opacity=' + from + ')'; elem.filters.alpha.opacity = from; }
  if(from > to) step *= -1;
  function go()
  {
    elem.style.opacity = elem.style.opacity*1 + step/100;
    if(elem.filters) elem.filters.alpha.opacity = elem.filters.alpha.opacity*1 + step;
    if(step>0) { if((elem.filters && elem.filters.alpha.opacity >= to) || (elem.style.opacity*1 >= to/100)) { eval('window.clearInterval(timer'+seed+')'); if(code) eval(code); } }
    else { if((elem.filters && elem.filters.alpha.opacity <= to) || (elem.style.opacity*1 <= to/100)) { eval('window.clearInterval(timer'+seed+')'); if(code) eval(code); } }
  }
  if(!step*1 || !delay*1)
  {
    elem.style.opacity = to/100;
    if(elem.filters) elem.filters.alpha.opacity = to;
    if(code) eval(code);
  }
  else eval('timer'+seed+' = window.setInterval(go,delay);')
  return false;
}

// картинкопоказывалка (часть 0)
function loadImage(curr,prev,next,text,pos,count)
{
  ge('dlkp_img').innerHTML = count > 1 ? '<img src="'+ urlencode(unescape(curr)) +'" style="cursor: pointer;" alt="" onmousedown="this.style.top = \'0px\'; this.style.left = \'0px\';" onmouseout="this.style.top = \'-2px\'; this.style.left = \'-1px\';" onmouseup="if(event.ctrlKey && !event.button) { showImage(\'' + unescape(prev).split("'").join("\\'") + '\'); } else if(event.shiftKey && !event.button) { window.open(\'' + urlencode(unescape(curr)) + '\') } else if(event.button<2) { showImage(\'' + unescape(next).split("'").join("\\'") + '\'); }" onload="imageLoaded(\'' + curr + '\',\'' + prev + '\',\'' + next + '\',\'' + text + '\',' + pos + ',' + count + ')" title="Щелчок мышью — следующее изображение, Ctrl+щелчок — предыдущее изображение, Shift+щелчок — открыть в новом окне">' : '<img src="'+ urlencode(unescape(curr)) +'" style="cursor: pointer;" alt="" onload="imageLoaded(\'' + curr + '\',\'' + prev + '\',\'' + next + '\',\'' + text + '\',' + pos + ',' + count + ')" onclick="if(event.shiftKey && !event.button) { window.open(\'' + urlencode(unescape(curr)) + '\') } else if(!event.button) hideImage();" title="Щелчок мышью — закрыть, Shift+щелчок — открыть в новом окне">';
  return false;
}

// картинкопоказывалка (часть 1)
function showImage()
{
  var tags = document.getElementsByTagName('dfn');
  var images = new Array;
  var currImage = false; var prevImage = false; var nextImage = false; var tempImage = false;
  var nextFlag = 0; var imagesCount = 0; var currPos = 0; var firstFlag = 0;
  for(i in tags)
  {
    url = tags[i].innerHTML;
    text = tags[i].title;
    if(text == undefined) continue;
    imagesCount++;
    images[url] = text;
    if(url == arguments[0]) { firstFlag = 1; currImage = url; currPos = imagesCount; currText = text; prevImage = tempImage; nextFlag = 1; }
    else if(nextFlag) { nextImage = url; nextFlag = 0; }
    tempImage = url;
  }
  if(!currImage && arguments[0])
  {
    currImage = arguments[0];
    currText = arguments[1] || '';
    imagesCount = 0;
  }
  else
  {
    if(!firstFlag)
    {
      currImage = tags[0].innerHTML;
      currText = tags[0].title;
      currPos = 1;
      if(imagesCount > 1) { if(tags[1].innerHTML) nextImage = tags[1].innerHTML; }
    }
    if(!prevImage && imagesCount > 1) prevImage = tags[imagesCount-1].innerHTML;
    if(!nextImage && imagesCount > 1) nextImage = tags[0].innerHTML;
  }
  currImage = escape(currImage);
  if(prevImage) prevImage = escape(prevImage);
  if(nextImage) nextImage = escape(nextImage);
  if(currText) currText = escape(currText);
  if(!ge('dlkp_fog'))
  {
    var div = document.createElement('div');
    document.body.appendChild(div);
    div.innerHTML = '<div id="dlkp_fog" style="z-index: 10000; display: none; opacity: 0; filter: alpha(opacity=0); position: fixed; width: 100%; height: 100%; top: 0px; left: 0px; //position: absolute; top: expression(eval(document.body.scrollTop) + \'px\'); width: expression(eval(document.body.scrollLeft + document.body.clientWidth) + \'px\'); background-color: white;" onclick="hideImage();"><span id=dlkp_oldtitle style="display: none;"></span><div id=dlkp_notice style="font: 11px Arial; color: black; text-align: center; margin-top: 5px;"></div></div>';
    div.innerHTML += '<div id="dlkp_img" style="z-index: 10002; display: none; visibility: hidden; opacity: 0; filter: alpha(opacity=0); position: fixed; top: 50%; left: 50%; //position: absolute; //top: expression(eval(document.body.scrollTop + (document.body.offsetHeight/2)) + \'px\'); margin-top: 0px; margin-left: 0px;"></div>';
    div.innerHTML += '<style type="text/css"> div#dlkp_txt a { color: #059; } div#dlkp_txt a:hover { color: #950; } </style><div id="dlkp_txt" style="z-index: 10003; display: none; opacity: 0; filter: alpha(opacity=0); /*border: 2px solid red;*/ position: fixed; width: 100%; top: 50%; left: 0px; //position: absolute; //top: expression(eval(document.body.scrollTop + (document.body.offsetHeight/2)) + \'px\'); margin-top: -0px; margin-left: 0px; font: 13px Arial; text-align: center; color: black;"></div>';
  }
  else ge('dlkp_img').style.visibility = 'hidden';
  ge('dlkp_txt').style.opacity = 0;
  if(ge('dlkp_txt').filters) { ge('dlkp_txt').style.filter = 'alpha(opacity=0)'; ge('dlkp_txt').filters.alpha.opacity = 0; }
  ge('dlkp_txt').innerHTML = '';
  var flagFirst = ge('dlkp_fog').style.display == 'none' ? true : false;
  ge('dlkp_fog').style.display = 'block';
  ge('dlkp_fog').style.cursor = 'wait';
  ge('dlkp_img').style.display = 'block';
  ge('dlkp_txt').style.display = 'block';
  if(flagFirst) fade('dlkp_fog',0,80,20,20,'loadImage(\'' + currImage +'\',\'' + prevImage + '\',\'' + nextImage + '\',\'' + currText + '\',\'' + currPos + '\',\'' + imagesCount + '\');');
  else loadImage(currImage,prevImage,nextImage,currText,currPos,imagesCount);
  window.timerOut = setTimeout("dlkpTimeout('" + currImage + "','" + nextImage + "')",5000);
  return false;
}

// картинкопоказывалка (часть 2)
function dlkpTimeout(curr,next)
{
  ge('dlkp_fog').style.cursor = 'default';
  if(!next || next == 'false') { alert(curr + '\n\nНе удается загрузить это изображение.'); hideImage(); }
  else if(confirm(curr + '\n\nНе удается загрузить это изображение. Перейти к следующему?')) showImage(next);
  else hideImage();
  return false;
}

// картинкопоказывалка (часть 3)
function imageLoaded(currImage,prevImage,nextImage,currText,currPos,imagesCount)
{
  clearTimeout(window.timerOut);
  currImage = unescape(currImage);
  prevImage = unescape(prevImage);
  nextImage = unescape(nextImage);
  currText = unescape(currText);
  var div = ge('dlkp_img');
  var img = ge('dlkp_img').getElementsByTagName('img')[0];
  var txt = ge('dlkp_txt');
  if(!img) return false;
  var winWidth = window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth);
  var winHeight = window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight);
  var srcWidth = img.width;
  var srcHeight = img.height;
  var imgWidth = img.width;
  var imgHeight = img.height;
  var currZoom = 100;
  if(imgWidth+100 > winWidth || imgHeight+100 > winHeight)
  {
    if(imgWidth/imgHeight > winWidth/winHeight)
    {
      var tempWidth = winWidth-100;
      var tempHeight = tempWidth*imgHeight/imgWidth;
      currZoom = Math.round(tempWidth*100/imgWidth);
      imgWidth = tempWidth;
      imgHeight = tempHeight;
    }
    else
    {
      var tempHeight = winHeight-100;
      var tempWidth = tempHeight*imgWidth/imgHeight;
      currZoom = Math.round(tempWidth*100/imgWidth);
      imgWidth = tempWidth;
      imgHeight = tempHeight;
    }
  }
  img.width = imgWidth;
  img.height = imgHeight;
  div.style.width = imgWidth + 10 + 'px';
  div.style.height = imgHeight + 10 + 'px';
  div.style.marginTop = '-' + imgHeight/2 - (currText?10:0) + 'px';
  div.style.marginLeft = '-' + imgWidth/2 + 'px';
  txt.style.marginTop = imgHeight/2 + 'px';
  div.style.visibility = 'visible';
  ge('dlkp_txt').innerHTML = currText;
  fade('dlkp_img',0,100,(currZoom<100?0:20),20,"ge('dlkp_fog').style.cursor = 'default';" + (currPos == 1 && imagesCount > 1 ? "ge('dlkp_notice').innerHTML = 'Это первое изображение в серии.'; setTimeout(\"ge('dlkp_notice').innerHTML = '';\",1000);" : '') + " fade('dlkp_txt',0,100," + (currZoom<100?'0':'20') + ",20);");
  if(ge('dlkp_oldtitle').innerHTML == '') ge('dlkp_oldtitle').innerHTML = document.title;
  var newTitle = imagesCount > 1 ? '[' + currPos + '/' + imagesCount + '] ' : '';
  newTitle += currImage.replace(/^.*[\/\\]/g,'') + ' (';
  switch(currImage.substr(currImage.lastIndexOf('.')+1).toLowerCase())
  {
    case 'gif': newTitle += 'GIF-изображение'; break;
    case 'jpg': newTitle += 'JPEG-изображение'; break;
    case 'png': newTitle += 'PNG-изображение'; break;
    default: newTitle += currImage.substr(currImage.lastIndexOf('.')+1).toUpperCase(); break;
  }
  var imageSize = (img.fileSize > 0 ? (img.fileSize >= 1048576 ? Math.round(img.fileSize/1048576*10)/10 + ' МБ, ' : Math.round(img.fileSize/1024*10)/10 + ' КБ, ') : '');
  newTitle += ', ' + srcWidth + String.fromCharCode(215) + srcHeight + ', ' + imageSize.split('.').join(',') + 'масштаб ' + currZoom + '%)';
  document.title = newTitle;
  return false;
}

// картинкопоказывалка (часть 4)
function hideImage()
{
  if(window.timerOut) clearTimeout(window.timerOut);
  var winWidth = window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth);
  var winHeight = window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight);
  var imgWidth = ge('dlkp_img').getElementsByTagName('img')[0].width;
  var imgHeight = ge('dlkp_img').getElementsByTagName('img')[0].height;
  fade('dlkp_img',100,0,(imgWidth+100 >= winWidth || imgHeight+100 >= winHeight?0:20),20,"ge('dlkp_fog').style.cursor = 'default'; ge('dlkp_txt').style.display = 'none'; ge('dlkp_img').innerHTML = ''; fade('dlkp_fog',80,0,20,20,\"ge('dlkp_fog').style.display = 'none'; ge('dlkp_img').style.display = 'none';\");");
  if(ge('dlkp_oldtitle').innerHTML) document.title = ge('dlkp_oldtitle').innerHTML;
  return false;
}

// урленкодилка
function urlencode(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));
}

// тултипилка
function engageTooltips(tag)
{
  function moveTip(e)
  {
    var e = e || window.event;
    div.style.top = (e.pageY ? e.pageY : e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop) + 16 + 'px';
    div.style.left = (e.pageX ? e.pageX : e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft) + 16 + 'px';
  }
  if(!document.getElementById('tooltip'))
  {
    var div = document.createElement('div');
    document.body.appendChild(div);
    div.id = 'tooltip';
    div.style.background = 'white';
    div.style.color = 'black';
    div.style.font = '13px Arial';
    div.style.padding = '0.15em 0.3em 0.15em 0.3em';
    div.style.position = 'absolute';
    div.style.top = '0px';
    div.style.left = '0px';
    div.style.display = 'none';
    div.style.opacity = '0';
    div.style.filter = 'alpha(opacity=0)';
  }

  function showTip()
  {
    div.style.display = 'block'; div.innerHTML = this.name; fade('tooltip',0,70,20,10,"elem.style.display = 'block'");
    return false;
  }

  for(i in document.getElementsByTagName(tag))
  {
    img = document.getElementsByTagName(tag)[i];
    if(!img.title || !/^[0-9]+$/.test(i)) continue;
    img.name = img.title;
    img.title = '';
    img.onmouseover = function() { div.style.display = 'block'; div.innerHTML = this.name; fade('tooltip',0,70,20,10,"elem.style.display = 'block'"); }
    img.onmouseout = function() { div.title = div.name; fade('tooltip',70,0,20,10,"elem.style.display = 'none'"); }
    if(img.addEventListener) img.addEventListener('mousemove', moveTip, false);
    else if(img.attachEvent) img.attachEvent('onmousemove', moveTip);
  }

  return false;
}

// пнг-фиксилка (применять в CSS так: //filter: expression(fixPNG(this)); )
function fixPNG(element)
{
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
  {
    var src;
    if (element.tagName=='IMG') { if (/\.png$/.test(element.src)) { src = element.src; element.src = "/img/n.gif"; } }
    else
    {
      src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
      if (src) { src = src[1]; element.runtimeStyle.backgroundImage="none"; }
    }
    if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
  }
}

// ге
function ge(id) { return document.getElementById(id); }

// поддержка горячих клавиш
function defineHotKey(key,code)
{
  if(typeof(key) == 'string')
  {
    var plus = key.indexOf('+');
    var key0 = plus > 0 ? key.substr(0,plus).toLowerCase() : undefined;
    if(!/^(ctrl|alt|shift)$/.test(key0)) return false;
    var key1 = key.substr(plus+1)*1;
  }
  else key1 = key;
  function react(e)
  {
    var e = e || window.event;
    var keyCode = e.which || e.keyCode;
    if((eval('e.'+key0+'Key')?key0:!key0) && keyCode == key1)
    {
      if(e.preventDefault) e.preventDefault(); e.returnValue = false;
      eval(code);
    }
  }
  if(document.addEventListener) document.addEventListener('keydown',react,false);
  else if(document.attachEvent) document.attachEvent('onkeydown',react);
}

// мд5
function md5(string)
{
  function RotateLeft(lValue, iShiftBits) { return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits)); }
  function AddUnsigned(lX,lY)
  {
    var lX4,lY4,lX8,lY8,lResult;
    lX8 = (lX & 0x80000000);
    lY8 = (lY & 0x80000000);
    lX4 = (lX & 0x40000000);
    lY4 = (lY & 0x40000000);
    lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
    if (lX4 & lY4) return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
    if (lX4 | lY4)
    {
      if (lResult & 0x40000000) return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
      else return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
    }
    else return (lResult ^ lX8 ^ lY8);
  }
  function F(x,y,z) { return (x & y) | ((~x) & z); }
  function G(x,y,z) { return (x & z) | (y & (~z)); }
  function H(x,y,z) { return (x ^ y ^ z); }
  function I(x,y,z) { return (y ^ (x | (~z))); }
  function FF(a,b,c,d,x,s,ac)
  {
    a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
    return AddUnsigned(RotateLeft(a, s), b);
  };
  function GG(a,b,c,d,x,s,ac)
  {
    a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
    return AddUnsigned(RotateLeft(a, s), b);
  };
  function HH(a,b,c,d,x,s,ac)
  {
    a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
    return AddUnsigned(RotateLeft(a, s), b);
  };
  function II(a,b,c,d,x,s,ac)
  {
    a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
    return AddUnsigned(RotateLeft(a, s), b);
  };
  function ConvertToWordArray(string)
  {
    var lWordCount;
    var lMessageLength = string.length;
    var lNumberOfWords_temp1=lMessageLength + 8;
    var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
    var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
    var lWordArray=Array(lNumberOfWords-1);
    var lBytePosition = 0;
    var lByteCount = 0;
    while ( lByteCount < lMessageLength )
    {
      lWordCount = (lByteCount-(lByteCount % 4))/4;
      lBytePosition = (lByteCount % 4)*8;
      lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)<<lBytePosition));
      lByteCount++;
    }
    lWordCount = (lByteCount-(lByteCount % 4))/4;
    lBytePosition = (lByteCount % 4)*8;
    lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
    lWordArray[lNumberOfWords-2] = lMessageLength<<3;
    lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
    return lWordArray;
  };
  function WordToHex(lValue)
  {
    var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
    for (lCount = 0;lCount<=3;lCount++)
    {
      lByte = (lValue>>>(lCount*8)) & 255;
      WordToHexValue_temp = "0" + lByte.toString(16);
      WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
    }
    return WordToHexValue;
  };
  function Utf8Encode(string)
  {
    string = string.replace(/\r\n/g,"\n");
    var utftext = "";

    for (var n = 0; n < string.length; n++)
    {
      var c = string.charCodeAt(n);
      if (c < 128) utftext += String.fromCharCode(c);
      else if((c > 127) && (c < 2048))
      {
        utftext += String.fromCharCode((c >> 6) | 192);
        utftext += String.fromCharCode((c & 63) | 128);
      }
      else
      {
        utftext += String.fromCharCode((c >> 12) | 224);
        utftext += String.fromCharCode(((c >> 6) & 63) | 128);
        utftext += String.fromCharCode((c & 63) | 128);
      }
    }
    return utftext;
  };
  var x=Array();
  var k,AA,BB,CC,DD,a,b,c,d;
  var S11=7, S12=12, S13=17, S14=22;
  var S21=5, S22=9 , S23=14, S24=20;
  var S31=4, S32=11, S33=16, S34=23;
  var S41=6, S42=10, S43=15, S44=21;
  string = Utf8Encode(string);
  x = ConvertToWordArray(string);
  a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
  for (k=0;k<x.length;k+=16)
  {
    AA=a; BB=b; CC=c; DD=d;
    a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
    d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
    c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
    b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
    a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
    d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
    c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
    b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
    a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
    d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
    c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
    b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
    a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
    d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
    c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
    b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
    a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
    d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
    c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
    b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
    a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
    d=GG(d,a,b,c,x[k+10],S22,0x2441453);
    c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
    b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
    a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
    d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
    c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
    b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
    a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
    d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
    c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
    b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
    a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
    d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
    c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
    b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
    a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
    d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
    c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
    b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
    a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
    d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
    c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
    b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
    a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
    d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
    c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
    b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
    a=II(a,b,c,d,x[k+0], S41,0xF4292244);
    d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
    c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
    b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
    a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
    d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
    c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
    b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
    a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
    d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
    c=II(c,d,a,b,x[k+6], S43,0xA3014314);
    b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
    a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
    d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
    c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
    b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
    a=AddUnsigned(a,AA);
    b=AddUnsigned(b,BB);
    c=AddUnsigned(c,CC);
    d=AddUnsigned(d,DD);
  }
  var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);
  return temp.toLowerCase();
}


function showAds()
{
  if(!document.getElementById('adsFog'))
	{
		var fog = document.createElement('div');
		document.body.appendChild(fog); fog.innerHTML = '<div id="adsFog" style="z-index: 10000; display: none; position: fixed; width: 100%; height: 100%; top: 0px; left: 0px; opacity: 0.5; background: black;"></div><div id="adsBackground" style="z-index: 10001; display: none; position: fixed; top: 100px; left: 50%; background: white; box-shadow: 0px 3px 30px #333; -moz-box-shadow: 0px 3px 30px #333; -webkit-box-shadow: 0px 3px 30px #333; width: 600px; margin: 0px 0px 0px -300px; border-radius: 10px;"><span style="font: 20px Arial; color: #666; text-decoration: none; cursor: pointer; position: absolute; top: 5px; left: 578px;" onmouseover="this.style.color=\'black\';" onmouseout="this.style.color=\'#666\';" onclick="hideAds();">&times;</span><iframe id="adsFrame" frameborder=0 scrolling=no width=560 height=340 src="/unisender.html" style="margin: 20px 20px;"></iframe><div style="text-align: center; margin-bottom: 20px;"><input type=button value="Спасибо, не надо" style="font-size: 14px;" onclick="hideAds();"></div><div style="font-size: 10px; margin: 10px 0px; text-align: center;">Если это окно появляется каждый раз, включите поддержку JavaScript и сохранение cookies в браузере.</div></div>'; }
  ge('adsFog').style.display = ge('adsBackground').style.display = 'block';
  return false;
}

function hideAds()
{
	ge('adsFog').style.display = ge('adsBackground').style.display = 'none';
  return false;
}

