//------------------------------------------------------------------------------
// RealTracs Menu (v.2)
//------------------------------------------------------------------------------
var gtimeIntervalMenuList;		// time interval to wait before closing menu list.
var gtimeIntervalQuickLinks;	// time interval to wait before closing quick links menu list.
var gstrMenuListToHide = '';	// id of the menu list to hide.

var garrMainMenuNames = ['Home', 'RTM', 'Search', 'Reports', 'Tax', 'Financial', 'Member Info', 'MyPage', 'Help','Quick Links', 'Logout', '' ];
var garrMainMenuUrls = ['Home.aspx', 'Home.aspx', 'Search/QuickSearch.aspx', 'Reports/HotSheets.aspx?tab=0', '', 'Financial/Amort.aspx?tab=0', 'MemberInfo/Info.aspx?tab=0', 'MyPage/MyPage.aspx', 'Help/ContactUs.aspx', 'RTM/EditQuickLinks.aspx?tab=0', 'Default.aspx?Action=logout', '']

var garrMenuList0 = [''];   
var garrMenuList1 = ['RTM', 'Contacts', 'Calendar', 'Roster', 'Email'];
var garrMenuList2 = ['Quick Search', 'MLS # Search', 'Cross Class Search', 'Custom Search'];
var garrMenuList3 = ['Hot Sheets', 'Activity', 'Agent Reports', 'Custom Reports', 'Public Site'];
var garrMenuList4 = ['CRS Tax System'];
var garrMenuList5 = ['Amortization Schedule', 'Buyer\'s Closing Cost', 'Seller\'s Net Sheet', 'Rent vs. Buy Estimate'];
var garrMenuList6 = ['Info', 'Discussion', 'Training Classes', 'Partners'];
var garrMenuList7 = ['My Page', 'Add/Edit', 'Broker', 'Staff'];	// pre Merak beta
//var garrMenuList6 = ['My Page', 'Add/Edit', 'Broker', 'Staff', 'Email (beta)'];	// Merak beta
var garrMenuList8 = ['Contact Us', 'Online Help'];
var garrMenuList9 = [''];  

var garrMenuListUrls1 = ['Home.aspx', 'RTM/Contacts/Contacts.aspx', 'RTM/RTMCalendar.aspx', 'RTM/Roster/Roster.aspx', ''];
var garrMenuListUrls2 = ['Search/QuickSearch.aspx', 'Search/MLSSearch.aspx?tab=0&tabstrip=mlsnumbersearch', 'Search/CrossClassSearch.aspx?tab=0&tabstrip=crossclasssearch', 'Search/CustomSearches.aspx?tab=0'];
var garrMenuListUrls3 = ['Reports/HotSheets.aspx?tab=0', 'Reports/Activity.aspx', 'Reports/AgentInventory.aspx', 'Reports/CustomReports.aspx?tab=0','Reports/PublicSiteStats/PageViewByMlsNumber.aspx'];
var garrMenuListUrls4 = ['Tax/TaxLogon.aspx'];
var garrMenuListUrls5 = ['Financial/Amort.aspx?tab=0', 'Financial/BuyerSheet.aspx?tab=0', 'Financial/SellerSheet.aspx?tab=0', 'Financial/RentVsBuy.aspx?tab=0'];
var garrMenuListUrls6 = ['MemberInfo/Info.aspx?tab=0', 'MemberInfo/DiscussionEntries.aspx?tab=0', 'MemberInfo/Training.aspx?tab=0', 'MemberInfo/Partners.aspx?tab=0'];
var garrMenuListUrls7 = ['MyPage/MyPage.aspx', 'AddEdit/AddEdit.aspx', 'Broker/Broker.aspx', 'Staff/Staff.aspx'];		// pre Merak beta
//var garrMenuListUrls6 = ['MyPage/MyPage.aspx', 'AddEdit/AddEdit.aspx', 'Broker/Broker.aspx', 'Staff/Staff.aspx', 'Common/MerakWebmail.aspx'];	// Merak beta
var garrMenuListUrls8 = ['Help/ContactUs.aspx', ''];
var garrMenuListUrls9; 


