﻿// Search
function search()
{
    if(document.getElementById("key").value=="")
    {
        alert('请输入搜索关键字！');
        document.getElementById("key").focus();
        return false;
    }
    location.href = "/search/" + document.getElementById("key").value + "/";
}

// User
function user()
{
    var str = "";
    var this_url = window.location.href;
    var userinfo = unescape(getUCookie("ps_userinfo"));
    if(userinfo != "undefined"){
        tempinfo = new Array();
        tempinfo = userinfo.split("$");
        str = "<a href='/user/" + tempinfo[2] + "/' style='font-weight:bold;color:blue;'>" + tempinfo[0] + "</a> |  <a href='/ucenter/'>会员中心</a> | <a href='/ucenter/logout/?return_url=" + this_url + "'>退出</a>";
    }else{
        str = "<a href='/ucenter/login/?return_url=" + this_url + "'>登录</a> | <a href='/ucenter/register/?return_url=" + this_url + "'>注册</a> | <a href='/help/04.html' target='_blank'>帮助</a>";
    }    
    document.write(str);
}

// Check Comment
function checkcomment()
{
    var comment = document.getElementById("content").value;
    if(comment == "")
    {
        alert('请输入评论内容！');
        document.getElementById("content").focus();
        return false;
    }
    var strlen = getstrlen(comment);
    if(strlen < 10)
    {
        alert('评论内容不得少于10个字符(即5个汉字)！');
        document.getElementById("content").focus();
        return false;
    }
}
function getstrlen(s)
{
    var l = 0;
    var a = s.split("");
    for(var i = 0; i<a.length; i++)
    {
        if(a[i].charCodeAt(0) < 299)
        {
            l++;
        }else{
            l+=2;
        }
    }
    return l;
} 


// setUCookie
function setUCookie(objName,value)
{
 	if(!objName || !value){
 		throw new Error("setUCookie(objName,value) 参数必须");
 	}
 	var exp = new Date();
    exp.setTime(exp.getTime() + 6*60*60*1000);
    document.cookie = objName + "="+ escape(value) +";expires=" + exp.toGMTString() + ";path=/"; 	
}

// getUCookie
function getUCookie(objName)
{
    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 site_js(){site_cont();search_text();search_select();}
function site_cont(){
    var str = "";
    var this_url = window.location.href;
    
    username = unescape(getUCookie("ps_username"));

    if(username != "undefined"){
        str = "<a href='/bbs/space.php?username="+username+"' style='font-weight:bold;color:blue;'>"+username+"</a> | <a href='/ucenter/login.php?action=logout&return_url="+this_url+"'>退出</a> | <a href='/ucenter/'>会员中心</a> | <a href='/'>首页</a> | <a href='/bbs/'>论坛</a>";
    }else{
        str = "<a href='/ucenter/login.php?action=login&return_url="+this_url+"'>登录</a> | <a href='/ucenter/login.php?action=register&return_url="+this_url+"'>注册</a> | <a href='/help/index.html' target='_blank'>帮助</a> | <a href='/'>首页</a> | <a href='/bbs/'>论坛</a> | <a href='/sitemap/' target='_blank'>导航</a>";
    }    
    document.getElementById("cont").innerHTML = str;
}
// setCopy
function setCopy(_sTxt){
	var url=parent.location.href;
	sTxt = _sTxt + "\n" + url;
	try{clipboardData.setData('Text',sTxt)}catch(e){}
	alert('页面地址已经复制到剪贴板,\n请用粘贴或Ctrl+V发给你的MSN/QQ好友吧!');
}
// addBookmark
function addBookmark(title) {
	var url=parent.location.href;
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,""); 
	} else if( document.all ) {
		window.external.AddFavorite( url, title);
		} else if( window.opera && window.print ) {
			return true;
	}
}


// setUCookie
function setUCookie(objName,value)
{
 	if(!objName || !value){
 		throw new Error("setUCookie(objName,value) 参数必须");
 	}
 	var exp = new Date();
    exp.setTime(exp.getTime() + 6*60*60*1000);
    document.cookie = objName + "="+ escape(value) +";expires=" + exp.toGMTString() + ";path=/"; 	
}

// getUCookie
function getUCookie(objName)
{
    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]);
    }
}

