    var xh;
    /*阿阮，這個function不要重覆定義到，要使用$的話我們的頁面都有include prototype.js裡面就有宣告了
    function $(obj){
        return document.getElementById(obj);
    }
    */
    function createObject() {
        if (window.XMLHttpRequest) { // 如果可以取得XMLHttpRequest
            xh = new XMLHttpRequest();  // Mozilla、Firefox、Safari
        }
        else if (window.ActiveXObject) { // 如果可以取得ActiveXObject
            xh = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer
        }
    }

function stkClearMe(control)
{
    if(control.value == '請輸入搜尋關鍵字'){
        control.value = '';
    }
    control.style.color = "black";
}
function stkRestore(control, str)
{
 if (control.value == '') {control.value = str; control.style.color = "#a8a8a8";};

}
function stkchkmsg(){
   if (document.Search_Form.search_keyword.value == '請輸入搜尋關鍵字' || document.Search_Form.search_keyword.value == '') {
        alert('請輸入搜尋關鍵字!!');
        document.Search_Form.search_keyword.focus();
        return false;
    }
}


    //版主私訊 system msg
    function check_sysmsg(){

        if(msg_check(document.sysmsg.subject.value)==false) {
            alert('請輸入標題!!');
            document.sysmsg.subject.focus();
            return false;
        }

        if(document.sysmsg.subject.value.length>30){
            alert('標題過長!!');
            return false;
        }

        if(document.sysmsg.sforum.checked==false && document.sysmsg.ssub.checked==false && document.sysmsg.sgroup.checked==false) {
            alert('請至少勾選一個版群!!');
            document.sysmsg.sforum.focus();
            return false;
        }

/*
        if(document.privmsg_send.mreceive.value.length>30){
            alert('收件人 Id 過長!!');
            return false;
        }
*/

        if (msg_check(document.sysmsg.content.value)==false) {
            alert('請輸入內容!!');
            document.sysmsg.content.focus();
            return false;
        }

        if(document.sysmsg.content.value.length>250){
            alert('內容過長!!');
            return false;
        }

        if(document.sysmsg.sforum.checked == false){
            document.sysmsg.sforum.value = "futile";
        }

        if(document.sysmsg.ssub.checked == false){
            document.sysmsg.ssub.value = "futile";
        }

        if(document.sysmsg.sgroup.checked == false){
            document.sysmsg.sgroup.value = "futile";
        }

        new Ajax.Request("system_action.php", {
        parameters: $H({subject: document.sysmsg.subject.value,
                        content: document.sysmsg.content.value,
                        userip:  document.sysmsg.getip.value,
                        sforum:  document.sysmsg.sforum.value,
                        ssub:    document.sysmsg.ssub.value,
                        sgroup:  document.sysmsg.sgroup.value}).toQueryString(),
        onSuccess: function(transport) {
            if(transport.responseText == "success") {
                show_msg('版主訊息新增成功!!');
                location.href="system_msg.htm";
            } else
                show_msg(transport.responseText);
        }

       });
    }


    //精華區文章分類搬移
    function cream_move(tid){
            var arr = document.getElementsByTagName('INPUT');
            var have_data=0
            var have_check = 0;
            var tid_string = "";
            for(var i = 0; i < arr.length; i++){
                if(arr[i].id == tid){
                    have_data++;
                    if(arr[i].checked == true) {
                        have_check++;
                        tid_string += ","+arr[i].value;
                    }
                }
            }
            if(have_data <=0) {
                show_msg('沒有任何精華區文章');
                return false;
            }
            if(have_check <=0) {
                show_msg('您尚未勾選任何精華區文章');
                return false;
            }
            tid_string = tid_string.substr(1,tid_string.length);

            new Ajax.Request("cream_action.php", {
            parameters: $H({cate_move:      document.cream_list.cream_del.value,
                            channel:        document.cream_list.channel.value,
                            fid:            document.cream_list.fid.value,
                            userid:         document.cream_list.userid.value,
                            tid_ary:        tid_string,
                            special_no:     document.cream_list.special_no.value,
                            user_ip:        document.cream_list.user_ip.value}).toQueryString(),
            onSuccess: function(transport) {
                if(transport.responseText == "success") {
                    show_msg('精華區文章搬移成功!!');
                    location.reload();
                } else
                    show_msg(transport.responseText);
                }

            });
    }//endof function


    //精華區文章刪除
    function cream_delete(tid){

            var arr = document.getElementsByTagName('INPUT');
            var have_data=0
            var have_check = 0;
            var tid_string = "";
            for(var i = 0; i < arr.length; i++){
                if(arr[i].id == tid){
                    have_data++;
                    if(arr[i].checked == true) {
                        have_check++;
                        tid_string += ","+arr[i].value;
                    }
                }
            }
            if(have_data <=0) {
                show_msg('沒有任何精華區文章');
                return false;
            }
            if(have_check <=0) {
                show_msg('您尚未勾選任何精華區文章');
                return false;
            }
            tid_string = tid_string.substr(1,tid_string.length);

            new Ajax.Request("cream_action.php", {
            parameters: $H({cream_del:  document.cream_list.cream_del.value,
                            channel:    document.cream_list.channel.value,
                            fid:        document.cream_list.fid.value,
                            userid:     document.cream_list.userid.value,
                            tid_ary:    tid_string,
                            user_ip:    document.cream_list.user_ip.value}).toQueryString(),
            onSuccess: function(transport) {
                if(transport.responseText == "success") {
                    show_msg('精華區文章刪除成功!!');
                    location.reload();
                } else
                    show_msg(transport.responseText);
                }

            });
    }//endof function


    //分子版文章批次加入精華區
    function cream_tjoin(tid){
            var arr = document.getElementsByTagName('INPUT');
            var have_data=0
            var have_check = 0;
            var tid_string = "";
            for(var i = 0; i < arr.length; i++){
                if(arr[i].id == tid){
                    have_data++;
                    if(arr[i].checked == true) {
                        have_check++;
                        tid_string += ","+arr[i].value;
                    }
                }
            }
            if(have_data <=0) {
                show_msg('沒有任何文章');
                return false;
            }
            if(have_check <=0) {
                show_msg('您尚未勾選任何文章');
                return false;
            }
            tid_string = tid_string.substr(1,tid_string.length);

            new Ajax.Request("cream_action.php", {
            parameters: $H({cream_join:     document.post_admin.cream_join.value,
                            channel:        document.post_admin.channel.value,
                            fid:            document.post_admin.fid.value,
                            userid:         document.post_admin.userid.value,
                            tid_ary:        tid_string,
                            special_no:     document.post_admin.special_no.value,
                            user_ip:        document.post_admin.user_ip.value}).toQueryString(),
            onSuccess: function(transport) {
                if(transport.responseText == "success") {
                    show_msg('文章加入精華區成功!!');
                    location.reload();
                } else
                    show_msg(transport.responseText);
                }

            });
    }//endof function




    function msg_check(txtval){
        if(txtval.length==0){
            return false;
        }
        var i=0;
        while (i<txtval.length) {
            if (txtval.substring(i,i+1) != ' ')
                return true;
                i=i+1;
        }
        return false;
    }





    //留言板張貼檢查程式
    function add_check(){
        var tf = $("Main_Form");
        if(check_null(tf.Subject,"請輸入主題") == false) return false;
        if(check_null(tf.Author,"請輸入作者") == false) return false;
        if(check_null(tf.Content,"請輸入留言內容") == false) return false;
        var bkup = $("Func_Row").innerHTML;
        $("Func_Row").innerHTML = "資料傳輸中，請稍後";

        //使用ajax方式存資料，避免按reload造成重覆資料進資料庫的問題
        createObject(); // 建立非同步請求物件
        xh.open("POST", "privmsg_action.php",false);  // 開啟連結
        var str = "&Subject="+encodeURIComponent(tf.Subject.value)+"&Author="+encodeURIComponent(tf.Author.value)+"&Content="+encodeURIComponent(tf.Content.value);
        //仍有問題要修改，若有輸入&的符號會造成誤判（嘟嘟說用encodeURI但測試結果仍相同）
        xh.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xh.send(str);  // 傳送請求
        alert(xh.responseText);
        if(xh.responseText != "ok"){
            alert("※※※※　系統訊息　※※※※\r\n\r\n目前無法存入資料庫，請稍後再嘗試");
            $("Func_Row").innerHTML = bkup;
        } else {
            if(confirm("※※※※　系統訊息　※※※※\r\n\r\n已成功張貼留言，\r\n\r\n您要繼續張貼下一筆嗎？")){
                tf.reset();
                $("Func_Row").innerHTML = bkup;
            } else
                location.href="index.php";
        }
        return false;
    }

    //判斷輸入欄位是否為空值
    function check_null(obj,msg){
        if(obj.value == ""){
            alert(msg);
            obj.focus();
            return false;
        }
        return true;
    }

    //換頁function
    function goto(page){
        location.href=page;
    }

    //回上頁
    function goback(){
        history.back();
    }
