function mdiv (){
	this.root;//选择框
	this.selroot;//选择框选中后更改的区域
	this.seldiv;//浮动层最外层
	this.cnt;//选项最外层,所有选项都要添加到这里
	this.length = 0;//选项数量；
	this.value;//当前选项值
	this.items = [];//所有选项
	this.selectIndex = 0;//当前选项序号
	this.onchange = function (){};//选择事件函数
	//alert(this.selectIndex);
}
mdiv.activeDiv = null;
mdiv.curRoot = null;
mdiv.prototype.isIE=function (){
	return (navigator.userAgent.toLowerCase().indexOf("ie")  > -1);
}
mdiv.prototype.getOffset=function (element){//计算对象在页面上的位置
	  var valueT = 0, valueL = 0; 
	  do {valueT += element.offsetTop || 0; 
		valueL += element.offsetLeft || 0; 
		element = element.offsetParent; }
		while (element); 
	  return [valueL, valueT];	
}
mdiv.prototype.init=function (root,selroot) {
	var me = this;
	me.root = root;
	me.selroot = selroot || root;
	me.seldiv = mdiv.Create("div",false,"mdiv");
	me.cnt = mdiv.Create("div",me.seldiv);
	me.seldiv.style.display = "none";
	try{
		document.attachEvent("onmousedown",function(){me.disdiv();});
	}
	catch (ex){
		document.addEventListener("mousedown",function(){me.disdiv();}, false);
	}
	
	me.root.onclick = function (){
		me.show();
		me.HideSome();
		me.autoHeight();
	}
	
	
	
}
mdiv.prototype.select=function (obj) 
{
	var me = this;
	var value = obj.getAttribute("sel_value");
	me.value = value;
	me.selectIndex = obj.getAttribute("sel_index");
	me.selroot.style.padding = 0;
	me.selroot.innerHTML = obj.innerHTML;
	me.onchange();
	me.hide();	
}
mdiv.prototype.show=function () 
{
	var me = this;
	var pos = me.getOffset(me.root);
	var seldiv = me.seldiv;
	if(seldiv.style.display != "none"){
		seldiv.style.display = "none";
		return;
	}
	var ss=seldiv.style;
	ss.clear="both";
	ss.background="#fff";
	ss.border="solid 1px #FF9933";
	ss.borderTop="none";
	ss.position = "absolute";
	
	ss.left = pos[0] +1+ "px";
	ss.top= pos[1] + me.root.offsetHeight + "px";
	//ss.maxHeight="200px";
	ss.overflow="auto";
	ss.zIndex="1";
	//alert(pos[1]);
	ss.width = (me.root.offsetWidth-((document.compatMode == "BackCompat")?0:2)-1 )+ "px";
	//alert(ss.width);
	ss.display = "";
}
mdiv.prototype.hide=function () {
	var me = this;
	me.seldiv.style.display = "none";
}
mdiv.prototype.disdiv=function () {
	var me = this;
	//alert(me.seldiv.style.display);
	if(me.seldiv.style.display != "none"){
		me.hide();
	}
	me.ShowSome();
}
mdiv.prototype.add=function (obj,cssHover,value,selected) {
	var me=this;
	me.items.push(obj);
	obj.setAttribute("sel_value",value);
	try{
		me.cnt.appendChild(obj);
		me.length = me.items.length;
		var index = me.items.length - 1;
		obj.setAttribute("sel_index",index);
		obj.onmouseover=function(){
			obj.setAttribute("cssBack",obj.className);
			obj.className = obj.className + cssHover;
		}
		obj.onmouseout = function(){
			obj.className = obj.className.replace(cssHover,"");
		}
		obj.onmousedown = function(){
			me.select(obj);
		}	
	}
	catch(ex){}
	if(selected){
		me.select(obj);	
	}
}
mdiv.Create=function (str,parentObj,cssName){
	var obj=document.createElement(str);
	if(parentObj)
	{parentObj.appendChild(obj);}
	else
	{document.body.appendChild(obj);}
	if(cssName)obj.className=cssName;
	return obj;
}//简化
mdiv.prototype.autoHeight=function(){};
mdiv.prototype.HideSome=function(){};
mdiv.prototype.ShowSome=function(){};

