﻿var nt=null;
var Jsurl=location.search; 	var JsRequest = new Object(); 
if(Jsurl.indexOf("?")!=-1) { 
	var str = Jsurl.substr(1); 
	var strs = str.split("&"); 
	for(var i=0;i<strs.length;i++) { 
		JsRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]); 
	} 
} 
function clearNotice(){
	if(nt!=null) nt.clear();
}
var listid=null;
var bkpzid=null;
var bkid=null;
var bkwzid=null;
var qishu=null;
var bkmc=null;
function loadData(){
	listid = JsRequest['listid'];
	updateInfo(listid);
	$('commentbutton').onclick=commentSend;
	Event.observe($('mycomment'),'keydown',keySubmit);
	kf();
}
function updateInfo(_listid){
	new Ajax.Request('behind/book_intro_info.aspx?listid='+_listid,{method:'get',onComplete:Complete,onFailure:Failure});
	function Failure(ccc){
		alert(ccc.responseText);
	}
	function Complete(ccc){
		var thisXml = ccc.responseXML;
		var free = elementAttrib(thisXml.selectNodes('/root')[0],'free');
		var info = thisXml.selectNodes('//root/info')[0];
		var imgurl='/bookcover/'+elementAttrib(info,'bkdz')+'fm.jpg';
		bkpzid=elementAttrib(info,'bkpzid');
		qishu=elementAttrib(info,'qishu');
		bkid=elementAttrib(info,'bkid');
		bkwzid = elementAttrib(info,'bkwzid');
		bkmc=elementAttrib(info,'bkmc');
		var type=elementAttrib(info,'type');
		var sortcode=elementAttrib(info,'sortcode');
		var readdate=elementAttrib(info,"readdate");
		var ss=elementAttrib(info,"update").split(' ')[0].split('-');
		var d=new Date(ss[0],ss[1]-1,ss[2]-(-1));
		var dd=new Date();
		if(readdate == "ok"||d.toDateString()==dd.toDateString()){
			var yuedu='<span style="margin:0px 4px 0px 4px;">'+(type.indexOf('M')==-1?'<img src="'+'/education/comm/dmt-tubiao1-1.gif'+'">':'<img onclick="openMBook(\''+bkid+'\')" style="cursor:pointer" src="'+'/education/comm/dmt-tubiao1.gif'+'">')+'</span>';
			yuedu+=type.indexOf('E')==-1?'<img src="'+'/education/comm/dzb-tubiao1-1.gif'+'">':'<img onclick="openEBook(\''+bkwzid+'\')" style="cursor:pointer" src="'+'/education/comm/dzb-tubiao1-1.gif'+'">';
			var tmp='<a class="bigimg" style="margin:2px;"><img onclick="'+(type.indexOf('M')==-1? 'openEBook(\''+bkwzid+'\')': 'openMBook(\''+bkid+'\')')+'" style="cursor:pointer;" src="'+imgurl+'"><span>'+qishu+'</span></a>';
		}
		else{
			var yuedu= readdate;		
			var tmp='<a class="bigimg" style="margin:2px;"><img style="cursor:pointer;" src="'+imgurl+'"><span>'+qishu+'</span></a>';
		}
		
		$('navigation').innerHTML='您当前的位置&#8250;&#8250; <a href="/education" style="color:black;">教学频道首页</a> &#8250;&#8250 <a style="color:black;" href="/education/sortview.aspx?sort='+elementAttrib(info,'sortcode')+'">'+elementAttrib(info,'sort')+'</a> &#8250;&#8250 '+bkmc;

		tmp+='<div style="float:left;width:490px;"><p style="height:18px;margin:2px;border-bottom:solid 1px;font-size:14px;">报刊信息</p>';
		tmp+='<p class="inforow"><span class="infolabel">报刊名称:</span>'+bkmc+'</p>';
		tmp+='<p class="inforow"><span class="infolabel">刊期:</span>'+elementAttrib(info,'kq')+'</p>';
	//	tmp+='<p class="inforow"><span class="infolabel">在线阅读价:</span>'+(free==listid? '<strong style="color:red">免费</strong>': '1.00元/本')+'</p>';
		tmp+='<p class="inforow"><a href="/zhifuzhongxin/byfw.aspx" target="_blank"><img style="margin: 0px 2px 0px 2px;vertical-align: middle;" src="/education/comm/by-tubiao.gif"></a><a href="/zhifuzhongxin/bnfw.aspx" target="_blank"><img style="margin: 0px 2px 0px 2px;vertical-align: middle;" src="/education/comm/bn-tubiao.gif"></a>报刊任你看！</p>';
		tmp+='<p class="inforow"><span class="infolabel">实物订阅价:</span>'+elementAttrib(info,'dj')+'<span style="margin-left:20px;"><a href="/dybk/dybkbz1.aspx?bkpzid='+bkpzid+'" target="_blank"><img src="/education/comm/dy-tb.jpg" border=0></a></span>'+'</p>';
		tmp+='<p class="inforow"><span class="infolabel">邮发代号:</span>'+elementAttrib(info,'yfdh')+'</p>';
		tmp+='<p class="inforow"><span class="infolabel">统一刊号:</span>'+elementAttrib(info,'tykh')+'</p>';
		tmp+='<p class="inforow"><span class="infolabel">阅读次数:</span>'+elementAttrib(info,'hits1')+'/累计</p>';
		tmp+='<p class="inforow"><span class="infolabel">更新日期:</span>'+elementAttrib(info,'update')+'</p>';
		tmp+='<p class="inforow"><span class="infolabel">在线阅读:</span>'+yuedu+'<a href="/education/book_intro.aspx?listid='+free+'"><img style="margin: 0px 2px 0px 2px;" src="/popular/comm/free.gif"></a></p>';
		tmp+='<p class="inforow"><span class="infolabel"></span>'+'<a href="javascript:void(0);" onclick="AddBookStore(\''+listid+'\',\''+bkid+'\',\''+bkwzid+'\',\''+bkmc+'\',\''+qishu+'\')">[ 放入书架 ]</a>'+'<a href="/popular/ksxx.aspx?bkpzid'+bkpzid+'">[ 刊社信息 ]</a>'+'<a href="javascript:void(0);" onclick="toFriend()">[ 推荐给好友 ]</a>'+'</p>';
		tmp+='</div>';
		new Insertion.Bottom($('info'),tmp);
		var optype = 'M';
		var mllist = thisXml.selectNodes('//root/bkmllist/row');
		if(mllist.length==0){
			mllist = thisXml.selectNodes('//root/bkwzmllist/row');
			optype = 'E';
		}
		tmp='';
		if(readdate == "ok"){
		if (optype=='M'){
			for(var i=0;i<mllist.length;i++){
				tmp+='<p class="inforow"><a href="javascript:void(0);" onclick="openMBook('+'\''+bkid+'\',\''+elementAttrib(mllist[i],'page')+'\''+')" style="padding:0px 0px 0px 4px;">'+elementAttrib(mllist[i],'title')+'</a></p>'
			}
		}
		else{
			for(var i=0;i<mllist.length;i++){
				//tmp+='<p class="inforow"><a target="_blank" href="/education/Ebook.aspx?id='+bkwzid+'&page='+i+'&name='+escape(bkmc)+'" style="padding:0px 0px 0px 4px;">'+elementAttrib(mllist[i],'title')+'</a></p>'
				tmp+='<p class="inforow"><a href="javascript:openEBook(\''+bkwzid+'\',\''+i+'\')" style="padding:0px 0px 0px 4px;">'+elementAttrib(mllist[i],'title')+'</a></p>'
			}
		}
		}
		else{
			for(var i=0;i<mllist.length;i++){
				tmp+='<p class="inforow"><a href="javascript:void(0);" onclick="alert(\''+readdate+'\')" style="padding:0px 0px 0px 4px;">'+elementAttrib(mllist[i],'title')+'</a></p>'
			}

		}
		Element.update($('mllist'),tmp);
		
		updateOldBooks(bkpzid,1);
		updateComment(bkpzid,1);
		updateRelation(sortcode);
		updateCW();
	}
}
var oldbookpage=1;
var oldbookpages=1;
function updateOldBooks(_bkpzid,_page){
	oldbookpage = _page;
	new Ajax.Request('behind/book_intro_old.aspx?bkpzid='+_bkpzid+'&pagesize=14&page='+_page,{method:'get',onComplete:Complete,onFailure:Failure});
	function Failure(ccc){
		alert(ccc.responseText);
	}
	function Complete(ccc){
		var thisXml = ccc.responseXML;
		var root=thisXml.selectNodes('//root')[0];
		var pages=elementAttrib(root,'pages');
		var counts=elementAttrib(root,'counts');
		oldbookpages=pages;
		Element.update($('oldbookpages'),'<span style="margin:0px 4px 0px 4px;">共有'+counts+'本</span>'+'<span style="font-size:12px;margin:0px 4px 0px 4px;">14本/页</span>'+'<span style="font-size:12px;margin:0px 4px 0px 4px;">第'+_page+'页/共'+pages+'页</span>'+'<span style="font-size:12px;margin:0px 4px 0px 4px;"><a style="font-size:12px;" href="javascript:void(0);" onclick="oldbookFirst()">首页</a></span>'+'<span style="font-size:12px;margin:0px 4px 0px 4px;"><a style="font-size:12px;" href="javascript:void(0);" onclick="oldbookPrev()">上页</a></span>'+'<span style="font-size:12px;margin:0px 4px 0px 4px;"><a style="font-size:12px;" href="javascript:void(0);" onclick="oldbookNext()">下页</a></span>'+'<span style="font-size:12px;margin:0px 4px 0px 4px;"><a style="font-size:12px;" href="javascript:void(0);" onclick="oldbookLast()">尾页</a></span>');
		var tmp='';
		var rows=thisXml.selectNodes('//root/row');
		for(var i=0;i<rows.length;i++){
			tmp+='<a href="/education/book_intro.aspx?listid='+elementAttrib(rows[i],'listid')+'" class="smallimg" style="margin:4px;"><img src="'+'/bookcover/'+elementAttrib(rows[i],'bkdz')+'fs.jpg"><span>'+elementAttrib(rows[i],'qishu')+'</span></a>';
		}
		Element.update($('old'),tmp);
	}
}
function oldbookNext(){
	if(oldbookpage<oldbookpages){
		oldbookpage++;
		updateOldBooks(bkpzid,oldbookpage);
	}
}
function oldbookPrev(){
	if(oldbookpage>1){
		oldbookpage--;
		updateOldBooks(bkpzid,oldbookpage);
	}
}
function oldbookFirst(){
	oldbookpage=1;
	updateOldBooks(bkpzid,oldbookpage);
}
function oldbookLast(){
	oldbookpage=oldbookpages;
	updateOldBooks(bkpzid,oldbookpage);
}

