﻿    function ScrollTop() {
        window.scrollTo(0, 0);
        FitLoader() 
    }

    function FitLoader() {
        if ($("#update-right-content-container").length > 0 && $("#loading").length > 0) {
            var pos = $("#update-right-content-container").offset();
            $("#loading").css({ "left": (pos.left) + "px" });
            $("#loading").width($("#update-right-content-container").width());
        }
    }

    function EndRequestHandler() {
        
        if ($("#ParentCategoryID").length > 0) {
            $("#ParentCategoryID").change(function () {

                var strCategoryId = "";
                $("#ParentCategoryID option:selected").each(function () {
                    strCategoryId = $(this)[0].value;
                });

                var url = "/GetChildCategories/" + strCategoryId;
                $("#ChildCategoryID").empty();
                $.getJSON(url, null, function (data) {
                    $.each(data, function (optionData) {
                        $("#ChildCategoryID").append($("<option></option>").val(this['Value']).html(this['Text']));
                    });
                });
            });
        }
    }

    $(document).ready(function () {
        
        if ($("#update-right-content-container").length > 0) {
            $("#update-right-content-container").resize(
                function () {
                    FitLoader();
                }
            );
        }

        FitLoader();
    });


    //----------------recaptcha--------------------
    function showRecaptcha(element) {
        var RecaptchaOptions = {
            theme: 'white',
            lang: 'en',
            custom_theme_widget: 'recaptcha_widget'
        };
        Recaptcha.create("6LfJHr4SAAAAAMyAsBChL0JLN3ZSP9zEhz65vuaT", element, RecaptchaOptions);
        RecaptchaStr_en.play_again = "replay";
        RecaptchaStr_en.cant_hear_this = "can't hear";
    }

    function ValidateRecaptcha() {
        $.ajax({
            type: "POST",
            url: "/Shared/ValidateRecapatcha/",
            data: { challengeValue: Recaptcha.get_challenge(), responseValue: Recaptcha.get_response() },
            success: onValidateRecaptchaSuccess,
            error: onValidateRecaptchaFailed
        });
        //GetWebService().ValidateRecaptcha(Recaptcha.get_challenge(), Recaptcha.get_response(), onValidateRecaptchaSuccess, onValidateRecaptchaFailed);
    }

    function onValidateRecaptchaSuccess(ret) {
        if (ret == true) {
            $("form:last").submit();
        }
        else {
            var ul = $("#validationSummary ul");

            if (ul.length > 0) {
                $("#validationSummary").addClass("validation-summary-errors");
                $("#validationSummary").removeClass("validation-summary-valid");
                ul.html("");
                ul.append("<li>Incorrect RECAPTCHA words, please try again</li>")
            }
            //Reload recaptcha in case it fails 
            Recaptcha.reload();
        }
    }

    function onValidateRecaptchaFailed(req, status, error) {
        alert('an error has occured');
    } 
