var ppqu_login_status		= null;
var userAgent	= navigator.userAgent.toLowerCase();
var is_ie		= (userAgent.indexOf('msie') != -1);
var chatTop	= "60px";
function getObject(objName)
{
	if(document.getElementById)
	{
		return eval('document.getElementById("' + objName + '")');
	}
	else if(document.layers)
	{
		return eval("document.layers['" + objName +"']");
	}
	else
	{
		return eval('document.all.' + objName);
	}
}
function ajax()
{
	var a	= null;
	try
	{
		a	= new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			a	= new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			a	= null;
		}
	}
	if(!a && typeof XMLHttpRequest != "undefined")
	{
		a	= new XMLHttpRequest();
	}
	return a;
}
function login_ppqu()
{
	if(ppqu_login_status && ppqu_login_status.readyState!=0)
	{
		ppqu_login_status.abort()
	}
	ppqu_login_status	= ajax();
	if(ppqu_login_status)
	{
		ppqu_login_status.open("GET", "/login.php?nocache=" + Math.random(), true);
		ppqu_login_status.onreadystatechange	= function()
		{
			if(ppqu_login_status.readyState==4 && ppqu_login_status.responseText)
			{
				getObject('topmessage').innerHTML	= ppqu_login_status.responseText;
			}
		};
		ppqu_login_status.send(null);
	}
}
//---- COOKIE ----
function getExpTime(time, type)
{
	var expTime	= new Date();
	switch(type)
	{
		case 'year' :
			expTime.setFullYear(expTime.getFullYear() + time);
			break ;
		case 'month' :
			expTime.setMonth(expTime.getMonth() + time);
			break;
		case 'day' :
			expTime.setDate(expTime.getDate() + time);
			break;
		case 'hour' :
			expTime.setHours(expTime.getHours() + time);
			break;
	}
	return expTime.toGMTString();
}
function getCookieVal(offset)
{
	var endstr	= document.cookie.indexOf(";", offset);
	if(endstr == -1)
		endstr	= document.cookie.length;
	return decodeURIComponent(document.cookie.substring(offset, endstr));
}
function getCookie(name)
{
	var arg		= name + "=";
	var alen	= arg.length;
	var clen	= document.cookie.length;
	var i		= 0;
	while (i < clen)
	{
		var j	= i + alen;
		if (document.cookie.substring(i, j) == arg)
		{
			return getCookieVal(j);
		}
		i	= document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
		{
			break;
		}
	}
	return "";
}
function setCookie(name, value, expires, path, domain, secure)
{
	document.cookie		= name + "=" + encodeURIComponent(value) +
	((expires) ? "; expires=" + expires : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}
function delCookie(name)
{
	var last_date	= new Date();
	expiresTime		= last_date.setTime(last_date.getTime() - 100);
	setCookie(name, '', expiresTime, '', '') ;
}
function StringBuilder()
{
	this._stringArray	= new Array();
}
StringBuilder.prototype.append		= function(str)
{
	this._stringArray.push(str);
}
StringBuilder.prototype.toString	= function(joinGap)
{
	return this._stringArray.join(joinGap);
}
getFlashHtml	= function(flashArguments, flashPlayerCID)
{
	var _attrs	= new StringBuilder();
	var _params	= new StringBuilder();
	if(typeof(flashPlayerCID) == 'undefined')
	{
		flashPlayerCID	= 'D27CDB6E-AE6D-11cf-96B8-444553540000';
	}
	for(var k in flashArguments)
	{
		switch(k)
		{
			case "movie":
				continue;
				break;
			case "id":
			case "name":
			case "width":
			case "height":
			case "style":
				_attrs.append(k + "='" + flashArguments[k] + "' ");
				break;
			default:
				_params.append("<param name='" + ((k=="src") ? "movie":k) + "' value='" + flashArguments[k] + "' />");
				_attrs.append(k + "='" + flashArguments[k] + "' ");
		}
	}
	if(is_ie)
	{
		return "<object classid='clsid:" + flashPlayerCID + "' " + _attrs.toString('') + ">" + _params.toString('') + "<embed " + _attrs.toString('') + " type='application/x-shockwave-flash'></embed>" + "</object>";
	}
	else
	{
		return "<embed " + _attrs.toString('') + " type='application/x-shockwave-flash'></embed>";
	}
}
function chatLoad()
{
	getObject('ChatFlashDiv').style.top		= chatTop;
	setInterval('chatMove()', 10);
}
//document.documentElement.scrollTop
function chatMove()
{
	if (navigator.userAgent.indexOf("MSIE") == -1)
	{
		chatTop	= (window.pageYOffset + document.body.clientHeight - 350) + "px";
		if(getObject('ChatFlashDiv').style.top == chatTop)
		{
			return false;
		}
		getObject('ChatFlashDiv').style.top		= "1px";
		getObject('ChatFlashDiv').style.top		= (window.pageYOffset + document.body.clientHeight - 350) + "px";
		getObject('ChatFlashDiv').style.left	= (document.body.offsetWidth - 240) + "px";
	}
	else
	{
		chatTop	= (document.body.scrollTop + document.body.offsetHeight - 350) + "px";
		if(getObject('ChatFlashDiv').style.top == chatTop)
		{
			return false;
		}
		getObject('ChatFlashDiv').style.top		= (document.body.scrollTop + document.body.offsetHeight - 350) + "px";
		getObject('ChatFlashDiv').style.left	= (document.body.offsetWidth - 240) + "px";
	}
}
function chatLogin(path)
{
	if(typeof path == "undefined")
	{
		path	= "/";
	}
	var flashvars	= "user_cookie=" + getCookie('user_cookie') + "&amp;user_email=" + getCookie('user_email');
/*	var swf			= getFlashHtml({"src":path + 'images/chat.swf', "width":"200", "height":"300", "allowScriptAccesss":"always", "id":"ChatFlashId", "name":"ChatFlashId", "wmode":"transparent", "flashvars":flashvars}); */
	var swf			= getFlashHtml({"src":path + 'images/chat.swf', "width":"200", "height":"300", "allowScriptAccesss":"always", "id":"ChatFlashId", "name":"ChatFlashId", "flashvars":flashvars});
	getObject("ChatFlashDiv").innerHTML	= swf;
}
function chatClose()
{
	getObject('ChatFlashDiv').innerHTML	= '';
}

