var str_help;
var pairs;
var asCookie;
var browser;
var pcnumber;
var sDateAndPath;
var nPCLength;


function pass_pc_code(target)
{
var the_target;
the_target = target;
the_target += "?" + pcnumber;
location=the_target;
}



//  ***NOTE no escaping has been done to any strings***
//  The path of the cookie has been changed to '/'.  The client may have a
//  pre-existing cookie without a path.  This cookie will not affect the
//      following revised script.

// Get string from path
str_help = window.location.search;
pcnumber = str_help.substring(1,str_help.length);


// Check if affiliate ID is in the correct range

if ((pcnumber.length < 5) || (pcnumber.length > 7))
{
    pcnumber = "";

    // Cookie should contain only one valid name-value pair
    asCookie = (document.cookie).split (";");

    for (i = 0; i < asCookie.length; i++)
    {
        pairs = asCookie [i].split ("=");
        if (pairs [0].indexOf ("id") != -1)
        {
            pcnumber = pairs [1];
        }
    }

    if (pcnumber)
    {
        nPCLength = pcnumber.length;
    }
    else
    {
        nPCLength = 0;
    }

    
    // Check if ID is within the acceptable range
    if (nPCLength < 5 || nPCLength > 7)
    {
        pcnumber = "32130";     // Default to Bear Trek
    }
}

sDateAndPath = "path=/;expires=Wednesday, 01-Jan-2020 00:00:01 GMT";

//document.write("Final PCNUMBER:" + pcnumber + "<br>");    //foo

// Write cookie (if other parameters are added, above parsing will need to be altered)
document.cookie = "id=" + pcnumber + ";" + sDateAndPath;

function TISnewWindow(page) {
OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no,scrollbars=yes,resize=yes,width=750,height=500");
}
function newWindow(page) {
OpenWin = this.open(page, "Popup", "toolbar=no,width=450,height=300,left=100,top=100,status=no,scrollbars=yes,resize=yes");
}
