// Selection path determines which way the user has selected to start a search
// 0 = Nothing chosen
// 1 = Use destination to populate cruise line list
// 2 = Cruise Line to populate destination list
var crSelectionPath = 0;

function openOneVendorWindow()
{
	$("#selectVendor").css("display", "none");

	// Setup any defaults
	$("#vendorNumberText").css("display", "block");
	if (vendorsToView == -1) {
		vendorsToView = 0;
		$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
	}
	
	// Set waiting screen
	$("#vendors").css("display","none");  						   
	$("#loadingVendors").css("display","block");  						   

	// We've got vendors so let's get all the values
	var checkedVendors = "";

	// Setup popup blocker window counts
	$("#vendorNumber").html(0);
	$("input:checked").each ( 
		function(index) {
			
			checkedVendors = checkedVendors + $(this).val() + "|";
			
			// Reset the images to "unchecked status" on popup blocker layer if window isn't open
			windowName = "win" + $(this).val();
			if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
				$( "#crbutton_" + $(this).val() ).attr( "src",  CDN_PATH + "/checkprices.gif");
				
				// Since we've closed the window increase the vendorsToView amount
				if (vendorsToView < 0)
					vendorsToView++;
			}
			else {
				
				// Determine vendors to view
				if (vendorsToView > 0)
					vendorsToView--;
				
				if (vendorsToView == 1)
					$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
				else if (vendorsToView == 0)
					$( "#vendorNumberText" ).css("display", "none");
				else
					$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
			}
		}
	);

	// Get month selected
	var dateSelected = $("#cruiseDate").val();
	
	// Get cruiseline if it exists
	var clID = $("#cruiselineID").val();

	// Get shipID if it exists
	var shipID = $("#shipID").val();
	
	// destinations
	var destID = $("#destinations").val();

	// destinations
	var section = $("#section").val();

	// Setup data to send to ajax call
	var dataToSend = "vendors=" + escape(checkedVendors) + "&date=" + escape(dateSelected) + "&clID=" + escape(clID) + "&shipID=" + escape(shipID) + "&destID=" + escape(destID) + "&section=" + escape(section) + "&ipAddress=" + escape(ip);

	// Make ajax call with info
	var vendorArray = new Array;
	$.ajax(
	{
		url: '/ajax/ajx_getCheckRateVendors.php',
  		dataType: 'text',
  		//dataType: 'json',
  		data: dataToSend,
		async:   false,
  		success: function(data) 
		{
			vendorArray = eval("(" + data + ")");
			//vendorArray = data;
		}
	});

	// Setup one window positioning
	var top = 125;
	var left = 525;
	//var width = 600;
	//height = 450;
	var winHeight = $(window).height() * 0.75;
	var winWidth = $(window).width() * 0.5;	
	
	// Try to open up all the popups 1st to see if a popup blocker is enabled
	var windowName = "";
	var maxWindows = 0;
	var crWinArray = new Array();
	var lastOpenedWinName = "";
	var reOpenedWindow = false;
	
	$.each(vendorArray,
	function(i, item)
	{
		windowName = "win" + i;

		// Check if window was closed previously
		var windowCreated = false;
		if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
			openedAllCRWins = false;
			windowCreated = true;
		}

		// Open up window until we can't open it any more
//		crPopupWins[windowName] = window.open("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, "top=" + top + ",left=" + left + ",width=" + width + ",height=" + height + ",location=1,scrollbars=1,status=1,menubar=1,resizable=1");
		crPopupWins[windowName] = openBrowserWindow("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, top, left, winWidth, winHeight);
		if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
				
			// Put end placeholder in popup blocked window so we can determine where to add the next window in popup array next time we come in here
			crPopupWins[windowName] = "end";	
			popupBlocker = true;

			return false;   // We found popup blocker so return false to break out of this each and continue on through rest of function
		}
			
		crWinArray[maxWindows] = windowName;
		maxWindows++;

		// Set button to selected
		$( "#crbutton_" + item.vendorID ).attr( "src",  CDN_PATH + "/checkpricessel.gif");

		// Keep track of last window
		if (windowCreated) {
			lastOpenedWinName = windowName;
		}

		// Charge vendor if needed
		chargeVendor(item.vendorID, clID);
	});
	
	// Have we opened all vendor windows once?
	if ( popupBlocker && (maxWindows == 1) && !openedAllCRWins) {
		openedAllCRWins = true;
		
		// Check for vendor cookie and set if it doesn't exist
		$( "#crIndividualVendors" ).dialog( "open" );
		
		if (lastOpenedWinName != "") {
			crPopupWins[lastOpenedWinName].focus();		
		}
			
		reOpenedWindow = true;
	}
		
	// Reverse order of focus so #1 vendor is on top if we've already opened up all windows
	if (!openedAllCRWins && !reOpenedWindow) {
		$.each(crWinArray.reverse(),
		function(i, item)
		{
			crPopupWins[item].focus();
		});
	}
	
	if (popupBlocker && openedAllCRWins && !reOpenedWindow) {
		
		// We've already cycled throw all the windows and didn't open a new one
		// Put back original options
		$("#loadingVendors").css("display","none");  						   
		$("#vendors").css("display","block");  			
		$( "#crIndividualVendors" ).dialog( "open" );		
	}
	else if (popupBlocker && !reOpenedWindow) {

		// Display box with individual check rate vendors
		$( "#crIndividualVendors" ).dialog( "open" );
		
		if (lastOpenedWinName == "") {
			
			// Incase some of the copy already openned the 1st window and we can't open any windows
			vendorsToView++;
			
			if (vendorsToView == 1)
				$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
			else if (vendorsToView == 0)
				$( "#vendorNumberText" ).css("display", "none");
			else
				$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");			
		}
		else
			crPopupWins[lastOpenedWinName].focus();
	}
	
	// Put back original options
	$("#loadingVendors").css("display","none");  						   
	$("#vendors").css("display","block");  			

	return false;
}

function openVendorWindows()
{
	// Determine if any vendor selected
	var vendorsChecked = $("input:checked").length;
	
	if(vendorsChecked == 0) {
		$("#selectVendor").css("display", "block");
		return false;
	}
	else if (vendorsChecked == 1) {
		
		// Let's loosely couple this and handle it separately since 1 vendor window needs to be positioned different
		openOneVendorWindow();
		return true;
	}
	else
		$("#selectVendor").css("display", "none");

	// Setup any defaults
	$("#vendorNumberText").css("display", "block");
	if (vendorsToView == -1) {
		vendorsToView = vendorsChecked - 1;
		
		if (vendorsToView == 1)
			$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
		else
			$("#vendorNumberText").html("You have " + vendorsToView + " more sites to check");
	}
	
	// Set waiting screen
	$("#vendors").css("display","none");  						   
	$("#loadingVendors").css("display","block");  						   

	// We've got vendors so let's get all the values
	var checkedVendors = "";

	// Setup popup blocker window counts
	$("#vendorNumber").html(vendorsChecked - 1);
	$("input:checked").each ( 
		function(index) {
			
			checkedVendors = checkedVendors + $(this).val() + "|";
			
			// Reset the images to "unchecked status" on popup blocker layer if window isn't open
			windowName = "win" + $(this).val();
			if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
				$( "#crbutton_" + $(this).val() ).attr( "src",  CDN_PATH + "/checkprices.gif");
				
				// Since we've closed the window increase the vendorsToView amount
				if (vendorsToView < (vendorsChecked-1))
					vendorsToView++;
			}
			else {
				
				// Determine vendors to view
				if (vendorsToView > 0)
					vendorsToView--;
				
				if (vendorsToView == 1)
					$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
				else if (vendorsToView == 0)
					$( "#vendorNumberText" ).css("display", "none");
				else
					$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
			}
		}
	);

	// Get month selected
	var dateSelected = $("#cruiseDate").val();
	
	// Get cruiseline if it exists
	var clID = $("#cruiselineID").val();

	// Get shipID if it exists
	var shipID = $("#shipID").val();
	
	// destinations
	var destID = $("#destinations").val();

	// destinations
	var section = $("#section").val();

	// Setup data to send to ajax call
	var dataToSend = "vendors=" + escape(checkedVendors) + "&date=" + escape(dateSelected) + "&clID=" + escape(clID) + "&shipID=" + escape(shipID) + "&destID=" + escape(destID) + "&section=" + escape(section) + "&ipAddress=" + escape(ip);

	// Make ajax call with info
	var vendorArray = new Array;
	$.ajax(
	{
		url: '/ajax/ajx_getCheckRateVendors.php',
  		dataType: 'text',
  		//dataType: 'json',
  		data: dataToSend,
		async:   false,
  		success: function(data) 
		{
			vendorArray = eval("(" + data + ")");
			//vendorArray = data;
		}
	});

	// Loop through each vendor now that we have
