function getObject(id) {
	if(document.getElementById) return document.getElementById(id);
	else if(document.all) return document.all(id);
	else if(document.layers) return document.layers[id];
	else return false;
}
function show(id) {
	getObject('submenu'+id).style.display = "block";
	getObject('menu'+id).style.border = "none";
}
function hide(id) {
	getObject('submenu'+id).style.display = "none";
}

function moveTip(e) {
	if (document.getElementById("floatTip")) {
		floatTipStyle = document.getElementById("floatTip").style;
		w = 250;
		var iebody = document.compatMode && document.compatMode != "BackCompat" ? document.documentElement : document.body;
		if (document.all) {
			x = event.x + iebody.scrollLeft;
			y = event.y + iebody.scrollTop;
		} else  {
			x = e.pageX;
			y = e.pageY;
		}
		if ((x + w + 10) < document.body.clientWidth) {
			floatTipStyle.left = x + 10 + 'px';
		} else {
			floatTipStyle.left = x + 10 - w + 'px';
		}
		floatTipStyle.top = y - 10 - document.getElementById("floatTip").clientHeight + 'px';
	}
}
function toolTip(msg) {
	floatTipStyle = document.getElementById("floatTip").style;
	if (msg) {
		document.getElementById("floatTip").innerHTML = msg;
		floatTipStyle.display = "block";
	} else {
		floatTipStyle.display = "none";
	}
}

function clear_field(a) {
	a.value = "";
	a.onfocus = "";
}

function onpassword() {
	getObject("password").value = "";
	getObject("password").onfocus = "";
}

var blocksContent = new Array();

function stripText (n, max_height, tail)
{
  var parent = getObject('block'+n);
  var container = getObject('short_block'+n);

  if (!parent || !container) return false;

  if (blocksContent[n]) {
  	var content = blocksContent[n];
  }
  else {
  	var content = container.innerHTML.split(" ");
  	blocksContent[n] = content;
  }

  var curr_content = "";
  container.innerHTML = "";

  for (var i = 0; i < content.length; i ++) {
    container.innerHTML += (i > 0 ? " " : "") + content[i] + (i < content.length - 1 ? tail : "");
    if (parent.offsetHeight > max_height) {
      container.innerHTML = curr_content + tail;
    	break;
    }
    //document.write(parent.offsetHeight+"/"+parent.clientWidth+" ");
    curr_content += (i > 0 ? " " : "") + content[i];
    container.innerHTML = curr_content;
  }

  return true;
}

function commentForm (id, e)
{
	if (e == 2 && window.location.hash != '#replay')
		return;
	var form = getObject('replay');
	getObject ('r'+id).appendChild(form);
	getObject ('parent_id').value = id;
	form.style.display = 'block';
	if (!e) {
		getObject('error').style.display = 'none';
		getObject('comments').value = "";
	}
}

function checkForm ()
{
	var error;
	if (!getObject('user_id')) {
		if (!getObject('secret').value) error = "Введите число на картинке.";
		if (!getObject('name').value) error = "Введите Ваше имя.";
	}
	if (!getObject('comments').value) error = "Введите Ваш комментарий.";
	if (error) {
		getObject('error').innerHTML = "<b>Ошибка:</b> " + error;
		getObject('error').style.display = 'block';
		return false;
	}
	return true;
}

function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1) {
      endstr = document.cookie.length;
   }
   return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen) {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg) {
         return getCookieVal (j);
      }
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) {
         break;
      }
   }
   return null;
}