$(document).ready( SetupShortlist );

function SetupShortlist()
{
	if( $.browser.msie && $.browser.version <= 6.0 )
	{
		var html =
		  "<iframe style=\"position: absolute; display: block; " +
		  "z-index: -1; width: 360px; height: 100%; top: 0; left: 0;" +
		  "filter: mask(); background-color: #ffffff; border:none; \"></iframe>";

		$("#shortlistContainer").append(html);
		$("#shortlistContainer").show();
		$("#shortlistContainer").hide();		
	}
	
	// open the shortlist if we are not on the login page
	if( GetOpenShortlist() && window.location.href.indexOf("/site/shortlist-login") == -1 )
	{
		ToggleShortlist();
	}	
	
}

var shortlistCount = 0;
var shortlistItemsCount = 0;
var g_isLoggedIn = false;
var g_currentShortlistItems;

// sorry about this !
var g_pdfTypes = new Object();
g_pdfTypes["accommodation"] = "1";
g_pdfTypes["what-to-see-and-do/activities"] = "2";
g_pdfTypes["what-to-see-and-do/attractions"] = "3";
g_pdfTypes["what-to-see-and-do/entertainment"] = "3";
g_pdfTypes["what-to-see-and-do/shopping"] = "3";
g_pdfTypes["what-to-see-and-do/food-and-drink"] = "3";
g_pdfTypes["what-to-see-and-do/events"] = "3";
g_pdfTypes["what-to-see-and-do/tours-and-guided-tours"] = "3";
g_pdfTypes["what-to-see-and-do/search-results"] = "3";

function StoreCurrentShortlist(id)
{
	$.cookie("currentShortlist", id, {path: "/"} );
}

function GetCurrentShortlist()
{
	return $.cookie("currentShortlist");
}

function StoreOpenShortlist(isOpen)
{
	$.cookie("openShortlist", isOpen, {path: "/"} );
}

function GetOpenShortlist()
{
	if ($.cookie("openShortlist") == null )
		return false;
	else if ($.cookie("openShortlist") == "true" )
		return true;
	else
		return false;
}

function InitShortList()
{
    var timestamp = new Date();

    $("#shortlistIntro").hide();
    $("#shortlistTemp").hide();
    $("#shortlistSelect").hide();
    $("#shortlistItems").hide();
    $("#shortlistOptions").hide();
    $("#EmailForm").hide();
    $("#noItems").hide();
    
    if (g_isLoggedIn)
        $("#dataload").load("/site/shortlist-home?t=" + timestamp.getTime() + " #myShortlists", {}, LoadShortlists);
    else
        LoadShortlists();
}

function DisplayShortlist(visible)
{
	if(visible)
	{	
		$("#closePanel").css("opacity", 0.01);
		$("#closePanel").css("z-index",1);
		$("#closePanel").width($(document).width());
		$("#closePanel").height($(document).height());
						
		$("#closePanel").show();
		$("#closePanel").click(function(){ ToggleShortlist(); });
				
		$("#loading").show();
		$("#shortlist").addClass("open");
		$("#shortlistContainer").css("height","2em");
		$("#shortlistContainer").css("z-index",7000);
		$("#shortlistContainer").slideDown();
		
		SetIsLoggedIn();
		InitShortList();
	}
	else
	{
		$("#closePanel").unbind("click").hide();
		StoreOpenShortlist(false);
		
		$("#shortlistContainer").slideUp("fast", function()
		{
			$("#shortlist").removeClass("open");
			$("#shortlistIntro").hide();
			$("#shortlistTemp").hide();
			$("#shortlistSelect").hide();
			$("#shortlistItems").hide();
			$("#shortlistOptions").hide();
			$("#EmailForm").hide();
			$("#pleaseLogin").hide();
			
			g_openingShortList = false;
		});
	}
	
	g_shortListOpen = visible;
}

function SetIsLoggedIn()
{
    var resText;
    
    resText = $.ajax({ async: false, cache: false, url: "/site/shortlist-home" }).responseText;
    g_isLoggedIn = resText.indexOf("Shortlist Login") < 0;
}

