/*
* Created by Boris TS, 07/05/07 - ITG#374061 (IDV Map Listings Integration Enhancement)
* JS functions for IDV Virtual Earth map. All needed variables merged out on the form:
*	var mapAppType
*	var mapVEPath
*
* Revisions:
*/


function ShowMapApplication(strUrl,listingRIDs,dType,isArchive,listingSortOrder)
{
	if (typeof(mapAppType) == 'undefined')
	{
		mapAppType = 0;
	}

	//alert ('map app: ' + mapAppType)
	// If appType=0 then current app so call MapApplication() 
	if (mapAppType == 0)
	{
		MapApplication(strUrl);
	}
	else	
	{
	// If appType=1 then new IDV app so call VEMapApplication()
		VEMapApplication(listingRIDs,dType,isArchive,listingSortOrder);
	} //if (appType == 0)
}





//Opens up the regular Map Listing popup screen on click of Map link
function MapApplication(strUrl)
{
	var newWin
	var windowProperties 
	
	//scrollbars=no?
	//menubar=no (Client Portal)
	//toolbar=no (Client Portal)
	windowProperties = "menubar=no,toolbar=no,resizable=yes,directories=no,scrollbars=no,status=no";
	newWin = window.open(strUrl, 'newMapWin', windowProperties);

	//RNI #090403-000119, BTs, 09/07/2009 - removed newWin.focus();
	//newWin.focus();

 	return false;
}

//Opens up the VE Map Listing popup screen on click of Map link
function VEMapApplication(listingRIDs,dType,isArchive,listingSortOrder)
{

	// TODO: isArchive

	// dType - 'L'-from the Listings result, 'S'-from the Search Criteria
	 
	var objFrm;
	var objInput;
	var objWindow;
	var windowProperties 
	var strUrl
	
	//strUrl = mapVEPath + "&DTYPE=" + dType + "&datasource=Property&LISTINGS=" + listingRIDs + "&LISTINGSORTORDER=" + listingSortOrder;
	strUrl = mapVEPath + "&DTYPE=" + dType + "&datasource=Property";

	//alert (strUrl + " ~~ Listing Rids: " + listingRIDs + " ~~ isArchive: " + isArchive + " ~~ listingSortOrder: " + listingSortOrder)

	windowProperties = "resizable=yes,scrollbars=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0";
	//objWindow = window.open('', 'mapWindow', windowProperties)
	// TODO: remove window.open and use the POST method instead GET.
	//objWindow = window.open(strUrl + '&LISTINGS=' + listingRIDs + '&LISTINGSORTORDER=' + listingSortOrder, 'mapWindow', windowProperties)

    objFrm = document.createElement("form");
    objFrm.method = "POST";
	objFrm.action = strUrl;
	objFrm.target = "mapWindow";
	
	//Listing RIDs
	objInput = document.createElement("INPUT");
	objInput.type = "hidden";
	objInput.name = "LISTINGS";
	objInput.value = listingRIDs;
	objFrm.appendChild(objInput);

	//Listing Sort Order
	if (typeof(listingSortOrder) != 'undefined')
	{
		objInput = document.createElement("INPUT");
		objInput.type = "hidden";
		objInput.name = "LISTINGSORTORDER";
		objInput.value = listingSortOrder;
		objFrm.appendChild(objInput);
	}
	
    //isArchive
	objInput = document.createElement("INPUT");
	objInput.type = "hidden";
	objInput.name = "isArchive";
	objInput.value = isArchive;
	objFrm.appendChild(objInput);
	document.appendChild(objFrm);
	document.appendChild(objFrm);
	
	//ITG 438269 12Dec07
	objWindow = window.open('about:blank','mapWindow',windowProperties);
	
	objFrm.submit();
	objWindow.focus();
	//return false;

}
