// Copyright 2003, NandoMedia InSite registration system

function getCookieVal(offset) {
 var endstr=document.cookie.indexOf(";",offset);
 if (endstr==-1)
 endstr=document.cookie.length;
 return unescape(document.cookie.substring(offset,endstr));
}
function GetCookie(cname) {
 var arg=cname+"="; var alen=arg.length;
 var clen=document.cookie.length; var i=0;
 while (i<clen) {
 var j=i+alen;
 if (document.cookie.substring(i,j)==arg) return getCookieVal (j); i=document.cookie.indexOf("",i)+ 1;
 if (i==0) break;
 } return null;
}
function SaveCookie(cname,cvalue,cdays,cpath) {
 ex = new Date; ex.setTime(ex.getTime() + (cdays*86400000));
 if (cpath == null) { cpath = "/" }
 else { cpath = "; path=" + cpath }
 document.cookie=cname + '=' + cvalue + '; expires=' + ex.toGMTString() + cpath + "; domain=.chron.com";
}


// Cookie Cleanup Script
var insitecookie="chron_user_auth";
var pluckcookie="hd";
var loginpage="http://www.chron.com/apps/pluck/login.mpl?url=";
var tmpvalue3=0;

var thePluckCookie = GetCookie(pluckcookie);
if (thePluckCookie == ".null") {
   thePluckCookie = "";
}
var theInsiteCookie= GetCookie(insitecookie);
if (theInsiteCookie == ".null") {
   theInsiteCookie = "";
}
//alert("PluckCookie: " + thePluckCookie + "\nInsiteCookie: " + theInsiteCookie);

// silly logic...
var redir = 0; // do nothing
if (theInsiteCookie) {
   if (! thePluckCookie) {
     document.location=loginpage+escape(document.location);
   }
} else {
   if (thePluckCookie) {
     SaveCookie(pluckcookie,'',0,'/');
     //document.location=loginpage+escape(document.location);
   }
}
