function commentStringFix(comment) {
    if (comment == "Tell us about your upcoming events." || comment == "Add additional information here." || comment == "Add other comments here." || comment == "Add comments or questions here.")
    {
        comment = "";
    }
    return comment;
}

function getSatisfactionLevel(radioSet)
{
    var value;
    for (var i = 0; i < radioSet.length; i++)
    {
        if (radioSet[i].checked)
        {
            value = radioSet[i].value;
        }
    }
    if (value == "n/a")
    {
        value = "NA";
    }
    else if (Number(value) > 7)
    {
        value = value + " of 9 : Very Satisfied"
    }
    else if (Number(value) > 3)
    {
        value = value + " of 9 : Satisfied"
    }
    else
    {
        value = value + " of 9 : Dissatisfied"
    }
    return value;
}

function submitEventRequest()
{
    var error = document.getElementById("error");
    var eventRequest = document.getElementById("eventRequest");
    var name = eventRequest.name.value;
    if (name.length < 1)
    {
        error.innerHTML = "<i>* Please enter the event coordinator name.</i>";
    }
    else
    {
        var phone = eventRequest.phone.value;
        if (phone.length < 1)
        {
            error.innerHTML = "<i>* Please enter a phone number.</i>";
        }
        else
        {
            var email = eventRequest.email.value;
            if (email.length < 1)
            {
                error.innerHTML = "<i>* Please enter an email address.</i>";
            }
            else if (email.indexOf("@") == -1 || email.indexOf(".") == -1)
            {
                error.innerHTML = "<i>* Please enter a valid email address.</i>";
            }
            else
            {
                var event = eventRequest.event.value;
                var eventLocation = eventRequest.eventLocation.value;
                var eventStart = eventRequest.eventStart.value;
                var eventEnd = eventRequest.eventEnd.value;
                var notes = commentStringFix(eventRequest.notes.value);
                var message = "Event Coordinator: " + name + "\r\n";
                message += "Phone Number: " + phone + "\r\n";
                message += "Email: " + email + "\r\n";
                message += "Event Name: " + event + "\r\n";
                message += "Event Location: " + eventLocation + "\r\n";
                message += "Event Date: " + eventStart + " to " + eventEnd + "\r\n";
                message += "Additional Information: " + notes + "\r\n";
                eventRequest.message.value = message;
                eventRequest.submit();
            }
        }
    }
}

function submitSurvey() {
    var error = document.getElementById("error");
    var survey = document.getElementById("survey");
    var email = survey.email.value;
    var name = survey.name.value;
    if (name.length < 1)
    {
        error.innerHTML = "<i>* Please enter your name.</i>";
    }
    else {
        var event = survey.event.value;
        if (event.length < 1)
        {
            error.innerHTML = "<i>* Please enter the event name.</i>";
        }
        else
        {
            var pm = survey.pm.value;
            if (pm == "none")
            {
                error.innerHTML = "<i>* Please select a project manager.</i>";
            }
            else
            {
                var pmMeetingAttendance = getSatisfactionLevel(survey.pmMeetingAttendance);
                var pmTimelyResponse = getSatisfactionLevel(survey.pmTimelyResponse);
                var pmBid = getSatisfactionLevel(survey.pmBid);
                var pmOverall = getSatisfactionLevel(survey.pmOverall);
                var pmComments = commentStringFix(survey.pmComments.value);
                var tsTechnicalCompetence = getSatisfactionLevel(survey.tsTechnicalCompetence);
                var tsSystemConfig = getSatisfactionLevel(survey.tsSystemConfig);
                var tsCustomerService = getSatisfactionLevel(survey.tsCustomerService);
                var tsCommunication = getSatisfactionLevel(survey.tsCommunication);
                var tsOverall = getSatisfactionLevel(survey.tsOverall);
                var tsComments = commentStringFix(survey.tsComments.value);
                var ovQuality = getSatisfactionLevel(survey.ovQuality);
                var ovCommunication = getSatisfactionLevel(survey.ovCommunication);
                var ovValue = getSatisfactionLevel(survey.ovValue);
                var ovRoadblocks = getSatisfactionLevel(survey.ovRoadblocks);
                var ovComments = commentStringFix(survey.ovComments.value);
                var upcomingEvents = commentStringFix(survey.upcomingEvents.value);
                var message = "Name: " + name + "\r\n";
                message += "Event Name: " + event + "\r\n";
                message += "Project Manager: " + pm + "\r\n\r\n";
                message += "Project Management\r\n";
                message += "Meeting Attendance: " + pmMeetingAttendance + "\r\n";
                message += "Timely Response to Planning: " + pmTimelyResponse + "\r\n";
                message += "Bid - Complete/Accurate/Timely: " + pmBid + "\r\n";
                message += "Overall Performance: " + pmOverall + "\r\n";
                message += "Project Management Comments: " + pmComments + "\r\n\r\n";
                message += "Technical Support\r\n";
                message += "Technical Competence: " + tsTechnicalCompetence + "\r\n";
                message += "System Configurations: " + tsSystemConfig + "\r\n";
                message += "Customer Service: " + tsCustomerService + "\r\n";
                message += "Communication: " + tsCommunication + "\r\n";
                message += "Overall Performance: " + tsOverall + "\r\n";
                message += "Technical Support Comments: " + tsComments + "\r\n\r\n";
                message += "Overall Value\r\n";
                message += "Quality in Delivery: " + ovQuality + "\r\n";
                message += "Effective Communication: " + ovCommunication + "\r\n";
                message += "Value and Innovation: " + ovValue + "\r\n";
                message += "Removed Roadblocks: " + ovRoadblocks + "\r\n";
                message += "Overall Comments: " + ovComments + "\r\n\r\n";
                message += "Upcoming Events: " + upcomingEvents + "\r\n";
                survey.message.value = message;
                survey.submit();
            }
        }
    }
}

function submitContactForm() {
    var error = document.getElementById("error");
    var contactForm = document.getElementById("contactForm");
    var name = contactForm.name.value;
    if (name.length < 1) {
        error.innerHTML = "<i>* Please enter your name.</i>";
    }
    else {
        var phone = contactForm.phone.value;
        if (phone.length < 1) {
            error.innerHTML = "<i>* Please enter a phone number.</i>";
        }
        else {
            var email = contactForm.email.value;
            if (email.length < 1) {
                error.innerHTML = "<i>* Please enter an email address.</i>";
            }
            else if (email.indexOf("@") == -1 || email.indexOf(".") == -1) {
                error.innerHTML = "<i>* Please enter a valid email address.</i>";
            }
            else {
                var comments = commentStringFix(contactForm.comments.value);
                var message = "Name: " + name + "\r\n";
                message += "Phone Number: " + phone + "\r\n";
                message += "Email: " + email + "\r\n";
                message += "Comments or Questions: " + comments + "\r\n";
                contactForm.message.value = message;
                contactForm.submit();
            }
        }
    }
}