//------------------------------------------------------------------------------
function initMain(tbl) {
	// Generates main menu bar and assignes listeners
	tbl.insertRow(0);
	for( var x = 0; x < tbl.tBodies[0].rows.length; x++ ) {
		for( var iCol = 0; iCol < garrMainMenuNames.length; iCol++ ) {
			var y = document.createElement('td');
			if(iCol != 11) //rounded image on the end.
			{
			    y.onmouseover = menuOver;
			    y.onmouseout = menuOut;
			    y.onclick = doMenuHeaderNav;
			}
			else
			{
			    y.className = 'roundedEnd';
			}
			y.appendChild(document.createTextNode(garrMainMenuNames[iCol]));
			
			if(isMac()) {
				y.style.height = '23px';
			}
			
			tbl.tBodies[0].rows[x].appendChild(y);
		}
	}
}
//------------------------------------------------------------------------------
function initMenuList(tbl) {

    
	// Generates single menu list and assignes listeners
	var iTblIdx = tbl.id.slice(3);
	var arr = eval('garrMenuList' + iTblIdx);
	tbl.onmouseover = menuListOver;
	tbl.onmouseout = menuListOut;
	
	//for sub menus that are empty, get out.
    if(arr){
        if(arr.length == 1){
            if(arr[0] == ''){
                return;    
            }
        }
    }
    
	for (var i = 0; i < arr.length; i++) {
		    tbl.insertRow(0);
	}
	for( var x = 0; x < tbl.tBodies[0].rows.length; x++ ) {
		var y = document.createElement('td');
		y.appendChild(document.createTextNode(arr[x]));
		y.onmouseover = menuListItemOver;
		y.onmouseout = menuListItemOut;
		y.onclick = doMenuNav;
		y.id = tbl.id + 'menuitem' + x;
		tbl.tBodies[0].rows[x].appendChild(y);
	}
}
//------------------------------------------------------------------------------
function initQuickLinksMenuList() {
	var tbl = document.getElementById('tblMenuQuickLinks');
	tbl.onmouseover = displayQuickLinks;
	tbl.onmouseout = waitThenHideQuickLinks;
	for( var x = 0; x < tbl.tBodies[0].rows.length; x++ ) {
		//alert(x);
		tbl.tBodies[0].rows[x].cells[0].onmouseover = menuListItemOver;
		tbl.tBodies[0].rows[x].cells[0].onmouseout = menuListItemOut;
	}
}
//------------------------------------------------------------------------------
// EVENT DRIVEN MENU FUNCTIONS
//------------------------------------------------------------------------------
function menuOver() { 
	hideAllMenuLists();
	flattenAllHeaders();
	this.className = 'clsMenuHeaderHover';
	try {
		var m = document.getElementById('tbl' + this.cellIndex); 
		m.style.display = 'block';
	} catch (e) {}
}
//------------------------------------------------------------------------------
function menuOut() { 
	try {
		//alert(this.cellIndex);
		var m = document.getElementById('tbl' + this.cellIndex);
		if (this.cellIndex == 9 || this.cellIndex == 10 || this.cellIndex == 0) {
			flattenAllHeaders(); // 10 = logout, has no menu list so flattenAllHeaders.
		} else {
			waitThenHideMenuList(m, 500);
		}
	} catch (e) { }
}
//------------------------------------------------------------------------------
function menuListOver() {
	window.clearInterval(gtimeIntervalMenuList)
}
//------------------------------------------------------------------------------
function menuListOut() {
	waitThenHideMenuList(this, 200);
}
//------------------------------------------------------------------------------
function menuListItemOver() {
	this.className = 'clsMenuListItemHover';
}
//------------------------------------------------------------------------------
function menuListItemOut() {
	this.className = 'clsMenuListItemNormal';
}
//------------------------------------------------------------------------------
function doMenuHeaderNav() {
	flattenAllHeaders();
	hideAllMenuLists();
	if(this.cellIndex != 4){
		window.top.location = endWithSlash(gsAppPath) + garrMainMenuUrls[this.cellIndex];
	}
	else{
		window.open(endWithSlash(gsAppPath) + 'Tax/TaxLogon.aspx', null, '');
	}
}
//------------------------------------------------------------------------------
function doMenuNav() {
	flattenAllHeaders();
	hideAllMenuLists();
	var ele = this;
	var iTbl = -1;
	var iRow = this.parentNode.rowIndex;
	for (var iup = 0; iup < 5; iup++) {
		if(ele.tagName == 'TABLE') {
			iTbl = ele.id.slice(3);
			iup = 99;  // to exit loop
		} else {
			ele = ele.parentNode;
		}
}
	if (iTbl == 1 && iRow == 4) {
	    // window.open(endWithSlash(gsAppPath) + 'MyPage/EmailLogon.aspx', null, ''); // pre-Merak
	    window.open(endWithSlash(gsAppPath) + 'MyPage/EmailTransition.aspx', null, ''); // Merak transition
	} else if (iTbl == 4 && iRow == 0) {
	    window.open(endWithSlash(gsAppPath) + 'Tax/TaxLogon.aspx', null, '');
	} else if (iTbl == 8 && iRow == 1) {
	    window.open(endWithSlash(gsAppPath) + 'Help/OnlineHelpIndex.aspx', null, 'top=50,left=50,resizable,height=540,width=780');
	}

	else if (iTbl == 9) {
	blnIgnore = false;
	for (var ictr = 0; ictr < 9; ictr++) {
	    var ele;
	    var table;
	    table = document.getElementById('tbl' + iTbl);
	    try {		        
	       ele = table.rows[iRow].cells[ictr].innerHTML;
    	}
	    catch (e) { }

	    if (iTbl == 9 && iRow == ictr && ele == 'Email') {
	            blnIgnore = true;
	            window.open(endWithSlash(gsAppPath) + 'MyPage/EmailTransition.aspx', null, ''); // Merak transition
	        }
	    }
	    if (blnIgnore == false) {
	        window.top.location = endWithSlash(gsAppPath) + eval('garrMenuListUrls' + iTbl + '[iRow]');
	    }	    
	}
	else {
	    window.top.location = endWithSlash(gsAppPath) + eval('garrMenuListUrls' + iTbl + '[iRow]');
	}
}

