<!--

/*************************************
"toss your cookies" by Martin Mahoney v 1.3 01/2001
the get, set, and delete functions are from the Javascript Bible
by Danny Goodman with some modification by me
*************************************/

// grab date, set an expiration date
var today = new Date();
// this var will be passed to setCookie() if you choose to 
// store it semi-permanently
var expiresNow = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);

// search cookie string for specific cookie name
// this is because Navigator stores all cookies 
// in one file and furthermore, when 2 cookies have the same domain
// they are lumped into one string, delimited by a ; and a space
function getCookie(name){
    var arg = name + "=";
    var aLen = arg.length;
    var cLen = document.cookie.length;
    var i = 0;
    // parse cookie for name substring
    while(i < cLen){
        var j = i + aLen;
        if(document.cookie.substring(i,j) == arg){
            // if there is a match, extract the related value
         //   alert(" this is the value" +getCookieVal(j));
            return getCookieVal(j);
        }
        // if not, start search again at beginning of next string
        i = document.cookie.indexOf(" ",i) + 1;
        // if there is nothing to search, i.e. no cookies at all, exit loop and return null
        if(i == 0){
            break;
        }
    }
    // no match, return null
    return null;
}

// extracts the value of whatever name was passed to getcookie()
function getCookieVal(offset){
    var endStr = document.cookie.indexOf(";",offset);
    // if indexof doesn't match a ; we are at the end of the file
    // or cookie, so grab the whole cookie string
    if(endStr == -1){
        endStr = document.cookie.length;
    }
    // de-URL encode, return plain text string
    return unescape(document.cookie.substring(offset,endStr));
}

// name and value are required, the rest are optional
// If you don't set an expiration time, the cookie is 
// only a session cookie, that is, it only exists in 
// memory for the duration of the user's visit
function setCookie(name,value,expires,path,domain,secure){
	document.cookie = name + "=" + escape(value) +            // set and encode name/value
    ((expires) ? "; expires=" + expires.toGMTString() : "") + // set exp. must be stored in GMT format
    ((path) ? "; path=" + path : "") +                        // best left to default. set this if you want make the cookie available to other documents in the site
    ((domain) ? "; domain=" + domain : "") +                  // best left to default. set this if you need to control what domain will access the cookie
    ((secure) ? "; secure" : "");  
                          // best left to default. set this if the cookie requires transmission via https
}

// name and value are required, the rest are optional
// by setting the expiration date to a prior date
// you can remove the cookie
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";
    }
}

// this function will selectively delete
// a given country from the itinerary cookie
// and reset it with the new values
function removeCookie(name, cntryName){
    
    var orgValue = getCookie(name);
    var index = orgValue.indexOf(cntryName);
    var subValue = orgValue.substring(0,index);
    var subValue2 = orgValue.substring(index + cntryName.length + 1, orgValue.length);
    setCookie('travelerItinerary', subValue + subValue2,expiresNow,"/");    
}

// set cookie for itinerary tool
// and check that they do not 
// exceed the max allowable entries
function eatCookies(name, cntryName){
	var cookieStr = getCookie(name);
	if(cookieStr == null)
	{
		setCookie('travelerItinerary', cntryName + "$", expiresNow, "/");
		return true;
	}
	
	itemsArray = cookieStr.split("$");
	if(itemsArray.length > 10)
	{
		alert("Your Itinerary is limited to 10 items");
		return false;
	}
	else
	{
    	var newValue = getCookie(name) + cntryName + "$";
    	setCookie('travelerItinerary',newValue,expiresNow,"/"); 
		return true;
	} 
}

// test if cookies are disabled
// to use the itinerary tool they
// must be enabled
function chkCookie(){
  setCookie('iscookieOK','cookieOK');
  if(getCookie('iscookieOK') == null){
    alert("You must have cookies enabled to use the My Itinerary tool. Please see your browser's help file to change this setting");
    theFlag = false;
  }
}

//-->