
function getLoginID()
{
	var sCookieName = "hbloginid=";
	var sCookie;
	var sWholeCookie = document.cookie;
	var nValueBegin = sWholeCookie.indexOf(sCookieName);
	if(nValueBegin != -1)
	{
		var nValueEnd = sWholeCookie.indexOf(";", nValueBegin);
		if (nValueEnd == -1)
			nValueEnd = sWholeCookie.length;
		
		var sValue = sWholeCookie.substring(nValueBegin + sCookieName.length, nValueEnd); //获得Cookie值

		return unescape(sValue);
	}
	return "";
}

//#################################################################################################################

//################################  [ History Start] ##############################################################


function NoteInfo(){
	var his = new History();
	//his.Write(document.title.substring(0,document.title.indexOf("_")),location.href,document.getElementById("spanProductID").innerText);
	his.Write(document.getElementById("spanProductName").innerText,location.href,document.getElementById("spanProductID").innerText);
}

function ShowHistory(){
	var his = new History();
	var bookInfo = his.Read();
	
	var hisParent = GetHTMLObjectById("divHistoryParent");
	var hisChild = GetHTMLObjectById("divHistory");
	
	if(bookInfo.length >0){		
		hisParent.style.display="";
		
		for(var i =0;i<bookInfo.length;i++){
			var obj=document.createElement("<li>");
			obj.innerHTML="<a href='"+ bookInfo[i].GetHref() +"' title='"+ bookInfo[i]  +"' target='_blank'>" + left(bookInfo[i].GetName(),11) + "</a>";
			hisChild.appendChild(obj);
			
			if(i==4)
				break;
		}
		
		if(bookInfo.length > 5){
			var obj=document.createElement("<div>");
			obj.align ="right";
			obj.innerHTML ="<a href='/moreHistory.htm'>更多...</a>";
			hisChild.appendChild(obj);
		}
	}
}


//****************************************** History Class Code *****************************************

//***************************************************
// 功能说明：以Cookie形式在客户端记录浏览过的图书信息
// 
//***************************************************


function History()
{
	this.cookieName ="hopebook_history_data"; 	//cookie Name
	this.number = 20;							//save book number
	this.divisionSignForMoreBookInfo ="@@";
	this.divisionSignForNameAndHref ="$$";
	
	History.prototype.GetAllCookies = function(){
		return document.cookie;
	}
	
	History.prototype.NextMonth = function(){
		var date = new Date();
		date.setMonth(date.getMonth() + 2);
		return date;
	}
	
	History.prototype.Write = function(bookName,bookLinkHref,bookID){
		if(this.GetAllCookies() =="")
			document.cookie=this.cookieName+"="+escape(bookName + this.divisionSignForNameAndHref + bookLinkHref + this.divisionSignForNameAndHref + bookID) + ";expires=" + this.NextMonth().toGMTString()+";path=/";
		else{
			var bookInfoAry = this.GetBookInfoByArray();
			if(bookInfoAry == null){;
				document.cookie=this.cookieName+"="+escape(bookName + this.divisionSignForNameAndHref + bookLinkHref + this.divisionSignForNameAndHref + bookID) + ";expires=" + this.NextMonth().toGMTString()+";path=/";
			}else{
				var tempString = bookName + this.divisionSignForNameAndHref + bookLinkHref + this.divisionSignForNameAndHref + bookID;

				for(var i =0;i<bookInfoAry.length;i++){
					if(unescape(bookInfoAry[i]) == tempString)
						return;
				}

				tempString = escape(tempString);

				for(var i =0;i<bookInfoAry.length;i++){
					tempString +=this.divisionSignForMoreBookInfo + bookInfoAry[i];
					if(i>=this.number -2)
						break;
				}
				
				document.cookie=this.cookieName+"=" + tempString + ";expires=" + this.NextMonth().toGMTString()+";path=/";
			}
		}
	}
	
	History.prototype.GetBookInfoByArray = function(){
		var allCookies = this.GetAllCookies();
		
		var bookInfo = allCookies.indexOf(this.cookieName);
		
		if(bookInfo==-1)
			return null;
			
		var startIndex = bookInfo + this.cookieName.length + 1;
		var endIndex = allCookies.indexOf(";",startIndex);
		
		if(endIndex == -1)
			endIndex = allCookies.length;
			
		var bookInfoString = allCookies.substring(startIndex,endIndex);
		
		return bookInfoString.split(this.divisionSignForMoreBookInfo);
	}
	
	History.prototype.Read = function(){
		var bookInfoAry = this.GetBookInfoByArray();
		
		if(bookInfoAry == null){
			return 0
		}
		
		var tempBookInfoAry = new Array();
		for(var i =0;i<bookInfoAry.length;i++){
			var tempString = unescape(bookInfoAry[i]);
			var tempAry = tempString.split(this.divisionSignForNameAndHref);

			tempBookInfoAry[i] = new  HistoryInfo(tempAry[0],tempAry[1],tempAry[2]);
		}		
		return tempBookInfoAry;
	}
}

function HistoryInfo(bookName,bookHref,bookID){
	this.bookName = bookName;
	this.bookHref = bookHref;
	this.bookID = bookID.trim();
					
	
	HistoryInfo.prototype.GetName=  function(){
		return this.bookName;
	}
	
	HistoryInfo.prototype.GetHref=  function(){
		return this.bookHref;
	}
	
	HistoryInfo.prototype.GetID=  function(){
		return this.bookID;
	}
	
	HistoryInfo.prototype.toString=  function(){
		return this.bookName;
	}
}
//################################  [ History End ] ##############################################################

