var sBrowserName = navigator.appName;		// Client browser brand
var sBrowserVer = navigator.appVersion;		// Client browser Version
var fBrowserVer;
var oPdfWindow;
var oReportWizardWindow;

var iScreenWidth = screen.availWidth;		// Client's screen width (in pixels)
var iScreenHeight = screen.availHeight;		// Client's screen height (in pixels, not including taskbar)

// Determine browser's version
switch (sBrowserName)
{
	case "Microsoft Internet Explorer":
		sBrowserVer = sBrowserVer.substring(sBrowserVer.indexOf("MSIE ")+5);
		fBrowserVer = parseFloat(sBrowserVer.substring(0,sBrowserVer.indexOf(";")));
		break;
	case "Netscape":
		fBrowserVer = parseFloat(sBrowserVer);
		break;
}

// Creates path of current location from root directory
if (typeof(sMainPath) == 'undefined')
{
	var sPathName = location.pathname;
	var sMainPath = sPathName.substring(sPathName.substring(1).indexOf("/")+2);
	var sDirsBack = "";
	var iSlashLoc = sMainPath.indexOf("/");
	while (iSlashLoc > -1)
	{
		sDirsBack += "../";
		sMainPath = sMainPath.substring(iSlashLoc+1);
		iSlashLoc = sMainPath.indexOf("/");
	}
}

// Tayab: so many window functions, but none of them generic enough to take window size and not BE SPECIFIC for any particular window
function OpenPopup(url, winName, width, height)
{
    //ATT make it optional for width & height
    if (typeof(width) == "undefined" || width == null)
		width = screen.availWidth-50;

    if (typeof(height) == "undefined" || height == null)
		height = screen.availHeight-70;

	window.open(url, winName, 'scrollbars=1,resizable=0,' + createWinPos(width, height));
}

// This function returns a string with the exact 
// X and Y positions to center the window on the screen,
// which will be passed into the window.open() string.
// (as well as the width and height)
// Example:
// width=250,height=100,top=200,left=350
// Pass in the window's height and width values
function createWinPos(piWindowWidth,piWindowHeight)
{	
	// Tayab: added -10 to window width to account for border which is 5 pixels on each side
	var iWinXLoc = (iScreenWidth - piWindowWidth - 10) / 2;
	
	var iWinYLoc = (iScreenHeight - piWindowHeight) / 2;
	//alert("iWinXLoc="+iWinXLoc+"\niWinYLoc="+iWinXLoc)
	// Tayab: set to zero
	if (iWinYLoc<15)iWinYLoc=0;

	return "width=" + piWindowWidth.toString() + ",height=" + piWindowHeight.toString() + ",top=" + iWinYLoc.toString() + ",left=" + iWinXLoc.toString();
}

function createDialogWinPos(piWindowWidth,piWindowHeight)
{	
	var iWinXLoc = (iScreenWidth - piWindowWidth) / 2;
	var iWinYLoc = (iScreenHeight - piWindowHeight) / 2;
	
	return "dialogWidth:" + piWindowWidth.toString() + "; dialogHeight:" + piWindowHeight.toString() + "; dialogTop:" + iWinYLoc.toString() + "; dialogLeft:" + iWinXLoc.toString();
}

function noCopy()
// If user clicks on image, alert box shows up
{
	alert("This image is protected from copying, as per the photo restrictions listed in your subscription contract.");
}

// Creates pop-up window showing an image (psImageURL) and it's description (psTitle)
function imageWin(psImageURL,psTitle)
{	
	var oImageWindow;
	oImageWindow = window.open(sDirsBack + "imageviewer/EnlargeImage.aspx?psImgURL=" + escape(psImageURL) + "&psTitle=" + escape(unescape(psTitle)),"imgWin","top=0,left=0,scrollbars=1,resizable=1,width=" + (screen.availWidth-10).toString() + ",height=" + (screen.availHeight-28).toString());
}
//overloaded method to take two more parameters: imageid and propertyid
// Creates pop-up window showing an image (psImageURL) and it's description (psTitle)
function imageWin2(psImageURL,psTitle, psImageId, psPropertyId)
{	
	var oImageWindow;
	oImageWindow = window.open(sDirsBack + "imageviewer/EnlargeImage.aspx?psImgURL=" + escape(psImageURL) + "&psTitle=" + escape(unescape(psTitle)) + "&imageid=" +psImageId + "&propertyid=" + psPropertyId,"imgWin","top=0,left=0,scrollbars=1,resizable=1,width=" + (screen.availWidth-10).toString() + ",height=" + (screen.availHeight-28).toString());
}


