var login_body=false;
document.domain="qq.com";

function getCookie(name){
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr != null)
		return unescape(arr[2]);
	return "";
}

function deleteCookie(name){
	setCookie(name, "");
}

function setCookie(name,value){
	document.cookie = name + "=" + value + "; path=/; domain=qq.com";
}

function gid(id){
	return top.document.getElementById ? top.document.getElementById(id) : null;
}

function Browser()
{
	var ua, s, i;
	this.isIE = false;
	this.isNS = false;
	this.isOP = false;
	this.isSF = false;
	ua = navigator.userAgent.toLowerCase();
	s = "opera";
	if ((i = ua.indexOf(s)) >= 0)
	{this.isOP = true;return;}
	s = "msie";
	if ((i = ua.indexOf(s)) >= 0) 
	{this.isIE = true;return;}
	s = "netscape6/";
	if ((i = ua.indexOf(s)) >= 0)
	{this.isNS = true;return;}
	s = "gecko";
	if ((i = ua.indexOf(s)) >= 0) 
	{this.isNS = true;return;}
	s = "safari";
	if ((i = ua.indexOf(s)) >= 0) 
	{this.isSF = true;return;}
}
function gname(name)
{
	return top.document.getElementsByTagName?top.document.getElementsByTagName(name):new Array();
}
function StrCode(str)
{
	if(encodeURIComponent) 
	   return encodeURIComponent(str);
	if(escape) 
	   return escape(str);
}

function GetLogonContainer()
{
	return top.document.getElementById("logonContainer");
}

function ScreenConvert()
{	
	var browser = new Browser();
	var objScreen = gid("ScreenOver");
	if(!objScreen) {
		objScreen = top.document.createElement("div");
	}
	var oS = objScreen.style;
	objScreen.id = "ScreenOver";
	oS.display = "block";
	oS.top = oS.left = oS.margin = oS.padding = "0px";
	var wh;
	var ww;
	if (top.document.body.clientHeight)
	{
		wh = top.document.body.clientHeight + "px";
		ww = top.document.body.clientWidth + "px";
	}
	else if (top.innerHeight)
	{
		wh = window.innerHeight + "px";
		ww = window.innerWidth + "px";
	}
	else
	{
		wh = "100%";
		ww = "100%";
	}
	oS.width = ww; 
	oS.height = wh;
	oS.position = "absolute";
	oS.zIndex = "3";
	if ((!browser.isSF) && (!browser.isOP))
	{
		oS.background = "#000000";
	}
	else
	{
		oS.background = "#000000";
	}
	oS.filter = "alpha(opacity=40)";
	oS.opacity = 40/100;
	oS.MozOpacity = 40/100;
	//top.document.body.appendChild(objScreen);
	GetLogonContainer().appendChild(objScreen);
	
	var allselect = gname("select");
	for (var i=0; i<allselect.length; i++) 
		allselect[i].style.visibility = "hidden";
}
	
function DialogLoc()
{
	var dde = top.document.documentElement;
	if (top.innerWidth)
	{
		var ww = top.innerWidth;
		var wh = top.innerHeight;
		var bgX = top.pageXOffset;
		var bgY = top.pageYOffset;}
	else
	{
		var ww = dde.offsetWidth;
		var wh = dde.offsetHeight;
		var bgX = dde.scrollLeft;
		var bgY = dde.scrollTop;
	}
	t_DiglogX = (bgX + ((ww - t_DiglogW)/5));
	t_DiglogY = (bgY + ((wh - t_DiglogH)/3));
}

function DialogHide()
{
	var objDialog = top.document.getElementById("DialogMove");
	if (objDialog)
	  objDialog.style.display = "none";
	ScreenClean();	  
}
function ScreenClean()
{
  var objScreen = top.document.getElementById("ScreenOver");
  if (objScreen)
     objScreen.style.display = "none";
  var allselect = gname("select");
  for (var i=0; i<allselect.length; i++)
     allselect[i].style.visibility = "visible";
}

// 公司统一登陆开始
function ptlogin2_onResize(width, height)
{	
	login_wnd = document.getElementById("Qlogin_div");
	if (login_wnd)
	{
		login_wnd.style.visibility = "hidden"
		login_wnd.style.width = width + "px";
		login_wnd.style.height = height + "px";		
		login_wnd.style.visibility = "visible"
	}
}

function ptlogin2_onClose()
{
	login_wnd = document.getElementById("Qlogin_div");	

	login_wnd.style.display="none";
	DialogHide();
	login_body=false;
}

function QQopenLogin(urlparam)
{
	OpenLogin(urlparam, '');
}

function OpenLogin(urlparam, retURL)
{
	var url = "http://ui.ptlogin2.qq.com/cgi-bin/login" + "?" + urlparam;	
	login_wnd = document.getElementById("Qlogin_div");
	if (retURL == "")
	{		
		retURL = escape(escape(window.parent.location.href));
	}
	else
	{
		retURL = escape(escape(retURL));
	}

	if (login_wnd != null){
		login_wnd.style.display = "block";	//设为block， 否则页面不会真正载入	
		url += "qlogin_jumpname=jifen";		
		url += "&qlogin_param=url%3D" + retURL;		
		url += "&qlogin_auto_login=0";//1 为支持自动登陆
		url += "&style=0";
		url += "&appid=11000401&s_url=";
		url += escape(window.parent.location.href);

		document.getElementById("Qlogin_frame").src = url;
	}
}

function createLoginDialog(showdata,ow,oh,w,h)
{
	  var objDialog = top.document.getElementById("DialogMove");
	  if (!objDialog)
	  objDialog = top.document.createElement("div");
	  t_DiglogW = ow;
	  t_DiglogH = oh;
	  DialogLoc();
	  objDialog.id = "DialogMove";
	  var oS = objDialog.style;
	  oS.display = "block";
	  oS.top = t_DiglogY + "px";
	  oS.left = t_DiglogX + "px";
	  oS.margin = "0px";
	  oS.padding = "0px";
	  oS.width = w + "px";
	  oS.height = h + "px";
	  oS.position = "absolute";
	  oS.zIndex = "5";
	  
	  objDialog.innerHTML = showdata;																	
	  GetLogonContainer().appendChild(objDialog);
}

function QQDialogShow(showdata,ow,oh,w,h)
{
	createLoginDialog(showdata,ow,oh,w,h);
	QQopenLogin('');
}

function QQNeedLogin(Title)
{
  if(login_body==true)
     return;
  login_body=true;	 
  ScreenConvert();
  var AJAX_LoginBody="<div id=Qlogin_div style=\"display:none;  position:absolute; left: 50%; top: 0px; width:373px; height:280px; padding:0; margin:0px;\" align=\"center\"><iframe id=\"Qlogin_frame\" frameborder=\"0\" scrolling=\"no\" width=\"100%\" height=\"100%\" src=\"\"><\/iframe></div>";
  QQDialogShow(AJAX_LoginBody,221,147,373,280);
}

function LoginRetURL(retURL)
{
	if(login_body==true)
	{
		return;
	}
  
	login_body=true;	 
	ScreenConvert();
	var AJAX_LoginBody="<div id=Qlogin_div style=\"display:none;  position:absolute; left: 50%; top: 0px; width:373px; height:280px; padding:0; margin:0px;\" align=\"center\"><iframe id=\"Qlogin_frame\" frameborder=\"0\" scrolling=\"no\" width=\"100%\" height=\"100%\" src=\"\"><\/iframe></div>";
	createLoginDialog(AJAX_LoginBody,221,147,373,280);
	OpenLogin('',retURL);
}

// 公司统一登陆结束