// 
// 截取子字符串
//
function left(str,len){
	if(str.length<=len)
		return str;
		
	return str.substr(0,len);
}


//函数名：chksafe
//功能介绍：检查是否含有"'",'\\',"/"
//参数说明：要检查的字符串
//返回值：0：是  1：不是
function chksafe(a)
{
	var temp1,temp2
        fibdn = new Array ("'" ,"\\", ",", ";", "/", "&quot;", "%", "|");
	m=fibdn.length;
	n=a.length;
	for (ii=0;ii<m;ii++)
	{	for (jj=0;jj<n;jj++)
		{	temp1=a.charAt(jj);
			temp2=fibdn[ii];
			if (temp1==temp2)
			{	return 0; }
		}
	}
	return 1;

}

//函数名：chkemail
//功能介绍：检查是否为Email Address
//参数说明：要检查的字符串
//返回值：0：不是  1：是
function chkemail(a)
{	var i=a.length;
	var temp = a.indexOf('@');
	var tempd = a.indexOf('.');
	if (temp > 1) {
		if ((i-temp) > 3){

				if ((i-tempd)>0){
					return 1;
				}

		}
	}
	return 0;
}

//函数名：fucPWDchk
//功能介绍：检查是否含有非数字或字母
//参数说明：要检查的字符串
//返回值：0：含有 1：全部为数字或字母
function fucPWDchk(str)
{
  var strSource ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
  var ch;
  var i;
  var temp;

  for (i=0;i<=(str.length-1);i++)
  {

    ch = str.charAt(i);
    temp = strSource.indexOf(ch);
    if (temp==-1)
    {
     return 0;
    }
  }
  if (strSource.indexOf(ch)==-1)
  {
    return 0;
  }
  else
  {
    return 1;
  }
}

//函数名：fucCheckNUM
//功能介绍：检查是否为数字
//参数说明：要检查的数字
//返回值：1为是数字，0为不是数字
function fucCheckNUM(NUM)
{
	var i,j,strTemp;
	strTemp="0123456789.";
	if ( NUM.length== 0)
		return 0
	for (i=0;i<NUM.length;i++)
	{
		j=strTemp.indexOf(NUM.charAt(i));
		if (j==-1)
		{
		//说明有字符不是数字
			return 0;
		}
	}
	//说明是数字
	return 1;
}

//函数名：chkspc
//功能介绍：检查是否含有空格
//参数说明：要检查的字符串
//返回值：0：是  1：不是
function chkspc(a)
{
	var i=a.length;
	var j = 0;
	var k = 0;
	while (k<i)
	{
		if (a.charAt(k) != " ")
			j = j+1;
		k = k+1;
	}
	if (j==0)
	{
		return 0;
	}

	if (i!=j)
	{ return 2; }
	else
	{
		return 1;
	}
}

//函数名：fucCheckTEL
//功能介绍：检查是否为电话号码
//参数说明：要检查的字符串
//返回值：1为是合法，0为不合法
function fucCheckTEL(TEL)
{
	var i,j,strTemp;
	strTemp="0123456789-()（）#转";
	for (i=0;i<TEL.length;i++)
	{
		j=strTemp.indexOf(TEL.charAt(i));
		if (j==-1)
		{
		//说明有字符不合法
			return 0;
		}
	}
	//说明合法
	return 1;
}

//函数名：fucCheckLength
//功能介绍：检查字符串的长度
//参数说明：要检查的字符串
//返回值：长度值
function fucCheckLength(strTemp)
{
	var i,sum;
	sum=0;
	for(i=0;i<strTemp.length;i++)
	{
		if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))
			sum=sum+1;
		else
			sum=sum+2;
	}
	return sum;
}

function opennew(newurl,windowName,width,height)
{
var theLeft,theTop
theLeft=(screen.width-width)/2-2
theTop=(screen.height-height)/2
window.open(newurl,windowName,'width='+width+',height='+height+',scrollbars=1,status=0,toolbar=0,resizable=0,left='+theLeft+',top='+theTop+'').focus();
//return true;
}
function opennewfull(newurl,windowName)
{
window.open(newurl,windowName,'width='+screen.width+',height='+(screen.height-55)+',scrollbars=1,toolbar=0,resizable=0,left=0,top=0').focus();
}

function openModal(newUrl,windowName,width,height,controlName){
controlName.value=showModalDialog(newUrl,windowName,"dialogWidth:"+width+";dialogHeight:"+height+";center:1")
}

function openScript(url, width, height){
	var Win = window.open(url,"openScript",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=yes' );
}


function onChange(i){
childSort=document.all("child" + i);
//theTd=document.all("td" + i);
	if(childSort.style.display=="none"){
//		theTd.bgcolor="#ffffff";
		childSort.style.display="";}
	else{
//		theTd.bgcolor="#000000";
		childSort.style.display="none";}
}


function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		//field.value = field.value.substring(0, maxlimit);
		countfield.value = maxlimit - field.value.length;
	} else {
		countfield.value = maxlimit - field.value.length;
	}
}
