﻿function RemoveLabel(event, control, defaultValue, newValue)
{
    if(control.options[0].innerHTML == defaultValue)
    {
        Element.remove(control.options[0]);
    }
}

function AgeVerify(e)
{
    var month = $(ClientIDs.month).value;
    var year = $(ClientIDs.year).value;
    var day = $(ClientIDs.day).value;

    new Ajax.Request(callbackPage, {
      method: 'post',
      parameters: { action: 'verify', month: month, year: year, day: day, cookie: cookieName },
      onSuccess: function(transport) {
        var text = transport.responseText;
        if(text == "True")
        {
          eval(callbackSuccessFunction);
        }
        else
        {
          eval(callbackFailureFunction);
        }
      },
      onFailure: function(transport) {
        error.innerHTML = "Please provide a valid date of birth.";
      }
    });
    
    return false;
}

function AgeVerifyWithRedirect(e)
{
    var month = $(ClientIDs.month).value;
    var year = $(ClientIDs.year).value;
    var day = $(ClientIDs.day).value;

    new Ajax.Request(callbackPage, {
      method: 'post',
      parameters: { action: 'verify', month: month, year: year, day: day, cookie: cookieName },
      onSuccess: function(transport) {
        var text = transport.responseText;
        if(text == "True") {
          window.location.href = successUrl;
        }
        else {
          window.location.href = failureUrl;
        }
      },
      onFailure: function(transport) {
        error.innerHTML = "Please provide a valid date of birth.";
      }
    });
    
    return false;
}