var $__ = jQuery;

jQuery(document).ready(function ($)
{
    // add to the existing functionality
    $('#contact-form .submit-btn').click(function (event)
    {
        if (validate("contact-form"))
            postbackASPFormByID("contactSubmit", "input")

    });
});

function validate(divtoValidate) 
{
    var shouldSubmit = true;
    $__("#requiredError").hide();
    $__("#emailError").hide();
    $__("#" + divtoValidate + " input, #" + divtoValidate + " textarea").each
    (
        function ()
        {
            if ($__(this).hasClass("required"))
            {
                if ($__(this).val() == '')
                {
                    // inline to make sure the style overrides other classes
                    $__(this).attr("style", "border:solid red 1px;");
                    shouldSubmit = false;
                    $__("#requiredError").show();
                }
            }

            if ($__(this).hasClass("email"))
            {
                var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
                var address = $__(this).val();
                if (reg.test(address) == false)
                {
                    $__(this).attr("style", "border:solid red 1px;");
                    shouldSubmit = false;
                    $__("#emailError").show();
                }
            }
        }

    );
    return shouldSubmit;
}


function postbackASPFormByID(objID, type)
{
    var obj = $__(type + "[id*='" + objID + "']");
    obj.trigger("click");
}



