/*
 * <%-- $Author: powem $ --%>
 * <%-- $Date: 2009/11/09 04:20:48 $ --%>
 * <%-- $Revision: 1.7 $ --%>
 * 
 * Based on global.js:
 * <%-- Date: 2009/10/28 17:02:00  --%>
 * <%-- Revision: 1.18  --%>
 *
 * tracking functions for merck.com and Merck manuals
 * These functions are intended to work in tandem with WebTrends code
 * version 8.5 or later.
 *
 */

function MerckTracker(){
    /*
     * Modify these if necessary
     */
    this.downloadtypes="xls,doc,pdf,txt,csv,zip";
    this.audiotypes="wma,mp3,m4a";
    this.videotypes="wmv,flv";
    this.WT = this.DCS = this.DCSext = null;
    this.prodSitesArray = new Array();
    this.searchCookieName = "OSS";
    this.searchCookieCrumb = "term";
    this.mainSearchPage = "userSearch.do";
    this.mmSearchPage = "search.html";
    this.mmProPagesCg = new RegExp(/\/mmpe\/|\/mkgr\//);
    this.mmConsPagesCg = new RegExp(/\/mmhe\/|\/mmanual_ha\//);
    this.mmConsPagesSgHome = new RegExp(/\/mmhe\//);
    this.mmConsPagesSgHA = new RegExp(/\/mmanual_ha\//);
    this.mmProPagesSgPhy = new RegExp(/\/mmpe\//);
    this.mmProPagesSgGer = new RegExp(/\/mkgr\//);

    // Private members
    //var productsXML = "mercksites.xml";
    /*
     * End user modifiable options
     */
    var that = this;
    
    this.wt = {};
    this.dcs = {};

    /*
     * Helper function to add a meta element to the page
     * this is a privileged function, meaning it is not a public method but is
     * available to any public instance methods and can see private data.
     *
     */
    this.mtAddMeta=function(name,content){

        var mtMeta = document.createElement('meta');
        mtMeta.name = name;
        mtMeta.content = content;
        document.getElementsByTagName('head').item(0).appendChild(mtMeta);
    }

    /*
     * Determine if an href belongs to an identified product site
     *
     */
    this.mtIsProductSiteLink=function(prodSitesArray,site){
        var sites = prodSitesArray;
        var isSite = false;
        for(var i=0;i<sites.length;i++){
            if(site.indexOf(sites[i]) != -1){
                isSite=true;
                break;
            }
        }
        return isSite;
    }

    /*
     * Determine if an href belongs to an identified video site
     *
     */
    this.mtIsVideoSiteLink=function(videoSitesArray,site){
        var sites = videoSitesArray;
        var isSite = false;
        for(var i=0;i<sites.length;i++){
            if(site.indexOf(sites[i]) != -1){
                isSite=true;
                break;
            }
        }
        return isSite;
    }
    /*
     * back up current WT object properties like this:
     * this.mtSaveWT(_tag.WT,this.wt);
     * this.mtSaveWT(_tag.DCS,this.dcs);
     */
    this.mtSaveWT=function(obj,bu){
        for(var prop in obj){
            bu[prop] = obj[prop];
        }
    }

    /*
     * Restore current WT object properties like this:
     * this.mtRestoreWT(_tag.WT,this.wt);
     */
    this.mtRestoreWT=function(obj,bu){
        for(var prop in bu){
            obj[prop] = bu[prop];
        }
    }

    /*
     * Reads the specified XML file to get the collection of sites that are to be considered
     * Merck product sites
     *
     */
    this.mtGetProductSitesXML=function(){
        var i = 0;
        var siteId;
        var site;
        var domain;
        var ps = new Object();
        $.ajax({
            type: "GET",
            url: productsXML,
            dataType: "xml",
            success: function(xml) {
                $(xml).find('site').each(function(){
                    siteId = $(this).attr('id');
                    site = $(this).find('name').text();
                    domain = $(this).find('domain').text();
                    that.prodSitesArray[i++] = domain;
                });

            }

        }); // end ajax

    }
    this.mtGetProductSitesJSON=function(){
        var i = 0;
        for (var site in productSites){
            if(!productSites.hasOwnProperty(site)){
                continue;
            }
            this.prodSitesArray[i] = productSites[site];
            i++;
        }

    }

    // these are for the distinct pages tracking, to construct hashed identifiers
    // written by David Smith, Technology Leaders, LLC

    this.CrcArcTab = new Array(
        0x0000,0xC0C1,0xC181,0x0140,0xC301,0x03C0,0x0280,0xC241,0xC601,0x06C0,0x0780,0xC741,0x0500,
        0xC5C1,0xC481,0x0440,0xCC01,0x0CC0,0x0D80,0xCD41,0x0F00,0xCFC1,0xCE81,0x0E40,0x0A00,0xCAC1,
        0xCB81,0x0B40,0xC901,0x09C0,0x0880,0xC841,0xD801,0x18C0,0x1980,0xD941,0x1B00,0xDBC1,0xDA81,
        0x1A40,0x1E00,0xDEC1,0xDF81,0x1F40,0xDD01,0x1DC0,0x1C80,0xDC41,0x1400,0xD4C1,0xD581,0x1540,
        0xD701,0x17C0,0x1680,0xD641,0xD201,0x12C0,0x1380,0xD341,0x1100,0xD1C1,0xD081,0x1040,0xF001,
        0x30C0,0x3180,0xF141,0x3300,0xF3C1,0xF281,0x3240,0x3600,0xF6C1,0xF781,0x3740,0xF501,0x35C0,
        0x3480,0xF441,0x3C00,0xFCC1,0xFD81,0x3D40,0xFF01,0x3FC0,0x3E80,0xFE41,0xFA01,0x3AC0,0x3B80,
        0xFB41,0x3900,0xF9C1,0xF881,0x3840,0x2800,0xE8C1,0xE981,0x2940,0xEB01,0x2BC0,0x2A80,0xEA41,
        0xEE01,0x2EC0,0x2F80,0xEF41,0x2D00,0xEDC1,0xEC81,0x2C40,0xE401,0x24C0,0x2580,0xE541,0x2700,
        0xE7C1,0xE681,0x2640,0x2200,0xE2C1,0xE381,0x2340,0xE101,0x21C0,0x2080,0xE041,0xA001,0x60C0,
        0x6180,0xA141,0x6300,0xA3C1,0xA281,0x6240,0x6600,0xA6C1,0xA781,0x6740,0xA501,0x65C0,0x6480,
        0xA441,0x6C00,0xACC1,0xAD81,0x6D40,0xAF01,0x6FC0,0x6E80,0xAE41,0xAA01,0x6AC0,0x6B80,0xAB41,
        0x6900,0xA9C1,0xA881,0x6840,0x7800,0xB8C1,0xB981,0x7940,0xBB01,0x7BC0,0x7A80,0xBA41,0xBE01,
        0x7EC0,0x7F80,0xBF41,0x7D00,0xBDC1,0xBC81,0x7C40,0xB401,0x74C0,0x7580,0xB541,0x7700,0xB7C1,
        0xB681,0x7640,0x7200,0xB2C1,0xB381,0x7340,0xB101,0x71C0,0x7080,0xB041,0x5000,0x90C1,0x9181,
        0x5140,0x9301,0x53C0,0x5280,0x9241,0x9601,0x56C0,0x5780,0x9741,0x5500,0x95C1,0x9481,0x5440,
        0x9C01,0x5CC0,0x5D80,0x9D41,0x5F00,0x9FC1,0x9E81,0x5E40,0x5A00,0x9AC1,0x9B81,0x5B40,0x9901,
        0x59C0,0x5880,0x9841,0x8801,0x48C0,0x4980,0x8941,0x4B00,0x8BC1,0x8A81,0x4A40,0x4E00,0x8EC1,
        0x8F81,0x4F40,0x8D01,0x4DC0,0x4C80,0x8C41,0x4400,0x84C1,0x8581,0x4540,0x8701,0x47C0,0x4680,
        0x8641,0x8201,0x42C0,0x4380,0x8341,0x4100,0x81C1,0x8081,0x4040);

    // written by David Smith, a helper function for the unique pages tracking
    this.mtCrc16=function (str)   {
        var c;
        var crc=0;
        for (var n=0; n< str.length; n++)  {
            c = str.charCodeAt(n);
            crc= ((crc>>8)&0xFF)^this.CrcArcTab[(crc^c)&0xFF];
        }
        return crc.toString(32).toUpperCase();
    }

    /*
     * Private method calls
     */
    this.mtGetProductSitesJSON();

} // end constructor


/*
 * WT.dl=31 is a product site click.  This is a special category of
 * offsite click that is a site that belongs to Merck but not identifiable
 * by the Merck name.
 *
 */

MerckTracker.prototype.mtFlagProductSiteClick=function(){

    var save = this.mtSaveWT;
    var restore = this.mtRestoreWT;
    var wt = this.wt;
    var dcs = this.dcs;

    var ps = this.prodSitesArray;
    var site = "";
    for(var i = 0; i < ps.length; i++){
        var h = "a[href*="+ps[i]+"]";
        $().find(h).unbind('click');
        $().find(h).bind('click',function(){

            save(_tag.WT,wt);
            save(_tag.DCS,dcs);

            var thisUrl = $.url.setUrl(this.href);
            var site = $.url.attr("host");
            _tag.dcsMultiTrack("DCS.dcssip",site,'DCS.dcsqry','','DCS.dcsuri',this.pathname,
                'WT.ti',"Link to Product Site: " +site,'WT.dl','31','WT.pi','Product Site Click');
            restore(_tag.WT,wt);
            restore(_tag.DCS,dcs);

        });
    }
}

/*
 * Returns true if the hostname has 'merck.com' in it
 * 
 */
MerckTracker.prototype.mtIsMerckSite=function(site){
    var isSite = false;
    if(site.indexOf("merck.com") != -1){
        isSite = true;
    }
    return isSite;
}

/*
 * Track clicks out of manuals back into main merck site
 * WT.z_merck=1
 *
 */

MerckTracker.prototype.mtOnSiteClick=function(){

    var siteRegex = new RegExp(/mmpe|mmhe|mmanual_ha|mkgr|redirector.pl/);

    var save = this.mtSaveWT;
    var restore = this.mtRestoreWT;
    var wt = this.wt;
    var dcs = this.dcs;

    $('a[href*=merck]').each(function(){

        if(siteRegex.test($(this).attr('href')) == false){
            $(this).click(function(){

                save(_tag.WT,wt);
                save(_tag.DCS,dcs);
                _tag.dcsMultiTrack('DCS.dcsqry','','DCS.dcsuri',this.pathname,'WT.ti',this.innerHTML,
                    'WT.z_merck','1','WT.pi','Merck Main Site');
                WT.z_merck="";
                restore(_tag.WT,wt);
                restore(_tag.DCS,dcs);
            });
        }
    });
}

/*
 * Run after WT code loads
 * a download is defined by WT.dl=20
 *
 */
MerckTracker.prototype.mtFlagDownloadClick=function(){
    var save = this.mtSaveWT;
    var restore = this.mtRestoreWT;
    var wt = this.wt;
    var dcs = this.dcs;
    $('a[href$=.pdf],a[href$=.doc],a[href$=.zip]').unbind('click', _tag.dcsDownload);
    $('a[href$=.pdf],a[href$=.doc],a[href$=.zip]').click(function(){
        save(_tag.WT,wt);
        save(_tag.DCS,dcs);
        var hn = this.hostname;
        if(_tag.WT.oss.length>0){
            _tag.WT.oss_s='1';
            _tag.WT.oss="";
            _tag.WT.oss_r="";
        }
        _tag.dcsMultiTrack("DCS.dcssip",hn,'DCS.dcsqry','','WT.dl','20','DCS.dcsuri',this.pathname,'WT.ti',
            "Download: "+this.innerHTML,'WT.pi','Downloads');
        restore(_tag.WT,wt);
        restore(_tag.DCS,dcs);
    });
}

/*
 * Run after WT code loads
 * An audio play is defined by WT.dl=33 for merck.com
 * and WT.dl=35 for manuals
 *
 */

MerckTracker.prototype.mtFlagAudioClick=function(site){

    var save = this.mtSaveWT;
    var restore = this.mtRestoreWT;
    var wt = this.wt;
    var dcs = this.dcs;

    switch(site){

        case "merck" :

            $('a[href$=.mp3],a[href$=.m4a]').click(function(){
                save(_tag.WT,wt);
                save(_tag.DCS,dcs);

                var hr = this.pathname;
                var hn = this.hostname;
                var tName = hr.split("/");
                var title = "Audio: "+ tName[tName.length-1];
                _tag.dcsMultiTrack("DCS.dcssip",hn,'DCS.dcsqry','','WT.dl','33','DCS.dcsuri',hr,'WT.ti',title,
                    'WT.pi','Audio Play');

            });
            break;

        case "manuals" :

            $('a[href$=.mp3],a[href$=.m4a]').click(function(){

                save(_tag.WT,wt);
                save(_tag.DCS,dcs);

                var hr = this.pathname;
                var hn = this.hostname;
                var tName = hr.split("/");
                var title = "Audio: "+ tName[tName.length-1];
                _tag.dcsMultiTrack("DCS.dcssip",hn,'DCS.dcsqry','','WT.dl','35','DCS.dcsuri',hr,'WT.ti',title,
                    'WT.pi','Audio Play');

                restore(_tag.WT,wt);
                restore(_tag.DCS,dcs);
            });

            if(window.location.pathname.indexOf('/resources/multimedia/name/audio.html') != -1){
                $('a[href$=x.html]').click(function(){
                    save(_tag.WT,wt);
                    save(_tag.DCS,dcs);
                    _tag.dcsMultiTrack('DCS.dcsqry','','DCS.dcsuri',this.pathname,'WT.ti','Audio: '+this.innerHTML,
                        'WT.dl','35','WT.pi','Audio Play');
                    restore(_tag.WT,wt);
                    restore(_tag.DCS,dcs);
                });
            }
            break;
    }

}

MerckTracker.prototype.mtFlagItunesClick=function(){

    var save = this.mtSaveWT;
    var restore = this.mtRestoreWT;
    var wt = this.wt;
    var dcs = this.dcs;

    $('a:contains("Subscribe via iTunes")').click(function(){

        save(_tag.WT,wt);
        save(_tag.DCS,dcs);

        _tag.dcsMultiTrack('DCS.dcsqry','','DCS.dcsuri',this.href.split("url=")[1],'WT.ti',this.innerHTML,
            'WT.dl','39','WT.pi','Subscribe');

        restore(_tag.WT,wt);
        restore(_tag.DCS,dcs);

    });

}

/*
 * WT.z_lexi=1
 * Run this before WebTrends code runs
 */
MerckTracker.prototype.mtFlagLexiCompPage=function(){

    if(window.location.href.indexOf("lexicomp") == -1){
        return;
    }

    this.mtAddMeta("WT.z_lexi", "1");
}

/*
 * Run after WT code loads
 * WT.dl=34
 *
 */

MerckTracker.prototype.mtFlagVideoClick=function(){

    var save = this.mtSaveWT;
    var restore = this.mtRestoreWT;
    var wt = this.wt;
    var dcs = this.dcs;

    $().find('a[href^=http://www.careertv.com][href*=VideoID]').click(function(){

        save(_tag.WT,wt);
        save(_tag.DCS,dcs);

        var hn = this.hostname;
        _tag.dcsMultiTrack("DCS.dcssip",hn,'DCS.dcsqry','','WT.dl','34','DCS.dcsuri',this.pathname,'WT.ti',
            "Video: "+this.innerHTML,'WT.pi','Video Play');
        restore(_tag.WT,wt);
        restore(_tag.DCS,dcs);
    });

    $().find('a[href^=http://get.adobe.com/flashplayer]').click(function(){

        save(_tag.WT,wt);
        save(_tag.DCS,dcs);

        var title = $(this).find('img').attr('alt');
        var hn = this.hostname;
        _tag.dcsMultiTrack("DCS.dcssip",hn,'DCS.dcsqry','','WT.dl','34','DCS.dcsuri',this.pathname,'WT.ti',"Video: "+title,
            'WT.pi','Video Play');
        restore(_tag.WT,wt);
        restore(_tag.DCS,dcs);
    });


    $('a[href$=.flv],a[href$=.wmv]').click(function(){

        save(_tag.WT,wt);
        save(_tag.DCS,dcs);

        _tag.dcsMultiTrack('DCS.dcsqry','','WT.dl','34','DCS.dcsuri',this.pathname,'WT.ti',"Video: "+this.innerHTML,
            'WT.pi','Video Play');
        restore(_tag.WT,wt);
        restore(_tag.DCS,dcs);
    });

    if(window.location.pathname.indexOf('/resources/multimedia/name/video.html') != -1){
        $('a[href$=x.html]').click(function(){

            save(_tag.WT,wt);
            save(_tag.DCS,dcs);

            _tag.dcsMultiTrack('DCS.dcsqry','','DCS.dcsuri',this.pathname,'WT.ti','Video: '+this.innerHTML,
                'WT.dl','36','WT.pi','Video Play');
            restore(_tag.WT,wt);
            restore(_tag.DCS,dcs);
        });
    }

}

/*
 * Run after WT code loads
 * set the site to "merck" for the main site or "manuals" for Merck Manuals
 * No javascript on share-site.html at this time.
 * For manuals, email a topic page.
 *
 */
MerckTracker.prototype.mtFlagEmailClick=function(site){
    var save = this.mtSaveWT;
    var restore = this.mtRestoreWT;
    var wt = this.wt;
    var dcs = this.dcs;

    switch(site){
        case "manuals" :
            $().find('a[href*=emailpage]').unbind('click');
            $().find('a[href*=emailpage]').click(function(){

                save(_tag.WT,wt);
                save(_tag.DCS,dcs);

                _tag.dcsMultiTrack('DCS.dcsqry','','DCS.dcsuri',window.location,'WT.ti',
                    "Email: " + document.title,'WT.z_cont','1','WT.z_email','1','WT.pi','Content Email');
                restore(_tag.WT,wt);
                restore(_tag.DCS,dcs);
            });

            break;
        case "merck" :

            $('a:contains("Share")').click(function(){

                save(_tag.WT,wt);
                save(_tag.DCS,dcs);

                _tag.dcsMultiTrack('DCS.dcsqry','','DCS.dcsuri',window.location,'WT.ti',document.title,
                    'WT.z_email','1','WT.z_cont','1','WT.pi','Content Email');
                restore(_tag.WT,wt);
                restore(_tag.DCS,dcs);
            });
            /*
            if($.url.attr('path').indexOf('share-site.html') != -1){
                $(':submit').click(function(){
                    _tag.dcsMultiTrack('DCS.dcsuri',window.location,'WT.ti',document.title,'WT.z_email','1');
                });
            } else if ($.url.attr('path').indexOf('/contact/home.html') != -1){
                $('ul.utility-buttons li.shareButton a').click(function(){
                    _tag.dcsMultiTrack('DCS.dcsuri',window.location,'WT.ti',"Email: Contact Page",'WT.z_email','1');
                });
            }
            */

            break;
    }
}

/*
 * Run before WT code runs
 * WT.z_topic=1 to count topic page views
 *
 */
MerckTracker.prototype.mtFlagTopicPage=function(){

    var topic = $('p:contains("Topics")').length > 0 ? true : false;

    if(topic == false){
        return;
    }
    this.mtAddMeta("WT.z_topic", "1");
}

/*
* Run before WT data collector
* Doesn't matter if WT code is loaded
* Sets meta tags for content groups and subgroups by parsing the directory
* structure at the top 2 levels for merck.com and by identifying the manuals
* for Merck Manuals
* Also, sets WT.z_manual to the name of the manual if we're in a manual page
*
*/
MerckTracker.prototype.mtSetContentGroups=function(site){

    var cg = "";
    var sg = "";
    var href = window.location.href;

    switch(site){

        case "merck" :

            cg = ($.url.segment(0) == null) ? "Home" : $.url.segment(0);
            sg = ($.url.segment(1) == null) ? "" : $.url.segment(1);

            break;

        case "manuals" :
            var mmCgConName = "Patients & Caregivers";
            var mmCgPhyName = "Healthcare Professionals";

            var mmSgHome = "Merck Manual: Home Edition";
            var mmSgHA = "Merck Manual: Health & Aging";
            var mmSgPro = "Merck Manual of Diagnosis and Therapy";
            var mmSgGr = "Merck Manual of Geriatrics";

            var manualParam = "WT.z_manual";

            if(this.mmConsPagesCg.test(href) == true){
                cg = mmCgConName;
                sg = (this.mmConsPagesSgHome.test(href) == true) ? mmSgHome : "";
                if(sg==""){
                    sg = (this.mmConsPagesSgHA.test(href) == true) ? mmSgHA : "";
                }
            } else if(this.mmProPagesCg.test(href) == true){
                cg = mmCgPhyName;
                sg = (this.mmProPagesSgPhy.test(href) == true) ? mmSgPro : "";
                sg = ((sg="") && this.mmProPagesSgGer.test(href) == true) ? mmSgGr : "";
            }
            // if the subgroup is nonempty, then it's the name of a manual, so
            // set the name here
            if(sg != ""){
                this.mtAddMeta(manualParam, sg);
            }
            break;
    } // end switch

    this.mtAddMeta('WT.cg_n', cg);
    this.mtAddMeta('WT.cg_s', sg);
}

/*
* Doesn't matter if WT code is loaded
* set page real estate flags on the home page
*
*/
MerckTracker.prototype.mtSetNavigation=function(){

    var isHome = $.url.segment(0) == null ? true : false;

    if (isHome == false){
        return;
    }
    $('ul.sitemap  a').each(function(m){
        $(this).attr('href', $(this).attr('href')+"?WT.svl=footer");
    });

    $('ul.homeCols a:not(.arrow)').each(function(a){
        $(this).attr('href', $(this).attr('href')+"?WT.svl=content&WT.pi=content+Views");
    });

    $('a.arrow').each(function(m){
        $(this).attr('href', $(this).attr('href')+"?WT.svl=content");
    });


    $( "ul.topNav a").each(function(m){
        $(this).attr('href', $(this).attr('href')+"?WT.svl=topnav");
    });

    $("div.globalNav a").each(function(m){
        $(this).attr('href',$(this).attr('href')+"?WT.svl=mainnav");
    });
}
/*
 * Run before WT code runs, because it sets a meta tag.
 * Sets WT.z_subject to the subject specified on the page
 *
 * Modified to add section name along with subject and also
 * modified to set section name on the section link that clicks back to the top
 * level page.  mp - 11/4/09
 *
 */
MerckTracker.prototype.mtSetSubject=function(){

    var isSubject = $('td.bcrumbTitleCell:contains("Subject")').length > 0? true : false;

    if(isSubject == false){
        return;
    }
    var subjectParam = "WT.z_subject";
    var subjectName = $('td.bcrumbTitleCell:contains("Subject")').next('td').next('td').find('a').html();

    var sectionParam = "WT.z_section";
    var sectionName  = $('td.bcrumbTitleCell:contains("Section")').next('td').next('td').find('a').html();

    $('td.bcrumbTitleCell:contains("Section")').next('td').next('td').find('a').each(function(){
        $(this).attr('href', $(this).attr('href')+"?WT.z_section="+$(this).html())
    });

    this.mtAddMeta(sectionParam, sectionName);
    this.mtAddMeta(subjectParam, subjectName);
}

/*
 * Run before the WT code, this sets a meta tag
 * Sets WT.z_resourceSection to the name of the topic, type or drawing specified
 * as 'current' on a resources page.
 *
 */
MerckTracker.prototype.mtSetResourceTopic=function(){

    var locRe = new RegExp(/\/mmhe\/(resources|appendices|about)\//);
    if(locRe.test(window.location.href) == false){
        return;
    }

    if($('a.plsLink') != null){
        $('a.plsLink').each(function(){
            $(this).attr('href',$(this).attr('href')+'WT.z_resource='+$.query()['WT.z_resource'])
        });
    }

    var resourceTopicParam = "WT.z_resourceSection";
    var isTopic = $('td.bcrumbTitleCell:contains("Topics")').length > 0 ? true : false;
    var isType  = $('p.bcrumbLabel:contains("Types")').length > 0 ? true : false;
    var isDrawing = $('td.bcrumbTitleCell:contains("Drawings")').length > 0 ? true : false;
    var topic = "";
    if (isTopic == true){
        topic = $('td.bcrumbTitleCell:contains("Topics")').next('td').next('td').find('a.current').html();

        $('td.bcrumbTitleCell:contains("Topics")').next('td').next('td').find('a.bcLink').each(function(){
            $(this).attr('href', $(this).attr('href')+"?WT.z_resource="+$.query()['WT.z_resource']);
        });
        $('p.bcrumbLabel:contains("Resource")').parent().next().next().find('a').each(function(){
            $(this).attr('href', $(this).attr('href')+"?WT.z_resource="+$.query()['WT.z_resource']);
        });
    } else if(isType == true) {
        topic = $('p.bcrumbLabel:contains("Types")').next('td').next('td').find('a.current').html();
        
        $('p.bcrumbLabel:contains("Type")').parent().next().next().children().find('a.bcLink').each(function(){
            $(this).attr('href', $(this).attr('href')+"?WT.z_resource="+$.query()['WT.z_resource']);
        });
    } else if (isDrawing == true){
        topic = $('td.bcrumbTitleCell:contains("Drawings")').next('td').next('td').find('a.current').html();

        // flag top level resource links with resource name to carry it on click through
        jQuery('a.MMchapterLnk').each(function(){
            $(this).attr('href', $(this).attr('href')+"?WT.z_resource="+$.query()['WT.z_resource'])
        });
        // flag bread crumb links on the individual topic pages so that clicks carry the resource title
        // with them
        $('td.bcrumbTitleCell:contains("Drawings")').next('td').next('td').find('a.bcLink').each(function(){
            $(this).attr('href',$(this).attr('href')+'?WT.z_resource='+$.query()['WT.z_resource'])
        });
    } else {
        topic = "";
    }
    this.mtAddMeta(resourceTopicParam, topic);
}

/*
* Run after WT code is loaded
* set WT.z_print=1 for clicks to printable view
*
*/
MerckTracker.prototype.mtFlagPrintClick=function(site){

    var save = this.mtSaveWT;
    var restore = this.mtRestoreWT;
    var wt = this.wt;
    var dcs = this.dcs;

    switch(site){

        case "merck" :

            if (location.pathname.indexOf("printer-friendly.html") != -1){
                this.mtAddMeta("WT.z_print", "1");
            }

            $('a:contains("Print")').click(function(){

                save(_tag.WT,wt);
                save(_tag.DCS,dcs);

                _tag.dcsMultiTrack('DCS.dcsqry','','DCS.dcsuri',this.pathname,
                    'WT.ti',"Print Topic: " + document.title,'WT.z_cont','1','WT.z_print','1',
                    'WT.pi','Content Print');
                restore(_tag.WT,wt);
                restore(_tag.DCS,dcs);
            });

            break;

        case "manuals" :
            $('a[href*=/print/]').click(function(){

                save(_tag.WT,wt);
                save(_tag.DCS,dcs);

                _tag.dcsMultiTrack('DCS.dcsqry','','DCS.dcsuri',this.pathname,'WT.ti',
                    "Print Topic: " + document.title,'WT.z_print','1','WT.z_cont','1',
                    'WT.z_print','1','WT.pi','Content Print');
                restore(_tag.WT,wt);
                restore(_tag.DCS,dcs);
            });

            break;
    }

}

/*
 * WT.dl=35
 * These clicks actually go off site to merckbooks via a redirector.
 * This may be out of date -- mp 11/8/2009
 * 
 */
MerckTracker.prototype.mtFlagPdaClick=function(){

    var save = this.mtSaveWT;
    var restore = this.mtRestoreWT;
    var wt = this.wt;
    var dcs = this.dcs;

    $('a[href$=PDA.html]').click(function(){

        save(_tag.WT,wt);
        save(_tag.DCS,dcs);

        _tag.dcsMultiTrack('DCS.dcsqry','','DCS.dcsuri',this.pathname,'WT.ti',"PDA: "+document.title,
            'WT.dl','38','WT.pi','Merck Books Click');
        restore(_tag.WT,wt);
        restore(_tag.DCS,dcs);
    });
}

/*
 * WT.z_alert=1
 *
 */
MerckTracker.prototype.mtFlagAlertSubscribeClick=function(){
    var save = this.mtSaveWT;
    var restore = this.mtRestoreWT;
    var wt = this.wt;
    var dcs = this.dcs;
    $('a[href$=email_alert.html]').click(function(){
        save(_tag.WT,wt);
        save(_tag.DCS,dcs);
        _tag.dcsMultiTrack('DCS.dcsqry','','DCS.dcsuri',this.pathname,'WT.ti',"Alert:  Subscription",
            'WT.z_alert','1','WT.pi','Alert Subscribe');
        restore(_tag.WT,wt);
        restore(_tag.DCS,dcs);
    });
    $(':image[name=Subscribe]').click(function(){
        save(_tag.WT,wt);
        save(_tag.DCS,dcs);
        _tag.dcsMultiTrack('DCS.dcsqry','','DCS.dcsuri',window.location,'WT.ti',"Alert:  Subscription",
            'WT.z_alert','1','WT.pi','Alert Subscribe');
        restore(_tag.WT,wt);
        restore(_tag.DCS,dcs);
    });

}

/*
* Run after WT code is loaded and has run.
* This function depends on the previous running of WebTrends code,
* in order to set the object property WT.vg_f_s
* Tracks whether or not a page loaded is the first page of visit or subsequent page
*/
MerckTracker.prototype.mtBounceCheck=function(){

    // check for first page bounce
    if(typeof _tag.WT.vt_f_s == "undefined") {
        _tag.WT.z_bounces = "0";
    } else if (_tag.WT.vt_f_s == "1" ) {
        _tag.WT.z_bounces = "1";
    } else if (_tag.WT.vt_f_s == "" || _tag.WT.vt_f_s == 0 ) {
        _tag.WT.z_bounces = "0";
    }
}

MerckTracker.prototype.mtIsSiteSearch=function(){
    var isSearch = false;
    if((location.href).indexOf(this.mainSearchPage) != -1 ||
        (location.href).indexOf(this.mmSearchPage) != -1){
        isSearch = true;
        this.mtAddMeta("WT.pi", "Searches");
    }
    return isSearch;
}

/*
* Run after WT coded is loaded
* Flags search results clicks so we can track clicks on them
* WT.oss_s=1 flags a "successful" search, meaning that a search result
* was clicked
*/
MerckTracker.prototype.mtMainTrackSearchClick=function(){
    if(!this.mtIsSiteSearch()){
        return;
    }

    var downloadRegex = new RegExp(/pdf|doc|zip/);

    _tag.WT.oss=$.query()['strSearchTerm'];
    _tag.WT.oss_r=$('div#searchcontainer').next('b').html();
    _tag.WT.oss_r = (_tag.WT.oss_r == null) ? "0" : _tag.WT.oss_r;

    var ossSuccess = "1";

    var save = this.mtSaveWT;
    var restore = this.mtRestoreWT;
    var wt = this.wt;
    var dcs = this.dcs;

    var sCName = this.searchCookieName;
    var sCCrumb = this.searchCookieCrumb;

    $.Jookie.Initialise(sCName, "-1");
    var cookieValue = $.Jookie.Get(sCName,sCCrumb);
    if(cookieValue == null || cookieValue == "undefined"){
        $.Jookie.Initialise(sCName, "-1");
        $.Jookie.Set(sCName, sCCrumb, _tag.WT.oss);
    }else if(cookieValue.indexOf(_tag.WT.oss) == -1){
        cookieValue += ";" + _tag.WT.oss;
        $.Jookie.Set(sCName, sCCrumb, cookieValue);
    } else {
    }

    $('div#columnCenter table a[href]').click(function(){


        var hr = this.pathname;
        var title = this.innerHTML;
        
        if (downloadRegex.test(hr) == true){
            _tag.WT.pi="Successful Searches";
            _tag.WT.oss_s=ossSuccess;
            return;
        }
        
        save(_tag.WT,wt);
        save(_tag.DCS,dcs);

       
        
        _tag.dcsMultiTrack('DCS.dcsqry','','WT.oss','','WT.oss_r','','WT.oss_s',ossSuccess,
            'DCS.dcsuri',this.pathname,'WT.ti',this.innerHTML,'WT.pi','Successful Searches');
        restore(_tag.WT,wt);
        restore(_tag.DCS,dcs);
    });
}

/*
* Run after WT code is loaded
* Flags result clicks so we can track successful searches as ones in which a
* result was clicked
* Note that the multitrack calls unset WT.oss and WT.oss_r so they won't be
* resent as part of the data collection.
*
*/
MerckTracker.prototype.mtManualsTrackSearchClick=function(){

    if(location.href.indexOf("search.html") == -1){
        return;
    }

    var ossResults = $.trim($('p.searchResults').html().split('of')[1]);
    var ossSuccess = ($('.textNoEntries').html() == null) ? true : false;

    _tag.WT.oss=$.query()['qt'];

    _tag.WT.oss_r= (ossSuccess == true) ? ossResults : "0";

    var save = this.mtSaveWT;
    var restore = this.mtRestoreWT;
    var wt = this.wt;
    var dcs = this.dcs;

    $().find('.searchTable:contains("Subject titles")').each(function(x){
        var headerText = $(this).find('.bigHeader').html();
        $(this).find('a.MMchapterLnk').each(function(y){
            var hr = $(this).attr('pathname');
            var title = headerText + ": " + $(this).html();
            $(this).click(function(){

                save(_tag.WT,wt);
                save(_tag.DCS,dcs);

                _tag.dcsMultiTrack('DCS.dcsqry','','WT.oss','','WT.oss_r','','DCS.dcsuri',hr,
                    'WT.ti',title,'WT.oss_s','1','WT.pi','Successful Searches');
                restore(_tag.WT,wt);
                restore(_tag.DCS,dcs);

            });
        });

        $(this).find('a.MMtopicLnk').each(function(y){
            var hr = $(this).attr('pathname');
            var title = headerText + ": " + $(this).html();
            $(this).click(function(){

                save(_tag.WT,wt);
                save(_tag.DCS,dcs);

                _tag.dcsMultiTrack('DCS.dcsqry','','WT.oss','','WT.oss_r','','DCS.dcsuri',hr,'WT.ti',title,
                    'WT.oss_s','1','WT.pi','Successful Searches');
                restore(_tag.WT,wt);
                restore(_tag.DCS,dcs);
            });
        });

    });

    $().find('.searchTable:contains("Topic titles")').each(function(y){
        var headerText = $(this).find('.bigHeader').html();
        $(this).find('a.MMtopicLnk').each(function(y){
            var hr = $(this).attr('pathname');
            var title = headerText + ": " + $(this).html();
            $(this).click(function(){

                save(_tag.WT,wt);
                save(_tag.DCS,dcs);

                _tag.dcsMultiTrack('DCS.dcsqry','','WT.oss','','WT.oss_r','','DCS.dcsuri',hr,'WT.ti',title,
                    'WT.oss_s','1','WT.pi','Successful Searches');
                restore(_tag.WT,wt);
                restore(_tag.DCS,dcs);
            });
        });
    });

    $().find('.searchTable:contains("Index entries")').each(function(y){
        var headerText = $(this).find('.bigHeader').html();
        var anchors = $(this).find('a[pathname]');

        $(anchors).click(function(){

            save(_tag.WT,wt);
            save(_tag.DCS,dcs);

            var hr = $(this).attr('pathname');
            var title = headerText + ": " + $(this).html().replace(/\s{2,}/g, " ");
            _tag.dcsMultiTrack('DCS.dcsqry','','WT.oss','','WT.oss_r','','DCS.dcsuri',hr,'WT.ti',title,
                'WT.oss_s','1','WT.pi','Successful Searches');
            restore(_tag.WT,wt);
            restore(_tag.DCS,dcs);
        });
    });

    // Pages section
    var pageHeader = "Pages";

    $('td > p[class="searchTopic"] a').each(function(m){



        var hr = $(this).attr('pathname');
        var title = pageHeader + ": " + $(this).html();
        $(this).click(function(){

            save(_tag.WT,wt);
            save(_tag.DCS,dcs);

            _tag.dcsMultiTrack('DCS.dcsqry','','WT.oss','','WT.oss_r','','DCS.dcsuri',hr,'WT.ti',title,
                'WT.oss_s','1','WT.pi','Successful Searches');
            restore(_tag.WT,wt);
            restore(_tag.DCS,dcs);
        });

    });

    $('p[class="searchTopicDesc"] a').each(function(n){
        var hr = $(this).attr('pathname');
        var title = pageHeader + ": " + $(this).html();
        $(this).click(function(){

            save(_tag.WT,wt);
            save(_tag.DCS,dcs);

            _tag.dcsMultiTrack('DCS.dcsqry','','WT.oss','','WT.oss_r','','DCS.dcsuri',hr,'WT.ti',title,
                'WT.oss_s','1','WT.pi','Successful Searches');
            restore(_tag.WT,wt);
            restore(_tag.DCS,dcs);
        });
    });
}
/*
* Run before WT data collection
* flag page tiers as tier 2 if tier 1 meta tag is not set
*
*/

MerckTracker.prototype.mtFlagPageTier=function(){
    var tier = $('meta[name="WT.z_tier"]').attr('content');
    if(tier == '1'){
        return;
    } else {
        var name="WT.z_tier2";
        var content="1";

        this.mtAddMeta(name, content);
    }
}

/*
* Run after WT code is loaded
* WT.dl=30 flags clicks to the worldwide Merck sites
*/
MerckTracker.prototype.mtFlagWorldwideClick=function(){

    var save = this.mtSaveWT;
    var restore = this.mtRestoreWT;
    var wt = this.wt;
    var dcs = this.dcs;

    $('a.btn-worldwide').click(function(){

        save(_tag.WT,wt);
        save(_tag.DCS,dcs);

        _tag.dcsMultiTrack('DCS.dcsqry','','DCS.dcsuri',document.location,'WT.ti',
            'Link to Worldwide Site:  '+document.title,'WT.dl','30','WT.pi','Worldwide Merck Site Click');
        restore(_tag.WT,wt);
        restore(_tag.DCS,dcs);
    });
/*
    var wwLinks = "";
    wwLinks += "ul#countries-americas li a,ul#countries-europe li a";
    wwLinks += "ul#countries-pacific li a,ul#countries-mideast li a";
    $().find(wwLinks).click(function(){
        _tag.dcsMultiTrack('DCS.dcsuri',this.href,'WT.ti',"Worldwide: "+this.innerHTML,'WT.dl','30');
    });
    */
}

/*
* Does not matter if WT coded is loaded
* Flags section and resource links in /mmpe/ and /mmhe/
* WT.z_section for section links and WT.z_resource for resource links
*
*/
MerckTracker.prototype.mtFlagSectionsResources=function(){

    if((location.href.indexOf("/mmhe/") == -1) && (location.href.indexOf("/mmpe/")) == -1){
        return;
    }

    $('div div.MMnavTitleBar:contains("Sections")').next().find('li a').each(function(){
        $(this).attr('href', $(this).attr('href')+"?WT.z_section="+$(this).html());

    });

    $('div div.MMnavTitleBar:contains("Resources")').next().find('li a').each(function(){
        $(this).attr('href', $(this).attr('href')+"?WT.z_resource="+$(this).html());

    });

}

/*
* Run after WT code is loaded
* Flags links for offsite clicks (everything not merck.com)
* This excludes merckbooks.com also (any link that does not contain the string
* 'merck' in the URL is flagged)
*
*/
MerckTracker.prototype.mtFlagOffsiteClick=function(){
    var isProductSiteCheck = this.mtIsProductSiteLink;
    var isVideoSiteCheck = this.mtIsVideoSiteLink;
    var videoSites=["www.careertv.com","get.adobe.com"];
    var sites = this.prodSitesArray;
    var isMerckSite = this.mtIsMerckSite;

    var save = this.mtSaveWT;
    var restore = this.mtRestoreWT;
    var wt = this.wt;
    var dcs = this.dcs;

    $('a[href^=http]').each(function(){
        var isProductSite = isProductSiteCheck(sites,this.href);
        var isVideoSite = isVideoSiteCheck(videoSites,this.href);
        var isOnSite = isMerckSite(this.href);
        if(isProductSite == false && isVideoSite == false && isOnSite == false){
            $(this).click(function(){
                save(_tag.WT,wt);
                save(_tag.DCS,dcs);

                var hn = this.hostname;
                _tag.dcsMultiTrack("DCS.dcssip",hn,'DCS.dcsqry','','DCS.dcsuri',this.pathname,
                    'WT.ti','Link to Offsite Page: '+this.innerHTML,'WT.dl','24',
                    'WT.pi','Non-Merck Site Click');
                restore(_tag.WT,wt);
                restore(_tag.DCS,dcs);
            });
        }
    });
}

/*
* Run after WT code is loaded
* WT.dl=37 flags merckbook.com clicks
*/
MerckTracker.prototype.mtFlagMerckBookClick=function(){

    var save = this.mtSaveWT;
    var restore = this.mtRestoreWT;
    var wt = this.wt;
    var dcs = this.dcs;

    $('a[href*=merckbooks.com]').click(function(){

        save(_tag.WT,wt);
        save(_tag.DCS,dcs);

        var hn=this.hostname;
        _tag.dcsMultiTrack("DCS.dcssip",hn,'DCS.dcsqry','','DCS.dcsuri',this.pathname,'WT.ti',this.innerHTML,
            'WT.dl','37','WT.pi','Merck Book Click');
        restore(_tag.WT,wt);
        restore(_tag.DCS,dcs);
    });
}

/*
* This should run after WT code is loaded and before WT data collector is called
* collector for the main site
*
*/
MerckTracker.prototype.mtMainCollect=function(){
    this.mtFlagAudioClick("merck");
    this.mtFlagVideoClick();
    this.mtFlagDownloadClick();
    this.mtFlagEmailClick("merck");
    this.mtFlagPrintClick("merck");
    this.mtSetNavigation();
    this.mtMainTrackSearchClick();
    this.mtSetContentGroups("merck");
    this.mtFlagPageTier();
    this.mtFlagWorldwideClick();
    this.mtFlagProductSiteClick();
    this.mtFlagOffsiteClick();
    this.mtUniquePages();
}

/*
* This should run after WT code and before WT data collector is called
* collector for the manuals
* This is for Merck Manuals
*
*/
MerckTracker.prototype.mtManualsCollect=function(){
    this.mtFlagAudioClick("manuals");
    this.mtFlagVideoClick();
    this.mtFlagDownloadClick();
    this.mtFlagEmailClick("manuals");
    this.mtFlagPrintClick("manuals");
    this.mtFlagMerckBookClick();
    this.mtSetSubject();
    this.mtFlagSectionsResources();
    this.mtSetResourceTopic();
    this.mtManualsTrackSearchClick();
    this.mtFlagAlertSubscribeClick();
    this.mtFlagPdaClick();
    this.mtFlagItunesClick();
    this.mtFlagOffsiteClick();
    this.mtSetContentGroups("manuals");
    this.mtFlagLexiCompPage();
    this.mtFlagTopicPage();
    this.mtFlagProductSiteClick();
    this.mtUniquePages();
}

MerckTracker.prototype.mtDebug=function(){

    this.mtAddMeta("TestName", "TestContent");
    var ps = this.prodSitesArray;

}

// function for tracking/counting unique pages viewed by visitors
// written by David Smith
MerckTracker.prototype.mtUniquePages= function() {
    var sCName="mtP";
    var sCPage=this.mtCrc16(location.pathname);
    var d=new Date();
    var dNow = d.getFullYear()*100+d.getMonth();
    $.Jookie.Initialise(sCName, "5256000"); // 10 year cookie in minutes
    var cookieValue = $.Jookie.Get(sCName,sCPage);
    if(cookieValue == null){
        $.Jookie.Set(sCName, sCPage, dNow.toString());
        this.mtAddMeta("WT.z_distinct_m", "1");
        this.mtAddMeta("WT.z_distinct_y", "1");
    } else if (dNow!=cookieValue){
        $.Jookie.Set(sCName, sCPage, dNow.toString());
        this.mtAddMeta("WT.z_distinct_m","1");
        if (d.getFullYear()!=cookieValue.substring(0,4)) {
            this.mtAddMeta("WT.z_distinct_y", "1");
        }
    }
}

/*
 * =============================================================================
 *                         end of code written by TL
 * =============================================================================
 */

// an addition/plugin to jQuery for parsing query strings
// from http://www.nabble.com/method-plugin-for-getting-query-string-vars--td6919130.html#a6919130
jQuery.query = function() {
    var r = {};
    var q = location.search;
    q = q.replace(/^\?/,''); // remove the leading ?
    q = q.replace(/\&$/,''); // remove the trailing &
    jQuery.each(q.split('&'), function(){
        var key = this.split('=')[0];
        var val = this.split('=')[1];
        // convert floats
        if(/^[0-9.]+$/.test(val))
            val = parseFloat(val);
        // ingnore empty values
        if(val)
            r[key] = val;
    });
    return r;
};

// jQuery cookie plugin
// -------------------------------------------------
/*
  License:
  Jookie 1.0 jQuery Plugin

  Copyright (c) 2008 Jon Combe (http://joncom.be)

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
*/

(function($) {

    $.Jookie = {
        Data:         {},
        Debug:        function(a)     {
            Debug(a)
        },
        Delete:       function(a)     {
            Delete(a)
        },    // delete cookie
        Get:          function(a,b)   {
            return Get(a,b)
        },    // get a single value from a cookie
        Initialise:   function(a,b)   {
            Initialise(a,b)
        },
        Set:          function(a,b,c) {
            Set(a,b,c)
        },    // set a single value to a cookie
        Unset:        function(a,b)   {
            Unset(a,b)
        }     // remove a single value from a cookie
    }

    // PUBLIC: show debugging information
    function Debug(sName) {
        var lsRegExp = /\+/g;
        var sJSON = unescape(String(Extract(sName)).replace(lsRegExp, " "));
        alert("Name: " + sName +
            "\nLifespan: " + $.Jookie.Data[sName].iLifespan +
            " minutes\nCookie Existed Prior to Init: " + $.Jookie.Data[sName].bMadeEarlier + "\n\n" +
            sJSON);
    }

    // PUBLIC: delete a cookie
    function Delete(sName) {
        delete $.Jookie.Data[sName];
        document.cookie = (sName + "=; expires=" + (new Date(1990, 6, 3)).toGMTString() + "; path=/");
    }

    // PRIVATE: extract the contents of a cookie
    function Extract(sName) {
        var vValue = null;
        var aContents = document.cookie.split(';');
        sName += "=";

        // loop through cookie strings
        for (var iIndex in aContents) {
            var sString = aContents[iIndex];
            while (sString.charAt(0) == " ") {
                sString = sString.substring(1, sString.length);
            }
            if (sString.indexOf(sName) == 0) {
                vValue = sString.substring(sName.length, sString.length);
                break;
            }
        }

        // return extracted value
        return vValue;
    }

    // PUBLIC: retrieve a cookie's value
    function Get(sName, sVariableName) {
        return $.Jookie.Data[sName].oValues[sVariableName];
    }

    // PUBLIC: Initialise the plugin
    function Initialise(sName, iLifespanInMinutes) {
        if (typeof $.Jookie.Data[sName] == "undefined") {
            var oRetrievedValues = {};
            var bCookieExists = false;

            // extract cookie value
            var vCookieValue = Extract(sName);
            if (vCookieValue !== null) {
                oRetrievedValues = JSON.parse( unescape(String(vCookieValue).replace(/\+/g, " ")) );
                bCookieExists = true;
            }

            // add cookie details to object
            $.Jookie.Data[sName] = {
                iLifespan    : iLifespanInMinutes,
                bMadeEarlier : bCookieExists,
                oValues      : oRetrievedValues
            };
            Save(sName);
        }
    }

    // PRIVATE: write cookie to user's browser
    function Save(sName) {
        var sExpires = "";
        if ($.Jookie.Data[sName].iLifespan > 0) {
            var dtDate = new Date();
            dtDate.setMinutes(dtDate.getMinutes() + $.Jookie.Data[sName].iLifespan);
            sExpires = ("; expires=" + dtDate.toGMTString());
        }
        document.cookie = (sName + "=" +
            escape(JSON.stringify($.Jookie.Data[sName].oValues)) +
            sExpires + "; path=/");
    }

    // PUBLIC: set and save a cookie's value
    function Set(sName, sVariableName, vValue) {
        $.Jookie.Data[sName].oValues[sVariableName] = vValue;
        Save(sName);
    }

    // PUBLIC: delete a single variable from a cookie
    function Unset(sName, sVariableName) {
        delete $.Jookie.Data[sName].oValues[sVariableName];
        Save(sName);
    }

})(jQuery);

/*
    http://www.JSON.org/json2.js
    2008-05-25

    Public Domain.

    NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.

    See http://www.JSON.org/js.html

    This file creates a global JSON object containing two methods: stringify
    and parse.

        JSON.stringify(value, replacer, space)
            value       any JavaScript value, usually an object or array.

            replacer    an optional parameter that determines how object
                        values are stringified for objects without a toJSON
                        method. It can be a function or an array.

            space       an optional parameter that specifies the indentation
                        of nested structures. If it is omitted, the text will
                        be packed without extra whitespace. If it is a number,
                        it will specify the number of spaces to indent at each
                        level. If it is a string (such as '\t' or '&nbsp;'),
                        it contains the characters used to indent at each level.

            This method produces a JSON text from a JavaScript value.

            When an object value is found, if the object contains a toJSON
            method, its toJSON method will be called and the result will be
            stringified. A toJSON method does not serialize: it returns the
            value represented by the name/value pair that should be serialized,
            or undefined if nothing should be serialized. The toJSON method
            will be passed the key associated with the value, and this will be
            bound to the object holding the key.

            For example, this would serialize Dates as ISO strings.

                Date.prototype.toJSON = function (key) {
                    function f(n) {
                        // Format integers to have at least two digits.
                        return n < 10 ? '0' + n : n;
                    }

                    return this.getUTCFullYear()   + '-' +
                         f(this.getUTCMonth() + 1) + '-' +
                         f(this.getUTCDate())      + 'T' +
                         f(this.getUTCHours())     + ':' +
                         f(this.getUTCMinutes())   + ':' +
                         f(this.getUTCSeconds())   + 'Z';
                };

            You can provide an optional replacer method. It will be passed the
            key and value of each member, with this bound to the containing
            object. The value that is returned from your method will be
            serialized. If your method returns undefined, then the member will
            be excluded from the serialization.

            If the replacer parameter is an array, then it will be used to
            select the members to be serialized. It filters the results such
            that only members with keys listed in the replacer array are
            stringified.

            Values that do not have JSON representations, such as undefined or
            functions, will not be serialized. Such values in objects will be
            dropped; in arrays they will be replaced with null. You can use
            a replacer function to replace those with JSON values.
            JSON.stringify(undefined) returns undefined.

            The optional space parameter produces a stringification of the
            value that is filled with line breaks and indentation to make it
            easier to read.

            If the space parameter is a non-empty string, then that string will
            be used for indentation. If the space parameter is a number, then
            the indentation will be that many spaces.

            Example:

            text = JSON.stringify(['e', {pluribus: 'unum'}]);
            // text is '["e",{"pluribus":"unum"}]'


            text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
            // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'

            text = JSON.stringify([new Date()], function (key, value) {
                return this[key] instanceof Date ?
                    'Date(' + this[key] + ')' : value;
            });
            // text is '["Date(---current time---)"]'


        JSON.parse(text, reviver)
            This method parses a JSON text to produce an object or array.
            It can throw a SyntaxError exception.

            The optional reviver parameter is a function that can filter and
            transform the results. It receives each of the keys and values,
            and its return value is used instead of the original value.
            If it returns what it received, then the structure is not modified.
            If it returns undefined then the member is deleted.

            Example:

            // Parse the text. Values that look like ISO date strings will
            // be converted to Date objects.

            myData = JSON.parse(text, function (key, value) {
                var a;
                if (typeof value === 'string') {
                    a =
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
                    if (a) {
                        return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
                            +a[5], +a[6]));
                    }
                }
                return value;
            });

            myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
                var d;
                if (typeof value === 'string' &&
                        value.slice(0, 5) === 'Date(' &&
                        value.slice(-1) === ')') {
                    d = new Date(value.slice(5, -1));
                    if (d) {
                        return d;
                    }
                }
                return value;
            });


    This is a reference implementation. You are free to copy, modify, or
    redistribute.

    This code should be minified before deployment.
    See http://javascript.crockford.com/jsmin.html

    USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
    NOT CONTROL.
*/

/*jslint evil: true */

/*global JSON */

/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", call,
    charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, getUTCMinutes,
    getUTCMonth, getUTCSeconds, hasOwnProperty, join, lastIndex, length,
    parse, propertyIsEnumerable, prototype, push, replace, slice, stringify,
    test, toJSON, toString
*/

if (!this.JSON) {

    // Create a JSON object only if one does not already exist. We create the
    // object in a closure to avoid creating global variables.

    JSON = function () {

        function f(n) {
            // Format integers to have at least two digits.
            return n < 10 ? '0' + n : n;
        }

        Date.prototype.toJSON = function (key) {

            return this.getUTCFullYear()   + '-' +
            f(this.getUTCMonth() + 1) + '-' +
            f(this.getUTCDate())      + 'T' +
            f(this.getUTCHours())     + ':' +
            f(this.getUTCMinutes())   + ':' +
            f(this.getUTCSeconds())   + 'Z';
        };

        var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        escapeable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        gap,
        indent,
        meta = {    // table of character substitutions
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        },
        rep;


        function quote(string) {

            // If the string contains no control characters, no quote characters, and no
            // backslash characters, then we can safely slap some quotes around it.
            // Otherwise we must also replace the offending characters with safe escape
            // sequences.

            escapeable.lastIndex = 0;
            return escapeable.test(string) ?
            '"' + string.replace(escapeable, function (a) {
                var c = meta[a];
                if (typeof c === 'string') {
                    return c;
                }
                return '\\u' + ('0000' +
                    (+(a.charCodeAt(0))).toString(16)).slice(-4);
            }) + '"' :
            '"' + string + '"';
        }


        function str(key, holder) {

            // Produce a string from holder[key].

            var i,          // The loop counter.
            k,          // The member key.
            v,          // The member value.
            length,
            mind = gap,
            partial,
            value = holder[key];

            // If the value has a toJSON method, call it to obtain a replacement value.

            if (value && typeof value === 'object' &&
                typeof value.toJSON === 'function') {
                value = value.toJSON(key);
            }

            // If we were called with a replacer function, then call the replacer to
            // obtain a replacement value.

            if (typeof rep === 'function') {
                value = rep.call(holder, key, value);
            }

            // What happens next depends on the value's type.

            switch (typeof value) {
                case 'string':
                    return quote(value);

                case 'number':

                    // JSON numbers must be finite. Encode non-finite numbers as null.

                    return isFinite(value) ? String(value) : 'null';

                case 'boolean':
                case 'null':

                    // If the value is a boolean or null, convert it to a string. Note:
                    // typeof null does not produce 'null'. The case is included here in
                    // the remote chance that this gets fixed someday.

                    return String(value);

                // If the type is 'object', we might be dealing with an object or an array or
                // null.

                case 'object':

                    // Due to a specification blunder in ECMAScript, typeof null is 'object',
                    // so watch out for that case.

                    if (!value) {
                        return 'null';
                    }

                    // Make an array to hold the partial results of stringifying this object value.

                    gap += indent;
                    partial = [];

                    // If the object has a dontEnum length property, we'll treat it as an array.

                    if (typeof value.length === 'number' &&
                        !(value.propertyIsEnumerable('length'))) {

                        // The object is an array. Stringify every element. Use null as a placeholder
                        // for non-JSON values.

                        length = value.length;
                        for (i = 0; i < length; i += 1) {
                            partial[i] = str(i, value) || 'null';
                        }

                        // Join all of the elements together, separated with commas, and wrap them in
                        // brackets.

                        v = partial.length === 0 ? '[]' :
                        gap ? '[\n' + gap +
                        partial.join(',\n' + gap) + '\n' +
                        mind + ']' :
                        '[' + partial.join(',') + ']';
                        gap = mind;
                        return v;
                    }

                    // If the replacer is an array, use it to select the members to be stringified.

                    if (rep && typeof rep === 'object') {
                        length = rep.length;
                        for (i = 0; i < length; i += 1) {
                            k = rep[i];
                            if (typeof k === 'string') {
                                v = str(k, value, rep);
                                if (v) {
                                    partial.push(quote(k) + (gap ? ': ' : ':') + v);
                                }
                            }
                        }
                    } else {

                        // Otherwise, iterate through all of the keys in the object.

                        for (k in value) {
                            if (Object.hasOwnProperty.call(value, k)) {
                                v = str(k, value, rep);
                                if (v) {
                                    partial.push(quote(k) + (gap ? ': ' : ':') + v);
                                }
                            }
                        }
                    }

                    // Join all of the member texts together, separated with commas,
                    // and wrap them in braces.

                    v = partial.length === 0 ? '{}' :
                    gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
                    mind + '}' : '{' + partial.join(',') + '}';
                    gap = mind;
                    return v;
            }
        }

        // Return the JSON object containing the stringify and parse methods.

        return {
            stringify: function (value, replacer, space) {

                // The stringify method takes a value and an optional replacer, and an optional
                // space parameter, and returns a JSON text. The replacer can be a function
                // that can replace values, or an array of strings that will select the keys.
                // A default replacer method can be provided. Use of the space parameter can
                // produce text that is more easily readable.

                var i;
                gap = '';
                indent = '';

                // If the space parameter is a number, make an indent string containing that
                // many spaces.

                if (typeof space === 'number') {
                    for (i = 0; i < space; i += 1) {
                        indent += ' ';
                    }

                // If the space parameter is a string, it will be used as the indent string.

                } else if (typeof space === 'string') {
                    indent = space;
                }

                // If there is a replacer, it must be a function or an array.
                // Otherwise, throw an error.

                rep = replacer;
                if (replacer && typeof replacer !== 'function' &&
                    (typeof replacer !== 'object' ||
                        typeof replacer.length !== 'number')) {
                    throw new Error('JSON.stringify');
                }

                // Make a fake root object containing our value under the key of ''.
                // Return the result of stringifying the value.

                return str('', {
                    '': value
                });
            },


            parse: function (text, reviver) {

                // The parse method takes a text and an optional reviver function, and returns
                // a JavaScript value if the text is a valid JSON text.

                var j;

                function walk(holder, key) {

                    // The walk method is used to recursively walk the resulting structure so
                    // that modifications can be made.

                    var k, v, value = holder[key];
                    if (value && typeof value === 'object') {
                        for (k in value) {
                            if (Object.hasOwnProperty.call(value, k)) {
                                v = walk(value, k);
                                if (v !== undefined) {
                                    value[k] = v;
                                } else {
                                    delete value[k];
                                }
                            }
                        }
                    }
                    return reviver.call(holder, key, value);
                }


                // Parsing happens in four stages. In the first stage, we replace certain
                // Unicode characters with escape sequences. JavaScript handles many characters
                // incorrectly, either silently deleting them, or treating them as line endings.

                cx.lastIndex = 0;
                if (cx.test(text)) {
                    text = text.replace(cx, function (a) {
                        return '\\u' + ('0000' +
                            (+(a.charCodeAt(0))).toString(16)).slice(-4);
                    });
                }

                // In the second stage, we run the text against regular expressions that look
                // for non-JSON patterns. We are especially concerned with '()' and 'new'
                // because they can cause invocation, and '=' because it can cause mutation.
                // But just to be safe, we want to reject all unexpected forms.

                // We split the second stage into 4 regexp operations in order to work around
                // crippling inefficiencies in IE's and Safari's regexp engines. First we
                // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
                // replace all simple value tokens with ']' characters. Third, we delete all
                // open brackets that follow a colon or comma or that begin the text. Finally,
                // we look to see that the remaining characters are only whitespace or ']' or
                // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.

                if (/^[\],:{}\s]*$/.
                    test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
                        replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
                        replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {

                    // In the third stage we use the eval function to compile the text into a
                    // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
                    // in JavaScript: it can begin a block or an object literal. We wrap the text
                    // in parens to eliminate the ambiguity.

                    j = eval('(' + text + ')');

                    // In the optional fourth stage, we recursively walk the new structure, passing
                    // each name/value pair to a reviver function for possible transformation.

                    return typeof reviver === 'function' ?
                    walk({
                        '': j
                    }, '') : j;
                }

                // If the text is not JSON parseable, then a SyntaxError is thrown.

                throw new SyntaxError('JSON.parse');
            }
        };
    }();
}

/* ===========================================================================
*
* JQuery URL Parser
* Version 1.0
* Parses URLs and provides easy access to information within them.
*
* Author: Mark Perkins
* Author email: mark@allmarkedup.com
*
* For full documentation and more go to http://projects.allmarkedup.com/jquery_url_parser/
*
* ---------------------------------------------------------------------------
*
* CREDITS:
*
* Parser based on the Regex-based URI parser by Steven Levithan.
* For more information (including a detailed explaination of the differences
* between the 'loose' and 'strict' pasing modes) visit http://blog.stevenlevithan.com/archives/parseuri
*
* ---------------------------------------------------------------------------
*
* LICENCE:
*
* Released under a MIT Licence. See licence.txt that should have been supplied with this file,
* or visit http://projects.allmarkedup.com/jquery_url_parser/licence.txt
*
* ---------------------------------------------------------------------------
*
* EXAMPLES OF USE:
*
* Get the domain name (host) from the current page URL
* jQuery.url.attr("host")
*
* Get the query string value for 'item' for the current page
* jQuery.url.param("item") // null if it doesn't exist
*
* Get the second segment of the URI of the current page
* jQuery.url.segment(2) // null if it doesn't exist
*
* Get the protocol of a manually passed in URL
* jQuery.url.setUrl("http://allmarkedup.com/").attr("protocol") // returns 'http'
*
*/

jQuery.url = function()
{
    var segments = {};

    var parsed = {};

    /**
* Options object. Only the URI and strictMode values can be changed via the setters below.
*/
    var options = {

        url : window.location, // default URI is the page in which the script is running

        strictMode: false, // 'loose' parsing by default

        key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], // keys available to query

        q: {
            name: "queryKey",
            parser: /(?:^|&)([^&=]*)=?([^&]*)/g
        },

        parser: {
            strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,  //less intuitive, more accurate to the specs
            loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // more intuitive, fails on relative paths and deviates from specs
        }

    };

    /**
* Deals with the parsing of the URI according to the regex above.
* Written by Steven Levithan - see credits at top.
*/
    var parseUri = function()
    {
        str = decodeURI( options.url );

        var m = options.parser[ options.strictMode ? "strict" : "loose" ].exec( str );
        var uri = {};
        var i = 14;

        while ( i-- ) {
            uri[ options.key[i] ] = m[i] || "";
        }

        uri[ options.q.name ] = {};
        uri[ options.key[12] ].replace( options.q.parser, function ( $0, $1, $2 ) {
            if ($1) {
                uri[options.q.name][$1] = $2;
            }
        });

        return uri;
    };

    /**
* Returns the value of the passed in key from the parsed URI.
*
* @param string key The key whose value is required
*/
    var key = function( key )
    {
        if ( ! parsed.length )
        {
            setUp(); // if the URI has not been parsed yet then do this first...
        }
        if ( key == "base" )
        {
            if ( parsed.port !== null && parsed.port !== "" )
            {
                return parsed.protocol+"://"+parsed.host+":"+parsed.port+"/";
            }
            else
            {
                return parsed.protocol+"://"+parsed.host+"/";
            }
        }

        return ( parsed[key] === "" ) ? null : parsed[key];
    };

    /**
* Returns the value of the required query string parameter.
*
* @param string item The parameter whose value is required
*/
    var param = function( item )
    {
        if ( ! parsed.length )
        {
            setUp(); // if the URI has not been parsed yet then do this first...
        }
        return ( parsed.queryKey[item] === null ) ? null : parsed.queryKey[item];
    };

    /**
* 'Constructor' (not really!) function.
*  Called whenever the URI changes to kick off re-parsing of the URI and splitting it up into segments.
*/
    var setUp = function()
    {
        parsed = parseUri();

        getSegments();
    };

    /**
* Splits up the body of the URI into segments (i.e. sections delimited by '/')
*/
    var getSegments = function()
    {
        var p = parsed.path;
        segments = []; // clear out segments array
        segments = parsed.path.length == 1 ? {} : ( p.charAt( p.length - 1 ) == "/" ? p.substring( 1, p.length - 1 ) : path = p.substring( 1 ) ).split("/");
    };

    return {

        /**
* Sets the parsing mode - either strict or loose. Set to loose by default.
*
* @param string mode The mode to set the parser to. Anything apart from a value of 'strict' will set it to loose!
*/
        setMode : function( mode )
        {
            strictMode = mode == "strict" ? true : false;
            return this;
        },

        /**
* Sets URI to parse if you don't want to to parse the current page's URI.
* Calling the function with no value for newUri resets it to the current page's URI.
*
* @param string newUri The URI to parse.
*/
        setUrl : function( newUri )
        {
            options.url = newUri === undefined ? window.location : newUri;
            setUp();
            return this;
        },

        /**
* Returns the value of the specified URI segment. Segments are numbered from 1 to the number of segments.
* For example the URI http://test.com/about/company/ segment(1) would return 'about'.
*
* If no integer is passed into the function it returns the number of segments in the URI.
*
* @param int pos The position of the segment to return. Can be empty.
*/
        segment : function( pos )
        {
            if ( ! parsed.length )
            {
                setUp(); // if the URI has not been parsed yet then do this first...
            }
            if ( pos === undefined )
            {
                return segments.length;
            }
            return ( segments[pos] === "" || segments[pos] === undefined ) ? null : segments[pos];
        },

        attr : key, // provides public access to private 'key' function - see above

        param : param // provides public access to private 'param' function - see above

    };

}();

/*
 * Added to Merck project 11 October 2009
 * $Id: mercktracker.js,v 1.7 2009/11/09 04:20:48 powem Exp $
 */

/*
  License:
  Jookie 1.0 jQuery Plugin

  Copyright (c) 2008 Jon Combe (http://joncom.be)

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
*/

(function($) {

    $.Jookie = {
        Data:         {},
        Debug:        function(a)     {
            Debug(a)
        },
        Delete:       function(a)     {
            Delete(a)
        },    // delete cookie
        Get:          function(a,b)   {
            return Get(a,b)
        },    // get a single value from a cookie
        Initialise:   function(a,b)   {
            Initialise(a,b)
        },
        Set:          function(a,b,c) {
            Set(a,b,c)
        },    // set a single value to a cookie
        Unset:        function(a,b)   {
            Unset(a,b)
        }     // remove a single value from a cookie
    }

    // PUBLIC: show debugging information
    function Debug(sName) {
        var lsRegExp = /\+/g;
        var sJSON = unescape(String(Extract(sName)).replace(lsRegExp, " "));
        alert("Name: " + sName +
            "\nLifespan: " + $.Jookie.Data[sName].iLifespan +
            " minutes\nCookie Existed Prior to Init: " + $.Jookie.Data[sName].bMadeEarlier + "\n\n" +
            sJSON);
    }

    // PUBLIC: delete a cookie
    function Delete(sName) {
        delete $.Jookie.Data[sName];
        document.cookie = (sName + "=; expires=" + (new Date(1990, 6, 3)).toGMTString() + "; path=/");
    }

    // PRIVATE: extract the contents of a cookie
    function Extract(sName) {
        var vValue = null;
        var aContents = document.cookie.split(';');
        sName += "=";

        // loop through cookie strings
        for (var iIndex in aContents) {
            var sString = aContents[iIndex];
            while (sString.charAt(0) == " ") {
                sString = sString.substring(1, sString.length);
            }
            if (sString.indexOf(sName) == 0) {
                vValue = sString.substring(sName.length, sString.length);
                break;
            }
        }

        // return extracted value
        return vValue;
    }

    // PUBLIC: retrieve a cookie's value
    function Get(sName, sVariableName) {
        return $.Jookie.Data[sName].oValues[sVariableName];
    }

    // PUBLIC: Initialise the plugin
    function Initialise(sName, iLifespanInMinutes) {
        if (typeof $.Jookie.Data[sName] == "undefined") {
            var oRetrievedValues = {};
            var bCookieExists = false;

            // extract cookie value
            var vCookieValue = Extract(sName);
            if (vCookieValue !== null) {
                oRetrievedValues = JSON.parse( unescape(String(vCookieValue).replace(/\+/g, " ")) );
                bCookieExists = true;
            }

            // add cookie details to object
            $.Jookie.Data[sName] = {
                iLifespan    : iLifespanInMinutes,
                bMadeEarlier : bCookieExists,
                oValues      : oRetrievedValues
            };
            Save(sName);
        }
    }

    // PRIVATE: write cookie to user's browser
    function Save(sName) {
        var sExpires = "";
        if ($.Jookie.Data[sName].iLifespan > 0) {
            var dtDate = new Date();
            dtDate.setMinutes(dtDate.getMinutes() + $.Jookie.Data[sName].iLifespan);
            sExpires = ("; expires=" + dtDate.toGMTString());
        }
        document.cookie = (sName + "=" +
            escape(JSON.stringify($.Jookie.Data[sName].oValues)) +
            sExpires + "; path=/");
    }

    // PUBLIC: set and save a cookie's value
    function Set(sName, sVariableName, vValue) {
        $.Jookie.Data[sName].oValues[sVariableName] = vValue;
        Save(sName);
    }

    // PUBLIC: delete a single variable from a cookie
    function Unset(sName, sVariableName) {
        delete $.Jookie.Data[sName].oValues[sVariableName];
        Save(sName);
    }

})(jQuery);

/*
    http://www.JSON.org/json2.js
    2008-05-25

    Public Domain.

    NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.

    See http://www.JSON.org/js.html

    This file creates a global JSON object containing two methods: stringify
    and parse.

        JSON.stringify(value, replacer, space)
            value       any JavaScript value, usually an object or array.

            replacer    an optional parameter that determines how object
                        values are stringified for objects without a toJSON
                        method. It can be a function or an array.

            space       an optional parameter that specifies the indentation
                        of nested structures. If it is omitted, the text will
                        be packed without extra whitespace. If it is a number,
                        it will specify the number of spaces to indent at each
                        level. If it is a string (such as '\t' or '&nbsp;'),
                        it contains the characters used to indent at each level.

            This method produces a JSON text from a JavaScript value.

            When an object value is found, if the object contains a toJSON
            method, its toJSON method will be called and the result will be
            stringified. A toJSON method does not serialize: it returns the
            value represented by the name/value pair that should be serialized,
            or undefined if nothing should be serialized. The toJSON method
            will be passed the key associated with the value, and this will be
            bound to the object holding the key.

            For example, this would serialize Dates as ISO strings.

                Date.prototype.toJSON = function (key) {
                    function f(n) {
                        // Format integers to have at least two digits.
                        return n < 10 ? '0' + n : n;
                    }

                    return this.getUTCFullYear()   + '-' +
                         f(this.getUTCMonth() + 1) + '-' +
                         f(this.getUTCDate())      + 'T' +
                         f(this.getUTCHours())     + ':' +
                         f(this.getUTCMinutes())   + ':' +
                         f(this.getUTCSeconds())   + 'Z';
                };

            You can provide an optional replacer method. It will be passed the
            key and value of each member, with this bound to the containing
            object. The value that is returned from your method will be
            serialized. If your method returns undefined, then the member will
            be excluded from the serialization.

            If the replacer parameter is an array, then it will be used to
            select the members to be serialized. It filters the results such
            that only members with keys listed in the replacer array are
            stringified.

            Values that do not have JSON representations, such as undefined or
            functions, will not be serialized. Such values in objects will be
            dropped; in arrays they will be replaced with null. You can use
            a replacer function to replace those with JSON values.
            JSON.stringify(undefined) returns undefined.

            The optional space parameter produces a stringification of the
            value that is filled with line breaks and indentation to make it
            easier to read.

            If the space parameter is a non-empty string, then that string will
            be used for indentation. If the space parameter is a number, then
            the indentation will be that many spaces.

            Example:

            text = JSON.stringify(['e', {pluribus: 'unum'}]);
            // text is '["e",{"pluribus":"unum"}]'


            text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
            // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'

            text = JSON.stringify([new Date()], function (key, value) {
                return this[key] instanceof Date ?
                    'Date(' + this[key] + ')' : value;
            });
            // text is '["Date(---current time---)"]'


        JSON.parse(text, reviver)
            This method parses a JSON text to produce an object or array.
            It can throw a SyntaxError exception.

            The optional reviver parameter is a function that can filter and
            transform the results. It receives each of the keys and values,
            and its return value is used instead of the original value.
            If it returns what it received, then the structure is not modified.
            If it returns undefined then the member is deleted.

            Example:

            // Parse the text. Values that look like ISO date strings will
            // be converted to Date objects.

            myData = JSON.parse(text, function (key, value) {
                var a;
                if (typeof value === 'string') {
                    a =
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
                    if (a) {
                        return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
                            +a[5], +a[6]));
                    }
                }
                return value;
            });

            myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
                var d;
                if (typeof value === 'string' &&
                        value.slice(0, 5) === 'Date(' &&
                        value.slice(-1) === ')') {
                    d = new Date(value.slice(5, -1));
                    if (d) {
                        return d;
                    }
                }
                return value;
            });


    This is a reference implementation. You are free to copy, modify, or
    redistribute.

    This code should be minified before deployment.
    See http://javascript.crockford.com/jsmin.html

    USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
    NOT CONTROL.
*/

/*jslint evil: true */

/*global JSON */

/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", call,
    charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, getUTCMinutes,
    getUTCMonth, getUTCSeconds, hasOwnProperty, join, lastIndex, length,
    parse, propertyIsEnumerable, prototype, push, replace, slice, stringify,
    test, toJSON, toString
*/

if (!this.JSON) {

    // Create a JSON object only if one does not already exist. We create the
    // object in a closure to avoid creating global variables.

    JSON = function () {

        function f(n) {
            // Format integers to have at least two digits.
            return n < 10 ? '0' + n : n;
        }

        Date.prototype.toJSON = function (key) {

            return this.getUTCFullYear()   + '-' +
            f(this.getUTCMonth() + 1) + '-' +
            f(this.getUTCDate())      + 'T' +
            f(this.getUTCHours())     + ':' +
            f(this.getUTCMinutes())   + ':' +
            f(this.getUTCSeconds())   + 'Z';
        };

        var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        escapeable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        gap,
        indent,
        meta = {    // table of character substitutions
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        },
        rep;


        function quote(string) {

            // If the string contains no control characters, no quote characters, and no
            // backslash characters, then we can safely slap some quotes around it.
            // Otherwise we must also replace the offending characters with safe escape
            // sequences.

            escapeable.lastIndex = 0;
            return escapeable.test(string) ?
            '"' + string.replace(escapeable, function (a) {
                var c = meta[a];
                if (typeof c === 'string') {
                    return c;
                }
                return '\\u' + ('0000' +
                    (+(a.charCodeAt(0))).toString(16)).slice(-4);
            }) + '"' :
            '"' + string + '"';
        }


        function str(key, holder) {

            // Produce a string from holder[key].

            var i,          // The loop counter.
            k,          // The member key.
            v,          // The member value.
            length,
            mind = gap,
            partial,
            value = holder[key];

            // If the value has a toJSON method, call it to obtain a replacement value.

            if (value && typeof value === 'object' &&
                typeof value.toJSON === 'function') {
                value = value.toJSON(key);
            }

            // If we were called with a replacer function, then call the replacer to
            // obtain a replacement value.

            if (typeof rep === 'function') {
                value = rep.call(holder, key, value);
            }

            // What happens next depends on the value's type.

            switch (typeof value) {
                case 'string':
                    return quote(value);

                case 'number':

                    // JSON numbers must be finite. Encode non-finite numbers as null.

                    return isFinite(value) ? String(value) : 'null';

                case 'boolean':
                case 'null':

                    // If the value is a boolean or null, convert it to a string. Note:
                    // typeof null does not produce 'null'. The case is included here in
                    // the remote chance that this gets fixed someday.

                    return String(value);

                // If the type is 'object', we might be dealing with an object or an array or
                // null.

                case 'object':

                    // Due to a specification blunder in ECMAScript, typeof null is 'object',
                    // so watch out for that case.

                    if (!value) {
                        return 'null';
                    }

                    // Make an array to hold the partial results of stringifying this object value.

                    gap += indent;
                    partial = [];

                    // If the object has a dontEnum length property, we'll treat it as an array.

                    if (typeof value.length === 'number' &&
                        !(value.propertyIsEnumerable('length'))) {

                        // The object is an array. Stringify every element. Use null as a placeholder
                        // for non-JSON values.

                        length = value.length;
                        for (i = 0; i < length; i += 1) {
                            partial[i] = str(i, value) || 'null';
                        }

                        // Join all of the elements together, separated with commas, and wrap them in
                        // brackets.

                        v = partial.length === 0 ? '[]' :
                        gap ? '[\n' + gap +
                        partial.join(',\n' + gap) + '\n' +
                        mind + ']' :
                        '[' + partial.join(',') + ']';
                        gap = mind;
                        return v;
                    }

                    // If the replacer is an array, use it to select the members to be stringified.

                    if (rep && typeof rep === 'object') {
                        length = rep.length;
                        for (i = 0; i < length; i += 1) {
                            k = rep[i];
                            if (typeof k === 'string') {
                                v = str(k, value, rep);
                                if (v) {
                                    partial.push(quote(k) + (gap ? ': ' : ':') + v);
                                }
                            }
                        }
                    } else {

                        // Otherwise, iterate through all of the keys in the object.

                        for (k in value) {
                            if (Object.hasOwnProperty.call(value, k)) {
                                v = str(k, value, rep);
                                if (v) {
                                    partial.push(quote(k) + (gap ? ': ' : ':') + v);
                                }
                            }
                        }
                    }

                    // Join all of the member texts together, separated with commas,
                    // and wrap them in braces.

                    v = partial.length === 0 ? '{}' :
                    gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
                    mind + '}' : '{' + partial.join(',') + '}';
                    gap = mind;
                    return v;
            }
        }

        // Return the JSON object containing the stringify and parse methods.

        return {
            stringify: function (value, replacer, space) {

                // The stringify method takes a value and an optional replacer, and an optional
                // space parameter, and returns a JSON text. The replacer can be a function
                // that can replace values, or an array of strings that will select the keys.
                // A default replacer method can be provided. Use of the space parameter can
                // produce text that is more easily readable.

                var i;
                gap = '';
                indent = '';

                // If the space parameter is a number, make an indent string containing that
                // many spaces.

                if (typeof space === 'number') {
                    for (i = 0; i < space; i += 1) {
                        indent += ' ';
                    }

                // If the space parameter is a string, it will be used as the indent string.

                } else if (typeof space === 'string') {
                    indent = space;
                }

                // If there is a replacer, it must be a function or an array.
                // Otherwise, throw an error.

                rep = replacer;
                if (replacer && typeof replacer !== 'function' &&
                    (typeof replacer !== 'object' ||
                        typeof replacer.length !== 'number')) {
                    throw new Error('JSON.stringify');
                }

                // Make a fake root object containing our value under the key of ''.
                // Return the result of stringifying the value.

                return str('', {
                    '': value
                });
            },


            parse: function (text, reviver) {

                // The parse method takes a text and an optional reviver function, and returns
                // a JavaScript value if the text is a valid JSON text.

                var j;

                function walk(holder, key) {

                    // The walk method is used to recursively walk the resulting structure so
                    // that modifications can be made.

                    var k, v, value = holder[key];
                    if (value && typeof value === 'object') {
                        for (k in value) {
                            if (Object.hasOwnProperty.call(value, k)) {
                                v = walk(value, k);
                                if (v !== undefined) {
                                    value[k] = v;
                                } else {
                                    delete value[k];
                                }
                            }
                        }
                    }
                    return reviver.call(holder, key, value);
                }


                // Parsing happens in four stages. In the first stage, we replace certain
                // Unicode characters with escape sequences. JavaScript handles many characters
                // incorrectly, either silently deleting them, or treating them as line endings.

                cx.lastIndex = 0;
                if (cx.test(text)) {
                    text = text.replace(cx, function (a) {
                        return '\\u' + ('0000' +
                            (+(a.charCodeAt(0))).toString(16)).slice(-4);
                    });
                }

                // In the second stage, we run the text against regular expressions that look
                // for non-JSON patterns. We are especially concerned with '()' and 'new'
                // because they can cause invocation, and '=' because it can cause mutation.
                // But just to be safe, we want to reject all unexpected forms.

                // We split the second stage into 4 regexp operations in order to work around
                // crippling inefficiencies in IE's and Safari's regexp engines. First we
                // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
                // replace all simple value tokens with ']' characters. Third, we delete all
                // open brackets that follow a colon or comma or that begin the text. Finally,
                // we look to see that the remaining characters are only whitespace or ']' or
                // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.

                if (/^[\],:{}\s]*$/.
                    test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
                        replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
                        replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {

                    // In the third stage we use the eval function to compile the text into a
                    // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
                    // in JavaScript: it can begin a block or an object literal. We wrap the text
                    // in parens to eliminate the ambiguity.

                    j = eval('(' + text + ')');

                    // In the optional fourth stage, we recursively walk the new structure, passing
                    // each name/value pair to a reviver function for possible transformation.

                    return typeof reviver === 'function' ?
                    walk({
                        '': j
                    }, '') : j;
                }

                // If the text is not JSON parseable, then a SyntaxError is thrown.

                throw new SyntaxError('JSON.parse');
            }
        };
    }();
}
