// JScript File

var SAVERESULTSDIALOGWIDTH = 740;
var SAVERESULTSDIALOGHEIGHT = 690;
var commonDialogPath;
var emailLimit, emailLimitErrorMessage;
var cmaListingsLimit, cmaListingsLimitErrorMessage;
var mapListingsLimit, mapListingsLimitErrorMessage;

var __saveAsArguments = { origin: '', payload: '' };	//args to pass to Save As wizard
function openSaveResultsDialog() {
	
	__saveAsArguments.origin = 'report';
	__saveAsArguments.payload = __selector.selectedIDs();
	var wizUrl = '../SavedItems/SaveAs/SaveAsStart.aspx?origin=report';
	var features;
	var diagResult;
	
	if (__saveAsArguments.payload.length > 0) {
		wizUrl += '&hasargs=true';
	} else {
		__saveAsArguments.payload = null;
	}
	
	if (navigator.appName.toLowerCase().indexOf('explorer') > -1) {
		features = "dialogHeight:" + SAVERESULTSDIALOGHEIGHT + "px";
		features += ";dialogWidth:" + SAVERESULTSDIALOGWIDTH + "px";
		features +=";center:1";
		features +=";help:0";
		features +=";status:0";
		
		diagResult = window.showModalDialog(wizUrl, __saveAsArguments, features);

		features = "dialogHeight:300px";
		features += ";dialogWidth:356px";
		features +=";center:1";
		features +=";help:0";
		features +=";status:0";
		
		if (diagResult == true) {
			cdblShowConfirmSaveAsResults();
		} else if (diagResult != null)  {
			var values = diagResult.toString().split(',');
			if (values.length > 1) {
				if (values[0] == 'SaveAsSearch' && values[1] == 'true') {
					cdblShowConfirmSaveAsSearch();
				}
			}
		}
	} else {	//this does NOT currently work correctly
		//as of now, NN and firefox can't do modals
		features =  "height:" + SAVERESULTSDIALOGHEIGHT + "px";
		features += ";width:" + SAVERESULTSDIALOGWIDTH + "px";
		 //features += ";left:" + SAVERESULTSDIALOGLEFT;
		//features += ";top:" + SAVERESULTSDIALOGTOP;
		 features +=";center:1";
		features +=";help:0";
		features +=";status:0";
		window.open(wizUrl, "Save As", features);
	} 
}//openSaveResultsDialog()

function emailPopUp()
{
	//dialogWidth: 767px; dialogHeight: 697px
	var count;
	var viewAll;
	var selected;
	var ids;
	
	if (__selector) {
	    if (__selector.selectedCount > 0)
	    {
		    count = __selector.selectedCount;
		    viewAll = 0;
	    }
	    else
	    {
		    count = __selector.totalResultsCount;
		    viewAll = 1;
	    }
	    ids = __selector.selectedIDs();
	}
	
	
	if (count > emailLimit) {
	    openCommonDialog(4,emailLimitErrorMessage.replace("&lt;BR/&gt; {0}",""),'E-mail Limit - TREND',0,'',0,1,0,'',commonDialogPath + '/commondialog.aspx',0,0,0,0,'','','','',-1,-1);
    } else {
    	var winHeight = '650px';
	    var winWidth = '740px';

	    var newWin = window.open(GetResolveUrl() + "/Report/Popups/EmailPrep.aspx?count=" + count + "&viewAll=" + viewAll + "&ListingIDs=" + ids, "ButtonTrayEmai", "resizable=no,width=" + winWidth + ",height=" + winHeight + ",top=200,status=yes,scrollbars=no,");
    }
}

function cmaPopUp()
{
	var count;
	var viewAll;
	var selected;
	var ids;
	
	if (__selector) {
	    if (__selector.selectedCount > 0)
	    {
		    count = __selector.selectedCount;
		    viewAll = 0;
	    }
	    else
	    {
		    count = __selector.totalResultsCount;
		    viewAll = 1;
	    }
	}
	
	
	if (count > cmaListingsLimit)
	{
	    openCommonDialog(4,cmaListingsLimitErrorMessage,'Error - TREND',0,'TREND',0,1,0,'',commonDialogPath + '/commondialog.aspx',0,0,0,0,'','','','',-1,-1);
    }
    else
    {
		if (typeof __selector.synchronize == "function")
		{
			__selector.synchronize("cmaWizardSyncCallback",null);
		}
		else
		{
			launchCMAWizard();
		}
    }
}