// Creates a pop-up window for a PDF file (located at psPDFURL)
function pdfWin(psURL)
{
	oPDFWindow = window.open(psURL, "_blank", "resizable=1,status=0," + createWinPos(790,540));
}

// <Tayab:BugFix_12704 Date="18 Jul 2005">
// Made Report Wizard modal
// fixes were made in multiple files, to search use text "12704" and search in all *.js, *.htm files
function ReportWizardModal(psURL)
{
// Tayab: MSDN KB 831678
// When Microsoft Internet Explorer opens a new window from a modal or modeless 
// HTML dialog box, the new window may appear in a different process and does not 
// contain the cookie information from the dialog box.
//
// WORKAROUND: To work around this behavior, pass the window object of the parent of the dialog 
// box into the dialog box, and then use that object to open the new window.

	var args = new Object;
	args.window = window;
	oReportWizardWindow = window.showModalDialog(psURL,args,"dialogHeight:625px;dialogWidth:800px;status:no;scroll:no;resizable:yes;help:no");
}
// </Tayab:BugFix_12704>

// Creates a pop-up window for map
function mapWin(psMapURL)
{
	var oMapWindow;
	oMapWindow = window.open(psMapURL,"popMapWin",createWinPos(625,420));
}

// Creates a pop-up window for map of building set
function mapWinSet(psMapURL)
{
	var oMapWindow;
	oMapWindow = window.open(psMapURL,"popMapWin",createWinPos(625,395));
}

// Creates a generic pop-up window for displaying a Web site (shows all toolbars)
function wwwWin(psURL)
{	
	var oWWWWindow;
	var iWinWidth;
	var iWinHeight;
	
	if (iScreenWidth < 1000)
	{
		iWinWidth = 640;
		iWinHeight = 480;
	}
	else if (iScreenWidth > 1200)
	{
		iWinWidth = 1024;
		iWinHeight = 768;
	}
	else
	{
		iWinWidth = 800;
		iWinHeight = 600;
	}
	
	if (sBrowserName == "Netscape")
	{
		iWinWidth -= 8;
		iWinHeight -= 109;
	}
	
	oWWWWindow = window.open(psURL,"webWin","toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1," + createWinPos(iWinWidth,iWinHeight));
}

// Creates a chrome-less pop-up window for showing disclaimer pages (i.e., terms of use, privacy policy, etc.)
function discWin(psURL)
{	
	var oDisclaimerWin;
	oDisclaimerWin = window.open(psURL,"popWindow","toolbar=1,scrollbars=1,resizable=1," + createWinPos(500,350));
}
// Creates a chrome-less pop-up window for showing disclaimer for Property
function mainDiscWin()
{	
	var oDisclaimerWin;
	var sURL = "http://property.costar.com/common/terms.aspx"
	oDisclaimerWin = window.open(sURL,"popMainDiscWindow","toolbar=1,scrollbars=1,resizable=1," + createWinPos(500,350));
}

