var garrRooms = [];
var garrUserRooms = [];
var gaL = [];
var garrColWidths=[];
var gobjDivRoomItems=null;
var gobjDivSummary=null;
var garrDataCookie=['sc_data',''];
var garrLocationCookie=['sc_location',''];
var garrUnitSizesCookie=['sc_unitsizes',''];
var gobjDate=new Date();
var gstrCollapseExpand="none";
var gintTotalSize=0;
var garrSuggestedSizes=[];
var gintNumSuggestedSizes = 2;
var gobjHtmlLocationSelector=null;
var gintHouseTotal=0;
var gstrSavedLocation="";
var gblnPost=false;

if (defined(window.onload) && window.onload != null)
{
	var oldOnload=window.onload;
	window.onload=function(){
		oldOnload();
		init();
	};
}
else
{
	window.onload=init;
}

function init()
{
	gobjDate.setDate(gobjDate.getDate() + 30);
	gobjHtmlLocationSelector=getObjHtmlLocationSelector();
	loadSavedData();
	enforceRoomDisplay();
	setLocationSelectorIndex(gstrSavedLocation);
}

function loadRoom(strRoomName)
{
	var strRet="<div id='head'><h2><b><img src='/images/quote/icon_2.gif' alt=''>" + strRoomName + " " + "</b></h2></div>";
	strRet += "<div id='roomItemsPad'><div class='intro'>Press the \'+\' button to add items to your summary calculation. Return to Step 1 to see different lists of household items.</div>"
	if (gobjDivRoomItems==null)
	{
		gobjDivRoomItems=document.getElementById('roomItems');
	}
	strRet += "<div id='roomItemsCnt'>";
	strRet += "<table class='hdrRoom' border='0' cellspacing='0' cellpadding='0'>";
	strRet += "<tr class='r1'>"
	strRet += "<td class='c1'>Description</td>";
	//strRet += "<td class='c2'>Size</td>";
	//strRet += "<td class='c3'>Qty</td>";
	strRet += "<td class='c2'>Qty</td>";
	strRet += "<td class='c3'>+</td>";
	strRet += "</tr><tr><td colspan='4' class='paddingBottom'>&nbsp;</td></tr>";
	for (var i=1; i<garrRooms[strRoomName].length; i++)
	{
		strRet += makeItemRow(strRoomName, i, false, false);
	}
	strRet += "</table>";
	strRet += "</div></div><div style='clear:both;'></div>";
	if (gobjDivRoomItems != null)
	{
		gobjDivRoomItems.innerHTML=strRet + "</div>";
	}

}

