﻿// JScript 文件
function $(id) { return document.getElementById(id) }


// 获取关键词
function AjaxSearch(obj, Name) {

    var ajax = new list("", "<book>" + Name + "</book>", "10");
    ajax.onSuccess = function () {
        if (document.getElementById("search_result") != null)
            document.getElementById("search_result").innerHTML = xmlHttp.responseText;
    }
    ajax.Init();
}

function checkCookieExist() {
    if (cookie("LoginName") != "" && cookie("LoginName") != null) {
        if (document.getElementById("loginName") != null)
            document.getElementById("loginName").innerHTML = "您好" + cookie("LoginName") + ",&nbsp;&nbsp;<a href=\"\" onclick='delCookie(\"LoginName\")'>[退出]</a>";
    } else {
        if (document.getElementById("loginName") != null)
            document.getElementById("loginName").innerHTML = "您好,欢迎您的光临&nbsp;&nbsp;<a href=\"/login/login.aspx\" target=\"_blank\">[请登录]</a>&nbsp;&nbsp;<a href=\"/login/register.aspx\" target=\"_blank\">[免费注册]</a>";

    }
}

function tabit(id, cid) {
    biz_tit1.className = "tagsbutton2"; biz_tit2.className = "tagsbutton2"; id.className = "tagsbutton lanktitle";
    biz_1.style.display = "none"; biz_2.style.display = "none"; cid.style.display = "block";
}

function cookie(name) {
    var cookieArray = document.cookie.split("; "); //得到分割的cookie名值对    
    var cookie = new Object();
    for (var i = 0; i < cookieArray.length; i++) {
        var arr = cookieArray[i].split("=");       //将名和值分开    
        if (arr[0] == name) return unescape(arr[1]); //如果是指定的cookie，则返回它的值    
    }
    return "";
}

function delCookie(name)//删除cookie
{
    document.cookie = name + "=;expires=" + (new Date(0)).toGMTString();
}
//========================== 关闭当前页面开始 ==========================
//执行关闭网页
function SetClosePage(ShowText) {
    // 提示信息
    if (ShowText.toString().length > 0) {
        if (window.confirm(ShowText)) {
            window.close();
        }
    }
    else {
        window.close();
    }
}
//========================== 关闭当前页面结束 ==========================
//新闻Digg
function AjaxDigg(strType, strID) {
    if (getCookie("WebDigg") == strID) {
        alert("您已经评论过")
        return false;
    }
    var str = "<book>";
    str += "<mode>" + strType + "</mode>";
    str += "<id>" + strID + "</id>";
    str += "</book>"
    var ajax = new list("", str, "6");
    ajax.onSuccess = function () {
        if (strType == "up") {
            if (document.getElementById("up") != null)
                document.getElementById("up").innerHTML = "已顶过";
            addCookie("WebDigg", strID, "1")
            if (document.getElementById("CountUp") != null)
                document.getElementById("CountUp").innerHTML = ++document.getElementById("CountUp").innerHTML;
        } else {
            if (document.getElementById("down") != null)
                document.getElementById("down").innerHTML = "已踩过";
            addCookie("WebDigg", strID, "1")
            if (document.getElementById("CountDown") != null)
                document.getElementById("CountDown").innerHTML = ++document.getElementById("CountDown").innerHTML;
        }
    }
    ajax.Init();
}

