function updateNav(mainNavId, mainNavTab, subNavId, subNavTab, onClassName) {
    if (mainNavTab != '') {
        var mnLinks = $('#' + mainNavId + ' a');
        var i = 0;

	    for (i=0;i<mnLinks.length;i++) {
	        if ($(mnLinks[i]).html().toLowerCase() == mainNavTab.toLowerCase()) {
	            $(mnLinks[i]).parent().addClass(onClassName);
	        }
	    }
    }

    // if (mnLinks[0].firstChild.innerHTML.toLowerCase() == mainNavTab.toLowerCase()) { mnLinks[0].className('current'); }
    if (subNavTab != '') {
        var snLinks = $('#' + subNavId + ' a');
        for (i=0;i<snLinks.length;i++) {
            if ($(snLinks[i]).html().toLowerCase() == subNavTab.toLowerCase()) {
                $(snLinks[i]).parent().addClass(onClassName);
            }
        }
    }
    return true;
}

function checkTeeSignProgram(teeSignAndProgramChosen) {
    var t = teeSignAndProgramChosen;
    var x = document.getElementById('teeSignOne');
    var y = document.getElementById('teeSignTwo');
    if (t == 'teeSignOne') {
        if (y.checked) {
            y.checked = false;
        }
    }
    else if (t == 'teeSignTwo') {
        if (x.checked) {
            x.checked = false;
        }   
    }
}

function resetSponsorLevel() {
    if (document.getElementById('noSponsor').checked) {
        document.getElementById('presentingSponsor').value = '0';
        document.getElementById('platinumSponsor').value = '0';
        document.getElementById('goldSponsor').value = '0';
        document.getElementById('silverSponsor').value = '0';
        document.getElementById('bronzeSponsor').value = '0';
    }
}


// START global vars
tempFieldValue = 'nothing';
// END global vars


function updateCart(formName, displayCart, doSubmit) {
    document.forms[formName].formSubmit.value = 'Please Wait...';
    document.forms[formName].formSubmit.disabled = true;
    if (!displayCart) {
        ColdFusion.Ajax.submitForm(formName, '/includes/cart-display.cfm?displayCart=false');
    }
    else {
        ColdFusion.Ajax.submitForm(formName, '/includes/cart-display.cfm', callBackCart, errorHandler);
    }
    if (doSubmit) {
        ColdFusion.navigate('billing.cfm');
        //document.forms[formName].submit();
    }
}

function callBackCart(text) {
    var x = document.getElementById('cartDisplay');
    x.innerHTML = text;
}
function errorHandler(code, msg) {
    alert('Error!! ' + code + ': ' + msg);
}
function changePaymentForm(paymentType) {
    var destUrl = '/includes/' + paymentType + '-form.cfm';
    ColdFusion.navigate(destUrl, 'paymentTypeFormContainer');
}
function clearInnerHTML(containerId) {
    var x = document.getElementById(containerId);
    x.innerHTML = '';
}
function editLink(editLink, container) {
    var thisHref = editLink.getAttribute('href');
    ColdFusion.navigate(thisHref, container);
}

function commitEdit(formName, container, paymentType) {
    var formSubmitUrl = '';
    var returnUrl = '';
    if (container == 'billAddressContainer') {
        formSubmitUrl = '/includes/code/update-billing.cfm';
        returnUrl = '/includes/code/remote-functions.cfc?method=getBillingAddress&type=' + paymentType;
    }
    else if (container == 'paymentInfoContainer') {
        formSubmitUrl = '/includes/code/update-billing.cfm';
        returnUrl = '/includes/code/remote-functions.cfc?method=getPaymentInfo&type=' + paymentType;
    }
    ColdFusion.Ajax.submitForm(formName, formSubmitUrl);
    ColdFusion.navigate(returnUrl, container);
}

function clearAndChangeColor(fieldId) {
    var x = document.getElementById(fieldId);
    x.value = '';
    x.style.color = '#000000';
}

function pushFieldValue(fieldValue) {
    tempFieldValue = fieldValue;
}
function popFieldValue() {
    return tempFieldValue;
}
function restoreFieldValue(fieldId, fieldValue) {
    if (fieldValue == '') {
        var x = document.getElementById(fieldId);
        x.value = tempFieldValue;
        x.style.color = '#888888';
    }
}