//------------------------------------------------------------------------------
// SUPPORTING MENU FUNCTIONS
//------------------------------------------------------------------------------
function getValFromCookie(name) {
	var s = document.cookie;
	var i = s.indexOf(name + '=');
	s = s.slice(i);
	i = s.indexOf('&');
	s = s.slice(name.length + 1,i);
	return s;
}

function waitThenHideMenuList(oMenuListTbl, iInterval) {
	if (iInterval == null) { iInterval = 100; }
	gstrMenuListToHide = oMenuListTbl.id;
	gtimeIntervalMenuList = window.setInterval('hideMenuList(gstrMenuListToHide)', iInterval);
}
//------------------------------------------------------------------------------
function hideMenuList(sMenuListID) {
	flattenAllHeaders();
	window.clearInterval(gtimeIntervalMenuList);
	try {
		document.getElementById(sMenuListID).style.display = 'none';
	} catch(e) {}
}
//------------------------------------------------------------------------------
function hideAllMenuLists() {
	try {
		for( var i = 0; i <  garrMainMenuNames.length; i++) {
			document.getElementById('tbl' + i).style.display = 'none';
			window.clearInterval(gtimeIntervalMenuList);
		}
	} catch(e) { }
}
//------------------------------------------------------------------------------
function flattenAllHeaders() {
	for( var i = 0; i < garrMainMenuNames.length; i++) {
        if(i != 11)
	    {
		    document.getElementById('tblMainMenu').rows[0].cells[i].className = '';
		}

	}	
}
//------------------------------------------------------------------------------
function generateMenu() {
    garrMainMenuUrls = eval([hdnQLDefaultHPUrl.value, 'Home.aspx', 'Search/QuickSearch.aspx', 'Reports/HotSheets.aspx?tab=0', '', 'Financial/Amort.aspx?tab=0', 'MemberInfo/Info.aspx?tab=0', 'MyPage/MyPage.aspx', 'Help/ContactUs.aspx', 'RTM/EditQuickLinks.aspx?tab=0', 'Default.aspx?Action=logout', '']);
    garrMenuList9 = eval(hdnQLText.value);
    garrMenuListUrls9 = eval(hdnQLUrl.value);
    initMain(document.getElementById('tblMainMenu'));

	initMenuList(document.getElementById('tbl0'));
	initMenuList(document.getElementById('tbl1'));
	initMenuList(document.getElementById('tbl2'));
	initMenuList(document.getElementById('tbl3'));
	initMenuList(document.getElementById('tbl4'));
	initMenuList(document.getElementById('tbl5'));
	initMenuList(document.getElementById('tbl6'));
	initMenuList(document.getElementById('tbl7'));
	initMenuList(document.getElementById('tbl8'));
	initMenuList(document.getElementById('tbl9'));	
	initQuickLinksMenuList();
}

//------------------------------------------------------------------------------
function displayQuickLinks() {
	window.clearInterval(gtimeIntervalQuickLinks);
	document.getElementById('tblMenuQuickLinks').style.display = 'block';
}
//------------------------------------------------------------------------------
function waitThenHideQuickLinks() {
	gtimeIntervalQuickLinks = window.setInterval('hideQuickLinksMenu()', 500);
}
//------------------------------------------------------------------------------
function hideQuickLinksMenu() {
	document.getElementById('tblMenuQuickLinks').style.display = 'none';
}
//------------------------------------------------------------------------------
function hideMenuItem(menuitemid) {
	document.getElementById(menuitemid).style.display = 'none';
}
//------------------------------------------------------------------------------
// INLINE MENU CODE
//------------------------------------------------------------------------------
//try { generateMenu(); } catch(e) {}


