function verifyFieldsAreBlank()
{

    // Add Validation Code Here
    if (Ext.getCmp('firstName').getValue() == '')
    {
        Ext.Msg.show({
            title:'Invalid Entry',
            msg: 'Missing First Name',
            fn: resetCursor('firstName'),
            buttons: Ext.Msg.OK,
            icon: Ext.MessageBox.INFO
        });
        return false;
    }

    if (Ext.getCmp('email').getValue() == '')
    {
        Ext.Msg.show({
            title:'Invalid Entry',
            msg: 'Missing Email Address',
            fn: resetCursor('email'),
            buttons: Ext.Msg.OK,
            icon: Ext.MessageBox.INFO
        });
        return false;
    }

    if (Ext.getCmp('birthDate').getValue() == '')
    {
        Ext.Msg.show({
            title:'Invalid Entry',
            msg: 'Missing Birth Date',
            fn: resetCursor('birthDate'),
            buttons: Ext.Msg.OK,
            icon: Ext.MessageBox.INFO
        });
        return false;
    }

    if (Ext.getCmp('lastName').getValue() == '')
    {
        Ext.Msg.show({
            title:'Invalid Entry',
            msg: 'Missing Last Name',
            fn: resetCursor('lastName'),
            buttons: Ext.Msg.OK,
            icon: Ext.MessageBox.INFO
        });
        return false;
    }

    if (Ext.getCmp('phoneNumber').getValue() == '')
    {
        Ext.Msg.show({
            title:'Invalid Entry',
            msg: 'Missing Phone Number',
            fn: resetCursor('phoneNumber'),
            buttons: Ext.Msg.OK,
            icon: Ext.MessageBox.INFO
        });
        return false;
    }

    if (Ext.getCmp('gender').getValue() == '' || Ext.getCmp('gender').getValue() == 'Select your gender...')
    {
        Ext.Msg.show({
            title:'Invalid Entry',
            msg: 'Missing Gender',
            fn: resetCursor('gender'),
            buttons: Ext.Msg.OK,
            icon: Ext.MessageBox.INFO
        });
        return false;
    }

    return true;
}

function verifyStoreFieldsAreBlank()
{

    // Add Validation Code Here
    if (Ext.getCmp('firstName').getValue() == '')
    {
        Ext.Msg.show({
            title:'Invalid Entry',
            msg: 'Missing First Name',
            fn: resetCursor('firstName'),
            buttons: Ext.Msg.OK,
            icon: Ext.MessageBox.INFO
        });
        return false;
    }

    if (Ext.getCmp('email').getValue() == '')
    {
        Ext.Msg.show({
            title:'Invalid Entry',
            msg: 'Missing Email Address',
            fn: resetCursor('email'),
            buttons: Ext.Msg.OK,
            icon: Ext.MessageBox.INFO
        });
        return false;
    }

    if (Ext.getCmp('lastName').getValue() == '')
    {
        Ext.Msg.show({
            title:'Invalid Entry',
            msg: 'Missing Last Name',
            fn: resetCursor('lastName'),
            buttons: Ext.Msg.OK,
            icon: Ext.MessageBox.INFO
        });
        return false;
    }

    if (Ext.getCmp('phoneNumber').getValue() == '')
    {
        Ext.Msg.show({
            title:'Invalid Entry',
            msg: 'Missing Phone Number',
            fn: resetCursor('phoneNumber'),
            buttons: Ext.Msg.OK,
            icon: Ext.MessageBox.INFO
        });
        return false;
    }

    return true;
}

function displayMessage(title, msg)
{
    Ext.Msg.show({
        title: title,
        msg: msg,
        buttons: Ext.Msg.OK,
        icon: Ext.MessageBox.INFO
    });
}

function verifyContestantGenderMatchesDivision()
{

    var MALE = 'Male';
    var FEMALE = 'Female';

    if (Ext.getCmp('gender').getValue() == MALE)
    {
        if (Ext.getCmp('girls').getValue() || Ext.getCmp('openWomen').getValue() || Ext.getCmp('openWomenLongboard').getValue() || Ext.getCmp('proWomen').getValue())
        {
            displayMessage('Invalid Selection', 'Gender doesn\'t match event entered');
            return false;
        }
    }

    if (Ext.getCmp('gender').getValue() == FEMALE)
    {
        if (Ext.getCmp('boys').getValue() || Ext.getCmp('jrMen').getValue() || Ext.getCmp('openMen').getValue() || Ext.getCmp('proMen').getValue())
        {
            displayMessage('Invalid Selection', 'Gender doesn\'t match event(s) entered');
            return false;
        }
    }

    if (Ext.getCmp('masters').getValue() || Ext.getCmp('grandMasters').getValue() || Ext.getCmp('proBodyboard').getValue() || Ext.getCmp('proJunior').getValue() ||
            Ext.getCmp('menehune').getValue() || Ext.getCmp('tadpole').getValue() || Ext.getCmp('girls').getValue() ||
            Ext.getCmp('openWomen').getValue() || Ext.getCmp('openWomenLongboard').getValue() || Ext.getCmp('openMenLongboard').getValue() || Ext.getCmp('proWomen').getValue() ||
            Ext.getCmp('boys').getValue() || Ext.getCmp('jrMen').getValue() || Ext.getCmp('openMen').getValue() || Ext.getCmp('proMen').getValue())
    {
        return true;
    } else
    {
        displayMessage('Invalid Selection', 'Please select a contest division to enter');
        return false;
    }

    return true;
}

