﻿    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;
    }
   
     var isEdit=false;
    function SetReply(content,author,ip,authdate,index)
    {
        var strCon;
        if (content.indexOf("[/quote]") > 0)
        {
            content = content.substring(content.indexOf("[/quote]") + 8 ,content.length);
        }
        if (author == "")
        {
            author = ip;
        }
        if (index=="0")
        {
            strCon = "[quote]" + "原帖由楼主"+  author + "于" +  authdate + "发表";
        }
        else
        {
            strCon = "[quote]" + "原帖由" +index+"楼"+  author + "于" +  authdate + "发表";
        }
        var i=content.indexOf("--此评论于");
        if (i>0)
        {
            strCon = strCon + '\r\n' + content.substring(0,i).replace(/<BR>|<br>|<br\s*\/>|<BR\s*\/>/gmi,"\r\n") + "[/quote]" + '\r\n';
        }
        else
        {
            strCon = strCon + '\r\n' + content.replace(/<BR>|<br>|<br\s*\/>|<BR\s*\/>/gmi,"\r\n") + "[/quote]" + '\r\n';
        }
        var ctrl;
        ctrl = document.getElementById("uscCtrlCPView_txtReply")
        ctrl.value = strCon.replace(/&gt;/gmi, ">").replace(/&lt;/gmi, "<").replace(/&nbsp;/gmi," ").replace(/&quot;/gmi,"\"").replace(/&#39;/gmi,"\'").replace(/&amp;/gmi,"&");
        ctrl.focus(); 
        ctrl.value = ctrl.value;
        return false;
    }
    function chkdata(){
        var uscresult = checkdata();
        if( uscresult ){
            return true;
        }else{
            alert( jserror );
            return false;
        }
    }
    //发表处添加检查 tom add
    function chkCPdata()
    {
        var varEmail;
        var varPWD;
        varEmail=$("uscCtrlCPView_txtCPEmail").value;
        varPWD=$("uscCtrlCPView_txtCPPWD").value;
        varEmail=trim(varEmail);
        varPWD=trim(varPWD);
        if(varEmail=="")
        {
            alert("请填写EMAIL!");
            return false;
        }
        if(varPWD=="")
        {
            alert("请填写密码!");
            return false;
        }
        if(!CheckEmail(varEmail))
        {
            alert("EMAIL格式填写错误!");
            return false;
        }
        if(!CheckPassword(varPWD))
        {
            alert("不能包含非法字符，且长度必须在6-20位之间!");
            return false;
        }
        return true;
    }
    function SetCPEdit()
    {
       document.getElementById('checkChar2').innerText="（请至少输入50字）" ;
 
       ShowTextLength2(document.getElementById("uscCtrlCPView_EditWebTextBox"),'checkChar2',4000,50) ;
       document.getElementById("uscCtrlCPView_HidReplyMark").value="1";
       document.getElementById("uscCtrlCPView_EditWebTextBox").onkeyup= function(){ ShowTextLength2(document.getElementById("uscCtrlCPView_EditWebTextBox"),'checkChar2',4000,50);}
       
    }
    function SetCPReplyEdit()
    {
       document.getElementById('checkChar2').innerText="（请至少输入10字）" ;

       ShowTextLength2(document.getElementById("uscCtrlCPView_EditWebTextBox"),'checkChar2',4000,10) ;
       document.getElementById("uscCtrlCPView_HidReplyMark").value="2";
       document.getElementById("uscCtrlCPView_EditWebTextBox").onkeyup= function(){ ShowTextLength2(document.getElementById("uscCtrlCPView_EditWebTextBox"),'checkChar2',4000,10);}
       
    }
    
    function OnCancel()
    {
        ClearData('uscCtrlCPView_EditWebTextBox','checkChar2',document.getElementById('uscCtrlCPView_HidReplyMark').value);
        if ( document.getElementById("lititleTxt").style.display!='none')
        {
            document.getElementById("uscCtrlCPView_txtTitle").value='';
        }
        if ( document.getElementById("litagTxt").style.display!='none')
        {
            document.getElementById("uscCtrlCPView_txtTag").value='';
        }
    }
    
    function Login()
    {
        alert("请先登录!");
        document.getElementById('uscCtrlCPView_txtEmail').focus();
        return false;
    }
    function GetTag(name) 
    {
        var strTag=document.getElementById("uscCtrlCPView_txtTag").value.toString();
        if (strTag.indexOf(name)< 0){ document.getElementById("uscCtrlCPView_txtTag").value+=" "+name;}
　　}
　　function GetCPTag(name) 
    {
        var strTag=document.getElementById("uscCtrlCPView_txtCpTag").value.toString();
        if (strTag.indexOf(name)< 0){ document.getElementById("uscCtrlCPView_txtCpTag").value+=" "+name;}
　　}
　　
　　function CheckEditSave() 
    {
        if(isEdit)
        {
            var isok=true;
            var strerror="";
            var strTag=document.getElementById("uscCtrlCPView_txtTag").value;
            var strTitle=document.getElementById("uscCtrlCPView_txtTitle").value;
            if(strTitle=="")
            {
                isok=false;
                strerror="请输入标题!\r\n";
            }
            if (getstrlength(strTitle)>50)
            {
                isok=false;
                strerror=strerror+"标题不能超过50个字!\r\n";
            }
            if (getstrlength(strTag)>100)
            {
                isok=false;
                strerror=strerror+"标签不能超过100个字!\r\n";
            }
            if(isok){
                return CheckSave1('uscCtrlCPView_EditWebTextBox'); 
            }else{
                alert(strerror);
                strerror='';
                return false;   
            }
        }
        else
        {
            return CheckSave('uscCtrlCPView_EditWebTextBox');
        }
　　} 
　function CheckCPData()
    {
         
        var isok=true;
        var strerror="";
        var strContent=document.getElementById("uscCtrlCPView_txtCPContent").value;
        var strTag=document.getElementById("uscCtrlCPView_txtCpTag").value;
        var strTitle=document.getElementById("uscCtrlCPView_txtCPTitle").value;
        if(trim(strTitle).length<=0)
        {
            isok=false;
            strerror="请输入标题!\r\n";
        }
        if(trim(strContent).length<=0)
        {
            isok=false;
            strerror=strerror+"请输入内容!\r\n";
        }
        if (getstrlength(strTitle)>50)
        {
            isok=false;
            strerror=strerror+"标题不能超过50个字!\r\n";
        }
        if (getstrlength(strTag)>100)
        {
            isok=false;
            strerror=strerror+"标签不能超过100个字!\r\n";
        }
        if (getstrlength(strContent)<50)
        {
            isok=false;
            strerror=strerror+"请输入至少50个字的内容!\r\n";
        }
        if (getstrlength(strContent)>4000)
        {
            isok=false;
            strerror=strerror+"请输入4000个字以内的内容!\r\n";
        }
        if(!isok)
        {
            alert(strerror);
        }
        return isok;  
    
    }
   
     　//tom add 2009-11-03
    function OnCPCancel()
    {
         ClearData('uscCtrlCPView_txtCPContent','CheckCpContent',document.getElementById('uscCtrlCPView_CPAddMark').value);
         
         document.getElementById("uscCtrlCPView_txtCPTitle").value='';
         
         document.getElementById("uscCtrlCPView_txtCpTag").value='';
         
    }
    function GetContentJS(id,repid,TitleName,TAG)
    {
        var un;
        var str;
        un = document.getElementById(id);
        str=un.innerHTML.replace(/\r\n/gim,"");
        var i=str.indexOf("--此评论于");
        if (i>0)
        {
            document.getElementById("uscCtrlCPView_EditWebTextBox").value=str.substring(0,i).replace(/<DIV\s*id=[\"]*refers[\"]*><STRONG\s*class=[\"]*sfrom[\"]*>引用<\/STRONG><DIV\s*id=[\"]*refers_c[\"]*>/gim,"[quote]").replace(/<\/DIV><\/DIV>/gim,"[/quote]").replace(/<BR>|<br>/gmi,'\r\n').replace(/&gt;/gmi, ">").replace(/&lt;/gmi, "<").replace(/&nbsp;/gmi," ").replace(/&quot;/gmi,"\"").replace(/&#39;/gmi,"\'").replace(/&amp;/gmi,"&");
        }
        else   
        {
            document.getElementById("uscCtrlCPView_EditWebTextBox").value=str.replace(/<DIV\s*id=[\"]*refers[\"]*><STRONG\s*class=[\"]*sfrom[\"]*>引用<\/STRONG><DIV\s*id=[\"]*refers_c[\"]*>/gim,"[quote]").replace(/<\/DIV><\/DIV>/gim,"[/quote]").replace(/<BR>|<br>/gmi,'\r\n').replace(/&gt;/gmi, ">").replace(/&lt;/gmi, "<").replace(/&nbsp;/gmi," ").replace(/&quot;/gmi,"\"").replace(/&#39;/gmi,"\'").replace(/&amp;/gmi,"&");
        }
        document.getElementById("uscCtrlCPView_HidReplyID").value=repid;
        document.getElementById("uscCtrlCPView_HidREPLYINDEX").value=id;
     //   var TitleName='<%=TitleName.Replace("\\","\\\\").Replace("'","\\"+"'") %>';
       // var TAG='<%=TAG.Replace("\\","\\\\").Replace("'","\\"+"'") %>';
        document.getElementById("uscCtrlCPView_txtTitle").value=TitleName.replace(/&gt;/gmi, ">").replace(/&lt;/gmi, "<").replace(/&nbsp;/gmi," ").replace(/&quot;/gmi,"\"").replace(/&#39;/gmi,"\'").replace(/&amp;/gmi,"&");
        document.getElementById("uscCtrlCPView_txtTag").value=TAG.replace(/&gt;/gmi, ">").replace(/&lt;/gmi, "<").replace(/&nbsp;/gmi," ").replace(/&quot;/gmi,"\"").replace(/&#39;/gmi,"\'").replace(/&amp;/gmi,"&");
        if (id!='0')
        {
            document.getElementById("lititle").style.display='none';
            document.getElementById("lititleTxt").style.display='none';
            document.getElementById("litag").style.display='none';
            document.getElementById("litagTxt").style.display='none';
            document.getElementById("litags").style.display='none';
//            document.getElementById("psave").style.marginLeft='180px';
            isEdit=false;
        }
        else
        {
            document.getElementById("lititle").style.display='';
            document.getElementById("lititleTxt").style.display='';
            document.getElementById("litag").style.display='';
            document.getElementById("litagTxt").style.display='';
            document.getElementById("litags").style.display='';
//             document.getElementById("psave").style.marginLeft='0';
            isEdit=true;
        }
    }  
           function SetCPAddJS()
        {
               document.getElementById('CheckCpContent').innerText="（请至少输入50字）" ; 
       ShowTextLength2(document.getElementById("uscCtrlCPView_txtCPContent"),'CheckCpContent',4000,50) ;
       document.getElementById("uscCtrlCPView_CPAddMark").value="1";
       document.getElementById("uscCtrlCPView_txtCPContent").onkeyup= function()
       { 
            ShowTextLength2(document.getElementById("uscCtrlCPView_txtCPContent"),'CheckCpContent',4000,50);
       }
        }  
        
 function doButton( e) { 
 
    var key = window.event ? e.keyCode:e.which;
    
    if(key==13)  
    { 
        //btSubmit指对应的提交按扭的id名称
        var keyID = e.srcElement ?e.srcElement.id:e.target.id;
        var IsBack;
        if(keyID=="uscCtrlCPView_txtReply"||keyID=="uscCtrlCPView_EditWebTextBox" ||keyID=="uscCtrlCPView_txtCPContent"||keyID=="uscCtrlCPView_EditWebTextBox" )
        {
        
            IsBack= true;
        }
        else
        {
            IsBack= false;
        }
         
        return IsBack;
        
    }
}
