Wiki=function(){this.invokelist=new Array()};Wiki.prototype={getCursor:function(d){var a={start:0,end:0};if(d.setSelectionRange){a.start=d.selectionStart;a.end=d.selectionEnd}else{if(!document.selection){return 0}else{if(document.selection&&document.selection.createRange){var b=document.selection.createRange();var c=b.duplicate();c.moveToElementText(d);c.setEndPoint("EndToEnd",b);a.start=c.text.length-b.text.length;a.end=a.start+b.text.length}}}return a},setCursor:function(c,d,a){if(c.createTextRange){var b=c.createTextRange();b.move("character",d);b.select()}else{if(c.selectionStart){c.setSelectionRange(d,a)}}},custom:function(d,k,b,h){var g=$("#"+d)[0];var e=0;g.focus();var n=this.getCursor(g);var l=g.scrollTop;if(document.selection){var f=document.selection;var a=f.createRange();a.colapse;if(typeof(h)=="undefined"){v=k+a.text+b;e=n.end+k.length}else{v=a.text+h;e=n.end+h.length}a.text=v}else{var r=g.selectionStart;var m=g.selectionEnd;if(m<=2){m=g.textLength}var c=(g.value).substring(0,r);var q=(typeof(h)=="undefined")?(g.value).substring(r,m):h;var j=(g.value).substring(m,g.textLength);q=k+q+b;g.value=c+q+j;var e=r+(q.length)-b.length}this.setCursor(g,e,e);if(l){g.scrollTop=l}g.focus()},bold:function(a){this.custom(a,"**","**")},italic:function(a){this.custom(a,"//","//")},stroke:function(a){this.custom(a,"","")},underline:function(a){this.custom(a,"__","__")},user:function(b){var a=prompt("Введите имя пользователя","");if(a){this.custom(b,"","","@"+a)}},video:function(b){var a=prompt("Введите URL на видео в youtube или rutube","http://");if(a){this.custom(b,"","","{{"+a+"}}")}},image:function(id){if(typeof(this.invokelist.image)=="string"){eval(this.invokelist.image+"('"+id+"')")}},link:function(e){var d=$("#"+e)[0];if(d.setSelectionRange){var c=d.selectionStart!=d.selectionEnd}else{var a=document.selection.createRange();var c=a.text!=""}if(!c){alert("Выделите текст, который хотите сделать ссылкой");return}var b=prompt("Введите URL ссылки","http://");if(!/^(http|https|ftp)\:\/\/[0-9A-Za-z][0-9A-Za-z\-\.]*\.[a-zA-Z]{2,4}/.test(b)){alert("Это не URL");return}this.custom(e,"[["+b+"|","]]")},getLines:function(f){var e=this.getCursor(f);if(document.selection){var c=document.selection;var a=c.createRange();a.colapse;var b=e.start;var d=e.end}else{var b=f.selectionStart;var d=f.selectionEnd}if(f.value.substring(b-1,b)!="\n"){b=f.value.substring(0,b).lastIndexOf("\n")+1}if(f.value.substring(d,d+1)!="\n"){d=d+f.value.substring(d+1,f.value.length).indexOf("\n")+1}return{start:b,end:d}},quote:function(a){var d=$("#"+a)[0];d.focus();var k=this.getLines(d);ss=k.start;es=k.end;var h=d.value.substring(ss,es);var b=(d.value).substring(0,ss);var e=(d.value).substring(es,d.textLength);var c=h.split("\n");h="";for(i=0;i")?">":"> ")+j}h=h.substring(1);d.value=b+h+e;var c=ss+h.length;this.setCursor(d,c,c);d.focus()},list:function(a,j){var d=$("#"+a)[0];d.focus();var l=this.getLines(d);ss=l.start;es=l.end;var h=d.value.substring(ss,es);var b=(d.value).substring(0,ss);var e=(d.value).substring(es,d.textLength);var c=h.split("\n");h="";for(i=0;i