    function MM_openBrWindow(theURL,winName,features)
    {
        window.open(theURL,winName,features);
    }

    function check_email(str) 
    {
        return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
    }

    function check_apply_form(form)
    {
        if(form.title.value == "") {
            alert("請輸入標題!!");
            return false;
        }

        if(form.content.value == "") {
            alert("請輸入內容!!");
            return false;
        }

        return true;
    }

    function check_auth_form(form) 
    {
        if(form.password1.value != form.password2.value) {
            alert("兩次密碼輸入不相同!");
            return false;
        }
        
        return true;
    }

    function check_auth_form2(form) 
    {
        if(form.PersonID.value.length == 0) {
            alert("請輸入身分證號碼!!");
            return false;
        }
        
        if(form.Phone.value.length == 0) {
            alert("請輸入電話號碼!!");
            return false;
        }
        
        if(form.Address.value.length == 0) {
            alert("請輸入地址!!");
            return false;
        }
        
        return true;
    }

    function check_comment_form(form) 
    {
        if(form.content.value=="") {
            alert("所有欄位皆為必填!");
            return false;
        }
        
        return true;
    }	  

    function check_upload_pic(form)
    {
        if(form.pic.value == "") {
            alert("請選擇圖片上傳!");
            return false;
        }
        return true;
    }

    function confirmAllDelete(theLink)
    {
        if(typeof(window.opera) != 'undefined')
            return true;
        
        var is_confirmed = confirm('請注意! 你選擇刪除整個相簿\n確定要刪除嗎?');
              
        return is_confirmed;
    }

    function confirmAbuse(theLink) {
        if(typeof(window.opera) != 'undefined')
            return true;
        var is_confirmed = confirm('當對方累積一定數量的被檢舉數後，會被系統自動列入水桶名單，暫時無法留言\n\n請三思，確定您要檢舉這篇留言？');
        return is_confirmed;
    }

    function confirmDelete(theLink)
    {
        if(typeof(window.opera) != 'undefined')
            return true;
        
        var is_confirmed = confirm('確定要刪除嗎?');
              
        return is_confirmed;
    }
    
    function confirmDeleteMainCat(theLink)
    {
        if(typeof(window.opera) != 'undefined')
            return true;
        
        var is_confirmed = confirm('請注意！刪除此主目錄，包含其中的子目錄所有文章也都會刪除！\n確定要刪除嗎？請三思！');
              
        return is_confirmed;
    }

    function confirmDeleteMainCat2(theLink)
    {
        if(typeof(window.opera) != 'undefined')
            return true;
        
        var is_confirmed = confirm('請注意！刪除此主目錄，包含其中的子目錄所有照片也都會刪除！\n確定要刪除嗎？請三思！');
              
        return is_confirmed;
    }

    function confirmDelete2(theLink)
    {
        if(typeof(window.opera) != 'undefined')
            return true;
        
        var is_confirmed = confirm('此群組下還有好友, 請你三思! 確定要刪除嗎?');
              
        return is_confirmed;
    }

    function cantDelete(theLink)
    {
        alert("此分類下還有朋友或是預設分類目錄, 不能刪除!");

        return false;
    }

    function cantHide(theLink)
    {
        alert("此分類是預設分類目錄, 不能隱藏!");

        return false;
    }

    function cantDeleteLinkCat(theLink)
    {
        alert("此分類下還有資料, 不能刪除!");

        return false;
    }

    function cantDeleteDiaryCat(theLink)
    {
        alert("此日記目錄下還有文章, 不能刪除!");

        return false;
    }

    function cantDeleteGalleryCat(theLink)
    {
        alert("此相簿目錄下還有相片, 不能刪除!");

        return false;
    }

    function cbox_switch2(myform)
    {
        var arg = false;
        
        if(myform.id_all.checked == true)
            arg = true;
        else
            arg = false;

        for(var i=0;i<myform.elements.length;i++) {
            if(myform.elements[i].type == "checkbox") {
                myform.elements[i].checked = arg;
            }
        }
    }

    function check_friend_cat_form(form)
    {
        if(form.newcat.value == "") {
            alert("請輸入新增分類名稱!");
            return false;
        }
        
        return true;
    }

    function check_friend_cat_form2(form)
    {
        for(var i = 0; i < form.elements.length; i++) {
            if(form.elements[i].name == "cname[]") {
                if(form.elements[i].value == "") {
                    alert("分類名稱不能空白!");
                    return false;
                }
            }
        }

        return true;
    }

    function checkSortValue(form)
    {
        var arr = new Array();

        for(var i = 0, j = 0; i < form.elements.length; i++) {
            if(form.elements[i].name == "newpos[]") {
                arr[j++] = form.elements[i].value;
            }
        }

        for(var i = 0; i < arr.length-1; i++) {
            for(var j = i+1; j < arr.length; j++) {
                if(arr[i] == arr[j]) {
                    alert("位置值不能相同!");
                    return false;
                }
            }
        }

        return true;
    }

    //function checkForward(uid, id, type) 
    function checkForward(id, type) 
    {
        /*
        if(uid == "0") {
            alert("請先登入");
            return false;
        }*/

        //var url = "forward.php?uid="+uid+"&id="+id+"&type="+type;
        var url = "forward.php?id="+id+"&type="+type;
        window.open(url, '', 'menubar=no,scrollbars=no,width=300,height=480,top=150,left=150');

        return true;
    }

    function applyFriend(fid, uid) 
    {
        if(uid == "0") {
            alert("請先登入");
            return false;
        }

        var url = "/friend2.php?apply="+fid;
        window.open(url, '', 'menubar=no,scrollbars=no,location=no,width=790,height=470,top=150,left=150');

        return true;
    }

    function broadcast() 
    {
        var url = "broadcast.php";
          
        window.open(url, '', 'menubar=no,scrollbars=no,width=300,height=160,top=150,left=150');
    }
    
    function broadcast2(rid, ruid)
    {
        var url = "broadcast.php?" + "rid=" + rid + "&ruid=" + ruid;
        window.open(url, '', 'menubar=no,scrollbars=no,width=550,height=285,top=150,left=150');
    }

    function openRecommand(page, did, h) 
    {
        var url = "/"+page+"?did="+did;
        var opt = 'menubar=no,scrollbars=no,width=360,height='+h+',top=150,left=150';
          
        window.open(url, 'recommand', opt);
    }

    function openReport(page, did, h) 
    {
        var url = "/"+page+"?did="+did;
        var opt = 'menubar=no,scrollbars=no,width=360,height='+h+',top=150,left=150';
          
        window.open(url, 'report', opt);
    }

    function emptyField(object, str)
    {
        if(object.value == str) {
            object.value = "";
        }
    }

    function insertDiaryPic() 
    {
        var url = "uploadpic.php?to=diarypic";
        window.open(url, 'uploadpic', 'menubar=no,scrollbars=no,width=550,height=500,top=150,left=150');
    }

    function insertGalleryToDiaryPic(type) 
    {
        url = "gallerylist.php?type="+type;
        var oWindow = window.open(url, 'uploadpic', 'menubar=no,scrollbars=no,width=550,height=500,top=150,left=150');
        oWindow.FCK = window.FCK;
    }

    function insertGIntoEditor(my_value, uid, type)
    {
        if(my_value != "") {
            oImage = window.opener.FCK.CreateElement( 'IMG' ) ;
            oImage.src = "http://rvp.mwsrv.com/gallerypic/" + uid + "/" + my_value;
            oImage.border = '0';
        }
        window.close();
    }

    function insertGIntoDiary(my_value, uid, type)
    {
        if(my_value != "") {
            pic = "<img src='http://rvp.mwsrv.com/gallerypic/"+uid+"/"+my_value+"'>";
            window.opener.document.getElementById('insertPic').innerHTML = pic;
            window.opener.document.DiaryPost.gpic.value = my_value;
            window.opener.document.DiaryPost.pic.value = "";
        }
        window.close();
    }

    function insertPicValue(my_value, to)
    {
        if(my_value != "") {
            pic = "<img src='http://pic.mwsrv.com/"+to+"/tmp/"+my_value+"'>";
            if(to == "diarypic") {
                window.opener.document.DiaryPost.pic.value = my_value;
                window.opener.document.DiaryPost.gpic.value = "";
            }
            else if(to == "gallerypic") {
                window.opener.document.GalleryPost.pic.value = my_value;
            }
            window.opener.document.getElementById('insertPic').innerHTML = pic;
        }
        window.close();
        return false;
    }

    function deleteDiaryPostPic(form)
    {
        var is_confirmed = confirm('執行本按鈕會將您的照片刪除，若您日記未編修完成也請先存檔，以免資料遺失之憾');
        if(is_confirmed) {
            document.DiaryPost.pic.value = "";
            document.DiaryPost.gpic.value = "";
            document.getElementById('insertPic').innerHTML = "";
        }
    }

    function deleteDiaryEditPic(form)
    {
        var is_confirmed;
        if(document.getElementById('insertPic').innerHTML == "") {
            is_confirmed = confirm('執行本按鈕會將您的"原照片"刪除，若您未編修完成也請先存檔，以免資料遺失之憾');
            if(is_confirmed) {
                document.DiaryPost.oldpic.value = "";
                document.DiaryPost.oldgpic.value = "";
                document.getElementById('ooldpic').innerHTML = "(無)";
            }
        }
        else {
            is_confirmed = confirm('執行本按鈕會將您的"新照片"刪除，若您未編修完成也請先存檔，以免資料遺失之憾');
            if(is_confirmed) {
                document.DiaryPost.pic.value = "";
                document.DiaryPost.gpic.value = "";
                document.getElementById('insertPic').innerHTML = "";
            }
        }
    }

    function insertGalleryPic()
    {
        var url = "uploadpic.php?to=gallerypic";
        window.open(url, 'uploadpic', 'menubar=no,scrollbars=no,width=550,height=500,top=150,left=150');
    }

    function checkDiaryReply(obj)
    {
        if(obj.value == "" || obj.value.match(/^\s+/)) {
            alert("請填寫回應內容");
            return false;
        } else if(obj.value.length > 1000){
            alert("文章超過 1000 字，請分篇送出");
            return false;
        }
        return true;
    }

    function checkDiaryReplyName(obj)
    {
        if(obj.value == "") {
            alert("請填寫留言人");
            return false;
        }
        return true;
    }

    function CreateBookmark(title,url) {
        if(window.sidebar) { // Mozilla/firefox
            window.sidebar.addPanel(title, url,"");
        } else if(window.external) {
            window.external.AddFavorite(url,title);
        } else if(window.opera && window.print) {
            return true;
        }
    }

    function checkSendMsg(fid, uid)
    {
        if(uid == "0") {
            alert("請先登入");
            return false;
        }
        
        var url = "/sendMsg.php?uid="+fid;
        window.open(url, '', 'menubar=no,scrollbars=no,width=560,height=430,top=150,left=150');

        return true;
    }

    function openOringalPic(fname, width, height)
    {
        var url = "showpic.php?pic="+fname;
        if(width > 800 && height > 600)
            var vars = "menubar=no,scrollbars=yes,width=800,height=600,top=150,left=150";
        else if(width > 800 && height <= 600) {
            height = parseInt(height) + 30;
            var vars = "menubar=no,scrollbars=yes,width=800,height="+height+",top=150,left=150";
        } else if(width <= 800 && height > 600) {
            width = parseInt(width) + 30;
            var vars = "menubar=no,scrollbars=yes,width="+width+",height=600,top=150,left=150";
        } else {
            var vars = "menubar=no,scrollbars=yes,width="+width+",height="+height+",top=150,left=150";
        }
        window.open(url, '', vars);
    }

    function checkCheckBox(form, obj)
    {
        var n = 0;
        for(var i = 0; i < form.elements.length; i++) {
            if(form.elements[i].name == obj) {
                if(form.elements[i].checked == true)
                    n++;
            }
        }
        if(n == 0) {
            alert("請至少選擇一項來動作");
            return false;
        }
        return true;
    }	

    function checkLogin(guest, who, url)
    {
        if(guest == "0") {
            alert("請先登入");
            return false;
        }
        
        who.location = url;
        return false;
    }

    function checkLogin2(guest, who, url)
    {
        if(guest == "0") {
            alert("請先登入");
            return false;
        }
        
        window.open(url, '', 'menubar=no,scrollbars=yes,width=560,height=430,top=150,left=150');
        return false;
    }

    function checkLogin3(guest, who, page, user)
    {
        var url = page + '?to=' + user;

        if(guest == "0") {
            alert("請先登入");
            return false;
        }
        
        window.open(url, '', 'menubar=no,scrollbars=yes,width=320,height=300,top=150,left=150');
        return false;
    }

    function openComment(id)
    {
        var url = '/showComment.php?cid='+id;
        window.open(url, '', 'menubar=no,scrollbars=yes,width=150,height=150,top=150,left=150');
        return false;
    }

    function checkKeyword(form)
    {
        if(form.keyword.value == "") {
            alert("請輸入關鍵字");
            return false;
        }
        return true;
    }

    var tagwindow = '';
    function openTagURL(url)
    {
        var name = "tagWindow";
        var argv = "";
        if (!tagwindow.closed && tagwindow.location) {
            tagwindow.location.href = url;
            tagwindow.location.reload(true);
        } else {
            tagwindow = window.open(url,name,argv);
            if (!tagwindow.opener) tagwindow.opener = self;
        }
        if (window.focus) { tagwindow.focus(); }
        return false;
    }

    function utf8_decode(utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

    function confirmDeleteSelect(obj){
       if(typeof(window.opera) != 'undefined'){
          var input_Ele = document.createElement('input');
          input_Ele.type = 'hidden';
          input_Ele.name ='submit_d';
          input_Ele.value ='d10';
          document.getElementById(obj).appendChild(input_Ele);
          document.getElementById(obj).submit();
       }         
       else if(confirm('確定要刪除嗎?')){
               var input_Ele = document.createElement('input');
               input_Ele.type = 'hidden';
               input_Ele.name ='submit_d';
               input_Ele.value ='d10';
               document.getElementById(obj).appendChild(input_Ele);
               document.getElementById(obj).submit();
       }  
    }

    function confirmReadAll(obj,box){
       if(confirm('請注意，按下「確定」後，將會把您的訊息收發室內容全數標示成已讀，請問您是否確定？')){
          var input_Ele = document.createElement('input');
          input_Ele.type = 'hidden';
          input_Ele.name ='submit_r';
          input_Ele.value ='r11';
          document.getElementById(obj).appendChild(input_Ele);
          document.getElementById(obj).submit();
       }
    }


    function confirmDeleteAll(obj,box){
       if(confirm('請注意，按下「確定」後，將會把您的'+box+'內容全數刪去，請問您確定要刪除嗎？')){
          var input_Ele = document.createElement('input');
          input_Ele.type = 'hidden';
          input_Ele.name ='submit_d';
          input_Ele.value ='d11';
          document.getElementById(obj).appendChild(input_Ele);
          document.getElementById(obj).submit();
       }
    }

    function setIframeURL(url) {
        var win = document.getElementById('contentFrame');
        if (!win)
            win = document.getElementsByTagName('iframe')[0].contentWindow
        else
            win = win.contentWindow;
        if (win)
            win.location.href = url;
        return false;
    }

    function selectConfirm(obj)
    {
        var sel = confirm("如果您在此切換為群組信，所有未儲存的內容將會不見，確定您存了嗎？");
        if(sel) {
           obj.href = "cp.php?op=myMailbox&sub_op=MailGWrite";
           return true;
        }
        else
           return false;
    }
