﻿//创建一个XMLHttpRequest对象
var xmlHttp;
function createXmlHttpRequest()
{
    if(window.XMLHttpRequest)
    {
        xmlHttp=new XMLHttpRequest();
        if(xmlHttp.overrideMimeType)
        {
            xmlHttp.overrideMimeType("text/xml");
        }
    }
    else if(window.ActiveXObject)
    {
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    
    if(!xmlHttp)
    {
        window.alert("你的浏览器不支持创建XMLHttpRequest对象！");
    }
    
    return xmlHttp;
}
//创建CheckUserName
function CheckUserName(name)
{
    createXmlHttpRequest();
    var url="AjaxDisposeEvent.aspx?AJDAction=1&Name="+encodeURI(name);
    xmlHttp.open("post",url,true);
    xmlHttp.onreadystatechange=CheckUserNameResult;
    //xmlHttp.send(null);
    xmlHttp.send("");
}
//创建用户检测的回调函数
function CheckUserNameResult()
{
    if(xmlHttp.readyState==4)//服务器响应状态
    {
        if(xmlHttp.status==200)//代码执行状态
        {
            if(xmlHttp.responseText=="true")
            {
                alert("同名妮称已经存在！");
                document.getElementById("LblUserExist").focus();
            }
        }
        
    }
}

//收藏文章
function AddMyCollected(docid)
{
    createXmlHttpRequest();
    var url="/AjaxDisposeEvent.aspx?AJDAction=2&DID="+encodeURI(docid);
    xmlHttp.open("post",url,true);
    xmlHttp.onreadystatechange=AddMyCollectedResult;
    //xmlHttp.send(null);
    xmlHttp.send("");
}
//收藏文章的回调函数
function AddMyCollectedResult()
{
    if(xmlHttp.readyState==4)//服务器响应状态
    {
        if(xmlHttp.status==200)//代码执行状态
        {
            alert(xmlHttp.responseText);
        }
        
    }
}

//文章评论数
function GetDocTotalComments(docid)
{
    createXmlHttpRequest();
    var url="/AjaxDisposeEvent.aspx?AJDAction=3&DID="+encodeURI(docid);
    xmlHttp.open("post",url,true);
    xmlHttp.onreadystatechange=GetDocTotalCommentsResult;
    //xmlHttp.send(null);
    xmlHttp.send("");
}
//文章评论数的回调函数
function GetDocTotalCommentsResult()
{
    if(xmlHttp.readyState==4)//服务器响应状态
    {
        //alert(xmlHttp.readyState+ "  "+xmlHttp.status);
        if(xmlHttp.status==200)//代码执行状态
        {
            //alert(xmlHttp.responseText);
            document.getElementById("LblCommentCnt").innerHTML=xmlHttp.responseText;
            //alert(document.getElementById("LblCommentCnt").innerHTML);
            //document.getElementById("LblCommentCnt").innerHTML=xmlHttp.responseText;
        }
        
    }
}

//相关文章
function GetRelDocList(docid)
{
    createXmlHttpRequest();
    var url="/AjaxDisposeEvent.aspx?AJDAction=4&DID="+encodeURI(docid);
    xmlHttp.open("post",url,true);
    xmlHttp.onreadystatechange=GetRelDocListResult;
    //xmlHttp.send(null);
    xmlHttp.send("");
}
//相关文章的回调函数
function GetRelDocListResult()
{
    if(xmlHttp.readyState==4)//服务器响应状态
    {
        //alert(xmlHttp.readyState+ "  "+xmlHttp.status);
        if(xmlHttp.status==200)//代码执行状态
        {
            //alert(xmlHttp.responseText);
            document.getElementById("DivRelationLst").innerHTML=xmlHttp.responseText;
            //alert(document.getElementById("LblCommentCnt").innerHTML);
            //document.getElementById("LblCommentCnt").innerHTML=xmlHttp.responseText;
        }
        
    }
}

//相关文章以及评论总数
function GetRelDocAndCommentCnt(docid)
{
    createXmlHttpRequest();
    var url="/AjaxDisposeEvent.aspx?AJDAction=5&DID="+encodeURI(docid);
    xmlHttp.open("post",url,true);
    xmlHttp.onreadystatechange=GetRelDocAndCommentCntResult;
    //xmlHttp.send(null);
    xmlHttp.send("");
}
//相关文章以及评论总数的回调函数
function GetRelDocAndCommentCntResult()
{
    if(xmlHttp.readyState==4)//服务器响应状态
    {
        //alert(xmlHttp.readyState+ "  "+xmlHttp.status);
        if(xmlHttp.status==200)//代码执行状态
        {
            //alert(xmlHttp.responseText);
            var lindextag=xmlHttp.responseText.lastIndexOf("#");
            if(lindextag!= -1)
            {
                document.getElementById("DivRelationLst").innerHTML=xmlHttp.responseText.substr(0,lindextag);
                document.getElementById("LblCommentCnt").innerHTML=xmlHttp.responseText.substring(lindextag+1);
            }
            //alert(document.getElementById("LblCommentCnt").innerHTML);
            //document.getElementById("LblCommentCnt").innerHTML=xmlHttp.responseText;
        }
        
    }
}

//关键字描述
function GetKeyWordDescription(cid)
{
    createXmlHttpRequest();
    var url="/AjaxDisposeEvent.aspx?AJDAction=6&CID="+encodeURI(cid);
    
    xmlHttp.open("post",url,true);
    xmlHttp.onreadystatechange=GetKeyWordDescriptionResult;
    //xmlHttp.send(null);
    xmlHttp.send("");
}
//关键字描述的回调函数
function GetKeyWordDescriptionResult()
{
    //alert(xmlHttp.readyState);
    if(xmlHttp.readyState==4)//服务器响应状态
    {
        //alert(xmlHttp.readyState+ "  "+xmlHttp.status);
        if(xmlHttp.status==200)//代码执行状态
        {
            //alert(xmlHttp.responseText);
            document.getElementById("DivKeyWordDescription").innerHTML=xmlHttp.responseText;
        }
        
    }
}

//同名文章
function GetSameTitleDescription(ctitle)
{
    //alert(ctitle);
    createXmlHttpRequest();
    var url="/AjaxDisposeEvent.aspx?AJDAction=7&Title="+encodeURI(ctitle);
    //alert(url);
    xmlHttp.open("post",url,true);
    xmlHttp.onreadystatechange=GetSameTitleDescriptionResult;
    //xmlHttp.send(null);
    xmlHttp.send("");
    
}
//同名文章的回调函数
function GetSameTitleDescriptionResult()
{
    //alert(xmlHttp.readyState);
    if(xmlHttp.readyState==4)//服务器响应状态
    {
        //alert(xmlHttp.readyState+ "  "+xmlHttp.status);
        if(xmlHttp.status==200)//代码执行状态
        {
            //alert(xmlHttp.responseText);
            if(trim(xmlHttp.responseText)!="")
            {
                document.getElementById("DivSameTitleDescription").innerHTML=xmlHttp.responseText;
                document.getElementById("DivSameTitleDescription").style.display="block";
            }
        }
        
    }
}

function OpenWin(argurl)
{
	window.open(argurl,'','toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes, location=yes, status=yes')
} 

function TbxOnKeyDown() {
    if (event.keyCode == 13) 
    {
     return false;
    }
}

function resizeIframe(obj) {
    var Iframe = document.getElementById(obj);

        if (Iframe){
            if (Iframe.contentDocument){//ff
                Iframe.style.height = Iframe.contentDocument.body.scrollHeight +60+'px';
            }
            else if(Iframe.document && Iframe.document.body.scrollHeight){//ie
            Iframe.style.height = mainFrame.document.body.scrollHeight + 60 + 'px';
        }
    }
}

//去左空格; 
function ltrim(strparam)
{ 
    return strparam.replace( /^\s*/, ""); 
} 
//去右空格; 
function rtrim(strparam)
{ 
    return strparam.replace( /\s*$/, ""); 
} 
//去左右空格; 
function trim(strparam)
{ 
    return rtrim(ltrim(strparam)); 
} 

//搜索文章
function SearchArticle(strKeyWordId,strUrl)
{
    if(trim(document.getElementById(strKeyWordId).value)=="" || trim(document.getElementById(strKeyWordId).value)=="请输入关键字")
    {
        alert("请输入搜索条件！");
    }
    else
    {
        top.location.href=strUrl+encodeURI(trim(document.getElementById(strKeyWordId).value));
    }
}
//搜索文章
function SearchArticleByKeyWord(strKeyWord,strUrl,type)
{
    if(trim(strKeyWord)=="")
    {
        alert("请输入搜索条件！");
    }
    else
    {
        top.location.href=strUrl+encodeURI(trim(strKeyWord));
    }
}

function Request(strName)
{ 
    var strHref = window.document.location.href; 
    var intPos = strHref.indexOf("?"); 
    var strRight = strHref.substr(intPos + 1);

    var arrTmp = strRight.split("&"); 
    for(var i = 0; i < arrTmp.length; i++) 
    { 
        var arrTemp = arrTmp[i].split("=");

        if(arrTemp[0].toUpperCase() == strName.toUpperCase()) 
            return arrTemp[1]; 
    } 
    return ""; 
}

//内容恶意代码检测
function GetBadScriptDescription(content)
{
    //alert(ctitle);
    createXmlHttpRequest();
    var url="/AjaxDisposeEvent.aspx?AJDAction=8&CDoc="+encodeURI(ctitle);
    //alert(url);
    xmlHttp.open("post",url,true);
    xmlHttp.onreadystatechange=GetBadScriptDescriptionResult;
    //xmlHttp.send(null);
    xmlHttp.send("");
    
}
//内容恶意代码检测的回调函数
function GetBadScriptDescriptionResult()
{
    //alert(xmlHttp.readyState);
    if(xmlHttp.readyState==4)//服务器响应状态
    {
        //alert(xmlHttp.readyState+ "  "+xmlHttp.status);
        if(xmlHttp.status==200)//代码执行状态
        {
            //alert(xmlHttp.responseText);
            if(trim(xmlHttp.responseText)!="")
            {
                confirm(xmlHttp.responseText);
            }
        }
        
    }
}

//打开网页并最大化
function OpenWebMaxSize(url,winname)
{
    var now=new Date();
    var vy=now.getFullYear();
    var vm=now.getMonth()+1;
    var vd=now.getDate();


    var h=now.getHours(); 
    var m=now.getMinutes(); 
    var s=now.getSeconds(); 
    var wm=now.getMilliseconds();

    var winname=vy+""+vm+""+vd+ ""+h+""+m+""+s+""+wm;
    
    var mywin=window.open(url,winname,"toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,left=0,top=0,,width=500,height=480");
    mywin.moveTo(0, 0);
    mywin.resizeTo(screen.availWidth,screen.availHeight);

}

//打开网页并设置
function OpenWebCustom(url,swidth,sheight)
{
    var myleft = ( screen.availWidth - swidth ) / 2;
    var mytop = ( screen.availHeight - sheight ) / 2; 
    window.open(argurl,'','left=' + myleft +',top=' + mytop+ 
        ',width='+swidth+',height='+sheight+',toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=yes, status=no')

}

//
function ContentKeyWordSearch(keywordcontrolid,tag)
{
    var keywordcontrol=document.getElementById(keywordcontrolid);
    var strkeyword="";
    if (keywordcontrol == null)
    {
        strkeyword="";
    }
    else
    {
        if (keywordcontrol.value.length > 0)
        {
            strkeyword=keywordcontrol.value;
        }
    }
    if(trim(strkeyword)=="")
    {
        alert("请输入搜索关键字！");
        return;
    }
    
    strkeyword=encodeURI(strkeyword);
  
    if(tag==1)
        top.location.href="search.aspx?ChID=0&AID=0&KW="+strkeyword;
    else
        top.location.href="/search.aspx?ChID=0&AID=0&KW="+strkeyword;
}