﻿function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function hasVideoPlayed(swf) {
    // This function manipulates a cookie to prevent the home page video from playing more than once.
    if (readCookie(swf) != null) {
        // Found the name of the video.  Its presence is sufficient to deduce that the video has been watched.
        return true;
    }
    else {
        // Haven't viewed this particular video yet.  Add the name of the video.
        createCookie(swf, "1", 365);
        return false;
    }
}