// SiteNav
openMenu = function(AllNav){var getEls = document.getElementById(AllNav).getElementsByTagName("li");for (var i=0; i<getEls.length; i++){getEls[i].onmouseover=function(){this.className+="shownav";};getEls[i].onmouseout=function(){this.className=this.className.replace("shownav","");}}}




// Foucs
function index_focus(){var str = "<object data='/images/focus/focus.swf?bcastr_xml_url=/images/focus/focus_index.xml' type='application/x-shockwave-flash' width='426' height='246'><param name='movie' value='/images/focus/focus.swf?bcastr_xml_url=/images/focus/focus_index.xml' /></object>";document.getElementById("index_focus").innerHTML = str;}

// Functions
var k167={$:function(objName){if(document.getElementById){return eval('document.getElementById("'+objName+'")')}else{return eval('document.all.'+objName)}},isIE:navigator.appVersion.indexOf("MSIE")!=-1?true:false,addEvent:function(l,i,I){if(l.attachEvent){l.attachEvent("on"+i,I)}else{l.addEventListener(i,I,false)}},delEvent:function(l,i,I){if(l.detachEvent){l.detachEvent("on"+i,I)}else{l.removeEventListener(i,I,false)}},readCookie:function(O){var o="",l=O+"=";if(document.cookie.length>0){var i=document.cookie.indexOf(l);if(i!=-1){i+=l.length;var I=document.cookie.indexOf(";",i);if(I==-1)I=document.cookie.length;o=document.cookie.substring(i,I)}};return o},writeCookie:function(i,l,o,c){var O="",I="";if(o!=null){O=new Date((new Date).getTime()+o*3600000);O="; expires="+O.toGMTString()};if(c!=null){I=";domain="+c};document.cookie=i+"="+escape(l)+O+I},readStyle:function(I,l){if(I.style[l]){return I.style[l]}else if(I.currentStyle){return I.currentStyle[l]}else if(document.defaultView&&document.defaultView.getComputedStyle){var i=document.defaultView.getComputedStyle(I,null);return i.getPropertyValue(l)}else{return null}},absPosition:function(o,I){var l=o.offsetLeft,O=o.offsetTop,i=o.offsetParent,c="";try{while(i.id!=document.body&&i.id!=document.documentElement&&i!=I&&i!=null){c+=i.tagName+" , ";i=i.offsetParent;l+=i.offsetLeft;O+=i.offsetTop}}catch(e){};return{left:l,top:O}},cutString:function(I,o){if(typeof(I)!="string"){return null};if(!(/^[0-9]*[1-9][0-9]*$/).test(o)){return I};if(o==0){return I};var l=0,i="";for(var O=0;O<I.length;O++){if(I.charCodeAt(O)>255){l+=2}else{l++};if(l<=o-2){i+=I.charAt(O)}else{if(O==I.length-1){i+=I.charAt(O)}else{i+=".."};break}};return i}};
function DivSelect(o,I){var c=this;c.id=o;c.divId=I;c.selectObj=k167.$(c.id);if(!c.selectObj){return};var l=c;c.status="close";c.parentObj=c.selectObj.parentNode;while(k167.readStyle(c.parentObj,"display")!="block"){if(c.parentObj.parentNode){c.parentObj=c.parentObj.parentNode}else{break}};c.parentObj.style.position="relative";c.selectObjWidth=c.selectObj.offsetWidth;c.selectObjHeight=c.selectObj.offsetHeight;c.selectPosition=k167.absPosition(c.selectObj,c.parentObj);c.selectObj.style.visibility="hidden";c.divObj=document.createElement("div");c.divObj.id=c.divId;c.parentObj.appendChild(c.divObj);c.divObj.style.width=c.selectObjWidth+"px";c.divObj.style.position="absolute";c.divObj.style.left=c.selectPosition.left+"px";c.divObj.style.top=c.selectPosition.top+"px";c.divObj.onclick=function(){l.click()};c.divObj_count=document.createElement("div");c.divObj.appendChild(c.divObj_count);c.divObj_count.className="ds_cont";c.divObj_title=document.createElement("div");c.divObj_count.appendChild(c.divObj_title);c.divObj_title.className="ds_title";c.divObj_button=document.createElement("div");c.divObj_count.appendChild(c.divObj_button);c.divObj_button.className="ds_button";c.divObj_list=document.createElement("div");c.divObj.appendChild(c.divObj_list);c.divObj_list.className="ds_list";c.divObj_list.style.display="none";c.list=[];var i;for(var O=0;O<c.selectObj.options.length;O++){i=document.createElement("p");c.list.push(i);c.divObj_list.appendChild(i);i.innerHTML=c.selectObj.options[O].innerHTML;if(c.selectObj.selectedIndex==O){c.divObj_title.innerHTML=i.innerHTML};i.onmouseover=function(){this.className="selected"};i.onmouseout=function(){this.className=""};i.onclick=function(){l.select(this.innerHTML)}};c.select=function(i){var l=this;for(var I=0;I<l.selectObj.options.length;I++){if(l.selectObj.options[I].innerHTML==i){l.selectObj.selectedIndex=I;l.divObj_title.innerHTML=i;break}}};c.clickClose=function(I){var i=I.target?I.target:event.srcElement;do{if(i==l.divObj){return};if(i.tagName=="BODY"){break};i=i.parentNode}while(i.parentNode);l.close()};c.open=function(){var i=this;i.divObj_list.style.display="block";i.status="open";k167.addEvent(document,"click",i.clickClose)};c.close=function(){var i=this;i.divObj_list.style.display="none";i.status="close";k167.delEvent(document,"click",i.clickClose)};c.click=function(){var i=this;if(i.status=="open"){i.close()}else{i.open()}}};

