document.domain="qq.com"
var g_myBodyInstance = null;
var g_init   = null;
var isMinNS4 = null;
var isMinNS5 = null;
var isMinIE4 = null;
var isMinIE5 = null;


function getWindowWidth()
{
	if (isMinIE4||isMinNS5)
		return (g_myBodyInstance.clientWidth);
	else if (isMinNS4)
		return (window.innerWidth);
	return (-1);
}

function getWindowHeight()
{
	if (isMinIE4||isMinNS5)
		return (g_myBodyInstance.clientHeight);
	else if (isMinNS4)
		return(window.innerHeight);
	
	return(-1);
}

function getWidth(layer)
{
	if (isMinIE4||isMinNS5)
	{
		if (layer.style.pixelWidth)
			return (layer.style.pixelWidth);
		else
			return (layer.clientWidth);
	}
	else if (isMinNS4)
	{
		if (layer.document.width)
			return (layer.document.width);
		else
			return (layer.clip.right - layer.clip.left);
	}
	
	return (-1);
}

function getHeight(layer)
{
	if (isMinIE4||isMinNS5)
	{
		if (false && layer.style.pixelHeight)
			return (layer.style.pixelHeight);
		else
			return (layer.clientHeight);
	}
	else if (isMinNS4)
	{
		if (layer.document.height)
			return (layer.document.height);
		else
			return (layer.clip.bottom - layer.clip.top);
	}
	
	return(-1);
}

function getPageScrollY()
{
	if (isMinIE4||isMinNS5)
		return (g_myBodyInstance.scrollTop);
	else if (isMinNS4)
		return (window.pageYOffset);
	
	return (-1);
}

function moveLayerTo(layer, x, y)
{
	if (isMinIE4)
	{
		layer.style.left = x;
		layer.style.top  = y;
	}
	else if (isMinNS5)
	{
		layer.style.left = x+'px';
		layer.style.top  = y+'px';
	}
	else if (isMinNS4)
    	layer.moveTo(x, y);
}


function ptlogin2_onResize(width, height)
{	
	login_wnd = document.getElementById("login_div");
	if (login_wnd)
	{
		login_wnd.style.width = width + "px";
		login_wnd.style.height = height + "px";

		//确定位置
		if ( getWindowWidth() != getWidth(login_wnd) )
		{
			moveLayerTo(login_wnd,(getWindowWidth()-getWidth(login_wnd))/2,getPageScrollY()+(getWindowHeight()-getHeight(login_wnd))/2);
		}
		
		login_wnd.style.visibility = "hidden"
		login_wnd.style.visibility = "visible"
	}
}

function ptlogin2_onClose()
{
	login_wnd = document.getElementById("login_div");	
	login_wnd.style.display="none";
	$('body').unblock().css({"overflow-y":"auto"});		
}

function openLogin(aid)
{
	ptlogin2_form();
	login_wnd = document.getElementById("login_div");
	if (login_wnd != null){
		
		login_wnd.style.visible = "hidden"	//先隐藏，这样用户就看不到页面的尺寸变化的效果
		login_wnd.style.display = "block"	//设为block， 否则页面不会真正载入		
		var argv = openLogin.arguments
		if ( argv[1] )
		{
			surl = argv[1];
		}
		else
		{
			surl = window.location;
		}		
		
		var url = "http://ui.ptlogin2.qq.com/cgi-bin/login" + "?"
		url += "f_url=loginerroralert"
		url += "&style=1"
		url += "&appid="  + aid
	  url += "&s_url="  + escape(surl)	
		
		document.getElementById("login_frame").src = url;
	}
	login_wnd.style.display="block";
}


function ptlogin2_form()
{
	if ( !g_init )
	{
		g_myBodyInstance = document.body;
		isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 && parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
		isMinNS5 = (navigator.appName.indexOf("Netscape") >= 0 && parseFloat(navigator.appVersion) >= 5) ? 1 : 0;
		isMinIE4 = (document.all) ? 1 : 0;
		isMinIE5 = (isMinIE4 && navigator.appVersion.indexOf("5.") >= 0) ? 1 : 0;
		isMacIE = (isMinIE4 && navigator.userAgent.indexOf("Mac") >= 0) ? 1 : 0;
		isOpera = (navigator.appName.indexOf("Opera") >= 0) ? 1 : 0;	
		if (document.compatMode != "BackCompat" && !isOpera )
		{	 
		    g_myBodyInstance = document.documentElement;
		}
		var div_=document.getElementById('login_div');
		//alert(g_myBodyInstance.id);
		if(!div_)
		{
			var div=document.createElement('div'); 
			div.id="login_div";
			div.style.display="none";
			div.style.position="absolute";
			div.style.left="40%";
			div.style.top="50%";
			div.style.width="400px";
			div.style.height="330px";
			div.style.padding="0";
			div.style.margin="0";
			div.style.zIndex="99";
			
			div.innerHTML="<iframe name=\"login_frame\" id=\"login_frame\" frameborder=\"0\" scrolling=\"auto\" width=\"100%\" height=\"100%\" src=\"\"></iframe>";
			document.body.appendChild(div);
		}

		g_init = true;
	}	

}

