// Global variables/constants.
var intWindowHeight, intWindowWidth;
var isNS, isAllowableNS, isIE;
var intAvailHeight = window.screen.availHeight;
var	intAvailWidth = window.screen.availWidth;
var arrChatWidth = new Array();

arrChatWidth[0] = "";
arrChatWidth[1] = "100px";
arrChatWidth[2] = "142px";
arrChatWidth[3] = "217px";
arrChatWidth[4] = "292px";
arrChatWidth[5] = "367px";
arrChatWidth[6] = "";

// Global variables/constants.
var WINDOW_HEIGHT_CONFIG_CHECK	= 550;
var WINDOW_WIDTH_CONFIG_CHECK	= 425;
var WINDOW_HEIGHT_XFER_NOTIFY	= 200;
var WINDOW_WIDTH_XFER_NOTIFY	= 325;
var WINDOW_WIDTH_800_600_CHAT_RESIZE	= 600;
var WINDOW_WIDTH_1280_1024_CHAT_RESIZE	= 640;

var intChatResizeWidth = ( (window.screen.width == 800) ? WINDOW_WIDTH_800_600_CHAT_RESIZE : WINDOW_WIDTH_1280_1024_CHAT_RESIZE );

isNS = ( navigator.appName == "Netscape" );
isAllowableNS = ( isNS && ( parseFloat(navigator.appVersion) < 5 ) );
isIE = ( navigator.appName == "Microsoft Internet Explorer" );
isMac = ( navigator.platform == "MacPPC" );

function loadQueueDropDown(val) {
	top.window.oVRLFrames.refreshFrame("VRLTabs","vrl_tabs.asp?tabsel=queues&q_id=" + val);
}

function loadActiveUsersDropDown(val,ostype) {
	top.window.oVRLFrames.refreshFrame("VRLChatSend", "vrl_message_host.asp?patronid=" + val + "&process=selpatron&ostype=" + ostype);
}

function newPatronNotification(qid,qname,session_tab,patron_id) {
	var strPopUpURL, strPopUpTitle, strPopUpContentFile, strPopUpContentParms;
	var strPopUpWinParms;
	
	//	Set up window parms & open window.
	strPopUpWinParms		= "height=350,width=470,resizable=yes,scrollbars=yes";
	strPopUpContentFile		= "contentfile=vrl_info_patron.asp";
	strPopUpTitle			= "New Patron Alert!";
	strPopUpContentParms	= strPopUpContentFile + "&contentfileparms=patron_id=" + escape(patron_id) + ",patron_login_name=" + escape(patron_id) + ",context=queue,context_id=" + qid + ",new_patron=true,title=" + escape(strPopUpTitle);
	strPopUpURL				= "vrl_info_patron.asp?" + strPopUpContentParms;
	
	top.window.oNewPatronNotificationWin = top.window.openPopUpWinWithReturn(strPopUpURL,"PatronInfoPopUp" + patron_id,strPopUpWinParms);
}

function xferPatronNotification(from_host_name,patron_name) {
	var strPopUpURL, strPopUpTitle, strPopUpContentFile, strPopUpContentParms;
	var strPopUpWinParms;
	
	strPopUpContentFile		= "contentfile=vrl_alert_newpatron.asp";
	strPopUpContentParms	= "contentfileparms=XFER," + from_host_name + "," + patron_name;
	strPopUpTitle			= "Transferred Patron Alert!";
	strPopUpURL				= "/" + top.window.oVRLState.siteName + "/popUpFrames.asp?title=" + escape(strPopUpTitle) + "&" + strPopUpContentFile + "&" + strPopUpContentParms;
	strPopUpWinParms		= "height=" + WINDOW_HEIGHT_XFER_NOTIFY + ",width=" + WINDOW_WIDTH_XFER_NOTIFY + ",resize=yes";
	
	top.window.oXferPatronNotification = openPopUpWinWithReturn(strPopUpURL,"VRLPatronTransfer",strPopUpWinParms);
}

function waitPatronNotification(title) {
	var strPopUpURL, strPopUpTitle, strPopUpContentFile, strPopUpContentParms;
	var strPopUpWinParms;
	
	strPopUpContentFile		= "contentfile=vrl_alert_newpatron.asp";
	strPopUpContentParms	= "contentfileparms=WAIT";
	strPopUpTitle			= title;
	strPopUpURL				= "/" + top.window.oVRLState.siteName + "/popUpFrames.asp?title=" + escape(strPopUpTitle) + "&" + strPopUpContentFile + "&" + strPopUpContentParms;
	strPopUpWinParms		= "height=250,width=250,resize=yes";
	
	top.window.oWaitPatronNotificationWin = openPopUpWinWithReturn(strPopUpURL,"VRLPatronWait",strPopUpWinParms);
}

