﻿function changeTag(thisObj)
{
    if(thisObj.getAttribute("focus") == "1") return;
    var objs = thisObj.parentNode.parentNode.getElementsByTagName("img");
    for(var i=0;i<objs.length;i++)
    {
        if(objs[i] == thisObj){thisObj.src = thisObj.src.replace("_b.gif", "_f.gif");thisObj.setAttribute("focus", "1"); $(thisObj.getAttribute("rel")).style.display = "block"; }
        else{objs[i].src  = objs[i].src.replace("_f.gif", "_b.gif"); objs[i].setAttribute("focus", "0"); $(objs[i].getAttribute("rel")).style.display = "none"; }
    }
}

//------------
var tagTableParams = {_tdFocus : null, _divFocus : null}

function initTagTable(){
    var tableObj = $("tagtable");
    var rows0 = tableObj.rows[0];
    for(var i=0;i<rows0.cells.length;i++)
    {
        if(!rows0.cells[i].getAttribute("rel")) continue;
        rows0.cells[i].onclick = function(){changeTdTag(this)};
        rows0.cells[i].onmouseover = function(){this.className = "td"};
        rows0.cells[i].onmouseout = function(){if(this.getAttribute("isfocus") == "0")this.className = ""};
        if(rows0.cells[i].getAttribute("isfocus") == "1"){tagTableParams._tdFocus = rows0.cells[i]; tagTableParams._divFocus = $(rows0.cells[i].getAttribute("rel"));tagTableParams._divFocus.style.display = "block";rows0.cells[i].className = "td"};
    }
}
function changeTdTag(tdObj){
if(tdObj.getAttribute("isfocus") == "1") return;
tdObj.setAttribute("isfocus", "1");
tagTableParams._tdFocus.className = "";
tagTableParams._tdFocus.setAttribute("isfocus", "0");
tagTableParams._tdFocus = tdObj;
tdObj.className = "td";
tagTableParams._divFocus.style.display = "none";
tagTableParams._divFocus = $(tdObj.getAttribute("rel"));
tagTableParams._divFocus.style.display = "block";

}
//------------

function changeUserButton(thisObj){
var imgs = thisObj.getElementsByTagName("img");
for(var i=0;i<imgs.length;i++){
imgs[i].onmouseover = function(){this.src=this.src.replace(").gif", "1).gif");};
imgs[i].onmouseout = function(){this.src=this.src.replace("1).gif", ").gif");};
//imgs[i].onclick = function(){if(currentUserCID != null){location.href=this.getAttribute("href");}else{userParams.login();}}
imgs[i].onclick = function(){location.href=this.getAttribute("href");}
}
}

function loginCheck(){if($("ln").value.trim()==""){alert("请填写帐户");$("ln").focus();return false;};if($("pw").value.trim()==""){alert("请填写密码");$("pw").focus();return false;};return true;}

function loadcomm(cid,mod){
var getQuerys = "../ps/Comment.aspx?m="+mod+"&i=" + cid;
var xmlhttp = ajaxXmlHttp(); xmlhttp.open("POST", getQuerys, true); xmlhttp.setRequestHeader("cache-control","no-cache"); xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlhttp.send(null);
xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4){ if(xmlhttp.status == 200){ $("bookcommlist").innerHTML = xmlhttp.responseText;  return; }}}
}

function sendcomm(mod){
var cmod = mod, cpid = $("_bookid").value, cmsg = $("_commc").value.trim();
if(cmsg.length < 2 || cmsg.length > 2000){ajaxMessage("小提示：华章图书评论字数限制在2-2000！内容中首和尾的空格不算字噢！", true);$("_commc").focus();return;}
ajaxMessage("正在为您保存评论，请稍候...");
var getQuerys = "../ps/Comment.aspx?a=s&m="+cmod+"&i="+cpid; cmsg = cmsg.replaceAndChar();
var xmlhttp = ajaxXmlHttp(); xmlhttp.open("POST", getQuerys, true); xmlhttp.setRequestHeader("cache-control","no-cache"); xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlhttp.send(cmsg);
xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4){ if(xmlhttp.status == 200){ $("bookcommlist").innerHTML = xmlhttp.responseText; ajaxMessage(); $("_commc").value=""; return; }else{ajaxMessage();ajaxMessage("操作失败，请稍候再重新提交！",true);}}}
}