function loadSummary(blnIsPageLoad)
{
	var intItemTotal=0;
	var intRoomTotal=0;
	var intHouseTotal=0;
	var strLastRoom="";
	var strRet="<div id='head'><h2><b><img src='/images/quote/icon_3.gif' alt=''>Summary</b></h2></div><div id='itemsSummaryCnt'>";
	strRet += "<div class='intro'>The items you've selected are listed below. Once you've added items, you will be able to \"Request a Quote\" for the total space you require.</div>";
	var strTmp="";
	var strTmpCookie="";
	var blnRoomHasQuantity=false;

	gintHouseTotal=0;
	garrDataCookie[1]="";

	if (gobjDivSummary==null)
	{
		gobjDivSummary=document.getElementById('itemsSummary');
	}

	for (i=0; i<garrUserRooms.length; i++)
	{
		var key=garrUserRooms[i];
		blnRoomHasQuantity=false;
		strTmpCookie="";
		intItemTotal=0;
		if (strLastRoom != key)
		{
			intRoomTotal=0;
		}

		for (var j=1; j<garrRooms[key].length;j++)
		{
			if (garrRooms[key][j][2] > 0)
			{
				var intItemSize=garrRooms[key][j][1];
				var intItemQuantity=garrRooms[key][j][2];
				if (!blnRoomHasQuantity)
				{
					strTmp="<div class='roomSummaryContainer' id='container_" + key + "' style='display:" + garrRooms[key][0][1] + ";'>";
					strTmp += "<table class='hdrSummary' border='0' cellspacing='0' cellpadding='0'>";
					strTmp += "<tr class='r1'>";
					strTmp += "<td class='c1'>Description</td>";
					//strTmp += "<td class='c2'>Size</td>";
					strTmp += "<td class='c2'>Qty</td>";
					strTmp += "<td class='c3'>Total</td>";
					strTmp += "<td class='c4'>X</td>";
					strTmp += "</tr><tr><td colspan='4' class='paddingBottom'>&nbsp;</td></tr>";
					blnRoomHasQuantity=true;
				}
				intItemTotal = (intItemSize * intItemQuantity);
				intRoomTotal += intItemTotal;
				strTmp += makeItemRow(key, j, true, true);
				if (strTmpCookie.length>0)
				{
					strTmpCookie += ",";
				}
				else
				{
					strTmpCookie += key + ":";
				}
				strTmpCookie += "" + j + "=" + intItemQuantity;
			}
		}
		if (blnRoomHasQuantity)
		{
			strTmp += "</table></div>";
			garrRooms[key][0][0]=true;
			if (garrDataCookie[1].length > 0)
			{
				garrDataCookie[1] += "|";
			}
			garrDataCookie[1] += strTmpCookie;
			intHouseTotal += intRoomTotal;
			gintHouseTotal = intHouseTotal;
			strRet += "<div id='roomHeading' title='Expand or contract this list' onclick=\"toggleRoom('" + key + "')\"><b>" + key + "</b><span>+/-</span><div style='clear:both;'></div></div>" + strTmp;
			//strRet += "<div class='roomTotal'><div style='float:right; margin-right:" + garrColWidths[3] + ";'>Room Total (m3): " + (intRoomTotal).toFixed(2) + "</div></div><div style='clear:both;'></div>";
			strRet += "<table border='0' cellspacing='0' cellpadding='0' class='roomTotal'><tr><td colspan='3'>Room Total (m3): " + (intRoomTotal).toFixed(2) + "</td><td style='width:" + garrColWidths[3] + ";'></td><td class='padding'></td></tr></table><div style='clear:both;'></div>";

		}
		strLastRoom=key;
	}

	if (intHouseTotal >0)
	{
		gintTotalSize=intHouseTotal;
		//strRet += "<table border='0' cellspacing='0' cellpadding='0' class='houseTotal'><tr><td colspan='3'><b>Storage Space Required (m3): " + (intHouseTotal).toFixed(2) + "</b></td><td style='width:" + garrColWidths[3] + ";'></td><td class='padding'></td></tr></table><div style='clear:both;'></div>";
	}
	else
	{
		strRet += "<div class='intro'>There are no items.</div>";
	}
	strRet += "</div>"
	if (intHouseTotal >0)
	{
		strRet += "<div id='rq'><a href='/selfstorage/?sc=" + (intHouseTotal).toFixed(2) + "'>Storage Space Required (m3): " + (intHouseTotal).toFixed(2) + "<br />Click here to Request a Quote</a></div>";
	}
	if (gobjDivSummary != null)
	{
		gobjDivSummary.innerHTML=strRet;
	}

	setDataCookie();
	loadStorageCalculator();

	if (intHouseTotal >0)
	{
		findSuitableContainers(blnIsPageLoad);
	}
}

function loadStorageCalculator()
{
	var objStorageLocatorContainer=document.getElementById("storageLocatorContainer");
	var objStorageLocatorContactForm=document.getElementById("storageLocatorContactForm");
	var objstorageLocatorMsg=document.getElementById("storageLocatorMsg");

	if (gintHouseTotal <= 0)
	{
		if (objStorageLocatorContainer != null)
		{
			objStorageLocatorContainer.style.display="none";
		}
		if (objStorageLocatorContactForm != null)
		{
			objStorageLocatorContactForm.style.display="none";
		}
		if (objstorageLocatorMsg != null)
		{
			objstorageLocatorMsg.style.display="block";
		}
	}
	else
	{
		if (objStorageLocatorContactForm != null)
		{
			objstorageLocatorMsg.style.display="none";
			objStorageLocatorContainer.style.display="block";
			objStorageLocatorContactForm.style.display="block";
		}
	}
}

