/* 公用函数 */
// --------------------------------------------------------------------------------------------------

// 设置网页背景色
function SetWebBackColor(wcBackColor)
{
	document.body.style.backgroundColor = wcBackColor;
	document.getElementById('AlphaPageTop').style.backgroundColor = wcBackColor;
	document.getElementById('AlphaPageBottom').style.backgroundColor = wcBackColor;
}

// 设置网页背景图片
function SetWebBackImage(wcBackImageUrl)
{
	if (wcBackImageUrl == ' ') {
		document.body.style.backgroundImage = ''; 
	} else {
		document.body.style.backgroundImage = 'url(' + wcBackImageUrl + ')'; 
	}
}

// 设置网页标题
function SetWebTitleText(wtWebTitleText)
{
	document.title = wtWebTitleText;
}

/* 目录页函数 */
// --------------------------------------------------------------------------------------------------
function SetBookNameText(ctBookNameText)
{
	document.getElementById('BookNameId').innerText = ctBookNameText;
}

// 设置书籍名称的样式
function SetBookNameStyle(csFontName, csFontColor, csFontSize, csFontBold)
{
	AElemen = document.getElementById('BookNameId');
	
	AElemen.style.fontFamily = csFontName;
	AElemen.style.color = csFontColor;
	AElemen.style.fontSize = csFontSize;
	if (csFontBold == true) {
		AElemen.style.fontWeight = 'bold';
	} else
	{
		AElemen.style.fontWeight = '';
	} 
}

// 设置章节相关信息：如更新时间
function SetBookInfoText(ciBookInfoText)
{
	AElemen = document.getElementById('BookInfoId');
	AElemen.innerText = ciBookInfoText;
	
	if (ciBookInfoText == ' ') {
		AElemen.style.display='none';
	} else {
		AElemen.style.display='block';
	}
}

// 设置章节相关信息的样式
function SetBookInfoStyle(biFontName, biFontColor, biFontSize, biFontBold)
{
	AElemen = document.getElementById('BookInfoId');
	
	AElemen.style.fontFamily = biFontName;
	AElemen.style.color = biFontColor;
	AElemen.style.fontSize = biFontSize;
	if (biFontBold == true) {
		AElemen.style.fontWeight = 'bold';
	} else
	{
		AElemen.style.fontWeight = '';
	} 
}
// 向网页插入章节列表HTML代码
function SetChapterListHtml(chChapterListHtml)
{
	document.getElementById('ChapterListId').innerHTML = chChapterListHtml;
}

// 返回分卷HTML”$UnitTitleText$“：代表分卷标题文本；“$UnitChapterListHtml$“代表分卷章节列表的HTML代码
function GetUnitHtml(uhParams)
{
	return '        <div id="UnitTitle">$UnitTitleText$ &nbsp;</div>' + '\r\n' + '          <ul>' + '\r\n' + '$UnitChapterListHtml$' + '\r\n' + '          </ul>' + '\r\n' + '        <div id="UnitListEnd"></div>'+ '\r\n';
}

// 返回分卷章节列表的HTML代码“$ChapterHrefHtml$”：插入的连接代码
function GetChapterLineHtml(uhParams)
{
	return '            <li>$ChapterHrefHtml$</li>' + '\r\n' + '         <li>$ChapterHrefHtml$</li>' + '\r\n' + '            <li>$ChapterHrefHtml$</li>' + '\r\n' + '            <li>$ChapterHrefHtml$</li>'+ '\r\n';
}

