<!--
//
// Use the following variable to specify the maximum 
// number of times the user can submit the form
//
var maxSubmits = 1

function validate(frm)
{
    //
    // Get the "TotalSubmissions" cookie
    //
    var totalSubmits = eval(GetCookie('TotalSubmissions'))
    //
    // If it hasn't been set, initialize it to 0
    //
    if (totalSubmits == null)
        totalSubmits = 0
    //
    // See if totalSubmits is greater than or equal to maxSubmits
    //
    if (totalSubmits >= maxSubmits)
    {
        //
        // If so, don't submit the form
        //
        alert("It looks like you already voted today. Please vote another day!")
        return false
    }
    else
    {
        //
        // Otherwise, increment and save the cookie and submit the form
        //
        totalSubmits = totalSubmits + 1
        BakeIt(totalSubmits, "TotalSubmissions")
        return true
    }
}

//
// This function is for testing purposes only!
//
function ResetCounter()
{
    BakeIt(0, "TotalSubmissions")
}

function BakeIt(cookieData, cookieName) 
{
    //
    // Use this variable to set the number of days after which the cookie will expire
    //
    var days = 1;
    //
    // Calculate the expiration date
    //
    var expires = new Date ();
    expires.setTime(expires.getTime() + days * (24 * 60 * 60 * 1000)); 
    //
    // Set the cookie
    //
    SetCookie(cookieName, cookieData, expires);
}

function SetCookie(cookieName, cookieData, expireDate) 
{
    document.cookie = cookieName + "=" + escape(cookieData) + "; expires=" + expireDate.toGMTString();
}    

function GetCookie(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 GetCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
    }
    return null;
}

function GetCookieVal (offset) 
{
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}
//-->