// put page title in status bar
window.status = 'Medic Assist International';

// menuover
function menuover(id, pg) {
        // colour the button
        document.getElementById('m1_'+id).className='menulft_on';
        document.getElementById('m2_'+id).className='menumid_on';
        document.getElementById('m3_'+id).className='menurt_on';
        // close any open submenus, unless they need to stay open (project pages)
        if (pg != 'project') {
        var i = 1;
                while (i < 6) {
                var row = document.getElementById('submenu_'+i)
                if (row) {
                        var display = row.style.display;
                        row.style.display = 'none';
                }
                i++;
                }
        }
        }

// menuout
function menuout(id) {
        document.getElementById('m1_'+id).className='menulft_off';
        document.getElementById('m2_'+id).className='menumid_off';
        document.getElementById('m3_'+id).className='menurt_off';
        }

// submenuover
function submenuover(id) {
        // colour the button
        document.getElementById('m1_'+id).className='menulft_on';
        document.getElementById('m2_'+id).className='menumid_on';
        document.getElementById('m3_'+id).className='menurt_on';
        }

// show/hide submenus
function showsubmenu(id) {
        // show the submenu
        var row = document.getElementById(id);
        var display = row.style.display;
        row.style.display = '';
}

// validate 'updates' form
function validateUpdates() {
        var validForm = true;
        if(document.updates.email.value == ""){
                validForm = false
        }
        if(validForm) {
                document.updates.submit();
        }
        else {
                alert("Please ensure you enter a valid email address.");
        }
}

// validate 'emailus' form
function validateEmailus() {
        var validForm = true;
        var nameAlert = "";
        var contactAlert = "";
        var enquiryAlert = "";

        if(document.emailus.realname.value == ""){
                validForm = false
                var nameAlert = "Please include your name. \n";
        }

        if(document.emailus.email.value == "" && document.emailus.phone.value == "" && document.emailus.address.value == ""){
                validForm = false
                var contactAlert = "Please include details of how we can contact you. \n";
        }

        if(document.emailus.enquiry.value == ""){
                validForm = false
                var enquiryAlert = "Please include your enquiry. \n";
        }

        if(validForm) {
                document.emailus.submit();
        }
        else {
                alert("In order to process your enquiry, please follow the instructions below:\n\n" + (nameAlert) + (contactAlert) + (enquiryAlert));
        }
}

// validate donation_form form
function validate_donation_form() {
        var validForm = true;
        var validContactDetails = true;
        var amountAlert = "";
        var databaseAlert = "";
        var giftaidAlert = "";

        // this gets the value of the selected radio button and inserts it into a variable called selType
        var selType = null;
        var st = document.donation_form.gift_aid;
        for (i = 0; i < st.length; i++) {
                if (st[i].checked) {
                        selType = st[i].value;
                }
        }

        if((document.donation_form.pay_pounds.value == "0") && (document.donation_form.pay_pence.value == "00")){
                validForm = false
                var amountAlert = "Please enter the amount you wish to donate. \n";
        }

        if((selType == "Yes") && ((document.donation_form.fullname.value == "") || (document.donation_form.address.value == ""))){
                validForm = false
                var giftaidAlert = "If you have chosen to make a Gift Aid decleration, please supply your full name and address. \n";
        }

        if ((document.donation_form.address.value == "") && (document.donation_form.email.value == "")) { validContactDetails = false; } else { validContactDetails = true; }
        if((document.donation_form.db_box.checked) && ((document.donation_form.fullname.value == "") || (validContactDetails == false))){
                validForm = false
                var databaseAlert = "If you have chosen to receive news from MAI, please provide contact details. \n";
        }


        if(validForm) {
                document.donation_form.button.value = "Sending...";
                document.donation_form.button.disabled = true;

                document.donation_form.gift_aid_sel.value = selType;

                if (document.donation_form.db_box.checked) {
                        document.donation_form.db_confirm.value = "Yes";
                }
                else {
                        document.donation_form.db_confirm.value = "No";
                }

                if (document.donation_form.project_box.checked) {
                        document.donation_form.transferable_donation.value = "No";
                }
                else {
                        document.donation_form.transferable_donation.value = "Yes";
                }

                document.donation_form.submit();
        }
        else {
                alert("In order to process your donation, please correct the error(s) listed below:\n\n" + (amountAlert) + (databaseAlert) + (giftaidAlert));
        }
}
