﻿$(document).ready(function(){
    $(document).pngFix();
    $(".Send").click(function(){
    ContactUsFormSubmit()
    })
    $(".Clean").click(function(){
        $(".ErrMsg").css("display","none");
        $(".CheckField").each(function(i){
            $(this).val("");
            $(this).removeClass("RedBorder");
        })
    })
    $(".Gift").click(function(){
        window.location = 'Forms/oren_giron_present.doc'; 
    })
    $(".Form").click(function(){
        window.location = 'Forms/oren_giron_cook.doc'; 
    })
    $(".Logo").click(function(){
        window.location = 'http://www.osim-bishul.co.il'; 
    })
    $(".InputNum").keypress(function(e) {
        if (e.whice != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) return false;
    })
    $('#buttonOne').jFav();
})
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) {
        $(".Send").attr("onclick", "");
        $(".ErrMsg").css("display", "none");
        document.ContactUsForm.submit();
    }
    else $(".ErrMsg").css("display", "block");
}