function makeItemRow(strRoomName, intRoomItemNum, blnReadOnly, blnItemTotal)
{
	var strRet="";
	var strItemName=garrRooms[strRoomName][intRoomItemNum][0];
	var intItemMass=garrRooms[strRoomName][intRoomItemNum][1].toFixed(2);
	var intItemCount=garrRooms[strRoomName][intRoomItemNum][2];
	var strOnChangeJs="";
	var strOnClickJs="";
	var strRemoveFromCartJs=""
	var arrInputQtyIds=[];

	garrColWidths=['73%', '10%', '10%', '7%'];

	!blnReadOnly ? blnReadOnly=false : blnReadOnly=true;
	!blnItemTotal ? blnItemTotal=false : blnItemTotal=true;

	if (blnItemTotal)
	{
		garrColWidths=['67%', '10%', '15%', '7%'];
	}

	strRet += "<tr>"
	strRet += "<td id='itemList' style='width:" + garrColWidths[0] + "; padding-left:4px;' onmouseover=\"Tip('Size: " + intItemMass + "(m3)');\" onmouseout=\"UnTip()\">" + strItemName + "</td>";
	//strRet += "<td style='width:" + garrColWidths[1] + "; text-align:right; padding-right:2px;'>" + intItemMass + "</td>";
	strRet += "<td style='width:" + garrColWidths[1] + ";' align='center'>";
	strRet += "<input type='text' size='2' maxlength='2'";
	if (!blnReadOnly)
	{
		arrInputQtyIds[0]="r_qty_" + strRoomName + "_" + intRoomItemNum;
		strRet += " class='items' id='" + arrInputQtyIds[0] + "'";
		strRet += " value='1'";
		strOnClickJs="updateItemQuantity(0, 'r', '" + strRoomName + "', '" + intRoomItemNum + "');";
		strOnChangeJs="valInputQuantity('r', '" + strRoomName + "', '" + intRoomItemNum + "');"

	}
	else
	{
		arrInputQtyIds[1]="s_qty_" + strRoomName + "_" + intRoomItemNum;
		strRet += " class='items' id='" + arrInputQtyIds[1] + "'";
		strRet += " value='" + intItemCount + "'";
		strOnClickJs="";
		strOnChangeJs="updateItemQuantity(1, 's', '" + strRoomName + "', '" + intRoomItemNum + "');"
		strRemoveFromCartJs = "updateItemQuantity(1, 's', '" + strRoomName + "', '" + intRoomItemNum + "', 0);"
	}

	strRet += " onchange=\"" + strOnChangeJs + "\"></td>";

	if (blnItemTotal)
	{
		var intItemTotal = (garrRooms[strRoomName][intRoomItemNum][1] * garrRooms[strRoomName][intRoomItemNum][2]);
		strRet += "<td style='text-align:right; width:" + garrColWidths[2] + "; font-weight:bold; padding-right:2px;'>" + (intItemTotal).toFixed(2) + "</td>";
		strRet += "<td style='width:" + garrColWidths[3] + ";'><a class='addQty' href=\"javascript:" + strRemoveFromCartJs + "\">x</a></td>";
	}
	else
	{
		strRet += "<td style='width:" + garrColWidths[3] + ";'><a class='addQty' href=\"javascript:" + strOnClickJs + "\">+</a></td>";
	}
	return (strRet + "</tr><tr><td colspan='4' class='paddingBottomItem'>&nbsp;</td></tr>");
}

function updateItemQuantity(triStateAddSubRep, strItemIdPrefix, strRoomName, intRoomItemNum, newVal)
{
	var strItemId=strItemIdPrefix + "_qty_" + strRoomName + "_" + intRoomItemNum;
	var objHtmlEl=document.getElementById(strItemId);
	var strMathOperator=(triStateAddSubRep==-1 ? "-=" : triStateAddSubRep==1 ? "=" : "+=");
	if (objHtmlEl != null)
	{
		if (defined(newVal) && newVal.toString().length>0) objHtmlEl.value=newVal;
		valInputQuantity(strItemIdPrefix, strRoomName, intRoomItemNum);
		eval("garrRooms[strRoomName ][intRoomItemNum][2]" + strMathOperator + "parseFloat(" + objHtmlEl.value + ")");
		if (garrRooms[strRoomName][intRoomItemNum][2] < 0) garrRooms[strRoomName][intRoomItemNum][2]=0;
		if (garrRooms[strRoomName][intRoomItemNum][2] > 99) garrRooms[strRoomName][intRoomItemNum][2]=99;
		if (triStateAddSubRep!=1) updateUserRoomList(strRoomName, false);
		loadSummary(false);
	}
}