// Creates pop-up window for entering server-side e-mail
function emailWin(psEmailAddress,psSubject,psExplanationEnum,psClientID,psCCEmailAddress,psUsageTrackingInfo)
{	
	var oEmailWindow;
	var sURL;
	sURL = sDirsBack + "Email/Email.aspx?expl=" + psExplanationEnum + "&ClientID=" + psClientID + "&addr=" + escape(psEmailAddress) + "&subj=" + escape(psSubject);
	if (psCCEmailAddress != "")
	{
		sURL += "&cc=" + escape(psCCEmailAddress);
	}
	
	if (typeof(psUsageTrackingInfo) != "undefined" && psUsageTrackingInfo != null && psUsageTrackingInfo != "")
	{
		sURL += "&UsageTrackingInfo=" + psUsageTrackingInfo;
	}
	
	oEmailWindow = window.open(sURL,"popWin",createWinPos(340,420));
}

// bool parameter pbControlImplemented implemented for compatibility with existing projects.
// It indicates do Email control and Support aspx page have been
// implemented in current project

//NOT USED ANYMORE IN LeftMenu control 
function supportWin(psSubject, pbControlImplemented)
{
	if (pbControlImplemented == false)
	{
		this.emailWin('support@costar.com', psSubject , 'Support', '' , '');
	}
	else
	{
		var oSupportWindow;
		var sURL;
		sURL = sDirsBack + "Support/Support.aspx?subj=" + escape(psSubject);
		oEmailWindow = window.open(sURL,"popWin",createWinPos(340,425));
	}

}

//creates and opens popup window for the Support control host page
function openSupportWin(psSubject, psUrl)
{
	var oSupportWindow;
	var sURL = psUrl + "?subj=" + escape(psSubject);
	oSupportWindow = window.open(sURL,"popSupportWin",createWinPos(340,425));
}

// Creates pop-up window for exporting data
function exportWin(piRowCount)
{	
	var sURL = "../Export/ExportForm.aspx";
	if (piRowCount != null && typeof(piRowCount) != "undefined")
	    sURL += "?RowCount=" + piRowCount;
	var oExportWindow;
	oExportWindow = window.open(sURL,"popExportWindow",createWinPos(555,425));//555,425 for custom and 370,235 for Export
}

// Creates pop-up window for exporting google earth data
function exportGoogleEarth(psExportPath)
{	
	var sURL = null;
	if (psExportPath != null && typeof(psExportPath) != "undefined")
    	sURL = psExportPath + "/GoogleEarthExport.aspx";
    else
        sURL = "./GoogleEarthExport.aspx";

	var oExportGoogleEarthWindow;
	oExportGoogleEarthWindow = window.open(sURL, "popGoogleEarthExportWindow", "scrollbars=0," + createWinPos(475,235));	
}

// Creates pop-up window for tour order
function slideShowWin(psContext)
{
	var sURL = "../SlideShow/SlideShow.aspx?context=" + psContext;
	//sURL = "../Results/WaitResults.aspx?sGoToURL=" + sURL;
	var oSlideShowWindow;
	//oSlideShowWindow = window.open(sURL, "popSlideShowWindow", "fullscreen = 1");
	oExportWindow = window.open(sURL, "popSlideShowWindow", "resizable=1," + createWinPos(iScreenWidth, iScreenHeight));
}

// Creates pop-up window for tour order
function tourOrderWin(psContext)
{
	var sURL = "../TourOrder/TourOrderForm.aspx?context=" + psContext;
	var oTourOrderWindow;
	// <Tayab:BugFix_12704 Date="26 Jul 05">
	// Tour Order made modal as part of fix for 12704
	var args = new Object;
	args.window = window;
	oTourOrderWindow = window.showModalDialog(sURL, args, "dialogHeight:440px;dialogWidth:760px;status:no;scroll:no;resizable:yes;help:no");
	// </Tayab:BugFix_12704>	
}

// Creates a pop-up window for the Preferences page
function prefWin()
{
	var sURL = "../Preferences/Preferences.aspx";
	var oPrefWindow;
	oPrefWindow = window.open(sURL,"popPrefWindow","scrollbars=1," + createWinPos(735,440));
}

// Creates a pop-up window for the Help page
function helpWin(psURLPrefix)
{
	var sURLPrefix = (psURLPrefix != null ? psURLPrefix : "..");
	var sURL = "/Help/Main.htm";
	var oHelpWindow;
	
	oHelpWindow = window.open(sURLPrefix + sURL,"popHelpWindow",createWinPos(750,440));
}

