// ##### Start common cookie functions ##### // Boolean variable set if alert should be displayed if cookie exceeds 4KB var caution = false; // JavaScript 1.0 compatibility if (location.replace == null) location.replace = location.assign; // name - name of the cookie // value - value of the cookie // [expires] - expiration date of the cookie (if null: end of current session) // [path] - path for which the cookie is valid (if null: path of calling document) // [domain] - domain for which the cookie is valid (if null: domain of calling document) // [secure] - boolean value for secure transmission function setCookie(name, value, expires, path, domain, secure) { var newCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); if (caution && (name + "=" + escape(value)).length >= 4000) { if (confirm("Cookie exceeds 4KB and will be cut!")) { document.cookie = newCookie; } } else { document.cookie = newCookie; } } // name - name of the desired cookie // * return string containing value of specified cookie or null if cookie does not exist function getCookie(name) { var cookieName = name + "="; var cookieNameSPos = document.cookie.indexOf(cookieName); if (cookieNameSPos == -1) { return null; } else { var cookieValueSPos = cookieNameSPos + cookieName.length var cookieValueEPos = document.cookie.indexOf(";", cookieValueSPos); if (cookieValueEPos == -1) { cookieValueEPos = document.cookie.length; } return unescape(document.cookie.substring(cookieValueSPos, cookieValueEPos)); } } // name - name of the cookie // [path] - path of the cookie (must be same as path used to create cookie) // [domain] - domain of the cookie (must be same as domain used to create cookie) // * path and domain default if assigned null or omitted if no explicit argument proceeds function deleteCookie(name, path, domain) { if (getCookie(name)) { document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; } } function showCookie(name) { alert(getCookie(name)); } // Return detour cookie value. // For use by bumpDetourCookie, testDetourCookie function _getNextDetourCookieValue(name) { var seen = getCookie(name); if (!seen) { seen = 0; } else if (seen == 'detoured') { // from prior versions of this script seen = 1; // they've seen it once } seen++; return seen; } var number_of_times = 3; // number of times to show to a given user var how_often = 3; // how often to inflict it (N of "every Nth page") var first_time = 1; // how many pages to show before the first roadblock // Return true if we should detour, false if not function testDetourCookie(name) { var seen = _getNextDetourCookieValue(name); if (seen % how_often == first_time && seen <= how_often * number_of_times) { return true; } else { return false; } } // Increment the detour cookie value. function bumpDetourCookie(name) { var seen = _getNextDetourCookieValue(name); var expires_at = (new Date((new Date()).getTime() + 86400000)); setCookie(name, seen, expires_at, '/', '.familyeducation.com'); } // This function is called from the detour page itself. // If cookie already set, redirects to destination page. // name - name of cookie associated with detour page function checkDetourCookie(name) { var t = testDetourCookie(name); bumpDetourCookie(name); if (t) { // Let the roadblock be shown by returning return; } else { // Go directly to the page var r = location.search.match(/[?&]page=([^&]*)/); if (r != null) { r = unescape(r[1]); location.replace(r); } else { alert('Could not find page parameter'); } } } // Customize roadblock frequency by calling this function // print-reg.html and page-reg.html is calling this function, at this time function setDetourCookieFreq(number_of_times_new, how_often_new, first_time_new) { if ( number_of_times_new ) { number_of_times = number_of_times_new; } if ( how_often_new ) { how_often = how_often_new; } if ( first_time_new ) { first_time = first_time_new; } } // ####### End common cookie functions #######