function refreshOpToOpWindow(url,name,parms) {
	var strWinParms;
	var strWinType;
	var bWinClosed;
	var oWin;
	
	strWinParms = "height=275,width=352,resizable=yes,scrollbars=yes";
	strWinType = eval("typeof(top.window." + name + ")");
	
	if ( strWinType != "undefined" ) {
		// There is a window.
		bWinClosed = eval("top.window." + name + ".closed");
		if ( bWinClosed ) {
			// The window has been closed; open it.
			oWin = openPopUpWinWithReturn(url,name,strWinParms);
			oWin.focus();
			eval("top.window." + name + " = oWin;");
		}
		else {
			// The window is open; just refresh the message window.
			strHref = eval("top.window." + name + ".VRLOpToOpMsgs.document.location.href;");
			eval("top.window." + name + ".VRLOpToOpMsgs.document.location.href = top.window." + name + ".VRLOpToOpMsgs.document.location.href;");
		}
	}
	else {
		// There is no window; open one.
		oWin = openPopUpWinWithReturn(url,name,strWinParms);
		oWin.focus();
		eval("top.window." + name + " = oWin;");
	}
}

function openPopUpWin(url,name,parms) {
	var oPopUpWin;
	
	oPopUpWin = window.open(url,name,parms);
}

function openPopUpWinWithReturn(url,name,parms) {
	var oPopUpWin;
	
	oPopUpWin = window.open(url,name,parms);
	
	return oPopUpWin;
}