function customGridWin(psViewType)
{
	var sURL = "../CustomGrid/CustomGrid.aspx?ViewTypeID=" + psViewType;
	var oCustomGridWindow;
	oCustomGridWindow = window.open(sURL,"popCustomGridWindow",createWinPos(600,370));
}				

function viewImageWin(psImageURL,piWinWidth, piWinHeight, pbResizable)
{
	var oImageWindow;
	var iWinWidth = 600;
	var iWinHeight = 400;
	var bResizable = true;
	var sOptions = "resizable=1,scrollbars=1,";
	
	if (piWinWidth != null && piWinHeight != null)
	{
		iWinWidth = piWinWidth;
		iWinHeight = piWinHeight;
	}
	
	if (pbResizable != null)
	{
		bResizable = pbResizable;
	}
	
	if (!bResizable)
	{
		sOptions = "";
	}
	
	oImageWindow = window.open("","popImgWin", sOptions + createWinPos(iWinWidth, iWinHeight));
	oImageWindow.document.open();
	oImageWindow.document.writeln("<html><head><title>&nbsp;</title></head>");
	oImageWindow.document.writeln("<body bgcolor=\"#FFFFFF\" topmargin=\"0\" leftmargin=\"0\" marginheight=\"0\" marginwidth=\"0\" onLoad=\"this.focus()\">");
	oImageWindow.document.writeln("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" height=\"100%\"><tr><td align=\"center\">");
	oImageWindow.document.writeln("<img src=\"" + psImageURL + "\" alt=\"\"/>");
	oImageWindow.document.writeln("</td></tr></table>");
	oImageWindow.document.writeln("</body></html>");
	oImageWindow.document.close();
}

// Creates a pop-up window for the Upload Attachment page
function uploadWin(piQueryID)
{
	var sURL = "../Attachment/AddAttachment.aspx?QueryID=" + piQueryID;
	var oUploadWindow;
	if (piQueryID == "")
		sURL = "../Attachment/AddAttachment.aspx?ShowDropDown='Yes'";
	oUploadWindow = window.open(sURL, "popUploadWindow", createWinPos(340,390));
}


// Creates a generic pop-up window for displaying a web site (shows all toolbars)
function cpdPopupWin(psURL)
{	
	var oCPDWindow;
	var iWinWidth;
	var iWinHeight;
	
	iWinWidth = 789;
	iWinHeight = 562;
	//oCPDWindow = window.open("/Property/Results/WaitResults.aspx?sGoToURL=" + escape(psURL),"cpdWin","resizable=1," + createWinPos(iWinWidth,iWinHeight));
	oCPDWindow = window.open(psURL,"cpdWin","resizable=0," + createWinPos(iWinWidth,iWinHeight));
}

function tenantPopupWin(psURL)
{	
	var oTenantWindow;
	var iWinWidth;
	var iWinHeight;
	
	iWinWidth = 800;
	iWinHeight = 595;
	oTenantWindow = window.open(psURL,"tenantWin","scrollbars=1,resizable=0," + createWinPos(iWinWidth,iWinHeight));
}
//blockes the opener window while the popup one is active
function Block_Opener()
{
	try
	{
		if(opener.IsManaged)
		{
			if (opener) opener.blockEvents();
		}
	}
	catch(oEx)
	{ //Do Nothing
	}	
}
//unblockes parent window
function Unblock_Opener()
{	
	try
	{
		if(opener.IsManaged)
		{
			if (opener) opener.unblockEvents();
		}
	}
	catch(oEx)
	{ //Do Nothing
	}		
}
	function RefreshOpener()
	{
		var OpenerUrl = window.opener.document.location.href;
		var sChar = "&";
		if (window.opener.document.location.href.lastIndexOf("Reload=True") == -1)
		{  
			if (window.opener.document.location.href.lastIndexOf("?") == -1)
			{
				sChar = "?";
			}
			window.opener.document.location.href = OpenerUrl + sChar + "Reload=True";
		}
		else
		{
			window.opener.document.location.reload();
		}
	}




