//******************************
// All toplevel pages.


//*********************//
//* Auto Calc Scripts *//
//*********************//

function Preloads()
{

    this.submitsearch_on = new Image();	    this.submitsearch_on.src	= "/images/btn_search_on.gif";
	this.submitsearch_off = new Image();	this.submitsearch_off.src	= "/images/btn_search_off.gif";
    this.hidehelpframe_on = new Image();	this.hidehelpframe_on.src	= "/images/btn_helpnav_hide_on.gif";
	this.hidehelpframe_off = new Image();	this.hidehelpframe_off.src	= "/images/btn_helpnav_hide_off.gif";
    this.showhelpframe_on = new Image();	this.showhelpframe_on.src	= "/images/btn_helpnav_show_on.gif";
	this.showhelpframe_off = new Image();	this.showhelpframe_off.src	= "/images/btn_helpnav_show_off.gif";

}

//POPUP WINDOWS

/*
	Returns the x coordinate relative to the screen of the
	specified window instance.	
*/
function getWindowX(thisWindow)
{
	return thisWindow.screenLeft ? thisWindow.screenLeft : thisWindow.screenX;
}

/*
	Returns the y coordinate relative to the screen of the
	specified window instance.	
*/
function getWindowY(thisWindow)
{
	return thisWindow.screenTop ? thisWindow.screenTop : thisWindow.screenY;
}

//Collaboration phase 2: Interview navbar hack begin
function hideNavPage(pageName)
{
//	changeToHide('startbtn_' + pageName);
//	changeToHide('middlebtn_' + pageName);
//	changeToHide('endleftbtn_' + pageName);
//	changeToHide('endrightbtn_' + pageName);
//	changeToHide('text_' + pageName);
}	

function showNavPage(pageName)
{
//	changeToShowTR('startbtn_' + pageName);
//	changeToShowTR('middlebtn_' + pageName);
//	changeToShowTR('endleftbtn_' + pageName);
//	changeToShowTR('endrightbtn_' + pageName);
//	changeToShowTR('text_' + pageName);
}
//Collaboration phase 2: Interview navbar hack end

//preload images here
if (document.images)
{
	var preloads = new Preloads();
}

function mouseOnOff(img,onoff)
{
	document[img].src = preloads[img+"_"+onoff].src;
}

function mouseOnOffSrc(img, src)
{
	document[img].src = src;
}

function resizeCheck()
{
	if (oldWidth < window.innerWidth || oldWidth > window.innerWidth || oldHeight > window.innerHeight || oldHeight < window.innerHeight )
	{
		document.f.randnocache.value=(new Date()).getTime();
		document.f.submit();
	}
}

function doOnload()
{
	//overwrite this function in main component if necessary.
}

var cellHeight = "100%";
function saveWindowDimensions()
{
	if(navigator.appName == 'Netscape')// && !window.oldWidth)
	{
		cellHeight = window.innerHeight-153; //144 = header height + footer height
		window.onresize = resizeCheck;
		window.oldWidth = window.innerWidth;
		window.oldHeight = window.innerHeight;
	}
}

function savePopupWindowDimensions()
{
	if(navigator.appName == 'Netscape')// && !window.oldWidth)
	{
		cellHeight = window.innerHeight-67; //67 = popup header height + popup footer height
		window.onresize = resizeCheck;
		window.oldWidth = window.innerWidth;
		window.oldHeight = window.innerHeight;
	}
}


//***************//
//* MHS SCRIPTS *//
//***************//

//<!--Guide-->
var pop = null;
function AgentPopup()
{
	if( pop != null)
	{
		document.all.agentLink.innerText = "Show";
		pop.close();
		pop = null;
	}
	else
	{

		document.all.agentLink.innerText = "Hide";
		var loc = "/msagent/controlcenter.htm";
		var width = 400;
		var height = 400;

		pop = window.open(loc, "controlcenter", 'width=' + width + ',height=' + height + ', status=yes,menubar=no,resizable=no,top=0,left=600,screenX=0,screenY=0');
		pop.focus();

	}
}

function AgentPopupDownload()
{
		var loc = "/msagent/settings.htm";
		var width = 650;
		var height = 550;

		pop = window.open(loc, "controlcenter", 'width=' + width + ',height=' + height + ', status=yes,menubar=no,resizable=no,top=0,left=600,screenX=0,screenY=0');
		pop.focus();
}

//******************************
// CONFIRM COMMAND

function ConfirmDelete(description, query)
{
	var sure = confirm("Are you sure you want to permanently delete " + UnescapeDQ(description) + "?");
	if (sure == true) location = query;
}

function ConfirmInactive(description, query)
{
	var sure = confirm("Are you sure you want to inactivate " + UnescapeDQ(description) + "?");
	if (sure == true) location = query;
}

function ConfirmUnlink(description, query)
{
	var sure = confirm("Are you sure you want to unlink " + UnescapeDQ(description) + "?");
	if (sure == true) location = query;
}

//******************************
// POPUP WINDOWS

//	getWindowPosition
//*********************************************
//	Returns a multi-browser-compatible string to
//	be used in the window.open() features parameter.
//*********************************************

function getWindowPosition(x, y)
{
	var position = "screenX=" + x + ",screenY=" + y;
	if (getMSIEVersionNumber() != -1)
	{
		position = "left=" + x + ",top=" + y;
	}
	return position;
}

function centerPopup(height, width)
{
	return MHSCenterPopup(height, width);
}

function MHSCenterPopup(height, width)
{
	var x = (window.screen.availWidth/2) - (width/2);
	var y = (window.screen.availHeight/2) - (height/2);
	var position = getWindowPosition(x, y);
//	alert("MHSCenterPopup method: position =["+position+"].");
	return position;
}