function showMorePlayers(playerLoopCount, numberToShow) {
    var firstToShow = (playerLoopCount*numberToShow)+1;
    var k = firstToShow+numberToShow;
    
    if (jsPlayerLoopCount < 11) {
        for (i=firstToShow; i<k; i++) {
            $('#playerInfo_' + i).show();        
        }
        jsPlayerLoopCount++;
        $('#playerName_' + eval((jsPlayerLoopCount*jsNumberOfPlayers)-3)).focus()
        if (jsPlayerLoopCount == 10) {
            $('#addMorePlayersSubmit').hide();
        }
    } 
}

function checkForRequiredFields(formName) {
    var i = 0;
    var requiredTextInputArray = ['payerFirstName','payerLastName','payerStreet1','payerCityName','payerPostalCode','payerPhone','payer'];
    var requiredSelectInputArray = ['payerStateOrProvince'];
    var currentSelect = '';
    var currentText = '';
    var alertMessage = '';
    var pto = document.billingForm.paymentType;
    var paymentType = "";
    
    for (i=0;i<pto.length;i++) {
        if (pto[i].checked) {
            paymentType = pto[i].value;
        }
    }
    
    switch(paymentType) {
        case 'creditCard': {
            requiredSelectInputArray.push('creditCardType');
            requiredTextInputArray.push('creditCardNumber');
            requiredSelectInputArray.push('expMonth');
            requiredSelectInputArray.push('expYear');
            requiredTextInputArray.push('cvv2');
            break;
        }
        case 'ledger': {
            requiredTextInputArray.push('ledgerNumber');
            break;
        }
        case 'invoice': {
            requiredTextInputArray.push('shipToName');
            break;
        }
    }
    
    for (i=0;i<requiredTextInputArray.length;i++) {
        currentText = document.getElementById(requiredTextInputArray[i]);
        if (currentText.value == '') {
            alertMessage = alertMessage + currentText.getAttribute('displayName') + '\n';
        }
    }
    for (i=0;i<requiredSelectInputArray.length;i++) {
        currentSelect = document.getElementById(requiredSelectInputArray[i]);
        if (currentSelect.options[currentSelect.selectedIndex].value == '') {
            alertMessage = alertMessage + currentSelect.getAttribute('displayName') + '\n';
        }
    }
    if (alertMessage != '') {
        alertMessage = 'All required fields must be completed:\n' + alertMessage;
        alert(alertMessage);
        return false; 
    }
    return true;
}

function checkForAlphaInNumeric(onWhatEvent,whichForm) {
    var golfNonAlphaArray = ['presentingSponsor','platinumSponsor','goldSponsor','silverSponsor','bronzeSponsor','cocktailForTen','cocktailForOne','caddies'];
    var wineDinnerNonAlphaArray = ['grandCruCorporateSponsorship','reservedCabernetTableSponsorship','individualSeat','raffleTicket'];
    var nonAlphaArray = "";
    var alertMsg = '';
    var showError = false;
    var showAlert = false;
    var i = 0;
    
    switch(whichForm) {
        case 'wineDinnerRegForm':
            nonAlphaArray = wineDinnerNonAlphaArray;
            break;
        case 'wineDinnerRaffleTicketForm':
            nonAlphaArray = ['raffleTicket'];
            break;
        default:
            nonAlphaArray = golfNonAlphaArray;
            break;
    }
    
    for (i=0; i<nonAlphaArray.length; i++) {
        var thisFF = document.getElementById(nonAlphaArray[i]);
        if (thisFF.value != '' && isNaN(thisFF.value)) { 
            showAlert = true;
            showError = true;
            alertMsg = alertMsg + thisFF.getAttribute('displayName') + '\n';
            highlightOrNotSponsorField(thisFF.id, true);
        } else {
            highlightOrNotSponsorField(thisFF.id, false);
        }
    }
    
    if (showError) {
        if (whichForm == 'wineDinnerRegForm') {
            $('#validationError').show('fast').css('background-color','#FF8F8F').html('<span style="padding-left:5px;">Only numbers allowed for quantities</span>');
            $('#validationErrorSpacer').show('fast');
        } else {
            showHideSponsorError('show');
        }        
    } else {
        if (whichForm == 'wineDinnerRegForm') {
            $('#validationError').hide('fast').css('background-color','transparent').html('');
            $('#validationErrorSpacer').hide('fast');
        } else {
            showHideSponsorError('hide');
        }
    }
    
    if (alertMsg != '') {
        alertMsg = 'Only numbers are allowed for quantities, please check the following fields:\n\n' + alertMsg + '\n\n';
        showAlert = true;
    }
    
    if (onWhatEvent == 'onSubmitEvent' && whichForm == 'wineDinnerRegForm') {
        if ($('#individualSeat').val() > 4) {
            alertMsg = alertMsg + 'You are only allowed to purchase four(4) Individual Seats\n\n';
            showAlert = true;
        }
    }
    
    if (onWhatEvent == 'onSubmitEvent' && showAlert) {
        alert(alertMsg);
        return false;
    }
}