function saveSurveyWin(psSource)
{	

	var sFeatures = "scroll:no;resizable:no;dialogHeight:450px;dialogWidth:500px;status:no;center:yes;help:no";
	
	
	try
	{
		dialogWin.win = window.showModalDialog(sDirsBack + "Query/SaveSearch.aspx?Source=" + psSource,window,sFeatures);
	}
	catch(oEx)
	{
		window.showModalDialog(sDirsBack + "Query/SaveSearch.aspx?Source=" + psSource,window,sFeatures);
	}

}


function openFeedback(psURL, psWinName, piWidth, piHeight)
{
	var sProductID = (typeof(iProductID) != "undefined" ? iProductID.toString() : "");
	
	if (sProductID != "" && sProductID != "0")
	{
		if (psURL.indexOf("?") > -1)
		{
			sProductID = "&ProductID=" + sProductID;
		}
		else
		{
			sProductID = "?ProductID=" + sProductID;
		}
	}
	
	try
	{
		dialogWin.win = window.open(psURL + sProductID, psWinName, createWinPos(piWidth, piHeight));
	}
	catch(oEx)
	{
		window.open(psURL + sProductID, psWinName, createWinPos(piWidth, piHeight));
	}
}

function siteMapWin(psServerName)
{
	var oSiteMapWindow;
	var sSiteMapLink;
	
	if (psServerName == null)
	{
		psServerName = "";
	}
	
	sSiteMapLink = psServerName + "/sitemap/";
	oSiteMapWindow = window.open(sSiteMapLink,"sitemapWindow","scrollbars=1,width=350,height=500,top=0,left=0,screenX=0,screenY=0");
}

function myDataWin(psUrl, psWindowName)
{
	var oMyDataWindow;
	oMyDataWindow = window.open(psUrl, psWindowName, "resizable=0," + createWinPos(740, 415));
}

function WindowResizeTo(piNewWindowWidth ,piNewWindowHeight)
{
	var iWinXCntr = (iScreenWidth - piNewWindowWidth) / 2;  //Window center position
	var iWinYCntr = (iScreenHeight - piNewWindowHeight) / 2;
	window.resizeTo(piNewWindowWidth, piNewWindowHeight);
	window.moveBy( -(window.screenLeft - iWinXCntr) , -( window.screenTop - iWinYCntr)); 
}

function ShowCriteriaWin(psURL)
{	
	try
	{
		dialogWin.win = window.open(psURL,"popShowCriteriaWin","resizable=1," + createWinPos(500,350));
	}
	catch(oEx)
	{
		window.open(psURL,"popShowCriteriaWin","resizable=1," + createWinPos(500,350));
	}

}
function UnderConstruction()
{
	alert("This functionality is not currently available.");
	return false;
}

//-----------------------Change Add Banners----------------------------------
	var BannerChangeInterval = 40000;		//First Load: 40 sec.
	var BannerImageTag = "";			//Should we hae a default?
	var PreferredMarket = "NTL";		//In case it fails to retreave PreferredMarket;
	var BannerTag;
	var IsPortal = false;				//??
	var BannerID;			




	
	function LoadBannerAd() 
	{
		var oIntercal = document.getElementById("htmlInterval");
		if(oIntercal)
		{
			if(oIntercal.innerHTML!="")
			{
				BannerChangeInterval = parseInt(oIntercal.innerHTML); 
			}
		}	
		var oBannerID = document.getElementById("htmlBannerID");
		if(oBannerID)
		{
			if(oBannerID.innerHTML!="")
			{
				BannerID = parseInt(oBannerID.innerHTML); 
			}
		}












		setTimeout("ChangeBanner()",BannerChangeInterval);
	}
	function ChangeBanner()
	{		
		if(document.getElementById("htmlPreferredMarket").innerHTML!="")
		{
			PreferredMarket = document.getElementById("htmlPreferredMarket").innerHTML;
		}	
		UTBannerAd.GetBanner(PreferredMarket, GetBannerCallback); 
		if(isNaN(parseInt(BannerChangeInterval)))
		{
			BannerChangeInterval = 40000;
		}  			
		setTimeout("ChangeBanner()", BannerChangeInterval);
	}
	function GetBannerCallback(poResponse) 
	{	
		if(poResponse.value) 
		{			
			try
			{
				BannerChangeInterval = parseInt(poResponse.value.Duration);
			}
			catch(e)
			{
				BannerChangeInterval = 40000;
			}
			BannerImageTag = poResponse.value.AdHtml;
			BannerID = poResponse.value.ID

		}										
		BannerTag = document.getElementById("BannerSection");	
		if(BannerTag)
		{	
			BannerTag.innerHTML=BannerImageTag;
		}
//testing:	to be removed on checking in the file
//window.status = "Banner ID: " + BannerID + ". Interval: " + BannerChangeInterval/1000 + " sec.";			
	}				