//	var top = 100 + (25*vendorsChecked);
//	var left = 500 + (25*vendorsChecked);
	var top = $(window).height() * 0.50;
	var left = 0;
	var winHeight = $(window).height() * 0.75;
	var winWidth = $(window).width() * 0.33;
	
	// Try to open up all the popups 1st to see if a popup blocker is enabled
	var windowName = "";
	var maxWindows = 0;
	var crWinArray = new Array();
	var lastOpenedWinName = "";
	var reOpenedWindow = false;
	
	$.each(vendorArray,
	function(i, item)
	{
		windowName = "win" + i;

		// Check if window was closed previously
		var windowCreated = false;
		if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
			openedAllCRWins = false;
			windowCreated = true;
		}

		// Open up window until we can't open it any more
		//crPopupWins[windowName] = window.open("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, "top=" + top + ",left=" + left + ",width=" + winHeight + ",height=" + winHeight + ",location=1,scrollbars=1,status=1,menubar=1,resizable=1");
		crPopupWins[windowName] = openBrowserWindow("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, top, left, winWidth, winHeight);
		
		if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
				
			// Put end placeholder in popup blocked window so we can determine where to add the next window in popup array next time we come in here
			crPopupWins[windowName] = "end";	
			popupBlocker = true;

//			top += 25;
//			left += 25;
			left += winWidth;
				
			return false;   // We found popup blocker so return false to break out of this each and continue on through rest of function
		}
			
//		top += 25;
//		left += 25;

		// Because IE is so wierd move the window to the right position
		try {
			crPopupWins[windowName].resizeTo(winWidth,winHeight);
			crPopupWins[windowName].moveTo(left,top);
		}
		catch (err) {
			// if you get access denied then don't do anything
		}
		
		left += winWidth;
		
		crWinArray[maxWindows] = windowName;
		maxWindows++;

		// Set button to selected
		$( "#crbutton_" + item.vendorID ).attr( "src",  CDN_PATH + "/checkpricessel.gif");

		// Keep track of last window
		if (windowCreated) {
			lastOpenedWinName = windowName;
		}

		// Charge vendor if needed
		chargeVendor(item.vendorID, clID);
	});
	
	// Have we opened all vendor windows once?
	if ( popupBlocker && (maxWindows == vendorsChecked) && !openedAllCRWins) {
		openedAllCRWins = true;
		
		// Check for vendor cookie and set if it doesn't exist
		$( "#crIndividualVendors" ).dialog( "open" );
		
		if (lastOpenedWinName != "") {
			crPopupWins[lastOpenedWinName].resizeTo($(window).width() * 0.50, $(window).height() * 2);
			crPopupWins[lastOpenedWinName].moveTo(500,$(window).height() * 0.20);
			crPopupWins[lastOpenedWinName].focus();		
		}
			
		reOpenedWindow = true;
	}
		
	// Reverse order of focus so #1 vendor is on top if we've already opened up all windows
	if (!openedAllCRWins && !reOpenedWindow) {
		$.each(crWinArray.reverse(),
		function(i, item)
		{
			crPopupWins[item].focus();
		});
	}
	
	if (popupBlocker && openedAllCRWins && !reOpenedWindow) {
		
		// We've already cycled throw all the windows and didn't open a new one
		// Put back original options
		$("#loadingVendors").css("display","none");  						   
		$("#vendors").css("display","block");  			
		$( "#crIndividualVendors" ).dialog( "open" );		
	}
	else if (popupBlocker && !reOpenedWindow) {

		// Display box with individual check rate vendors
		$( "#crIndividualVendors" ).dialog( "open" );
		
		if (lastOpenedWinName == "") {
			
			// Incase some of the copy already openned the 1st window and we can't open any windows
			vendorsToView++;
			
			if (vendorsToView == 1)
				$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
			else if (vendorsToView == 0)
				$( "#vendorNumberText" ).css("display", "none");
			else
				$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");			
		}
		else {
			// Move and resize window
			crPopupWins[lastOpenedWinName].resizeTo($(window).width() * 0.50,  $(window).height() * 2);
			crPopupWins[lastOpenedWinName].moveTo(500,$(window).height() * 0.20);
			crPopupWins[lastOpenedWinName].focus();
			
		}
	}
	
	// Put back original options
	$("#loadingVendors").css("display","none");  						   
	$("#vendors").css("display","block");  			

	return false;
}


function isSEMEvent()
{
	var semEntryPage = getCookie("SEM_ENTRYPAGE");
	
	if (semEntryPage != null && semEntryPage.indexOf("CCSEM") != -1)
		return true;
	else
		return false;
}

function chargeVendor(vendorID, cID)
{
	// Check for vendor cookie and charge if not set
	var vCookieName = "ccvendor" + vendorID;
	if (empty(getCookie(vCookieName))) {
		setCookie(vCookieName, '1', '', '/', '.cruisecritic.com', '' );
						
		// Get user IP if already set
		if (empty(ip))
			ip = "";

		// Get current page
		var adClickPage=window.location.href;
						
		// Get any SEM values
		var semEntryPage = "";
		var semEntryPageRef = "";
		if (isSEMEvent()) {
			semEntryPage = getCookie("SEM_ENTRYPAGE");
			semEntryPageRef = getCookie("SEM_ENTRYPAGEREF");
		}

		// Add in google event
		trackEvent("CheckRates", "billingEvent", 0, true);

		// Charge vendor for this session
		$.ajax(
		{
			url: '/ajax/ajx_crBillingEvent.php',
	  		dataType: 'json',
	  		data: "vendor=" + vendorID + "&ip=" + escape(ip) + "&adClickPage=" + urlencode(adClickPage) + "&semEntryPage=" + escape(semEntryPage) + "&semEntryPageRef=" + escape(semEntryPageRef) + "&cID=" + escape(cID),
	  		success: function(data) 
			{
			}
		});
	}

	return true;
}

