cookie redirect

http://stackoverflow.com/questions/9145187/if-cookie-does-not-exist-alert-and-redirect

JavaScript

/* needed a set cookie function for dema*/
function setCookie(c_name,value,exdays) {
    var exdate=new Date();
        exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
}
/*end*/

function getCookie(c_name) {
    var c_value = document.cookie;
    var c_start = c_value.indexOf(" " + c_name + "=");
    if (c_start == -1) c_start = c_value.indexOf(c_name + "=");
    if (c_start == -1) {
        c_value = null;
    } else {
        c_start = c_value.indexOf("=", c_start) + 1;
        var c_end = c_value.indexOf(";", c_start);
        if (c_end == -1) {
            c_end = c_value.length;
        }
        c_value = unescape(c_value.substring(c_start, c_end));
    }
    return c_value;
}

var acookie = getCookie("cookiename");
if (!acookie) {
    alert("Cookie not found.");
}
setCookie('cookiename', 'test', '2');

/* check it again */

var acookie = getCookie("cookiename");
if (acookie) {
    alert("Cookie found. The value is : "+ acookie);
}