function sendmsg(mod){
if(currentUserCID == null){ajaxMessage("您不是登录用户，不能发布留言", true); return; }
var cmod = mod, cmsg = $("_msgc").value.trim();
if(cmsg.length < 2 || cmsg.length > 2000){ajaxMessage("小提示：华章图书留言字数限制在2-2000！内容中首和尾的空格不算字噢！", true);$("_msgc").focus();return;}
ajaxMessage("正在为您保存留言，请稍候...");
var getQuerys = "../mc/Default.aspx?a=msg&m="+cmod; cmsg = cmsg.replaceAndChar();
var xmlhttp = ajaxXmlHttp(); xmlhttp.open("POST", getQuerys, true); xmlhttp.setRequestHeader("cache-control","no-cache"); xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlhttp.send(cmsg);
xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4){ if(xmlhttp.status == 200){ $("ctl00_left_msglist").innerHTML = xmlhttp.responseText + $("ctl00_left_msglist").innerHTML; ajaxMessage(); $("_msgc").value=""; return; }else{ajaxMessage();ajaxMessage("操作失败，请稍候再重新提交！",true);}}}
}

function saveFav(cid){
var getQuerys = "../mc/Default.aspx?a=fav&i=" + cid;
var xmlhttp = ajaxXmlHttp();xmlhttp.open("POST", getQuerys, true);xmlhttp.setRequestHeader("cache-control","no-cache");xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlhttp.send(null);xmlhttp.onreadystatechange = function(){if(xmlhttp.readyState == 4){if(xmlhttp.status == 200){var result = xmlhttp.responseText; if(result.charAt(0) == "1") ajaxMessage("小提示：已加入您的书架", true); else ajaxMessage(result.substring(1), true); return; } } }
}


function getFlash(src, wid, hei, params) {
wid = wid.toString();
if(wid.charAt(wid.length - 1) != "%") wid = wid + "px";
hei = hei.toString();
if(hei.charAt(hei.length - 1) != "%") hei = hei + "px";

document.write( "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='"+wid+"' height='"+hei+"'>");
document.write( "<param name=movie value='"+src+"'>");
if(params){document.write( "<param name=flashvars value=\""+params+"\">");params = " flashvars=\""+params+"\"";}
document.write( "<param name=quality value=high /><param name=wmode value=transparent />");
document.write( "<embed"+params+" src='"+src+"' quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='"+wid+"' height='"+hei+"' wmode=transparent></embed>");
document.write( "</embed></object>");
}


var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) 
{
    //alert(document.body.filters);

   if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
   {
      var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
     var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
     var imgTitle = (myImage.title) ? 
                 "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
     var imgStyle = "display:inline-block;" + myImage.style.cssText
     var strNewHTML = "<span " + imgID + imgClass + imgTitle
                 + " style=\"" + "width:" + myImage.width 
                 + "px; height:" + myImage.height 
                 + "px;" + imgStyle + ";"
                 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                 + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
     myImage.outerHTML = strNewHTML    
   }
}




//点击连接打开新窗口
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


//大图载入进度条
var t_id = setInterval(animate,20);
var pos=0;
var dir=2;
var len=0;

function animate()
{
var elem = document.getElementById('progress');
if(elem != null) {
if (pos==0) len += dir;
if (len>32 || pos>79) pos += dir;
if (pos>79) len -= dir;
if (pos>79 && len==0) pos=0;
elem.style.left = pos;
elem.style.width = len;
}
}

