﻿    function copyToClipboard(txt) {   
        if(window.clipboardData) {   
            window.clipboardData.clearData();   
            window.clipboardData.setData("Text", txt);
            return true;   
        } else if(navigator.userAgent.indexOf("Opera") != -1) {   
            window.location = txt;
            return true;   
        } else if (window.netscape) {   
            try {   
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");   
            } catch (e) {   
                alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");   
            }   
            var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);   
            if (!clip)   
                return false;   
            var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);   
            if (!trans)   
                return false;    
            trans.addDataFlavor('text/unicode');   
            var str = new Object();   
            var len = new Object();   
            var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);   
            var copytext = txt;   
            str.data = copytext;   
            trans.setTransferData("text/unicode",str,copytext.length*2);   
            var clipid = Components.interfaces.nsIClipboard;   
            if (!clip)   
                return false;   
            clip.setData(trans,null,clipid.kGlobalClipboard);   
            return true;   
        }   
    }  
    function AddBookmark()
    {
        var WebTitle = document.title;//标题 
        if(WebTitle == null){ 
            var t_titles = document.getElementByTagName("title");
            if(t_titles && t_titles.length >0) 
            { 
                WebTitle = t_titles[0]; 
            }else{ 
                WebTitle = ""; 
            } 
        }
        if (document.all)
            window.external.AddFavorite(window.location.href, WebTitle);
        else if (window.sidebar)
            window.sidebar.addPanel(WebTitle, window.location.href, "")
    }
    function CopyCode()
    {
        if(copyToClipboard(window.location.href))
        {
            alert("已将链接复制到剪贴板中！");
        }
        else
        {
            alert("复制失败！");
        }
    }
	
function ClearData(id,txtid)
    {
	ClearData(id,txtid,'2');
}

    function ClearData(id,txtid,markvalue)
    {
         document.getElementById(id).value='';
	if(markvalue=="1")
	{
		 document.getElementById(txtid).innerHTML='（请至少输入50字符）';
	}
	else
	{
		document.getElementById(txtid).innerHTML='（请至少输入10字符）';	
	}
    }
    function onSaveCheck(id)
    {
        var un,pw;
        un = document.getElementById(id);
        if (un != null)
        {
            if (trim(un.value) == "")
            {
            
                alert("内容不能为空！");
                return false;
            }
            else if (getstrlength(un.value) <10)
            {
                alert("请输入至少10个字符的内容!");
                return false;
            }
            else
            {
                var strValue = un.value;
                if (strValue.indexOf("[/quote]") >= 0)
                {
                    strValue = strValue.substring(strValue.indexOf("[/quote]") + 8).replace("\r\n","");
                }
                if (!checkStrLength(trim(strValue),1,4000))
                {
                    alert("除去引用内容，发表内容不得为空或超过4000个字符！");
                    return false;
                }
            }
        }
        return true;
    }
    function CheckSave(id)
    {
        var un,pw;
        un = document.getElementById(id);
        if (un != null)
        {
            if (trim(un.value) == "")
            {
           
                alert("内容不能为空！");
                return false;
            }
            else if (getstrlength(un.value) <10)
            {
                alert("请输入至少10个字符的内容!");
                return false;
            }
            else
            {
                var strValue = un.value;
                if (strValue.indexOf("[/quote]") >= 0)
                {
                    strValue = strValue.substring(strValue.indexOf("[/quote]") + 8).replace("\r\n","");
                }
                if (!checkStrLength(trim(strValue),1,4000))
                {
                    alert("除去引用内容，发表内容不得为空或超过4000个字符！");
                    return false;
                }
            }
        }
        return true;
    }
	function CheckSave1(id)
    {
        var un,pw;
        un = document.getElementById(id);
        if (un != null)
        {
            if (trim(un.value) == "")
            {
                alert("内容不能为空！");
                return false;
            }
            else if (getstrlength(un.value) <50)
            {
                alert("请输入至少50个字符的内容!");
                return false;
            }
            else
            {
                var strValue = un.value;
                if (strValue.indexOf("[/quote]") >= 0)
                {
                    strValue = strValue.substring(strValue.indexOf("[/quote]") + 8).replace("\r\n","");
                }
                if (!checkStrLength(trim(strValue),1,4000))
                {
                    alert("除去引用内容，发表内容不得为空或超过4000个字符！");
                    return false;
                }
            }
        }
        return true;
    }