/*
* 中国教材图书网 copyright 2004-2006 
* Author: 咸立华
* Mail: xianlihua@gmail.com
*/
/************************************************************************/
// 窗口加载完毕需要立即执行的函数
window.onload = function()
{
	btnBlur();
	ttlSet();
	cssSet();
	menuFocus();
	searchBarBorderSet();
	statusSet();
	imgSet();
}
var $ = function(id)
{
	if(document.getElementById(id))
		return document.getElementById(id);
}
// 设置按钮的点击效果
var btnBlur = function()
{
	var btn = document.getElementsByTagName("input");
	var btn2 = document.getElementsByTagName("button");
	if(btn)
	{
		for(var i=0;i<btn.length;i++)
		{
			if(btn[i].type == 'button') 
				btn[i].onfocus = new Function("this.blur()");
		}
	}
	if(btn2)
	{
		for(var j=0;j<btn2.length;j++)
		{
			btn2[j].onfocus = new Function("this.blur()");
		}
	}
}
// 设置文档标题
var ttlSet = function()
{
	document.title = "中国教材图书网 - 中国最专业的网上教材书店!";
}
// 设置文档样式表,采用Ajax技术
var cssSet = function()
{
	var css = document.getElementsByTagName("link");
	if(css)
	{
		for(var i=0;i<css.length;i++)
		{
			if(css[i].type.toLowerCase() == 'text/css') css[i].href = '../style/style.css';
		}
	}
}
// 设置当前导航样式
var menuFocus = function(){
	var loc = location.href;
	var fileName = loc.substring(loc.lastIndexOf("/")+1);
	if(!$("menu")) return;
	var aMenu = $("menu").getElementsByTagName("a");
	for(var i=0;i<aMenu.length;i++)
	{
		aMenu[i].style.borderBottom = '#eefaff 1px solid';
		aMenu[i].onclick = function()
		{
			this.style.borderBottom = '#FF4500 1px solid';
			this.style.backgroundColor = "#FF4500";
			this.style.color = "#FFFF00";
		}
		aMenu[i].onfocus = new Function("this.blur()");
	}
	// 主页
	if(fileName.indexOf("main.aspx") != -1 && aMenu[0].href.indexOf("main.aspx"))
	{
		aMenu[0].style.backgroundColor = "#FF4500";
		aMenu[0].style.color = "#FFFF00";
		aMenu[0].style.borderBottom = '#FF4500 1px solid';
		return true;
	}
	// 大中专教材
	if(fileName.indexOf("booklist.aspx?classx=1") != -1 && aMenu[1].href.indexOf("booklist.aspx?classx=1"))
	{
		aMenu[1].style.backgroundColor = "#FF4500";
		aMenu[1].style.color = "#FFFF00";
		aMenu[1].style.borderBottom = '#FF4500 1px solid';
		return true;
	}
	// 教学辅导
	if(fileName.indexOf("booklist.aspx?classx=3") != -1 && aMenu[2].href.indexOf("booklist.aspx?classx=3"))
	{
		aMenu[2].style.backgroundColor = "#FF4500";
		aMenu[2].style.color = "#FFFF00";
		aMenu[2].style.borderBottom = '#FF4500 1px solid';
		return true;
	}
	// 学术图书
	if(fileName.indexOf("booklist.aspx?classx=2") != -1 && aMenu[3].href.indexOf("booklist.aspx?classx=2"))
	{
		aMenu[3].style.backgroundColor = "#FF4500";
		aMenu[3].style.color = "#FFFF00";
		aMenu[3].style.borderBottom = '#FF4500 1px solid';
		return true;
	}
	// 缺书登记
	if(fileName.indexOf("forbook.aspx") != -1 && aMenu[4].href.indexOf("forbook.aspx"))
	{
		aMenu[4].style.backgroundColor = "#FF4500";
		aMenu[4].style.color = "#FFFF00";
		aMenu[4].style.borderBottom = '#FF4500 1px solid';
		return true;
	}
	// 教育资讯
	if(fileName.indexOf("news_list.aspx?type=5") != -1 && aMenu[5].href.indexOf("news_list.aspx?type=5"))
	{
		aMenu[5].style.backgroundColor = "#FF4500";
		aMenu[5].style.color = "#FFFF00";
		aMenu[5].style.borderBottom = '#FF4500 1px solid';
		return true;
	}
	// 出版动态
	if(fileName.indexOf("news_list.aspx?type=3") != -1 && aMenu[6].href.indexOf("news_list.aspx?type=3"))
	{
		aMenu[6].style.backgroundColor = "#FF4500";
		aMenu[6].style.color = "#FFFF00";
		aMenu[6].style.borderBottom = '#FF4500 1px solid';
		return true;
	}
	// 精彩书评
	if(fileName.indexOf("news_list.aspx?type=6") != -1 && aMenu[7].href.indexOf("news_list.aspx?type=6"))
	{
		aMenu[7].style.backgroundColor = "#FF4500";
		aMenu[7].style.color = "#FFFF00";
		aMenu[7].style.borderBottom = '#FF4500 1px solid';
		return true;
	}
}
var searchBarBorderSet = function()
{
	var bookSearchBar = $("bookSearchBar");
	var newsSearchBar = $("newsSearchBar");
	if(location.href.indexOf("main.aspx")!=-1 && bookSearchBar && newsSearchBar)
	{
		bookSearchBar.className += " noTopBorder noBottomBorder";
		newsSearchBar.className += " noTopBorder";
	}
}
var statusSet = function()
{
	status = "中国教材图书网 - 中国最专业的网上教材书店!";
}
var imgSet = function()
{
	var imgs = document.images;
	for(var i=0;i<imgs.length;i++)
	{
		if((parseInt(imgs[i].style.width)==85 || imgs[i].width==85) && (parseInt(imgs[i].style.height)==125 || imgs[i].height==125) && !imgs[i].src) imgs[i].src='../images/siteImage/no-pic.jpg';
	}
}
var toTop = function()
{
	window.scrollTo(0,0);
}


//-------------------------------------------//

//event
var Event = {
	get: function(e)
	{
		return e || window.event;
	},
	X: function(e)
	{
		var e = this.get(e);
		return e.pageX || (e.clientX + (document.body.scrollLeft || document.documentElement.scrollLeft));
	},
	Y: function(e)
	{
		var e = this.get(e);
		return e.pageY || (e.clientY + (document.body.scrollTop || document.documentElement.scrollTop));
	}
}
//// drag
var drag = {
	_xoff: 0,
	_yoff: 0,
	_obj: null,
	load: function(element)
	{
		if(!$(element)) return;
		var element = $(element);
		element.onmouseover = function()
		{
			this.style.cursor = "move";
		}
		var d = this;
		element.onmousedown = function(e)
		{
			this.style.cursor = "move";
			d._xoff = parseInt(this.style.left) - Event.X(e);
			d._yoff = parseInt(this.style.top) - Event.Y(e);
			d._obj = this;
			return false;
		}
		element.onmouseup = function()
		{
			d._obj = null;
		}
	}
}
document.onmousemove = function(e)
{
	if(drag._obj)
	{
		drag._obj.style.left = drag._xoff + Event.X(e) + "px";
		drag._obj.style.top = drag._yoff + Event.Y(e) + "px";
		return false;
	}
}
/*---------------------------------------------------------------*/
window.onerror = function(){return true;}