function DisplayLoading(visible)
{
	if(visible)
	{
		$("#loading").fadeIn("fast");
		$("#shortlistIntro").fadeOut();
		$("#shortlistTemp").fadeOut();
		$("#shortlistSelect").fadeOut();
		$("#shortlistItems").fadeOut();
		$("#shortlistOptions").fadeOut();
		$("#EmailForm").fadeOut();
		$("#pleaseLogin").fadeOut();
		$("#noItems").fadeOut();
	}
	else
	{
		$("#loading").fadeOut();
	}
}

function RegisterLogin()
{
	StoreOpenShortlist(true);
	
	if( shortlistItemsCount > 0 )
		SaveShortlist();
	else
		window.location.href  = "/site/shortlist-login";
				

	return false;
}

function LoadShortlists()
{
	var id = 0;

	if (g_isLoggedIn) {
	    if ($("#dataload").html().length != 0) {
	        shortlistCount = BuildShortlists();

	        if (shortlistCount > 0) {
	            if (GetCurrentShortlist() == null) {
	                id = $("#ddlShortlists").selectedValues()[0];
	                StoreCurrentShortlist(id);
	            }
	            else if (GetCurrentShortlist() == -1) {
	                // load the last shortlist
	                document.getElementById("ddlShortlists").selectedIndex = document.getElementById("ddlShortlists").options.length - 1;
	                StoreCurrentShortlist($("#ddlShortlists").selectedValues());
	            }
	            else {
	                id = GetCurrentShortlist();
	                $("#ddlShortlists").selectOptions(id);
	            }
	        }
	    }
	}
	
	var timestamp = new Date();

	if (id != 0) {
	    $.ajax(
		{
		    type: "GET",
		    url: "/site/shortlist-home?epaction=loaddms&epkey=" + id,
		    cache: false,
		    success: function() {
		        $("#dataload").load("/site/shortlist-current?t=" + timestamp.getTime() + " #myShortlist", {}, LoadCurrentShortlist);
		    }
		});
	}
	else
	    $("#dataload").load("/site/shortlist-current?t=" + timestamp.getTime() + " #myShortlist", {}, LoadCurrentShortlist);
}

/* loads the shortlists */
function GetShortlists()
{
	shortlists = new Array();
	var count = 0;
	
	$("#dataload #myShortlists div.ItryActions p a").each(function()
	{
		id = ParseShortlistID($(this).attr("href"));
		name = $(this).parent().parent().prev().prev().prev("h3").html();
		if( name == null || name == "null" || name.length == 0 )
			name = "My Shortlist " + (count+1);
		
		shortlists[count] = new Shortlist(id,name);
		count++;
	});
	
	return shortlists;
}


function BuildShortlists()
{
	var shortlists = GetShortlists();

	dropdownlist = $("#shortlistSelect select");
	dropdownlist.empty();

	for(i=0 ; i<shortlists.length ; i++)
	{
		dropdownlist.append("<option value='"+shortlists[i].GetID()+"'>"+shortlists[i].GetName()+"</option>");
	}
	
	return shortlists.length;
}

/* parses the shortlist ID from the delete itineray link */
function ParseShortlistID(url)
{
	url = url.substring( url.indexOf("epkey=") + 6);
	return url;
}

function LoadCurrentShortlist() {

    if ($("#dataload").html().length != 0) {
        shortlistItemsCount = BuildShortlist();
        if (shortlistItemsCount > 0 || shortlistCount > 0) {
            DisplayContent("shortlistItems");
        }
        else {
            DisplayContent("shortlistIntro");
        }
    }
    else {
        DisplayContent("shortlistIntro");
    }
}