function openIndividualVendor(vendorID)
{
	// Get month selected
	var dateSelected = $("#cruiseDate").val();
	
	// Get cruiseline if it exists
	var clID = $("#cruiselineID").val();

	// Get shipID if it exists
	var shipID = $("#shipID").val();

	// Get destination if it exists
	var destID = $("#destinations").val();

	// Get section if it exists
	var section = $("#section").val();

	// Setup data to send to ajax call
	var dataToSend = "vendors=" + escape(vendorID) + "&date=" + escape(dateSelected) + "&clID=" + escape(clID) + "&shipID=" + escape(shipID) + "&destID=" + escape(destID) + "&section=" + escape(section) + "&ipAddress=" + escape(ip);

	// Make ajax call with info
	var vendorArray = new Array;
	$.ajax(
	{
		url: '/ajax/ajx_getCheckRateVendors.php',
  		dataType: 'text',
  		//dataType: 'json',
  		data: dataToSend,
		async:   false,
  		success: function(data) 
		{
			vendorArray = eval("(" + data + ")");
			//vendorArray = data;
		}
	});

	var top = $(window).height() * 0.20;
	var left = 500;
	
	$.each(vendorArray,
	function(i, item)
	{
		
		var windowName = "win" + i;
		//crPopupWins[windowName] = window.open("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, "top=" + top + ",left=" + left + ",width=600,height=450,location=1,scrollbars=1,status=1,menubar=1,resizable=1");
		crPopupWins[windowName] = openBrowserWindow("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, top, left, $(window).width() * 0.50,  $(window).height() * 0.65);
		$( "#crbutton_" + item.vendorID ).attr( "src",  CDN_PATH + "/checkpricessel.gif");
		crPopupWins[windowName].focus();
		chargeVendor(item.vendorID, clID);
		
		// Determine vendors to view
		if (vendorsToView > 0)
			vendorsToView--;
				
		if (vendorsToView == 1)
			$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
		else if (vendorsToView == 0)
			$( "#vendorNumberText" ).css("display", "none");
		else
			$("#vendorNumberText").html("You have " + vendorsToView + " more sites to check");
	});
	
	return true;
}

function setPopupSelection()
{
	// Reset checkedVendors value if we change vendors checked
	vendorsToView = -1;
	
	$("input:checkbox").each ( 
		function(index) {
			
			var vendorID = $(this).val();
			if ($(this)[0].checked)
				$("#vendor_"+vendorID).css("display", "block");
			else
				$("#vendor_"+vendorID).css("display", "none");
			
	});
	return true;
}

function updateCruiseLineList()
{
	// If selection path is cruise line then do not populate cruise line drop down
	if (crSelectionPath == 2)
		return true;
	else
		crSelectionPath = 1;
	
	// Get destination if it exists
	var destID = $("#crDestList").val();

	// Get destination if it exists
	var cSection = $("#cSection").val();

	// Setup data to send to ajax call
	var dataToSend = "destID=" + escape(destID) + "&section=" + escape(cSection);

	// Make ajax call with info
	var clArray = new Array;
	$.ajax(
	{
		url: '/ajax/ajx_getCRDestCruiseLines.php',
  		dataType: 'text',
  		//dataType: 'json',
  		data: dataToSend,
		async:   true,
  		success: function(data) 
		{
			clArray = eval("(" + data + ")");

			// Clear out cruise line list in order to repopulate with valid cruise lines
			$("#crCruiseLine option").remove();
			$("#crCruiseLine").append( $('<option></option>').val("").html("Any Cruise Line") );
	
			// Add valid cruise lines to list
			$.each(clArray,
				function()
				{
					$("#crCruiseLine").append(  $('<option></option>').val(this.id).html(this.name) );
				}
			);
	
			// Set cruiseline to Any Cruise Line
			$("#crCruiseLine").val("");
		}
	});
	
	return true;
}

function updateDestList()
{
	// If selection path is cruise line then do not populate cruise line drop down
	if (crSelectionPath == 1)
		return true;
	else
		crSelectionPath = 2;

	// Get cruiseline if it exists
	var cruiseLineID = $("#crCruiseLine").val();

	// Get destination if it exists
	var cSection = $("#cSection").val();

	// Setup data to send to ajax call
	var dataToSend = "cruiseLineID=" + escape(cruiseLineID) + "&section=" + escape(cSection);

	// Make ajax call with info
	var destArray = new Array;
	$.ajax(
	{
		url: '/ajax/ajx_getCRDestCruiseLines.php',
  		dataType: 'text',
  		//dataType: 'json',
  		data: dataToSend,
		async:   true,
  		success: function(data) 
		{
			destArray = eval("(" + data + ")");
			
			// Clear out destination list in order to repopulate with valid destinations
			$("#crDestList option").remove();
			$("#crDestList").append( $('<option></option>').val("").html("Any Destination") );
	
			// Add valid destinations to list
			$.each(destArray,
				function()
				{
					$("#crDestList").append(  $('<option></option>').val(this.id).html(this.name) );
				}
			);
	
			// Set cruiseline to Any Destination
			$("#crDestLine").val("");
		}
	});

	return true;
}

function getChargedVendors()
{
	// Get current list of cookies
	var cookieArray = getCookiesArray();
	var chargedVendors = "";
	
	for(var name in cookieArray) {
		
		// Create current charged vendors list
		if (strstr(name, "ccvendor", false)) {
			chargedVendors += str_replace("ccvendor", "", name) + "|";
		}
	}	
	
	return chargedVendors;
}

function openVendorWindows300()
{

	// Set waiting screen
	$("#vendors300").css("display","none");  						   
	$("#loadingVendors").css("display","block");  						   

	// Add GA event
	trackEvent("CheckRates", "cpClick", 0, true);

	// Get month selected
	var dateSelected = $("#crCruiseDate").val();
	
	// Get cruiseline if it exists
	var clID = $("#crCruiseLine").val();

	// destinations
	var destID = $("#crDestList").val();

	// Charged Vendors
	var chargedVendors = $("#cVendors").val();
	//var chargedVendors = getChargedVendors();

	// Check Rates section if it exists
	var cSection = $("#cSection").val();

	// Setup data to send to ajax call
	var dataToSend = "vendors=&date=" + escape(dateSelected) + "&clID=" + escape(clID) + "&destID=" + escape(destID) + "&section=" + escape(cSection) + "&cVendors=" + escape(chargedVendors) + "&useVCM=1" + "&ipAddress=" + escape(ip);

	// Make ajax call with info
	var vendorArray = new Array;
	$.ajax(
	{
		url: '/ajax/ajx_getCheckRateVendors.php',
  		dataType: 'text',
  		//dataType: 'json',
  		data: dataToSend,
		async:   false,
  		success: function(data) 
		{
			vendorArray = eval("(" + data + ")");
			//vendorArray = data;
		}
	});

	// Loop through each vendor now that we have
	//var top = 300;
	//var left = 500;
	//var top = 600;
	var top = $(window).height() * 0.50;
	var left = 0;
	var winHeight = $(window).height() * 0.75;
	var winWidth = $(window).width() * 0.33;
	
	// Try to open up all the popups 1st to see if a popup blocker is enabled
	var windowName = "";
	var maxWindows = 0;
	var crWinArray = new Array();
	var lastOpenedWinName = "";
	var reOpenedWindow = false;
	vendorsToView = -1;
	
	// Get vendor number and clear out the old list if it exists
	$("#crVendorList").empty();
	var vendorsChecked = 0;

	$.each(vendorArray, 
		function(i, item) 
		{
			vendorsChecked++;
			var html = "<div id='vendor_" + i + "' onMouseUp='openIndividualVendor300(\"" + i + "\");'> <a class='plain' href='#'><img id='crbutton_" + i + "' src='" + CDN_PATH + "/checkprices.gif' class='crbutton2' /><span class='crVendorName'>" + item.name + "</span></a></div>";
			$("#crVendorList").append(html);
		}
	);
	$("#vendorNumberText").css("display", "block");
	if (vendorsToView == -1) {
		vendorsToView = vendorsChecked;
		
		if (vendorsToView == 1)
			$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
		else if (vendorsToView == 0)
			$( "#vendorNumberText" ).css("display", "none");
		else
			$("#vendorNumberText").html("You have " + vendorsToView + " more sites to check");
	}
	
	$.each(vendorArray,
	function(i, item)
	{
		windowName = "win" + i;

		// Check if window was closed previously
		var windowCreated = false;
		if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
			openedAllCRWins = false;
			windowCreated = true;
		}

		// Open up window until we can't open it any more
		//crPopupWins[windowName] = window.open("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, "top=" + top + ",left=" + left + ",width=" + winWidth + ",height=" + winHeight + ",location=1,scrollbars=1,status=1,menubar=1,resizable=1");
		crPopupWins[windowName] = openBrowserWindow("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, top, left, winWidth, winHeight);
		if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
				
			// Put end placeholder in popup blocked window so we can determine where to add the next window in popup array next time we come in here
			crPopupWins[windowName] = "end";	
			popupBlocker = true;

			//top += 25;
			//left += 25;
			left += winWidth;			
				
			return false;   // We found popup blocker so return false to break out of this each and continue on throw rest of function
		}
			
		//top += 25;
		//left += 25;
		// Because IE is so wierd move the window to the right position
		try {
			crPopupWins[windowName].resizeTo(winWidth,winHeight);
			crPopupWins[windowName].moveTo(left,top);
		}
		catch (err) {
			// if you get access denied then don't do anything
		}
		
		left += winWidth;		
		
		crWinArray[maxWindows] = windowName;
		maxWindows++;
		lastOpenedWinName = windowName;
			
		// Only update a window that has not been opened yet
		if ($( "#crbutton_" + item.vendorID ).attr("src") != CDN_PATH + "/checkpricessel.gif") {
			
			// Determine vendors to view
			if (vendorsToView > 0)
				vendorsToView--;
		}
		
		$( "#crbutton_" + item.vendorID ).attr( "src",  CDN_PATH + "/checkpricessel.gif");
		if (vendorsToView == 1)
			$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
		else if (vendorsToView == 0)
			$( "#vendorNumberText" ).css("display", "none");
		else
			$("#vendorNumberText").html("You have " + vendorsToView + " more sites to check");


		// Charge vendor if needed
		chargeVendor(item.vendorID, clID);
	});
	
	// Have we opened all vendor windows once?
	if ( popupBlocker && (maxWindows == vendorsChecked) && !openedAllCRWins) {
		openedAllCRWins = true;
		
		// Check for vendor cookie and set if it doesn't exist
		// Reset position of dialog
		$( "#crIndividualVendors" ).dialog( "open" );
		
		if (lastOpenedWinName != "") {
			crPopupWins[lastOpenedWinName].resizeTo($(window).width() * 0.50, $(window).height());
			crPopupWins[lastOpenedWinName].moveTo(500,$(window).height() * 0.2);
			crPopupWins[lastOpenedWinName].focus();		
		}
			
		reOpenedWindow = true;
	}
		
	// Reverse order of focus so #1 vendor is on top if we've already opened up all windows
	if (!openedAllCRWins && !reOpenedWindow) {
		$.each(crWinArray.reverse(),
		function(i, item)
		{
			crPopupWins[item].focus();
		});
	}
	
	if (popupBlocker && openedAllCRWins && !reOpenedWindow) {
		
		// We've already cycled throw all the windows and didn't open a new one
		// Put back original options
		$("#loadingVendors").css("display","none");  						   
		$("#vendors").css("display","block");  			
		
		// Reset position of dialog
		$( "#crIndividualVendors" ).dialog( "open" );
		crPopupWins[lastOpenedWinName].focus();		
	}
	else if (popupBlocker && !reOpenedWindow) {

		// Display box with individual check rate vendors
		// Reset position of dialog
		$( "#crIndividualVendors" ).dialog( "open" );

		
		if (lastOpenedWinName == "") {
			
			// Incase some of the copy already openned the 1st window and we can't open any windows
			vendorsToView++;
			
			if (vendorsToView == 1)
				$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
			else if (vendorsToView == 0)
				$( "#vendorNumberText" ).css("display", "none");
			else
				$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");			
		}
		else {

			// Move and resize window
			crPopupWins[lastOpenedWinName].resizeTo($(window).width() * 0.50, $(window).height());
			crPopupWins[lastOpenedWinName].moveTo(500, $(window).height() * 0.2);
			crPopupWins[lastOpenedWinName].focus();
			
		}
	}

	
	// Put back original options
	$("#loadingVendors").css("display","none");  						   
	$("#vendors300").css("display","block");  			

	return false;
}

