///////////////////////////////////////// Allow only numeric ///////////////////////////////////////////////
// Numeric only control handler, I took this from the web, not my code, but I changed in it
jQuery.fn.ForceNumericOnly =
function () {
    return this.each(function () {
        $(this).keydown(function (e) {
            var key = e.charCode || e.keyCode || 0;
            // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
            return (
                key == 8 ||
                key == 9 ||
                key == 46 ||
                (key >= 37 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105));
        })
    })
};

$(document).ready(function () {
    $("#contactPhone").ForceNumericOnly();
    $("#investorsPhone").ForceNumericOnly();
    $("#calculatorCost").ForceNumericOnly();
    $("#downPayment").ForceNumericOnly();
    $("#newsletterPhone").ForceNumericOnly();
    $("#phone").ForceNumericOnly();
});
////////////////////////////////////////// Allow only numeric ///////////////////////////////////////////////



/////////////////////////////////////////// hover on header dropdown menu ///////////////////////////////////
$(document).ready(function () {
    $(".headerDropDown").find(".item").mouseover(function () {
        var myItem = $(this);
        $(".headerDropDown").find(".item").removeClass("sel");
        var currentTop = myItem.position().top;
        if ($(this).hasClass('abstyle'))
        targetTop = parseInt(currentTop) + 17;
        else
        targetTop = parseInt(currentTop) + 6;
        myItem.parent().find(".slider").stop().animate({ top: targetTop + "px" }, 40, function () {
            myItem.addClass("sel");
        });
    });

    var mouseIsInsideAboutUsHeader = 0;
    var mouseIsInsideAboutUsTab = 0;
    var mouseIsInsideproductsSolutionsHeader = 0;
    var mouseIsInsideproductsSolutionsTab = 0;
    var mouseIsInsideWhyAcsysHeader = 0;
    var mouseIsInsideWhyAcsysTab = 0;
    var mouseIsInsideAcsysNetHeader = 0;
    var mouseIsInsideAcsysNetTab = 0;

    // checks if mouse is inside the dropdown related component
    $(".aboutUs").mouseenter(function () {
        mouseIsInsideAboutUsHeader = 1;
    }).mouseleave(function () {
        mouseIsInsideAboutUsHeader = 0;
        if (mouseIsInsideAboutUsTab == 0) {
            closeAboutUsHeader();
        }
    });
    // on hover over a header item element, drop the submenu down
    $(".tab2").mouseenter(function () {
        mouseIsInsideAboutUsTab = 1;
        setTimeout(function () {
            $(".headerDropDown").show();
            $(".aboutUs").stop().animate({ height: "179px" }, 200);
        }, 20);
    }).mouseleave(function () {
        mouseIsInsideAboutUsTab = 0;
        if (mouseIsInsideAboutUsHeader == 0) {
            closeAboutUsHeader();
        }
    });
    // close about us header tab
    function closeAboutUsHeader() {
        setTimeout(function () {
            if (mouseIsInsideAboutUsHeader == 0 && mouseIsInsideAboutUsTab == 0) {
                $(".aboutUs").stop().animate({ height: "0px" }, 200, function () {
                    //$(".headerDropDown").hide();
                });
            }
        }, 70);
    }

    // checks if mouse is inside the dropdown related component
    $(".productsSolutions").mouseenter(function () {
        mouseIsInsideproductsSolutionsHeader = 1;
    }).mouseleave(function () {
        mouseIsInsideproductsSolutionsHeader = 0;
        if (mouseIsInsideproductsSolutionsTab == 0) {
            closeproductsSolutionsHeader();
        }
    });
    // on hover over a header item element, drop the submenu down
    $(".tab3").mouseenter(function () {
        mouseIsInsideproductsSolutionsTab = 1;
        setTimeout(function () {
            $(".headerDropDown").show();
            $(".productsSolutions").stop().animate({ height: "66px" }, 200);
        }, 20);
    }).mouseleave(function () {
        mouseIsInsideproductsSolutionsTab = 0;
        if (mouseIsInsideproductsSolutionsHeader == 0) {
            closeproductsSolutionsHeader();
        }
    });
    // close about us header tab
    function closeproductsSolutionsHeader() {
        setTimeout(function () {
            if (mouseIsInsideproductsSolutionsHeader == 0 && mouseIsInsideproductsSolutionsTab == 0) {
                $(".productsSolutions").stop().animate({ height: "0px" }, 200, function () {
                    //$(".headerDropDown").hide();
                });
            }
        }, 10);
    }

    // checks if mouse is inside the dropdown related component
    $(".whyAcsys").mouseenter(function () {
        mouseIsInsideWhyAcsysHeader = 1;
    }).mouseleave(function () {
        mouseIsInsideWhyAcsysHeader = 0;
        if (mouseIsInsideWhyAcsysTab == 0) {
            closeWhyAcsysHeader();
        }
    });
    // on hover over a header item element, drop the submenu down
    $(".tab4").mouseenter(function () {
        mouseIsInsideWhyAcsysTab = 1;
        setTimeout(function () {
            $(".headerDropDown").show();
            $(".whyAcsys").stop().animate({ height: "66px" }, 200);
        }, 20);
    }).mouseleave(function () {
        mouseIsInsideWhyAcsysTab = 0;
        if (mouseIsInsideWhyAcsysHeader == 0) {
            closeWhyAcsysHeader();
        }
    });
    // close about us header tab
    function closeWhyAcsysHeader() {
        setTimeout(function () {
            if (mouseIsInsideWhyAcsysHeader == 0 && mouseIsInsideWhyAcsysTab == 0) {
                $(".whyAcsys").stop().animate({ height: "0px" }, 200, function () {
                    //$(".headerDropDown").hide();
                });
            }
        }, 10);
    }

    // checks if mouse is inside the dropdown related component
    $(".acsysNet").mouseenter(function () {
        mouseIsInsideAcsysNetHeader = 1;
    }).mouseleave(function () {
        mouseIsInsideAcsysNetHeader = 0;
        if (mouseIsInsideAcsysNetTab == 0) {
            closeAcsysNetHeader();
        }
    });
    // on hover over a header item element, drop the submenu down
    $(".tab6").mouseenter(function () {
        mouseIsInsideAcsysNetTab = 1;
        setTimeout(function () {
            $(".headerDropDown").show();
            $(".acsysNet").stop().animate({ height: "100px" }, 200);
        }, 20);
    }).mouseleave(function () {
        mouseIsInsideAcsysNetTab = 0;
        if (mouseIsInsideAcsysNetHeader == 0) {
            closeAcsysNetHeader();
        }
    });
    // close about us header tab
    function closeAcsysNetHeader() {
        setTimeout(function () {
            if (mouseIsInsideAcsysNetHeader == 0 && mouseIsInsideAcsysNetTab == 0) {
                $(".acsysNet").stop().animate({ height: "0px" }, 200, function () {
                    //$(".headerDropDown").hide();
                });
            }
        }, 10);
    }
});
/////////////////////////////////////// End of hover on header dropdown menu ////////////////////////////////