//------------------------------------------------------------------------------
//                              GLOBALLY USED FUNCTIONS
//------------------------------------------------------------------------------
// Returns the content for the clock displayed in the menu control.
function clockTick() {
	try { document.getElementById('spnClock').innerHTML = getClockInfo();
	} catch(e) {}
}
window.setInterval("clockTick()", 1000);
clockTick();
//------------------------------------------------------------------------------
function getClockInfo() {
	var now = new Date();
	var arrMonth = ['0', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
	if (document.body.offsetWidth > 900) {
		var t = arrMonth[now.getMonth() + 1] + ' ';
		t += padZero(now.getDate()) + ', ' + padZero(now.getFullYear()) + '  ';
		t += (now.getHours() > 12 ? now.getHours() - 12 : now.getHours()) + ':';
		t += padZero(now.getMinutes()) + ' '+ (now.getHours() > 11 ? 'PM' : 'AM');
	    // show window width.
	    //t += ' <span id="spnOffsetWidth" style="color:red; display:none;">w=' + document.body.offsetWidth + '</span>';  
		return t;
	}  else  { 
		return ''; 
	}
}
//------------------------------------------------------------------------------
function dontAllowCtrlN(e) { 
    if (e.ctrlKey && e.keyCode==78){ 
        alert('CTRL+N for new window disabled.  \nLaunch another instance of your browser for a separate session.');
        e.cancelBubble = true;
        //event.keyCode = 0;
        return false;
    } 
} 
//------------------------------------------------------------------------------
function isIE() {
	if(navigator.appName.toLowerCase() == 'microsoft internet explorer' && document.all) {
		return true;
	} else {
		return false;
	}
}
//------------------------------------------------------------------------------
function isMac() {
	var brs = navigator.userAgent.toLowerCase();
	if(brs.search(/macintosh/) != -1 || brs.search(/mac\x5fpowerpc/) != -1 || brs.search(/mac\sos\sx/) != -1) {
		return true;
	} else {
		return false;
	}
}
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//					showModalDialog branching
// Rather than use showModalDialog() which is IE only, use showModal() and pass in
// the same params as the showModalDialog().  If the browser is IE, it uses modal,
// otherwise it simulates a modal with window.open and js to retain focus.
//------------------------------------------------------------------------------
function showModal(sUrl, sName, sAttributes) {
	if (isIE()) {
		return window.showModalDialog(sUrl, sName, sAttributes);
//		var retVal = window.showModalDialog(sUrl, sName, sAttributes);
//		if(retVal != null) { return retVal; }
	} else {
		//var retVal = dialog(sUrl, sName, sAttributes, true);
		return dialog2(sUrl, sName, sAttributes, true);
		//return false;
		//if(retVal != null) { return retVal; }
	}
}
//------------------------------------------------------------------------------
function dialog2(url, name, feature, isModal) {
	// Mimics a modal with window.open by adding ModalFocus event listener to the parent to return focus to the "modal".
	if(url == null)		{ return false; }
	if(name == null)	{ name="" }
	if(feature == null) { feature="" };

	// convert showModalDialog feature syntax to window.open feature syntax
	feature = feature.replace(/;/g, ',');	
	feature = feature.replace(/px/g, '');
	feature = feature.replace(/:/g, '=');
	feature = feature.replace(/dialogHeight/g, 'height');
	feature = feature.replace(/dialogWidth/g, 'width');

	if(document.getBoxObjectFor) 
	{
		if(isModal) 
		{		 
			var Modal = window.open(url,name,"modal=yes," + feature);
			var ModalFocus = function() 
			{
				if(!Modal.closed)	//if(Modal != null)
				{		
					Modal.focus();
				} 
				else 
				{
					Modal=null;
					window.removeEventListener('focus', ModalFocus, false);
					ModalFocus = null;
				}
			};
			window.addEventListener('focus', ModalFocus, false ); 
			return false;
		} 
		else 
		{
			return window.open(url,name,"modal=1," + feature);
		}	 
	} 
	else 
	{
		return window.open(url,name,feature);
	}
	//return null;
}
//------------------------------------------------------------------------------
/*
String.prototype.isArgument=function() {
	return /^([a-zA-Z]){1,}=([0-9]){1,}$/.test(this);
}
function dialog(url,name,feature,isModal)
{
 if(url==null){return false;}
 url = url
 if(name==null){name=""}
 if(feature==null){feature=""};
 if(window.showModelessDialog)
 {
  	var WindowFeature = new Object();
	WindowFeature["width"] = 400;
	WindowFeature["height"]  =400;
	WindowFeature["left"]  = "";
	WindowFeature["top"]  =  "";
	WindowFeature["resizable"]  = "";

	if(feature !=null && feature!="")
	{
      feature = ( feature.toLowerCase()).split(",");
	
      for(var i=0;i< feature.length;i++)
		{
          if( feature[i].isArgument())
			{
               var featureName = feature[i].split("=")[0];
			   var featureValue = feature[i].split("=")[1];
			  
			   if(WindowFeature[featureName]!=null){WindowFeature[featureName] = featureValue; }
			}
		}
	}
 
  if(WindowFeature["resizable"]==1 || WindowFeature["resizable"]=="1" || WindowFeature["resizable"].toString().toLowerCase()=="yes"){WindowFeature["resizable"] = "resizable:1;minimize:1;maximize:1;"}
  if(WindowFeature["left"]!=""){WindowFeature["left"] ="dialogLeft:" +  WindowFeature["left"] +"px;";}
  if(WindowFeature["top"]!=""){WindowFeature["top"] ="dialogTop:" +  WindowFeature["Top"] +"px;"; }
  if(window.ModelessDialog ==null){window.ModelessDialog = new Object() ; };
  if(name!="")
  {
   if(window.ModelessDialog[name]!=null && !window.ModelessDialog[name].closed )
   {
     window.ModelessDialog[name].focus();
	 return window.ModelessDialog[name];
   }
  }
	var F = WindowFeature["left"] +WindowFeature["top"] +  "dialogWidth:"+WindowFeature["width"] +" px;dialogHeight:"+WindowFeature["height"]+"px;center:1;help:0;" + WindowFeature["resizable"] +"status:0;unadorned:0;edge: raised; ;border:thick;"
	if(isModal)
	{
		window.showModalDialog(url,self,F);
		return false;
	}
	else
	{
		window.ModelessDialog[name] = window.showModelessDialog(url,self,F);
		return window.ModelessDialog[name];
	}	
 }
 else
 {
   if(document.getBoxObjectFor)
   {
	 if(isModal)
	 {		 
		 var Modal = window.open(url,name,"modal=1," + feature);
		 var ModalFocus = function()
		 {
			if(!Modal.closed){Modal.focus();}
			else{Modal =null;window.removeEventListener(ModalFocus,"focus");ModalFocus = null; };					
		 }
		 window.addEventListener( "focus",ModalFocus, false ); 
		 return false;
	 }
	 else
	 {
		return window.open(url,name,"modal=1," + feature);
	 }	 
   }
   else
   { 
     return window.open(url,name,feature);
   }
   //
 }
 return null;
}
*/
//------------------------------------------------------------------------------



//------------------------------------------------------------------------------
// Popup/new window functions:
//------------------------------------------------------------------------------
// Opens a modal dialog with a calendar control, and returns the selected date into the value of CtrlName.
function getCommonDate(sCtrlName)  {  
	if(isIE()) {
		returnValue = window.showModalDialog(endWithSlash(gsAppPath) + 'Common/PopupCalendar.aspx?FormName=' + document.forms[0].name + '&CtrlName=' + sCtrlName, "PopUpCalendar", 'dialogWidth=245px;dialogHeight=320px;resizable=0;status=0;help=0');
		if (returnValue != null) {
			eval('document.all.' + sCtrlName + '.value = returnValue');
			try { eval('document.all.' + sCtrlName + '.focus()'); } catch(e){ }
		}
	} else {
		//alert('This feature only supported in Internet Explorer');
		window.showModal(endWithSlash(gsAppPath) + 'Common/PopupCalendar.aspx?FormName=' + document.forms[0].name + '&CtrlName=' + sCtrlName, "PopUpCalendar", 'dialogWidth=245px;dialogHeight=320px;resizable=0;status=0;help=0');
		return;
	}
}
//------------------------------------------------------------------------------
function showHelp(iHelpID, sBookmarkName) { 
	var sUrl = endWithSlash(gsAppPath) + 'Help/OnlineHelp.aspx?helpid=' + iHelpID;
	if (sBookmarkName != null) { sUrl += '&bookmark=' + sBookmarkName; }
	window.open(sUrl ,iHelpID,'width=600px,height=400px,resizable=no,scrollbars=yes,help=no'); 
}	
//------------------------------------------------------------------------------
function openExternalURL(url) {
    var w = screen.width - 100;
    var h = screen.height - 250;
    window.open(url,'ExternalURL','top=50,left=50,resizable,scrollbars,menubar,toolbar,height=' + h + ',width=' + w + ',status,location=yes');
}
//------------------------------------------------------------------------------
function showAgentInfo(iAgentID) {
	window.showModal(endWithSlash(gsAppPath) + 'Common/AgentInformation.aspx?UserID=' + iAgentID, ''
							, 'dialogHeight:460px;dialogWidth:400px;status=0;center:yes');
}
//------------------------------------------------------------------------------
function showOfficeInfo(iOfficeID) {
	window.showModal(endWithSlash(gsAppPath) + 'Common/OfficeInformation.aspx?OfficeID=' + iOfficeID, ''
							, 'dialogHeight:270px;dialogWidth:400px;status=0;center:yes');	
}
//------------------------------------------------------------------------------
function showSchoolInfo(iSchoolID) {
	window.showModal(endWithSlash(gsAppPath) + 'Common/SchoolInformation.aspx?SchoolId=' + iSchoolID, ''
							, 'dialogHeight:270px;dialogWidth:400px;status=0;center:yes');	
}
//------------------------------------------------------------------------------
function showOpenHouseInfo(iListingID, iPropertyClassID) {
	window.showModal(endWithSlash(gsAppPath) + 'Common/OpenHouseInfo.aspx?ListingId=' + iListingID + '&PropertyClassID=' + iPropertyClassID, ''
							, 'dialogHeight:450px;dialogWidth:650px;status=0;center:yes');
}

function ShowOpenHouseInformation(ListingId, intPropertyClassID, sOHIndicator) {
    window.showModalDialog(endWithSlash(gsAppPath) + 'Common/OpenHouseInfo.aspx?ListingId=' + ListingId + '&PropertyClassID=' + intPropertyClassID + '&OHIndicator=' + sOHIndicator, '', 'dialogHeight:450px;dialogWidth:650px;center:yes');
}

//------------------------------------------------------------------------------
function openMediaPage(iListingID) { showMediaPage(iListingID);	}
//------------------------------------------------------------------------------
function showMediaPage(iListingID) {
	window.open(endWithSlash(gsAppPath) + 'Search/MediaDisplay.aspx?ListingID=' + iListingID);
}
//------------------------------------------------------------------------------
function showMediaPage2(url) {
	window.open(url, 'NewHousePicsWindow', 'width=830,height=750,resizable,top=50,left=50,status=no,scrollbars=yes');
}
//------------------------------------------------------------------------------
function showMapSingle(iListingID, iPropertyClassID, bHideDraw) {

	var sPrp = 'res';
	switch (iPropertyClassID) {
		case 1: sPrp = 'res'; break;
		case 2: sPrp = 'cnd'; break;
		case 3: sPrp = 'llf'; break;
		case 4: sPrp = 'mul'; break;
		case 5: sPrp = 'com'; break;
		case 6: sPrp = 'rnt'; break;
		case 8: sPrp = 'auc'; break;
	}
	showMapSingle2(iListingID, sPrp, bHideDraw);
}
//------------------------------------------------------------------------------
function showMapSingle2(iListingID, sPrpAbbrev, bHideDraw) {

    var w = window.screen.width - 200;
    var h = window.screen.height - 200;
	var sHide = '&hidedraw=false';

	if(bHideDraw != null) {
		if(bHideDraw == '1' || bHideDraw == 'true' || bHideDraw == 'True') {
			sHide = '&hidedraw=true';
		}
	}

	//use for .NET mapping
	var url = trimEnd(gsAppPath) + gsMappingPath + 'Mapping.aspx?init=true' + sHide + '&prp=' + sPrpAbbrev + '&ListingID=' + iListingID + '&width=' + w + '&height=' + h;
	var features = 'toolbar=0,status=0,location=0,directories=0,menubar=0,resizable=yes,top=0,left=0,width=' + w + ',height=' + h;
	window.open(url, '_blank', features);
}
//------------------------------------------------------------------------------
function showEmailListings(iPropertyClassID) {
	return showModal(endWithSlash(gsAppPath) + 'Search/EmailListingsPopup.aspx?PropertyClassID=' + iPropertyClassID
		,null,'dialogWidth:900px;dialogHeight:700px;center:yes;resizable=1;status=0;');
}
//------------------------------------------------------------------------------
function showActionItem(iActionItemID) { 
	var retVal = window.showModal(endWithSlash(gsAppPath) + 'Common/ActionItemPopup.aspx?ActionItemID=' + iActionItemID
		,null,'dialogWidth:700px;dialogHeight:600px;center:yes;resizable:1;status:0;scrollbars:1;');
	if (retVal == '1') {
		window.location = window.location;	// refresh
	}
}
//------------------------------------------------------------------------------
function selectAgent(previousControl, sctrlAgentID, sctrlAgentName, blnEnableClearAgent) {

	// sctrlAgentID = client ID of the UserID/AgentID field
	// sctrlAgentName = client ID of the agent display name.
	// blnEnableClearAgent = whether or not to show the "Clear Agent" button.
	// used by AddEdit\ChangeStatus.ascx, EditListing.ascx, NewListing.ascx, ViewMenu.ascx, AppControls\SelectListingAgent.ascx
	// With these changes, AddEditMemberSearch.aspx appears to be no longer being used.
	// Also remmed out Utility.vb -> BuildSelectListingAgentClientScript and BuildRosterSearchPopupClientScript
	
	if(blnEnableClearAgent == null || blnEnableClearAgent == '') { blnEnableClearAgent = false; }
	var oAgentID = document.getElementById(sctrlAgentID);
	var oAgentName = document.getElementById(sctrlAgentName);
	var sUrl = gsAppPath + 'Common/RosterSearch.aspx?PreviousControl=' + previousControl + '&ClearAgentEnabled=' + blnEnableClearAgent + '&ctrlUserID=' + sctrlAgentID + '&ctrlFullName=' + sctrlAgentName;
	var retVal = window.showModal(sUrl, 'selectAgent', 'dialogHeight:350px;dialogWidth:550px;center:yes;scrollbars=auto;');
	if(isIE()) {
		if(retVal != null) {
			if(retVal.split('~')[1] == '-1') {
				oAgentID.value = '';
				oAgentName.value = '';
			} else {
				oAgentID.value = retVal.split('~')[0];
				oAgentName.value = retVal.split('~')[1];
			}
		}
	}
}
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
// used by reports pages (that don't have the menu);
//------------------------------------------------------------------------------
function openNewWindow(url, name, width, height) {
	window.open(url, name, 'width=' + width + ',height=' + height + ', scrollBars');
} 
//------------------------------------------------------------------------------
function showMapSingle3(url) {
    var w = window.screen.width - 200;
    var h = window.screen.height - 200;
	var features = 'toolbar=0,status=0,location=0,directories=0,menubar=0,resizable=yes,top=0,left=0,width=' + w + ',height=' + h;
	url += '&width=' + w + '&height=' + h;
	window.open(url, '_blank', features);
}
//------------------------------------------------------------------------------
// Depricated functions used by reports pages repointing to new functions
// ReportShell.aspx, ListingDetailReportMain.aspx, EmailPublicReports.aspx
//------------------------------------------------------------------------------
function ShowAgentInformation(iAgentID)	  {	showAgentInfo(iAgentID);	}
function ShowOfficeInformation(iOfficeID) {	showOfficeInfo(iOfficeID);	}
function ShowSchoolInformation(iSchoolID) {	showSchoolInfo(iSchoolID);	}
//function ShowOpenHouseInformation(iListingID, iPropertyClassID) {showOpenHouseInfo(iListingID, iPropertyClassID); }
function openNewWindowHousePics(url) {		showMediaPage2(url);		}
function openNewWindowMapping(url)   {		showMapSingle3(url);		}
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
// Home Page image button functions (Day/Week/Month/Edit buttons)
//------------------------------------------------------------------------------
function doImageButtonMouseover() {
	if(isImageButton(this)) { this.src = this.src.replace(/up|down/, 'over'); }
}
//------------------------------------------------------------------------------
function doImageButtonMouseout() {
	if(isImageButton(this)) { this.src = this.src.replace(/over|down/, 'up'); }
}
//------------------------------------------------------------------------------
function doImageButtonMouseDown() {
	if(isImageButton(this)) { this.src = this.src.replace(/up|over/, 'down'); }
}
//------------------------------------------------------------------------------
function doImagebuttonMouseUp() {
	if(isImageButton(this)) { this.src = this.src.replace('down', 'over'); }
}
//------------------------------------------------------------------------------
function isImageButton(ele) {
	return (ele.tagName == 'IMG') ? true : false;
}
//------------------------------------------------------------------------------

// *****************************************************************************
//------------------------------------------------------------------------------
// Generic Functions
//------------------------------------------------------------------------------
function endWithSlash(s) {
	if(s.charAt(s.length-1) == "/") {
		return s;
	} else {
		return s + '/';
	}
}
//------------------------------------------------------------------------------
function trimEnd(s, sChar) {
	if(sChar == null) { sChar = "/"; }	// default to slash (/)
	if(s.charAt(s.length-1) == sChar) {
		return s.substring(0, s.length - 1);
	} else {
		return s;
	}
}
//------------------------------------------------------------------------------
function stripHTML(s) {
	var re = /<(.|\n)+?>/gi;
	return s.replace(re, '');
}
//------------------------------------------------------------------------------
function padZero(i) {
	return i < 9 ? '0' + i : i;
}
//------------------------------------------------------------------------------
function roundToPennies(n) {  // 5.786 returns 5.79
	var v = n * 100;
	v = Math.round(v) / 100;
	var strv = v.toString();
	var iDot = parseInt(strv.indexOf('.'));
	if ((iDot > -1) && (strv.length - iDot == 2)) { strv = strv + '0'; }  //  if there is only 1 digit to the right of the decimal, append a zero.
	if ((iDot > -1) && (strv.length - iDot < 2)) { strv = strv.slice(0, iDot + 2); } // chop off any digits beyond the 1/100 place.
	return strv;
}
//------------------------------------------------------------------------------
function cleanNonNumeric(ctrl, retValIfEmpty) {
	ctrl.value = stripNonNumeric(ctrl.value, retValIfEmpty);
}
//------------------------------------------------------------------------------
function stripNonNumeric(s, retValIfEmpty) {
	if (s == '' && retValIfEmpty != null) { s = retValIfEmpty; }
	var re = /[^0-9.]/g;
	s = s.replace(re, '');
	if (s == '') {s = '0';}
	return s;
}
//------------------------------------------------------------------------------
function isLeapYear(year) {
	if (year == null) {
		var dat = new Date;
		year = dat.getFullYear();
	}
	return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0;
}
//------------------------------------------------------------------------------
function formatCommas(amount, blnShowDollar) {	// 17524 -> $17,524

	var delimiter = ",";		// replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3) {
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d != null) {
		if(d.length > 0) { amount = n + '.' + d;
		} else {
			amount = n;
		}
	} else {
		amount = n;
	}
	amount = minus + amount;
	if(blnShowDollar == 1) { amount = '$' + amount; }
	return amount;
}
//------------------------------------------------------------------------------
function setCommasForTableColumn(oTbl, iColIdx, iStartRowIdx, blnShowDollar) {
	// oTbl = reference to table.  
	// iColIdx = zero based index of column to process.
	// iStartRowIdx = zero based index of first row to process.
	// blnShowDollar = [0|1] whether or not to show dollar sign ($).
	try {
		if(iStartRowIdx  == null) { iStartRowIdx  = 1 }
		if(blnShowDollar == null) { blnShowDollar = false; }
		var cell;
		for(var i = iStartRowIdx; i < oTbl.rows.length; i++)
		{
			cell = oTbl.rows[i].cells[iColIdx];
			cell.innerHTML = formatCommas(cell.innerHTML, blnShowDollar);
		}
	}
	catch(e) {}
}
//---- End Generic Functions --------------------------------------------------

