/* Minification failed. Returning unminified contents.
(3,53-54): run-time error JS1100: Expected ',': =
(3,57-58): run-time error JS1002: Syntax error: ,
(3,72-73): run-time error JS1100: Expected ',': =
 */


function LodaMoreButton(elementName, viewelemntsize = 10, skiptelement = 10) {
    var itc = $("." + elementName);
    if (itc !== null && itc !== 'undefined' && itc.length > 0) {

        $("." + elementName).slice(0, viewelemntsize).show();

        if ($(".lodeMore-btu").length > 0) {
            $(".lodeMore-btu").on('click', function (e) {
                e.preventDefault();
                $("." + elementName + ":hidden").slice(0, skiptelement).slideDown();

                if ($("." + elementName + ":hidden").length === 0) {
                    $(this).fadeOut('slow');
                }
                var bottom = $(window).height() - itc.outerHeight();

                $('html,body').animate({
                    scrollTop: $(this).offset().top //- bottom
                }, 1500);
            });
        }
    }
}


    //$('.lodeMore-btu .scrolltop').click(function () {
    //    $('body,html').animate({
    //        scrollTop: 0
    //    }, 600);
    //    return false;
    //});

    //$(window).scroll(function () {
    //    if ($(this).scrollTop() > 50) {
    //        $('.totop a').fadeIn();
    //    } else {
    //        $('.totop a').fadeOut();
    //    }
    //});;
// subscriber start

var subscriberForm = $("#subscriberForm");
if (subscriberForm != null && subscriberForm != 'undefined' && subscriberForm.length > 0) {

    $('#newsletter-submit').click(function (e) {
        submitNewsLetter();
        e.preventDefault();
    });
}
function submitNewsLetter() {
    //check that the terms were accepted

    //get the email input
    emailVal = $('#user-email-input').val();
    email = isEmail(emailVal);
    if (email === true) {
        contactListID = $('#contact-list-id').val();
        registerUser(emailVal, contactListID);
    } else {
        //flag the user
        $('#newsletter-form-msg').html('Please insert a valid email address').fadeIn();
    }

}

function isEmail(email) {
    var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    return regex.test(email);
}

function registerUser(email, contactListID) {
    var args = "email:'";
    args = args + email + "'";
    args = args + ",contactListID:'" + contactListID + "'";
    var result = CallPageMethod("registerUser", success, fail, args);
    return result;
}

function CallPageMethod(methodName, onSuccess, onFail, args) {
    var _registerCounter = "registerCounter";
    
    //if (getCookie(_registerCounter) === null) {
    //      setCookie(_registerCounter, 1, { expires: 1 });
    //} else {
    //    var couter = parseInt(getCookie(_registerCounter));
    //    if (couter <= 3) {
    //        setCookie(_registerCounter, couter + 1)
    //    } else {
    //        alert('You can register Only 3 Time , Thanks you!');
    //        return false;
    //    }
    //}

    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: "{" + args + "}",
        async: true,
        processData: false,
        cache: false,
        url: '/Shared/RegisterUserWithoutRobot',
        success: function (data) {
            var obj = $('.newsletter-signup-form');
            console.log(data.status);
            if (data.status === "succses") {
                alert('You have been successfully subscribed!');
            }
            else {
                if (data.status === "conflict") {
                    alert('This email already exists!');
                }
                else {
                    if (data.status === "robots" || data.status === "abuser") {
                        $('#newsletter-submit').unbind('click');

                    }
                }
            }
        },
        error: function (response) {
            alert("An error occurred." + response.responseText);
        }
    });
}

function success() {
    if (html !== null) {
        var obj = $('.newsletter-signup-form');

        if (html.d === "succses") {
            obj.text('Thank you!');
        }
        else {
            if (html.d === "conflict") {
                obj.text('This email already exists!');
            }
            else {
                if (html.d === "robots" || html.d === "abuser") {
                    $('#newsletter-submit').unbind('click');

                }
            }
        }
    }
}

function fail(response) {
    alert("An error occurred." + response.responseText);
}

    // subscriber end
;