function updateComment(_bkpzid,_page){
	var pd='bkpzid='+_bkpzid+'&pagesize=4&page='+_page;
	new Ajax.Request('/popular/behind/loadcomment.aspx',{method:'post',postBody:pd,onComplete:Complete,onFailure:Failure});
	function Failure(ccc){
		alert(ccc.responseText);
	}
	function Complete(ccc){
		var thisXml = ccc.responseXML;
		var root=thisXml.selectNodes('//root')[0];
		var pages=elementAttrib(root,'pages');
		var counts=elementAttrib(root,'counts');
		var rows=thisXml.selectNodes('//root/row');
		var tmp='';
		for(var i=0;i<rows.length;i++){
			tmp+='<p class="inforow" style="width:680px; overflow: hidden; white-space: nowrap;"><span style="margin:0px 8px 0px 2px;">'+elementAttrib(rows[i],'date')+'</span>网友: '+elementAttrib(rows[i],'user')+'</p>';
			tmp+='<p class="inforow" style="width:680px; overflow: hidden; white-space: nowrap;"><span style="margin:0px 8px 0px 10px;">'+elementData(rows[i]).truncate(50)+'</span></p>';
		}
		Element.update($('comment'),tmp);
	}
}
function refreshComment(){
	Element.update($('comment'),'wait... ...');
	updateComment(bkpzid,1);
}
function keySubmit(evt){
	var the_evt = evt || window.event;
	if(the_evt.altKey && the_evt.keyCode==Event.KEY_RETURN)
		commentSend();
}
function commentSend(){
	var tmp=$('mycomment').value.truncate(200).replaceTags();
	var pb='bkpzid='+bkpzid+'&qishu='+qishu+'&mycomment='+tmp;
	if($('mycomment').value.strip()!=''){
		new Ajax.Request("/popular/behind/AddCommentToSvc.aspx",{postBody:pb,onComplete:Complete});
	}
	$('mycomment').value=tmp;
	$('mycomment').focus();
	function Complete(ccc){
		if(ccc.responseText!='0') 
			alert(ccc.responseText);
		else{
			$('mycomment').value='';
			alert('您的评论发表成功');
		}
		
		refreshComment();
	}
}