/* displays the specified content div */
function DisplayContent(contentDiv)
{
	newHeight = 0;
	
	switch(contentDiv)
	{
		case "shortlistIntro": 
			newHeight = 23; 
			
			break;
		case "shortlistItems": 
			
			$("#shortlistItems").css("height", "auto");
			
			if( shortlistItemsCount == 0 )
				newHeight = 11;
			else if( shortlistItemsCount == 1 )
				newHeight = 19;
			else if( shortlistItemsCount == 2 )
				newHeight = 26;
			else if( shortlistItemsCount == 3 )
				newHeight = 34;
			else if( shortlistItemsCount == 4 )
				newHeight = 41;
			else if( shortlistItemsCount > 4 )
			{
				newHeight = 41;
				$("#shortlistItems").css("overflow-y", "auto");
				$("#shortlistItems").css("overflow-x", "hidden");
				$("#shortlistItems").css("height", "30em");
			}
						
			break;
		default: newHeight = 4; break;
	}
	
	$("#shortlistContainer").animate( { height:newHeight+"em" }, 800, function()
	{
		$("#" + contentDiv).fadeIn();
			
		switch(contentDiv)
		{
			case "shortlistIntro": 
				
				$("#shortlistTemp").hide();
				$("#shortlistSelect").hide();
				$("#noItems").hide();
				$("#shortlistItems").hide();
				$("#shortlistOptions").hide();
				$("#EmailForm").hide();
				$("#pleaseLogin").fadeIn();
				
				break;
				
			case "shortlistItems": 
			
				$("#shortlistIntro").hide();
				
				if( !g_isLoggedIn )
				{
					$("#pleaseLogin").fadeIn();
				}
				else
				{
					$("#pleaseLogin").hide();
				}
				
				if( shortlistCount > 0 )
				{
					$("#shortlistSelect").fadeIn();
					$("#viewOnMap").fadeIn();
					$("#shortlistOptions").fadeIn();
					$("#btnNew").show();
					$("#btnSave").hide();
					$("#shortlistTemp").hide();
				}
				else
				{
					$("#btnNew").hide();
					$("#btnSave").show();
					$("#shortlistTemp").fadeIn();
					$("#shortlistOptions").fadeIn();
					$("#viewOnMap").hide();
				}
				
				if( shortlistItemsCount > 0 )
				{
					$("#noItems").hide();
					$("#viewOnMap").show();
					$("#btnPrint").removeAttr("disabled");
					
					if( g_isLoggedIn ) 
					{
						$("#btnSend").removeAttr("disabled");
						$("#btnBrochure").removeAttr("disabled");
					}
					else
					{
						$("#btnBrochure").attr("disabled", true);
						$("#btnSend").attr("disabled", true);
					}
				}
				else
				{
					$("#viewOnMap").hide();
					$("#noItems").fadeIn();
					$("#btnPrint").attr("disabled", true);
					$("#btnBrochure").attr("disabled", true);
					$("#btnSend").attr("disabled", true);
				}
			
				break;
		}	
		
		g_openingShortList = false;
		
	});
	
	DisplayLoading(false);
}

/* builds the shortlist from data on the page and returns the number of items */
function BuildShortlist()
{	
	GetShortlistItems();
	$("#shortlistItems").empty();
	
	for(i=0 ; i<g_currentShortlistItems.length ; i++ )
	{
		OutputShortlistItem(g_currentShortlistItems[i], i!=0, i<g_currentShortlistItems.length-1, i );
	}
	SetItinaryButtons();
	
	return g_currentShortlistItems.length;
}

function GetShortlistItems()
{
	g_currentShortlistItems = new Array();
	var count = 0;
	var block = true;
	var obj;
	var objCount;

	obj = $("#dataload #myShortlist .ItnryItems table.ItnryTbl tbody tr");
	objCount = obj.length;

	obj.each(function() {
	    var name = $(this).find("td.item a.number").html();
	    if (name != null) {
	        var url = $(this).find("td.item a.number").attr("href");
	        var id = ParseID(url);
	        var type = ParseType(url);

	        var description = $("ol.searchResults li h2 a[href*='" + id + "']").parent().parent().find("div.desc p").html();
	        var imageUrl = $("ol.searchResults li h2 a[href*='" + id + "']").parent().parent().find("div.thumbnail img").attr("src");
	        url = $("ol.searchResults li h2 a[href*='" + id + "']").attr("href");

	        g_currentShortlistItems[count] = new ShortlistItem(id, type, name, description, url, imageUrl);

	        count++;
	    }
	});
	
	
	
}

