﻿var _rdoAnnuallyId, _rdoMonthlyId, _fldAnnuallyId, _fldMonthlyId, _btnSubmit;
var _currType = "ANNUAL";
var alertBox;

var fldAnnual, fldMonthly, btnSubmit;

function InitTags(rdoAnnuallyId, rdoMonthlyId, fldAnnuallyId, fldMonthlyId, btnSubmitId)
{
    _rdoAnnuallyId = rdoAnnuallyId;
    _rdoMonthlyId = rdoMonthlyId;
    _fldAnnuallyId = fldAnnuallyId;
    _fldMonthlyId = fldMonthlyId;
    _btnSubmitId = btnSubmitId;


    document.getElementById(_rdoAnnuallyId).checked = true;

    fldAnnual = document.getElementById(_fldAnnuallyId);
    fldMonthly = document.getElementById(_fldMonthlyId);
    btnSubmit = document.getElementById(_btnSubmitId);

    alertBox = document.getElementById("alertBox");
    TogglePledge(_currType);
}

function TogglePledge(type)
{
    _currType = type;

    objAnnuallyPanel = fldAnnual.parentNode.parentNode;
    objMonthlyPanel = fldMonthly.parentNode.parentNode;


    if (_currType == "ANNUAL")
    {
        fldAnnual.disabled = false;
        fldMonthly.disabled = true;

        fldAnnual.focus();
        fldAnnual.select();

        objMonthlyPanel.style.backgroundColor = null;
        objAnnuallyPanel.style.backgroundColor = "#ffa700";
    }
    else if (_currType == "MONTHLY")
    {
        document.getElementById(_fldAnnuallyId).disabled = true;
        document.getElementById(_fldMonthlyId).disabled = false;

        fldMonthly.focus();
        fldMonthly.select();

        objAnnuallyPanel.style.backgroundColor = null;
        objMonthlyPanel.style.backgroundColor = "#ffa700";
    }

    alertBox.innerHTML = null;
    alertBox.style.display = "none";
}

function CheckInput()
{
    btnSubmit.disabled = false;

    if (_currType == "ANNUAL" && fldAnnual.value.length > 0)
    {
        if (parseInt(fldAnnual.value) < 600)
        {
            //alertBox.innerHTML = "Please note, your donation amount is less than $600 and does not qualify you to become a Friend of Grassroots";
            //alertBox.className = "AlertBox AlertWarning";

            //return confirm("We thank you for your pledge. However please note, your donation amount is less than $600 and does not qualify you to become a Friend of Grassroots\n\nClick OK to continue or CANCEL to change the amount.");
            return true;
        }
        else if (parseInt(fldAnnual.value) >= 600)
        {
            //alertBox.innerHTML = "You qualify as a Friend of Grassroots!";
            //alertBox.className = "AlertBox AlertMessage";

            alert("Congratulations! You qualify as a Friend of Grassroots! This donation will be billed once.\n\nClick OK to continue.");
            return true;
        }

        alertBox.style.display = "";
    }
    else if (_currType == "MONTHLY" && fldMonthly.value.length > 0)
    {
        if (parseInt(fldMonthly.value) < 50)
        {
            //alertBox.innerHTML = "The monthly donation amount you have entered is less than $50 and does not meet the minimum requirement to become a Friend of Grassroots.\n\nYou must enter a One-Time donation if you wish to pledge this amount.";
            //alertBox.className = "AlertBox AlertError";

            //btnSubmit.disabled = true;
            alert("Because your donation is less than $50 and does not qualify for becoming a Friend of Grassroots, you must enter your donation as a One-Time donation.\n\nPlease change your selection to One-Time Donation and enter and enter your amount.");
            TogglePledge("ANNUAL");
            return false;
        }
        else if (parseInt(fldMonthly.value) >= 50)
        {
            //alertBox.innerHTML = "Congratulation! You qualify as a Friend of Grassroots!";
            //alertBox.className = "AlertBox AlertMessage";

            alert("Congratulations! You qualify as a Friend of Grassroots! This donation amount be will billed monthly.\n\nClick OK to continue.");
            return true;
        }

        //alertBox.style.display = "";
    }
    //else
    //return false;


}

function Validate()
{
    if (_currType == "ANNUAL" && (fldAnnual.value.length == 0 || !IsValidNumber(fldAnnual.value)))
    {
        //alertBox.innerHTML = "Please enter a valid One-Time donation.";
        //alertBox.className = "AlertBox AlertError";
        //alertBox.style.display = "";
        alert("Please enter a valid One-Time donation.");

        fldAnnual.focus();

        return false;
    }
    else if (_currType == "MONTHLY" && (fldMonthly.value.length == 0 || !IsValidNumber(fldMonthly.value)))
    {
        //alertBox.innerHTML = "Please enter a valid Monthly donation.";
        //alertBox.className = "AlertBox AlertError";
        //alertBox.style.display = "";

        alert("Please enter a valid Monthly donation.");

        fldMonthly.focus();

        return false;
    }
    else if (!CheckInput())
        return false;
    else
    {
        alertBox.innerHTML = "";
        alertBox.className = null;
        alertBox.style.display = "none";

        return true;
    }


}

function ToggleCVV2()
{

    if ($("#CVV2").is(":hidden"))
        $("#CVV2").slideDown("slow");
    else
        $("#CVV2").hide("slow");
}
            