// Tracking JS

function setTracking()
{
	var pageUrl      = window.location.href.replace("http://", "");
	
	if(!pageUrl.match(/sim-only/))
	{
		var urlParts     = pageUrl.split("/mobile-phones/");
		var urlPartsTwo  = urlParts[1].split("/");
		var handsetName  = urlPartsTwo[0];
		var section      = urlPartsTwo[1].replace(".html", "");
		var sectionParts = section.split("?");
	
		// This is to strip any query string.
		if(sectionParts.length != 1)
		{
			section = sectionParts[0];
		}
	
		var handsetType = document.getElementById("htype").value;
	
		var handsetTypeTag = '';
	
		if(handsetType == 'mbb')
		{
			handsetTypeTag = 'mbb';
		}
		else
		{
			handsetTypeTag = 'deal';
		}
	
		var trackingCode = '';
	
		if(section == 'description') {
			trackingCode = '/handset-page/' + handsetName;
		}
		else if(section == 'pay-monthly') {
			trackingCode = '/paym-' + handsetTypeTag + '-page/' + handsetName;
		}
		else if(section == 'pay-as-you-go') {
			trackingCode = '/payg-' + handsetTypeTag + '-page/' + handsetName;
		}
		else if(section == 'reviews') {
			trackingCode = '/reviews-page/' + handsetName;
		}
		else if(section == 'specifications') {
			trackingCode = '/specifications-page/' + handsetName;
		}
		else if(section == 'product-updates') {
			trackingCode = '/product-updates-page/' + handsetName;
		}
		
		urchinTracker(trackingCode);
	}
}

addLoadListener(setTracking);

var pageUrl = window.location.href.replace("http://", "");

if(pageUrl.match(/pay-monthly\.html/))
{
	if(!pageUrl.match(/description|specifications|reviews/))
	{
		$("#hpc").show();
	}
}

// Fix to show title in IE6.
if(identifyBrowser() == "ie6")
{
	$(".globalHeader").html($("#hpt").html());
}

/********** VIRTUAL PAGES (pay-monthly.html) **********/
$(document).ready(function()
{
	if(pageUrl.match(/mp=1/))	
	{
		$("#retailerSelectBox").css("display","none");
	}
	else
	{
		$("#retailerSelectBox").css("display","block");
	}
	
	if(pageUrl.match(/pay-monthly/))
	{
		// If any page view orders change this needs to change to reflect the new order!
		var pageMappings = new Array();
		pageMappings["Pay Monthly"] = 4;
		pageMappings["Description"] = 1;
		pageMappings["Specifications"] = 2;
		pageMappings["Reviews"] = 3;		
		
		var currentPageView = 4;
		
		$("#main_template_header ul li a").click(function()
		{	
			var clickText = $(this).text();
			var currentText = $(".current_state").text();
			var temp = "";
			
			temp = currentText.substring(0,7);		
			
			if(temp == "Reviews")
			{
				currentText = "Reviews";
			}
			
			currentPageView = pageMappings[currentText];
			
			if(currentPageView == undefined)
			{				
				currentPageView = 4;
			}					
			
			temp = clickText.substring(0,7);
			
			if(temp == "Reviews")
			{
				clickText = "Reviews";
			}			
			
			var chosenPageId = pageMappings[clickText];				
			
			if(chosenPageId != currentPageView)
			{					
				$("#main_template_header ul li a").removeClass("current_state");
				$(this).addClass("current_state");
				$("#page" + currentPageView).hide();			
				$("#hpc").hide();
				
				$("#page" + chosenPageId).fadeIn();
				
				if(chosenPageId == 4)
				{
					$("#hpc").fadeIn();
				}
				
				currentPageView = chosenPageId;
				
				if($(this).text() == "Pay Monthly")
				{	
					setDealPagenationLinks();
				}
				else if($(this).text() == "Reviews")
				{
					setReviewsPagenationLinks();
				}
			}
			
			return false;
		});
	
		setDealPagenationLinks();
	}
	else if(pageUrl.match(/reviews/))
	{
		setReviewsPagenationLinks();
	}
});
/********** VIRTUAL PAGES END (pay-monthly.html) **********/