

//exports
var exportBusy;
function setExportBusy(buttoncontrolID, busy) {
    exportBusy=busy;
    var exportbutton = document.getElementById(buttoncontrolID);
    if (exportbutton) {
        
        exportbutton.style.cursor=busy ? "wait":"default";
    }
    

}
function doExportWithSystemCheck(exportbutton) {
    var selected, totalResultsCount;
    
    if (__selector) {
        selected=__selector.selectedCount;
    	if (selected == 0) {
    		openSelectAtLeastOneCommonDialog();
    		return false;
    	}
        totalResultsCount = __selector.totalResultsCount;
    }
    if (!exportBusy) {
        setExportBusy(exportbutton.Id,true);
        
        CheckExportSubsystemServerCall("exportstatus," + selected,exportbutton.Id);
        return false;
    }
}

//this gets called where ARGS is the result
function CheckExportSubsystemCallback(args,context) {
	 
    if (args == "okay") {
        
        __selector.synchronize("doExportSyncCallback",null)
    } else {
        //display the warning
        switch (args) {
    
            case "other" : {
                 showExportSubsystemErrorOther();
            }
            break;
            case "red" : {
                 showExportSubsystemErrorRed();
            }
            break;
            case "orange" : {
                 showExportSubsystemErrorOrange();
            }
            case "limit" : {
                showExportLimitError();
            }
            break;
           
        }
         
    }

    setExportBusy(context,false);    
}

function CheckExportSubsystemCallbackError(args,context) {

}

function doExportCheck() {
    
    var count;
    var selected, totalResultsCount;
    
    if (__selector) {
        selected=__selector.selectedCount;
        totalResultsCount = __selector.totalResultsCount;
        if (selected == 0) {
        	openSelectAtLeastOneCommonDialog();
        	return false;
        }
    }

    count = selected;
    CheckExportLimitServerCall("exportlimit," + count,"");
    return false;
}


//this gets called where ARGS is the result
//function CheckExportLimitCallback(args,context) {

//    if (args == "true") {
//        //open the export dialog
//        doExport();
//    } else {
//        //display the warning
//        showExportLimitError();
//    }
//    
//}
 

function doExportSyncCallback(context, success) {
    doExport();
}

 

function doExport() {

    var features = "resizable: no; dialogWidth: 550px; dialogHeight: 420px; top: 200; edge: sunken; help: no; status: yes";
    //var exportURL = (ListingReportRequestedBy == 4) ? "./Popups/InventoryExport.aspx" : "./Popups/Export.aspx";
    var exportURL = "./Popups/Export.aspx";
    var count;
    var viewAll;
    var selected, totalResultsCount;
    
    if (__selector) {
        selected=__selector.selectedCount;
        totalResultsCount = __selector.totalResultsCount;
        if (selected == 0) {
        	openSelectAtLeastOneCommonDialog();
        	return false;
        }
    }

    count = selected;
    if (selected == totalResultsCount)
    {
        viewAll = 1;
    }
    else
    {
        viewAll = 0;
    }
    exportURL = exportURL + "?count=" + count + "&viewAll=" + viewAll + "&ListingReportListingCategoryID=" + ListingReportListingCategoryID;
 
     

     var result = window.showModalDialog(exportURL, null, features);

     if (result == "MyExports") {
        window.location="../Exports/MyExports.aspx";
     }
     return false;

}

function openAppointmentPopup(listingID, listGroupCode, localRoot) {
	var url = localRoot +
		'/Report/Popups/AppointmentScheduler.aspx?ListingId=' +
		listingID +
		'&ListGroupCode=' +
		listGroupCode;
	var win = window.open(url, 'appointmentScheduler');
	win.focus();
}