function openIndividualVendor300(vendorID)
{
	// Get month selected
	var dateSelected = $("#crCruiseDate").val();
	
	// Get cruiseline if it exists
	var clID = $("#crCruiseLine").val();

	// Get destination if it exists
	var destID = $("#crDestList").val();

	// Get section if it exists
	var section = $("#section").val();

	// Setup data to send to ajax call
	var dataToSend = "vendors=" + escape(vendorID) + "&date=" + escape(dateSelected) + "&clID=" + escape(clID) + "&destID=" + escape(destID) + "&section=" + escape(section) + "&ipAddress=" + escape(ip);

	// Make ajax call with info
	var vendorArray = new Array;
	$.ajax(
	{
		url: '/ajax/ajx_getCheckRateVendors.php',
  		dataType: 'text',
  		//dataType: 'json',
  		data: dataToSend,
		async:   false,
  		success: function(data) 
		{
			vendorArray = eval("(" + data + ")");
			//vendorArray = data;
		}
	});

	var top = $(window).height() * 0.20;
	var left = 500;

	// Make sure that selector is in the right spot
	$("#crIndividualVendors").dialog("options", "position", [1,1]);
	
	$.each(vendorArray,
	function(i, item)
	{
		
		var windowName = "win" + i;
		crPopupWins[windowName] = openBrowserWindow("/checkrates/crvendors.php?dv=" + escape(item.data), windowName,top, left, $(window).width() * 0.50, $(window).height() * 0.65);

		// Only update a window that has not been opened yet
		if ($( "#crbutton_" + item.vendorID ).attr("src") != CDN_PATH + "/checkpricessel.gif") {
			
			// Determine vendors to view
			if (vendorsToView > 0)
				vendorsToView--;
		}
		
		$( "#crbutton_" + item.vendorID ).attr( "src",  CDN_PATH + "/checkpricessel.gif");
		chargeVendor(item.vendorID, clID);
		
		if (vendorsToView == 1)
			$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
		else if (vendorsToView == 0)
			$( "#vendorNumberText" ).css("display", "none");
		else
			$("#vendorNumberText").html("You have " + vendorsToView + " more sites to check");
			
		crPopupWins[windowName].focus();
	});
	
	return false;
}

function openBrowserWindow(url, windowName, top, left, winWidth, winHeight)
{
		return window.open(url, windowName, "top=" + top + ",left=" + left + ",width=" + winWidth + ",height=" + winHeight + ",location=1,scrollbars=1,status=1,menubar=1,resizable=1");
}

function openFACVendorWindows(keyID, cSection, vendorList, clID, shipID, destID, dateSelected)
{

	// Set waiting screen
	$("#checkRatesButton2_" + keyID).css("display","none");  		
	$("#NoVendors_" + keyID).css("display", "none");	
	$("#loadingVendors_" + keyID).css("display","block");  						   

	// Charged Vendors
	var chargedVendors = vendorList;

	// Setup data to send to ajax call
	var dataToSend = "vendors=&date=" + escape(dateSelected) + "&clID=" + escape(clID) + "&shipID=" + escape(shipID) + "&destID=" + escape(destID) + "&section=" + escape(cSection) + "&cVendors=" + escape(chargedVendors) + "&useVCM=1" + "&ipAddress=" + escape(ip);

	// Make ajax call with info
	var vendorArray = new Array;
	$.ajax(
	{
		url: '/ajax/ajx_getCheckRateVendors.php',
  		dataType: 'text',
  		//dataType: 'json',
  		data: dataToSend,
		async:   false,
  		success: function(data) 
		{
			vendorArray = eval("(" + data + ")");
			//vendorArray = data;
		}
	});

	// Loop through each vendor now that we have
	var top = $(window).height() * 0.50;
	var left = 0;
	var winHeight = $(window).height() * 0.75;
	var winWidth = $(window).width() * 0.33;
	
	// Try to open up all the popups 1st to see if a popup blocker is enabled
	var windowName = "";
	var maxWindows = 0;
	var crWinArray = new Array();
	var lastOpenedWinName = "";
	var reOpenedWindow = false;
	vendorsToView = -1;
	
	// Get vendor number and clear out the old list if it exists
	$("#crVendorList").empty();
	var vendorsChecked = 0;

	$.each(vendorArray, 
		function(i, item) 
		{
			vendorsChecked++;
			var html = "<div id='vendor_" + i + "' onMouseUp='openFACIndividualVendor(\"" + i + "\", \"" + cSection + "\", " + clID + ", " + shipID + ", " + destID + ", \"" + dateSelected + "\");'> <a class='plain' href='#'><img id='crbutton_" + i + "' src='" + CDN_PATH + "/checkprices.gif' class='crbutton2' /><span class='crVendorName'>" + item.name + "</span></a></div>";
			$("#crVendorList").append(html);
		}
	);
	$("#vendorNumberText").css("display", "block");
	if (vendorsToView == -1) {
		vendorsToView = vendorsChecked;
		
		if (vendorsToView == 1)
			$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
		else if (vendorsToView == 0)
			$( "#vendorNumberText" ).css("display", "none");
		else
			$("#vendorNumberText").html("You have " + vendorsToView + " more sites to check");
	}
	
	$.each(vendorArray,
	function(i, item)
	{
		windowName = "win" + i;

		// Check if window was closed previously
		var windowCreated = false;
		if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
			openedAllCRWins = false;
			windowCreated = true;
		}

		// Open up window until we can't open it any more
		crPopupWins[windowName] = openBrowserWindow("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, top, left, winWidth, winHeight);
		if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
				
			// Put end placeholder in popup blocked window so we can determine where to add the next window in popup array next time we come in here
			crPopupWins[windowName] = "end";	
			popupBlocker = true;

			left += winWidth;			
				
			return false;   // We found popup blocker so return false to break out of this each and continue on throw rest of function
		}
			
		// Because IE is so wierd move the window to the right position
		try {
			crPopupWins[windowName].resizeTo(winWidth,winHeight);
			crPopupWins[windowName].moveTo(left,top);
		}
		catch (err) {
			// if you get access denied then don't do anything
		}
		
		left += winWidth;		
		
		crWinArray[maxWindows] = windowName;
		maxWindows++;
		lastOpenedWinName = windowName;
			
		// Only update a window that has not been opened yet
		if ($( "#crbutton_" + item.vendorID ).attr("src") != CDN_PATH + "/checkpricessel.gif") {
			
			// Determine vendors to view
			if (vendorsToView > 0)
				vendorsToView--;
		}
		
		$( "#crbutton_" + item.vendorID ).attr( "src",  CDN_PATH + "/checkpricessel.gif");
		if (vendorsToView == 1)
			$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
		else if (vendorsToView == 0)
			$( "#vendorNumberText" ).css("display", "none");
		else
			$("#vendorNumberText").html("You have " + vendorsToView + " more sites to check");


		// Charge vendor if needed
		chargeVendor(item.vendorID, clID);
	});
	
	// Have we opened all vendor windows once?
	if ( popupBlocker && (maxWindows == vendorsChecked) && !openedAllCRWins) {
		openedAllCRWins = true;
		
		// Check for vendor cookie and set if it doesn't exist
		// Reset position of dialog
		$( "#crIndividualVendors" ).dialog( "open" );
		
		if (lastOpenedWinName != "") {
			crPopupWins[lastOpenedWinName].resizeTo($(window).width() * 0.50, $(window).height());
			crPopupWins[lastOpenedWinName].moveTo(500,$(window).height() * 0.2);
			crPopupWins[lastOpenedWinName].focus();		
		}
			
		reOpenedWindow = true;
	}
		
	// Reverse order of focus so #1 vendor is on top if we've already opened up all windows
	if (!openedAllCRWins && !reOpenedWindow) {
		$.each(crWinArray.reverse(),
		function(i, item)
		{
			crPopupWins[item].focus();
		});
	}
	
	if (popupBlocker && openedAllCRWins && !reOpenedWindow) {
		
		// We've already cycled throw all the windows and didn't open a new one
		// Put back original options
		$("#loadingVendors_" + keyID).css("display","none");  						   
		$("#checkRatesButton2_" + keyID).css("display","block");  			
		
		// Reset position of dialog
		$( "#crIndividualVendors" ).dialog( "open" );
		crPopupWins[lastOpenedWinName].focus();		
	}
	else if (popupBlocker && !reOpenedWindow) {

		// Display box with individual check rate vendors
		// Reset position of dialog
		$( "#crIndividualVendors" ).dialog( "open" );

		
		if (lastOpenedWinName == "") {
			
			// Incase some of the copy already openned the 1st window and we can't open any windows
			vendorsToView++;
			
			if (vendorsToView == 1)
				$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
			else if (vendorsToView == 0)
				$( "#vendorNumberText" ).css("display", "none");
			else
				$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");			
		}
		else {

			// Move and resize window
			crPopupWins[lastOpenedWinName].resizeTo($(window).width() * 0.50, $(window).height());
			crPopupWins[lastOpenedWinName].moveTo(500, $(window).height() * 0.2);
			crPopupWins[lastOpenedWinName].focus();
			
		}
	}

	
	// Put back original options
	$("#loadingVendors_" + keyID).css("display","none");  						   
	$("#checkRatesButton2_" + keyID).css("display","block");  	
	
	if (vendorsChecked == 0)
		$("#NoVendors_" + keyID).css("display", "block");

	return false;
}