/////////////////////////////////////////////// opens certificate ///////////////////////////////////////////
function openCertificate(certificate) {
    var routeUrl = $("#routeUrl").val();

    // redirect to certificate url
    window.open(routeUrl + 'Content/uploads/certificates/' + certificate, "_blank");
}
/////////////////////////////////////////// End of opens certificate ////////////////////////////////////////

/////////////////////////////////////////// Case Study Filter slider ////////////////////////////////////////
function filterSwitch(obje) {
    setTimeout(function () {
        $(".filterItem").find("div").removeClass("selected");
    }, 200);
    var topLocation = $(obje).position().top;
    $(".filterSlide").stop().animate({ top: topLocation + "px" }, 400, function () {
        $(obje).find("div").addClass("selected");
    });
}
//////////////////////////////////////// End of Case Study Filter slider ////////////////////////////////////

/////////////////////////////////////////// Project top menu slider /////////////////////////////////////////
function slideProductTopMenu(obje) {
    var leftLocation    = $(obje).position().left;
    $(".sliderPro").stop().animate({ left: leftLocation + "px" });
}
//////////////////////////////////////// End of Project top menu slider /////////////////////////////////////

////////////////////////////////////////// Project top menu slider 2 ////////////////////////////////////////
function slideProductTopMenu2(obje) {
    var routeUrl                = $("#routeUrl").val();

    var leftLocation            = $(obje).position().left;
   // $(".sliderPro").stop().animate({ left: leftLocation + "px" });
    if ($(obje).hasClass('one')) {
        var imagePath           = routeUrl + "Content/images/slidingRed1.png";
        var backgroundImagePath = "url(" + imagePath + ")";
        $(".sliderPro").css('background-image', backgroundImagePath);
        $(".sliderPro").stop().animate({ width: "329px", left: leftLocation + "px" });
    }
    else if ($(obje).hasClass('two')) {
        var imagePath           = routeUrl + "Content/images/slidingRed2.png";
        var backgroundImagePath = "url(" + imagePath + ")";
        $(".sliderPro").css('background-image', backgroundImagePath);
        $(".sliderPro").stop().animate({ width: "257px", left: leftLocation + "px" });
    }
    else if ($(obje).hasClass('three')) {
        var imagePath           = routeUrl + "Content/images/slidingRed3.png";
        var backgroundImagePath = "url(" + imagePath + ")";
        $(".sliderPro").css('background-image', backgroundImagePath);
        $(".sliderPro").stop().animate({ width: "132px", left: leftLocation + "px" });
    }
    else if ($(obje).hasClass('four')) {
        var imagePath           = routeUrl + "Content/images/slidingRed4.png";
        var backgroundImagePath = "url(" + imagePath + ")";
        $(".sliderPro").css('background-image', backgroundImagePath);
        $(".sliderPro").stop().animate({ width: "154px", left: leftLocation + "px" });
    }
}
////////////////////////////////////// End of Project top menu slider 2 /////////////////////////////////////


function locks() {
    setTimeout("suiteLocks()", 3000);
}


function defineSelectedTab(obj) {
    var routeUrl = $("#routeUrl").val();
        if (obj=="1") {
            var imagePath = routeUrl + "Content/images/slidingRed1.png";
            var backgroundImagePath = "url(" + imagePath + ")";
            $(".sliderPro").css('background-image', backgroundImagePath);
            $(".sliderPro").css('left','33px');
        }
        if (obj=="2") {
            var imagePath = routeUrl + "Content/images/slidingRed2.png";
            var backgroundImagePath = "url(" + imagePath + ")";
            $(".sliderPro").css('background-image', backgroundImagePath);
            $(".sliderPro").css('left', '378px');
        }
        if (obj=="3") {
            var imagePath = routeUrl + "Content/images/slidingRed3.png";
            var backgroundImagePath = "url(" + imagePath + ")";
            $(".sliderPro").css('background-image', backgroundImagePath);
            $(".sliderPro").css('left', '651px');
        }
        if (obj=="4") {
            var imagePath = routeUrl + "Content/images/slidingRed4.png";
            var backgroundImagePath = "url(" + imagePath + ")";
            $(".sliderPro").css('background-image', backgroundImagePath);
            $(".sliderPro").css('left', '800px');
        }
    }