// switchTabs
function switchTabs(tabNum,parentId){var tabs = document.getElementById(parentId.id).getElementsByTagName('li');var boxId = parentId.parentNode.id;for (var i = 0; i < tabs.length; i++){var thisTab = tabs[i];if ((thisTab.id != '')){document.getElementById(boxId+'_content'+i).style.display = 'none';if (i == tabNum){if (i == 0){thisTab.className = 'on first';}else{thisTab.className = 'on';}document.getElementById(boxId+'_content'+i).style.display = 'block';}else{thisTab.className = '';}}}}

// Away
function $(id){ return document.getElementById(id)}
function away(num){var MenuButton=$("MenuButton_"+num);var Cont=$("Cont_"+num);var buttonMenu;buttonMenu=MenuButton.className;if ( buttonMenu=="start"){Cont.style.display="none";MenuButton.className='away';}else if(buttonMenu=="away"){MenuButton.className='start';Cont.style.display="block";}}

// AjaxObject
function GetXmlHttpObject(handler)
{ 
	var objXmlHttp=null;	
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP";
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP";
		} 
		try
		{   
			objXmlHttp=new ActiveXObject(strName);
			objXmlHttp.onreadystatechange=handler; 
			return objXmlHttp;
		} 
		catch(e)
		{ 
			alert("Error. Scripting for ActiveX might be disabled");
			return;
		} 
	}
	else
	{
		objXmlHttp=new XMLHttpRequest();
		objXmlHttp.onload=handler;
		objXmlHttp.onerror=handler;
		return objXmlHttp;
	}
}

// get_showComment
function get_showComment(n){
    document.getElementById("commentlist").innerHTML = "<div>评论载入中...</div>";
    var getID = escape(document.getElementById("comment-id").value);
    var channelID = escape(document.getElementById("comment-channelid").value);
    var ajaxUrl = "/ajaxComment.asp?page="+n+"&id="+getID+"&channelid="+channelID;
	xmlHttp=GetXmlHttpObject(get_Commentlist);
	xmlHttp.open("GET",ajaxUrl,true);
	xmlHttp.send(null);
}

