

function saveComparisonSelections()
{
	var phonesSep = "";
	for (var i = 0; i < comparisonContainers.containers.length; i++)
	{
		if (comparisonContainers.containers[i].currentProduct != null)
		{
			phonesSep += comparisonContainers.containers[i].currentProduct.name + "~" + i + "¤";
		}
	}
	if (phonesSep != "")
	{
		phonesSep = phonesSep.substr(0, phonesSep.length -1); //remove last separator
	}

	comparisonSelectionsCookie.put("phones", phonesSep);
	comparisonSelectionsCookie.write();
}

function loadComparisonSelections()
{
	if ( ! comparisonSelectionsCookie.found )
	{
		return;
	}

	var phonesSep = comparisonSelectionsCookie.get("phones");
	if (phonesSep != "" && phonesSep != null)
	{
		var phoneInfo = phonesSep.split("¤");
		var phoneName = null;
		var phoneCompIndex = null;
		for (var i = 0; i < phoneInfo.length; i++)
		{
			phoneName = phoneInfo[i].split("~")[0];
			phoneCompIndex = phoneInfo[i].split("~")[1];
			comparisonContainers.containers[phoneCompIndex].currentProduct = allPhones.getPhoneByName(phoneName);
		}
	}

}

//for the interface for selecting phones that are to be compared
function renderOuterComparisonSelectionElements()
{
	var finalHtml = "";

	var compContainer = null;

	for (var k = 0; k < comparisonContainers.containers.length; k++)
	{
		compContainer = comparisonContainers.containers[k];

		finalHtml += 
			"<div class=\"comparisonSelectionProductContainer\" onmouseout=\"removeDropToAddMessages();\" id=\"" + compContainer.elementID + "\">" + 
			"</div>";
	}
	document.getElementById("comparisonSelectionPanel").innerHTML = finalHtml;
}

//for the interface for selecting phones that are to be compared
function renderComparisonSelectionElements()
{
	var finalHtml = "";

	var compContainer = null;

	for (var k = 0; k < comparisonContainers.containers.length; k++)
	{
		renderComparisonSelectionElement(comparisonContainers.containers[k]);
	}
}


//for the interface for selecting phones that are to be compared
function renderComparisonSelectionElement(compContainer)
{
	var finalHtml = "";
	if (compContainer.currentProduct == null)
	{
		finalHtml = "";
	}
	else
	{
		var template = document.getElementById("comparisonSelectionElementTemplate").innerHTML.replace(/&gt;/g, ">").replace(/&lt;/g, "<");
		var finalHtml = template;
		finalHtml = finalHtml.replace(/#container_id#/g, compContainer.elementID);
		finalHtml = finalHtml.replace(/#phone_name#/g, compContainer.currentProduct.name);
		finalHtml = finalHtml.replace(/#phone_price#/g, compContainer.currentProduct.price);
		finalHtml = finalHtml.replace(/#phone_url#/g, compContainer.currentProduct.shopUrl);
		finalHtml = finalHtml.replace(/#phoneimage_html#/g, "<img alt='test1' src='" + compContainer.currentProduct.imageUrlThumbnail + "'/>");
		finalHtml = finalHtml.replace(/#removephone_link#/g, "javascript:void(removeFromComparison('" + compContainer.elementID + "'));");
	}
	document.getElementById(compContainer.elementID).innerHTML = finalHtml;
}