//------------------------------------------------------------------------------
// Inline code...
//------------------------------------------------------------------------------
// Cancel CTRL + N
document.onkeydown = function(e) { 
    var blnCtrlKey;
    var iKeyCode;
    if(isIE()) {
		blnCtrlKey = window.event.ctrlKey;
		iKeyCode = window.event.keyCode;
    } else {
		blnCtrlKey = e.ctrlKey;
		iKeyCode = e.keyCode;
    }
    if (blnCtrlKey == true && iKeyCode == 78) { 
        return false; 
    } 

}

function saveAs() {
    if (isIE()) {
        document.execCommand('SaveAs', true, 'Report.htm');
    }
    else {
        var strLocation = window.location.toString();
        strLocation = strLocation.replace('CMAReport_Main.aspx', 'CMAReport_View.aspx');

        var queryStringChar = '&';
        if (strLocation.indexOf('?') == -1) {
            queryStringChar = '?';
        }
        window.location.replace(strLocation + queryStringChar + 'action=SaveAs'); 
    }
}

//function showReportFirefoxBug() {
//	// Show "Report FireFox Bug box"
//	if(!isIE()) {
//		try {
//			if(window.location.toString().indexOf('ListingDetailReportHeader.aspx') == -1) 
//			{
//				var spn = document.createElement('span');
//				var hideFFBox = function() { this.parentNode.style.display = 'none'; document.getElementById('spnReportFFBug').removeEventListener('click', showFeedbackPage, false);}
//				var showFeedbackPage = function() { window.open(gsAppPath + 'Common/ReportBugPopup.aspx?to=firefox@realtracs.com','','width=770,height=550px,scrollbars=1,modal=yes'); }
//				spn.id = 'spnReportFFBug';
//				spn.innerHTML = '<img src="' + gsAppPath + 'AppImages/ff_logo_30x30.png" style="float:right;"/>' 
//					+ 'Report<br/>Firefox<br/>bug. <span id="spnHideFFBox" class="clsFakeHref" style="float:left;right:2px;bottom:2px;position:absolute;">Close</span>';
//				document.getElementsByTagName('body')[0].appendChild(spn);
//				document.getElementById('spnHideFFBox').addEventListener('click', hideFFBox, false)
//				spn.addEventListener('click', showFeedbackPage, false)
//			}
//		} catch(e) {}
//	}
//}
//showReportFirefoxBug();