//written by Cheery for ru-board.com
function quote()
{
this.sel_started=false,this.insert_over=false,this.mouse_down=false
var instimeout=1000,an_url="http://anonym.to/?",bropacity="filter: alpha(opacity=30);-moz-opacity:0.3;opacity:0.3",
ttxt="<b>&nbsp;Вставить цитату&nbsp;</b>",
ttxt2="<font size=-2><b><font color=red>X</font></b>&nbsp;</font>",
ttxt3="<span name='an_url' id='an_url'></span>"
document.write('<div id="insert_window" style="position:absolute;visibility:hidden" class=dats><div style="z-index:1000;position:absolute;background-color:black;'+bropacity+'"><span style="visibility:hidden">'+ttxt+ttxt2+ttxt3+'</span></div><div style="z-index:1001;position:relative;top:-7px;left:-7px;cursor:pointer;background-color:#FFFFEE;border-style:solid;border-color:#565656;border-width:1px;color:blue" onmouseout="setTimeout(hide_insert,'+instimeout+');qt.insert_over=false" onmouseover="qt.insert_over=true;copyQ()"><span onmousedown="qt.insert_cite()" align=center>'+ttxt+'</span>'+ttxt3+'<span onclick="qt.remove_insert()" title="Отключить фичу">'+ttxt2+'</span></div></div>')
this.f_not_member=function(evt)
{evt=get_e(evt)   
var targ=who_fired_event(evt)
if (targ&&targ.tagName!='TEXTAREA'&&(targ.tagName!='INPUT'&&targ.type!='TEXT'&&targ.type!='PASSWORD')) return true
  else return false}
this.remove_insert=function()
{var ok=confirm("Вы уверены, что хотите отключить данную фичу?\nОна будет доступна только после очистки cookies.")
if (ok) {Set_Cookie("finsert",1,365);this.hide_insert()}}
this.insert_mup=function(evt)
{
this.mouse_down=false
if (!this.sel_started) return
   else this.sel_started=false
evt=get_e(evt)
var txt2=''
if (window.getSelection) txt2=window.getSelection()
else if (document.getSelection) txt2=document.getSelection()
else if (document.selection) txt2=document.selection.createRange().text
if(txt2!=''&&this.f_not_member(evt)&&getById('post')&&!Get_Cookie('finsert'))
 {
  var coords=getMouseCoords(evt),iw=getById('insert_window');
  iw.style.left=coords[0]-62+'px';
  iw.style.top=coords[1]-17+'px';
  var url=this.isUrl(txt2);
  var lnks=document.getElementsByName('an_url');
  if (url!='') {for(var i=0;i<lnks.length;i++) lnks[i].innerHTML="<a href='"+an_url+"http://"+url+"' target=_blank><img src='"+ipath+"/popup_icon.gif' height=10 alt='^' title='Перейти по анонимной ссылке http://"+url+" в новом окне' width=15 border=0></a>&nbsp;"}
    else {for(var i=0;i<lnks.length;i++) lnks[i].innerHTML=""}
  iw.style.visibility='visible';
  setTimeout(hide_insert,instimeout);
 }
}
this.isUrl=function(s) {
try{var reg=new RegExp("([\\-\\w]+\\.)+\\w{2,3}(\\/[%\\-\\w]+(\\.\\w{2,})?)*(([\\w\\-\\.\\?\\\\/+@&#;`~=%!]*)(\\.\\w{2,})?)*\\/?","i")
var urls=reg.exec(s)
if (urls!=null) return urls[0]}
catch(e){};return ''}
this.insert_cite=function(){pasteQ();this.insert_over=false;this.hide_insert()}
this.hide_insert=function(){
if (!this.insert_over) 
 {//stupidity of old Opera, which doesn't refresh the textarea in case of simple visibility=hidden, have to move it outside
  var iw=getById('insert_window');iw.style.left=-100+'px';iw.style.top=-100+'px';}
 }
}
function hide_insert(){qt.hide_insert();}
function getMouseCoords(e) {
 var posx=0,posy=0,e=get_e(e);
  if ((e.clientX||e.clientY) &&
     document.body &&
     document.body.scrollLeft!=null) {
  posx=e.clientX+document.body.scrollLeft;
  posy=e.clientY+document.body.scrollTop;
 }
 if ((e.clientX||e.clientY) &&
     document.compatMode=='CSS1Compat' && 
     document.documentElement && 
     document.documentElement.scrollLeft!=null) {
  posx=e.clientX+document.documentElement.scrollLeft;
  posy=e.clientY+document.documentElement.scrollTop;
 }
 if (e.pageX||e.pageY) {
  posx=e.pageX;
  posy=e.pageY;
 }
return [posx,posy];}
var qt=new quote();
myEvent(document,'mousedown',(function(evt){if(qt.f_not_member(evt)) qt.mouse_down=true}),"+");
myEvent(document,'mousemove',(function(){if(qt.mouse_down&&!qt.sel_started) {qt.sel_started=true;qt.mouse_down=false}}),"+");
myEvent(document,'mouseup',(function(evt){qt.insert_mup(evt)}),"+")