function updateRelation(_sortcode){
	new Ajax.Request('behind/book_intro_relation.aspx?sortcode='+_sortcode,{method:'get',onComplete:Complete,onFailure:Failure});
	function Failure(ccc){
		alert(ccc.responseText);
	}
	function Complete(ccc){
		var thisXml = ccc.responseXML;
		var tmp='';
		var rows=thisXml.selectNodes('//root/row');
		for(var i=0;i<rows.length;i++){
			tmp+='<a href="/education/book_intro.aspx?listid='+elementAttrib(rows[i],'listid')+'" class="smallimg" style="margin:4px 4px 0px 4px;height:146px;overflow: hidden; white-space: nowrap;"><img src="'+'/bookcover/'+elementAttrib(rows[i],'bkdz')+'fs.jpg"><span>'+elementAttrib(rows[i],'bkmc')+'</span></a>';
		}
		Element.update($('relation'),tmp);
	}	
}

function updateCW(){
	new Ajax.Request('behind/LoadCwtop.aspx?',{method:'get',onComplete:Complete,onFailure:Failure});
	function Failure(ccc){
		alert(ccc.responseText);
	}
	function Complete(ccc){
		var thisXml = ccc.responseXML;
		var row = thisXml.selectNodes('/root/row');
		var tmp='';
		for(var i=0; i<row.length; i++){
			tmp+='<p class="inforow" style="width:290px;"><a href="/education/Cwinfo.aspx?id='+elementAttrib(row[i],'id')+'">'+elementAttrib(row[i],'name').truncate(40)+'</a></p>';
			if(i>=11) break;
		}
		$('CW').innerHTML = tmp;
	}
}