function loadSavedData()
{
	var savedData=getCookie(garrDataCookie[0]);
	if (savedData != null && savedData.length>1)
	{
		gstrSavedLocation=getCookie(garrLocationCookie[0]);
		if (gblnPost || confirm("We have found previously saved data for you.\n\nClick 'OK' to load the data or 'Cancel' to start fresh.\n "))
		{
			var arrData=savedData.split("|");
			for (var i=0; i<arrData.length; i++)
			{
				var arrRoomData=arrData[i].split(":")
				var roomName=arrRoomData[0];
				updateUserRoomList(roomName, true);
				var roomData=arrRoomData[1];
				var strItems=arrRoomData[1].split(",");
				for (var j=0; j<strItems.length; j++)
				{
					var arrRoomItems=strItems[j].split("=");
					var itemIndex=arrRoomItems[0];
					var strItemQuantity=arrRoomItems[1];
					garrRooms[roomName][itemIndex][2]=parseFloat(strItemQuantity);
				}
			}
			loadRoom(garrUserRooms[0]);
		}
	}
	loadSummary(true);
}

function toggleRoom(strRoomName)
{
	garrRooms[strRoomName][0][1]=garrRooms[strRoomName][0][1]=="none" || garrRooms[strRoomName][0][1].length==0 ? "block" : "none";
	enforceRoomDisplay();
	if (garrRooms[strRoomName][0][1]=="block")
	{
		loadRoom(strRoomName);
	}
}

function toggleAllRooms()
{
	gstrCollapseExpand = (gstrCollapseExpand == "none" || gstrCollapseExpand.length==0 ? "block" : "none");

	var intStateRoomsExpanded=stateRoomsExpanded();
	if (intStateRoomsExpanded==1 && gstrCollapseExpand=="block")
	{
		gstrCollapseExpand = "none";
	}
	else if (intStateRoomsExpanded==-1 && gstrCollapseExpand=="none")
	{
		gstrCollapseExpand = "block";
	}

	for (var i in garrRooms)
	{
		if (typeof(garrRooms[i]) != "function")
		{
			if (garrRooms[i][0][0]==true)
			{
				garrRooms[i][0][1]=gstrCollapseExpand;
			}
		}
	}
	enforceRoomDisplay();
}

function enforceRoomDisplay()
{
	for (var i in garrRooms)
	{
		if (typeof(garrRooms[i]) != "function")
		{
			var objDivRoom=document.getElementById("container_" + i);
			if (objDivRoom != null)
			{
				objDivRoom.style.display=garrRooms[i][0][1];
			}
		}
	}
}

function stateRoomsExpanded()
{
	var intNumRoomsItemSelected=0;
	var intNumRoomsExpanded=0;
	var intRet=0;

	for (var i in garrRooms)
	{
		if (typeof(garrRooms[i]) != "function")
		{
			if (garrRooms[i][0][0]==true)
			{
				intNumRoomsItemSelected++;
				if (garrRooms[i][0][1]=="block")
				{
					intNumRoomsExpanded++;
				}
			}
		}
	}
	if (intNumRoomsExpanded==intNumRoomsItemSelected)
	{
		intRet=1;
	}
	else if (intNumRoomsExpanded==0)
	{
		intRet=-1;
	}
	else
	{
		intRet=0;
	}
	return (intRet);
}
function sL(strLocationName, strUnitSize, strAreaM3, strAreaM2, strCostWeek, strCostMonth)
{
	this.locationName=strLocationName;
	this.locationUnitSize=strUnitSize;
	this.locationUnitAreaM3=strAreaM3;
	this.locationUnitAreaM2=strAreaM2;
	this.locationUnitCostWeek=strCostWeek;
	this.locationUnitCostMonth=strCostMonth;
}

