/**************************************************************************
Purpose:	Functions for popup widows
Inputs: 
Returns: 
Mod Hist:
Name			Date        Comment
ShawnB			4/1/02		Created
ChrisB			7/22/02		Added Product Info and Location functions
Diego.Carreras	12/10/02	Added VendorList function
Patrick Chiang	6/18/2003	Added My Plan details
**************************************************************************/
// <script language="javaScript">
var POPUP_TYPE_STAR_RATINGS = 0;
var POPUP_TYPE_MY_PARTY = 1;
var POPUP_TYPE_VIRTUAL_TOUR = 2;
var POPUP_TYPE_INFO = 3;
var POPUP_TYPE_POLICY = 4;
var POPUP_TYPE_AIR_DETAILS = 5;
var POPUP_TYPE_CURRENCY = 6;
var POPUP_TYPE_CALENDAR = 7;
var POPUP_TYPE_PRODUCT_INFO = 8;
var POPUP_TYPE_LOCATION_MAP = 9;
var POPUP_TYPE_VENDOR_LIST = 10;
var popupWindows = new Array(11);
	
function Open_Window(popURL,popName,popupType,w,h,t,l,scroll) {
	if(popupWindows[popupType] != null && !popupWindows[popupType].closed){
		popupWindows[popupType].close();
	}
	var winprops = 'height=' + h + ',width=' + w + ',top=' + t + ',left=' + l + ',scrollbars=' + scroll + ',resizable=no';
	var win = window.open(popURL, popName, winprops);
	popupWindows[popupType] = win;
	return win;
}
	
function CloseAllPopups() {
	for (var i = 0; i < popupWindows.length; i++){	
		if(popupWindows[i] != null && !popupWindows[i].closed){
			popupWindows[i].close();
		}
	} 
}

function Open_StarRating(strURL) {
	Open_Window(strURL, 'StarRating', POPUP_TYPE_STAR_RATINGS, 450, 300, 200, 100, 'yes');
}

function Open_Calendar(intX, intY) {
	//calculate the location of the window relative to the launch icon
	xVal = Number(intX);
	yVal = Number(intY);
	var xLoc = 0;
	var yLoc = 0;
	if(xVal == 200 && yVal == 200) {
		xLoc = xVal;
		yLoc = yVal;
	}else if(xVal > 245 && (xVal + 245) > screen.availHeight) {
		xLoc = xVal - 245;
		yLoc = yVal - 180;
	} else {
		xLoc = xVal + 15;
		yLoc = yVal - 180;
	}
	//need to return window to calendar javascript
	return Open_Window('', 'Calendar', POPUP_TYPE_CALENDAR, 230, 176, xLoc, yLoc, 'no');
}

function Open_Currency(strURL) {
	Open_Window(strURL, 'Currency', POPUP_TYPE_CURRENCY, 370, 270, 100, 100, 'no');
}

function Open_MyParty(strURL, intX, intY) {
	Open_Window(strURL, 'MyParty', POPUP_TYPE_MY_PARTY, 275, 200, intX, intY, 'no');
}

function Open_Tour(strURL) {
	var intLastSlash = strURL.lastIndexOf('/');
	strURL = strURL.substring(0,intLastSlash+1);
	var strTourLocation = "http://" + appDestCmsDomainName + "/tour.htm?strParentGUID=";
	var strURL = strTourLocation + ReturnEscape(strURL);
	Open_Window(strURL, 'Tour', POPUP_TYPE_VIRTUAL_TOUR, 680, 420, 0, 0, 'no');
}

function Open_Virtual_Tour(strURL, intW, intH) {
	Open_Window(strURL, 'LodgingTour', POPUP_TYPE_VIRTUAL_TOUR, intW, intH, 0, 0, 'no');
}

function Open_Air_Details(strURL) {
	Open_Window(strURL, 'AirDetails', POPUP_TYPE_AIR_DETAILS, 450, 310, 200, 100, 'yes');
}

function Open_Policy(strURL) {
	Open_Window(strURL, 'Policy', POPUP_TYPE_POLICY, 470, 400, 200, 100, 'yes');
}

function Open_VendorList(strURL, intW, intH, intT, intL ) {
	Open_Window(strURL, 'VendorList', POPUP_TYPE_VENDOR_LIST, intW, intH, intT, intL, 'yes');
}

/*	Purpose: Opens general info popup page, without altering the URL
	Inputs: strURL - URL to be opened
	Returns:
*/
function Open_General_Info(strURL) {
	Open_Window(strURL, 'InfoPopup', POPUP_TYPE_INFO, 642, 600, 0, 0, 'yes');
}

// OPAQUE RATES: additional parameter for the Open_Info call indicates opaque mode
function Open_Info(strProductURL, strVendorID, strAppendQueryString) {
	var popUrl, w, h;
	
	// Remove everything after the last slash in the URL
	strProductURL = strProductURL.replace(/\/[^\/]*$/,"/");
	
	if(strProductURL.lastIndexOf('/') == (strProductURL.length - 1)){
		popURL = "http://" + appDestCmsDomainName + "/info/info.asp?GUID=" + ReturnEscape(strProductURL); 

		if(strAppendQueryString.indexOf('ShowGolfwits') >= 0)
		{
			// Use a different size for GolfWits popups.
			w = 639;
			h = 530;
		}
		else
		{
			w = 560;
			h = 550;
		}
	} else if(strProductURL.indexOf('{') == 0) {
		popURL = "http://" + appDestCmsDomainName + "/info/info.asp?GUID=" + strProductURL;
		w = 560;
		h = 550;
	} else {
		popURL = strProductURL;
		w = 642;
		h = 600;
	}
	
	if(!isNaN(strVendorID)) {
		popURL = popURL + "&VendorID=" + strVendorID;
	}
	
	if (strAppendQueryString) {
		popURL = popURL + "&" + strAppendQueryString;
	}
	
	Open_Window(popURL, 'InfoPopup', POPUP_TYPE_INFO, w, h, 0, 0, 'yes');
}

function ReturnEscape(strUrl) {
	var strOutput = strUrl.substring(5,strUrl.length);
	var urlReg = new RegExp("\/", ["gi"]);
	if(strOutput.indexOf('/')>=0){
		strOutput = strOutput.replace(urlReg,'$');	
	}
	if(strOutput.indexOf('.')>=0) {
		strOutput = strOutput.replace(/\./gi,'~');
	}
	return strOutput;
}

function Open_Product_Info(strProductId, strProductName) {
	var strURL = "get_product_info.asp?productId=" + strProductId + "&productName=" + strProductName;
	Open_Window(strURL, 'ProductInfo', POPUP_TYPE_PRODUCT_INFO, 470, 400, 200, 100, 'yes');
}

function Open_Location(popURL){
	// The varVirtualUrl value must be set on the page calling this function
	popURL = "virtual_tour/" + popURL;
	Open_Location_Map(popURL);
}
	
function Open_Location_Map(strURL) {
	Open_Window(strURL, 'LocationMap', POPUP_TYPE_LOCATION_MAP, 470, 550, 0, 0, 'no');
}

/*	Purpose: Opens my plan details popup page
	Inputs: strCartKey - Cart key of the cart object, strCartIndex - Index of cart item
	Returns:
*/
function Open_My_Plan_Details(strCartKey, strCartIndex) {
	var strURL = "my_plan_details.asp?cartKey=" + strCartKey + "&cartIndex=" + strCartIndex;
	Open_Window(strURL, 'MyPlanDetails', POPUP_TYPE_PRODUCT_INFO, 470, 400, 200, 100, 'yes');
}