function openFACIndividualVendor(vendorID, cSection, clID, shipID, destID, dateSelected)
{
	// Setup data to send to ajax call
	var dataToSend = "vendors=" + escape(vendorID) + "&date=" + escape(dateSelected) + "&clID=" + escape(clID) + "&shipID=" + escape(shipID) + "&destID=" + escape(destID) + "&section=" + escape(cSection) + "&ipAddress=" + escape(ip);

	// Make ajax call with info
	var vendorArray = new Array;
	$.ajax(
	{
		url: '/ajax/ajx_getCheckRateVendors.php',
  		dataType: 'text',
  		//dataType: 'json',
  		data: dataToSend,
		async:   false,
  		success: function(data) 
		{
			vendorArray = eval("(" + data + ")");
			//vendorArray = data;
		}
	});

	var top = $(window).height() * 0.20;
	var left = 500;

	// Make sure that selector is in the right spot
	$("#crIndividualVendors").dialog("options", "position", [1,1]);
	
	$.each(vendorArray,
	function(i, item)
	{
		
		var windowName = "win" + i;
		crPopupWins[windowName] = openBrowserWindow("/checkrates/crvendors.php?dv=" + escape(item.data), windowName,top, left, $(window).width() * 0.50, $(window).height() * 0.65);

		// Only update a window that has not been opened yet
		if ($( "#crbutton_" + item.vendorID ).attr("src") != CDN_PATH + "/checkpricessel.gif") {
			
			// Determine vendors to view
			if (vendorsToView > 0)
				vendorsToView--;
		}
		
		$( "#crbutton_" + item.vendorID ).attr( "src",  CDN_PATH + "/checkpricessel.gif");
		chargeVendor(item.vendorID, clID);
		
		if (vendorsToView == 1)
			$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
		else if (vendorsToView == 0)
			$( "#vendorNumberText" ).css("display", "none");
		else
			$("#vendorNumberText").html("You have " + vendorsToView + " more sites to check");
			
		crPopupWins[windowName].focus();
	});
	
	return false;
}

function openHoverWindows(itinID, section)
{
	// Stupid accordian fix for IE
	if ($.browser.msie) {
		$("input[name='vendors" + itinID + "']").css('zoom', '1');
		$(".vendorSpacer-300").css('zoom', '1');
	}

	// Determine if any vendor selected
	var vendorsChecked = $("input:checked[name='vendors" + itinID + "']").length;
	
	if(vendorsChecked == 0) {
		$("#selectVendor" + itinID).css("display", "block");
		return false;
	}
	else if (vendorsChecked == 1) {

		// Let's loosely couple this and handle it separately since 1 vendor window needs to be positioned different
		openOneHoverWindow(itinID, section);
		return true;
	}
	else
		$("#selectVendor" + itinID).css("display", "none");

	// Add GA event
	trackEvent("CheckRates", "cpClick", 0, true);

	// Setup any defaults
	$("#vendorNumberText").css("display", "block");
	vendorsToView = vendorsChecked - 1;
		
	if (vendorsToView == 1)
		$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
	else
		$("#vendorNumberText").html("You have " + vendorsToView + " more sites to check");
	
	// Set waiting screen
	$("#vendors").css("display","none");  						   
	$("#loadingVendors").css("display","block");  						   

	// We've got vendors so let's get all the values
	var checkedVendors = "";

	// Setup popup blocker window counts
	$("#vendorNumber" + itinID).html(vendorsChecked - 1);
	$("input:checked[name='vendors" + itinID + "']").each ( 
		function(index) {
			
			checkedVendors = checkedVendors + $(this).val() + "|";
			
			// Reset the images to "unchecked status" on popup blocker layer if window isn't open
			windowName = "win" + $(this).val();
			if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
				$( "#crbutton_" + $(this).val() ).attr( "src",  CDN_PATH + "/checkprices.gif");
				
				// Since we've closed the window increase the vendorsToView amount
				if (vendorsToView < (vendorsChecked-1))
					vendorsToView++;
			}
			else {
				
				// Determine vendors to view
				if (vendorsToView > 0)
					vendorsToView--;
				
				if (vendorsToView == 1)
					$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
				else if (vendorsToView == 0)
					$( "#vendorNumberText").css("display", "none");
				else
					$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
			}
		}
	);

	// Get month selected
	var dateSelected = $("#cruiseDate" + itinID).val();
	
	// Get cruiseline if it exists
	var clID = $("#cruiselineID" + itinID).val();

	// Get shipID if it exists
	var shipID = $("#shipID" + itinID).val();
	
	// destinations
	var destID = $("#destID" + itinID).val();

	// section
	if (section == "")
		section = $("#section").val();

	// Setup data to send to ajax call
	var dataToSend = "vendors=" + escape(checkedVendors) + "&date=" + escape(dateSelected) + "&clID=" + escape(clID) + "&shipID=" + escape(shipID) + "&destID=" + escape(destID) + "&section=" + escape(section) + "&ipAddress=" + escape(ip);
	
	// Make ajax call with info
	var vendorArray = new Array;
	var checkedVendorArray = new Array;
	checkedVendorArray = checkedVendors.split('|');
	checkedVendorArray.pop(); // Remove empty last element
	var firstTime = true;
	$.ajax(
	{
		url: '/ajax/ajx_getCheckRateVendors.php',
  		dataType: 'text',
  		//dataType: 'json',
  		data: dataToSend,
		async:   false,
  		success: function(data) 
		{
			vendorArray = eval("(" + data + ")");
			//vendorArray = data;
			
			// TODO: Need to revisit returning this as dataType: json instead of text
			// Do this ugly loop for now as eval is reordering the returned json 
			$.each(checkedVendorArray,
			function(i,chVendorID)
			{
				// Setup check rate popup
				$.each(vendorArray,
				function(j, item)
				{
					if (item.vendorID == chVendorID) {
					
						if (firstTime) {
							$("#crVendorList").html('<div id="vendor_' + item.vendorID + '"><a class="plain" href="javascript:void(0)" onMouseUp="return openIndividualHoverVendor(' + item.vendorID + ', \'' + itinID + '\')"><img id="crbutton_' + item.vendorID + '" src="' + CDN_PATH + '/checkpricessel.gif" class="crbutton2" /><span style="margin-left: 10px; position: relative; top: -8px;">' + item.name + '</span></a></div>');
							firstTime = false;
						}
						else {
							$("#crVendorList").append('<div id="vendor_' + item.vendorID + '"><a class="plain" href="javascript:void(0)" onMouseUp="return openIndividualHoverVendor(' + item.vendorID + ', \'' + itinID + '\')"><img id="crbutton_' + item.vendorID + '" src="' + CDN_PATH + '/checkprices.gif" class="crbutton2" /><span style="margin-left: 10px; position: relative; top: -8px;">' + item.name + '</span></a></div>');

						}
						
						return true;
					}
				});
			});
		}
	});
	
	// Loop through each vendor now that we have
//	var top = 100 + (25*vendorsChecked);
//	var left = 500 + (25*vendorsChecked);
	//var top = $(window).height() * 0.50;
	var top = 0;
	var left = 0;
	var ratio = 16;
	
	var winHeight = $(window).height() * 0.75;
	var winWidth = $(window).width() * 0.60;
	
	// Try to open up all the popups 1st to see if a popup blocker is enabled
	var windowName = "";
	var maxWindows = 0;
	var crWinArray = new Array();
	var lastOpenedWinName = "";
	var reOpenedWindow = false;

	$.each(checkedVendorArray,
	function(i, chVendorID)
	{
		windowName = "win" + chVendorID;

		// Check if window was closed previously
		var windowCreated = false;
		if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
			openedAllCRWins = false;
			windowCreated = true;
		}

		// TODO: Need to revisit returning this as dataType: json instead of text
		// Do this ugly loop for now as eval is reordering the returned json 	
		// Look for vendor info we need
		var item = "";
		$.each(vendorArray,
		function(j, vendorItem)
		{
			if (vendorItem.vendorID == chVendorID) {
				item = vendorItem;					
				return true;
			}
		});
		
		// Open up window until we can't open it any more
		crPopupWins[windowName] = openBrowserWindow("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, top, left, winWidth, winHeight);
		
		if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
				
			// Put end placeholder in popup blocked window so we can determine where to add the next window in popup array next time we come in here
			crPopupWins[windowName] = "end";	
			popupBlocker = true;

			//left += winWidth;
			top += winHeight/ratio;
			left += winWidth/ratio;
				
			return false;   // We found popup blocker so return false to break out of this each and continue on through rest of function
		}
			
//		top += 25;
//		left += 25;

		// Because IE is so wierd move the window to the right position
		try {
			crPopupWins[windowName].resizeTo(winWidth,winHeight);
			crPopupWins[windowName].moveTo(left,top);
		}
		catch (err) {
			// if you get access denied then don't do anything
		}
		
		//left += winWidth;
		top += winHeight/ratio;
		left += winWidth/ratio;
		
		crWinArray[maxWindows] = windowName;
		maxWindows++;

		// Set button to selected
		$( "#crbutton_" + item.vendorID ).attr( "src",  CDN_PATH + "/checkpricessel.gif");

		// Keep track of last window
		if (windowCreated) {
			lastOpenedWinName = windowName;
		}

		// Charge vendor if needed
		chargeVendor(item.vendorID, clID);
	});
	
	
	
	// Have we opened all vendor windows once?
	if ( popupBlocker && (maxWindows == vendorsChecked) && !openedAllCRWins) {
		openedAllCRWins = true;
		
		// Check for vendor cookie and set if it doesn't exist
		$( "#crIndividualVendors").dialog( "open" );
		
		if (lastOpenedWinName != "") {
			
			try {
				crPopupWins[lastOpenedWinName].resizeTo($(window).width() * 0.50, $(window).height() * 0.80);
				crPopupWins[lastOpenedWinName].moveTo(500,$(window).height() * 0.20);
				crPopupWins[lastOpenedWinName].focus();		
			}
			catch (err) {
				// if you get access denied then don't do anything
			}
		
		
		}
			
		reOpenedWindow = true;
	}
		
	// Reverse order of focus so #1 vendor is on top if we've already opened up all windows
	if (!openedAllCRWins && !reOpenedWindow) {
		$.each(crWinArray.reverse(),
		function(i, item)
		{
			crPopupWins[item].focus();
		});
	}
	
	if (popupBlocker && openedAllCRWins && !reOpenedWindow) {
		
		// We've already cycled throw all the windows and didn't open a new one
		// Put back original options
		$("#loadingVendors").css("display","none");  						   
		$("#vendors").css("display","block");  			
		$( "#crIndividualVendors").dialog( "open" );		
	}
	else if (popupBlocker && !reOpenedWindow) {

		// Display box with individual check rate vendors
		$( "#crIndividualVendors").dialog( "open" );
		
		if (lastOpenedWinName == "") {
			
			// Incase some of the copy already openned the 1st window and we can't open any windows
			vendorsToView++;
			
			if (vendorsToView == 1)
				$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
			else if (vendorsToView == 0)
				$( "#vendorNumberText").css("display", "none");
			else
				$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");			
		}
		else {
			
			try {

				// Move and resize window
				crPopupWins[lastOpenedWinName].resizeTo($(window).width() * 0.50,  $(window).height() * 0.80);
				crPopupWins[lastOpenedWinName].moveTo(500,$(window).height() * 0.20);
				crPopupWins[lastOpenedWinName].focus();
			}
			catch (err) {
				// if you get access denied then don't do anything
			}
			
		}
	}
	
	// Put back original options
	$("#loadingVendors").css("display","none");  						   
	$("#vendors").css("display","block");  			

	return false;
}