//进度条和大图转换
function remove_loading() {
this.clearInterval(t_id);
var targelem = document.getElementById('loader_container');
targelem.style.display='none';
targelem.style.visibility='hidden';
var t_id = setInterval(animate,60);
}


/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact//这段说明必须完整保留*/


var offsetfrommouse=[5,5]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.

var defaultimageheight = 40;	// maximum image size.
var defaultimagewidth = 40;	// maximum image size.

var timer;

function gettrailobj(){
if (document.getElementById)
return document.getElementById("preview_div").style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("preview_div")
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function hidetrail(){	
	gettrailobj().display= "none";
	document.onmousemove=""
	gettrailobj().left="-500px"
	clearTimeout(timer);
}

//延迟0.2秒载入大图
function showtrail(imagename,title,content,width,height){
	i = imagename
	t = title
	c = content
	w = width
	h = height
	timer = setTimeout("show('"+i+"',t,c,w,h);",200);
}
//载入大图
function show(imagename,title,content,width,height){
 
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) {
		( width == 0 ) ? width = defaultimagewidth: '';
		( height == 0 ) ? height = defaultimageheight: '';
			//docwidth>650 && docheight>500－－大图显示的条件之一：文档宽度需大于650px，高度大于500px
		width+=30
		height+=55
		defaultimageheight = height
		defaultimagewidth = width
	
		document.onmousemove=followmouse; 

//生成大图界面		
		newHTML = '<div class="border_preview" style="width:'+  width +'px; height:'+ height +'px;"><div id="loader_container"><div id="loader"><div align="center">正在读取...</div><div id="loader_bg"><div id="progress"></div></div></div></div>';
		//newHTML = newHTML + '<img onload="javascript:remove_loading();" src="' + imagename + '"><b>《' + title + '》</b><br />' + content;
		newHTML = newHTML + '<img onload="javascript:remove_loading();" src="' + imagename + '">' + content;
		newHTML = newHTML + '</div>'; 
		
		if(navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1 ){
			newHTML = newHTML+'';
		}		

		gettrailobjnostyle().innerHTML = newHTML;
		gettrailobj().display="block";
	}
}

//大图随鼠标移动
function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}

//用户部分
var userParams = {
    join : function(){var windowTitle="我的注册信息";if(currentUserCID!=null){windowTitle="修改我的注册资料"};showDialogWindow('../mc/Join.aspx', 600, 400, windowTitle);},
    login : function(){if(currentUserCID==null){showDialogWindow('../mc/Login.aspx', 300, 220, '会员登录');}else{ajaxMessage("您已经是登录会员，不需要重新登录", true)}},
    cpw : function(){showDialogWindow('../mc/ChangePwd.aspx', 300, 200, '修改密码');},
    findpw : function(){if(window == top){showDialogWindow('../mc/FindPW.htm', 400, 300, '找回密码');}else{parent.window.setTimeout('userParams.findpw()', 100);parent.window.showDialogWindow();}},
    
    tea_VIP : function(){showDialogWindow('../mc/VIPTeacher.aspx', 750, 500, '教师帐户升级到VIP');},
    tea_trans : function(){showDialogWindow('../mc/ApplyTranslate.aspx', 800, 500, '填写翻译申请');},
    tea_apply : function(){showDialogWindow('../mc/TeacherApply.htm', 800, 500, '填写选题申请');},
    tea_sample : function(){showDialogWindow('../mc/ApplySample.aspx', 800, 500, '填写样书申请');},
    
    rea_VIP : function(){showDialogWindow('../mc/VIPReader.aspx', 800, 500, '专业读者帐户升级到VIP');},
    
    age_order : function(gets){showDialogWindow(gets, 300, 200, '填写订购数量');},
    
    author:function(authorID){showDialogWindow('AuthorForm.aspx?i='+authorID, 800, 500, '作者信息');},
    trans:function(authorID){showDialogWindow('AuthorForm.aspx?i='+authorID, 800, 500, '译者信息');}

   
}
function getHeadText(){
if(currentUserCID == null) document.write("<a href=\"javascript:userParams.login()\">登录</a> <a href=\"javascript:userParams.join()\">注册</a> &nbsp; &nbsp; <a href=\"javascript:void(0)\" onclick=\"window.external.AddFavorite(window.location.href, window.document.title)\">加入收藏</a> ");
else
if(isAdministrator)
document.write("<a href=\"../mc/Login.aspx?o=\">退出</a> <a href=\"javascript:userParams.join()\">资料</a> &nbsp; &nbsp; <a href=\""+isAdministrator+"\">网站管理</a> ");
else
document.write("<a href=\"../mc/Login.aspx?o=\">退出</a> <a href=\"javascript:userParams.join()\">资料</a> &nbsp; &nbsp; <a href=\"javascript:void(0)\" onclick=\"window.external.AddFavorite(window.location.href, window.document.title)\">加入收藏</a> ");
}
//----------

