// JavaScript Document

// Funkcja odpowiadaj±ca za obsługę adresów e-mail
function mail(u,d,s){locationstring="mailto:"+u+"@"+d+"?Subject="+s;window.location = locationstring;}


/* Cytowanie komentarzy */
function quoteText(author, bodyID) {
		var ta = document.getElementById('comment'), info = document.getElementById('quoteinfo')
			,selection = window.getSelection ? window.getSelection() : document.selection
			,quoted = selection.toString!==undefined ? selection.toString() : (selection.createRange ? selection.createRange().text : '')
			,comm = document.getElementById(bodyID);
		if ( !ta ) return;

		if ( info ) info.style.display = 'none';	// hide quickquote info box

		if ( !quoted && comm ) {	// there is no selection and comment exists
			quoted = comm.textContent!==undefined ? comm.textContent : (comm.innerText!==undefined ? comm.innerText : '');
			// show quickquote info box
			info.style.display = 'block';
		}

		ta.focus(); // makes caret stick to the end of text in IE
		ta.value += '[b]'+author+'[/b]' + ' napisał(a):\n[quote]'+ quoted.replace(/\t/g,'').replace(/^[\r\n]*/,'').replace(/[\r\n]*$/,'') +'[/quote]\n';
	}

  function editComment(commentid) {
    var commBody = document.getElementById('body'+commentid);
    if ( !commBody ) return;

    var commH = commBody.offsetHeight-8, commW = commBody.offsetWidth-8
     , commPos = getElemTopLeftPos(commBody);
    var ta = document.createElement('textarea');
     ta.style.width = commW+'px'; ta.style.height = commH+'px';
     ta.style.position = 'absolute'; ta.style.left = commPos.left, ta.style.top = commPos.top;
     ta.style.margin = '4px';
    document.body.appendChild( ta );

  }

  function getElemTopLeftPos(elem) {
    var pos = { left: 0, top: 0 };
    while ( elem.offsetParent ) {
      pos.left += elem.offsetLeft;
      pos.top += elem.offsetTop;
      elem = elem.offsetParent;
    }
    return pos;
  }