/* parses the product id from the product Url */
function ParseID(url)
{
	if( url.indexOf("?") != - 1)
		url = url.substring(0, url.indexOf("?"));
	
	return url.substring(url.lastIndexOf("-")+2);
}

/* parses the product type from the product Url */
function ParseType(url)
{
	var type;
	var start;
	var end;
	
	url = url.replace("http://", "");
	url = url.replace(window.location.hostname, "");
	
	start = url.indexOf("/", 1);
	end = url.indexOf("/", start +1 );
	
	type = url.substring(start+1, end);
	
	if( type != "accommodation" )
	{
		end = url.indexOf("/", end +1 );
		type = url.substring(start+1, end);
	}
	
	return type;
}

/* outputs a new shortlist item */
function OutputShortlistItem(shortlistItem, canMoveUp, canMoveDown, index)
{
	newItem = $("#shortlistItemTemplate").clone();
			
	newItem.attr("id", shortlistItem.GetID());
	newItem.removeClass("template");
	newItem.attr("style", "");
	
	newItem.find(".info h2 a").append(shortlistItem.GetName());
	newItem.find(".info h2 a").attr("href", shortlistItem.GetUrl());
	newItem.find(".info p").append(shortlistItem.GetDescription());
	newItem.find(".image img").attr("src", shortlistItem.GetImageUrl());
	newItem.find(".image img").attr("alt", shortlistItem.GetName());
	
	$("#shortlistItems").append(newItem);
}

function SetItinaryButtons()
{
	count = 0;
	$("#shortlistItems .shortlistItem").each(function() 
	{
		id = $(this).attr("id");
		
		
		$(this).find(".options a.remove").unbind();
		$(this).find(".options a.up").unbind();
		$(this).find(".options a.down").unbind();
		
		$(this).find(".options a.remove").attr("i", id);
		$(this).find(".options a.remove").click(function(){ return RemoveItineryItem($(this).attr("i")); });
		
		button = $(this).find(".options a.up");
		if( count > 0 )
		{	
			button.attr("i", id);
			button.attr("p", count);
			button.click(function() { MoveItineryItem("u",$(this).attr("i"),$(this).attr("p"));return false;})
			button.find("img").attr("src","/images/shortlist/move-up.png");
		}
		else
			button.find("img").attr("src","/images/shortlist/move-up-disabled.png");
			
		button = $(this).find(".options a.down");
		if( count < $("#shortlistItems .shortlistItem").length-1 )
		{
			button.attr("i", id);
			button.attr("p", count);
			button.click(function(){ MoveItineryItem("d",$(this).attr("i"),$(this).attr("p"));return false; });
			button.find("img").attr("src","/images/shortlist/move-down.png");
		}
		else
			button.find("img").attr("src","/images/shortlist/move-down-disabled.png");
		
		$(this).removeClass("even");
		$(this).removeClass("odd");
		
		if( count % 2 == 0 )
			$(this).addClass("even");
		else
			$(this).addClass("odd");
		
		count++;
	});
}

/* removes the itinery item from the current shortlist */
function RemoveItineryItem(id)
{
	$.ajax(
	{
		type: "GET",
		url: "/site/shortlist-current?epaction=ctrlremove&epkey=" + id,
		cache: false,
		success: function()
		{
			$.get("/site/shortlist-current?epaction=savedms");
		}
	});
	
	var timestamp = new Date();
	$("#dataload").load("/site/shortlist-current?t="+timestamp.getTime()+" #myShortlist", {}, function()
	{
		if( $("#dataload").html().length != 0 )
			BuildShortlist();
	});

	$("#" + id).slideUp("normal",function()
	{ 
		$(this).remove();
		if( $("#shortlistItems .shortlistItem").length == 0 )
		{
			DisplayLoading(true);
			InitShortList();
		}
		else
			SetItinaryButtons();
	});
	
	return false;
}

