﻿function ContactUsFormSubmit() {
    var flag = true;
    $(".CheckField").each(function(i) {
        if (typeof $(this).attr("regex") != 'undefined') {
            var regex = new RegExp($(this).attr("regex"));
            if ($(this).attr("class").indexOf("required") != -1) {
                if (!(regex).test($(this).val())) {
                    $(this).addClass("RedBorder");
                    flag = false;
                }
                else $(this).removeClass("RedBorder");
                //else $("#" + ($(this).attr("ErrMsg"))).css("display","none"); 
            }
            else // IF IT NOT A REQUIRED FIELD
            {
                if ($(this).val().length > 0) {
                    if (!(regex).test($(this).val())) {
                        $(this).addClass("RedBorder");
                        flag = false;
                    }
                    else $(this).removeClass("RedBorder");
                }
            }
        }
    })
    if (flag) {
        $("#ContactUsSendBtn").attr("onclick", "");
        $(".BTN").removeClass("SendBtnHover");
        $(".BTN").removeClass("SendBtnOn");
        $(".BTN").addClass("SendBtnOff");
        $(".ErrMsg").css("display", "none");
        document.ContactUsForm.submit();
    }
    else $(".ErrMsg").css("display", "block");

}
$(document).ready(function() {
    $(document).pngFix();
    $(".InputNum").keypress(function(e) {
        if (e.whice != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) return false;
    })
    $(".BTN").hover(function() {
        $(".BTN").removeClass("SendBtnOn");
        $(".BTN").addClass("SendBtnHover");
    }, function() {
        $(".BTN").removeClass("SendBtnHover");
        $(".BTN").addClass("SendBtnOn");
    })
    $(".Logo").click(function() {
        window.location = 'http://www.nalleyglass.com/';
    })
    $(".Winlink").click(function() {
        window.location = 'Windows.aspx';
    })
    $(".AutoLink").click(function() {
        window.location = 'Auto_Glass.aspx';
    })    
}); 