//---------------------End of Change Add Banners--------------------------------	

function DoesQueryStringHaveParam(psQueryString, psParamName)
{
	 var bHasParam = false;
	 var oParamArray = psQueryString.substring(1).split("&");
	 
	 for (var i = 0; i < oParamArray.length; i ++)
	 {
		  if (oParamArray[i].split("=")[0].toLowerCase() == psParamName.toLowerCase())
		  {
				bHasParam = true;
				break;
		  }
	 }
	 
	 return bHasParam;
}

function GetQueryStringParamValue(psQueryString, psParamName)
{
	 var sParamValue = "";
	 var oParamArray = psQueryString.substring(1).split("&");
	 
	 for (var i = 0; i < oParamArray.length; i ++)
	 {
		  if (oParamArray[i].split("=")[0].toLowerCase() == psParamName.toLowerCase())
		  {
				sParamValue = oParamArray[i].split("=")[1];
				break;
		  }
	 }
	 
	 return sParamValue;
}

// Opens full-page ad window. AdID is extracted from querystring.
function OpenFullPageAd(pbShowScrollBars)
{
	 var bHasAdID = false;
	 var bIsReview = (typeof(bIsWebAdReviewPage) != "undefined" && bIsWebAdReviewPage);
	 var bHasFPValue = (typeof(sWebAdFPValue) != "undefined" && sWebAdFPValue != null);
	 var sOriginalQS = location.search;
	 var sQS = sOriginalQS;
	 var sParam = "";

	 if (sOriginalQS == "") 
	 {
		  if (BannerID)
		  {
				sQS = "?AdID=" + BannerID;
		  }
	 }
	 else 
	 {
		  if (!(this.DoesQueryStringHaveParam(sOriginalQS, "AdID")))
		  {
				sQS = "?AdID=" + BannerID;
		  }
	 }

	 if (bHasFPValue && !(this.DoesQueryStringHaveParam(sOriginalQS, "fp")))
	 {
		  sQS += (sQS.substring(0,1) == "?" ? "&" : "?") + "fp=" + sWebAdFPValue;
	 }

	 if (bIsReview && !(this.DoesQueryStringHaveParam(sOriginalQS, "p")))
	 {
		  sQS += (sQS.substring(0,1) == "?" ? "&" : "?") + "p=1";
	 }

	 var oWin = null;
	 var sDirectory = "/";

	 if (location.pathname.substring(0,11).toLowerCase() == "/admanager/")
	 {
		  sDirectory = "/AdManager/";
	 }
	 else if (location.pathname.substring(0,16).toLowerCase() == "/customerportal/")
	 {
		  sDirectory = "/CustomerPortal/";
	 }

	 var sAdURLPrefix = location.protocol  + "//" + location.host + sDirectory;
	 var sAdURLDir = ((this.GetQueryStringParamValue(sQS,"p") == "1" || this.GetQueryStringParamValue(sOriginalQS,"p") == "1") ? "AdReview/" : "Common/BannerAd/");
	 var sOptions = "scrollbars=0,resizable=0";

	 if (pbShowScrollBars != null)
	 {
		  if (pbShowScrollBars)
		  {
				sOptions = "scrollbars=1,resizable=1";
		  }
	 }

	 oWin = window.open(sAdURLPrefix + sAdURLDir + "FullPageAd.aspx" + sQS, "FullPageAdWindow", sOptions);
}

