//This checks if there is a "promotion" query string.  If there is it will 
//set the promotionCode var = promotion query string
var qs = window.location.search.substring(1);
var promotionCode = "";
if (qs.indexOf("promotion") > -1) 
{
    promotionCode = qs.substring(qs.indexOf("promotion") + 10);
}

//This checks if there is a "promotion" query string.  If there is it will 
//set the promotionCode var = promotion query string
var campaignCode = "";
if (qs.indexOf("campaign") > -1) {
    campaignCode = qs.substring(qs.indexOf("campaign") + 9);
}

//When the Apply Online link is clicked this method will be called.  It will check
//whether the main page has received a promotion code.  If it has, it will build that
//into the link for calling the buy online page and fire off the popup.
//pageCode: G=GSP, I=ISA, U=UT, T=TFSP
function BuildApplyOnlineLink(productType) 
{
    productType = productType.toUpperCase();

    //Set the name of the buy online aspx page to redirect to based on the 
    //product type character passed in
    if (productType == "T") 
    {
        //TFSP
        webPage = "tesp.aspx"
    }
    else if (productType == "G") 
    {
        //GSP
        webPage = "gsp.aspx"
    }
    else if (productType == "I") 
    {
        //ISA    
        webPage = "isa.aspx"
    }
    else if (productType == "U") 
    {
        //UT
        webPage = "ut.aspx"
    }
    
    var qsPromo = "";
    if (promotionCode.length > 0) 
    {
        qsPromo = "?promotion=" + promotionCode;
    }
    
    openWindow('webx', webPage + qsPromo, '', 'width=1000,height=540,scrollbars=no,resizable=no');
    return false;
}

//This section handles contact forms and will do the same as the above method.
//However, these are dealt with via a "campaign" querystring rather than a
//"promotion" querystring as above.  Hence the separate method.
//It whether the main page has received a campaign code.  If it has, it will build that
//into the link for calling the contact page and fire off the popup.
//pageCode: H=GB
function BuildContactLink(contactType) 
{
    contactType = contactType.toUpperCase();

    //Set the name of the buy online aspx page to redirect to based on the 
    //product type character passed in
    if (contactType == "H") {
        //GB QUOTE
        webPage = "contactgbquote.aspx"
    }

    var qsPromo = "";
    if (promotionCode.length > 0) {
        qsPromo = "?campaign=" + promotionCode;
    }

    openWindow('webx', webPage + qsPromo, '', 'toolbar=no,status=no,menubar=no,resizable=no,scrollbars=yes,width=600,height=600,top=100,left=100');
    return false;
}

//This section handles contact forms and will do the same as the above method.
//However, these are dealt with via a "campaign" querystring rather than a
//"promotion" querystring as above.  Hence the separate method.
//It whether the main page has received a campaign code.  If it has, it will build that
//into the link for calling the contact page and fire off the popup.
//pageCode: H=GB
function BuildStaticPageLink(productType) 
{
    productType = productType.toUpperCase();

    //Set the name of the buy online aspx page to redirect to based on the 
    //product type character passed in
    if (productType == "T") 
    {
        //TFSP
        webPage = "savings_tax_free.shtml";
    }
    else if (productType == "G") 
    {
        //GSP
        webPage = "savings_guaranteed.shtml";
    }
    else if (productType == "I") 
    {
        //ISA
        webPage = "tax_free_isa.shtml";
    }
    else if (productType == "U") 
    {
        //UT
        webPage = "savings_unit_trust.shtml";
    }

    var qsPromo = "";
    if (promotionCode.length > 0) {
        qsPromo = "?promotion=" + promotionCode;
    }

    document.location.href = webPage + qsPromo;
    return false;
}