// 设置页面状态 0：加载中页面；1：加载错误页面；2：目录正常页面
function SetWebListState(wlState)
{
	if (wlState == -1){
		document.getElementById('ListPageId').style.display='none';
		document.getElementById('LoadingPageId').style.display='none';
		document.getElementById('LoadErrorPageId').style.display='none';
		document.getElementById('LoadingPageId').className = '';
		document.getElementById('LoadErrorPageId').className = '';
	} else if (wlState == 0){
		document.getElementById('ListPageId').style.display='none';
		document.getElementById('LoadingPageId').style.display='block';
		document.getElementById('LoadErrorPageId').style.display='none';
		document.getElementById('LoadingPageId').className = 'LoadingBoxDiv';
		document.getElementById('LoadErrorPageId').className = '';
	} else if (wlState == 1){
		document.getElementById('ListPageId').style.display='none';
		document.getElementById('LoadingPageId').style.display='none';
		document.getElementById('LoadErrorPageId').style.display='block';
		document.getElementById('LoadingPageId').className = '';
		document.getElementById('LoadErrorPageId').className = 'LoadErrorBoxDiv';	
	} else if (wlState == 2){
		document.getElementById('ListPageId').style.display='block';
		document.getElementById('LoadingPageId').style.display='none';
		document.getElementById('LoadErrorPageId').style.display='none';
		document.getElementById('LoadingPageId').className = '';
		document.getElementById('LoadErrorPageId').className = '';			
	}
}

/* 章节页函数 */
// --------------------------------------------------------------------------------------------------


// 设置章节标题
function SetChapterTitleText(ctChapterTitleText)
{
	document.getElementById('ChapterTitleId').innerText = ctChapterTitleText;
}

// 设置书籍名称的样式
function SetChapterTitleStyle(csFontName, csFontColor, csFontSize, csFontBold)
{
	AElemen = document.getElementById('ChapterTitleId');
	
	AElemen.style.fontFamily = csFontName;
	AElemen.style.color = csFontColor;
	AElemen.style.fontSize = csFontSize;
	if (csFontBold == true) {
		AElemen.style.fontWeight = 'bold';
	} else
	{
		AElemen.style.fontWeight = '';
	} 
}

// 设置章节相关信息：如更新时间
function SetChapterInfoText(ciChapterInfoText)
{
	AElemen = document.getElementById('ChapterInfoId');
	AElemen.innerText = ciChapterInfoText;
	
	if (ciChapterInfoText == ' ') {
		AElemen.style.display='none';
	} else {
		AElemen.style.display='block';
	}
}

// 设置章节相关信息的样式
function SetChapterInfoStyle(ciFontName, ciFontColor, ciFontSize, ciFontBold)
{
	AElemen = document.getElementById('ChapterInfoId');
	
	AElemen.style.fontFamily = ciFontName;
	AElemen.style.color = ciFontColor;
	AElemen.style.fontSize = ciFontSize;
	if (ciFontBold == true) {
		AElemen.style.fontWeight = 'bold';
	} else
	{
		AElemen.style.fontWeight = '';
	} 
}

// 设置章节正文内容
function SetChapterTextText(ctChapterTextText)
{
	document.getElementById('ChapterTextId').innerText = ctChapterTextText;
}

// 设置章节正文Html内容
function SetChapterTextHtml(chChapterTextHtml)
{
	document.getElementById('ChapterTextId').innerHTML = chChapterTextHtml;
}

// 设置章节正文图片内容
function SetChapterTextImage(stChapterTextImageArrayString, stImgWidth)
{
	AimageHtml = '<div align="center">';
	AImageArray = stChapterTextImageArrayString.split('#|#');
	if (stImgWidth == '-1') {
		for(i = 0; i < AImageArray.length; i++)
		{
			AimageHtml = AimageHtml + '<div class="DivImage"><img src="' + AImageArray[i] + '" align="center" border=0></div>';
		}	
	} else {
		for(i = 0; i < AImageArray.length; i++)
		{
			AimageHtml = AimageHtml + '<div class="DivImage"><img src="' + AImageArray[i] + '" align="center" border=0 width="' + stImgWidth + 'px"></div>';
		}
	}
	AimageHtml = AimageHtml + '</div>';
	document.getElementById('ChapterPageId').style.width = "auto";
	document.getElementById('ChapterTextId').innerHTML = AimageHtml;
}

// 设置章节正文内容的样式
function SetChapterTextStyle(csFontName, csFontColor, csFontSize, csFontBold, csLineHeigh, csPageWidth)
{
	AElemen = document.getElementById('ChapterTextId');
	
	AElemen.style.fontFamily = csFontName;
	AElemen.style.color = csFontColor;
	AElemen.style.fontSize = csFontSize;
	if (csFontBold == true) {
		AElemen.style.fontWeight = 'bold';
	} else
	{
		AElemen.style.fontWeight = '';
	} 
	AElemen.style.lineHeight = csLineHeigh;
	document.getElementById('ChapterPageId').style.width = csPageWidth;
}