function tennisReg(onWhatEvent) {
    var nonAlphaArray = ['tennisPlayerWithDinner','cocktailForTen','cocktailForOne'];
    var alertMsg = 'Only numbers are allowed for quantities, please check the following fields:\n\n';
    var showError = false;
    var showAlert = false;
    var i = 0;
    
    for (i=0; i<nonAlphaArray.length; i++) {
        var thisFF = document.getElementById(nonAlphaArray[i]);
        if (thisFF.value != '' && isNaN(thisFF.value)) { 
            showAlert = true;
            showError = true;
            alertMsg = alertMsg + thisFF.getAttribute('displayName') + '\n';
            highlightOrNotSponsorField(thisFF.id, true);
        } else {
            highlightOrNotSponsorField(thisFF.id, false);
        }
    }
    
    if (showError) {
        showHideSponsorError('show');
    } else {
        showHideSponsorError('hide');
    }
    
    if (onWhatEvent == 'onSubmitEvent' && showAlert) {
        alert(alertMsg);
        return false;
    }
}



function highlightOrNotSponsorField(thisId, isHighlighted) {
    var x = document.getElementById(thisId);
    
    if (isHighlighted) { 
        x.style.backgroundColor = '#FF8F8F';
    } else {
        x.style.backgroundColor = '#FFFFFF';
    }
}

function showHideSponsorError(showOrHide) {
    var y = document.getElementById('validationError');
    
    if (showOrHide == 'show') {
        y.style.display = 'block';
    y.style.backgroundColor = '#FF8F8F';
    y.innerHTML = 'Only numbers allowed for quantities';
    } else {
        y.style.display = 'none';
        y.style.backgroundColor = '#FFFFFF';
        y.innerHTML = '';
    }
}

function validateAddPlayersForm() {
    var x = document.getElementById('companyName');
    if (x.value == '') {
        alert('A Company Name is required to submit player information.');
        return false;
    }
    return true;
}
function changeCartForReview() {
    $('#orderDetails #detailsHeader div.deleteColumn').hide();
    $('#orderDetails div.orderDetailRow div.deleteColumn').hide();
    $('#orderDetails #checkoutButtons').hide();    
    $('#orderDetails .descColumn').css('width', '627px');
}
function undoChangeCartForReview() {
    $('#orderDetails #detailsHeader div.deleteColumn').show();
    $('#orderDetails div.orderDetailRow div.deleteColumn').show();
    $('#orderDetails #checkoutButtons').show();
    $('#orderDetails .descColumn').css('width', '549px');
}

function setOtherDonationAmount(amount) {
    $('#otherDonationAmount').attr('value', amount);
    return true;
}

function setOtherChecked() {
    $('#otherDonationAmount').attr('checked', true);
    return true;
}

function checkDonationForm() {
    var alertMessage = '';
    
    if ($('#donationAmount').val() == '' && $('#donationRecurMonthly:checked').length == 0) {
        alertMessage = alertMessage + '<li>You must either select a one-time donation amount or a monthly donation amount</li>';
    } else if ($('#donationRecurMonthly:checked').length && $('#monthlyDonationAmount').val() == '') {
        alertMessage = alertMessage + '<li>You must select an amount for your monthly donation</li>';        
    }
        
    if (alertMessage != '') {
        alertMessage = '<h2>The following information is required\:</h2><ul>' + alertMessage + '</ul>';
        $('#formErrorDialog').html(alertMessage);
        $('#formErrorDialog').dialog('open');
        return false;
    } else {
        return true;
    }    
}


