﻿/***************
Solutions
***************/

// Product Selector
$(document).ready(function () {
    $("ul.productSelector > li").click(function () {
        $(this).siblings("li").removeClass("selected");
        $(this).addClass("selected");

        $("ul.products > li").removeClass("selected");
        $("ul.products > li:eq(" + $(this).index() + ")").addClass("selected");
    });
});

/*************
Contact
*************/

function Contact_Validate() {
    var errors = [];

    if ($.trim($("input#txtFirstName").val()) === "")
        errors.push("First Name is required");

    if ($.trim($("input#txtLastName").val()) === "")
        errors.push("Last Name is required");

    if ($.trim($("input#txtTitle").val()) === "")
        errors.push("Position or Title is required");

    if ($.trim($("input#txtOrganization").val()) === "")
        errors.push("School or Organization is required");

    if ($.trim($("input#txtEmail").val()) === "")
        errors.push("Email is required");
    else if (/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/.test($("input#txtEmail").val()) === false)
        errors.push("Please enter a valid Email");

    if ($.trim($("textarea#txtComments").val()) === "")
        errors.push("Please enter your comments");

    if ($.trim(Recaptcha.get_response()) === "")
        errors.push("Please fill in the captcha");

    if (errors.length > 0) {
        Form_DisplayErrors(errors);

        return false;
    }

    Form_ClearErrors();

    return true;
}

function Form_DisplayErrors(errors) {
    var html = "";

    html += '<p>Please make the following corrections:</p>';
    html += '<ul>';

    for (var i = 0; i < errors.length; i++)
        html += '<li>' + errors[i] + '</li>';

    html += '</ul>';

    $("div#validationSummary").html(html).show(); ;
}

function Form_ClearErrors(errors) {
    $("div#validationSummary").html("").hide();
}
