﻿        function getCookies() { return ""; }

	    Array.prototype.uniqueAry = function() {
	        var r = new Array();
	        o: for (var i = 0, n = this.length; i < n; i++) {
	            for (var x = 0, y = r.length; x < y; x++) {
	                if (r[x] == this[i]) {
	                    continue o;
	                }
	            }
	            r[r.length] = this[i];
	        }
	        return r;
	    }

	    function getCookie(cookieName) {
	        var dc = document.cookie;

	        //load external cookies from .canada.com if not currently on .canada.com
	        if (location.hostname.match(/\.canada\.com$/gi) == null)
	            dc += ";" + getCookies(); //append to existing document cookie

	        var cookie_str = ""; //this string will contain the value of the cookie name
	        var needle = "[A-Za-z0-9_-]*" + cookieName + "[A-Za-z0-9_-]*=[^;]+";
	        var regex = new RegExp(needle, "gi");
	        var matches = dc.match(regex);
	        if (matches != null) {
	            for (var x = 0; x < matches.length; x++)
	                matches[x] = matches[x].substring(matches[x].indexOf("=") + 1).replace(new RegExp("[\\s]+$", "g"), ""); //remove keyname prefix and trim
	            cookie_str = matches.join(",");
	            matches = cookie_str.split(",");
	            matches = matches.uniqueAry(); //remove duplicates
	            cookie_str = matches.join(";") + ";";
	        }
	        return unescape(cookie_str);
	    }

	    function getAdCookie() {
	        return getCookie("adcookie");
	    }

	    function setSurroundCookie(value) {
	        document.cookie = "surroundId=" + escape(value) + "; path=/";
	    }

	    function getSurroundCookie() {
	        var dc = document.cookie;
	        var prefix = "surroundId=";
	        var begin = dc.indexOf("; " + prefix);
	        if (begin == -1) {
	            begin = dc.indexOf(prefix);
	            if (begin != 0) return null;
	        }
	        else {
	            begin += 2;
	        }
	        var end = document.cookie.indexOf(";", begin);
	        if (end == -1) end = dc.length;
	        return unescape(dc.substring(begin + prefix.length, end));
	    }

	    // Setup for surround session.
	    var adid = ""; // used in the ad to start a surround session
	    var surroundTag = getSurroundCookie(); // Get surround session id from the cookie
	    if (surroundTag == null) // check if there was a surround session id in the cookie
	    {
	        surroundTag = "";
	    }
	    else {
	        surroundTag = "srnd=" + surroundTag + ";"; // finish setting up the key-value for the ad tags
	    }

	    //Setup for adcookie.
	    var adcookieTag = getAdCookie(); // Get the ad cookie string
	    
        // set ord value
	    var adOrdValue = Math.floor(Math.random()*90000000+1000000);