function checkDonationAmount(amount) {    
    if (isNaN(amount)) {
        $('#donationAmount').addClass('fieldError');
        $('#messageContainer').html('Only numbers are allowed').show();
    } else {
        $('#donationAmount').removeClass('fieldError');
        $('#messageContainer').hide().html('');            
    }
    if (amount >= 5000) {
        highlightSponsorLevel('platinum');
    } else if (amount < 5000 && amount >=1000) {
        highlightSponsorLevel('gold');
    } else if (amount < 1000 && amount >= 500) {
        highlightSponsorLevel('silver');
    } else if (amount < 500 && amount >= 151) {
        highlightSponsorLevel('bronze');
	} else if (amount = 150) {
        highlightSponsorLevel('anniversary');
    } else if (amount <= 149 && amount > 0) {
        highlightSponsorLevel('contributor');
    } else {
        highlightSponsorLevel('none');
    }
}

function highlightSponsorLevel(level) {
    switch(level) {
        case 'platinum': {
            $('#platinum').addClass('selectedSponsorLevel');
            $('#gold').removeClass('selectedSponsorLevel');
            $('#silver').removeClass('selectedSponsorLevel');
            $('#bronze').removeClass('selectedSponsorLevel');
			$('#anniversary').removeClass('selectedSponsorLevel');
            $('#contributor').removeClass('selectedSponsorLevel');
            break;
        }
        case 'gold': {
            $('#platinum').removeClass('selectedSponsorLevel');
            $('#gold').addClass('selectedSponsorLevel');
            $('#silver').removeClass('selectedSponsorLevel');
            $('#bronze').removeClass('selectedSponsorLevel');
			$('#anniversary').removeClass('selectedSponsorLevel');
            $('#contributor').removeClass('selectedSponsorLevel');
            break;
        }
        case 'silver': {
            $('#platinum').removeClass('selectedSponsorLevel');
            $('#gold').removeClass('selectedSponsorLevel');
            $('#silver').addClass('selectedSponsorLevel');
            $('#bronze').removeClass('selectedSponsorLevel');
			$('#anniversary').removeClass('selectedSponsorLevel');
            $('#contributor').removeClass('selectedSponsorLevel');
            break;
        }
        case 'bronze': {
            $('#platinum').removeClass('selectedSponsorLevel');
            $('#gold').removeClass('selectedSponsorLevel');
            $('#silver').removeClass('selectedSponsorLevel');
            $('#bronze').addClass('selectedSponsorLevel');
			$('#anniversary').removeClass('selectedSponsorLevel');
            $('#contributor').removeClass('selectedSponsorLevel');
            break;
        }
		case 'anniversary': {
            $('#platinum').removeClass('selectedSponsorLevel');
            $('#gold').removeClass('selectedSponsorLevel');
            $('#silver').removeClass('selectedSponsorLevel');
            $('#bronze').removeClass('selectedSponsorLevel');
			$('#anniversary').addClass('selectedSponsorLevel');
            $('#contributor').removeClass('selectedSponsorLevel');
            break;
        }
        case 'contributor': {
            $('#platinum').removeClass('selectedSponsorLevel');
            $('#gold').removeClass('selectedSponsorLevel');
            $('#silver').removeClass('selectedSponsorLevel');
            $('#bronze').removeClass('selectedSponsorLevel');
			$('#anniversary').removeClass('selectedSponsorLevel');
            $('#contributor').addClass('selectedSponsorLevel');
            break;
        }
        default: {
            $('#platinum').removeClass('selectedSponsorLevel');
            $('#gold').removeClass('selectedSponsorLevel');
            $('#silver').removeClass('selectedSponsorLevel');
            $('#bronze').removeClass('selectedSponsorLevel');
			$('#anniversary').removeClass('selectedSponsorLevel');
            $('#contributor').removeClass('selectedSponsorLevel');
            break;
        }
    }
}



