// GENERIC COOKIE FUNCTIONS
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 }
//don't assume www at front (failed on gamma-proxy).  look from other end, get .com out and then get the
//thing up to the first optional dot.  so if it's nandomedia.com or gamma-proxy.nandomedia.com or
//www.second.nandomedia.com it all gets set on nandomedia.com
// not like this:        sitedom=location.hostname.replace(/www\./,"");
// Split the hostname into an array so www.example.com => ("www","example","com")
       domain_array = location.hostname.split(".");
// Use the last two elements of the array to get your tier 2 domain
       t1=domain_array.pop();
       t2=domain_array.pop();
       sitedom= "." + t2 + "." + t1;
       document.cookie=cname + '=' + cvalue + '; expires=' + ex.toGMTString() + cpath + "; domain="+sitedom;
}
var oldc  = GetCookie( 'modbee_user_auth' );
var newc = GetCookie( 'modestomerced_user_auth');
if (newc && newc.indexOf( '.threshold' ) == -1) {
//this is copy of new cookie to old for harvest info integration--do not put this
//line in until 4.2 is turned off!
    SaveCookie('modbee_user_auth', escape(newc), 364, '/');
}
// the first if test failed, that means we don't have a non-threshold
// new cookie, so if we have an old non-threshold cookie we want it
// copied over
else if (oldc  &&  oldc.indexOf( '.threshold' ) == -1 ){
    //we have an non-threshold old cookie, copy it to the new one
    SaveCookie('modestomerced_user_auth', escape(oldc), 364, '/');
}
else {
}

