// Read a cookie from the browser function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return ""; } // Read a value from a multi-valued cookie function readCookieItem(cookieName, itemName, defaultValue) { var cookieValue = unescape(readCookie(cookieName)); var resultValue = defaultValue; if (cookieValue != '') { var itemIndex = cookieValue.indexOf(itemName + '='); if (itemIndex > -1) { // Get the index of the delimitor after the item we want var multiValueSplitIndex = cookieValue.indexOf('&', itemIndex); if (multiValueSplitIndex == -1) { // No delimitor, so we reached the end of the values multiValueSplitIndex = cookieValue.length; } // Make sure the indexes are valid if (multiValueSplitIndex > -1 && itemIndex < multiValueSplitIndex) { resultValue = cookieValue.substring(itemIndex + itemName.length + 1, multiValueSplitIndex); } } } return resultValue; } // Set a cookie on the user's browser function setCookie(name, value, expires, path, domain, secure) { // set time, it's in milliseconds var today = new Date(); today.setTime(today.getTime()); //if the expires variable is set, make the correct expires time, the current script below will set it for x number of days, to make it for hours, delete * 24, for minutes, delete * 60 * 24 if (expires) { expires = expires * 1000 * 60 * 60 * 24; } var expires_date = new Date(today.getTime() + (expires)); document.cookie = name + ' = ' + escape(value) + ((expires) ? '; expires = ' + expires_date.toGMTString() : '') + ((path) ? '; path = ' + path : '') + ((domain) ? '; domain = ' + domain : '') + ((secure) ? '; secure' : ''); } // Read a value from the query string function readQueryStringValue(itemName) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split("="); if (pair.length > 1) { if (pair[0] == itemName) { return pair[1]; } } } return ""; } // This will read the values from the query string and cookie the user for 30 days. // The values will be read from the confirmation page if the referred user registers // for an event. Note that sActiveUrl comes from config.js. function buildAffiliateCookie() { var clickId = readQueryStringValue("ltclickid"); var campaignId = readQueryStringValue("ltcmp"); if (clickId != "" && campaignId != "") { // Encodes into a multi-valued cookie var value = "ltcmp=" + campaignId + "<clickid=" + clickId; // TODO: Set your domain var domain = 'advantageqa.active.com'; setCookie("affiliate", value, 30, "/", domain); //$.cookie('affiliate', 'value', { expires: 30, path: '/' }); } } function deleteAffiliateCookie() { var domain = 'advantageqa.active.com'; setCookie("affiliate", '', -1, "/", domain); } function readAffiliateClickId() { return readCookieItem("affiliate", "ltclickid", ""); } function readAffiliateCampaignId() { return readCookieItem("affiliate", "ltcmp", ""); }