function cmaWizardSyncCallback(context,success) {
    launchCMAWizard()
}

function launchCMAWizard() {

	var ie7Height = 610;
	var ie7Width = 740;
	var winHeight = AdjustPopupHeight(ie7Height, "px");
	var winWidth = AdjustPopupWidth(ie7Width, "px");

    window.showModalDialog(GetResolveUrl() + '/Report/CMA/Wizard/CMAWizardStart.aspx','','dialogHeight:' + winHeight + ';dialogWidth:' + winWidth + 'px;status:1;help:0;resizable:1;center:1;scroll:0')

}

function mapSelectedPopUp()
{
	var count;
	var viewAll = 1;
	var selected;
	var ids;
	
	if (__selector) {
	    if (__selector.selectedCount > 0)
	    {
		    count = __selector.selectedCount;
		    viewAll = 0;
	    }
	    else
	    {
		    count = __selector.totalResultsCount;
		    viewAll = 1;
	    }
	}
	
	
	if (count > mapListingsLimit) {
	    openCommonDialog(4,mapListingsLimitErrorMessage,'Error - TREND',0,'TREND',0,1,0,'',commonDialogPath + '/commondialog.aspx',0,0,0,0,'','','','',-1,-1);
    } else {
		if (typeof __selector.synchronize == "function")
		{
			__selector.synchronize("mapListingsSyncCallback",viewAll);
		}
		else
		{
			launchMapReport(viewAll);
		}
    }
}

function mapListingsSyncCallback(context,success) {
    launchMapReport(context)
}

function launchMapReport(all) {
    var qs;
    var qtySelected;
    
    if (__selector && __selector.selectedIDs) {
        qtySelected = __selector.selectedIDs().length;
    }
    
    qs='viewAll=' + ((all) ? 1 : 0);
    
    //window.showModalDialog(GetResolveUrl() + '/Report/Popups/MapReport.aspx?' + qs,'','resizable: yes; dialogWidth: 900 px; dialogHeight: 750px;  help: 0; status: 1');
    var features = 'status,resizable,scrollbars,width=910,height=750'
    var win = window.open(GetResolveUrl() + '/Report/Popups/MapReport.aspx?' + qs, 'mapPopup', features, true);
    win.focus();

}

function openPrintOptions() {
    if (typeof __selector.synchronize == "function") {
        __selector.synchronize("printOptionsSyncCallback",null);
    } else {
        doPrintOptions();
    }
}

function printOptionsSyncCallback(context,success) {
    doPrintOptions()
}

function doPrintOptions()
{
	var count;
	var printAll;
	var selected;
	if (__selector) {
	    
	    if (__selector.selectedCount > 0) {
		    count = __selector.selectedCount;
		    printAll = 0;
	    } else {
		    count = __selector.totalResultsCount;
		    printAll = 1;
	    }
    }
	//var ids = getOnscreenSelectedItems();
	
	url = "../Report/Popups/PrintOptions.aspx";
	url += "?count=" + count;
	url += "&viewAll=" + printAll;
	//url += "&ListingIDs=" + ids;
	url += "&ListingReportRequestedBy=" + ListingReportRequestedBy;
	url += "&CurrentReport=" + CurrentReport;
	url += "&SavedSearchName=" + encodeURIComponent(SavedSearchName);
	url += "&SavedResultName=" + encodeURIComponent(SavedResultName);
	url += "&ContactName=" + encodeURIComponent(ContactName);

	var ie7Height = 600;
	var ie7Width = 600;
	var winHeight = AdjustPopupHeight(ie7Height, "px");
	var winWidth = AdjustPopupWidth(ie7Width, "px");

	var newWin = window.showModalDialog(url, "", "resizable: yes; dialogWidth: " + winWidth + "; dialogHeight: " + winHeight + "; top: 200; edge: sunken; help: no; status: yes; scroll: 0");
	//var win = window.open(url, "");
}
