	var gDMCLink	= new launchDMCApp();
	var gAddr		= "";
	var gCity		= "";
	var gZip		= "";
	var gState		= "";
	var gCallType	= "";
	var gLastQuery	= "";

	var m_iRowsPerPage = 1;
	var m_iFirstRow = -1;
	var m_iTotalRow = -1;
	
	var m_sGUID = "";
	
	var f = new Array();

	function openModalReport(sURL, vModalArgs, sModalFeat)
	{
		var sRetVal = window.showModalDialog(sURL,vModalArgs,sModalFeat);
		if (sRetVal != -1 && String(sRetVal) != 'undefined' && sRetVal != '')
		{
			window.open('../Email/Compose.aspx?modal=true&to=' + sRetVal,"mail","width:700;height:520;");
		}			
	}

	function doDigiMap(sNumber,sAddrDirection,sStreet,sAddr2,sCity,sState,sZip,sZip6)
	{
		gAddr		= "";
		gCity		= "";
		gZip		= "";
		gState		= "";
		if (!sNumber.length == 0)
		{
			gAddr += sNumber;
		}
		if (!sAddrDirection.length == 0)
		{
			gAddr += " " + sAddrDirection;
		}
		if (!sStreet.length == 0)
		{
			gAddr += " " + sStreet;
		}
		if (!sAddr2.length == 0)
		{
			gAddr += " " + sAddr2;
		}
		gCity = sCity;
		gZip  = sZip;
		if (!sZip6.length == 0)
		{
			gZip += " " + sZip6;
		}
		gState = sState;
					
		findLocation();

	}
	function findLocation() 
	{
 		gCallType = "ADDRESS";
 		gDMCLink.activate("ADDRESS");
	}
	function launchDMCApp()
	{
		this.window=null;
		this.activate = function (whichCallBack)
		{

			// if window already exists - use it
			if (this.window && !this.window.closed)
			{
				if(whichCallBack =="APN")
				{
					callBackZoomtoParcel();
				} 
				else if (whichCallBack =="ADDRESS")
				{
					callBackZoomtoAddress();
				} 
				else 
				{
					callBackZoomtoParcel();
				}
      		} 
			// need to create window
			else
			{
				this.window = window.open("../OtherSearches/DigiMap.asp","DigitalMapping");
			}
		}
		                
	}
	// required function called from package in DMC app after startup of the application
	function callBackZoomtoParcel()
	{
		// get the package - any custom code resides in packages
		var MyPkg = gDMCLink.window.environment.packages.getValue("ExternalAppIntegration");
		// call appropriate package function - add any additional required functions to package
		// zoomtoParcel finds parcels meeting the input attribute criteria and fits them to the map display
		MyPkg.zoomtoParcel(gLastQuery);
		gDMCLink.window.focus();
		// you can alternately call DMC API functions directly
	}

	function callBack()
	{
		//alert("callBack");
		if (gCallType == "APN") 
		{
	  		callBackZoomtoParcel();
		} 
		else if (gCallType == "ADDRESS") 
		{
			callBackZoomtoAddress();
		}
	}

	function callBackZoomtoAddress()
	{
		// get the package - any custom code resides in packages
		var MyPkg = gDMCLink.window.environment.packages.getValue("ExternalAppIntegration");
		// call appropriate package function - add any additional required functions to package
		MyPkg.zoomtoAddress(gAddr,gCity, gZip, gState);
		gDMCLink.window.focus();
		// you can alternately call DMC API functions directly
	}

	// this is the function to call from your app
	function zoomToParcel(sSQL)
	{
		// where clause for after window is invoked
		gLastQuery = sSQL;      
		gCallType = "APN";
		// activate the window if it is not already activated
		gDMCLink.activate("APN"); 
	}

	function initChecks()
	{
		var fraMain = getSpreadsheetFrame();
		var iCurRow = fraMain.GetFocusRow();
		var chkElem = document.getElementById( "chk" + iCurRow );
		if ( chkElem == null )
		{
			chkElem = document.getElementById( "chk1" );
			if ( chkElem != null )
			{
				if ( fraMain.IsSelected( iCurRow ) )
					chkElem.checked = true;
			}
			return;
		}
			
		while ( chkElem )
		{
			if ( fraMain.IsSelected( iCurRow ) )
				chkElem.checked = true;
				
			iCurRow++;
			chkElem = document.getElementById( "chk" + iCurRow );
		}
		
		iCurRow = fraMain.GetFocusRow() - 1;
		chkElem = document.getElementById( "chk" + iCurRow );
		while ( chkElem )
		{
			if ( fraMain.IsSelected( iCurRow ) )
				chkElem.checked = true;
				
			iCurRow--;
			chkElem = document.getElementById( "chk" + iCurRow );
		}
	}
	
	function initShowingTime()
	{
		var oImg = document.getElementById('imgShowingTime');
		if ( oImg )
		{
			if ( f[0] == 1 )
				oImg.style.display = '';
		}
	}

	function init(iRowsPerPage, iView, iCurRow, iTotalRows, sGUID)
	{
		try
		{
			m_sGUID  = sGUID;
			
			if(parent != null && parent.parent != null && parent.parent.parent != null && parent.parent.parent.fraTop != null && typeof(parent.parent.parent.fraTop.setAuditCustomize) == "function")
				parent.parent.parent.fraTop.setAuditCustomize();
			m_iRowsPerPage = iRowsPerPage;
			m_iFirstRow = iCurRow;
			m_iTotalRow = iTotalRows;
			initShowingTime();
			if (iView >= 29 && iView <= 31)
				initChecksCustom();
			else
				initChecks();
			m_iRowsPerPage = iRowsPerPage;
			
			updateNavButtons();
		}
		catch(e){}
	}

	function selectSSRow(chkElem)
	{
		var fraMain = getSpreadsheetFrame();
		var iSSRow = parseInt( chkElem.id.replace( "chk", "" ), 10 );
		var iCurRow = fraMain.GetFocusRow();
		var chkElem = document.getElementById( "chk" + iCurRow );
		if ( chkElem == null )
		{
			chkElem = document.getElementById( "chk1" );
			iSSRow = iCurRow;
		}
		fraMain.SetSelected( iSSRow, true );
	}

	function goNextPage()
	{
		var fraMain = getSpreadsheetFrame();
		var fraTop = getNavFrame();
		
		fraTop.document.all.Prev.disabled = true;
		fraTop.document.all.Next.disabled = true;
		fraTop.document.all.Next.onmouseout();
		fraTop.document.all.Prev.onmouseout();
		fraMain.MoveFocusRow(fraMain.GetFocusRow() + m_iRowsPerPage);
		fraTop.init();
	}

	function goPrevPage()
	{
		var fraMain = getSpreadsheetFrame();
		var fraTop = getNavFrame();
		
		fraTop.document.all.Prev.disabled = true;
		fraTop.document.all.Next.disabled = true;
		fraTop.document.all.Next.onmouseout();
		fraTop.document.all.Prev.onmouseout();
		fraMain.MoveFocusRow(fraMain.GetFocusRow() - m_iRowsPerPage);
		fraTop.init();
	}


	function updateNavButtons()
	{
		if ( m_iRowsPerPage > 1 )
		{
			var fraMain = getSpreadsheetFrame();
			var fraTop = getNavFrame();
			
			if ( fraMain && fraTop )
			{
				var iCur = Math.floor((fraMain.GetFocusRow()) / m_iRowsPerPage) * m_iRowsPerPage;
				var iMax = fraTop.GetTotalRowCount();
				var iSet = m_iRowsPerPage;
				
				if ( iCur == 0 )
					fraTop.document.all.Prev.disabled = true;
				else
					fraTop.document.all.Prev.disabled = false;
					
				if ( iCur + iSet >= iMax )
					fraTop.document.all.Next.disabled = true;
				else
					fraTop.document.all.Next.disabled = false;
					
				fraTop.document.all.spanCount.innerText = Math.floor((iCur) / iSet) + 1;
				fraTop.document.all.spanTotal.innerText = Math.floor((iMax - 1 ) / iSet) + 1;
			}
		}
	}
	
	function getSpreadsheetFrame()
	{
		if ( typeof(parent.fraMain) == 'object' ? typeof(parent.fraMain.GetFocusRow) == 'function' : false )
			return parent.fraMain;
		if ( typeof(parent.parent.fraMain) == 'object' ? typeof(parent.parent.fraMain.GetFocusRow) == 'function' : false )
			return parent.parent.fraMain;
		return null;
	}
	
	function getNavFrame()
	{
		if ( typeof(parent.fraTop) == 'object' ? typeof(parent.fraTop.GetListingSet) == 'function' : false )
			return parent.fraTop;
		if ( typeof(parent.parent.fraTop) == 'object' ? typeof(parent.parent.fraTop.GetListingSet) == 'function' : false )
			return parent.parent.fraTop;
		return null;
	}
	
	function getNextPic(iCurRow)
	{
		var sID = iCurRow;
		var iNextPic = Number(document.all.item("spnCurImg" + sID).innerHTML) + 1;
		if (iNextPic > Number(Number(document.all.item("spnTotImg" + sID).innerHTML)))
			iNextPic = 1;

		var aryPics = String(document.all.item("aryPicDataSpinner" + sID).value).split(",");
		var aryPopupPics = String(document.all.item("aryPicDataPopup" + sID).value).split(",");
		document.all.item("img" + sID).src = unescape(aryPics[iNextPic - 1]);
		document.all.item("img" + sID).popupImage = unescape(aryPopupPics[iNextPic - 1]);
		document.all.item("spnCurImg" + sID).innerHTML = iNextPic;
	}
	
	function getPrevPic(iCurRow)
	{
		var sID = iCurRow;
		var iNextPic = Number(document.all.item("spnCurImg" + sID).innerHTML) - 1;
		if (iNextPic <= 0)
			iNextPic = Number(Number(document.all.item("spnTotImg" + sID).innerHTML));
		
		var aryPics = new Array();
		var szPic = "null";
		var aryPopupPics = new Array();
		var szPopupPic = "";
		
		if (iNextPic > 0)
		{
			aryPics = String(document.all.item("aryPicDataSpinner" + sID).value).split(",");
			szPic = aryPics[iNextPic - 1];
			
			aryPopupPics = String(document.all.item("aryPicDataPopup" + sID).value).split(",");
			szPopupPic = aryPopupPics[iNextPic - 1];
		}

		document.all.item("img" + sID).src = unescape(aryPics[iNextPic - 1]);
		document.all.item("img" + sID).popupImage = szPopupPic;
		document.all.item("spnCurImg" + sID).innerHTML = iNextPic;
	}	

	function doAssocDocs(sListingID, iCurRow)
	{
		var sURL = "Docs.asp?GUID=" + m_sGUID + "&ListingID=" + sListingID;
		window.open(sURL,"_parent","",false);
	}
	
	function showFullDetail( bCurrent, iFirstID, iListingID, iView )
	{
		var sFeat	= 'dialogWidth:799px;dialogHeight:580px;status:0;help:no;scroll:no;resizable:yes;unadorned:yes;border:thin;';
		var sParams =	"view=" + iView;
		sParams		+=	"&ListingID=" + iListingID;
		sParams		+=	"&num="	+ iFirstID;
		sParams		+=	"&IsCurrent=" + bCurrent.toString();
		sParams		+=	"&outputtype=HTML";
		var sURL = "AuditDetail.aspx?" + sParams;
		var Args=new Object();
		Args.Window=this;
		window.showModalDialog(sURL, Args, sFeat);
	}

	function checkbox_onclick(iCurRow)
	{
		if (!parent || !parent.parent || !parent.parent.fraMain || !parent.parent.fraMain.SetSelected)
			return;

		if (document.getElementById("checkbox_" + iCurRow).checked)
		{
			if (!parent.parent.fraMain.IsSelected(iCurRow))
				parent.parent.fraMain.SetSelected(iCurRow, true);
		}
		else
		{
			if (parent.parent.fraMain.IsSelected(iCurRow))
				parent.parent.fraMain.SetSelected(iCurRow, true);
		}
	}
	
	function initChecksCustom()
	{
		if (!parent || !parent.parent || !parent.parent.fraMain || !parent.parent.fraMain.SetSelected)
			return;

		var iFirst = m_iFirstRow;
		var iTotal = m_iTotalRow;

		for (var i = iFirst; i < iFirst + iTotal; i++)
			if (document.getElementById("checkbox_" + i) != null && parent.parent.fraMain.IsSelected(i))
				document.getElementById("checkbox_" + i).checked = true;
	}
	
	function doQuickView(sListingID)
	{
		var sURL = '../quickView.asp?id=' + sListingID;
		var sFeat = "dialogWidth:700px;dialogHeight:400px;status:0;help:no;border:thin;";
		var sResult = new String(window.showModalDialog(sURL, "", sFeat));
	}
	
	function doHistory(sListingID, iCurRow)
	{
		if(parent.parent.fraTop != null && typeof(parent.parent.fraTop.initContent) == "function")
			parent.parent.fraMain.MoveFocusRow(iCurRow);
			parent.parent.fraTop.initContent("54", null, sListingID);
	}

	function doMap(sListingID, sMLSID) {
	    var sURL = 'Search/VE.aspx?Compact=yes&ShowDashboard=yes&ListingID=' + sListingID + '&mlsid=' + sMLSID + '&GUID=' + m_sGUID;
	    window.open(sURL, "_blank", "dependent=yes, width=550, height=550, titlebar=yes");
	} 
	
	function doTax(sListingID, iCurRow)
	{
		if(parent.parent.fraTop != null && typeof(parent.parent.fraTop.initContent) == "function")
			parent.parent.fraMain.MoveFocusRow(iCurRow);
			parent.parent.fraTop.initContent("24", null, sListingID);
	}
	function doValueSure(sListingID)
	{
		var sURL = "../ValueSureIntegration.asp?ListingID=" + sListingID;
		window.open(sURL, "ValueSureWindow", "", true);	
	}
	function doSmartHomeBuy(sListingID)
	{
		var sURL = "../SmartHomeBuyIntegration.asp?ListingID=" + sListingID;
		window.open(sURL, "SmartHomeBuyWindow", "", true);	
	}
	
	function getCurrentView(iView)
	{
		if ( parent.fraTop != null )
		{
			if ( typeof(parent.fraTop.getCurrentView) == "function" )
			{
				parent.fraTop.getCurrentView(iView);
			}
			else if ( typeof(parent.fraTop.initContent) == "function" && typeof(initContent) == "function" )
			{
				initContent(parent.fraTop);
			}
		}
	}