//分享到QQ等
function share_message(div){
	var str = "";
	str = str + "		<table width=\"100%\" border=\"0\" align=\"left\" cellpadding=\"1\" style=\"border:1px solid #B3E7FF;background:#EEFAFF;\"><tr>";				
	str = str + "			<td style=\"font-weight:bold;color:#0066FF;\"><span style=\"float:center;padding-top:7px;padding-left:50px\">分享到：</span><span style=\"float:center;padding-top:5px;height:20px\">";
    str = str + "          	&nbsp;<a href=\"javascript:void((function(s,d,e){if(/xiaonei\.com/.test(d.location))return;var%20f='http://share.xiaonei.com/share/buttonshare.do?link=',u=d.location,l=d.title,p=[e(u),'&amp;title=',e(l)].join('');function%20a(){if(!window.open([f,p].join(''),'xnshare',['toolbar=0,status=0,resizable=1,width=626,height=436,left=',(s.width-626)/2,',top=',(s.height-436)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();})(screen,document,encodeURIComponent));\" ><img alt=\"分享到校内人人网\" src=\"/Images/Include/ico_renren.gif\" align=\"top\" border=\"0\"></a>";
    str = str + "          	&nbsp;<a href=\"javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(kaixin=window.open('http://www.kaixin001.com/~repaste/repaste.php?&amp;rurl='+escape(d.location.href)+'&amp;rtitle='+escape(d.title)+'&amp;rcontent='+escape(d.title),'kaixin'));kaixin.focus();\"><img alt=\"转贴到开心网\" src=\"/Images/Include/ico_kaixin.gif\" align=\"top\" border=\"0\"></a>";
    str = str + "          	&nbsp;<a style=\"color: rgb(0, 0, 0); text-decoration: none; font-size: 12px; font-weight: normal;\" href=\"javascript:window.open('http://v.t.sina.com.cn/share/share.php?title='+encodeURIComponent(document.title.substring(0,76))+'&amp;url='+encodeURIComponent(location.href)+'&amp;rcontent=','_blank','scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes'); void 0\"><img src=\"/Images/Include/ico_sina.gif\" alt=\"转发到新浪微博\" align=\"top\" border=\"0\"></a>";
    str = str + "          	&nbsp;<a title=\"分享到QQ空间\" href=\"javascript:void(window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url='+encodeURIComponent(document.location.href)));\"><img title=\"分享到QQ空间\" src=\"/Images/Include/ico_qzone.gif\" align=\"top\" border=\"0\"></a>";
	str = str + "			&nbsp;<a onclick=\"{var _t=encodeURI(document.title);var _url=encodeURI(window.location);var _appkey='f39b8bdb69614c44b11f0c3ab574314d';var _site=encodeURI;var _pic='';var _u='http://v.t.qq.com/share/share.php?title='+_t+'&amp;url='+_url+'&amp;appkey='+_appkey+'&amp;site='+_site+'&amp;pic='+_pic; window.open( _u,'转播到腾讯微博', 'width=700, height=580, top=180, left=320, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no' ); };\" href=\"javascript:void(0)\"><img title=\"分享到腾迅微博\" src=\"/Images/Include/ico_weibo.gif\" align=\"top\" border=\"0\"></a>";
	str = str + "			&nbsp;<a onclick=\"window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?to=pengyou&amp;url='+encodeURIComponent(document.location.href));return false;\" href=\"javascript:void(0)\"><img title=\"分享到腾迅朋友\" src=\"/Images/Include/ico_pengyou.gif\" align=\"top\" border=\"0\"></a>";
    str = str + "        	&nbsp;<a title=\"分享到网易微博\" href=\"javascript:(function(){window.open('http://t.163.com/article/user/checkLogin.do?link=http://news.163.com/&amp;info='+encodeURIComponent(document.title)+' '+encodeURIComponent(location.href),'_blank','width=510,height=300');})()\"><img title=\"分享到网易微博\" src=\"/Images/Include/ico_163.gif\" align=\"top\" border=\"0\"></a>";
	str = str + "			&nbsp;<a href=\"javascript:window.open('http://www.douban.com/recommend/?url='+encodeURIComponent(document.location.href)+'&amp;title='+encodeURIComponent(document.title));void(0)\" class=\"fav_douban\" rel=\"nofollow\"><img title=\"分享到豆瓣\" src=\"/Images/Include/ico_douban.gif\" align=\"top\" border=\"0\"></a>";
	str = str + "		</span></td></tr></table>";
	document.getElementById(div).innerHTML = str;
}