function computeEntryCost()
{

    var amateurEvent = 35;
    var proEvent = 100;
    var proJrEvent = 80;
    var total = 0;
    var amateurCount = 0;
    var proCount = 0;
    var proJrCount = 0;
    var tax = 2;

    if (Ext.getCmp('tadpole').getValue())
    {
        amateurCount = amateurCount + 1;
    }
    if (Ext.getCmp('menehune').getValue())
    {
        amateurCount = amateurCount + 1;
    }
    if (Ext.getCmp('boys').getValue())
    {
        amateurCount = amateurCount + 1;
    }
    if (Ext.getCmp('girls').getValue())
    {
        amateurCount = amateurCount + 1;
    }
    if (Ext.getCmp('jrMen').getValue())
    {
        amateurCount = amateurCount + 1;
    }
    if (Ext.getCmp('openMen').getValue())
    {
        amateurCount = amateurCount + 1;
    }
    if (Ext.getCmp('masters').getValue())
    {
        amateurCount = amateurCount + 1;
    }
    if (Ext.getCmp('grandMasters').getValue())
    {
        amateurCount = amateurCount + 1;
    }
    if (Ext.getCmp('openWomen').getValue())
    {
        amateurCount = amateurCount + 1;
    }
    if (Ext.getCmp('openMenLongboard').getValue())
    {
        amateurCount = amateurCount + 1;
    }
    if (Ext.getCmp('openWomenLongboard').getValue())
    {
        amateurCount = amateurCount + 1;
    }
    if (Ext.getCmp('proJunior').getValue())
    {
        proJrCount = proJrCount + 1;
    }
    if (Ext.getCmp('proMen').getValue())
    {
        proCount = proCount + 1;
    }
    if (Ext.getCmp('proWomen').getValue())
    {
        proCount = proCount + 1;
    }
    if (Ext.getCmp('proBodyboard').getValue())
    {
        proCount = proCount + 1;
    }

    // Add Amateur Event Costs
    total = total + (amateurCount * amateurEvent);

    // Add Pro Event Costs
    total = total + (proCount * proEvent);

    // Add ProJr Event Costs
    total = total + (proJrCount * proJrEvent);

    return total + tax;

}

function computeStoreCost()
{

    var total = Ext.getCmp('foodFestivalAllCanEat').getValue();
    total = total.substring(total.indexOf("$") + 1, total.length);

    return total;

}

function verifyFields()
{

    if (!verifyFieldsAreBlank())
    {
        return false;
    }

    if (!verifyContestantGenderMatchesDivision())
    {
        return false;
    }

    return true;

}

function verifyStoreFields()
{

    if (!verifyStoreFieldsAreBlank())
    {
        return false;
    }

    return true;

}

function resetCursor(fieldName)
{
    //Ext.getCmp(fieldName).focus();
}

function populateFormFields(priceToCharge)
{

    var currentIndex;
    var currentEventsEntered;

    switch (priceToCharge)
    {
        case 37:
            currentIndex = 0
            break;
        case 72:
            currentIndex = 1
            break;
        case 107:
            currentIndex = 2
            break;
        case 137:
            currentIndex = 3
            break;
        case 172:
            currentIndex = 4
            break;
        case 102:
            currentIndex = 5
            break;
        case 202:
            currentIndex = 6
            break;
        case 82:
            currentIndex = 7
            break;
        case 387:
            currentIndex = 8
            break;
        case 287:
            currentIndex = 9
            break;
        //new form values start here
        case 352:
            currentIndex = 0
            break;
        case 252:
            currentIndex = 1
            break;
        case 317:
            currentIndex = 2
            break;
        case 217:
            currentIndex = 3
            break;
        case 117:
            currentIndex = 4
            break;
        case 282:
            currentIndex = 5
            break;
        case 182:
            currentIndex = 6
            break;
    }

    document.getElementById('os0').selectedIndex = currentIndex;
    document.getElementById('os00').selectedIndex = currentIndex;
    document.getElementById('os1').value = Ext.getCmp('firstName').getValue() + " " + Ext.getCmp('lastName').getValue();
    document.getElementById('os11').value = Ext.getCmp('firstName').getValue() + " " + Ext.getCmp('lastName').getValue();
    currentEventsEntered = getEventsEntered();
    document.getElementById('os2').value = "Events Entered: " + currentEventsEntered + ", Email Address: " + Ext.getCmp('email').getValue() + ", Phone Number: " + Ext.getCmp('phoneNumber').getValue() +
            ", Birth Date: " + Ext.getCmp('birthDate').getValue() + ", Gender: " + Ext.getCmp('gender').getValue();
    document.getElementById('os22').value = "Events Entered: " + currentEventsEntered + ", Email Address: " + Ext.getCmp('email').getValue() + ", Phone Number: " + Ext.getCmp('phoneNumber').getValue() +
            ", Birth Date: " + Ext.getCmp('birthDate').getValue() + ", Gender: " + Ext.getCmp('gender').getValue();
}

