/**
 * Namespace for comcast specific project code: Project
 */
Project = {};


/**
 * Project Global Variables Start 
 * Most of them should be loaded via HeadUC
 */
Project.PartnerCookieName="CIDF"; 
Project.hssWindowHight = 0;
Project.hssWindowWidth = 0;
Project.authenticationAdapterURL = "";
Project.channelCode = 0;
/**
 * Project Global Variables End 
 */

/**
 *	Returns true if the current user is logged on as a member,  
 *  encluding the 3rd-party single-sign-on of the partner
 */
Project.isMember = function()
{
	var partnerCookie = readCookie(Project.PartnerCookieName);
	var bIsMember = false; // Default Value
	
	if ((partnerCookie != null) && (partnerCookie != "") && (partnerCookie != ";")
	&& ProfileMgr.user.IsLoggedOn())
	{
		bIsMember = true;
	}
	
	return bIsMember
}

/**
 *	This function will open Popup for Online Shell
 */
 

Project.openRoom =  function (sUrl, iWidth, iHight, isMembersOnly)
{
	Claim.isString(this.authenticationAdapterURL, "Project.openRoom is called without initiating Project.authenticationAdapterURL");
	Claim.isNumber(this.channelCode, "Project.openRoom is called without initiating Project.channelCode");
	Claim.isString(this.PartnerCookieName, "Project.PartnerCookieName is empty");
	// initialize width & height in-case they are not provided
	if (! iWidth) iWidth = this.hssWindowWidth;
	if (! iHight) iHight = this.hssWindowHight;
	
	
    sUrl = this.authenticationAdapterURL + "?cmd=play&channel=" + this.channelCode + "&rurl=" + escape("http://" + location.host + "/" + sUrl);
    
    if  ( isMembersOnly && !Cookies.rawByName[this.PartnerCookieName])
    {
        ProfileMgr.sendToAdapter();
        return void(0);
    }
    
    try
    {
        window.open(sUrl, "online", "width=" + iWidth + ", height=" + iHight).focus();
    }
    catch(ex)
    {
        if(!window["log"])
            window.log = new Log4Js.Logger("[window] - app/lobby.aspx");
        log.error("couldn't open popup. Exception: " + Serialize(ex) );
    }
    return void(0);
}
/*
* go to page in the gameCenterWindowName window.
*/
Project.sendToPage = function(sUrl, bClosing)
{
	if(bClosing==null)
	{
		bClosing = false;
	}
	
	ClientMgr.openLink(sUrl);
	if(bClosing)
	{
		window.close();
	}							
}
/**
* goto login page using the UA adapter link in the gameCenterWindowName window.
*
*/
Project.sendToLogin = function(sUrl)
{	
	// show a message box asking the user if he want to continue (exit the game and login)
	// if yes goto the adapter   
	var retVal = confirm('This will end your game session');
	if(retVal)
	{
	
		ProfileMgr.submitToPage(	{	action : sUrl
									,	target : ProfileMgr.settings.gameCenterWindowName
									}
							); 
		window.close();								       
	}
}