// 4 functions, the three transition functions, and the main animation function   
function startAnimation(fadeInMilliseconds, timeBetweenFade, timesToLoop) {
    // initializing vars
    var thisMod = 0;
    var thisDelay = timeBetweenFade;
    var loopIterations = (3*timesToLoop)-1;

    // the loop
    for (var i=0; i<=loopIterations; i++) {                        
        thisMod = i%3;
         
        setTimeout('transition' + thisMod + '(' + fadeInMilliseconds + ')', thisDelay);
         
        thisDelay = thisDelay+(fadeInMilliseconds+timeBetweenFade);
    }
}
 
function transition0(fadeDuration) {
    $('#image1').fadeOut(fadeDuration);
    $('#image2').fadeIn(fadeDuration);       
}
 
function transition1(fadeDuration) {
    $('#image2').fadeOut(fadeDuration);
    $('#image1').fadeIn(fadeDuration);
}
 

function checkMonthlyForm() {
    var reqFields = ['payerFirstName','payerLastName','payerStreet1','payerCityName','payerStateOrProvince','payerPostalCode','payerPhone','payer','ledgerNumber'];
    var checkboxFields = ['termsAndConditions'];
    var alertMessage= '';
    var thisCheckbox = '';
    
    for (var i=0; i<reqFields.length; i++) {
        if ($('#' + reqFields[i]).val() == '') {
            alertMessage = alertMessage + '<li>' + $('#' + reqFields[i]).attr('displayName') + '</li>';
        }
    }
    for (var k=0; k<checkboxFields.length; k++) {
        thisCheckbox = '#' + checkboxFields[k] + ':checked';
        if (!$(thisCheckbox).length) {
            alertMessage = alertMessage + '<li>' + $('#' + checkboxFields[k]).attr('displayName') + '</li>';
        }
    }
    if (alertMessage != '') {
        alertMessage = '<h2>The following information is required:</h2><ul>' + alertMessage + '</ul>';
        $('#formErrorDialog').html(alertMessage);
        $('#formErrorDialog').dialog('open');
        return false;
    } else {
        disableSubmit();
        return true;
    }   
}
function disableSubmit() {
    $('#formSubmit').attr( {
        disabled: 'disabled',
        value: 'Processing...'        
    }).css('color', '#DFDFDF');
    $('img.submitLoading').show();    
} 
function unDisableSubmit() {
    $('#formSubmit').removeAttr('disabled');
}

function checkInsuranceFields() {
    var success = true;
    
    $('#lifeInsuranceSpecifics input').each(function() {
        if (this.value == '') {
            success = false;
        } 
    });
    
    return success;
}

function checkLegacyForm() {
    var reqFields = ["fullName","streetAddress1","cityName","stateOrProvince","postalCode","phoneNumber","emailAddress","signatureName","signatureDate"];
    var alertMessage= '';
    var insuranceFieldsEmpty = true;
    
    for (var i=0; i<reqFields.length; i++) {
        if ($('#' + reqFields[i]).val() == '') {
            alertMessage = alertMessage + '<li>' + $('#' + reqFields[i]).attr('displayName') + '</li>';
        }
    }
    if (alertMessage != '') {
        alertMessage = '<h3>The following fields are required:</h3><ul>' + alertMessage + '</ul>';
    }
    
    if ($('#charitableBequest:checked').length && !$('#charitableBequestMethodContainer input:checked').length) {
        alertMessage = alertMessage + '<p>If you select Charitable Bequest, you must select a type</p>';
    }
    
    if ($('#lifeInsuranceDesignation:checked').length && !checkInsuranceFields()) {
        alertMessage = alertMessage + '<p>If you select Life Insurance Designation, you must fill in all the associated fields listed below it</p>';
    }
    
    if ($('#recognitionName').val() == '' && !$('#recognitionNameAnonymous:checked').length) {
        alertMessage = alertMessage + '<p>You must either provide a name for recognition or click the checkbox to remain anonymous</p>';
    }
    
    
    // if alertMessage is not blank, it means we got some errors...so now we'll add more text
    //  to the error message and pop it up in a pretty dialog box
    if (alertMessage != '') {   
        $('#formErrorDialog').dialog('option', 'title', 'Error');     
        $('#formErrorDialog').html(alertMessage);
        $('#formErrorDialog').dialog('open');
        return false;
    } else {
        //disableSubmit();
        
        // debugging
        /*
        $('#formErrorDialog').html('<p>Form Validation Passed</p>');
        $('#formErrorDialog').dialog('open');
        return false;
        */
        return true;
    }
    
}


      


