var openWindows = new Array();

function tpPopUp(pUrl, pWinId, pProperties) {
	var windowProperties = pProperties;
	var windowId         = pWinId;

	if (windowProperties == "") {
	    windowProperties = "width=760,height=500,statusbar=no,scrollbars=yes,resizable=yes";
	}

	if (windowId == "") {
		windowId = "tpPopUp";
	}

	tpPopWin       = window.open(pUrl,windowId,windowProperties);
    openWindows[0] = tpPopWin;

	if (window.focus) {
		tpPopWin.focus();
	}
}

function goToAvailabilityChecker(pTrackingStr) {
	// Amended as part of CR-TP-2008-06-16 to remove redirected links into legacy availability checker page.
	// Now redirects to BB home page instead, meaning we won't break any legacy links in place that use this script
	//
    var url = "/time/broadbandaccess/";
    var trackerStr = "" + pTrackingStr;

    if (trackerStr != "" && trackerStr != "undefined") {
        url = url + "?" + trackerStr;
    }

    debug("goToAvailabilityChecker(): url = " + url);
    document.location.href = url;
}

function goToUrl(pUrl,pContext) {
	var contextualUrl = pUrl.split("#");
	var targetUrl     = contextualUrl[0];

	if (pContext) { // Append landing page file name to target URL
		targetUrl += "default_cd.htm";
	}

	if (contextualUrl.length > 1) { // Now append any named link to the target URL
		targetUrl += "#" + contextualUrl[1];
	}

	document.location.href = targetUrl;
}

function drawBackButton(pProdId) {
	var URL        = "";
	var imgRef     = "";
	var altText    = "click here to go back to Orange Home ";
	var btnLink    = "";
	var homeProdId = "";

	// Detect home product ID passed to this function via the querystring nvpair on
	// link into homephone or secondline page
	if (pProdId != "") {
		if      (pProdId.indexOf("max") != -1)     { homeProdId = "max"; }
		else if (pProdId.indexOf("select") != -1)  { homeProdId = "select"; }
		else if (pProdId.indexOf("starter") != -1) { homeProdId = "starter"; }

		// Set up the product-specific "back to..." button properties
		switch (homeProdId) {
			case "max":
				URL      = "/time/broadbandmax/";
				imgRef   = "/images/shared/buttons/back2max_btn.gif";
				altText += "Max";
				break;
			case "select":
				URL      = "/time/broadbandselect/";
				imgRef   = "/images/shared/buttons/back2select_btn.gif";
				altText += "Select";
				break;
			case "starter":
				URL      = "/time/broadbandstarter/";
				imgRef   = "/images/shared/buttons/back2starter_btn.gif";
				altText += "Starter";
				break;
			default:
		}

		// Construct the "back to..." button
		btnLink = "<a href=\"" + URL + "\"><img src=\"" + imgRef + "\" alt=\"" + altText + "\" /></a>";
		document.write(btnLink);
	}
}

function goToOrange()       { document.location.href="http://www.orange.co.uk"; }
function goToContactUs()    { document.location.href="http://www.orange.co.uk/aboutus/contactus"; }
function showUsageCalc()    { tpPopUp("/time/popup/usage.htm"); }
function showSpeedDemo()    { tpPopUp("/time/popup/speed.htm"); }
function showWirelessDemo() { tpPopUp("/time/popup/wireless.htm"); }
function showTalkDemo()     { tpPopUp('/time/popup/talk.htm'); }
function showExtras()       { tpPopUp("/time/popup/extras.htm"); }
function showSwitchPhone()  { tpPopUp("/time/popup/phone.htm"); }
function showTryBB()        { tpPopUp('/time/popup/trybroadband/'); }
function showModem()        { tpPopUp('/time/popup/modem.htm'); }
function showTalkFaqs()     { tpPopUp('/time/popup/talk_faq.htm'); }
function showMcAfee()       { tpPopUp('/time/popup/mcafee.htm'); }
function showTariffLinks()  { tpPopUp('http://download.orange.co.uk/talk/HomeVoicePriceGuideJan2009.pdf','tpTariffs','width=400,height=130,statusbar=no,scrollbars=yes,resizable=yes'); }
function showVatNote()      { tpPopUp('/time/popup/vat.htm','tpVatNote','width=790,height=480,statusbar=no,scrollbars=yes,resizable=yes'); }