﻿var g_aryTargets = [];

// 弹出快速登录窗口
function LoginFirst(strKey, iWidth, iHeight)
{
	var objQuickLogin = new QuickLogin();
	objQuickLogin.Show(strKey, iWidth, iHeight);
};

// 快速登陆窗口类
var QuickLogin = function()
{
	this.Show = function(strKey, iWidth, iHeight)
	{		
		var hdivIframeWrap = document.createElement('div');
		hdivIframeWrap.id = 'hdivQuickLoginIframeWrap';
		hdivIframeWrap.style.zIndex = 20;
		var thisIframe = document.createElement('iframe');
		thisIframe.id = 'iframeQuickLogin';
		thisIframe.src = 'http://www.popsheep.cn/QuickLogin.aspx?CK=' + strKey;
		thisIframe.width = iWidth;
		thisIframe.height = iHeight;
		thisIframe.scrolling = 'no';
		thisIframe.frameBorder = 0;
		thisIframe.allowTransparency = 'true';
		hdivIframeWrap.appendChild(thisIframe);
		document.body.appendChild(hdivIframeWrap);
		
		var iTop = document.documentElement.clientHeight / 2 - iHeight / 2;
		var iLeft = document.body.clientWidth / 2 - iWidth / 2;
		FixedPosition(hdivIframeWrap, iTop, iLeft);
	}
}

var FixedPosition = function(hdivTarget, iTop, iLeft)
{
	hdivTarget.style.display = "block";
	
	hdivTarget.style.top = iTop +"px";
	if(iLeft != null)
	{
		hdivTarget.style.left = iLeft +"px";
	}
	
	if (IsIe6())
	{
		hdivTarget.style.position = "absolute";
		var objTarget = [];
		objTarget.push(hdivTarget);
		objTarget.push(iTop);
		g_aryTargets.push(objTarget);
		FixedPosition.SetGlobal();
	}
	else
	{
		hdivTarget.style.position = "fixed";
	}
}

FixedPosition.SetGlobal = function(){
	window.attachEvent("onscroll",OnScroll);
}

var IsIe6 = function()
{
	return(navigator.userAgent.toLowerCase().indexOf('msie 6') != -1);
}

// 窗口滚动时
var OnScroll = function()
{
	for(var i = 0; i < g_aryTargets.length; i++)
	{
		g_aryTargets[i][0].style.top = (document.documentElement.scrollTop) + g_aryTargets[i][1] + "px";
	}
}

// 获得系统事件
function GetEvent()
{
	if (document.all)
	{
		return window.event;
	}
	
	// 递归查找产生Event或MouseEvent的事件，取event返回
	var functionTag = GetEvent.caller;
	while(functionTag != null)
	{
		var arg = functionTag.arguments[0];
		if(arg)
		{
			if(arg.constructor == Event || arg.constructor == MouseEvent || arg.constructor == KeyboardEvent)
			{
				return arg;
			}
		}
		functionTag = functionTag.caller;
	}
	return null;
}

// 获取产生事件的对象
function GetEventTarget()
{
	if(document.all)
	{
		return GetEvent().srcElement;
	}
	else
	{
		return GetEvent().target;
	}
}

// 阻止事件传播
function StopEventSpread(objEvent)
{
	if(document.all)
	{
		objEvent.cancelBubble = true;
	}
	else
	{
		objEvent.stopPropagation();
	}
}

function FloatAd(strImageSrc, strLinkUrl, bLeft, iLeft, iHeight)
{
	var hdivAdWrap = document.createElement('div');
	if(bLeft)
	{
		hdivAdWrap.style.left = iLeft +"px";
	}
	else
	{
		hdivAdWrap.style.right = iLeft +"px";
	}	
	hdivAdWrap.style.zIndex = 20;
	
	var hdivImageWrap = document.createElement('div');
	hdivImageWrap.style.zIndex = 22;
	hdivAdWrap.appendChild(hdivImageWrap);
	
	var link = document.createElement("a");
	link.href = strLinkUrl;
	hdivImageWrap.appendChild(link);
	
	var img = document.createElement("img");
	img.src = strImageSrc;
	link.appendChild(img);
	
	var hdivClose = document.createElement('div');
	hdivClose.className = 'a';
	hdivClose.style.position = 'absolute';
	hdivClose.style.right = '3px';
	hdivClose.style.top = '5px';
	hdivClose.style.width = '19px';
	hdivClose.style.height = '19px';
	hdivClose.style.zIndex = 25;
	hdivClose.style.cursor = 'pointer';
	hdivClose.onclick = CloseAd;
	hdivAdWrap.appendChild(hdivClose);
	
	img = document.createElement("img");
	img.src = 'http://www.popsheep.cn/Images/CloseFloatAd.jpg';
	img.width = 19;
	img.height = 19;
	hdivClose.appendChild(img);
	
	document.body.appendChild(hdivAdWrap);
	var iTop = document.documentElement.clientHeight / 2 - iHeight / 2;
	FixedPosition(hdivAdWrap, iTop);
};

function CloseAd()
{
	var hdivClose = GetEventTarget();
	hdivClose.parentNode.parentNode.parentNode.removeChild(hdivClose.parentNode.parentNode);
}