function openOneHoverWindow(itinID, section)
{
	$("#selectVendor" + itinID).css("display", "none");
	
	// Add GA event
	trackEvent("CheckRates", "cpClick", 0, true);

	// Setup any defaults
	$("#vendorNumberText").css("display", "block");
	if (vendorsToView == -1) {
		vendorsToView = 0;
		$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
	}
	
	// Set waiting screen
	$("#vendors").css("display","none");  						   
	$("#loadingVendors").css("display","block");  						   

	// We've got vendors so let's get all the values
	var checkedVendors = "";

	// Setup popup blocker window counts
	$("#vendorNumber").html(0);
	$("input:checked[name='vendors" + itinID + "']").each ( 
		function(index) {
			
			checkedVendors = checkedVendors + $(this).val() + "|";
			
			// Reset the images to "unchecked status" on popup blocker layer if window isn't open
			windowName = "win" + $(this).val();
			if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
				$( "#crbutton_" + $(this).val() ).attr( "src",  CDN_PATH + "/checkprices.gif");
				
				// Since we've closed the window increase the vendorsToView amount
				if (vendorsToView < 0)
					vendorsToView++;
			}
			else {
				
				// Determine vendors to view
				if (vendorsToView > 0)
					vendorsToView--;
				
				if (vendorsToView == 1)
					$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
				else if (vendorsToView == 0)
					$( "#vendorNumberText").css("display", "none");
				else
					$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
			}
		}
	);

	// Get month selected
	var dateSelected = $("#cruiseDate" + itinID).val();
	
	// Get cruiseline if it exists
	var clID = $("#cruiselineID" + itinID).val();

	// Get shipID if it exists
	var shipID = $("#shipID" + itinID).val();
	
	// destinations
	var destID = $("#destID" + itinID).val();

	// section
	if (section == "")
		section = $("#section").val();

	// Setup data to send to ajax call
	var dataToSend = "vendors=" + escape(checkedVendors) + "&date=" + escape(dateSelected) + "&clID=" + escape(clID) + "&shipID=" + escape(shipID) + "&destID=" + escape(destID) + "&section=" + escape(section) + "&ipAddress=" + escape(ip);

	// Make ajax call with info
	var vendorArray = new Array;
	$.ajax(
	{
		url: '/ajax/ajx_getCheckRateVendors.php',
  		dataType: 'text',
  		//dataType: 'json',
  		data: dataToSend,
		async:   false,
  		success: function(data) 
		{
			vendorArray = eval("(" + data + ")");
			//vendorArray = data;
		}
	});

	// Setup one window positioning
	var top = 125;
	var left = 525;
	//var width = 600;
	//height = 450;
	var winHeight = $(window).height() * 0.75;
	var winWidth = $(window).width() * 0.5;	
	
	// Try to open up all the popups 1st to see if a popup blocker is enabled
	var windowName = "";
	var maxWindows = 0;
	var crWinArray = new Array();
	var lastOpenedWinName = "";
	var reOpenedWindow = false;
	
	$.each(vendorArray,
	function(i, item)
	{
		windowName = "win" + i;

		// Check if window was closed previously
		var windowCreated = false;
		if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
			openedAllCRWins = false;
			windowCreated = true;
		}

		// Open up window until we can't open it any more
//		crPopupWins[windowName] = window.open("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, "top=" + top + ",left=" + left + ",width=" + width + ",height=" + height + ",location=1,scrollbars=1,status=1,menubar=1,resizable=1");
		crPopupWins[windowName] = openBrowserWindow("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, top, left, winWidth, winHeight);
		if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
				
			// Put end placeholder in popup blocked window so we can determine where to add the next window in popup array next time we come in here
			crPopupWins[windowName] = "end";	
			popupBlocker = true;

			return false;   // We found popup blocker so return false to break out of this each and continue on through rest of function
		}
			
		crWinArray[maxWindows] = windowName;
		maxWindows++;

		// Set button to selected
		$( "#crbutton_" + item.vendorID ).attr( "src",  CDN_PATH + "/checkpricessel.gif");

		// Keep track of last window
		if (windowCreated) {
			lastOpenedWinName = windowName;
		}

		// Charge vendor if needed
		chargeVendor(item.vendorID, clID);
	});
	
	// Have we opened all vendor windows once?
	if ( popupBlocker && (maxWindows == 1) && !openedAllCRWins) {
		openedAllCRWins = true;
		
		// Check for vendor cookie and set if it doesn't exist
		$( "#crIndividualVendors").dialog( "open" );
		
		if (lastOpenedWinName != "") {
			crPopupWins[lastOpenedWinName].focus();		
		}
			
		reOpenedWindow = true;
	}
		
	// Reverse order of focus so #1 vendor is on top if we've already opened up all windows
	if (!openedAllCRWins && !reOpenedWindow) {
		$.each(crWinArray.reverse(),
		function(i, item)
		{
			crPopupWins[item].focus();
		});
	}
	
	if (popupBlocker && openedAllCRWins && !reOpenedWindow) {
		
		// We've already cycled throw all the windows and didn't open a new one
		// Put back original options
		$("#loadingVendors").css("display","none");  						   
		$("#vendors").css("display","block");  			
		$( "#crIndividualVendors").dialog( "open" );		
	}
	else if (popupBlocker && !reOpenedWindow) {

		// Display box with individual check rate vendors
		$( "#crIndividualVendors").dialog( "open" );
		
		if (lastOpenedWinName == "") {
			
			// Incase some of the copy already openned the 1st window and we can't open any windows
			vendorsToView++;
			
			if (vendorsToView == 1)
				$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
			else if (vendorsToView == 0)
				$( "#vendorNumberText").css("display", "none");
			else
				$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");			
		}
		else
			crPopupWins[lastOpenedWinName].focus();
	}
	
	// Put back original options
	$("#loadingVendors").css("display","none");  						   
	$("#vendors").css("display","block");  			

	return false;
}