//打印页面_添加收藏_关闭页面
function Print_Home_Close(div){
	var str = "";
	str = str + "<a href=\"javascript:window.print();\" style=\"display:compact;background:url(/Images/Include/ico_print.gif) no-repeat;padding-left:22px;padding-bottom:5px;padding-top:4px;line-height:23px\">打印</a>\n";
	str = str + "&nbsp;&nbsp;\n";
	str = str + "<a href=\"javascript:AddFavorite(document.location.href,document.title);\" style=\"display:compact;background:url(/Images/Include/ico_add.gif) no-repeat;padding-left:22px;padding-bottom:5px;padding-top:4px;line-height:23px\">收藏</a>\n";
	str = str + "&nbsp;&nbsp;\n";
	str = str + "<a href=\"javascript:window.close();\" style=\"display:compact;background:url(/Images/Include/ico_close.gif) no-repeat;padding-left:22px;padding-bottom:5px;padding-top:2px;line-height:23px\">关闭</a>\n";
	document.getElementById(div).innerHTML = str;
}

//加入收藏
function AddFavorite(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

///**********************************新闻评论*****************************************************
function save() {
    if (getCookie("wbrefer") == document.getElementById("newsid").value) {
        window.alert("您不是已经提交过了嘛！");
        document.getElementById("userName").focus();
        return;
    }
    if (document.getElementById("userName").value == "" && document.getElementById("hasName").checked == false) {
        window.alert("请输入用户名!");
        document.getElementById("userName").focus();
        return;
    }
    if (document.getElementById("fcontent").value == "") {
        window.alert("请输入内容!");
        $("fcontent").focus();
        return;
    }
    // $("Result").innerHTML="提交成功";
    //	document.getElementById("myform").submit(); 
    //异步提交数据

    //var str="<book><name>"+$("userName").value +"</name><pass>"+ $("fcontent").value+"</pass></book>"
    var str = "<book>";
    str += "<typeid>" + document.getElementById("newsid").value + "</typeid>";
    str += "<name>" + document.getElementById("userName").value + "</name>";
    str += "<info>" + document.getElementById("fcontent").value + "</info>";
    str += "</book>";
    var ajax = new list("", str, "8");
    ajax.onSuccess = function () {
        if (xmlHttp.responseText == "ok") {
            // $("Result").innerHTML="提交成功";
            alert("评论成功");
            //document.cookie  = "wbrefer=1";
            addCookie("wbrefer", document.getElementById("newsid").value, "1")
        }
        else {
            // $("Result").innerHTML=="提交成功";
            alert("评论");
        }
    }
    ajax.Init();
}

function getCookie(objName) {//获取指定名称的cookie的值
    var arrStr = document.cookie.split("; ");
    for (var i = 0; i < arrStr.length; i++) {
        var temp = arrStr[i].split("=");
        if (temp[0] == objName) return unescape(temp[1]);
    }
}

function addCookie(objName, objValue, objHours) {      //添加cookie
    var str = objName + "=" + escape(objValue);
    if (objHours > 0) {                               //为0时不设定过期时间，浏览器关闭时cookie自动消失
        var date = new Date();
        var ms = objHours * 3600 * 1000;
        date.setTime(date.getTime() + ms);
        str += "; expires=" + date.toGMTString();
    }
    document.cookie = str;
}


function checkclick() {
    if (document.getElementById("hasName").checked == true) {
        document.getElementById("userName").value = "匿名用户"
    }
    else {
        document.getElementById("userName").value = ""
    }
}

function checkSMSMessage() {
    var content = document.getElementById("fcontent").value;
    document.getElementById("leaveCount").innerText = 120 - content.length;
    if (content.length >= 120) {
        document.getElementById("fcontent").value = content.substring(0, 120);
    }
}

function setLeaveCount() {
    window.setTimeout('checkSMSMessage()', 100);
}

///**********************************END**************************************************


/// <summary>
/// 获取模板
/// </summary>
/// <param name="parame">传递的参数</param>
/// <param name="ID">服务器处理程序</param>
/// <returns></returns>
function list(parame, xmldom, ID) {

    // 判断浏览器的类型
    if (document.implementation && document.implementation.createDocument) {
        // 支持Mozilla浏览器
        try {
            var oParser = new DOMParser();
            var xmlDoc = oParser.parseFromString(xmldom, "text/xml");
        }
        catch (e) {
            alert("error:001");
        }
    }
    else if (typeof window.ActiveXObject != 'undefined') {
        //var xmlDoc=Server.CreateObject("Msxml2.DOMDocument.4.0");        
        // 支持IE浏览器
        xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
        xmlDoc.async = false;
        xmlDoc.loadXML(xmldom);
    }
    else {
        alert("Browser unknown!");
    }
    var thisTHost = top.location.host;
    var obj = this;
    this.Init = function () {
        xmlHttp = false;
        if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();  //　非IE　浏览器
            if (!xmlHttp) {
                alert("创建 XMLHttpRequest 对象失败!");
            }
        }
        else if (window.ActiveXObject) {
            try { //IE
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); //较新版本的IE
            }
            catch (e) {
                try {
                    xmlHttp = new ActiveXOBject("Microsoft.XMLHTTP"); //旧版本IE
                }
                catch (e) {
                    //alert("error:002");
                }
            }
        }
        else {
            window.alert("不能创建　XMLHttpRequest对象，无法应用Ajax");
            return false;
        }
        var url = "http://" + thisTHost + "/Control/Ajax.ashx?"
        url += parame + "&ID=" + ID;
        xmlHttp.open("POST", url, false);
        xmlHttp.onreadystatechange = function () {
            if (xmlHttp.readyState == 4) {
                if (xmlHttp.status == 200) {
                    obj.onSuccess();
                }
            }
        }
        xmlHttp.send(xmlDoc);
    }
}