function findSuitableContainers(blnIsPageLoad)
{
	var strLocation="-1";
	var strStorageQuoteHtml="";
	var objDivStorageQuote=document.getElementById("storageLocator");
	var objFormStorageQuote=document.getElementById("storageLocatorContactForm");
	var objFormSpaceCalculatorRequest=document.getElementById("spaceCalculatorRequestForm");
	var strtmpCookieVal="";
	var intSelectedIndex=-1;
	var strEmailContents="";

	if (blnIsPageLoad && gstrSavedLocation.length > 0)
	{
		strLocation=gstrSavedLocation;
		setLocationSelectorIndex(strLocation);
		intSelectedIndex=getSelectedLocationIndex();
	}
	else if (gobjHtmlLocationSelector != null)
	{
		intSelectedIndex=getSelectedLocationIndex();
		strLocation=gobjHtmlLocationSelector.options[intSelectedIndex].value;
	}

	garrLocationCookie[1]=strLocation;
	garrSuggestedSizes=[];
	strEmailContents = " Location: " + strLocation;

	if (strLocation != "-1")
	{
		for (var i=0; i<gaL.length; i++)
		{
			if (gaL[i].locationName==strLocation && gaL[i].locationUnitAreaM3 >= gintTotalSize)
			{
				garrSuggestedSizes[garrSuggestedSizes.length++]=gaL[i];
				if (garrSuggestedSizes.length >= gintNumSuggestedSizes)
				{
					break;
				}
			}
		}
	}
	else
	{
		garrSuggestedSizes=[];
	}

	if (garrSuggestedSizes.length==0)
	{
		var strMsg="";
		if (intSelectedIndex == 0)
		{
			strMsg="<div class='intro'>Please select a location.</div>";
		}
		else
		{
			strMsg="<div class='intro'>Sorry. No suitable storage units could be found.</div>";
		}
		if (objFormStorageQuote != null)
		{
			objFormStorageQuote.style.display="none";
		}
		if (objDivStorageQuote != null)
		{
			objDivStorageQuote.innerHTML = strMsg;
		}
	}
	else
	{
		strStorageQuoteHtml += "<div class='roomSummaryContainer'>";
		strStorageQuoteHtml += "<table class='hdrUnitSizes' border='0' cellspacing='0' cellpadding='0'>";
		strStorageQuoteHtml += "<tr class='r1'>";
		strStorageQuoteHtml += "<td class='c1' style='padding-left:10px;width:50%;'>Size (m)</td>";
		strStorageQuoteHtml += "<td nowrap class='c1' style='padding-left:10px;width:50%;'>Area (m3)</td>";
		strStorageQuoteHtml += "</tr>";
		for (var i=0; i<garrSuggestedSizes.length; i++)
		{
			strStorageQuoteHtml += ("<tr><td nowrap style='text-align:right; padding: 0 10px 0 10px;'>" + (garrSuggestedSizes[i].locationUnitSize) + "</td><td style='text-align:right; padding-right:10px;'>" + (garrSuggestedSizes[i].locationUnitAreaM3) + "</td></tr>");
			if (strtmpCookieVal.length>0)
			{
				strtmpCookieVal += ":";
			}
			strtmpCookieVal += garrSuggestedSizes[i].locationUnitSize + "," + garrSuggestedSizes[i].locationUnitAreaM3;
			strEmailContents += ", Unit:" + garrSuggestedSizes[i].locationUnitSize + "  " + garrSuggestedSizes[i].locationUnitAreaM3 + "";
		}
		strStorageQuoteHtml += "</table></div>";
		if (objDivStorageQuote != null)
		{
			objDivStorageQuote.innerHTML = "Suggested unit sizes available at our " + strLocation + " location.<br /><br />" + strStorageQuoteHtml;
			if (objFormStorageQuote != null)
			{
				objFormStorageQuote.style.display="block";
			}
		}
		if (objFormSpaceCalculatorRequest != null)
		{
			objFormSpaceCalculatorRequest.location.value = strLocation;
			if (defined(garrSuggestedSizes[0]))
			{
				objFormSpaceCalculatorRequest.suggestedUnit1.value=garrSuggestedSizes[0].locationUnitSize + " (" + garrSuggestedSizes[0].locationUnitAreaM3 + " m3)";
				objFormSpaceCalculatorRequest.priceWeek1.value=garrSuggestedSizes[0].locationUnitCostWeek;
				objFormSpaceCalculatorRequest.priceMonth1.value=garrSuggestedSizes[0].locationUnitCostMonth;
			}
			if (defined(garrSuggestedSizes[1]))
			{
				objFormSpaceCalculatorRequest.suggestedUnit2.value=garrSuggestedSizes[1].locationUnitSize + " (" + garrSuggestedSizes[1].locationUnitAreaM3 + " m3)";
				objFormSpaceCalculatorRequest.priceWeek2.value=garrSuggestedSizes[1].locationUnitCostWeek;
				objFormSpaceCalculatorRequest.priceMonth2.value=garrSuggestedSizes[1].locationUnitCostMonth;
			}
		}
	}
	garrUnitSizesCookie[1]=strtmpCookieVal;
	setLocationAndUnitSizesCookie();
}