function populateStoreFormFields(priceToCharge)
{

    var currentIndex;
    var currentStoreItems;

    switch (priceToCharge)
    {
        //Form #1 - All you can eat tickets
        case "25":
            currentIndex = 0
            break;
        case "50":
            currentIndex = 1
            break;
        case "75":
            currentIndex = 2
            break;
        case "100":
            currentIndex = 3
            break;
        //Form #2 - Five Restaurant Sample Tickets
        case "15":
            currentIndex = 0
            break;
        case "30":
            currentIndex = 1
            break;
        case "45":
            currentIndex = 2
            break;
        case "60":
            currentIndex = 3
            break;
    }

    document.getElementById('os0').selectedIndex = currentIndex;
    document.getElementById('os00').selectedIndex = currentIndex;
    document.getElementById('os1').value = Ext.getCmp('firstName').getValue() + " " + Ext.getCmp('lastName').getValue();
    document.getElementById('os11').value = Ext.getCmp('firstName').getValue() + " " + Ext.getCmp('lastName').getValue();
    currentStoreItems = getStoreItems();
    document.getElementById('os2').value = "Store Item(s): " + currentStoreItems + ", Email Address: " + Ext.getCmp('email').getValue() + ", Phone Number: " + Ext.getCmp('phoneNumber').getValue();

}

function getEventsEntered()
{

    var events = new Array(14);
    var eventsEntered = "";

    if (Ext.getCmp('tadpole').getValue())
    {
        events[0] = "Tadpole";
    }
    if (Ext.getCmp('menehune').getValue())
    {
        events[1] = "Menehune";
    }
    if (Ext.getCmp('boys').getValue())
    {
        events[2] = "Boys";
    }
    if (Ext.getCmp('girls').getValue())
    {
        events[3] = "Girls/Jr Women";
    }
    if (Ext.getCmp('jrMen').getValue())
    {
        events[4] = "Jr Men";
    }
    if (Ext.getCmp('openMen').getValue())
    {
        events[5] = "Open Men";
    }
    if (Ext.getCmp('masters').getValue())
    {
        events[6] = "Masters";
    }
    if (Ext.getCmp('grandMasters').getValue())
    {
        events[7] = "Grand Masters";
    }
    if (Ext.getCmp('openWomen').getValue())
    {
        events[8] = "Open Women";
    }
    if (Ext.getCmp('openMenLongboard').getValue())
    {
        events[9] = "Open Men\'s Longboard";
    }
    if (Ext.getCmp('openWomenLongboard').getValue())
    {
        events[10] = "Open Women\'s Longboard";
    }
    if (Ext.getCmp('proJunior').getValue())
    {
        events[11] = "Pro Junior";
    }
    if (Ext.getCmp('proMen').getValue())
    {
        events[12] = "Pro Men";
    }
    if (Ext.getCmp('proWomen').getValue())
    {
        events[13] = "Pro Women";
    }
    if (Ext.getCmp('proBodyboard').getValue())
    {
        events[14] = "Pro Bodyboard";
    }

    for (var i = 0; i < events.length; i++)
    {
        if (events[i] != "" && events[i] != undefined)
        {
            if (eventsEntered != "")
            {
                eventsEntered = eventsEntered + ", " + events[i];
            } else
            {
                eventsEntered = events[i];
            }
        }
    }
    return eventsEntered;
}

function getStoreItems()
{

    var items = new Array(1);
    var storeItemsPurchased = "";

    if (Ext.getCmp('foodFestivalAllCanEat').getValue().indexOf("$") > 0)
    {
        items[0] = "Food Ticket Purchase - All You Can Eat";
    }
    if (Ext.getCmp('foodFestivalFiveSample').getValue().indexOf("$") > 0)
    {
        items[1] = "Food Ticket Purchase - 5 Restaurant Sampler";
    }

    for (var i = 0; i < items.length; i++)
    {
        if (items[i] != "" && items[i] != undefined)
        {
            if (storeItemsPurchased != "")
            {
                storeItemsPurchased = storeItemsPurchased + ", " + items[i];
            } else
            {
                storeItemsPurchased = items[i];
            }
        }
    }
    return storeItemsPurchased;
}
