var chatWindow = null;

function newChat(userID)
{
	var numArgs = newChat.arguments.length;
	if(chatWindow == null && readCookie('ie_chat_js') != 'client')
	{
		if(numArgs > 1)
		{
			chatWindow = window.open(newChat.arguments[1], 'iechat', "toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=465,height=540");
		}
		else
		{
			chatWindow = window.open('/chat/client', 'iechat', "toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=465,height=540");
		}
	}
	else
	{
		if(readCookie('ie_chat_js') == 'client')
		{
			//
		}
		else
		{
			if(chatWindow == null)
			{
				if(!chatWindow.closed)
				{
					//
					
				}
			}
			else
			{
				if(numArgs > 1)
				{
					chatWindow = window.open(newChat.arguments[1], 'iechat', "toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=465,height=540");
				}
				else
				{
					chatWindow = window.open('/chat/client', 'iechat', "toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=465,height=540");
				}
			}
		}
	}
	
	if(userID != undefined)
	{
		document.cookie = 'ie_chat_recipient=' + userID + '; path=/';
	}
}

/********************
 * Cookie Utilities *
 ********************/
function createCookie(name,value,days) {
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
