﻿function getTheDate() {
    var theDate = new Date();
    theDate.setDate(theDate.getDate() + 1);
    var hourOffset = parseInt(theDate.getTimezoneOffset() / 60);
    theDate.setUTCHours(hourOffset);
    theDate.setUTCMinutes(0);
    theDate.setUTCSeconds(0);
    theDate.setUTCMilliseconds(0);
    return theDate.toGMTString();
}

function setSponserCookie(value) {
    var theDate = getTheDate();
    document.cookie = "BerksGameDay_DS=" + escape(value) +
((theDate == null) ? "" : ";expires=" + theDate);
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function checkCookie() {
    username = getCookie('username');
    if (username != null && username != "") {
        alert('Welcome again ' + username + '!');
    }
    else {
        username = prompt('Please enter your name:', "");
        if (username != null && username != "") {
            setCookie('username', username, 365);
        }
    }
}

function gup(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}


function checkDailySponser(page) {
    if (getCookie("BerksGameDay_DS") == '' || getCookie("BerksGameDay_DS") == null) {
        setSponserCookie('false')
    }

    if (getCookie("BerksGameDay_DS") == 'false') {
        setSponserCookie('true')
        window.location = 'http://BerksGameDay.com/SponsoredBy.aspx?page=' + page;
    }
}


