var $C = function(o){ return document.createElement(o);}
var $G = function (id) {return "string" == typeof id ? document.getElementById(id) : id;};
var Default={
	loginBox : null,
	htdsLoginShow:function(){
		var styleId = "loginMaskStyle";
		var _head = document.getElementsByTagName("head").item(0);
		var _old = document.getElementById(styleId);
		if (_old) _old.parentNode.removeChild(_old);

		var _ua=navigator.userAgent.toLowerCase();
		var version = _ua.split(";");
		var isIE6 = /msie 6/.test(version[1]);
		var styleStr = "";
		if(isIE6){
			styleStr += 'html{ overflow:hidden;}'+
						'body{ height:100%; overflow:hidden; position:relative;}'+
						'#loginMask { position:absolute; width:100%; height:100%; top:0; left:0; right:17px; z-index:9999;}'+
						'#loginMask .lM_mask { position:absolute; top:0; left:0; width:100%; height:100%; background:#CCC; filter:alpha(opacity=50);opacity:0.5;}';
		}else{
			styleStr += '#loginMask { position:fixed; width:100%; height:100%; top:0; left:0; z-index:9999;}'+
						'#loginMask .lM_mask { position:fixed; top:0; left:0; background:#CCC; width:100%; height:100%; filter:alpha(opacity=50);opacity:0.5;}';
		}
		styleStr += '#loginMask .lM_box { position:relative; width:100%; height:50%; z-index:10000; }'+
					'#loginMask .lM_box .lM_b_main { position:relative; width:500px; margin:0 auto; top:50%; border:1px solid #f9c869; border-top:2px solid #f9c869;}'+
					'#loginMask .lM_box .lM_b_main .title { border-bottom:1px solid #f9c869; font-size:14px; font-weight:bold; text-align:left; height:26px; line-height:26px; overflow:hidden; background:url(images/close.gif) repeat-x; color:#454545;}'+
					'#loginMask .lM_box .lM_b_main .title span { float:left; margin-left:12px;}'+
					'#loginMask .lM_box .lM_b_main .title .close { float:right; width:29px; height:15px; text-indent:-100px; background:url(images/close.gif) no-repeat 0 -27px; overflow:hidden; margin-right:6px;}'+
					'#loginMask img,#loginMask div,#loginMask form,#loginMask span{margin:0px;padding:0px;border:0px;overflow:visible;}';
		var mystyle = document.createElement("style");
		mystyle.type = "text/css";
		mystyle.id = styleId;
		if(mystyle.styleSheet){// IE
			mystyle.styleSheet.cssText = styleStr;
		} else {// w3c
			var cssText = document.createTextNode(styleStr);
			mystyle.appendChild(cssText);
		}
		_head.appendChild(mystyle);
		
		if(this.loginBox == null) {
			this.loginBox = $C("div");
			this.loginBox.id = "loginMask";
			this.loginBox.style.display = "none";
			this.loginBox.innerHTML = '	<div class="lM_mask"></div>\n'+
									  '	<div class="lM_box" id="lM_box">\n'+
									  '		<div class="lM_b_main">\n'+
									  '			<div class="title">\n'+
									  '				<span>东方财富网通行证</span>\n'+
									  '				<a href="javascript:void();" onclick="Default.htdsLoginClose();return false;" onfocus="this.blur();" class="close">关闭</a>\n'+
									  '			</div>\n'+
									  '			<iframe name="loginiFrm" id="loginiFrm" src="" width="500" height="300" frameborder="0"></iframe>\n'+
									  '		</div>\n'+
									  '	</div>\n';
			document.body.insertBefore(this.loginBox, document.body.firstChild);
		}
	},
	htdsLoginClose:function(){

		if(this.loginBox) this.loginBox.style.display = "none";

		var styleId = "loginMaskStyle";
		var _head = document.getElementsByTagName("head").item(0);
		var _old = document.getElementById(styleId);
		if (_old) _old.parentNode.removeChild(_old);

		return false;
	},
    htdsLogin:function(){
        var result = true;
        if (!Default.isChanged("loginuname")) {
            result = false;
        }
        if (!Default.isChanged("loginpass")) {
            result = false;
        }
        if (result) { 
			this.htdsLoginShow();
			var formObj = $G("loginform");
			formObj.action = "http://passport.eastmoney.com/HtdsLogin.EmUser?backurl=http://hftfund.eastmoney.com/";
			formObj.target = "loginiFrm";
            formObj.submit();
			
			if(this.loginBox) this.loginBox.style.display = "block";
        }else{
            alert("请输入用户名和密码!");
        }
    },
    isChanged: function(o){
        return $G(o).value.length > 0 && $G(o).value != $G(o).defaultValue;
    }
}


