// JScript File

function accuracyHistoryPopUp(listingID, localRoot)
{
	var ie7Height = 654;
	var ie7Width = 985;
	var winHeight = AdjustPopupHeight(ie7Height, "px");
	var winWidth = AdjustPopupWidth(ie7Width, "px");
	
    var newWin = window.showModalDialog(localRoot + "/Report/LinksAndIcons/AccuracyHistory.aspx?listingID=" + listingID, "", "resizable: yes; dialogWidth: " + winWidth + "; dialogHeight: " + winHeight + "; top: 200; edge: sunken; help: no; status: yes; scroll: no;");
}

function accuracyIssuePopUp(listingID, localRoot)
{
	var newWin = window.showModalDialog(localRoot + "/Report/Popups/AccuracyIssue.aspx?listingID=" + listingID, "", "resizable: yes; dialogWidth: 752 px; dialogHeight: 556px; edge: sunken; help: no; status: yes");
	//var newWin = window.open('./popups/AccuracyIssue.aspx?listingID=' + listingID,'','scrollbars=no,width=740,height=525,top=10,left=10');
}

function clientListingFullPopUp(listingID, localRoot, radiusCenterDistance)
{
    //if (!(browserName == "Microsoft Internet Explorer")) {
    //	// Non-IE
    //	var url = RelativeWebDirectoryPath + "/Report/LinksAndIcons/ClientFullMlsNumberLink.aspx?lid=" + listingID;
    //	if (radiusCenterDistance != null && !isNaN(radiusCenterDistance)) { url += "&dis=" + radiusCenterDistance; }
	//
	//    var winWidth = 748;	
	//    var winHeight = 796;
	//    
	//    var features = 'status,resizable';
	//	var win = window.open(url, 'listingPopUp', features, true);
	//    //win.resizeTo(winWidth, winHeight);	//resizeTo() instead of features in case already open
	//    win.focus();
	//    
	//    listingPopUp(url, ie7Width, ie7Height);
    //} else {
    //    // IE        
        var result;
	    var features;
    	
	    //Setup Width and Height
	    var ie7Height = 742;
	    var ie7Width = 746;
	    var winHeight = AdjustPopupHeight(ie7Height, "px");
	    var winWidth = AdjustPopupWidth(ie7Width, "px");
    	
	    //setup pop-up
	    features = "dialogHeight: " + winHeight;
	    features += ";dialogWidth: " + winWidth;
	    features += ";edge: sunken";
	    features += ";center: 1";
	    features += ";help: 0";
	    features += ";status: 1";
	    features += ";resizable: 1";
	    features += ";scroll: 0";
        //display the popup, passing in needed QS values
	    var newWin = window.showModalDialog(localRoot + "/Report/LinksAndIcons/ClientFullMlsNumberLink.aspx?lid=" + listingID, null, features);
    //}
}

function floorPlanPopUp(listingID, localRoot)
{
	//var winHeight = 711; //653px modal
	//var winWidth = 679; //672px modal
	var features = 'status=yes,resizable=yes,scrollbars=yes,width=679,height=711';

    var win = window.open(localRoot + "/Report/LinksAndIcons/floorPlan.aspx?listingID=" + listingID, "historyPopUp", features, true);
	//win.resizeTo(winWidth, winHeight);	//resizeTo() instead of features in case already open
	win.focus();	//ensure child window comes to the front whenever called
}

function historyPopUp(listingID, listingCategoryID, localRoot)
{
	//var winHeight = 732; //650px modal
	//var winWidth = 752; //744px modal
	var features = 'status=yes,resizable=yes,width=752,height=732';
	
    var win = window.open(localRoot + "/Report/LinksAndIcons/History.aspx?listingID=" + listingID + "&listingCategoryID=" + listingCategoryID, "historyPopUp", features, true);
	//win.resizeTo(winWidth, winHeight);	//resizeTo() instead of features in case already open
	win.focus();	//ensure child window comes to the front whenever called
}

// show the one-line/hotsheet more info popup
function infoPopUp(listingID, categoryID, reportEnum, localRoot)
{
	//TODO: add a browser check here to handle non-IE popups
	var newWin = window.showModalDialog(localRoot + "/Report/LinksAndIcons/info.aspx?listingID=" + listingID + "&categoryID=" + categoryID + "&reportEnum=" + reportEnum, "", "resizable: no; dialogWidth: 310px; dialogHeight: 387px; top: 200; edge: sunken; help: no; status: yes; scroll: no;");
	//var newWin = window.open("./LinksAndIcons/info.aspx?listingID=" + listingID + "&categoryID=" + categoryID,"","scrollbars=yes,width=329,height=370,top=200");
}

