var _Script=document.getElementsByTagName("script");
var _Path=_Script[_Script.length-1].src.substring(0,_Script[_Script.length-1].src.lastIndexOf("/")+1);

var childCreate=false;
function Offset(e){
	//取标签的绝对位置
	var t = e.offsetTop;
	var l = e.offsetLeft;
	var w = e.offsetWidth;
	var h = e.offsetHeight+1;
	while(e=e.offsetParent){
		t+=e.offsetTop;l+=e.offsetLeft;
	}return {
		top : t,
		left : l,
		width : w,
		height : h
	}
}
function loadSelect(obj){
	var offset=Offset(obj);//取得Select所在的位置
	obj.style.display="none";//将真的select隐藏
	var iDiv = document.createElement("div");//虚拟一个div代替select
	iDiv.id="selectof" + obj.name;
	iDiv.style.position = "absolute";
	iDiv.style.width=offset.width + "px";
	iDiv.style.height=offset.height + "px";
	iDiv.style.top=offset.top + "px";
	iDiv.style.left=offset.left + "px";
	iDiv.style.background="url("+_Path+"images/droparrow.gif) no-repeat right -0px";
	iDiv.style.border="1px solid #7E3E00";
	iDiv.style.fontSize="14px";
	iDiv.style.color="#444";
	iDiv.style.cursor="pointer";
	iDiv.style.lineHeight=offset.height + "px";
	iDiv.style.textIndent="4px";
	document.body.appendChild(iDiv);
	var tValue=obj.options[obj.selectedIndex].innerHTML;//将select中默认的选项显示出来
	iDiv.innerHTML=tValue;
	//模拟鼠标点击
	iDiv.onmouseover=function(){iDiv.style.background="url("+_Path+"images/droparrow.gif) no-repeat right -0px";}
	iDiv.onmouseout=function(){iDiv.style.background="url("+_Path+"images/droparrow.gif) no-repeat right -0px";}
	iDiv.onclick=function(){//鼠标点击
		if (document.getElementById("selectchild" + obj.name)){//判断是否创建过div
			if (childCreate){//判断当前的下拉是不是打开状态，如果是打开的就关闭掉。否则打开。
				document.getElementById("selectchild" + obj.name).style.display="none";childCreate=false;
			}else{
				document.getElementById("selectchild" + obj.name).style.display="";childCreate=true;
			}
		}else{//初始一个div放在上一个div下边，当options的替身。
			var cDiv = document.createElement("div");
			cDiv.id="selectchild" + obj.name;
			cDiv.style.position = "absolute";
			cDiv.style.width=offset.width + "px";
			cDiv.style.height=obj.options.length *20 + "px";
			cDiv.style.top=(offset.top+offset.height+1) + "px";
			cDiv.style.left=offset.left + "px";
			cDiv.style.background="#FFF2E6";
			cDiv.style.border="1px solid #7E3E00";
			cDiv.style.fontSize="14px";
			var uUl = document.createElement("ul");
			uUl.id="uUlchild" + obj.name;
			uUl.style.listStyle="none";
			uUl.style.margin="0";
			uUl.style.padding="0";
			cDiv.appendChild(uUl);
			document.body.appendChild(cDiv);  
			childCreate=true;
			for (var i=0;i<obj.options.length;i++){//将原select标签中的options添加到li中
				var lLi=document.createElement("li");
				lLi.id=obj.options[i].value;
				lLi.style.textIndent="4px";
				lLi.style.height="20px";
				lLi.style.lineHeight="20px";
				lLi.style.cursor="pointer";
				lLi.style.fontSize="14px";
				lLi.style.color="#444";
				lLi.innerHTML=obj.options[i].innerHTML;
				uUl.appendChild(lLi);
			}
			var liObj=document.getElementById("uUlchild" + obj.name).getElementsByTagName("li");
			for (var j=0;j<obj.options.length;j++){//为li标签添加鼠标事件
				liObj[j].onmouseover=function(){
					this.style.background="#FFCFA4";this.style.color="white";
				}
				liObj[j].onmouseout=function(){this.style.background="#FFF2E6";this.style.color="black";}
				liObj[j].onclick=function(){//将选择的值保存到原select中。
					obj.options.length=0;obj.options[0]=new Option(this.innerHTML,this.id);
					document.getElementById("selectchild" + obj.name).style.display="none";//关闭下拉。
					childCreate=false;iDiv.innerHTML=this.innerHTML;
				}
			}
		}
	}
}
function hideSelect(name){
	var sName=name.split("|")
	for(n=0;n<sName.length;n++){
		document.getElementById("selectof" + sName[n]).style.display="none"
	}
}
function showSelect(name){
	var sName=name.split("|")
	for(n=0;n<sName.length;n++){
		document.getElementById("selectof" + sName[n]).style.display=""
	}
}
//document.onclick=hideCalendar;