function offsetLeft(obj){ x = obj.offsetLeft;for (objParent=obj.offsetParent;objParent;objParent=objParent.offsetParent)x+=objParent.offsetLeft;return x;}
function offsetTop(obj){ y = obj.offsetTop;for(objParent=obj.offsetParent;objParent;objParent=objParent.offsetParent)y+=objParent.offsetTop;return y;} 
var tifoodlParams = {inputObj:null, dlObj:null, inputValue:null}
function getdlItems(kws){
var getQuerys = "../ps/Kws.aspx?q=" + UrlEncode(kws);
var xmlhttp = ajaxXmlHttp(); xmlhttp.open("POST", getQuerys, true); xmlhttp.setRequestHeader("cache-control","no-cache"); xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlhttp.send(kws);
xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4){ if(xmlhttp.status == 200){ var backString = xmlhttp.responseText; if(backString!=""){appendItems(backString.split("\r\n"))};  return; }}}

}
function showdl(inputObj){
if(tifoodlParams.dlObj==null){
var tempDiv = document.createElement("div"); tempDiv.id = "tifoodl"; document.body.appendChild(tempDiv);
tifoodlParams.dlObj = tempDiv;
}
if(inputObj.value.trim() == ""){ hiddendl(inputObj); return;}
tifoodlParams.inputObj = inputObj;
tifoodlParams.inputValue = inputObj.value.trim();

tifoodlParams.dlObj.style.width = inputObj.offsetWidth - 6 + "px";
tifoodlParams.dlObj.style.top = offsetTop(inputObj) + inputObj.offsetHeight + "px";
tifoodlParams.dlObj.style.left = offsetLeft(inputObj) + "px";
tifoodlParams.dlObj.style.display = "block";
getdlItems(inputObj.value);
//appendItems(['hello1','heel2']);
}
function appendItems(items){
tifoodlParams.dlObj.innerHTML = "";
var newNode;
for(var i=0;i<items.length;i++){
newNode = document.createElement("div");
newNode.innerHTML = items[i];
tifoodlParams.dlObj.appendChild(newNode);
newNode.onmouseover = function(){this.style.backgroundColor = "#efefef";};
newNode.onmouseout = function(){this.style.backgroundColor = "";};
newNode.onclick = function(){tifoodlParams.inputObj.value = this.innerHTML;tifoodlParams.dlObj.style.display="none";};
}
}
function hiddendl(inputObj) {
    if (tifoodlParams.dlObj != null) {
        if (tifoodlParams.dlObj.display != "none") { setTimeout("tifoodlParams.dlObj.style.display = 'none'", 200); }
    }
}
function showNaviTitle(){
var tStr = "<span>LINGFENGSH.COM</span>" + document.title;
document.write(tStr);
}
var downloadParams = {href : null}
function getDownLoad(href,inpw,bID,fr,fs){
downloadParams.href = href;
if(!inpw)
window.open(href,'下载');
else
showDialogWindow("../ps/dlpw.aspx?b="+bID+"&fr="+fr+"&fs="+fs, 350, 200, "提示");
}