| 1 |
// Surrounds the selected text with text1 and text2. |
| 2 |
function surroundTheText(text1, text2, textarea) |
| 3 |
{ |
| 4 |
// Can a text range be created? |
| 5 |
if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange) |
| 6 |
{ |
| 7 |
var caretPos = textarea.caretPos, temp_length = caretPos.text.length; |
| 8 |
|
| 9 |
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2; |
| 10 |
|
| 11 |
if (temp_length == 0) |
| 12 |
{ |
| 13 |
caretPos.moveStart("character", -text2.length); |
| 14 |
caretPos.moveEnd("character", -text2.length); |
| 15 |
caretPos.select(); |
| 16 |
} |
| 17 |
else |
| 18 |
textarea.focus(caretPos); |
| 19 |
} |
| 20 |
// Mozilla text range wrap. |
| 21 |
else if (typeof(textarea.selectionStart) != "undefined") |
| 22 |
{ |
| 23 |
var begin = textarea.value.substr(0, textarea.selectionStart); |
| 24 |
var selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart); |
| 25 |
var end = textarea.value.substr(textarea.selectionEnd); |
| 26 |
var newCursorPos = textarea.selectionStart; |
| 27 |
var scrollPos = textarea.scrollTop; |
| 28 |
|
| 29 |
textarea.value = begin + text1 + selection + text2 + end; |
| 30 |
|
| 31 |
if (textarea.setSelectionRange) |
| 32 |
{ |
| 33 |
if (selection.length == 0) |
| 34 |
textarea.setSelectionRange(newCursorPos + text1.length, newCursorPos + text1.length); |
| 35 |
else |
| 36 |
textarea.setSelectionRange(newCursorPos, newCursorPos + text1.length + selection.length + text2.length); |
| 37 |
textarea.focus(); |
| 38 |
} |
| 39 |
textarea.scrollTop = scrollPos; |
| 40 |
} |
| 41 |
// Just put them on the end, then. |
| 42 |
else |
| 43 |
{ |
| 44 |
textarea.value += text1 + text2; |
| 45 |
textarea.focus(textarea.value.length - 1); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
//START AUTO COMPLETE |
| 50 |
function autosuggest(link) { |
| 51 |
q = document.getElementById('search-q').value; |
| 52 |
// Set the random number to add to URL request |
| 53 |
nocache = Math.random(); |
| 54 |
http.open('get', link+'newmessage&fepjscript=1&q='+q+'&nocache = '+nocache); |
| 55 |
http.onreadystatechange = autosuggestReply; |
| 56 |
http.send(null); |
| 57 |
} |
| 58 |
|
| 59 |
function createObject() { |
| 60 |
var request_type; |
| 61 |
var browser = navigator.appName; |
| 62 |
if(browser == "Microsoft Internet Explorer"){ |
| 63 |
request_type = new ActiveXObject("Microsoft.XMLHTTP"); |
| 64 |
}else{ |
| 65 |
request_type = new XMLHttpRequest(); |
| 66 |
} |
| 67 |
return request_type; |
| 68 |
} |
| 69 |
|
| 70 |
var http = createObject(); |
| 71 |
|
| 72 |
function autosuggestReply() { |
| 73 |
if(http.readyState == 4){ |
| 74 |
var response = http.responseText; |
| 75 |
e = document.getElementById('result'); |
| 76 |
if(response!=""){ |
| 77 |
e.innerHTML=response; |
| 78 |
e.style.display="block"; |
| 79 |
} else { |
| 80 |
e.style.display="none"; |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
function fepfillText(vv,v) { |
| 86 |
|
| 87 |
fillTextq(v); |
| 88 |
fillTextqq(vv) |
| 89 |
} |
| 90 |
|
| 91 |
function fillTextq(v) { |
| 92 |
e = document.getElementById('search-q'); |
| 93 |
e.value=v; |
| 94 |
document.getElementById('result').style.display="none"; |
| 95 |
} |
| 96 |
|
| 97 |
function fillTextqq(v) { |
| 98 |
e = document.getElementById('search-qq'); |
| 99 |
e.value=v; |
| 100 |
document.getElementById('result').style.display="none"; |
| 101 |
} |