﻿
// function autoSlideImage image
autoSlideImage = function(strSelector, timeDelay) {
    var tOut;
    var curindex = 0;
    var maxindex = 0;

    maxindex = $(strSelector).length;
    if (maxindex >= 2) {
        autochange($(strSelector + ":eq(" + curindex + ")"));
    }
    else {
        return 0;
    }
    function autochange(obj) {
        $(obj).fadeIn(800, function() {
            tOut = setTimeout(function() {
                $(strSelector + ":eq(" + curindex + ")").fadeOut(500, function() {
                    curindex++;
                    if (curindex == maxindex) curindex = 0;
                    autochange($(strSelector + ":eq(" + curindex + ")"));
                });
            }, timeDelay);
        });
    }
};

// function frontSlideImage image
frontSlideImage = function (strSelector, strSelectorDes, strSelectorButton, timeDelay) {
    var tOut;
    var curindex = 0;
    var maxindex = 0;
    var preIndex = 0;
    maxindex = $(strSelector).length;
    if (maxindex >= 2) {
        autochange($(strSelector + ":eq(" + curindex + ")"));
    }
    else {        
        $(strSelectorButton + ":eq(" + curindex + ")").addClass("active");
        $(strSelectorDes + ":eq(" + curindex + ")").fadeIn(800);
        $(strSelector + ":eq(" + curindex + ")").fadeIn(800);
    }
    $(strSelectorButton).click(function () {

        $(strSelector + ":eq(" + preIndex + ")").fadeOut(1000);
        $(strSelectorDes + ":eq(" + preIndex + ")").fadeOut(1000);
        $(strSelector + ":eq(" + curindex + ")").css("z-index", 0);       
        curindex = $(strSelectorButton).index($(this));
        autochange($(strSelector + ":eq(" + curindex + ")"));
        
    });

    function autochange(obj) {
        clearTimeout(tOut);
        $(obj).css("z-index", 1)
        preIndex = curindex;
        $(strSelectorButton + ".active").removeClass("active");
        $(strSelectorButton + ":eq(" + curindex + ")").addClass("active");
        $(strSelectorDes + ":eq(" + curindex + ")").fadeIn(800);
        $(obj).fadeIn(800, function () {
            tOut = setTimeout(function () {
                $(strSelector + ":eq(" + preIndex + ")").fadeOut(1000);
                $(strSelectorDes + ":eq(" + preIndex + ")").fadeOut(1000);

                $(strSelector + ":eq(" + curindex + ")").css("z-index", 0);
                curindex++;
                if (curindex == maxindex) curindex = 0;
                autochange($(strSelector + ":eq(" + curindex + ")"));
            }, timeDelay);
        });
    }
};

function getKeyPressEvent(e) {
    var keynum
    var keychar

    if (window.event) // IE
    {
        keynum = e.keyCode
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which
    }
    if (keynum == 13) {
        window.open('https://console.netpower.no/domains.php?domain_name=' + $('#domain_name').val() + '&dm_action=register_new&domain_selection_type=single&action=check_domains');
        return false;
    }
    else {
        keychar = String.fromCharCode(keynum)
        return keychar;
    }

}
