﻿$(document).ready(function(){
    $(document).pngFix();
    $(".BtnOff").hover(function(){
           $(this).removeClass("BtnOff").addClass("BtnOn");
        }, function ()
        {
           $(this).removeClass("BtnOn").addClass("BtnOff");
        }
    );
    $(".Cube").hover(function(){
           $(this).css("background", "#fff");
        }, function ()
        {
           $(this).css("background", "#729f1e");
        }
    );
    $(".HpBtn").click(function(){
        window.location = 'http://www.zarfati-group.co.il' ;
    })

    $("#Clean").click(function(){
        $("#FullName").val(""); 
        $("#Phone").val("");
        $("#Email").val("");
        $("#MoreInfo").val("");
    })      
    $("#SendBtn").click(function(){
        ContactUsFormSubmit();
    })
})
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 // 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) {
        $("#SendBtn").attr("onclick", "");
        $(".ErrMsg").css("display", "none");
            $.post("handlers/SendMail.ashx", 
                {FullName : $("#FullName").val(), Phone : $("#Phone").val(), Email : $("#Email").val(), MoreInfo : $("#MoreInfo").val()},
              function(data) {
                  if (data = "0")
                  {
                    $(".RContact").html("<div class='TxtInput R'><b>ארעה תקלה אנא נסו שנית במועד מאוחר יותר</b></div>");
                  }
                  else 
                  {
                    $(".RContact").html("<div class='TxtInput R'><b>תודה על יצירת הקשר, אנו נחזור אליכם בהקדם</b></div>");
                  }
              });
    }
    else $(".ErrMsg").css("display","block");
 
}

