// license_agree.js -- JavaScript utilities for license agreement
//
//  Version 1.2, 12 Nov 2003, J^T
//
//  Copyright © 2003, Electronic Data Systems Corporation.  All Rights Reserved.
//
// Usage: In pages requiring agreement, do two things:
//     1. In the HEAD element, include this script block:
//         <script type="text/javascript" language="JavaScript1.1" src="license_agree.js">
//     2. In the BODY tag, add the attribute onload="checkAgreed()"
//

// Increment this to require acceptance of a new license agreement from existing users

agreementVersion = 3;

agreementPageURL = "cpt_agree.shtml";

agreementCookieName = "AMA_CPT_licence_agreed";

agreementExpireDays = 365;




// Sets cookie values. Expiration date is optional
//
function setCookie(name, value, expire) {
    document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
}

// Returns a cookie value, given the name of the cookie.
//
function getCookie(name) {
    var search = name + "=";
    if (document.cookie.length > 0) {
        var offset = document.cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            var end = document.cookie.indexOf(";", offset);
            if (end == -1) {
                end = document.cookie.length;
            }
            return unescape(document.cookie.substring(offset, end));
        }
    }
}

// Check if user has "agreed" cookie, and redirect to agreement page if not.
//
function checkAgreed() {
	check_here = 1;
    if (getCookie(agreementCookieName) != agreementVersion) {
        window.location = agreementPageURL;
    }
	//mladdevents();
	//window.onload = mladdevents();
}

// User has pressed agree button.  Set cookie.
//
function userAgreed() {
	// Silliness here: AMA has agree to a year long session cookie, but the bureaucracy seems to...
	// ..."do what we've always done" and annoy the end users.  When that changes, uncomment the below.
	var agreeCookieExpireDate = null;//new Date();
	//agreeCookieExpireDate.setTime(agreeCookieExpireDate.getTime() + agreementExpireDays * 86400000 /*millisec per day*/);
	setCookie(agreementCookieName, agreementVersion, agreeCookieExpireDate);
    
	 //window.history.go(-1);
	
	//alert(document.referrer);
	if (navigator.userAgent.indexOf("MSIE") != -1) 
		{ // MSIE use go(-1) :-(
		window.history.go(-1);
		}
	else
		{ // Mozilla use document.referrer :-(
		window.location = document.referrer;
		}
	//alert(navigator.userAgent);
	
	if (navigator.userAgent.indexOf("Safari/85") != -1) { // Safari v85.x -- history bug :-(
        alert("Please re-select the link you wish to view.");
    }
}

// User has pressed reject button.  Back them out of the CPT content page.
//
function userRejected() {
    window.history.go(-2);
}

//mladdevents();