var mdiv_ly = new mdiv();           //修改3
var mdiv_by = new mdiv();
//var mdiv_ay = new mdiv();
var mdiv_ey = new mdiv();
var mdiv_fy = new mdiv();
//页面输出
window.onload = function () {
    mdiv_ly.init(G('self'), G('lbarea_ly'));     //修改1
    Creately();
    mdiv_by.init(G('selby'), G('lbarea_by'));
    Createby();
    //mdiv_ay.init(G('selay'), G('lbarea_ay'));
    //Createay();
    mdiv_ey.init(G('selfey'), G('lbarea_ey'));
    Createey();
    mdiv_fy.init(G('selffy'), G('lbarea_fy'));
    Createfy();
    
    //alert($('#aaaa').html())
}
function G(id) {
    return document.getElementById(id);
}

mdiv.prototype.HideSome = function () {
    if (G('ft')) G('ft').id = "dropTemp";
}
mdiv.prototype.ShowSome = function () {
    if (G('dropTemp')) G('dropTemp').id = "ft";
}

function CreateHDiv(T, cV)            //修改4
{
    var c = document.createElement("div");
    c.innerHTML = '<div style="cursor:pointer;text-align:left;margin:2px 0px 2px 7px;overflow:hidden;">' + T + '<div style="WIDTH:0;display:none">\\' + cV + '</div></div>';
    mdiv_ly.add(c, "color_over", cV);
}
function CreateIDiv(T, cV) {
    var c = document.createElement("div");
    c.innerHTML = '<div style="cursor:pointer;text-align:left;margin:2px 0px 2px 7px;overflow:hidden;">' + T + '<div style="WIDTH:0;display:none">\\' + cV + '</div></div>';
    mdiv_by.add(c, "color_over", cV);
}
function CreateADiv(T, cV) {
    var c = document.createElement("div");
    c.innerHTML = '<div style="cursor:pointer;text-align:left;margin:2px 0px 2px 7px;overflow:hidden;">' + T + '<div style="WIDTH:0;display:none">\\' + cV + '</div></div>';
    mdiv_ay.add(c, "color_over", cV);
}
function CreateEDiv(T, cV) {
    var c = document.createElement("div");
    c.innerHTML = '<div style="cursor:pointer;text-align:left;margin:2px 0px 2px 7px;overflow:hidden;">' + T + '<div style="WIDTH:0;display:none">\\' + cV + '</div></div>';
    mdiv_ey.add(c, "color_over", cV);
}
function CreateFDiv(T, cV) {
    var c = document.createElement("div");
    c.innerHTML = '<div style="cursor:pointer;text-align:left;margin:2px 0px 2px 7px;overflow:hidden;">' + T + '<div style="WIDTH:0;display:none">\\' + cV + '</div></div>';
    mdiv_fy.add(c, "color_over", cV);
}


function Creately() {                             //修改5
    CreateHDiv('题&nbsp;&nbsp;名', 'title');
    CreateHDiv('责任者', 'author');
    CreateHDiv('主题词', 'keyword');
    CreateHDiv('ISBN/ISSN', 'isbn');
    CreateHDiv('订购号', 'asordno');
    CreateHDiv('分类号', 'coden');
    CreateHDiv('索书号', 'callno');
    CreateHDiv('出版社', 'publisher');
    CreateHDiv('丛书名', 'series');
    CreateHDiv('题名拼音', 'tpinyin');
    CreateHDiv('责任者拼音', 'apinyin');
    mdiv_ly.select(mdiv_ly.items[0]);
}
function Createby() {
    CreateIDiv('标题', 'title');
    CreateIDiv('作者', 'author');
    CreateIDiv('全文', 'full_text');
    CreateIDiv('关键词', 'keyword');
    CreateIDiv('主题', 'subject');
    CreateIDiv('摘要', 'abstract');
    CreateIDiv('ISBN', 'isbn');
    CreateIDiv('ISSN', 'issn');
    CreateIDiv('任何', 'any');
    mdiv_by.select(mdiv_by.items[0]);
}
function Createay() {
    CreateADiv('中文文献', 'zh-CN');
    CreateADiv('外文文献', 'en-US');
    mdiv_ay.select(mdiv_ay.items[0]);
}
function Createey() {
    CreateEDiv('期刊名开头为', 'A_T_B');
    CreateEDiv('标题等于', 'A_T_M');
    CreateEDiv('标题包含所有词', 'T_W_A');
    CreateEDiv('ISSN 等于', 'I_M');
    //CreateEDiv('缩写刊名','exact');
    mdiv_ey.select(mdiv_ey.items[0]);
}
function Createfy() {
    CreateFDiv('标题', 'title');
    CreateFDiv('内容', 'content');
    mdiv_fy.select(mdiv_fy.items[0]);
}										