/* moves the itinery item */
function MoveItineryItem(direction, id, position)
{
	var epaction;
	var shortlistItem;
	itineryItem = $("#" + id);
	itineryItem.remove();
	
	if( direction == "u")
	{
		shortlistItem = g_currentShortlistItems[position];
		g_currentShortlistItems.splice(position, 1);
				
		epaction = "moveup";
		position--;
		$("#shortlistItems .shortlistItem:eq(" + position + ")").before(itineryItem);
		
		g_currentShortlistItems.splice(position,0, shortlistItem);
	}
		
	if( direction == "d")
	{
		shortlistItem = g_currentShortlistItems[position];
		g_currentShortlistItems.splice(position, 1);
		epaction = "movedown";
		$("#shortlistItems .shortlistItem:eq(" + position + ")").after(itineryItem);
		g_currentShortlistItems.splice(position+1, 0,shortlistItem);
	}
	
	$.ajax(
	{
		type: "GET",
		cache: false,
		url: "/site/shortlist-current?epaction="+epaction+"&epkey=" + id,
		success: function()
		{
			$.get("/site/shortlist-current?epaction=savedms");
		}
	});
	
	SetItinaryButtons();
}

function DisplayToolTip(e, tooltip)
{
	$(".tooltip").hide();	
	$(tooltip).css("left",e.pageX+10);
	$(tooltip).css("top",e.pageY+10);
	$(tooltip).fadeIn();
}

function HideToolTip(tooltip)
{
	$(tooltip).fadeOut();
}

function DisplaySendEmailForm(display)
{
	if( display ) 
	{
		
		// check that the user is logged in
		if (!g_isLoggedIn)
		{
			StoreOpenShortlist(true);
			window.location.href = "/site/shortlist-login";
		}
		else
		{			
			$("#shortlistOptions").hide();
			$("#EmailForm input#txtFrName").val("Enter your name");
			$("#EmailForm input#txtFrEmail").val("Enter friend's email");
			
			$("#EmailForm input#txtFrName").focus(function()
			{
				if( $(this).val() == "Enter your name")
					$(this).val("");
			});
			
			$("#EmailForm input#txtFrName").blur(function()
			{
				if( $(this).val() == "")
					$(this).val("Enter your name");
			});

			$("#EmailForm input#txtFrEmail").focus(function()
			{
				if( $(this).val() == "Enter friend's email")
					$(this).val("");
			});
			
			$("#EmailForm input#txtFrEmail").blur(function()
			{
				if( $(this).val() == "")
					$(this).val("Enter friend's email");
			});

			$("#EmailForm").fadeIn();
		}
	}
	else
	{
		$("#EmailForm").hide();	
		$("#shortlistOptions").fadeIn();
		$("#EmailForm input[type='text']").unbind("focus").unbind("blur");
	}
}

function SendEmail()
{
	$("#btnSendEmail").val("Sending...");
	$("#btnSendEmail").attr("disabled",true);
	
	jQuery.post("http://" + window.location.host + "/site/shortlist-home", {"epaction":"emailfr","txtFrName":$("#txtFrName").val(), "txtFrEmail":$("#txtFrEmail").val(), "txtMsg":" " }, function() 
	{
		$("#btnSendEmail").removeAttr("disabled");
		DisplaySendEmailForm(false);
		$("#btnSendEmail").val("Send");
	});
}

/* saves the current shortlist */
function SaveShortlist()
{
	DisplayLoading(true);
	
	if( !g_isLoggedIn )
	{
		// user is not logged in, forward to login page and set cookie to 
		// keep shortlist open
		StoreOpenShortlist(true);
		StoreCurrentShortlist(-1);
		window.location.href = "?epaction=savedms";
	}
	else
	{
		// user l is logged in so save basket and reload the shortlists
		jQuery.get("http://" + window.location.host + "/site/shortlist-home?epaction=savedms");
		InitShortList();
	}
	
}

