
function GetAppBaseURL()
{
    var pat = /(\w+:\/\/[^/]+).*/
    
    var res = pat.exec( document.URL );
    
    if ( res[1] )
    {
        return res[1];
    }
    else
    {
        return "";
    }        

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// --- Start: Inline pop-up code ---

var __gPopup = null;
var __gDwnld = null;

function __onPopupDownloadDone(src)
{
   // Invoked by the browser when it has finished 
   // downloading the source document to be rendered
   // in the popup window.
   __gPopup.document.write(src);
   __gPopup.document.body.style.borderWidth="5px";
   __gPopup.document.body.style.borderStyle="outset";

} 

function __cancelPopup()
{
   // Return true if a popup window is open and we closed it.

   if (parent && parent.__gPopup && parent.__gPopup.isOpen)
   {
      parent.__gPopup.hide();
      return true;
   }
   else
   {
      return false;
   }

}

function openPopup2(url, name, w, h, resize)
{
   if (!__gDwnld)
   {
      __gDwnld = document.createElement("<DOWNLOAD ID='__gDwnld' STYLE='behavior:url(#default#download)'/>"); 
      document.body.appendChild(__gDwnld);
   }

   __gPopup = window.createPopup();

   __gDwnld.startDownload(url,  __onPopupDownloadDone);

   // Center the window over the body element.
   var cw=document.body.clientWidth;
   var ch=document.body.clientHeight;
   var posx=cw/2 - w/2;
   var posy=ch/2 - h/2;
   var HOFSET = 150;
   
   // A bit above horizontal center looks nice.
   if ( posy > HOFSET*2 )
     posy -= HOFSET; 

   __gPopup.show(posx, posy, w, h, document.body);
}
// --- End: Inline pop-up code ---
////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function openPopup(theURL, theName, theWidth, theHeight, resizable)
{
    // resizable parameter is optional, defaults to yes
    if (!resizable) {
        resizable = 'yes';
    }
        
	var wl = (screen.availWidth - theWidth) / 2;
	var wt = (screen.availHeight - theHeight) / 2;
	var thePopup = window.open(theURL, theName, 
		'height='+theHeight+',width='+theWidth+',left='+wl+',top='+wt+
		',resizable=' + resizable + ',scrollbars=no,status=no,location=no,menubar=no,toolbar=no');
	//thePopup.moveTo(50,100);
	 
	listenflag = false;
	if (thePopup) // will be null if popup blocker zapped it.
	{
	    try {
	        thePopup.opener = window; // make sure the "new" window knows where it came from.
	        thePopup.focus(); // return false;//
	    }
	    catch(e)
	    {
	        // Popup blocker may invalidate the window, set to null
	        // so it can be handled.
	        thePopup = null;
	    }    
	}
	listenflag = true;
	return thePopup;
}

function openModalDialog(theURL, theName, theWidth, theHeight)
{
	// Note that parameter "theName" is ignored. (wanted to keep signature the same as openPopup)
	var wl = (screen.availWidth - theWidth) / 2;
	var wt = (screen.availHeight - theHeight) / 2;
	var thePopup = window.open(theURL, theName,	// pass in the current "opener" window as an argument
		'height='+theHeight+',width='+theWidth+',left='+wl+',top='+wt+',center=yes'+
		',resizable=yes,scroll=no,status=no,modal=yes')

	return thePopup;
}

function WindowCancel()
{
   // If we are called from a "popup" object (as opposed to a separate browser window)
   if (__cancelPopup())
      return;


	window.close();
	
	try {
	    if (window.opener && !window.opener.closed)
	    {
	    	window.opener.focus();
	    }
	} catch (e) {
	
	    // do nothing if the opener is unavailable.
	    // The window.opener.closed reference has been 
	    // seen to cause runtime errors.
	}    
}

function GetDaysInMonth(aMonth, aYear)
{
	var daysInMonth = new Array (31,28,31,30,31,30,31,31,30,31,30,31);

	// figure out how many days this month:
	if (aMonth == 1 && ((aYear % 4 == 0 && aYear % 100 != 0) || aYear % 400 == 0))
	{
		return 29;
	}
	// else
	return daysInMonth[aMonth];
}

function EnableButton(theButton)
{
	theButton.disabled = false;
	theButton.className = "";
}

function DisableButton(theButton)
{
	theButton.disabled = true;
	theButton.className = "buttonDisabled";
}

function openHelpWindow(theHelpUrl, theWidth, theHeight)
{
	var wl = (screen.availWidth - theWidth) / 2;
	var wt = (screen.availHeight - theHeight) / 2;
	var theHelpWindow = window.open(theHelpUrl, '_blank', 
		'height='+theHeight+',width='+theWidth+',left='+wl+',top='+wt+
		',resizable=yes,scrollbars=yes,status=no,location=no,menubar=no,toolbar=no');
	theHelpWindow.focus();
	return theHelpWindow;
}

function LaunchHelp(theBaseUrl, theScript)
{
    var pageName;
    switch(theScript)
    {
      case "/default.asp" :
        pageName = "hostLogin";
        break;
      case "/Account/Account.asp" :
        pageName = "myAccount";
        break;
      case "/Account/Preferences.asp" :
        pageName = "myPreferences";
        break;
	  case "/Login/ParticipantLogIn.asp" :
        pageName = "participantLogInPage1";
        break;
      case "/Schedule/po_recurrencePattern.asp" :
        pageName = "recurrencePattern";
        break;
      case "/Schedule/po_conferencePreferences.asp" :
        pageName = "conferencePreferences";
        break;
      case "/Schedule/po_portAvailability.asp" :
        pageName = "PortAvailability";
        break;    
      default:
        /*
        ** All other scripts use the same page name as the help file...
        */
        pageName = theScript.substring(theScript.lastIndexOf("/")+1,theScript.lastIndexOf("."));
	}
	var theHelpUrl = theBaseUrl + 'Help/' + pageName + 'Help.htm';
	return openHelpWindow(theHelpUrl, 600, 410);
}

//*********************************************************
// refreshFrame()
//
// 
// Purpose: Refresh frame or frames loaded in window.
//       
// Usage:   refreshFrame ( wndParent [, FrameID1 [, FrameID2 ...]] )
//
//          wndParent (required) :  Window object which is the parent of the
//                                  frames to refresh.
//
//          FrameID   (optional) :  ID(s) of frames to refresh
//
//          If no frameIDs are supplied, all window frames are refreshed.          
//
// Copyright © 2000-2002 Sonexis, Inc. All rights reserved
//*********************************************************

function refreshFrame(wndParent) {

    if (typeof(wndParent) != "object")
        return;

    try {
        if (wndParent && !wndParent.closed) {
        
            var intArgs = arguments.length;
            
            if (intArgs == 1) {
                // refresh all frames.  
                // true argument of reload() forces reload from server
                for (var j=0; j < wndParent.frames.length; j++) {          
                    wndParent.frames[j].location.reload(true);
                }
            } else {    
                // only refresh input frames (by name)
                for (var i=1; i < arguments.length; i++) {      
                    wndParent.frames[arguments[i]].location.reload(true);
                }
            }
        }
    } catch (e) {
        // Most likely execption due to window object being closed or invalid.
        // Take no action in this case.
    }
}

/*** COOKIE MANAGEMENT ***/
function setSessionCookie(name, value)
{
	setPersistentCookie(name, value);
}

/*
** The expireDate argument (optional) must be an ECMAscript Date() object.
** If expireDate is not supplied, the cookie will only persist for the duration of the session.
*/
function setPersistentCookie(name, value, expireDate)
{
	setCookieEx(document, name, value, expireDate);
}

/*
** The expireDate argument (optional) must be an ECMAscript Date() object.
** If expireDate is not supplied, the cookie will only persist for the duration of the session.
*/
function setCookieEx(documentRef, name, value, expireDate)
{
	if (null != expireDate)
		{
		documentRef.cookie = escape(name) + "=" + escape(value) + "; expires=" + expireDate.toGMTString();
		}
	else	{
		documentRef.cookie = escape(name) + "=" + escape(value);
		}
}

function deleteCookie(name)
{
	deleteCookieEx(document, name);
}

function deleteCookieEx(documentRef, name)
{
	var expireDate = new Date();

	expireDate.setTime(expireDate.getTime() - 1);
	documentRef.cookie = escape(name) + "=; expires=" + expireDate.toGMTString();
}


/*
** Returns the value for the cookie 'name'.
** Returns null if no cookie of that name exists.
** Returns undefined if cookie of that name exists, but no value has been assigned.
*/
function getCookieValue(name)
{
	var cookieDict = getAllCookieValues();
	return ((null == cookieDict[name]) ? null : cookieDict[name]);
}

/*
** Returns an associative array containing one element for each cookie value found.
** Each element can be accessed by cookie name.
*/
function getAllCookieValues()
{
	return getAllCookieValuesEx(document);
}

/*
** Returns an associative array containing one element for each cookie value found.
** Each element can be accessed by cookie name.
*/
function getAllCookieValuesEx(documentRef)
{
	var cookieList = documentRef.cookie.split("; ");
	var cookieDictionary = new Array();
	var name;


	for (var i=0; i < cookieList.length; i++)
		{
		name = cookieList[i].split("=")
		cookieDictionary[unescape(name[0])] = unescape(name[1]);
		}

	return cookieDictionary;
}
/*** COOKIE MANAGEMENT ***/