function insert_page(tag, id) {
    var myField;
    myField = document.getElementById(id);
    if (document.selection) {
        myField.focus();
        sel = document.selection.createRange();
        sel.text = tag;
        myField.focus();
    } else if (myField.selectionStart || myField.selectionStart == '0') {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        var cursorPos = endPos;
        myField.value = myField.value.substring(0, startPos)
            + tag
            + myField.value.substring(endPos, myField.value.length);
        cursorPos += tag.length;
        myField.focus();
        myField.selectionStart = cursorPos;
        myField.selectionEnd = cursorPos;
    } else {
        myField.value += tag;
        myField.focus();
    }
}

function BindBarMore(num,obj,name){
    var len = obj.parentNode.getElementsByTagName("span").length;
    for(var i=0;i<len;i++){
        obj.parentNode.getElementsByTagName("span")[i].className = "bar_03_span";
    }
    obj.className = "bar_03_spaned";
    for(var i=0;i<len;i++){
        document.getElementById(name+i).style.display = "none";
    }
    document.getElementById(name+num).style.display = "";
}


function checktoplogin() {
    if (cookie("LoginName") != "" && cookie("LoginName") != null) {
        var str = "";
        str = str + "<li><font color=\"#FF0000\">"+ cookie("LoginName") +"</font> 您好，欢迎您来到中国展会网！</li>";
        str = str + "<li><a style=\"color:#FF7300\" href=\"/member/Index.aspx\">&nbsp;&nbsp;后台管理中心</a></li>";
        str = str + "<li>　<a style=\"color:#FF7300\" href=\"\" onclick='delCookie(\"LoginName\")'>安全退出</a></li>";
        str = str + "<li>　<a href=\"/search/solely.aspx?url=Contact\" target=\"_blank\">帮助中心</a></li>";
        document.getElementById("toploginmessage").innerHTML = str;
    }
}