function listingPopUp(url, ie7Width, ie7Height)
{
	var winHeight = AdjustPopupHeight(ie7Height, '');	//no units for normal pop-up
	var winWidth = AdjustPopupWidth(ie7Width, '');
	var features = 'status=yes,resizable=yes,width=' + winWidth + ',height=' + winHeight;
	
	var win = window.open(url, 'listingPopUp', features, true);
	//win.resizeTo(winWidth, winHeight);	//resizeTo() instead of features in case already open
	win.focus();	//ensure child window comes to the front whenever called
}//listingPopUp()

function mapPopUp(listingIDs, mapServerURL, subjectPropertyListingID, realtorName, officePhone, preferredPhone, preferredPhoneName, realtorEmail, realtorOffice, showPartner)
{
    var url = "http://" + mapServerURL + "/MapsMulti.aspx";
    var params = "?MapListingIDs=" + listingIDs;
    if (subjectPropertyListingID != "")
        params += "&MapSubjectPropertyListingID=" + subjectPropertyListingID;
    if (realtorName != "")
        params += "&RealtorName=" + realtorName;
    if (officePhone != "")
        params += "&OfficePhone=" + officePhone;
    if (preferredPhone != "")
        params += "&PreferredPhone=" + preferredPhone;
    if (preferredPhoneName != "")
        params += "&PreferredPhoneName=" + preferredPhoneName;
    if (realtorEmail != "")
        params += "&RealtorEmail=" + realtorEmail;
    if (realtorOffice != "")
        params += "&RealtorOffice=" + realtorOffice;
     if (showPartner != "")
		params += "&ShowPartner=" + showPartner;
/*        
    var ie7Height = 850;    // This number is IE6 height - 55
    var ie7Width = 900;    // This number is IE6 width - 4
    var winHeight = AdjustPopupHeight(ie7Height, "px");
    var winWidth = AdjustPopupWidth(ie7Width, "px");
 
    if (ie6 || ie7)
        var newWin = window.showModalDialog(url + params, "", "resizable: yes; dialogWidth: " + winWidth + "; dialogHeight: " + winHeight + "; top: 200; edge: sunken; help: no; status: yes; scroll: no;");
    else
        var newWin = window.open(url + params, "", "toolbar,width=" + winWidth + ",height=" + winHeight + ",directories=no,menubar=no,resizable=yes,scrollbars=yes,toolbar=no,location=no,status=yes") 
*/
    var winHeight = 750; //850
    var winWidth = 910; //900
    var features = 'status,resizable,scrollbars,width='+ winWidth + ',height=' + winHeight;       
    
    var win = window.open(url + params, 'mapPopup', features, true);
	//win.resizeTo(winWidth, winHeight);	//resizeTo() instead of features in case already open
	win.focus();	//ensure child window comes to the front whenever called           
}

function memberDetailPopUp(memberID, localRoot, useModal, resultsetDataType)
{
	//When resultsetDataType is not passed in then default to 'Listing'.  This is used in logging where the popup came from.
	if(resultsetDataType == undefined)
		resultsetDataType = 'Listing';

	//When useModal is not passed in then do modal.  This is for backward compatibility,
	//because prior to this change this popup has always been modal.
	if(useModal == undefined || useModal) {
		var newWin = window.showModalDialog(localRoot + "/Report/Popups/MemberDetails.aspx?id=" + memberID + "&resultsetDataType=" + resultsetDataType, "", "resizable: yes; dialogWidth: 747 px; dialogHeight: 525px; edge: sunken; help: no; status: yes");
	}
	else {
		var features = 'status,resizable,scrollbars,width=757,height=500';
		var win = window.open(localRoot + "/Report/Popups/MemberDetails.aspx?id=" + memberID + "&resultsetDataType=" + resultsetDataType, "memberPopUp", features);
		win.focus();	//ensure child window comes to the front whenever called
	}	

}