// Resizes and redirects full-page ad window.
function ResizeRedirectAdWindow(psRedirectURL, piWindowWidth, piWindowHeight)
{
	var iWinWidth = 0;
	var iWinHeight = 0;
	var iWinXLoc = 0;
	var iWinYLoc = 0;
	var oWin = null;
	var bIsNewWindow = true;
	
	if (piWindowWidth != null && piWindowHeight != null)
	{
		iWinWidth = piWindowWidth;
		iWinHeight = piWindowHeight;
		bIsNewWindow = false;
		
		if (iScreenWidth < 1000)
		{
			iWinWidth = 640;
			iWinHeight = 480;
		}
		else
		{
			iWinWidth = 800;
			iWinHeight = 600;
		}
		
		iWinXLoc = (iScreenWidth - iWinWidth) / 2;
		iWinYLoc = (iScreenHeight - iWinHeight) / 2;
	}
	
	if (psRedirectURL != "")
	{
		if (bIsNewWindow)
		{
			wwwWin(psRedirectURL);
			this.close();
		}
		else
		{
			this.resizeTo(iWinWidth, iWinHeight);
			this.moveTo(iWinXLoc, iWinYLoc);
			location.replace(psRedirectURL);
		}
	}
}


var oCRMWindow;
//switch to CRM window. Open a new window if there currently is no CRM window
function SwitchToCRM(psUrl,pbLeaveBehind) 
{
	var iBrowserWidth =  Math.floor(window.screen.width * .85);
	var iBrowserHeight = Math.floor(window.screen.height * .7);

	var sParam = 'menubar=yes,location=yes,status=yes,scrollbars=yes,toolbar=yes,resizable=yes' +
								',top=' + Math.floor(window.screen.height * .05).toString() +
								',left=' + Math.floor((window.screen.width -iBrowserWidth)/2).toString() +
								',width=' + iBrowserWidth.toString() + ',height=' + iBrowserHeight.toString();
	window.name = "mainPortalPage";

	if ((!oCRMWindow) || oCRMWindow.closed)
	{
		oCRMWindow = window.open('', 'costarCRM', sParam, true);     
	}
	
	try {	
		if (oCRMWindow.document.location.href == 'about:blank' || oCRMWindow.document.location.href == '') {
			oCRMWindow.document.location.href = psUrl;
		}
	}
	catch(e) {
		//
		//eat exception. Don't let main page go to "access denied" screen
		//
	}
	finally {
		if (pbLeaveBehind == null || !pbLeaveBehind)
			oCRMWindow.focus();
		else {
			//send new CRM window to the back
			oCRMWindow.blur();
			window.focus();
		}
	}

	return false;
}


function OpenWindowResize ( psUrl, piNewWindowWidth ,piNewWindowHeight ) 
{
	var oWindow;

	var sParam = 'toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,' + createWinPos(piNewWindowWidth, piNewWindowHeight);
		oWindow = window.open( '', 'costarCRMViewDoc', sParam, true);     

	try {	
		//if (oWindow.document.location.href == 'about:blank' || oWindow.document.location.href == '') 
		//{
			oWindow.location.href = psUrl;
			oWindow.document.location.href =  psUrl;
					
		//}
	}
	catch(e) {
		//
		//eat exception. Don't let main page go to "access denied" screen
		//
	}
	finally {
		oWindow.focus();
	}

	return false;
}

function OpenModalWindow(psURL,sDialogName)
{
	window.showModalDialog(psURL, window, "dialogHeight:380px;dialogWidth:640px;status:no;scroll:no;resizable:yes;help:no;center:yes");
	
}