function openIndividualHoverVendor(vendorID, itinID)
{
	// Get month selected
	var dateSelected = $("#cruiseDate" + itinID).val();
	
	// Get cruiseline if it exists
	var clID = $("#cruiselineID" + itinID).val();

	// Get shipID if it exists
	var shipID = $("#shipID" + itinID).val();

	// Get destination if it exists
	var destID = $("#destID" + itinID).val();

	// Get section if it exists
	var section = $("#section").val();

	// Setup data to send to ajax call
	var dataToSend = "vendors=" + escape(vendorID) + "&date=" + escape(dateSelected) + "&clID=" + escape(clID) + "&shipID=" + escape(shipID) + "&destID=" + escape(destID) + "&section=" + escape(section) + "&ipAddress=" + escape(ip);

	// Make ajax call with info
	var vendorArray = new Array;
	$.ajax(
	{
		url: '/ajax/ajx_getCheckRateVendors.php',
  		dataType: 'text',
  		//dataType: 'json',
  		data: dataToSend,
		async:   false,
  		success: function(data) 
		{
			vendorArray = eval("(" + data + ")");
			//vendorArray = data;
		}
	});

	var top = $(window).height() * 0.20;
	var left = 500;
	
	$.each(vendorArray,
	function(i, item)
	{
		
		var windowName = "win" + i;
		//crPopupWins[windowName] = window.open("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, "top=" + top + ",left=" + left + ",width=600,height=450,location=1,scrollbars=1,status=1,menubar=1,resizable=1");
		crPopupWins[windowName] = openBrowserWindow("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, top, left, $(window).width() * 0.50,  $(window).height() * 0.65);
		$( "#crbutton_" + item.vendorID ).attr( "src",  CDN_PATH + "/checkpricessel.gif");
		crPopupWins[windowName].focus();
		chargeVendor(item.vendorID, clID);
		
		// Determine vendors to view
		if (vendorsToView > 0)
			vendorsToView--;
				
		if (vendorsToView == 1)
			$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
		else if (vendorsToView == 0)
			$( "#vendorNumberText").css("display", "none");
		else
			$("#vendorNumberText").html("You have " + vendorsToView + " more sites to check");
	});
	
	return true;
}


function openLandingWindows()
{
	// Determine if any vendor selected
	var vendorsChecked = $("input:checked[name='vendors']").length;
	
	if(vendorsChecked == 0) {
		$("#selectVendor").css("display", "block");
		return false;
	}
	else if (vendorsChecked == 1) {
		
		// Let's loosely couple this and handle it separately since 1 vendor window needs to be positioned different
		openOneLandingWindow();
		return true;
	}
	else
		$("#selectVendor").css("display", "none");
		
	// Add GA event
	trackEvent("CheckRates", "cpClick", 0, true);		

	// Setup any defaults
	$("#vendorNumberText").css("display", "block");
	if (vendorsToView == -1) {
		vendorsToView = vendorsChecked - 1;
		
		if (vendorsToView == 1)
			$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
		else
			$("#vendorNumberText").html("You have " + vendorsToView + " more sites to check");
	}
	
	// Set waiting screen
	$("#vendorItems").css("display","none");  						   
	$("#loadingVendors").css("display","block");  						   

	// We've got vendors so let's get all the values
	var checkedVendors = "";

	// Setup popup blocker window counts
	$("#vendorNumber").html(vendorsChecked - 1);
	$("input:checked[name='vendors']").each ( 
		function(index) {
			
			checkedVendors = checkedVendors + $(this).val() + "|";
			
			// Reset the images to "unchecked status" on popup blocker layer if window isn't open
			windowName = "win" + $(this).val();
			if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
				$( "#crbutton_" + $(this).val() ).attr( "src",  CDN_PATH + "/checkprices.gif");
				
				// Since we've closed the window increase the vendorsToView amount
				if (vendorsToView < (vendorsChecked-1))
					vendorsToView++;
			}
			else {
				
				// Determine vendors to view
				if (vendorsToView > 0)
					vendorsToView--;
				
				if (vendorsToView == 1)
					$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
				else if (vendorsToView == 0)
					$( "#vendorNumberText").css("display", "none");
				else
					$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
			}
		}
	);

	// Get month selected
	var dateSelected = $("#startDate").val();
	
	// Get cruiseline if it exists
	var clID = $("#cl").val();

	// destinations
	var destID = $("#port").val();

	// departure city
	var depCityID = $("#depcity").val();

	// departure city
	var section = $("#section").val();

	// Setup data to send to ajax call
	var dataToSend = "vendors=" + escape(checkedVendors) + "&date=" + escape(dateSelected) + "&clID=" + escape(clID) + "&destID=" + escape(destID) + "&depCityID=" + escape(depCityID) + "&section=" + escape(section) + "&ipAddress=" + escape(ip);

	// Make ajax call with info
	var vendorArray = new Array;
	var firstTime = true;
	$.ajax(
	{
		url: '/ajax/ajx_getCheckRateVendors.php',
  		dataType: 'text',
  		//dataType: 'json',
  		data: dataToSend,
		async:   false,
  		success: function(data) 
		{
			vendorArray = eval("(" + data + ")");
			//vendorArray = data;
			
			// Setup check rate popup
			$.each(vendorArray,
			function(i, item)
			{
				if (firstTime) {
					$("#crVendorList").html('<div id="vendor_' + item.vendorID + '"><a class="plain" href="#" onMouseUp="return openIndividualLandingVendor(' + item.vendorID + ')"><img id="crbutton_' + item.vendorID + '" src="' + CDN_PATH + '/checkpricessel.gif" class="crbutton2" /><span style="margin-left: 10px; position: relative; top: -8px;">' + item.name + '</span></a></div>');
					firstTime = false;
				}
				else {
					$("#crVendorList").append('<div id="vendor_' + item.vendorID + '"><a class="plain" href="#" onMouseUp="return openIndividualLandingVendor(' + item.vendorID + ')"><img id="crbutton_' + item.vendorID + '" src="' + CDN_PATH + '/checkprices.gif" class="crbutton2" /><span style="margin-left: 10px; position: relative; top: -8px;">' + item.name + '</span></a></div>');
				}
			});
		}
	});

	// Loop through each vendor now that we have
//	var top = 100 + (25*vendorsChecked);
//	var left = 500 + (25*vendorsChecked);
	//var top = $(window).height() * 0.50;
	var top = 0;
	var left = 0;
	var ratio = 16;
	
	var winHeight = $(window).height() * 0.75;
	var winWidth = $(window).width() * 0.60;
	
	// Try to open up all the popups 1st to see if a popup blocker is enabled
	var windowName = "";
	var maxWindows = 0;
	var crWinArray = new Array();
	var lastOpenedWinName = "";
	var reOpenedWindow = false;
	
	$.each(vendorArray,
	function(i, item)
	{
		windowName = "win" + i;

		// Check if window was closed previously
		var windowCreated = false;
		if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
			openedAllCRWins = false;
			windowCreated = true;
		}

		// Open up window until we can't open it any more
		crPopupWins[windowName] = openBrowserWindow("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, top, left, winWidth, winHeight);
		
		if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
				
			// Put end placeholder in popup blocked window so we can determine where to add the next window in popup array next time we come in here
			crPopupWins[windowName] = "end";	
			popupBlocker = true;

			//left += winWidth;
			top += winHeight/ratio;
			left += winWidth/ratio;
				
			return false;   // We found popup blocker so return false to break out of this each and continue on through rest of function
		}
			
//		top += 25;
//		left += 25;

		// Because IE is so wierd move the window to the right position
		try {
			crPopupWins[windowName].resizeTo(winWidth,winHeight);
			crPopupWins[windowName].moveTo(left,top);
		}
		catch (err) {
			// if you get access denied then don't do anything
		}
		
		//left += winWidth;
		top += winHeight/ratio;
		left += winWidth/ratio;
		
		crWinArray[maxWindows] = windowName;
		maxWindows++;

		// Set button to selected
		$( "#crbutton_" + item.vendorID ).attr( "src",  CDN_PATH + "/checkpricessel.gif");

		// Keep track of last window
		if (windowCreated) {
			lastOpenedWinName = windowName;
		}

		// Charge vendor if needed
		chargeVendor(item.vendorID, clID);
	});
	
	// Have we opened all vendor windows once?
	if ( popupBlocker && (maxWindows == vendorsChecked) && !openedAllCRWins) {
		openedAllCRWins = true;
		
		// Check for vendor cookie and set if it doesn't exist
		$( "#crIndividualVendors").dialog( "open" );
		
		if (lastOpenedWinName != "") {
			
			try {
				crPopupWins[lastOpenedWinName].resizeTo($(window).width() * 0.50, $(window).height() * 0.80);
				crPopupWins[lastOpenedWinName].moveTo(500,$(window).height() * 0.20);
				crPopupWins[lastOpenedWinName].focus();		
			}
			catch (err) {
				// if you get access denied then don't do anything
			}
		
		
		}
			
		reOpenedWindow = true;
	}
		
	// Reverse order of focus so #1 vendor is on top if we've already opened up all windows
	if (!openedAllCRWins && !reOpenedWindow) {
		$.each(crWinArray.reverse(),
		function(i, item)
		{
			crPopupWins[item].focus();
		});
	}
	
	if (popupBlocker && openedAllCRWins && !reOpenedWindow) {
		
		// We've already cycled throw all the windows and didn't open a new one
		// Put back original options
		$("#loadingVendors").css("display","none");  						   
		$("#vendorItems").css("display","block");  			
		$( "#crIndividualVendors").dialog( "open" );		
	}
	else if (popupBlocker && !reOpenedWindow) {

		// Display box with individual check rate vendors
		$( "#crIndividualVendors").dialog( "open" );
		
		if (lastOpenedWinName == "") {
			
			// Incase some of the copy already openned the 1st window and we can't open any windows
			vendorsToView++;
			
			if (vendorsToView == 1)
				$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
			else if (vendorsToView == 0)
				$( "#vendorNumberText").css("display", "none");
			else
				$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");			
		}
		else {
			
			try {

				// Move and resize window
				crPopupWins[lastOpenedWinName].resizeTo($(window).width() * 0.50,  $(window).height() * 0.80);
				crPopupWins[lastOpenedWinName].moveTo(500,$(window).height() * 0.20);
				crPopupWins[lastOpenedWinName].focus();
			}
			catch (err) {
				// if you get access denied then don't do anything
			}
			
		}
	}
	
	// Put back original options
	$("#loadingVendors").css("display","none");  						   
	$("#vendorItems").css("display","block");  			

	return false;
}

