function getMRRDisplayPercentage() {
    return -1;
}

function MRRGetCookieVal (offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

function MRRGetCookie (name) {
    var arg = name + "=";
    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 MRRGetCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}

function MRRSetCookie (name, value) {
    var argv = MRRSetCookie.arguments;
    var argc = MRRSetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
}

function MRRDeleteCookie (name) {
    var exp = new Date();
    exp.setTime (exp.getTime() - 1);
    var cval = MRRGetCookie (name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function MRRCheckCookie() {
    var hasMRRBeenDisplayed = MRRGetCookie('MRRDisplayed');
    if (hasMRRBeenDisplayed != null) {
        //We do not show MRR Survey Pop-up since it has already been displayed in this browser session.
        return false;
    }
    var display_percentage = getMRRDisplayPercentage();
    // Generate Random Number 1-100
    var rand_no = Math.ceil( Math.random() * 100 );
    //alert("rand_no: "+ rand_no);
    // 75% of the time, just exit here
//alert(rand_no);
    if (rand_no > display_percentage) {
        return false;
    }	
    var favorite = MRRGetCookie('MRR');
    if (favorite == null) {
        //Show pop-up since there are no cookies to specify the contrary
        //MRRShowPopUp();
        return true;
    } else {
        //Nothing happens here, we won't drop a cookie until they select something...
        return false;
    }
}

function MRRCheckAndSetCookie(exptime, cookie_domain) {
    var expDays = exptime;
    var exp = new Date();
    exp.setTime(exp.getTime() + (expDays*24*60*60*1000)); // This logic will treat the variable expDays as days
    var favorite = MRRGetCookie('MRR');
    if (favorite == null) {
        //alert('The survey should be launched here, since there are no cookies active');
        //window.open("http://www.yahoo.com","","title,resizable,scrollbars")
        MRRSetCookie ('MRR','MyRecipes',exp, '/', cookie_domain);
    } else {
        //alert('A survey should NOT launched because a survey has been taken within the last month');
        return false;
    }
}
