//==============================================================
if (!window.T){ T = {} }

T.$=function(a){return typeof(a)=='string'?document.getElementById(a):a};
//==============================================================
T.SetElemProgidAlpha = function(elem, n)
{
//elem.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=0,opacity="+n+")";
if (!n) n=70;
elem.style.filter="Alpha(opacity="+n+")";
elem.style.MozOpacity = ""+n/100;
}

T.CreateTopMaskDIV = function(alphaNum)
{
	/*
	if (window!=window.top)
	{
		 top.T.CreateTopMaskDIV(alphaNum);
		 return;
	}*/
	var _$Dmask = document.createElement("DIV");

	T.WinResizeMaskFull(_$Dmask);

    _$Dmask.style.position = "absolute";
    _$Dmask.setAttribute("id","DOM_T_DOMmaskDIV");
    _$Dmask.style.left = _$Dmask.style.top = "0px";
    _$Dmask.style.zIndex = 1000;
    _$Dmask.style.backgroundColor = "#F2F2F2"; // #EEEEEE #F2F2F2 #F3F9E8 #E7E4E2 #E7E9E4 #F2F2F2
    _$Dmask.onselectstart = function(){return false}
    
    document.body.appendChild(_$Dmask);
	T.SetElemProgidAlpha(_$Dmask, alphaNum);

	//window.attachEvent('onresize',T.WinResizeMaskFull);
}

/************************************************************
border:3px solid #38A8E4
*************************************************************/
T.CreateTopFrame = function(PO) {
    if (window != window.top) {
        top.T.CreateTopFrame(PO);
        return;
    }
    PO.w = PO.w || 455;
    PO.h = PO.h || 455;
    PO.name = PO.name || 'DOM_T_TopFrame';

    var d = document.createElement("IFRAME");
    d.setAttribute("id", PO.name);
    d.setAttribute("name", PO.name);
    var ds = d.style;
    ds.position = "absolute";
    ds.zIndex = 1001;
    ds.top = "40%";
    ds.left = "50%";
    ds.width = PO.w + "px";
    ds.height = PO.h + "px";
    ds.marginTop = -parseInt(PO.h / 2) + document.documentElement.scrollTop + "px"; //"-180px";
    ds.marginLeft = -parseInt(PO.w / 2) + "px";
    ds.backgroundColor = "transparent";
    //ds.border = PO.border||"3px solid #38A8E4";
    d.frameBorder = d.frameSpacing = 0;
    d.scrolling = d.scrolling = "no";
    d.allowTransparency = d.allowTransparency = "true";
    document.body.appendChild(d);
    d.src = PO.src;

    T.ScrollFrameToCenter();
}

T.ResizeFrame =  function(h)
{
    var name = 'DOM_T_TopFrame';
    var d = document.getElementById(name);
    d.style.height = h +"px";
}

T.fireLogin_BackOnCancel = 0;
T.CreateLoginFrameWin = function(param, _$cancelBack) {
    if (_$cancelBack == 1) T.fireLogin_BackOnCancel = 1;
    else T.fireLogin_BackOnCancel = 0;

    T.CreateTopMaskDIV(40);
    
    var requestUrl = document.location;
    if (param != null && param.url.length > 0)
        requestUrl = param.url;
        
    var PO = {
        w: 370, h: 385, src: '/MyAccount/PopupLogin.aspx?RequestUrl=' + requestUrl,
        border: '3px solid #38A8E4'
    }

    T.CreateTopFrame(PO);
    var _$allSelect = document.getElementsByTagName("SELECT");
    for (var i = 0; i < _$allSelect.length; i++) {
        if (_$allSelect[i].style.display != "none" && _$allSelect[i].style.visibility != "hidden") {
            _$allSelect[i].style.visibility = "hidden";
            _$allSelect[i]._visibility = 1;
        }
    }

    if (T.$('DOM_mainFrame')) {
        try {
            T.$('DOM_mainFrame').contentWindow.$('EMBED').each(function() { this.style.visibility = "hidden" });
        } catch (e) { }
    }
    var sttime;
    window.onscroll = function() {
        window.clearTimeout(sttime);
        sttime = window.setTimeout(T.ScrollFrameToCenter, 100);
    }
}

T.ScrollFrameToCenter=function()
{
	//XHTML下使用 document.documentElement ,html下使用 document.body
	T.$('DOM_T_TopFrame').style.marginTop = -180 + document.documentElement.scrollTop+"px";
}

T.WinResizeMaskFull = function(dom)
{
	var d=T.$('DOM_T_DOMmaskDIV')||dom;
	if (d)
	{
		try{
			d.style.width = document.documentElement.clientWidth+"px";
			d.style.height = document.documentElement.scrollHeight+"px";//clientHeight //window.screen.height;//
		}catch(e){}
	}
}

T.CancelTopFrame = function(noClear)
{
	//window.detachEvent('onresize',T.WinResizeMaskFull);
	window.onscroll = function(){}
    //T.SetCookie('gULS','-1',new Date(new Date().getTime()+1000*60*60*6),'/','qbar.qq.com');
    if (T.fireLogin_BackOnCancel==1)
    {
        if (window.history.length>0) window.history.back();
        else window.location.replace(BASE);
        T.fireLogin_BackOnCancel = 0;
    }
    var _$domdiv = document.getElementById("DOM_T_DOMmaskDIV");
    //if (_$domdiv) { _$domdiv.removeNode(true) }
    if (_$domdiv){document.body.removeChild(_$domdiv)}
    var _$loginFrame = document.getElementById("DOM_T_TopFrame");
    //if (_$loginFrame) { _$loginFrame.removeNode(true) }
    if (_$loginFrame){document.body.removeChild(_$loginFrame)}
    
    //特殊处理关掉浮动登录框之后主窗口无法聚焦的问题
    var a = document.createElement("input");
    a.style.position = "absolute";
    a.style.top = document.body.scrollTop;
    document.body.appendChild(a);
    try{a.focus()}catch(e){}finally{}
    //a.removeNode(true);
    document.body.removeChild(a);

    var _$allSelect = document.getElementsByTagName("SELECT");
    for (var i=0; i<_$allSelect.length; i++)
    {
        if (_$allSelect[i]._visibility == 1)
        {
            _$allSelect[i].style.visibility="inherit";
            _$allSelect[i]._visibility = 0;
        }
    }

	if(T.$('DOM_mainFrame'))
	{
		try{	
		T.$('DOM_mainFrame').contentWindow.$('EMBED').each(function(){this.style.visibility="inherit"});
		}catch(e){}
	}

	try{
		if(!noClear)top.T.afterLoginRS = "";
	}catch(e){}
}

T.CancelLoginWin = T.CancelTopFrame;

if(!T.GetQBarPath)
{
	T.GetQBarPath = function(_$spath)
	{	
		_$spath = _$spath || window.location.href;
/*
		if(window.BASE)return window.BASE.replace('http://','');

		var a=_$spath.replace('http://','').split('/')
		if(a.length==1)_$spath=a[0]
		else if(a.length>1)_$spath=a[0]+'/'+a[1]
		
		return _$spath+'/';
		*/
	}
}