function openOneLandingWindow()
{
	$("#selectVendor").css("display", "none");
	
	// Add GA event
	trackEvent("CheckRates", "cpClick", 0, true);	

	// Setup any defaults
	$("#vendorNumberText").css("display", "block");
	if (vendorsToView == -1) {
		vendorsToView = 0;
		$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
	}
	
	// Set waiting screen
	$("#vendorItems").css("display","none");  						   
	$("#loadingVendors").css("display","block");  						   

	// We've got vendors so let's get all the values
	var checkedVendors = "";

	// Setup popup blocker window counts
	$("#vendorNumber").html(0);
	$("input:checked[name='vendors']").each ( 
		function(index) {
			
			checkedVendors = checkedVendors + $(this).val() + "|";
			
			// Reset the images to "unchecked status" on popup blocker layer if window isn't open
			windowName = "win" + $(this).val();
			if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
				$( "#crbutton_" + $(this).val() ).attr( "src",  CDN_PATH + "/checkprices.gif");
				
				// Since we've closed the window increase the vendorsToView amount
				if (vendorsToView < 0)
					vendorsToView++;
			}
			else {
				
				// Determine vendors to view
				if (vendorsToView > 0)
					vendorsToView--;
				
				if (vendorsToView == 1)
					$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
				else if (vendorsToView == 0)
					$( "#vendorNumberText").css("display", "none");
				else
					$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
			}
		}
	);

	// Get month selected
	var dateSelected = $("#startDate").val();
	
	// Get cruiseline if it exists
	var clID = $("#cl").val();

	// destinations
	var destID = $("#port").val();

	// departure city
	var depCityID = $("#depcity").val();

	// section
	var section = $("#section").val();

	// Setup data to send to ajax call
	var dataToSend = "vendors=" + escape(checkedVendors) + "&date=" + escape(dateSelected) + "&clID=" + escape(clID) + "&destID=" + escape(destID) + "&depCityID=" + escape(depCityID) + "&section=" + escape(section) + "&ipAddress=" + escape(ip);

	// Make ajax call with info
	var vendorArray = new Array;
	$.ajax(
	{
		url: '/ajax/ajx_getCheckRateVendors.php',
  		dataType: 'text',
  		//dataType: 'json',
  		data: dataToSend,
		async:   false,
  		success: function(data) 
		{
			vendorArray = eval("(" + data + ")");
			//vendorArray = data;
		}
	});

	// Setup one window positioning
	var top = 125;
	var left = 525;
	//var width = 600;
	//height = 450;
	var winHeight = $(window).height() * 0.75;
	var winWidth = $(window).width() * 0.5;	
	
	// Try to open up all the popups 1st to see if a popup blocker is enabled
	var windowName = "";
	var maxWindows = 0;
	var crWinArray = new Array();
	var lastOpenedWinName = "";
	var reOpenedWindow = false;
	
	$.each(vendorArray,
	function(i, item)
	{
		windowName = "win" + i;

		// Check if window was closed previously
		var windowCreated = false;
		if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
			openedAllCRWins = false;
			windowCreated = true;
		}

		// Open up window until we can't open it any more
//		crPopupWins[windowName] = window.open("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, "top=" + top + ",left=" + left + ",width=" + width + ",height=" + height + ",location=1,scrollbars=1,status=1,menubar=1,resizable=1");
		crPopupWins[windowName] = openBrowserWindow("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, top, left, winWidth, winHeight);
		if (!crPopupWins[windowName] || crPopupWins[windowName].closed || typeof crPopupWins[windowName].closed==='undefined') {
				
			// Put end placeholder in popup blocked window so we can determine where to add the next window in popup array next time we come in here
			crPopupWins[windowName] = "end";	
			popupBlocker = true;

			return false;   // We found popup blocker so return false to break out of this each and continue on through rest of function
		}
			
		crWinArray[maxWindows] = windowName;
		maxWindows++;

		// Set button to selected
		$( "#crbutton_" + item.vendorID ).attr( "src",  CDN_PATH + "/checkpricessel.gif");

		// Keep track of last window
		if (windowCreated) {
			lastOpenedWinName = windowName;
		}

		// Charge vendor if needed
		chargeVendor(item.vendorID, clID);
	});
	
	// Have we opened all vendor windows once?
	if ( popupBlocker && (maxWindows == 1) && !openedAllCRWins) {
		openedAllCRWins = true;
		
		// Check for vendor cookie and set if it doesn't exist
		$( "#crIndividualVendors").dialog( "open" );
		
		if (lastOpenedWinName != "") {
			crPopupWins[lastOpenedWinName].focus();		
		}
			
		reOpenedWindow = true;
	}
		
	// Reverse order of focus so #1 vendor is on top if we've already opened up all windows
	if (!openedAllCRWins && !reOpenedWindow) {
		$.each(crWinArray.reverse(),
		function(i, item)
		{
			crPopupWins[item].focus();
		});
	}
	
	if (popupBlocker && openedAllCRWins && !reOpenedWindow) {
		
		// We've already cycled throw all the windows and didn't open a new one
		// Put back original options
		$("#loadingVendors").css("display","none");  						   
		$("#vendorItems").css("display","block");  			
		$( "#crIndividualVendors").dialog( "open" );		
	}
	else if (popupBlocker && !reOpenedWindow) {

		// Display box with individual check rate vendors
		$( "#crIndividualVendors").dialog( "open" );
		
		if (lastOpenedWinName == "") {
			
			// Incase some of the copy already openned the 1st window and we can't open any windows
			vendorsToView++;
			
			if (vendorsToView == 1)
				$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
			else if (vendorsToView == 0)
				$( "#vendorNumberText").css("display", "none");
			else
				$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");			
		}
		else
			crPopupWins[lastOpenedWinName].focus();
	}
	
	// Put back original options
	$("#loadingVendors").css("display","none");  						   
	$("#vendorItems").css("display","block");  			

	return false;
}

function openIndividualLandingVendor(vendorID)
{
	// Get month selected
	var dateSelected = $("#startDate").val();
	
	// Get cruiseline if it exists
	var clID = $("#cl").val();

	// Get destination if it exists
	var destID = $("#port").val();

	// Get destination if it exists
	var depCityID = $("#depcity").val();

	// Get destination if it exists
	var section = $("#section").val();

	// Setup data to send to ajax call
	var dataToSend = "vendors=" + escape(vendorID) + "&date=" + escape(dateSelected) + "&clID=" + escape(clID) + "&destID=" + escape(destID) + "&depCityID=" + escape(depCityID) + "&section=" + escape(section) + "&ipAddress=" + escape(ip);

	// Make ajax call with info
	var vendorArray = new Array;
	$.ajax(
	{
		url: '/ajax/ajx_getCheckRateVendors.php',
  		dataType: 'text',
  		//dataType: 'json',
  		data: dataToSend,
		async:   false,
  		success: function(data) 
		{
			vendorArray = eval("(" + data + ")");
			//vendorArray = data;
		}
	});

	var top = $(window).height() * 0.20;
	var left = 500;
	
	$.each(vendorArray,
	function(i, item)
	{
		
		var windowName = "win" + i;
		//crPopupWins[windowName] = window.open("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, "top=" + top + ",left=" + left + ",width=600,height=450,location=1,scrollbars=1,status=1,menubar=1,resizable=1");
		crPopupWins[windowName] = openBrowserWindow("/checkrates/crvendors.php?dv=" + escape(item.data), windowName, top, left, $(window).width() * 0.50,  $(window).height() * 0.65);
		$( "#crbutton_" + item.vendorID ).attr( "src",  CDN_PATH + "/checkpricessel.gif");
		crPopupWins[windowName].focus();
		chargeVendor(item.vendorID, clID);
		
		// Determine vendors to view
		if (vendorsToView > 0)
			vendorsToView--;
				
		if (vendorsToView == 1)
			$("#vendorNumberText").html("You have " + vendorsToView + " more site to check");
		else if (vendorsToView == 0)
			$( "#vendorNumberText").css("display", "none");
		else
			$("#vendorNumberText").html("You have " + vendorsToView + " more sites to check");
	});
	
	return true;
}

function setViewPortChecks(checkButtonName, section)
{
	// Get viewport size
	var viewPortSize = getViewPortSize($(window).width());

	// Setup data to send to ajax call
	var dataToSend = "attribute=checkedVendors&name=" + escape(section) + "&viewPortSize=" + escape(viewPortSize);
	
	// Make ajax call with info
	var vendorArray = new Array;
	$.ajax(
	{
		url: '/ajax/ajx_getCRAttributeInfo.php',
  		dataType: 'text',
  		//dataType: 'json',
  		data: dataToSend,
		async:   true,
  		success: function(data) 
		{
			attributeInfo = eval("(" + data + ")");
			
			// Reset check boxes
			$("input[name='" + checkButtonName + "']").attr('checked', false);
			
			checkedMax = attributeInfo.value;
			checkedCnt = 0;					
			$.each($("input[name='" + checkButtonName + "']"),
			   	function(i, item)
				{
					// Check to see the limit of what should and shouldn't be checked
					if (checkedCnt < checkedMax)
						item.checked = true;
						
					checkedCnt += 1;
				});
					
					   
		}
	});
}

function toggleVendors(toggleState)
{
	$(".hideRow").toggle();
	
	if (toggleState == 'hide') {
		$("#showAllVendors").show();
		$("#hideVendors").hide();
	}
	else {
		$("#showAllVendors").hide();
		$("#hideVendors").show();
	}
}