function loadChatItem(replytype,content,cobrowse_mode) {
	var strType;
	var strContent, strContent1;
	var oTarget, strLocation;
	
	strType = replytype.toUpperCase();
	
	switch(strType) {
		case "CLSEBENTRY":
			strContent = content.replace(/&#39;/g,"'");
			strContent1 = strContent.replace(/&#144;/g,"\n");
			oTarget = top.window.varframe.VRLChat.VRLChatSend.document.frmVRLHostMessageSend.txtMessageBody;
			oTarget.value = strContent1;
			break;
		case "CLSVRLBOOKMARK":
			var strLocalPath = "/" + top.window.oVRLState.VRLFQDN + "/";
			var bLocalLocation = ( content.indexOf(strLocalPath) != -1 )
			
			top.window.sendevent("loadChatItem: " + cobrowse_mode.toUpperCase());
			top.window.oVRLState.currentCobrowseURL = content;
			
			// For a local location (on the VRL server) we'll load it directly - not through vrl_page_rewrite.asp
			if ( !bLocalLocation ) {
				strContent1 = content.replace(/http:/g,"http_");
			}
			else {
				strContent1 = content;
			}
			if ( top.window.oVRLState.VRLCobrowseMode != COBROWSE_MODE_PRO ) {
				if ( !top.window.oPagePushWindow.push ) {
					if ( !bLocalLocation ) {
						strLocation = "http://" + top.window.oVRLState.VRLFQDN + "/" + top.window.oVRLState.siteName + "/pagepush/" + strContent1;
					}
					else {
						strLocation = strContent1;
					}
				}
				else {
					if ( !bLocalLocation ) {
						strLocation = "http://" + top.window.oVRLState.VRLFQDN + "/" + top.window.oVRLState.siteName + "/pagepush/push/" + strContent1;
						top.window.oPagePushWindow.push = false;
					}
					else {
						strLocation = strContent1;
					}
				}
				
				top.window.oPagePushWindow.setLocation(strLocation);
				top.window.oPagePushWindow.focus();
			}
			else {
				top.window.doConavigate(content, "");
				top.window.sendevent("doConavigate called in loadChatItem");
			}
			break;
		case "CLSSHAREDFILE":
			var intFileID, strPath, strParms, oSFWin;
			var strRefreshFile;
			
			if ( document.location.href.indexOf("_patron.asp") > 0 ) {
				strRefreshFile = "vrl_process_patron.asp";
			}
			else {
				strRefreshFile = "vrl_process_host.asp";
			}
			
			strParms = "height=500,width=500,scrollbars=yes,status=yes,location=no,menubar=yes,resizable=yes";
			intFileID = content;
			
			// the cobrowse_mode parameter is used for shared files as a "load" parameter - a way to tell the function 
			// whether this is a file that is just being viewed, not pushed. The querystring parameter "load" below 
			// will be used in vrl_sharedfile_load.asp to determine whether or not to raise the "shared file sent"
			// and "new message" events - a "load" doesn't raise them.
			if ( cobrowse_mode == "load" ) {
				strPath = "vrl_sharedfile_load.asp?shared_file_id=" + intFileID + "&load=true";
			}
			else {
				strPath = "vrl_sharedfile_load.asp?shared_file_id=" + intFileID;
			}
			oSFWin = openPopUpWinWithReturn(strPath,"VRLSharedFileWindow" + intFileID,strParms);
			oSFWin.focus();
	}	// END switch
}

function deleteReply(id) {
	var strLoc;
	var oTabWin = top.window.varframe.VRLTabs;
	
	if ( confirm("Are you sure you want to delete this scripted reply?\n\nPress 'OK' to continue.") ) {
		strLoc = oTabWin.document.location.href;
		
		if ( oTabWin.document.location.search.length == 0 ) {
			oTabWin.document.location.href = strLoc + "?tabsel=scripts&replydelid=" + id;
		}
		else {
			// Remove the replydelid in the querystring there's already one there. If there is, that means the user has deleted one one the previous page load.
			strLoc = strLoc.replace(/&replydelid=\d+(\D|$)/i,"");		
			oTabWin.document.location.href = strLoc + "&replydelid=" + id;
		}
	}
}

function deleteBookmark(id) {
	var strLoc;
	var oTabWin = top.window.varframe.VRLTabs;
	
	if ( confirm("Are you sure you want to delete this bookmark?\n\nPress 'OK' to contiunue.") ) {
		strLoc = oTabWin.document.location.href;
		
		if ( oTabWin.document.location.search.length == 0 ) { // The querystring might be empty if the session vars were used to remember state.
			oTabWin.document.location.href = strLoc + "?tabsel=bookmarks&replydelid=" + id;
		}
		else { // Remove the delid in the querystring there's already one there. If there is, that means the user has deleted one one the previous page load.
			strLoc = strLoc.replace(/&delid=\d+(\D|$)/i,"");		
			oTabWin.document.location.href = strLoc + "&delid=" + id;
		}
	}
}

function deleteSharedFile(id) {
	var strLoc;
	var oTabWin = top.window.varframe.VRLTabs;
	
	if ( confirm("Are you sure you want to delete this shared file?\n\nPress 'OK' to contiunue.") ) {
		strLoc = oTabWin.document.location.href;
		
		if ( oTabWin.document.location.search.length == 0 ) { // The querystring might be empty if the session vars were used to remember state.
			oTabWin.document.location.href = strLoc + "?tabsel=files&replydelid=" + id;
		}
		else { // Remove the replydelid in the querystring there's already one there. If there is, that means the user has deleted one one the previous page load.
			strLoc = strLoc.replace(/&shared_file_delid=\d+(\D|$)/i,"");		
			oTabWin.document.location.href = strLoc + "&shared_file_delid=" + id;
		}
	}
}

function timedWinClose(seconds) {
	var intMilliSeconds;
	
	intMilliSeconds = seconds*1000;
	setTimeout("top.window.opener.top.window.focus();top.window.close();",intMilliSeconds);
}

function processSaveXScriptSelection(save_val,parms) {
	if ( !save_val ) {
		if ( confirm("Are you sure?\n\nYou will not get another opportunity to save the transcript for this session.") ) {
			document.frmSaveXScript.action = "vrl_xscript_patronlogout.asp?process=nosave&contentfileparms=" + parms;
			return true;
		}
		else
			return false;
	}
}

function popupTimeout(timedout,usertype) {
	if ( timedout ) {
		if ( usertype.toUpperCase() == "CLSVRLHOST" ) {
			alert("Your session has timed out!\n\nTo access the system administrative functions please login again.");
			top.window.opener.document.location.href = "vrleb_intro.asp?process=timedout";
		}
		else {
			alert("Your session has timed out!\n\nYou will be returned to the home screen.");
			top.window.opener.document.location.href = "vrleb_intro.asp";
		}
		top.window.close();
	}
}

function confirmEndPatronSession(tabsel, patronid) {
	if ( confirm("Are you sure you want to end this patron's session?\n\nPress 'OK' to continue.") )
		document.location.href = "vrl_tabs.asp?tabsel=" + tabsel + "&bootid=" + patronid + "&process=dis_es_link";
}

function chkDate(mo,day,year) {
	var intNumDays;
	var bGoodMonth, bGoodDay, bGoodYear;
	
	bGoodMonth = ( mo.search(/^[\d]{1,4}$/) != -1 );
	bGoodDay = ( day.search(/^[\d]{1,4}$/) != -1 );
	bGoodYear = ( year.search(/^[\d]{1,4}$/) != -1 );
	
	if ( bGoodMonth && bGoodDay && bGoodYear ) {
		if ( ( mo > 12 ) || ( mo < 1 ) )
			bGoodMonth = false
		else
			bGoodMonth = true

		if ( (mo == 1) || (mo == 3) || (mo == 5) || (mo == 7) || (mo ==  8) || (mo == 10) || (mo == 12) ) {
			intNumDays = 31;
		}
		else if ( (mo == 2) ) {
			if ( isLeapYear(year) ) {
				intNumDays = 29;
			}
			else {
				intNumDays = 28;
			}
		}
		else {
			intNumDays = 30;
		}
		
		if ( (day > intNumDays) || !bGoodMonth ) {
			alert(mo + "-" + day + "-" + year + " is an invalid date!\n\nPlease change the date and submit your request again.");
			return false;
		}
		else {
			return true;
		}
	}
	else {
		alert(mo + "-" + day + "-" + year + " is an invalid date!\n\nPlease change the date and submit your request again.");
		return false;
	}
}
	
function isLeapYear(year) {
	return ( (year % 4) == 0 ) && ( ( !(year % 100) == 0 ) || ( (year % 400) == 0 ) );
}

function hasHTMLTags(txt) {
	if ( txt.indexOf("<") != -1 || txt.indexOf(">") != -1 ) {
		alert("The characters '<' and '>' are not allowed in the message text field!");
		return false;
	}
	else {
		return true;
	}
}

function goBack(oWin) {
	oWin.history.back();
}

function rptTypeOnChangeRefresh(option_selected) {
	document.location.href = "http://" + document.location.host + document.location.pathname + "?rpt_sel=" + option_selected;
}

function movePatronVRLWindows(win_ref) {
	var intYMove, intHeight, intWidth;
	var intAvailHeight, intAvailWidth, intCobrowseHeight
	
	intAvailHeight = window.screen.availHeight;
	intAvailWidth = window.screen.availWidth;
	intCobrowseHeight = intAvailHeight - 450;
	
	if ( navigator.appName == "Netscape" && navigator.platform == "Win32" ) {
		intYMove = 350;
		intHeight = 300;
		intWidth = 725;
	}
	else if ( navigator.appName == "Netscape" && ( navigator.platform == "MacPPC" || strCobrowseEnable.toUpperCase() == "OFF" ) ) {
		intYMove = 350;
		intHeight = 300;
		intWidth = 725;
	}
	else if ( navigator.appName == "Microsoft Internet Explorer" && navigator.platform == "Win32" ) {
		intYMove = 330;
		intHeight = 400;
		intWidth = 737;
	}
	else if ( navigator.appName == "Microsoft Internet Explorer" && ( navigator.platform == "MacPPC" || strCobrowseEnable.toUpperCase() == "OFF" ) ) {
		intYMove = 335;
		intHeight = 300;
		intWidth = 700;
	}
}

function openPatronChatWindow(entry_mode) {
	var strParms;
	var strPage;
	var intAvailHeight, intAvailWidth;
	var intCobrowseHeight;
	var intWinHeight, intWinWidth;
	
	intAvailHeight = window.screen.availHeight;
	intAvailWidth = window.screen.availWidth;
	intCobrowseHeight = intAvailHeight - 485;
	strPage = "vrl_frames_patron.asp";

	if ( entry_mode == top.window.COBROWSE_MODE_CLASSIC ) {
		intWinHeight	= (intAvailHeight * .9);
		intWinWidth		= 250;
		strParms		= "location=no,status=no,height=" + intWinHeight + ",width=" + intWinWidth + ",toolbar=no,resizable=yes,scrollbars=yes,menubar=no,screenX=0,screenY=0,top=0,left=0";

		top.window.VRLChatWin = window.open(strPage,"VRLplusBrowserConfig",strParms);
	}
	else {
		intWinHeight	= (intAvailHeight - 200);
		intWinWidth		= window.screen.availWidth - 100;
		strParms		= "location=no,status=no,height=" + intWinHeight + ",width=" + intWinWidth + ",toolbar=no,resizable=yes,scrollbars=yes,menubar=no,screenX=0,screenY=0,top=0,left=0";
		
		top.window.VRLChatWin = window.open(strPage,"VRLplusBrowserConfig",strParms);
		top.window.VRLChatWin.resizeTo(intWinWidth, intWinHeight + 29);
	}
}

function openPatronVRLWindow(fqdn, cobrowse_domain, site_name, cobrowse_mode) {
	var strParms;
	var strPage;
	var intAvailHeight, intAvailWidth;
	var intCobrowseHeight;
	var intWinHeight, intWinWidth;
	
	intAvailHeight = window.screen.availHeight;
	intAvailWidth = window.screen.availWidth;
	intCobrowseHeight = intAvailHeight - 485;
	strPage = "https://" + fqdn + "/" + site_name + "/vrl_frames_patron.asp?cobrowse_mode=" + cobrowse_mode + "&cobrowse_domain=" + cobrowse_domain + "&is_net_xfer=" + is_net_xfer + "&switch_over=" + switch_over;
	
	if ( cobrowse_mode.toUpperCase() == top.window.COBROWSE_MODE_PRO ) {
		if ( isNS && !isMac ) {
			intWinHeight	= (intAvailHeight * .9);
			intWinWidth		= (window.screen.availWidth * .9);
			strParms		= "location=no,status=no,height=" + intWinHeight + ",width=" + intWinWidth + ",toolbar=no,resizable=no,scrollbars=yes,menubar=no,screenX=0,screenY=0,top=0,left=0";

			window.open(strPage,"VRLplusBrowserConfig",strParms);
		}
		else {
			intWinHeight	= (intAvailHeight - 200);
			intWinWidth		= window.screen.availWidth - 100;
			
			top.window.resizeTo(intWinWidth, intWinHeight + 29);
			top.window.location.href = strPage;
		}
	}
	else {
		intWinHeight	= (intAvailHeight - 125);
		intWinWidth		= 275;
		strParms		= "location=no,status=no,height=" + intWinHeight + ",width=" + (intAvailWidth - intWinWidth) + ",toolbar=no,resizable=yes,scrollbars=yes,menubar=no,screenX=275,screenY=0,top=0,left=275";
		
		top.window.resizeTo(intWinWidth, intWinHeight + 29);
		top.window.location.href = strPage;
	}
}

function openHostVRLWindow_sb1(fqdn, site_name, browse_capability, vdesk_array) {
	var oVRLWin;
	var strParms;
	var strPage;
	var bSingleCheckBox = ( typeof(vdesk_array.checked) != "undefined" );
	
	if ( browse_capability == top.window.COBROWSE_MODE_PRO ) {
		if ( isAllowableNS ) {
			strParms = "height=" + ( window.screen.availHeight * .9 ) + ",width=" + ( window.screen.availWidth * .9 ) + ",status=no,resizable=no,scrollbars=yes,location=no,menubar=no,screenX=0,screenY=0,top=0,left=0";
		}
		else {
			strParms = "height=" + ( window.screen.availHeight * .9 ) + ",width=" + ( window.screen.availWidth * .9 ) + ",status=no,resizable=yes,scrollbars=yes,location=no,menubar=no,screenX=0,screenY=0,top=0,left=0";
		}
	}
	else {
		strParms	= "height=" + ( window.screen.availHeight * .9 ) + ",width=" + ( window.screen.availWidth * .4 ) + ",status=no,resizable=yes,scrollbars=yes,location=no,menubar=no,screenX=0,screenY=0,top=0,left=0";
	}
	
	strVDeskList = "";
	
	// If typeof(vdesk_array.length) is a number, we have an array, i.e. more than one VDesk in the cb list.
	if ( !bSingleCheckBox ) {
		if ( typeof(vdesk_array.length) == "number" ) {
			for ( i = 0; i < vdesk_array.length; i++ ) {
				if ( vdesk_array[i].checked ) {
					strVDeskList = strVDeskList + vdesk_array[i].value + ",";
				}
			}
			strVDeskList = strVDeskList.replace(/,$/,"");
		}
		else {
			strVDeskList = vdesk_array.value;
		}
	}
	else {
		if ( vdesk_array.checked ) {
			strVDeskList = vdesk_array.value;
		}
	}
	if ( strVDeskList.length == 0 ) {
		alert('You must select at least one Virtual Desk to enter Live Chat!');
		return false;
	}
	else {
		strPage	= "https://" + fqdn + "/" + site_name + "/vrl_frames_host.asp?browse_cap=" + browse_capability + "&vdesk_list=" + strVDeskList;
		
		oVRLWin = openPopUpWinWithReturn(strPage,"VRLplusHost",strParms);
		top.window.close();
	}
}

function openHostVRLWindow(fqdn, site_name, cobrowse_domain, cobrowse_mode) {
	var oVRLWin;
	var strParms;
	var strPage;
	
	if ( cobrowse_mode == top.window.COBROWSE_MODE_PRO ) {
		if ( isAllowableNS ) {
			strParms = "height=" + ( window.screen.availHeight * .9 ) + ",width=" + ( window.screen.availWidth * .9 ) + ",status=no,resizable=no,scrollbars=yes,location=no,menubar=no,screenX=0,screenY=0,top=0,left=0";
		}
		else {
			strParms = "height=" + ( window.screen.availHeight * .9 ) + ",width=" + ( window.screen.availWidth * .9 ) + ",status=no,resizable=yes,scrollbars=yes,location=no,menubar=no,screenX=0,screenY=0,top=0,left=0";
		}
	}
	else {
		strParms	= "height=" + ( window.screen.availHeight * .9 ) + ",width=" + ( window.screen.availWidth * .4 ) + ",status=no,resizable=yes,scrollbars=yes,location=no,menubar=no,screenX=0,screenY=0,top=0,left=0";
	}
	
	strPage	= "https://" + fqdn + "/" + site_name + "/vrl_frames_host.asp?cobrowse_mode=" + cobrowse_mode + "&cobrowse_domain=" + cobrowse_domain; //"/site_name/vrl_app_host.asp";
	
	oVRLWin = openPopUpWinWithReturn(strPage,"VRLplusHost",strParms);
}

function reopenHostVRLWindow(fqdn, site_name, cobrowse_domain, current_cobrowse_mode) {
	var oVRLWin;
	var strParms;
	var strPage;
	
	if ( current_cobrowse_mode == top.window.COBROWSE_MODE_PRO ) {
		strParms	= "height=" + ( window.screen.availHeight - 75 ) + ",width=" + ( window.screen.availWidth - 50 ) + ",status=no,resizable=yes,scrollbars=yes,location=no,menubar=no,screenX=0,screenY=0,top=0,left=0";
	}
	else {
		strParms	= "height=" + ( window.screen.availHeight - 75 ) + ",width=" + ( window.screen.availWidth/2 ) + ",status=no,resizable=yes,scrollbars=yes,location=no,menubar=no,screenX=0,screenY=0,top=0,left=0";
	}
	
	strPage	= "https://" + fqdn + "/" + site_name + "/vrl_frames_host.asp?cobrowse_domain=" + cobrowse_domain + "&process=cb_reconfig"; //"/site_name/vrl_app_host.asp";
	
	oVRLWin = openPopUpWinWithReturn(strPage,"VRLplusHost",strParms);
}

function isUndefined(obj) {
	var bUndefined;
	
	bUndefined = ( typeof(obj) == "undefined" );
	return bUndefined;
}

function openConfigCheckWindow_sb(user_type) {
	var oCheckWin;
	var strParms;
	var strPage;
	
	if ( user_type == top.window.USER_TYPE_PATRON ) {
		strPage	= "vrl_config_check_sb.asp?user_type=" + user_type.toUpperCase() + "&browse_mode=" + top.window.oVRLState.VRLCobrowseMode;
	}
	else {
		strPage	= "vrl_config_check_sb.asp?user_type=" + user_type.toUpperCase();
	}
	
	strParms = "height=" + WINDOW_HEIGHT_CONFIG_CHECK + ",width=" + WINDOW_WIDTH_CONFIG_CHECK + ",resizable=yes,scrollbars=yes,location=no,menubar=no,screenX=0,screenY=0,top=0,left=0";
	
	//top.window.oConfigWin = openPopUpWinWithReturn(strPage,"kjg",strParms);
	top.window.sharedbrowser.document.location.href = strPage;
}

function openConfigCheckWindow(user_type) {
	var oCheckWin;
	var strParms;
	var strPage;
	
	strPage		= "vrl_config_check.asp?user_type=" + user_type.toUpperCase();
	strParms	= "height=" + WINDOW_HEIGHT_CONFIG_CHECK + ",width=" + WINDOW_WIDTH_CONFIG_CHECK + ",resizable=yes,scrollbars=yes,location=no,menubar=no,screenX=0,screenY=0,top=0,left=0";
	
	top.window.oConfigWin = openPopUpWinWithReturn(strPage,"VRLplusBrowserConfig",strParms);
	
	if ( !checkForWin(top.window.oConfigWin) ) {
		openPopUpWin(strPage,"VRLplusBrowserConfig",strParms);
	}
}

function onWinClose() {
	chatWinCloseOut();
}

function chatWinCloseOut() {
	var strBase = "https://" + top.window.oVRLState.VRLFQDN;
	var bDoLogoutProcessing, bNSWindowResize, bNetXfer, bReconfigureCobrowse, bClassicSwitchOver;
	var bIsOperator = ( top.window.oVRLState.myUserType == top.window.USER_TYPE_OPERATOR );
	var bIsPatron = ( top.window.oVRLState.myUserType == top.window.USER_TYPE_PATRON );
	var bOpHasActivePatrons = ( top.window.oVRLState.VRLactiveUserID != "0" );
	var bLogoutConfirm, strConfMsg;
	var oAdminWin;
	
	bNSWindowResize			= ( top.window.isAllowableNS && top.window.oVRLState.offlineMethod.toUpperCase() == "WINDOW_CLOSED" );
	bClassicSwitchOver		= top.window.oVRLState.offlineMethod.toUpperCase() == "CLASSIC_SWITCHOVER";
	bReconfigureCobrowse	= top.window.oVRLState.reconfigureCobrowse;
	bDoLogoutProcessing		= !bNSWindowResize && !bReconfigureCobrowse && !bClassicSwitchOver;
	
	checkForWinAndClose(top.window.oWaitPatronNotificationWin);
	checkForWinAndClose(top.window.oNewPatronNotificationWin);
	checkForWinAndClose(top.window.oXferPatronNotification);
	
	if ( bDoLogoutProcessing ) {
		if ( !top.window.oVRLState.loggedOut ) {
			if ( top.window.oVRLState.VRLCobrowseMode.toUpperCase() == top.window.COBROWSE_MODE_PRO ) {
				top.window.hbapi.HBExitSession();
				top.window.hbapi.HBLogout();
			}
			
			if ( bIsOperator ) {
				if ( bOpHasActivePatrons && top.window.oVRLState.offlineMethod.toUpperCase() == "LOGOUT" ) {
					strConfMsg = "There are still patrons in your active session, are you sure you want to go offline?\n\nOK = Yes\nCancel = No";
					bLogoutConfirm = confirm(strConfMsg);
				}
				else {					
					bLogoutConfirm = true;
				}
				
				if ( bLogoutConfirm ) {
					if ( top.window.oVRLState.reconfigureCobrowse ) {
						top.window.oVRLState.reconfigureCobrowse = false;
					}
					
					top.window.oVRLState.loggedOut = true;
					top.window.oPagePushWindow.close();
					window.open(strBase + "/" + top.window.oVRLState.siteName + "/vrl_go_offline.asp","VRLOfflineProcessingWin","height=10,width=10,location=no");
					//refreshAdminWin();
					top.window.close();
				}
			}
			else if ( bIsPatron ) {
				if ( top.window.oVRLState.offlineMethod.toUpperCase() != "BOOTED_OPEN_WIN" ) {
					// We only need to refresh the main window to log the patron out if they haven't already been logged out as a result of having their session ended by the operator.
					top.window.refreshPatronMainWin(strBase + '/' + top.window.oVRLState.siteName + '/vrl_logout_patron.asp?process=' + top.window.oVRLState.offlineMethod + '&patronid=' + top.window.oVRLState.VRLSessionID);
					top.window.oPagePushWindow.close();
				}
				if ( top.window.oVRLState.reconfigureCobrowse ) {
					top.window.oVRLState.reconfigureCobrowse = false;
				}
				top.window.oVRLState.loggedOut = true;
				top.window.close();
			}
		}
	}
	top.window.sendevent('...chatWinCloseOut() done.');
}

function refreshAdminWin() {
	var oAdminWin;
	
	oAdminWin = window.open('','VRLplusAdminWin');
	if ( oAdminWin.document.location.href == "about:blank" ) {
		oAdminWin.document.location.href = '/' + top.window.oVRLState.siteName + '/vrleb_admin.asp';
	}
	oAdminWin.focus();
}
function checkForWinAndClose(obj_win) {
	if ( checkForWin(obj_win) ) {
		obj_win.close();
	}
}
function checkForWin(obj_win) {
	if ( typeof(obj_win) != "undefined" ) {
		if ( obj_win == null ) {
			return false;
		}
		else if ( !obj_win.closed ) {
			return true;
		}
		else {
			return false;
		}
	}
	else {
		return false;
	}
}
function enterPressed(e) {
    var myChar;
	var KEY_ENTER = 13;
		
    if (document.all) {
        e = window.event;
		myChar = e.keyCode;
    }
    else {
        if (document.layers) {
 			var myChar = e.which;
 		}
	}
    if ( myChar == KEY_ENTER ) {
		
        if (document.layers) {
            return true;
        }
        else if (document.all) {
            e.returnValue = true;
            return true;
        }
    }
}
function submitOnEnter(e) {
	if ( enterPressed(e) ) {
		submitForm();
		return false;
	}
}
function refreshPatronMainWin(url) {
	var oMainWin;
	var intResizeHeight = intAvailHeight * (.75);
	var intResizeWidth	= intAvailWidth * (.75);
	
	oMainWin = window.open(url,'VRLplusPatronOnline');
}
function realignClassicBrowseWin() {	
	if ( isAllowableNS || isIE ) {
		var intChatWinLeft = top.window.screenLeft;
		var intChatWinTop = top.window.screenTop;
		var intLeftOffset = 377;
		var intTopOffset = 72;
		
		top.window.oPagePushWindow.moveTo(intChatWinLeft + intLeftOffset, intChatWinTop + intTopOffset);
	}	
}
/* ===================================================================
/  Page push window object & methods
/  =================================================================== */
function pagePushWindow_refresh() {
	// See if the window exists and our object's location is set to something "valid."
	top.window.sendevent('Refreshing page push window.');
	if ( !isUndefined(this.winRef) ) {
		if ( !this.winRef.closed ) {
			this.winRef = top.window.openPopUpWinWithReturn(this.location, this.name, this.parms);
		}
		else {
			this.winRef = top.window.openPopUpWinWithReturn(this.location, this.name, this.parms);
		}
	}
	top.window.sendevent('Done refreshing page push window.');
}
//  =================================================================== */
function pagePushWindow_setLocation(location) {
	// See if the window exists and our object's location is set to something "valid."
	
	this.location = location;
	
	top.window.sendevent('Setting page push location: ' + location);
	
	if ( !isUndefined(this.winRef) && this.location.length >= 6 ) {
		if ( !this.winRef.closed ) {
			this.winRef = top.window.openPopUpWinWithReturn(this.location, this.name, this.parms);
		}
		else {
			this.winRef = top.window.openPopUpWinWithReturn(this.location, this.name, this.parms);
		}
	}
	else if ( this.location.length >= 6 ) {
		this.winRef = top.window.openPopUpWinWithReturn(this.location, this.name, this.parms);
	}
	else {
		
	}
	top.window.sendevent('Done setting page push location: ' + location);
}
function pagePushWindow_closed() {
	if ( !isUndefined(this.winRef) ) {
		return this.winRef.closed;
	}
}
function pagePushWindow_close() {
	if ( !isUndefined(this.winRef) ) {
		if ( !this.closed() ) {
			this.winRef.close();
		}
	}
}
function pagePushWindow_focus() {
	if ( !isUndefined(this.winRef) ) {
		if ( !this.closed() ) {
			this.winRef.focus();
		}
	}
}
function pagePushWindow_open() {
	this.winRef = top.window.openPopUpWinWithReturn(this.location, this.name, this.parms);
}
function pagePushWindow_moveTo(x, y) {
	if ( !isUndefined(this.winRef) ) {
		if ( !this.winRef.closed ) {
			this.winRef.moveTo(x, y);
		}
	}
}
function pagePushWindow(location, name, parms) {
	// Properties
	this.winRef;
	this.location		= location;
	this.name			= name;
	this.parms			= parms;
	this.closed			= pagePushWindow_closed;
	this.push			= false;
	
	// Methods
	this.setLocation	= pagePushWindow_setLocation;
	this.refresh		= pagePushWindow_refresh;
	this.open			= pagePushWindow_open;
	this.close			= pagePushWindow_close;
	this.focus			= pagePushWindow_focus;
	this.moveTo			= pagePushWindow_moveTo;
}
//  ===================================================================
function vrlFrames_readyToInit() {
	var bConavDefined = !isUndefined(this.conavframesetLoaded);
	var bHBApiDefined = !isUndefined(this.hbapiLoaded);
	var bapiFramesDefined = !isUndefined(this.apiFramesLoaded);
	
	if ( bapiFramesDefined ) {
		return true;
	}
	else {
		return false;
	}
}
function vrlFrames_refreshFrame(frame_name, frame_document_path) {
	var strTmpFrame;
	var bFrameLoaded;
	var oTmpWin = window.open('', frame_name);
	
	bFrameLoaded = eval("this." + frame_name + "Loaded");
	
	if ( bFrameLoaded ) {
		strTmpFrame = eval("this." + frame_name);
		strTmpFrame.document.location.href = frame_document_path;
	}
}
function vrlFrames() {
	// This object has "dynamic" properties in that they'll be created & set by each frame that registers itself
	// with this object. The properties wil be of the following form for each frame that registers:
	this.refreshFrame	= vrlFrames_refreshFrame;
	this.readyToInit	= vrlFrames_readyToInit;
}
function getFrame(frame_name) {
	var oWin = window.open('',frame_name);
	
	return oWin;
}
function listObjectProperties(obj) {
	var strNames;
	
	for ( i in obj ) {
		strVal = eval("obj." + i)
		strNames += i + "=" + strVal + "<BR>";
	}
	return strNames;
}