function openMBook(id,page){
	var thepage=page || 0;
	record(id,thepage);
	window.open('/popular/MBook/MBook.aspx?id='+id+'&page='+thepage,'MBookWin','height='+screen.availHeight+', width='+screen.availWidth+', top=0, left=0,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no,status=no,modal=yes');
	
};

function record(id,page)
{
  var xmlurl='/lib/recordMBook.aspx';
  var para="bkid="+id+"&page="+page;
  var myAjax=new Ajax.Request(xmlurl,{method: 'get', asynchronous: true,parameters: para, onComplete: null});
}
function openEBook(id,page){
	var thepage=page || 0;
	//document.location.href='/education/Ebook.aspx?id='+id+'&page='+thepage+'&name='+escape(bkmc);
	document.location.href='/education/Ebook.aspx?id='+id+'&page='+thepage+'&name='+bkmc;
}

function AddBookStore(listid,bkid,bkwzid,bkmc,qishu){
	clearNotice();
	nt=JsMessBox("添加到书架，请稍候... ... ",'');
	var pd="listid="+listid+"&bookname="+bkmc+"&qishu="+qishu+"&servicemode=education"+(bkid=='n/a'? '&booktype=E&bookid='+bkwzid: '&booktype=M&bookid='+bkid );
	new Ajax.Request("/memcp/behind/BookStoreAdd.aspx",{postBody:pd,onComplete:Complete,onFailure:Failure});
	function Failure(ccc){alert(ccc.responseText);};
	function Complete(ccc){
		clearNotice();
		switch(ccc.responseText){
			case "0":nt=JsShowMess('<p style="width=200px;">添加成功</p>',"",2000); break;
			case "1":nt=JsShowMess('<p style="width=200px;">本期报刊已经在您的书架里。</p>',"",2000); break;
			case "-1":nt=JsShowMess('<p style="width=200px;">添加失败。</p>',"",2000);break;
			default:alert(ccc.responseText);break;
		}
	}
}
function toFriend(){
	clipboardData.setData('text',document.location.href);alert('网址已复制，粘贴给好友请按CTRL+V.')
}