// get_Commentlist
function get_Commentlist(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){   
	    document.getElementById("commentlist").innerHTML = "";
	    
	    // Get Comment DATA
		xmlOrder = xmlHttp.responseXML.getElementsByTagName("Order");
		xmlAuthor = xmlHttp.responseXML.getElementsByTagName("Author");
		xmlContent = xmlHttp.responseXML.getElementsByTagName("Content");
		xmlPostTime = xmlHttp.responseXML.getElementsByTagName("PostTime");
		xmlAuthorIP = xmlHttp.responseXML.getElementsByTagName("AuthorIP");

        // Output Comment
		for(i=0;i<xmlContent.length;i++){
		    var Content = xmlContent[i].firstChild.data;
		    var div = document.createElement("ul");
            div.id = i;
		    if(Content == "没有评论"){
			    div.innerHTML = "还没有发表评论!"
		    }else{
		        var Order = xmlOrder[i].firstChild.data;
		        var Author = xmlAuthor[i].firstChild.data;
		        var PostTime = xmlPostTime[i].firstChild.data;
		        var AuthorIP = xmlAuthorIP[i].firstChild.data;
		        if(Author != "书源网友"){
		            userUrl = "/bbs/space.php?username="+Author+"";
		        }else{
		            userUrl = "/bbs/";
		        }
		        div.innerHTML = "<li><h2><b>第"+Order+"楼</b> <a href='"+userUrl+"' target='_blank'>"+Author+"</a> 在 "+PostTime+" 发表评论：</h2><div class='c'>"+Content+"</div></li>";
		    }
            document.getElementById("commentlist").appendChild(div);
		}
		
		// Output PagePath
		P_Nums = xmlHttp.responseXML.getElementsByTagName("data")[0].getAttribute('P_Nums');
		if (P_Nums>1) {
	    	var page = xmlHttp.responseXML.getElementsByTagName("data")[0].getAttribute('page');
		    var D_Nums = xmlHttp.responseXML.getElementsByTagName("data")[0].getAttribute('D_Nums');
		    var l1 = "<a class='total'>Total:&nbsp;"+D_Nums+"&nbsp;</a>"
			var l2 = "";
			for (var i =1;i<=P_Nums;i++) {
			     l2 += (i == page)?"<a class='curpage'>"+i+"</a>":"<a href='javascript:get_showComment("+i+")' class='num'>"+i+"</a>"
			}
			document.getElementById("multipage").innerHTML = l1+l2;
		}
    }
}

// SaveComment
function SaveComment(){
    var getID = escape(document.getElementById("comment-id").value);
    var content = escape(document.getElementById("comment-content").value);
    var channelID = escape(document.getElementById("comment-channelid").value);
 	content = content.replace(/\+/g,"%2B");
    var username = getCookie("ps_username");
    if(username == null){username = "书源网友";}

    if(content == ""){
	    alert("请填写评论内容！");
	    document.getElementById("comment-content").focus()
		return false;
	}else if(content.length<5){
		alert("请勿灌水，你的评论内容须超过5字！")
	    document.getElementById("comment-content").focus()
		return false;
	}else if(content.length>5000){
		alert("你的评论内容不能超过5000字！")
	    document.getElementById("comment-content").focus()
		return false;
	}
 
    // Save Comment
    var ajaxComment = "action=save&username="+username+"&callid="+getID+"&channelid="+channelID+"&content="+content;
	addComment = GetXmlHttpObject(sendData);
    addComment.open("POST","/ajaxComment.asp",false); 
    addComment.setRequestHeader("Content-Type","application/x-www-form-urlencoded") 
    addComment.send(ajaxComment);
    alert("发表成功！");
}

// get_showHits
function get_showHits(){
    var xmlHits;
    var getID = escape(document.getElementById("comment-id").value);
    var channelID = escape(document.getElementById("comment-channelid").value);
    var ajaxUrl = "channelid="+channelID+"&callid="+getID;
	xmlHits = GetXmlHttpObject(sendXml);
    xmlHits.open("POST","/ajaxHits.asp",false);
    xmlHits.setRequestHeader("Content-Type","application/x-www-form-urlencoded") 
    xmlHits.send(ajaxUrl);
	xmlHits = xmlHits.responseXML.getElementsByTagName("ajaxHits")
    document.getElementById("ajax-hits").innerHTML = xmlHits[0].firstChild.data;
}

// UpdateHits
function updateHits()
{
    var xmlHits;
    var getID = escape(document.getElementById("comment-id").value);
    var ajaxUrl = "channelid=10000&callid="+getID;
	xmlHits = GetXmlHttpObject(sendXml);
    xmlHits.open("POST","/ajaxHits.asp",false);
    xmlHits.setRequestHeader("Content-Type","application/x-www-form-urlencoded") 
    xmlHits.send(ajaxUrl);
}

// sendXml
function sendXml(){}
// sendData
function sendData(){document.getElementById("comment-content").value = "";get_showComment(1);}

// getCookie
function getCookie(objName){
    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]);
    }
}

// set_innerHTML
var global_html_pool = [];   
var global_script_pool = [];   
var global_script_src_pool = [];   
var global_lock_pool = [];   
var innerhtml_lock = null;   
var document_buffer = "";   
  
