(function(){
	var $  = function(o) { return typeof(o) == 'string' ? document.getElementById(o) : o; };
	var $C = function(s) { return document.createElement(s); };
	var $E = function(e) { tempObj = e.target ? e.target : event.srcElement; return tempObj; };
	var addEvent = function (elm, evType, fn, useCapture){
		if (elm.addEventListener) {
			elm.addEventListener(evType, fn, useCapture);
			return true;
		} else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		} else {
			elm['on' + evType] = fn;
		}
	};
	var delEvent = function(elm, evType, fn, useCapture){
		if (elm.removeEventListener) {
			elm.removeEventListener(evType, fn, useCapture);
			return true;
		} else if (elm.detachEvent) {
			var r = elm.detachEvent('on' + evType, fn);
			return r;
		} else {
			elm['on' + evType] = null;
			return;
		}
	};
	Function.prototype.bind=function(object,args){
	  args=args==null?[]:args;
	  var __method=this;
	  return function(){__method.apply(object,args)}
	};
	var LoginSelect = {
		iForm : "showLogin",
		iUser : "username",
		iPass : "password",
		iFldselect : "loginFldselect",
		iFldselectdis : null,
		iValObj : null,
		OptList : null,
		option : [
			{text:"通行证",value:"passport",action:"http://passport.eastmoney.com/BLogin.EmUser",un:"loginuname",pw:"loginpass"},
			{text:"",value:"",action:"",un:"",pw:""},
			{text:"第一内参",value:"dync",action:"http://www.caopanmima.com/caopanmimap/dyncs/default.aspx",un:"u",pw:"p"},
			{text:"财富报告",value:"cfbg",action:"http://product.eastmoney.com/shouye_dengru.aspx?action=yes",un:"user_username",pw:"user_pass"},
			{text:"09四季度报告",value:"baogao2",action:"http://caifumima.eastmoney.com/tzbgd/default.aspx",un:"u",pw:"p"}
		],
		init:function(){
			var loginFldselectBar = $C("div");
			loginFldselectBar.className = "loginFldselectBar";
			
			this.iFldselectdis = $C("span");
			this.iFldselectdis.id = "loginFldselectdis";
			this.iFldselectdis.innerHTML = this.option[0].text;
			loginFldselectBar.appendChild(this.iFldselectdis);
			
			var icoSplit = $C("span");
			icoSplit.className = "ico split";
			loginFldselectBar.appendChild(icoSplit);
			var icoDown = $C("span");
			icoDown.className = "ico down";
			loginFldselectBar.appendChild(icoDown);
	
			$(this.iFldselect).innerHTML = "";
			$(this.iFldselect).appendChild(loginFldselectBar);
			addEvent(loginFldselectBar,"click",this.clickLoginSelect.bind(this));
			
			this.OptList = $C("ul");
			this.OptList.className = "loginFldselectop";
			this.OptList.style.display = "none";
			var _optList = "";
			for(var i in this.option){
				if(this.option[i].value == "" && this.option[i].text == ""){
					_optList+="<li class=\"loginFldselectop_line\"></li>";
				}else{
					_optList+="<li><a onclick=\"LoginSelect.Select('"+this.option[i].value+"')\" target=\"_self\" href=\"javascript:void(0);\">"+this.option[i].text+"</a></li>";
				}
			}
			this.OptList.innerHTML = _optList;
			$(this.iFldselect).appendChild(this.OptList);
					
			this.iValObj = $C("input");
			this.iValObj.type = "hidden";
			this.iValObj.name = "select1";
			$(this.iFldselect).appendChild(this.iValObj);
		},
		clickLoginSelect:function(){
			if(this.OptList.style.display == "block"){
				this.LoginSelectClose();
			}else{
				this.OptList.style.display = "block";
				addEvent(document.body,"mousedown",this.LoginSelectClickOther);
			}
		},
		LoginSelectClickOther:function (e){
			thisObj = e.target?e.target:event.srcElement;
			do{
				if(thisObj.id == "loginFldselect" || thisObj == $("user_pass")) return;
				if(thisObj.tagName == "BODY"){LoginSelect.LoginSelectClose();return;};
				thisObj = thisObj.parentNode;
			}while(thisObj.parentNode);
		},
		LoginSelectClose:function (){
			this.OptList.style.display = "none";
			delEvent(document.body,"mousedown",this.LoginSelectClickOther);
		},
		Select:function (title){
			var titleName;
			for(var i in this.option){
				if(this.option[i].value == title){
					titleName = this.option[i].text;
					this.iValObj.value = this.option[i].value;
					$(this.iForm).action = this.option[i].action;
					$(this.iUser).name = this.option[i].un;
					$(this.iPass).name = this.option[i].pw;
					break;
				}
			}
			this.iFldselectdis.innerHTML = titleName;
			this.LoginSelectClose();
		}
	};
	window.LoginSelect = LoginSelect;
})();
