function gebi(id) {return document.getElementById(id);}

function absPosition(obj) { // Определяем top - left координаты блока obj
    var ox = 0;
    var oy = 0;
    while( obj ) {
        ox += obj.offsetLeft;
        oy += obj.offsetTop;
        //  В некоторых случаях почему-то для элемента на странице отсутствует офсет
        if ( obj.offsetParent == null ) {
           obj = obj.nodeName == 'BODY' ?  null : obj.parentNode;
        }

        if ( obj!=null ) obj = obj.offsetParent;
    }
    return {x:ox,y:oy};
}

function addLink(textareaId) {
  var _link = prompt("Введите ссылку. Пример: http://otvet.mail.ru", "http://");
  if (_link && _link != "") {
    var description = prompt("Описание ссылки. Пример: мои ответы", "");
  } else return false;
  if (!(description && description != "")) description = _link;
  var result = "<a href=\"" + _link + "\">" + description + "</a>";
  document.getElementById(textareaId).value += result;
  return false;
}
 
function add_photo() { 
    document.domain="mail.ru";
    popup = false;
    if (popup) popup.close();
    popup = window.open('http://foto.mail.ru/cgi-bin/photo/addphoto?answers=1&Title=&My=','add_pict','width=660,height=660,left='+(screen.width-660)/2+',top='+(screen.height-660)/2+',toolbars=no,scrollbars=yes,resizable=yes,left='+(screen.width-660)/2+',top='+(screen.height-660)/2); 
    if (popup) popup.focus(); 
} 

function add_video(){
    document.domain = "mail.ru";
    popup = false;
    if (popup) popup.close();
    popup = window.open('http://video.mail.ru/cgi-bin/photo/addvideo?answers=1&Title=','add_pict','width=660,height=660,left='+(screen.width-660)/2+',top='+(screen.height-660)/2+',toolbars=no,scrollbars=yes,resizable=yes,left='+(screen.width-660)/2+',top='+(screen.height-660)/2);
    if (popup) popup.focus();
}

function fkeyboard() {
  document.domain="mail.ru";
  window.open("http://mail.ru/kb/index.html?form=Compose&text=Body&keymode=2&savemode=3","keyb","height=360,width=610,toolbar=no,menubar=no,location=no,scrollbars=no,focus=yes,top=50,left=50");
  return false;
}

function lastQst( $name, $qid, $time ){
  var dt = new Date()
  dt.setSeconds( dt.getDate() + $time );  
  setCookie($name, $qid, dt.toGMTString() );
}

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
  ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function showRespectDiv(obj, link){ 
  var disp = gebi(obj).style.display;
  var dispStatus = disp == 'block' ? 1 : 0;
  var metadata = [ { display : 'block', link : 'Скрыть' }, { display : 'none', link : 'Предложить поддержку' } ];

  gebi( obj  ).style.display = metadata[ dispStatus ].display;
  gebi( link ).style.display = metadata[ 1 - dispStatus ].display;

  return false;
}

function parseEMail(email){
	var re = new RegExp("(.+)@([^\.]+)", "");
	var arr = re.exec(email);
	var result = { box: RegExp.$1, domain: RegExp.$2 };
	return result;
}

function ShowTopAnswerForm() {
	document.getElementById('AnswerTopForm').style.display = "block";
	document.getElementById('AnswerTopButton').style.display = "none";
	document.getElementById('AnswerBotForm').style.display = "none";
	document.getElementById('AnswerBotButton').style.display = "block";}
function HideTopAnswerForm() {
	document.getElementById('AnswerTopForm').style.display = "none";
	document.getElementById('AnswerTopButton').style.display = "block";}
function ShowBotAnswerForm() {
	document.getElementById('AnswerBotForm').style.display = "block";
	document.getElementById('AnswerBotButton').style.display = "none";
	document.getElementById('AnswerTopForm').style.display = "none";
	document.getElementById('AnswerTopButton').style.display = "block";}
function HideBotAnswerForm() {
	document.getElementById('AnswerBotForm').style.display = "none";
	document.getElementById('AnswerBotButton').style.display = "block";}
