
var IE=0;
var MZ=0;
var OP=0;
var selectedText='';

function hasSelectedFeature(){

        if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
                IE=1;
                return true;
        }

        if (navigator.userAgent.indexOf("Mozilla") != -1 ){
                MZ=1;
                return true;
        }
        if (navigator.userAgent.indexOf("Opera/8") != -1 ||
        navigator.userAgent.indexOf("Opera/9") != -1){
                OP=1;
                return true;
        }
        return false;
}
hasSelectedFeature();

function getSelectedText(){
        if (IE || OP){
                if (document.selection.createRange()) {
                        return document.selection.createRange().text;
                } else {
                        return '';
                }
        }
        if (MZ){
                var s;

                if (typeof(window.getSelection)=="function"){
                        s = window.getSelection().toString();
                }else{
                        s = document.getSelection();

                }
                return s;
        }

        return '';
}

function quoteMessage(author, selectedText, alert_message){

        if (selectedText.length == 0) {
            alert(alert_message);
            return;
        }
        if (author.length == 0) {
            addon = "";
        } else {
            addon = "='" + author + "'";
        }

        citeText = "[quote" + addon + "]" + selectedText + "[/quote]";

        frm = document.forms['post'];
        frm.elements["f[text]"].focus();
        frm.elements["f[text]"].value += citeText;
        frm.elements["f[text]"].focus();
}