/* saves the new name for the current shortlist */
function SaveShortlistName()
{
	$("#btnSaveName").attr("disabled", true);
	$("#btnSaveName").val("Saving...");
	
	jQuery.post("http://" + window.location.host + "/site/shortlist-current", {epaction:"savename",txtName:$("#txtShortlistName").val()}, function() 
	{
		$("#btnSaveName").removeAttr("disabled");
		DisplayRenameShortlist(false);	
		$("#btnSaveName").val("Save");
	});
	
}

/* displays the rename options */
function DisplayRenameShortlist(display)
{
	if(display)
	{
		$("#ddlShortlists").hide();
		$("#btnRename").hide();
		$("#txtShortlistName").fadeIn();
		$("#btnSaveName").fadeIn();
		$("#txtShortlistName").val( $("#ddlShortlists").selectedOptions().html() );
		$("#txtShortlistName").focus();
		$("#txtShortlistName").select();
	}
	else
	{
		$("#txtShortlistName").hide();

		$("#btnSaveName").hide();
		$("#ddlShortlists").fadeIn();
		$("#btnRename").fadeIn();
		
		$("#ddlShortlists").selectedOptions().html( $("#txtShortlistName").val() );
	}
}

/* loads the shortlist from the dropdown */
function LoadShortlist()
{
	DisplayLoading(true);
	
	var timestamp = new Date();
	var id = $("#ddlShortlists").selectedValues()[0];
	StoreCurrentShortlist(id);
	
	jQuery.get("http://" + window.location.host + "/site/shortlist-home?epaction=savedms", function()
	{
		jQuery.get("http://" + window.location.host + "/site/shortlist-home?epaction=loaddms&epkey=" + id, function(data,textStatus)
		{
			$("#dataload").load("/site/shortlist-current?t=" + timestamp.getTime() + " #myShortlist", {}, LoadCurrentShortlist);
		});
	});
}

function DeleteShortlist()
{
	if( confirm("Are you sure you want to delete this list?") )
	{
		
		$("#btnDelete").attr("disabled", true);
		$("#btnDelete").val("Deleting...");
		
		var newId = 0;
		var id = $("#ddlShortlists").val();
		
		$.ajax(
		{
			type: "GET",
			url: "/site/shortlist-home?epaction=deldms&epkey=" + id,
			cache: false,
			success: function()
			{
				DisplayLoading(true);
				$("#btnDelete").val("Delete");
				$("#btnDelete").removeAttr("disabled");
				$("#ddlShortlists").removeOption(id);
				
				if( $("#ddlShortlists").find("option").length > 0 )
				{
					newId = $("#ddlShortlists").selectedValues()[0];
					StoreCurrentShortlist(newId);
				}
				else
					StoreCurrentShortlist(0);
				

				
				if( newId > 0 )
				{
					$.ajax(
					{
						type: "GET",
						url: "/site/shortlist-home?epaction=loaddms&epkey=" + newId,
						cache: false,
						success: function()
						{
							InitShortList();
						}
					});
				}
				else
				{
					InitShortList();
				}
			}
		});
		
	}
}

/* prints the current short list */
function PrintShortlist()
{
	window.open("http://" + window.location.hostname + "/site/shortlist-print");
}

/* creates a new shortlist */
function NewShortlist()
{
	DisplayLoading(true);
	
	var timestamp = new Date();
	
	$.ajax(
	{
		type: "GET",
		url: "/site/shortlist-home?epaction=new",
		cache:false,
		success: function()
		{
			$.ajax(
			{
				type: "GET",
				cache: false,
				url: "/site/shortlist-home?epaction=savedms",
				success: function()
				{
					$("#dataload").load("/site/shortlist-home?t2="+timestamp.getTime()+" #myShortlists", {}, function() 
					{
						if( $("#dataload").html().length != 0 )
						{
							lists = GetShortlists();
							StoreCurrentShortlist(lists[lists.length-1].GetID());
							jQuery.get("http://" + window.location.host + "/site/shortlist-home?epaction=loaddms&epkey=" + lists[lists.length-1].GetID(), function()
							{
								InitShortList();
							});
						}
					});
				}
			});
		}
	});
}