function memberListingFullPopUp(listingID, radiusCenterDistance)
{
	var url = RelativeWebDirectoryPath + "/Report/LinksAndIcons/MemberFullMlsNumberLink.aspx?lid=" + listingID;

	if (radiusCenterDistance != null && !isNaN(radiusCenterDistance)) { url += "&dis=" + radiusCenterDistance; }
	
	//happy IE6 popup values:  736, 689 (doesn't appear to be translating nicely)
	//IE7 modal values 750 x 745
	var useModal;
	useModal = (typeof dialogArguments == 'undefined') ? false : true;
	
	
	if (!useModal) {
	    var ie7Width = 752;
	    var ie7Height = 738; //Ensure 1024x768 viewable, we subtract 30 (for the windows taskbar) from 768.	
	    listingPopUp(url, ie7Width, ie7Height);
	} else {
	    window.showModalDialog(url, "", "status;resizable; dialogWidth: 740 px; dialogHeight: 740px;");
	
	}
}
 

function officeDetailPopUp(officeID, localRoot, useModal, resultsetDataType)
{
	//When resultsetDataType is not passed in then default to 'Listing'.  This is used in logging where the popup came from.
	if(resultsetDataType == undefined)
		resultsetDataType = 'Listing';

	//When useModal is not passed in then do modal.  This is for backward compatibility,
	//because prior to this change this popup has always been modal.
	if(useModal == undefined || useModal) {
		var newWin = window.showModalDialog(localRoot + "/Report/Popups/OfficeDetails.aspx?id=" + officeID + "&resultsetDataType=" + resultsetDataType, "", "resizable: yes; dialogWidth: 747 px; dialogHeight: 525px; edge: sunken; help: no; status: yes");
	}
	else {
		var features = 'status,resizable,scrollbars,width=757,height=500';
		var win = window.open(localRoot + "/Report/Popups/OfficeDetails.aspx?id=" + officeID + "&resultsetDataType=" + resultsetDataType, "officePopUp", features);
		win.focus();	//ensure child window comes to the front whenever called
	}
}

function publicRecordsCountyAccessDeniedPopUp() 
{
    //TODO: add a browser check here to handle non-IE popups
    showPublicRecordsCountyAccessDenied();
}

function publicRecordsUnavailablePopUp() 
{
    //TODO: add a browser check here to handle non-IE popups
    showPublicRecordsUnavailable();
}

function retreiveOneLineListingPhoto(assetLocatorServerURL, mlsNumber, listingid, businesspartnerid)
{
      
    var imgSource = "http://" + assetLocatorServerURL + "?EntityType=Listing&AssetType=Image&BusinessPartnerID=" + businesspartnerid + "&MlsNumber=" + mlsNumber + "&ImageVersion=Final&ImageNumber=1"
     
      
    document.getElementById("listingPhotoPopUp" + listingid).src = imgSource
}

function virtualTourPopUp(url)
{
    //TODO: add a browser check here to handle non-IE popups
    //var newWin = window.showModalDialog(url, "", "resizable: yes; top: 200; edge: sunken; help: no; status: yes; dialogWidth: 752px; dialogHeight: 707px");
	var newWin = window.open(url,'','resizable=yes,scrollbars=yes,status=yes,width=752px,height=707px,top=5,left=5');
	newWin.focus();
}

function mapDirectionsPopup(address) {
	var encodedAddress = address.replace(/ /g, '+');
	var url = 'http://www.bing.com/maps/default.aspx?lvl=8&rtp=adr.+~adr.' + escape(encodedAddress).replace(/%A0/g, '+');
	var win = window.open(url);
	win.focus();
}

//------------ Callback support functions for the Send Email links ------------
function ClientSideSendEmailCallbackHandler(result,context) {
	//The server is not passing anything back so we don't need to do anything
	return;	
}

function OnClickSendEmail(pageDescription, screenType, emailAddress) {
	//This xml should match the Trend.Mls4.Framework.Report/Logging/SendEmailLinkEventArguments class.
	//The RequesterMemberID is not included because we can get it from MlsPrincipal 
	var xmlArgs = '<SendEmailLinkEventArguments>' +
			'<OriginatingPage>' + pageDescription + '</OriginatingPage>' + 
			'<ScreenType>' + screenType + '</ScreenType>' + 
			'<EmailAddress>' + emailAddress + '</EmailAddress>' + 
			'</SendEmailLinkEventArguments>';
			
	ServerCallForSendEmailCallback(xmlArgs);
}
//------------------------