function set_innerHTML(obj_id, html, time) {   
    if (innerhtml_lock == null) {   
        innerhtml_lock = obj_id;   
    }   
    else if (typeof(time) == "undefined") {   
        global_lock_pool[obj_id + "_html"] = html;   
        window.setTimeout("set_innerHTML('" + obj_id + "', global_lock_pool['" + obj_id + "_html']);", 10);   
        return;   
    }   
    else if (innerhtml_lock != obj_id) {   
        global_lock_pool[obj_id + "_html"] = html;   
        window.setTimeout("set_innerHTML('" + obj_id + "', global_lock_pool['" + obj_id + "_html'], " + time + ");", 10);   
        return;   
    }   
  
    function get_script_id() {   
        return "script_" + (new Date()).getTime().toString(36)   
        + Math.floor(Math.random() * 100000000).toString(36);   
    }   
  
    document_buffer = "";   
  
    document.write = function (str) {   
        document_buffer += str;   
    }   
    document.writeln = function (str) {   
        document_buffer += str + "\n";   
    }   
  
    global_html_pool = [];   
  
    var scripts = [];   
    html = html.split(/<\/script>/i);   
    for (var i = 0; i < html.length; i++) {   
        global_html_pool[i] = html[i].replace(/<script[\s\S]*$/ig, "");   
        scripts[i] = {text: '', src: '' };   
        scripts[i].text = html[i].substr(global_html_pool[i].length);   
        scripts[i].src = scripts[i].text.substr(0, scripts[i].text.indexOf('>') + 1);   
        scripts[i].src = scripts[i].src.match(/src\s*=\s*(\"([^\"]*)\"|\'([^\']*)\'|([^\s]*)[\s>])/i);   
        if (scripts[i].src) {   
            if (scripts[i].src[2]) {   
                scripts[i].src = scripts[i].src[2];   
            }   
            else if (scripts[i].src[3]) {   
                scripts[i].src = scripts[i].src[3];   
            }   
            else if (scripts[i].src[4]) {   
                scripts[i].src = scripts[i].src[4];   
            }   
            else {   
                scripts[i].src = "";   
            }   
            scripts[i].text = "";   
        }   
        else {   
            scripts[i].src = "";   
            scripts[i].text = scripts[i].text.substr(scripts[i].text.indexOf('>') + 1);   
            scripts[i].text = scripts[i].text.replace(/^\s*<\!--\s*/g, "");   
        }   
    }   
  
    var s;   
    if (typeof(time) == "undefined") {   
        s = 0;   
    }   
    else {   
        s = time;   
    }   
  
    var script, add_script, remove_script;   
  
    for (var i = 0; i < scripts.length; i++) {   
        var add_html = "document_buffer += global_html_pool[" + i + "];\n";   
        add_html += "document.getElementById('" + obj_id + "').innerHTML = document_buffer;\n";   
        script = document.createElement("script");   
        if (scripts[i].src) {   
            script.src = scripts[i].src;   
            if (typeof(global_script_src_pool[script.src]) == "undefined") {   
                global_script_src_pool[script.src] = true;   
                s += 2000;   
            }   
            else {   
                s += 10;   
            }   
        }   
        else {   
            script.text = scripts[i].text;   
            s += 10;   
        }   
        script.defer = true;   
        script.type =  "text/javascript";   
        script.id = get_script_id();   
        global_script_pool[script.id] = script;   
        add_script = add_html;   
        add_script += "document.getElementsByTagName('head').item(0)";   
        add_script += ".appendChild(global_script_pool['" + script.id + "']);\n";   
        window.setTimeout(add_script, s);   
        remove_script = "document.getElementsByTagName('head').item(0)";   
        remove_script += ".removeChild(document.getElementById('" + script.id + "'));\n";   
        remove_script += "delete global_script_pool['" + script.id + "'];\n";   
        window.setTimeout(remove_script, s + 10000);   
    }   
  
    var end_script = "if (document_buffer.match(/<\\/script>/i)) {\n";   
    end_script += "set_innerHTML('" + obj_id + "', document_buffer, " + s + ");\n";   
    end_script += "}\n";   
    end_script += "else {\n";   
    end_script += "document.getElementById('" + obj_id + "').innerHTML = document_buffer;\n";   
    end_script += "innerhtml_lock = null;\n";   
    end_script += "}";   
    window.setTimeout(end_script, s);   
}  