function GenerateBrochure()
{
	var buttonWidth;
	
	if( g_isLoggedIn )
	{
		buttonWidth = $("#btnBrochure").css("width");
		$("#btnBrochure").attr("disabled", true);
		$("#btnBrochure").val("Generating Brochure...");
		$("#btnBrochure").css("width", "145px");
				
		var productUrl;
		var pageUrl;
		
		var ThisPageURL = location.href;
		
		if (ThisPageURL.indexOf('au.vne.nmdemo.net') != -1)
		{
			pageUrl = "http://one-tourism-int.different-digital.co.uk/generate-brochure.aspx?" +
			//pageUrl = "http://localhost/ONE-Tourism/generate-brochure.aspx?" +
				"filename=" + $("#ddlShortlists").selectedOptions().html() + 
				"&url=" + escape("http://" + window.location.host + "/site/");

		}
		else if (ThisPageURL.indexOf('nz.vne.nmdemo.net') != -1)
		{
			pageUrl = "http://one-tourism-nz.different-digital.co.uk/generate-brochure.aspx?" +
			//pageUrl = "http://localhost/ONE-Tourism/generate-brochure.aspx?" +
				"filename=" + $("#ddlShortlists").selectedOptions().html() + 
				"&url=" + escape("http://" + window.location.host + "/site/");

		}
		else
		{
			pageUrl = "http://one-tourism.different-digital.co.uk/generate-brochure.aspx?" +
			//pageUrl = "http://localhost/ONE-Tourism/generate-brochure.aspx?" +
				"filename=" + $("#ddlShortlists").selectedOptions().html() + 
				"&url=" + escape("http://" + window.location.host + "/site/");
		}
		
		for(var i=0 ; i<g_currentShortlistItems.length ; i++)
		{
			productUrl = g_currentShortlistItems[i].GetUrl();
			productUrl = productUrl.substr( productUrl.lastIndexOf("/") + 1 );
			
			pageUrl += "&url" + (i+1) + "=" + productUrl;
			pageUrl += "&t" + (i+1) + "="  + g_pdfTypes[g_currentShortlistItems[i].GetType()];
		}
		
		$("#dataload").empty();
		$("#dataload").append("<iframe src=''></iframe>");
		$("#dataload iframe").load(function() 
		{
			$("#btnBrochure").removeAttr("disabled");
			$("#btnBrochure").val("Create Brochure");
			$("#btnBrochure").css("width", "120px");

		});
		$("#dataload iframe").attr("src", pageUrl);
		
		// ie doesn't fire the load event for iframe so just use a timer
		if( $.browser.msie )
		{
			setTimeout("$('#btnBrochure').removeAttr('disabled');$('#btnBrochure').val('Create Brochure');$('#btnBrochure').css('width', '120px');", 30000)
		}
	}
	return false;
}

/**
 * ShortlistItem class
 **/

function ShortlistItem(id,type,name, description, url, imageUrl) 
{
	this._id = id;
	this._name = name;	
	this._description = description;
	this._url = url;
	this._imageUrl = imageUrl;
	this._type = type;
}

ShortlistItem.prototype._name;
ShortlistItem.prototype.GetName = function() { return this._name; }
ShortlistItem.prototype._description;
ShortlistItem.prototype.GetDescription = function() { return this._description; }
ShortlistItem.prototype._id;
ShortlistItem.prototype.GetID = function() { return this._id; }
ShortlistItem.prototype._url;
ShortlistItem.prototype.GetUrl = function() { return this._url; }
ShortlistItem.prototype._imageUrl;
ShortlistItem.prototype.GetImageUrl = function() { return this._imageUrl; }
ShortlistItem.prototype._type;
ShortlistItem.prototype.GetType = function() { return this._type; }

/**
 * Shortlist class
 **/
function Shortlist(id,name)
{
	this._id = id;
	this._name = name;
}

Shortlist.prototype._id;
Shortlist.prototype.GetID = function() { return this._id; }
Shortlist.prototype._name;
Shortlist.prototype.GetName = function() { return this._name; }