function setDataCookie()
{
	setCookie(garrDataCookie[0], garrDataCookie[1], gobjDate, "/");
}

function setLocationAndUnitSizesCookie()
{
	setCookie(garrLocationCookie[0], garrLocationCookie[1], gobjDate, "/");
	setCookie(garrUnitSizesCookie[0], garrUnitSizesCookie[1], gobjDate, "/");
}

function getSelectedLocationIndex()
{
	return (gobjHtmlLocationSelector != null ?  gobjHtmlLocationSelector.options.selectedIndex : -1);
}

function setSelectedLocationIndex(intIndex)
{
	if (gobjHtmlLocationSelector != null)
	{
		gobjHtmlLocationSelector.options.selectedIndex=intIndex;
	}
}

function getObjHtmlLocationSelector()
{
	if (document.storageQuoteRequest && document.storageQuoteRequest.storageLocations)
	{
		return document.storageQuoteRequest.storageLocations;
	}
}

function setLocationSelectorIndex(strOptionValue)
{
	for (var i=0; i<gobjHtmlLocationSelector.options.length;i++)
	{
		if 	(gobjHtmlLocationSelector.options[i].value==strOptionValue)
		{
			setSelectedLocationIndex(i);
			break;
		}
	}
}

function valInputQuantity(strItemIdPrefix, strRoomName, intRoomItemNum)
{
	var strItemId=strItemIdPrefix + "_qty_" + strRoomName + "_" + intRoomItemNum;
	var objHtmlEl=document.getElementById(strItemId);
	if (objHtmlEl && objHtmlEl.value)
	{
		objHtmlEl.value=stripChars(false, objHtmlEl.value, '0123456789');
		if (objHtmlEl.value.length==0)
		{
			objHtmlEl.value=1;
		}
		if (parseFloat(objHtmlEl.value) < 0) objHtmlEl.value=0;
		if (parseFloat(objHtmlEl.value) > 99) objHtmlEl.value=99;

	}
}

function setCookie(cookiename, cookievalue)
{
    var argv = setCookie.arguments;
    var argc = setCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var DOMain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;

    document.cookie = cookiename + "=" + escape(cookievalue) +
      ((expires == null) ? "" 	      : ("; expires=" + expires.toGMTString())) +
      ((path    == null) ? ""	      : ("; path="    + path                 )) +
      ((DOMain  == null) ? "" 	      : ("; DOMain="  + DOMain               )) +
      ((secure  == true) ? "; secure" : "");

  return true;

}

function getCookie(name)
{
    var bikky = document.cookie;
    var index = bikky.indexOf(name + "=");
    if (index == -1) return null;
    index = bikky.indexOf("=", index) + 1;
    var endstr = bikky.indexOf(";", index);
    if (endstr == -1) endstr = bikky.length;
    return unescape(bikky.substring(index, endstr));
}

function stripChars(blnInBag, strTest, strValChars)
{
	var strRet = "";

	for (var i=0; i<strTest.length; i++)
	{
		var c = strTest.charAt(i);
		if (blnInBag)
		{
			if (strValChars.indexOf(c) == -1) strRet += c;
		}
		else
		{
			if (strValChars.indexOf(c) != -1) strRet += c;
		}
	}
	return (strRet);
}

function defined(varToTest)
{
	return (typeof(varToTest) != 'undefined');
}

function updateUserRoomList(strRooName, blnIsPageLoad)
{
	if (strRooName.toString().length > 0)
	{
		if (garrUserRooms.indexOf(strRooName) > -1)
		{
			garrUserRooms.splice(garrUserRooms.indexOf(strRooName),1);
		}
		if (blnIsPageLoad)
		{
			garrUserRooms.push(strRooName);
		}
		else
		{
			garrUserRooms.unshift(strRooName);
		}
	}
}

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}