// 显示导航信息对话框; 返回True要程序自己显示
function ShowChapterUrlNavigateBox(sbUrl)
{
	if (sbUrl == 'http://NullLastHref/'){
		return true;
	} else if (sbUrl == 'http://NullNextHref/'){
		return true;
	} else if (sbUrl == 'http://Null/'){
		return true;
	} else {
		return true;
	}
}

// 修改章节导航
function SetChapterUrlNavigate(cnChapterLastUrl, cnChapterListUrl, cnChapterNextUrl)
{
	document.getElementById('ChapterLastHrefId').href = cnChapterLastUrl;
	document.getElementById('ChapterListHrefId').href = cnChapterListUrl;
	document.getElementById('ChapterNextHrefId').href = cnChapterNextUrl;
}

// 导航章节页面
function PageNavigateTo(ptChapterIndex)
{
	if (ptChapterIndex == 1) {
		location = document.getElementById('ChapterLastHrefId').getAttribute('href');
	} else if (ptChapterIndex == 0) {
		location = document.getElementById('ChapterListHrefId').getAttribute('href');
	} else if (ptChapterIndex == 2) {
		location = document.getElementById('ChapterNextHrefId').getAttribute('href');
	}
}

// 返回导航章节网址
function GetPageNavigateUrl(guChapterIndex)
{
	if (guChapterIndex == 1) {
		return document.getElementById('ChapterLastHrefId').getAttribute('href');
	} else if (guChapterIndex == 0) {
		return document.getElementById('ChapterListHrefId').getAttribute('href');
	} else if (guChapterIndex == 2) {
		return document.getElementById('ChapterNextHrefId').getAttribute('href');
	}
}

// 热键导航章节页面
function KeyPageNavigate()
{
	if (event.keyCode == 37) {
		PageNavigateTo(1);
	} else if (event.keyCode == 13) {
		PageNavigateTo(0);
	} else if (event.keyCode == 39) {
		PageNavigateTo(2);
	}
}

// 设置页面状态 0：加载中页面；1：加载错误页面；2：目录正常页面
function SetWebChapterState(wsState)
{
	if (wsState == -1){
		document.getElementById('ChapterPageId').style.display='none';
		document.getElementById('LoadingPageId').style.display='none';
		document.getElementById('LoadErrorPageId').style.display='none';
		document.getElementById('LoadingPageId').className = '';
		document.getElementById('LoadErrorPageId').className = '';
	} else if (wsState == 0){
		document.getElementById('ChapterPageId').style.display='none';
		document.getElementById('LoadingPageId').style.display='block';
		document.getElementById('LoadErrorPageId').style.display='none';
		document.getElementById('LoadingPageId').className = 'LoadingBoxDiv';
		document.getElementById('LoadErrorPageId').className = '';
	} else if (wsState == 1){
		document.getElementById('ChapterPageId').style.display='none';
		document.getElementById('LoadingPageId').style.display='none';
		document.getElementById('LoadErrorPageId').style.display='block';
		document.getElementById('LoadingPageId').className = '';
		document.getElementById('LoadErrorPageId').className = 'LoadErrorBoxDiv';	
	} else if (wsState == 2){
		document.getElementById('ChapterPageId').style.display='block';
		document.getElementById('LoadingPageId').style.display='none';
		document.getElementById('LoadErrorPageId').style.display='none';
		document.getElementById('LoadingPageId').className = '';
		document.getElementById('LoadErrorPageId').className = '';			
		document.onkeyup = KeyPageNavigate;
	}
}

// 设置章节信息栏Html内容
function SetChapterMessageHtml(chChapterMessageHtml, chChapterMessageHtml2)
{
	document.getElementById('wPageMessageId').innerHTML = chChapterMessageHtml;
	document.getElementById('wPageMessageId2').innerHTML = chChapterMessageHtml2;
}