function MHSSizablePopup(query, height, width)
{
	mhssizablewin = window.open(query, "mhspopupsizablewin", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=" + height + ",width=" + width);
	if (mhssizablewin.opener == null) mhssizablewin.opener = self;
	mhssizablewin.focus();
}

function MHSPleaseWaitPopup(query)
{
	var width = 130;
	var height = 150;
	var x = (window.screen.availWidth/2) - (width/2);
	var y = (window.screen.availHeight/2) - (height/2);
	var position = "left=" + x + ",top=" + y;
	var size = "width=" + width + ",height=" + height;
	if (query == null)
	{
		query = "BaseAuthServlet?forwardURL=/PleaseWait.jsp";
	}
	mhspleasewait = window.open(query, 'mhspopuppleasewait', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,' + size + ',' + position);
	if (mhspleasewait.opener == null) mhspleasewait.opener = self;
	mhspleasewait.focus();
}

function ClosePleaseWaitPopup()
{
	var width = 150;
	var height = 50;
	var x = window.screen.width + 1000;
	var y = window.screen.height + 1000;
	var position = "left=" + x + ",top=" + y;
	//window.alert(position);
	mhspleasewait = window.open( '', 'mhspopuppleasewait', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,' + position);
	mhspleasewait.close();
}

function MHSSmallPopup(query)
{
	mhssmallwin = window.open(query, 'mhspopupsmallwin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=400,height=310');
	if (mhssmallwin.opener == null) mhssmallwin.opener = self;
	mhssmallwin.focus();
}

function MHSMediumPopup(query)
{
	mhsmediumwin = window.open(query, 'mhspopupmediumwin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=400,height=350');
	if (mhsmediumwin.opener == null) mhsmediumwin.opener = self;
	mhsmediumwin.focus();
}

function MHSLargePopup(query)
{
	mhslargewin = window.open(query, 'mhspopuplargewin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=400');
	if (mhslargewin.opener == null) mhslargewin.opener = self;
	mhslargewin.focus();
}



function OtherPopup(query)
{
	otherwin = window.open(UnescapeDQ(query), 'mhspopupotherwin');
	if (otherwin.opener == null) otherwin.opener = self;
	otherwin.focus();
}

function FlashPopup(filename)
{
	var win = filename;
	var i = win.indexOf(".");
	if(i != -1)
	{
		win = win.substring(0, i);
	}
	win = win.replace(/-| /gi, "");
	filename = escape(filename);

	var loc= "ViewFlash.jsp?fn=" + filename;
	var flashpop = window.open(loc, win, 'width=635,height=455, menubar=no,resizable=yes,screenX=0,screenY=0');

	if (flashpop.opener == null) flashpop.opener = self;
	flashpop.focus();
	flashpop.moveTo(0,0);
}

function CloseWindowAndForwardOpener(location)
{
	window.opener.location = location;
	self.close();

}//	end CloseWindowAndForwardOpener

function getAddressMap(useSimpleMap, sessionId)
{
	var street = document.xtolform['XT_STREET'].value;
	var zip = document.xtolform['XT_ZIP'].value;
	var country = document.xtolform['XT_COUNTRY'].value;
	var structureId = document.xtolform['XT_STRUCTURE_ID'].value;
	//alert("im here structureId: " + structureId + " needToCallValidateStreetAddress: " + needToCallValidateStreetAddress);
	
	if (street == "")
	{
		alert("The 'Street' field must be entered before using this feature");
		document.xtolform['XT_STRUCTURE_ID'].value = "";
		changeToHide("MAP_THIS_ADDRESS");
	}
	else if (zip == "")
	{
		alert("The 'ZIP Code' field must be entered before using this feature");
		document.xtolform['XT_STRUCTURE_ID'].value = "";
		changeToHide("MAP_THIS_ADDRESS");
	}
	else if ("USA" != country)
	{
		alert("Currently only addresses found in the USA are available");
		document.xtolform['XT_STRUCTURE_ID'].value = "";
		changeToHide("MAP_THIS_ADDRESS");
	}
	else if (structureId == "" || needToCallValidateStreetAddress)
	{
		if (needToCallValidateStreetAddress)
		{
			needToCallValidateStreetAddress = false;
			validateStreetAddress();
		}
		else
		{
			alert("The feature is only available after you have validated your address");
	        document.xtolform['XT_STRUCTURE_ID'].value = "";
	        changeToHide("MAP_THIS_ADDRESS");
		}        
	}
	else
	{		
		var width = 600;
		var height = 600;
		var url = document.location.href;
		var temp = url.substring((url.indexOf("//")+2));
		
		var domain = temp.substring(0, temp.indexOf("/"));
		var newUrl = "http://" + domain + "/apps/mhs/Map.jsp;jsessionid="+sessionId+"?structure_id="+structureId+"&street="+escape(street)+"&zipcode="+escape(zip)+"&simple="+useSimpleMap;
		
		var x = (window.screen.availWidth/2) - (width/2);
		var y = (window.screen.availHeight/2) - (height/2);
		var position = getWindowPosition(x, y);
		
		mqsizablewin =  window.open(newUrl, "mapquestmap", position + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,height=" + height + ",width=" + width);
		if (mqsizablewin.opener == null) mqsizablewin.opener = self;
		mqsizablewin.focus();
	}
}

//******************************
// PICK DATE

function PickDate(form, field)
{
	var nwquery = "CalendarServlet?frm=" + form + "&fld=" + field + "&dt=" + eval("document." + form + "." + field + ".value");
	datewin = window.open(nwquery, "datewin", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=385,height=320");
	if (datewin.opener == null) datewin.opener = self;
	datewin.focus();
}

function PickTodaysDate(_form, field)
{
	var now = new Date();
	mm = now.getMonth() + 1;
	dd = now.getDate();
	yy = now.getFullYear();
	theForm = eval('document.'+ _form);
	theForm[field].value= mm + '/' +  dd + '/' +  yy;
}

var dtCh = "/";
var minYear = 1900;
var maxYear = 2100;

function isDate(dtStr)
{
    var daysInMonth = DaysArray(12);
    var pos1 = dtStr.indexOf(dtCh);
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1);
    var strMonth = dtStr.substring(0, pos1);
    var strDay = dtStr.substring(pos1 + 1, pos2);
    var strYear = dtStr.substring(pos2 + 1);
    strYr = strYear;

    if(strDay.charAt(0) == "0" && strDay.length > 1)
        strDay = strDay.substring(1);

    if(strMonth.charAt(0) == "0" && strMonth.length > 1)
        strMonth = strMonth.substring(1);

    for(var i=1; i<=3; i++)
    {
        if (strYr.charAt(0) == "0" && strYr.length > 1)
            strYr = strYr.substring(1);
    }

    month = parseInt(strMonth);
    day = parseInt(strDay);
    year = parseInt(strYr);

    if(pos1 == -1 || pos2 == -1)
    {
    	alert("The date format should be : mm/dd/yyyy");
    	return false;
    }

    if(strMonth.length < 1 || month < 1 || month > 12)
    {
        alert("Please enter a valid month");
   		return false;
   	}

   	if(strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month])
    {
   		alert("Please enter a valid day");
   		return false;
   	}

   	if(strYear.length != 4 || year == 0 || year < minYear || year > maxYear)
    {
        alert("Please enter a valid 4 digit year between " + minYear + " and " + maxYear);
   		return false;
   	}

    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false)
    {
        alert("Please enter a valid date");
        return false;
   	}

    return true;
}

//******************************
// PICK PURCHASER

function PickPurchaser(form, field, field2, field3)
{
	var nwquery = "PurchaserServlet?frm=" + form + "&fld=" + field + "&fld2=" + field2 + "&fld3=" + field3;
	purchwin = window.open(nwquery, "mhspopuppurch", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=385,height=320");
	if (purchwin.opener == null) purchwin.opener = self;
	purchwin.focus();
}

//******************************

function isDisplayable(filename)
{
	var i	= filename.lastIndexOf(".");
	if (i == -1)
	{
		return false;
	}
	var ext = filename.substring(i,filename.length).toLowerCase();
	if (ext == ".gif" || ext == ".jpg" || ext == ".jpe" || ext == ".jpeg")
	{
		return true;
	}
	return false;
}


//******************************
//  Check Radio Button

function CheckRadioButton(form, element, index)
{
	eval("document." + form + "." + element + "[" + index + "]" + ".checked = true");
}

//******************************



//******************************
//  Submit Opener's Form

function SubmitOpenersForm(form)
{
	eval("window.opener.document." + form + ".submit()");
}

//******************************


//******************************
//  Change Opener's Location

function ChangeOpenersLocation(url)
{
	eval("window.opener.document." + form + ".submit()");
}

//******************************



//******************************
//  Toggle Check Box

function ToggleCheckbox(form, element)
{
	if (eval("document." + form + "." + element + ".checked == true"))
	{
		eval("document." + form + "." + element + ".checked = false");
	}
	else
	{
		eval("document." + form + "." + element + ".checked = true");
	}
}

//******************************

//******************************
//  Forward to Login

    function ForwardToLogin(url)
	{
		winName = window.name;

		if (winName != null)
		{
			//	Check for MHS Popup window
			if (winName.length > 7)
			{
				winPrefix = winName.substr(0, 8);
				if(winPrefix == "mhspopup")
				{
					window.opener.location = url;
					self.close();
					return;
				}
			}

			//	Check for XactTotal popup
			if (winName.length > 4)
			{
				winPrefix = winName.substr(0, 5);
				if(winPrefix == "xtpop")
				{
					window.opener.location = url;
					self.close();
					return;
				}
			}
		}
		window.location = url;
	}

//******************************


//******************************
//  Forward Popup or Main Window


    function ForwardPopupOrMain(PopupURL, MainURL)
	{
		var winName = window.name;
		var winPrefix = "";

		if (winName != null)
		{
			if (winName.length > 7)
			{
				winPrefix = winName.substr(0, 8);
				if(winPrefix == "mhspopup")
				{
					window.location = PopupURL;
					return;
				}
			}
		}

		window.location = MainURL;
	}

//******************************


//******************************
//  Unescape douple quotes

	function UnescapeDQ(str)
	{
		return str.replace(/~!~/gi, "\"");
	}

//******************************


//******************************
//  Check Supported Browser Type

	function isSupportedBrowser()
	{
		var version = parseFloat(navigator.appVersion);
		var browserUAString = navigator.userAgent;

		//  If browser is MS Internet Explorer
		if (browserUAString.indexOf("MSIE") != -1)
		{
			var msieVersion = browserUAString.slice(browserUAString.indexOf("MSIE ") + 5);
			if (parseFloat(msieVersion) >= 5.5)
			{
				return;
			}

			//	Get the actual MSIE version number rather than the number it reports in navigator.appVersion
			version = parseFloat(msieVersion);
		}
		alert("The browser you are using (" + navigator.appName + " " + version + ") is not supported by XactInfo.com.\n\nXactInfo.com supports Microsoft Internet Explorer 5.5 and higher.");
	}

//******************************


//******************************
//  ChangeBrowserNotifyOption

	function ChangeBrowserNotifyOption()
	{
		if (document.popunsupportedbrowser.UPUnsupportedBrowserPopSubmit.checked == true)
		{
			document.popunsupportedbrowser.submit();
		}
		else
		{
			window.close();
		}
		return;
	}

//******************************

//******************************
//  Set a input element value

	function setFormElementValue(element, value)
	{
		if (typeof eval(element) != "undefined")
		{
			eval(element).value = value;
		}
	}

//******************************


//******************************
//  Set Linked Radio Button

function SetLinkedRadioButton(radio, linkedField)
{
	if (linkedField.value == "" || linkedField.value == null)
	{
		radio.checked = false;
	}
	else
	{
		radio.checked = true;
	}
}

//******************************
//******************************
//  Get the version number of MSIE Browser.
//	If the browser is not MSIE, returns -1
//	Otherwise returns the version as a float.

	function getMSIEVersionNumber()
	{
		var previousString	= "MSIE ";
		var trailingString	= ";";
		var appString		= "Microsoft";

		if (navigator.appName.indexOf(appString) == -1)
		{
			return -1;
		}

		var versionString = navigator.appVersion;
		var begin = previousString.length + versionString.indexOf(previousString);
		var end = versionString.indexOf(trailingString, begin);
		versionString = versionString.substring(begin, end);
		return parseFloat(versionString);
	}
//******************************
//******************************
//  Returns the specified cookie value.
//	Returns null if the specified cookie was not found.
//

	function getCookie(name)
	{
		//	Declare return var
		var cookie = null;

		//	validate input
		if (name != null)
		{
			//	Declare & initalize vars
			var	nameValDelim = "=";
			var	cookieDelim = ";";
			var allCookies = document.cookie;
			var pos = allCookies.indexOf(name);

			//	Handle case: name exists
			if (pos != -1)
			{
				var start = pos + name.length + nameValDelim.length;
				var end = allCookies.indexOf(cookieDelim, start);
				if (end == -1)
				{
					end = allCookies.length;
				}
				cookie = allCookies.substring(start, end);
				cookie = unescape(cookie);
			}
		}

		//	Return null or cookie value
		return cookie;
	}
//******************************


//  Takes the current window.location and removes
//  everthing following the last slash then adds the
//  value of to
function relativeForward(to)
{
	var loc = window.location.pathname;
	window.location = getRelativeLocation(loc, to);
}

//  Takes the specified URL and removes
//  everthing following the last slash then adds the
//  value of to
function getRelativeLocation(URL, to)
{
	var loc = URL;
	var idx = loc.lastIndexOf("/") + 1;
	var newLoc = loc.substring(0, idx) + to;
	//alert("getRelativeLocation is returning [" + newLoc + "]");
	return newLoc;
}


//******************************
//  Forward to Login

    function handleTimeout(url)
	{
		winName = top.name;

		if (winName != null)
		{
			//	Check for MHS Popup window
			if (winName.length > 7)
			{
				winPrefix = winName.substr(0, 8);
				if(winPrefix == "mhspopup")
				{
					if (typeof top.poplevel != 'undefined')
					{
						var openerLevel = "top";
						var appendStr = ".opener";
						for (i = 0; i < poplevel; i++)
						{
							openerLevel += appendStr;
						}

						var curOpener = eval(openerLevel);
						curOpener.location = url;

						for (i = 0; i < poplevel; i++)
						{
							openerLevel = openerLevel.slice(0, openerLevel.length - appendStr.length);
							curOpener = eval(openerLevel);
							curOpener.close();
						}
					}
					else
					{
						top.opener.location = url;
					}
					top.close();
					return;
				}
			}

		}
		document.f.submit();
		//top.location = url;
	}

//******************************


function verifyItemsForm(itemsForm, itemNameField, itemPurchDateField, itemDescField, itemNoteField)
{
	if("" == itemsForm[itemNameField].value)
	{
		alert("An item name is required in order to save the item.")
		itemsForm[itemNameField].focus();
	}
	else if(itemsForm[itemNameField].value.length > 30)
	{
		alert("Please limit the item name to 30 characters")
		itemsForm[itemNameField].focus();
	}
	else if("" != itemsForm[itemPurchDateField].value && !isDate(itemsForm[itemPurchDateField].value))
	{
		itemsForm[itemPurchDateField].focus();
	}
	else if(itemsForm[itemDescField].value.length > 1000)
	{
		alert('Please limit the item description to 1000 characters.');
		itemsForm[itemDescField].focus();		
	}
	else if(typeof itemsForm[itemNoteField] != 'undefined' && null != itemsForm[itemNoteField] 
			&& itemsForm[itemNoteField].value.length > 1000)
	{	
		alert('Please limit your notes to 1000 characters.');
		itemsForm[itemNoteField].focus();		
	}
	else
	{
		itemsForm.submit();
	}
		
}
//******************************


function verifyClaimForm(claimForm, claimNameField, claimNoteField, claimDate)
{
	if("" == claimForm[claimNameField].value)
	{
		alert("An claim name is required in order to save the item.")
		claimForm[claimNameField].focus();
	}
	else if(claimForm[claimNameField].value.length > 30)
	{
		alert("Please limit the claim name to 30 characters")
		claimForm[claimNameField].focus();
	}
	else if("" != claimForm[claimDate].value && !isDate(claimForm[claimDate].value))
	{
		claimForm[claimDate].focus();
	}
	else if(typeof claimForm[claimNoteField] != 'undefined' && null != claimForm[claimNoteField] 
			&& claimForm[claimNoteField].value.length > 1000)
	{	
		alert('Please limit your notes to 1000 characters.');
		claimForm[claimNoteField].focus();		
	}
	else
	{
		claimForm.submit();
	}
		
}

//***********CONTENTS*************************
function selectItem(itemId, storeId, itemSrc, itemname, desc, manufacturer, model, purchname, purchprice, purchdate, itemurl)
{
	blockPopupContent(true, "Adding your item...");
	
	var nameInputName = 'itemname';
	var descInputName = 'desc';
	var manufInputName = 'manuf';
	var modelInputName = 'model';
	var purchnameInputName = 'purchname';
	var purchpriceInputName = 'purchprice';
	var purchdateInputName = 'purchdate';
	var itemurlInputName = 'itemurl';
	var itemidInputName = 'itemId';
	var storeidInputName = 'storeId';
	var itemsrcInputName = 'itemSrc';
	var itemqtyInputName = 'qty';
	var manufSpanId = 'manufSpan';//The value of this id must be TagItem.MANUF+"Span"
	var modelSpanId = 'modelSpan';//The value of this id must be TagItem.MODEL+"Span"


	if(!window.opener.closed)
	{
		inQuickEntryMode = false;
		inDefaultsMode = false;
		winOpener = window.opener;
		openerFormObject = null;
		
		if(typeof winOpener.document.itemform != 'undefined' && null != winOpener.document.itemform)
		{
			openerFormObject = winOpener.document.itemform;
		}
		else if(typeof winOpener.document.addItemsForm != 'undefined' && null != winOpener.document.addItemsForm)
		{
			openerFormObject = winOpener.document.addItemsForm
			inQuickEntryMode = true;
		}
		else if(typeof winOpener.document.addClaimItemsForm != 'undefined' && null != winOpener.document.addClaimItemsForm)
		{
			openerFormObject = winOpener.document.addClaimItemsForm;
			inQuickEntryMode = true;
		}
		if(typeof winOpener.document.addDefaultItemsForm != 'undefined' && null != winOpener.document.addDefaultItemsForm)
		{
			openerFormObject = winOpener.document.addDefaultItemsForm;
			inDefaultsMode = true;
		}
		
		if(openerFormObject)
		{
			if(inDefaultsMode)
			{
				nameInputName = openerFormObject.currItemPrefix.value + nameInputName + openerFormObject.currItemSuffix.value;
				descInputName = openerFormObject.currItemPrefix.value + descInputName + openerFormObject.currItemSuffix.value;
				manufInputName = openerFormObject.currItemPrefix.value + manufInputName + openerFormObject.currItemSuffix.value;
				modelInputName = openerFormObject.currItemPrefix.value + modelInputName + openerFormObject.currItemSuffix.value;
				purchnameInputName = openerFormObject.currItemPrefix.value + purchnameInputName + openerFormObject.currItemSuffix.value;
				purchpriceInputName = openerFormObject.currItemPrefix.value + purchpriceInputName + openerFormObject.currItemSuffix.value;
				purchdateInputName = openerFormObject.currItemPrefix.value + purchdateInputName + openerFormObject.currItemSuffix.value;
				itemurlInputName = openerFormObject.currItemPrefix.value + itemurlInputName + openerFormObject.currItemSuffix.value;
				itemidInputName = openerFormObject.currItemPrefix.value + itemidInputName + openerFormObject.currItemSuffix.value;
				storeidInputName = openerFormObject.currItemPrefix.value + storeidInputName + openerFormObject.currItemSuffix.value;
				itemsrcInputName = openerFormObject.currItemPrefix.value + itemsrcInputName + openerFormObject.currItemSuffix.value;
				itemqtyInputName = openerFormObject.currItemPrefix.value + itemqtyInputName + openerFormObject.currItemSuffix.value;
				manufSpanId = openerFormObject.currItemPrefix.value + manufSpanId + openerFormObject.currItemSuffix.value;
				modelSpanId = openerFormObject.currItemPrefix.value + modelSpanId + openerFormObject.currItemSuffix.value;
			}
			
			
			if("" == openerFormObject[nameInputName].value)
			{
				openerFormObject[nameInputName].value = itemname;	
			}
			
			openerFormObject[descInputName].value = desc;
			
			openerFormObject[manufInputName].value = manufacturer;
			openerFormObject[modelInputName].value = model;
			
			if("" == openerFormObject[purchnameInputName].value)
			{
				openerFormObject[purchnameInputName].value = purchname;
			}
			
			if("" != purchprice)
			{
				openerFormObject[purchpriceInputName].value = purchprice;
			}
			
			if("" == openerFormObject[purchdateInputName].value)
			{
				openerFormObject[purchdateInputName].value = purchdate;
			}
			openerFormObject[itemurlInputName].value = itemurl;
			openerFormObject[itemidInputName].value = itemId;
			openerFormObject[storeidInputName].value = storeId;
			openerFormObject[itemsrcInputName].value = itemSrc;
			
			openerFormObject[manufInputName].style.display = 'none';
			openerFormObject[modelInputName].style.display = 'none';
			
			manufSpan = winOpener.document.getElementById(manufSpanId);
			manufSpan.innerHTML = manufacturer;
			manufSpan.style.display = 'inline';
			
			modelSpan = winOpener.document.getElementById(modelSpanId);
			modelSpan.innerHTML = model;
			modelSpan.style.display = 'inline';
			
			popupAddToInvCheckbox = document.getElementById('addtoinventoryfromclaim');
			openerAddToInvCheckbox = openerFormObject.addtoinventoryfromclaim;
			if(null != openerAddToInvCheckbox && typeof openerAddToInvCheckbox != 'undefined' 
				&& null != popupAddToInvCheckbox && typeof popupAddToInvCheckbox != 'undefined')
			{
				openerAddToInvCheckbox.checked = popupAddToInvCheckbox.checked;
			}

			popupAddToRoom = document.getElementById('addtofolder');
			openerAddToRoom = openerFormObject.addtofolder;
			if(null != openerAddToRoom && typeof openerAddToRoom != 'undefined' 
				&& null != popupAddToRoom && typeof popupAddToRoom != 'undefined')
			{
				openerAddToRoom.value = popupAddToRoom.value;
			}

			popupQty = document.getElementById('qty');
			openerQty = openerFormObject[itemqtyInputName];
			if(null != openerQty && typeof openerQty != 'undefined' 
				&& null != popupQty && typeof popupQty != 'undefined')
			{
				openerQty.value = popupQty.value;
			}
			
			if(inQuickEntryMode)
			{
				openerFormObject.submit();
			}
		}
		
		if(!inQuickEntryMode)
		{
			winOpener.focus()
			window.close();
		}
	}
}

function populateVarsForDefaults(formObj, prefix, suffix)
{
	formObj.currItemPrefix.value = prefix;
	formObj.currItemSuffix.value = suffix;
}

function openItemSearchForDefaults(itemFormObj, itemFieldName, prefix, suffix)
{
	populateVarsForDefaults(itemFormObj, prefix, suffix)
	openItemSearch(itemFormObj, itemFieldName)
}

//itemFieldName is the name of the field you want to pull text from to populate the search box in the content search
var CONTENTS_POPUP_WINDOW = "CONTENTS_POPUP_WINDOW"
var contentsPopupWin = null;
function openItemSearch(itemFormObj, itemFieldName)
{		
	itemName = itemFormObj[itemFieldName].value;
	height = 792
	width = 960
	contentsURL = "content_search.jsp?search_for=" + escape(itemName) + "&contents_search=on&submit_search=true"
	if("addDefaultItemsForm" == itemFormObj.name)
	{
		if(null != itemFormObj.refSearchImg && typeof itemFormObj.refSearchImg != 'undefined'
			&& "" != itemFormObj.refSearchImg.value && "null" != itemFormObj.refSearchImg.value)
		{
			contentsURL += "&search_room="+itemFormObj.refSearchImg.value;
		}
	}
	contentsPopupWin = window.open(contentsURL, CONTENTS_POPUP_WINDOW, "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=" + height + ",width=" + width);
}

function onItemAdded(showItemAddedNotification)
{
	contentsPopupWin = window.open('', CONTENTS_POPUP_WINDOW);
	if(null != contentsPopupWin && typeof contentsPopupWin != 'undefined')
	{
		//this happens when they close the window before the item is added
		if("about:blank" == contentsPopupWin.document.location.href)
		{
			contentsPopupWin.close();
		}
		else
		{
			contentsPopupWin.focus();
			contentsPopupWin.blockPopupContent(false);
			if(showItemAddedNotification)
			{
				itemAddedDiv = contentsPopupWin.document.getElementById("item_added");
				if(null != itemAddedDiv && typeof itemAddedDiv != 'undefined')
				{
					itemAddedDiv.style.display = 'inline';
					setTimeout("hideItemAddedDiv()", 4000);
				}
			}
		}
	}
}

function hideItemAddedDiv()
{
	if(typeof contentsPopupWin != 'undefined' && null != contentsPopupWin && !contentsPopupWin.closed)
	{
		itemAddedDiv = contentsPopupWin.document.getElementById("item_added");
		if(null != itemAddedDiv && typeof itemAddedDiv != 'undefined')
		{
			itemAddedDiv.style.display = 'none';
		}
	}
}

function noShowItemAdded()
{
	ajaxPost("HndItems", 'noshowitemadded=true', null);
	itemAddedDiv = document.getElementById("item_added");
	if(null != itemAddedDiv && typeof itemAddedDiv != 'undefined')
	{
		itemAddedDiv.style.display = 'none';
	}
}

function blockPopupContent(blockContent, message)
{
	var popupBody = document.getElementById("popupBody");
	if(typeof popupBody != 'undefined' && null != popupBody)
	{
		var blocker = document.getElementById("popupBodyBlocker");
		if(typeof blocker == 'undefined' || null == blocker)
		{
			blocker = document.createElement('div');
			blocker.id = 'popupBodyBlocker';
			blocker.style.position = 'absolute';
			blocker.style.top = '0';
			blocker.style.left = '0';
			blocker.style.width = '100%';
			blocker.style.height = '100%';
			blocker.style.backgroundColor = '#FFFFFF';
			blocker.style.textAlign = 'center';
			blocker.style.verticalAlign = 'middle';
			blocker.style.fontSize = '18pt';
			blocker.style.display = 'none';
			popupBody.appendChild(blocker);
		}
		if(typeof message != 'undefined' && null != message)
		{
			blocker.innerHTML = '<div style="margin-top:30%">'+message+'</div>';
		}
		
		if(blockContent)
		{
			blocker.style.display = 'inline';
		}
		else
		{
			blocker.style.display = 'none';
		}
	}
}

function departmentChange()
{
	document.search_criteria_form.category_id.selectedIndex = VALUE_NOT_SET;
	document.search_criteria_form.type_id.selectedIndex = VALUE_NOT_SET;
	document.search_criteria_form.brand_id.selectedIndex = VALUE_NOT_SET;
	document.search_criteria_form.model_id.selectedIndex = VALUE_NOT_SET;
	document.search_criteria_form.todo.value = TODO_ITEM_SEARCH;
	document.search_criteria_form.submit();
}

function categoryChange()
{
	document.search_criteria_form.type_id.selectedIndex = VALUE_NOT_SET;
	document.search_criteria_form.brand_id.selectedIndex = VALUE_NOT_SET;
	document.search_criteria_form.model_id.selectedIndex = VALUE_NOT_SET;
	document.search_criteria_form.todo.value = TODO_ITEM_SEARCH;
	document.search_criteria_form.submit();
}

function typeChange()
{
	document.search_criteria_form.brand_id.selectedIndex = VALUE_NOT_SET;
	document.search_criteria_form.model_id.selectedIndex = VALUE_NOT_SET;
	document.search_criteria_form.todo.value = TODO_ITEM_SEARCH;
	document.search_criteria_form.submit();
}

function brandChange()
{
	document.search_criteria_form.model_id.selectedIndex = VALUE_NOT_SET;
	document.search_criteria_form.todo.value = TODO_ITEM_SEARCH;
	document.search_criteria_form.submit();
}

function selectDepartment(deptid, deptdesc)
{
	document.search_criteria_form.department_id.value = deptid;
	document.search_criteria_form.department_desc.value = deptdesc;
	document.search_criteria_form.category_id.value = VALUE_NOT_SET;
	document.search_criteria_form.category_desc.value = "";
	document.search_criteria_form.type_id.value = VALUE_NOT_SET;
	document.search_criteria_form.type_desc.value = "";
	document.search_criteria_form.todo.value = TODO_ITEM_SEARCH;
	document.search_criteria_form.submit();
}

function selectCategory(catid, catdesc)
{
	document.search_criteria_form.category_id.value = catid;
	document.search_criteria_form.category_desc.value = catdesc;
	document.search_criteria_form.type_id.value = VALUE_NOT_SET;
	document.search_criteria_form.type_desc.value = "";
	document.search_criteria_form.todo.value = TODO_ITEM_SEARCH;
	document.search_criteria_form.submit();
}

function selectType(typeid, typedesc)
{
	document.search_criteria_form.type_id.value = typeid;
	document.search_criteria_form.type_desc.value = typedesc;
	document.search_criteria_form.todo.value = TODO_ITEM_SEARCH;
	document.search_criteria_form.submit();
}

function selectDeptAndCat(deptid, deptdesc, catid, catdesc)
{
	document.search_criteria_form.department_id.value = deptid;
	document.search_criteria_form.department_desc.value = deptdesc;
	document.search_criteria_form.category_id.value = catid;
	document.search_criteria_form.category_desc.value = catdesc;
	document.search_criteria_form.type_id.value = VALUE_NOT_SET;
	document.search_criteria_form.type_desc.value = "";
	document.search_criteria_form.todo.value = TODO_ITEM_SEARCH;
	document.search_criteria_form.submit();
}

function selectTab(tabid)
{
	var curr_tab = document.search_criteria_form.searchtab.value;

	if(todoBasicSearch)
	{
		document.search_criteria_form.department_id.value = VALUE_NOT_SET_STR;
		document.search_criteria_form.department_desc.value = "";
		document.search_criteria_form.category_id.value = VALUE_NOT_SET_STR;
		document.search_criteria_form.category_desc.value = "";
		document.search_criteria_form.type_id.value = VALUE_NOT_SET_STR;
		document.search_criteria_form.type_desc.value = "";
	}
	else
	{
		if (curr_tab == 2)
		{
			document.search_criteria_form.department_desc.value = 
				document.search_criteria_form.department_id[
					document.search_criteria_form.department_id.selectedIndex].text;
			document.search_criteria_form.category_desc.value = 
				document.search_criteria_form.category_id[
					document.search_criteria_form.category_id.selectedIndex].text;
			document.search_criteria_form.type_desc.value = 
				document.search_criteria_form.type_id[
					document.search_criteria_form.type_id.selectedIndex].text;
		}
	}

	document.search_criteria_form.searchtab.value = tabid;
	document.search_criteria_form.todo.value= TODO_ITEM_SEARCH;
	document.search_criteria_form.submit();
}

function selectRoom(room)
{
	document.search_criteria_form.search_room.value = room;
	document.search_criteria_form.search_room_topic.value = '';
	document.search_criteria_form.search_room_refined_topic.value = '';
	document.search_criteria_form.search_room_general_item.value = '';
	document.search_criteria_form.search_room_general_item_code.value = '';
	document.search_criteria_form.search_room_search_string.value = '';
	document.search_criteria_form.todo.value= TODO_ITEM_SEARCH;
	document.search_criteria_form.submit();
}

function selectRoomTopic(room, topic)
{
	document.search_criteria_form.search_room.value = room;
	document.search_criteria_form.search_room_topic.value = topic;
	document.search_criteria_form.search_room_refined_topic.value = '';
	document.search_criteria_form.search_room_general_item.value = '';
	document.search_criteria_form.search_room_general_item_code.value = '';
	document.search_criteria_form.search_room_search_string.value = '';
	document.search_criteria_form.todo.value= TODO_ITEM_SEARCH;
	document.search_criteria_form.submit();
}

function selectRoomRefinedTopic(room, topic, refinedTopic)
{
	document.search_criteria_form.search_room.value = room;
	document.search_criteria_form.search_room_topic.value = topic;
	document.search_criteria_form.search_room_refined_topic.value = refinedTopic;
	document.search_criteria_form.search_room_general_item.value = '';
	document.search_criteria_form.search_room_general_item_code.value = '';
	document.search_criteria_form.search_room_search_string.value = '';
	document.search_criteria_form.todo.value= TODO_ITEM_SEARCH;
	document.search_criteria_form.submit();
}

function selectRoomGeneralItem(room, topic, refinedTopic, generalItem, generalItemCode)
{
	document.search_criteria_form.search_room.value = room;
	document.search_criteria_form.search_room_topic.value = topic;
	document.search_criteria_form.search_room_refined_topic.value = refinedTopic;
	document.search_criteria_form.search_room_general_item.value = generalItem;
	document.search_criteria_form.search_room_general_item_code.value = generalItemCode;
	document.search_criteria_form.search_room_search_string.value = '';
	document.search_criteria_form.todo.value= TODO_ITEM_SEARCH;
	document.search_criteria_form.submit();
}

function searchRoomSearch(searchString)
{
	if(null == searchString || "" == searchString)
	{
		return;
	}
	document.search_criteria_form.search_room_search_string.value = searchString;
	document.search_criteria_form.todo.value= TODO_ITEM_SEARCH;
	document.search_criteria_form.submit();
}

function selectResultsPageNumber(pageNumber, todo, basicSearchDeptId, amazonSearchIndex)
{
	document.search_criteria_form.search_results_page_number.value = pageNumber;
	if(null != document.search_criteria_form.basic_search_department_id &&
		typeof document.search_criteria_form.basic_search_department_id != 'undefined')
	{
		document.search_criteria_form.basic_search_department_id.value = basicSearchDeptId;
	}

	if(null != document.search_criteria_form.amazon_item_search_index &&
		typeof document.search_criteria_form.amazon_item_search_index != 'undefined')
	{
		document.search_criteria_form.amazon_item_search_index.value = amazonSearchIndex;
	}
	document.search_criteria_form.todo.value= todo;
	document.search_criteria_form.submit();
}

function reSubmitSearchResults(searchFor, basicDeptSearchId, xactcontentsSearch, amazonSearch, internetSearch)
{
	document.basic_search_form.search_for.value = searchFor;
	if("" != xactcontentsSearch)
	{
		document.basic_search_form.contents_search.checked = true;
	}
	else
	{		
		document.basic_search_form.contents_search.checked = false;
	}
	
	if("" != amazonSearch)
	{
		document.basic_search_form.amazon_search.checked = true;
	}
	else
	{		
		document.basic_search_form.amazon_search.checked = false;
	}
	
	if("" != internetSearch)
	{
		document.basic_search_form.internet_search.checked = true;
	}
	else
	{		
		document.basic_search_form.internet_search.checked = false;
	}
	
	document.basic_search_form.department_id.value= basicDeptSearchId;
	document.basic_search_form.todo.value= TODO_BASIC_SEARCH;
	document.basic_search_form.searchtab.value= 1;
	document.basic_search_form.submit();
}

function basicSearch()
{
	document.basic_search_form.search_for.value = document.
			basic_search_easy_submit.search_for_temp.value;

	if(nullTrim(document.basic_search_form.search_for.value) != "")
	{
		if(!document.basic_search_form.contents_search.checked 
			&& !document.basic_search_form.amazon_search.checked
			&& !document.basic_search_form.internet_search.checked)
		{
			alert("Please select the type of search you would like to perform.");
		}
		else
		{
			document.basic_search_form.todo.value= TODO_BASIC_SEARCH;
			document.basic_search_form.searchtab.value= 1;
			document.basic_search_form.submit();
		}
	}
}

function itemSearch(deptid, deptName, catid, catName, typeid, typeName, basicSearchDeptId)
{
	document.search_criteria_form.department_id.value = deptid;
	document.search_criteria_form.department_desc.value = deptName;
	document.search_criteria_form.category_id.value = catid;
	document.search_criteria_form.category_desc.value = catName;
	document.search_criteria_form.type_id.value = typeid;
	document.search_criteria_form.type_desc.value = typeName;
	document.search_criteria_form.search_for.value = searchFor;
	document.search_criteria_form.action = searchResultsPage;
	document.search_criteria_form.todo.value = TODO_SEARCH_RESULTS;
	document.search_criteria_form.amazon_item_search_index.value = '';
	document.search_criteria_form.basic_search_department_id.value = basicSearchDeptId;
	document.search_criteria_form.submit();
}

function amazonItemSearch(searchIndex, basicSearchDeptId)
{
	document.search_criteria_form.department_id.value = '';
	document.search_criteria_form.department_desc.value = '';
	document.search_criteria_form.category_id.value = '';
	document.search_criteria_form.category_desc.value = '';
	document.search_criteria_form.type_id.value = '';
	document.search_criteria_form.type_desc.value = '';
	document.search_criteria_form.search_for.value = searchFor;
	document.search_criteria_form.action = searchResultsPage;
	document.search_criteria_form.todo.value = TODO_SEARCH_RESULTS;
	document.search_criteria_form.amazon_item_search_index.value = searchIndex;
	document.search_criteria_form.basic_search_department_id.value = basicSearchDeptId;
	
	document.search_criteria_form.submit();
}


function standardSearch()
{
	if (searchtab == 2)
	{
		if((document.search_criteria_form.department_id[
				document.search_criteria_form.department_id.selectedIndex]
				.value == VALUE_NOT_SET_STR) ||
				(document.search_criteria_form.category_id[
				document.search_criteria_form.category_id.selectedIndex]
				.value == VALUE_NOT_SET_STR) ||
				(document.search_criteria_form.type_id[
				document.search_criteria_form.type_id.selectedIndex]
				.value == VALUE_NOT_SET_STR))
		{
			alert("You must select a department, group, \n"
				+ "and type before searching for items.");
		}
		else
		{
			document.search_criteria_form.action = searchResultsPage;
			document.search_criteria_form.todo.value= TODO_SEARCH_RESULTS;
			document.search_criteria_form.searchtab.value="1";
			document.search_criteria_form.submit();
		}
	}
	else
	{
		document.search_criteria_form.action = searchResultsPage;
		document.search_criteria_form.todo.value = TODO_SEARCH_RESULTS;
		document.search_criteria_form.searchtab.value="1";
		document.search_criteria_form.submit();
	}
}

function resetSearch()
{
	if(typeof document.search_criteria_form.department_id != 'undefined' && null != document.search_criteria_form.department_id)
	{	
		document.search_criteria_form.department_id.value = '';
	}
	if(typeof document.search_criteria_form.department_desc != 'undefined' && null != document.search_criteria_form.department_desc)
	{	
		document.search_criteria_form.department_desc.value = '';
	}
	if(typeof document.search_criteria_form.category_id != 'undefined' && null != document.search_criteria_form.category_id)
	{	
		document.search_criteria_form.category_id.value = '';
	}
	if(typeof document.search_criteria_form.category_desc != 'undefined' && null != document.search_criteria_form.category_desc)
	{	
		document.search_criteria_form.category_desc.value = '';
	}
	if(typeof document.search_criteria_form.type_id != 'undefined' && null != document.search_criteria_form.type_id)
	{	
		document.search_criteria_form.type_id.value = '';
	}
	if(typeof document.search_criteria_form.type_desc != 'undefined' && null != document.search_criteria_form.type_desc)
	{	
		document.search_criteria_form.type_desc.value = '';
	}
	if(typeof document.search_criteria_form.search_for != 'undefined' && null != document.search_criteria_form.search_for)
	{	
		document.search_criteria_form.search_for.value = '';
	}
	if(typeof document.search_criteria_form.todo != 'undefined' && null != document.search_criteria_form.todo)
	{	
		document.search_criteria_form.todo.value = '';
	}
	if(typeof document.search_criteria_form.amazon_item_search_index != 'undefined' && null != document.search_criteria_form.amazon_item_search_index)
	{	
		document.search_criteria_form.amazon_item_search_index.value = '';
	}
	if(typeof document.search_criteria_form.search_room != 'undefined' && null != document.search_criteria_form.search_room)
	{	
		document.search_criteria_form.search_room.value = '';
	}
	if(typeof document.search_criteria_form.search_room_topic != 'undefined' && null != document.search_criteria_form.search_room_topic)
	{	
		document.search_criteria_form.search_room_topic.value = '';
	}
	if(typeof document.search_criteria_form.search_room_refined_topic != 'undefined' && null != document.search_criteria_form.search_room_refined_topic)
	{	
		document.search_criteria_form.search_room_refined_topic.value = '';
	}
	if(typeof document.search_criteria_form.search_room_search_string != 'undefined' && null != document.search_criteria_form.search_room_search_string)
	{	
		document.search_criteria_form.search_room_search_string.value = '';
	}
	document.search_criteria_form.action = searchResultsPage;
	document.search_criteria_form.submit();
	
}

// Converts null strings to blanks and trims off begining and ending whitespace
function nullTrim(str)
{
	if (str == null)
		return "";

	str = str.replace(/^[\s]+/,'');		// removes whitespace from begining
	str = str.replace(/[\s]+$/,'');		// removes whitespace from end

	return str;
}

function getWindowWidth()
{
	var windowWidth=0;
	if(typeof(window.innerWidth)=='number')
	{
		windowWidth=window.innerWidth;
	}
	else
	{
		if(document.documentElement &&	document.documentElement.clientWidth)
		{
			windowWidth = document.documentElement.clientWidth;
		}
		else
		{
			if(document.body && document.body.clientWidth)
			{
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}

function getWindowHeight()
{
	var windowHeight=0;
	if(typeof(window.innerHeight)=='number')
	{
		windowHeight=window.innerHeight;
	}
	else
	{
		if(document.documentElement &&	document.documentElement.clientHeight)
		{
			windowHeight = document.documentElement.clientHeight;
		}
		else
		{
			if(document.body && document.body.clientHeight)
			{
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function dispRefinedTopics(topic, headers)
{
	//get rid of any number suffix
	var lastChar = topic.length-1;
	for(lastChar = topic.length-1;lastChar >= 0 && "1234567890".indexOf(topic.charAt(lastChar)) != -1;lastChar--);
	topic = topic.substring(0, lastChar+1);
	
	hotspotTopicsDiv = document.getElementById("refined_topics_popup");
	hotspotTopicsDiv.style.display = "block";
	
	hotspotTopicsContentsDiv = document.getElementById("refined_topics_popup_contents");
	hotspotTopicsContentsDiv.innerHTML = "";
	hotspotTopicsContentsDiv.innerHTML += "<u>" + topic + "</u><br>";
	if("" == headers)
	{
		hotspotTopicsContentsDiv.innerHTML += "<br>";
	}
	else
	{
		headerArray = headers.split(",");
		for(i = 0;i < headerArray.length;i++)
		{
			hotspotTopicsContentsDiv.innerHTML += "&nbsp;&nbsp;" + headerArray[i] + "<br>";
		}
	}
	
	hotspotTopicsDiv.style.width = hotspotTopicsContentsDiv.offsetWidth + 'px';
	positionRefinedTopics(null);
}

function hideRefinedTopics()
{
	hotspotTopicsDiv = document.getElementById("refined_topics_popup");
	hotspotTopicsDiv.style.width = '';
	hotspotTopicsDiv.style.display = "none";
}

function positionRefinedTopics(e)
{
	hotspotTopicsDiv = document.getElementById("refined_topics_popup");
	xspace = 15;
	yspace = 5;
	mouseX = getMouseX(e);
	mouseY = getMouseY(e);
	maxX = getWindowWidth() - hotspotTopicsDiv.offsetWidth - xspace;
	maxY = getWindowHeight() - hotspotTopicsDiv.offsetHeight - yspace;
	
	if(mouseY > maxY)
	{
		hotspotTopicsDiv.style.top = mouseY - hotspotTopicsDiv.offsetHeight - yspace;
	}
	else
	{
		hotspotTopicsDiv.style.top = mouseY + yspace;
	}
	
	if(mouseX > maxX)
	{
		tempLeftVal = mouseX - hotspotTopicsDiv.offsetWidth - 5;
		if(tempLeftVal < 0)
		{
			tempLeftVal = 0;
		}
		hotspotTopicsDiv.style.left = tempLeftVal;
		
	}
	else
	{
		hotspotTopicsDiv.style.left = mouseX + xspace;
	}
}

var globalMouseX = null;
function getMouseX(e)
{
	if(typeof event != 'undefined' && null != event)
	{
		globalMouseX = event.clientX + document.body.scrollLeft;
	}
	else if(typeof e != 'undefined' && null != e)
	{
		globalMouseX = e.pageX;
	}

	return globalMouseX;
}

var globalMouseY = null;
function getMouseY(e)
{
	if(typeof event != 'undefined' && null != event)
	{
		globalMouseY = event.clientY + document.body.scrollTop;
	}
	else if(typeof e != 'undefined' && null != e)
	{
		globalMouseY = e.pageY;
	}

	return globalMouseY;
}

/*
* This function resizes the divs on the reference search page based on the image size
* basically, it gets the window width and height, 
* and then subtracts away whatever other elements are in the same line horizontally or vertically
*/
function setRefSearchDivs()
{
	winWidth = getWindowWidth();
	winHeight = getWindowHeight();
	sideDivsTotHeight = imgHeight-40;

	resultsWidthBuffer = 18;
	resultsHeightBuffer = sideDivsTotHeight + 291;
	resultsMinWidth = 929;
	resultsMinHeight = 121;
	searchResultsDiv = document.getElementById("ref_search_results");
	if(typeof searchResultsDiv != 'undefined' && null != searchResultsDiv)
	{
		newWidth = (winWidth - resultsWidthBuffer);
		if(newWidth >= resultsMinWidth)
		{
			searchResultsDiv.style.width = newWidth + 'px';		
			newHeight = (getWindowHeight() - resultsHeightBuffer);
		}
		else // account for the bottom scroll bar
		{
			searchResultsDiv.style.width = resultsMinWidth + 'px';	
			newHeight = (winHeight - (resultsHeightBuffer - 20));	
		}
	
		if(newHeight >= resultsMinHeight)
		{
			searchResultsDiv.style.height = newHeight + 'px';
		}
		else
		{
			searchResultsDiv.style.height = resultsMinHeight + 'px';	
		}
	}
	
	
	refinedTopicsWidthBuffer = imgWidth + 25;
	refinedTopicsMinWidth = resultsMinWidth - imgWidth - 5;
	refinedTopicsDiv = document.getElementById("refined_topics");
	if(typeof refinedTopicsDiv != 'undefined' && null != refinedTopicsDiv)
	{
		newWidth = (winWidth - refinedTopicsWidthBuffer);
		if(newWidth >= refinedTopicsMinWidth)
		{
			refinedTopicsDiv.style.width = newWidth + 'px';		
		}
		else
		{
			refinedTopicsDiv.style.width = refinedTopicsMinWidth + 'px';		
		}
	}
	refinedTopicContentsHeight = parseInt(sideDivsTotHeight * .4);
	refinedTopicsContentsDiv = document.getElementById("refined_topics_contents");
	if(typeof refinedTopicsContentsDiv != 'undefined' && null != refinedTopicsContentsDiv)
	{
		newWidth = (winWidth - refinedTopicsWidthBuffer);
		if(newWidth >= refinedTopicsMinWidth)
		{
			refinedTopicsContentsDiv.style.width = newWidth + 'px';		
		}
		else
		{
			refinedTopicsContentsDiv.style.width = refinedTopicsMinWidth + 'px';		
		}
		refinedTopicsContentsDiv.style.height = refinedTopicContentsHeight + 'px';
	}
	
	generalItemsWidthBuffer = refinedTopicsWidthBuffer
	generalItemsMinWidth = refinedTopicsMinWidth
	generalItemsDiv = document.getElementById("general_items");
	if(typeof generalItemsDiv != 'undefined' && null != generalItemsDiv)
	{
		newWidth = (winWidth - generalItemsWidthBuffer);
		if(newWidth >= generalItemsMinWidth)
		{
			generalItemsDiv.style.width = newWidth + 'px';		
		}
		else
		{
			generalItemsDiv.style.width = generalItemsMinWidth + 'px';		
		}
	}
	generalItemsContentsHeight = parseInt(sideDivsTotHeight * .6);
	generalItemsContentsDiv = document.getElementById("general_items_contents");
	if(typeof generalItemsContentsDiv != 'undefined' && null != generalItemsContentsDiv)
	{
		newWidth = (winWidth - generalItemsWidthBuffer);
		if(newWidth >= generalItemsMinWidth)
		{
			generalItemsContentsDiv.style.width = newWidth + 'px';		
		}
		else
		{
			generalItemsContentsDiv.style.width = generalItemsMinWidth + 'px';		
		}
		generalItemsContentsDiv.style.height = generalItemsContentsHeight + 'px';
	}
}

function setDeptSearchDivs()
{
	winWidth = getWindowWidth();
	winHeight = getWindowHeight()

	resultsWidthBuffer = 18;
	resultsHeightBuffer = 270;
	resultsMinWidth = 929;
	resultsMinHeight = 121;
	searchResultsDiv = document.getElementById("dept_search_results");
	if(typeof searchResultsDiv != 'undefined' && null != searchResultsDiv)
	{
		newWidth = (winWidth - resultsWidthBuffer);
		if(newWidth >= resultsMinWidth)
		{
			searchResultsDiv.style.width = newWidth + 'px';		
			newHeight = (getWindowHeight() - resultsHeightBuffer);
		}
		else // account for the bottom scroll bar
		{
			searchResultsDiv.style.width = resultsMinWidth + 'px';	
			newHeight = (winHeight - (resultsHeightBuffer - 20));	
		}
	
		if(newHeight >= resultsMinHeight)
		{
			searchResultsDiv.style.height = newHeight + 'px';
		}
		else
		{
			searchResultsDiv.style.height = resultsMinHeight + 'px';	
		}
	}
}

function setFooter()
{
    if( document.getElementById('header') != null &&
	document.getElementById('body') != null &&
	document.getElementById('footer') != null)
	{
		var windowHeight = getWindowHeight();
        if(windowHeight>0)
        {
            var headerHeight = document.getElementById('header').offsetHeight;
			var contentHeight = document.getElementById('body').offsetHeight;
            var footerElement = document.getElementById('footer');
            var footerHeight = footerElement.offsetHeight;

			footerElement.style.position = setFooterStyle();

            if(windowHeight < (headerHeight+contentHeight+footerHeight) )
            {
            		footerElement.style.top = headerHeight+contentHeight;
            }else
            {
            		footerElement.style.top = windowHeight - footerHeight;
            }
        }
    }
}

