﻿jQuery.fn.extend({
    everyTime: function (interval, label, fn, times, belay) {
        return this.each(function () {
            jQuery.timer.add(this, interval, label, fn, times, belay);
        });
    },
    oneTime: function (interval, label, fn) {
        return this.each(function () {
            jQuery.timer.add(this, interval, label, fn, 1);
        });
    },
    stopTime: function (label, fn) {
        return this.each(function () {
            jQuery.timer.remove(this, label, fn);
        });
    }
});

jQuery.extend({
    timer: {
        guid: 1,
        global: {},
        regex: /^([0-9]+)\s*(.*s)?$/,
        powers: {
            // Yeah this is major overkill...
            'ms': 1,
            'cs': 10,
            'ds': 100,
            's': 1000,
            'das': 10000,
            'hs': 100000,
            'ks': 1000000
        },
        timeParse: function (value) {
            if (value == undefined || value == null)
                return null;
            var result = this.regex.exec(jQuery.trim(value.toString()));
            if (result[2]) {
                var num = parseInt(result[1], 10);
                var mult = this.powers[result[2]] || 1;
                return num * mult;
            } else {
                return value;
            }
        },
        add: function (element, interval, label, fn, times, belay) {
            var counter = 0;

            if (jQuery.isFunction(label)) {
                if (!times)
                    times = fn;
                fn = label;
                label = interval;
            }

            interval = jQuery.timer.timeParse(interval);

            if (typeof interval != 'number' || isNaN(interval) || interval <= 0)
                return;

            if (times && times.constructor != Number) {
                belay = !!times;
                times = 0;
            }

            times = times || 0;
            belay = belay || false;

            if (!element.$timers)
                element.$timers = {};

            if (!element.$timers[label])
                element.$timers[label] = {};

            fn.$timerID = fn.$timerID || this.guid++;

            var handler = function () {
                if (belay && this.inProgress)
                    return;
                this.inProgress = true;
                if ((++counter > times && times !== 0) || fn.call(element, counter) === false)
                    jQuery.timer.remove(element, label, fn);
                this.inProgress = false;
            };

            handler.$timerID = fn.$timerID;

            if (!element.$timers[label][fn.$timerID])
                element.$timers[label][fn.$timerID] = window.setInterval(handler, interval);

            if (!this.global[label])
                this.global[label] = [];
            this.global[label].push(element);

        },
        remove: function (element, label, fn) {
            var timers = element.$timers, ret;

            if (timers) {

                if (!label) {
                    for (label in timers)
                        this.remove(element, label, fn);
                } else if (timers[label]) {
                    if (fn) {
                        if (fn.$timerID) {
                            window.clearInterval(timers[label][fn.$timerID]);
                            delete timers[label][fn.$timerID];
                        }
                    } else {
                        for (var fn in timers[label]) {
                            window.clearInterval(timers[label][fn]);
                            delete timers[label][fn];
                        }
                    }

                    for (ret in timers[label]) break;
                    if (!ret) {
                        ret = null;
                        delete timers[label];
                    }
                }

                for (ret in timers) break;
                if (!ret)
                    element.$timers = null;
            }
        }
    }
});

if (jQuery.browser.msie)
    jQuery(window).one("unload", function () {
        var global = jQuery.timer.global;
        for (var label in global) {
            var els = global[label], i = els.length;
            while (--i)
                jQuery.timer.remove(els[i], label);
        }
    });



//JQUERY TİMER BİTİŞ

jQuery.fn.Numeric =
function () {
    return this.each(function () {
        $(this).keydown(function (e) {
            var key = e.charCode || e.keyCode || 0;
               return (
                key == 8 ||
                key == 9 ||
                key == 46 ||
                (key >= 37 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105)
                );
            });
           });
};

$.fn.toggleCheckbox = function () { 
    this.attr('checked', !this.attr('checked'));
}

$.fn.extend({
    scrollTo: function (speed, easing) {
        return this.each(function () {
            var targetOffset = $(this).offset().top;
            $('html,body').animate({ scrollTop: targetOffset }, speed, easing);
        });
    }
});

$.fn.shuffle = function () {
    return this.each(function () {
        var items = $(this).children().clone(true);
        return (items.length) ? $(this).html($.shuffle(items)) : this;
    });
}

$.shuffle = function (arr) {
    for (var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
    return arr;
}

$.ajaxPabbuc = function (url, callbackFnk, tyPe) {
    var args = arguments[0] || {}; // It's your object of arguments
    var argsLen = args.length;
    var checkvalue;
    function closeMessage(type) {
        if (type == "Modal") {
     //       $(".workingProcess").fadeOut("fast", function () {
     //           $(".overlayScreen").fadeOut("fast");
      //      });
        }
        else {
        //    $("#errorScreen").slideUp();
        }
    }

    function openMessage(type) {
    /*
        if (tyPe == 'Modal') {
            if ($(".overlayScreen").length < 1) { $("body").append('<div class="overlayScreen"></div>'); };
            var winHeight = $(window).height();
            var winWidth = $(window).width();
            $(".overlayScreen").css({
                width: '100%',
                height: $(document).height()
            }).fadeIn("fast");
            var elTop = (winHeight - $(".workingProcess").height()) / 2;
            var elLeft = (winWidth - $(".workingProcess").width()) / 2;
            $(".workingProcess").css("top", elTop + "px").css("left", elLeft + "px").fadeIn("fast");
        }
        else {
            $("#errorScreen").scrollTo(1000);
            $("#errorScreen").slideDown();
        }
        */
    }
    var timeLimit = 5;
    function ajaxPabbucCountDown(process) {
        if (process == 1) {
            clearInterval(checkvalue)
            closeMessage(tyPe);
            return false;
        }

        checkvalue = setInterval(function () {
            timeLimit -= 1;
            if (timeLimit == 0) {
                clearInterval(checkvalue);
                openMessage(tyPe);
            }
        }, 1000);
    }



    function stopCous() {
        clearInterval(checkvalue)
        closeMessage(tyPe);
        return false;
    }


    var data;
    $.ajax({
        url: url,
        async: false,
        data: "",
        timeout: 10000,
        global: false,
        contentType: "application/x-www-form-urlencoded; charset=iso-8859-9",
        type: "GET",
        beforeSend: function () {
            ajaxPabbucCountDown();

        },
        success: function (response) {
            clearInterval(checkvalue)
            data = response;
        },
        complete: function (response) {
            ajaxPabbucCountDown(1);
            stopCous();
        },

        error: function () {
            alert("Bir Hata Oluştu");
            clearInterval(checkvalue)
            ajaxPabbucCountDown(1);

        }
    });

    if (typeof callbackFnk == 'function') {
        callbackFnk.call(this, data);

    }
}

/* HEADER*/
function addCustomerCategory(furl, fkeys, customerId, brandId, sizeId) {
    $.ajax({
        url: "/interactive/addCustomerCategory.aspx",
        data: "furl=" + furl + "&k=" + fkeys + "&c=" + customerId + "&b=" + brandId + "&s=" + sizeId,
        global: false,
        type: "GET",
        dataType: "html",
        success: function (response) {
            document.getElementById("btnAddCustomerCategory").onclick = "";
            $("#btnAddCustomerCategory").removeClass("buKategoriyiTakipEt");
            $("#btnAddCustomerCategory").addClass("buKategoriyiTakipEttim");
        }
    });
}

$(document).ready(function () {

    $(".gotoTopLink").click(function () {
        $("html").scrollTo(1000);
    });


    var footerHeight = 135;
    $(".openFooter").mouseenter(function () {
        $(".gotoTop").animate({
            top: $(window).height() - footerHeight - 37 + 'px'
        });

        var mousePosition = false;
        var footerElement = $("#FooterContainer");
        footerElement.css("position", "fixed");
        footerElement.css("z-index", "9990");
        /*footerElement.css("top", $(window).height() - footerHeight + "px");
        footerElement.fadeIn("slow");*/
        footerElement.animate({ top: $(window).height() - footerHeight + "px" });
        closeIt(4000);

        footerElement.mouseover(function () {
            mousePosition = true;
            footerElement.fadeIn("slow");
        });
        footerElement.mouseleave(function () {
            closeIt(2000);
        });

        function closeIt(timer) {
            mousePosition = false;
            setTimeout(kontrol, timer);
        }

        function kontrol() {
            if (mousePosition == false) {
                /*  footerElement.fadeOut("slow", function () {
                $(".gotoTop").animate({
                top: $(window).height() - 37 +'px'
                });
                });*/

                footerElement.animate({
                    top: $(window).height() + "px"
                });
                    $(".gotoTop").animate({
                        top: $(window).height() - 37 + 'px'
                    });
            



            }
        }
    }).mouseleave(function () {

    });










    $("#heatmapImage").css("left", $("#Wrapper").position().left);

    $(document).keyup(function (e) {
        if (e.which == 115) {
            if ($("#heatmapImage").hasClass("hidden") == false) {
                $("#heatmapImage").addClass("hidden");
            }
            else {
                $("#heatmapImage").removeClass("hidden");
            }
        }
        if (e.which == 107) {
            var s = parseFloat($("#heatmapImage").css("opacity")) + 0.1;
            $("#heatmapImage").css("opacity", s);
        } else if (e.which == 109) {
            var s2 = $("#heatmapImage").css("opacity");
            $("#heatmapImage").css("opacity", s2 - 0.1);
        }
    });

    /*TIMEOUT FUNCTION START
    countDownSessionTimeOut();
    function countDownSessionTimeOut() {
    var timeLimit = 1080000;
    window.setTimeout(function () {
    countDownMake();
    }, timeLimit - 20000);
    }

    function countDownMake() {
    if ($(".overlayScreen").length < 1) { $("body").append('<div class="overlayScreen"></div>'); };
    var winHeight = $(window).height();
    var winWidth = $(window).width();
    $(".overlayScreen").css({
    width: '100%',
    height: $(document).height()
    }).fadeIn("fast");

    var elTop = (winHeight - $("#timeOutContain").height()) / 2;
    var elLeft = (winWidth - $("#timeOutContain").width()) / 2;
    $("#timeOutContain").css("top", elTop + "px").css("left", elLeft + "px").fadeIn("fast", function () {
    countDown();
    });

    var oldContent;
    function closeTimeOutBlock() {
    window.setTimeout(function () {
    $("#timeOutContain").fadeOut("fast", function () {
    $("#timeOutContain").html(oldContent);
    $(".overlayScreen").fadeOut("fast");
    });
    }, 800);
    }

    $("#mainLink").click(function () {
    var closeTop = $("#timeOutContain").height();
    $("#timeOutContain").flip({
    direction: 'rl',
    color: '#fff',
    onEnd: function () {
    oldContent = $("#timeOutContain").html();
    $("#timeOutContain").html('<div style="text-align:center"><img src="/frontend/images/timeOut_pabbuccom.gif"></div>');
    $("#timeOutContain").fadeOut("fast", function () {
    $("#timeOutContain").html(oldContent);
    $(".overlayScreen").fadeOut("fast", function () {
    window.location.reload();
    });
    });
    }
    })
    });

    $(".closeTimeOut").click(function () {
    var closeTop = $("#timeOutContain").height();
    $("#timeOutContain").flip({
    direction: 'rl',
    color: '#fff',
    onEnd: function () {
    oldContent = $("#timeOutContain").html();
    $("#timeOutContain").html('<div style="text-align:center"><img src="/frontend/images/timeOut_pabbuccom.gif"></div>');
    closeTimeOutBlock();
    }
    })
    });
    }

    function countDown() {
    var timeLimit = 20;
    var timeCurrent = timeLimit;
    var checkvalue = setInterval(function () {
    timeLimit -= 1;
    if (timeLimit < 10) {
    timeCurrent = "0" + timeLimit
    }
    else {
    timeCurrent = timeLimit;
    }
    $("#minute").text(timeCurrent);
    if (timeLimit == 0) {
    clearInterval(checkvalue);
    window.location.href = "/timeOut.aspx";
    }
    }, 1000);
    }

    /*TIMEOUT FUNCTION END*/


    /*LIGHTBOX LOGİN İÇİN

    $("#light-box-user-login").modal({
    overlayClose: true,
    onClose: function (dialog) {
    $.modal.close();
    }
    });


    */


    $(".closeBtn").click(function () {
        $(".warningMessage").slideUp();
    });
    /*Marka buttons ftd*/

    var uzerinde = 0;
    $(".marka_image").mouseover(function () {
        $(".marka_area").css("background", "#f2f2f2");
        $(".marka_buttons").fadeIn();
        uzerinde = 1;
    })
    $(".marka_area").mouseleave(function () {
        if (uzerinde == 1) {
            $(".marka_area").css("background", "#fff");
            $(".marka_buttons").fadeOut();
        }
    });

    /*
    Son eleman çizgisiz 
    FTD
    */
    var kacLi = $("div.cont li").length;
    /*
    Son eleman çizgisiz end
    */

    //ürün image ve yazıları fizlemece FTD

    $("div.img-container").mouseover(function () {
        $(this).next().find("a").css("color", "#ED008E");
    }).mouseout(function () {
        $(this).next().find("a").css("color", "#000000");
    });
    $("p.dotted a").mouseover(function () {
        $(this).css("color", "#ED008E");
    }).mouseout(function () {
        $(this).css("color", "#000000");
    });

    //ürün image ve yazıları fizlemece FTD end	
    var active_li = -1;
    try {
        $("#topMenu li").hover(
			function () {
			    active_li = $("#topMenu li").index($("#topMenu li.Active"));
			    $("#topMenu li").removeClass("Active");
			    $(this).addClass("Act");
			},
			function () {
			    $(this).removeClass("Act");
			    $("#topMenu li:eq(" + active_li + ")").addClass("Active");
			}
		);
        //li with fade class
    }

    catch (e) { }

    var pages = new Array("", "anasayfa", "kadin", "erkek", "cocuk", "aksesuvar", "canta", "marka");

    try {
        if (page_id >= 8)
            $("#topMenu_" + page_id).addClass("Active");
        else {
            $("#topMenu_12").addClass("Active");
            $("#" + pages[page_id]).parent().addClass("chosen");
        }
    }
    catch (err) {
        $("#topMenu_12").addClass("Active");
    }

    function getPosition(obj) {
        var offset = obj.offset();
        return offset.left + "," + offset.top;
    }

    /* TOP-MENU
    */
    $("div.bordery ul li:last-child").css("background", "none");

    $("#mainMenu .horizontal-menu li").mouseover(function () {
        var li_class = $(this).attr("class");

        if (li_class != "chosen")
            mover($(this));

        if (li_class != "chosen")
            showMenu($(this));

    }).mouseout(function () {
        var li_class = $(this).attr("class");

        if (li_class != "chosen")
            mout($(this));

        $('.popup_menu').hide();
    });

    $('.popup_menu').mouseover(function () {
        var patlat = $(this).attr("id").split("_");
        $(this).show();
        mover($('#' + patlat[1]).parent());
    }).mouseout(function () {
        $('.popup_menu').hide();
        mout($("#" + $(this).attr('id').replace(/popup_/, '')).parent());
    });

    function mover(obj) {
        var child = $(obj).children("a");

        child.css("height", "42px");
        child.css("marginTop", "0");
        child.css("backgroundPosition", "0 -37px");
    }

    function mout(obj) {
        var child = $(obj).children("a");

        child.css("height", "37px");
        child.css("marginTop", "5px");
        child.css("backgroundPosition", "0 0");
    }

    function showMenu(obj) {
        var pos = getPosition(obj).split(",");
        var x = pos[0];
        var y = Number(pos[1]) + Number(42);
        var popup_obj = $('#popup_' + $(obj).children("a").attr("id"));

        popup_obj.css("left", x + 'px');
        popup_obj.css("top", y + 'px');
        popup_obj.show();
    }

    /* LOGIN DURUMU  //Serdar.Y
    */

    var loginspan = $("#_topMenuText");

    $.ajax({
        url: "/interactive/getlogininfo.aspx",
        data: "",
        global: false,
        type: "POST",
        dataType: "html",
        success: function (response) {
            loginspan.html(response);
        }
    });

    //numara kaldirmaca FTD

    var intValue = 0;
    $(".numara_olcu").mouseover(function () {
        $(this).find("span").fadeIn("normal");
        intValue = window.clearTimeout(intValue);
    });
    $(".numara_olcu").mouseout(function () {
        intValue = window.setTimeout('kapa()', 5000);
    });


    $(".kupon-cursorPointer").click(function () {
        className = $(this).next().find("td p").attr("class");
        if (className == "close-menu") {
            $(this).next().find("td p.close-menu").attr("class", "open-menu");
            $(this).find("td#oklu").css({ "background": "url(localImages/OSImages/kupon-selected-bg.gif) no-repeat top left", "padding-left": "30px" });
        } else if (className == "open-menu") {
            $(this).next().find("td p.open-menu").attr("class", "close-menu");
            $(this).find("td#oklu").css({ "background": "url(localImages/OSImages/kupon-Uselected-bg.gif) no-repeat top left", "padding-left": "30px" });
        }

    });

    function kapa() {
        $(".numara_olcu span").fadeOut("slow");
    }

    $(".closeBox").click(function () {

        $('#iframe').hide();
        $('#coverBody').hide();
        $('#mask').hide();
    });

    //Sepette Login Pencerelerini açip kapatiyor

    $(".signUpBtn1").click(function () {

        $("#loginForm1").hide();
        $("#gizlilikDiv").hide();
        $("#guvenlikDiv").hide();
        $("#loginForm2").fadeIn("slow");

    });

    $(".signInBtn").click(function () {

        $("#loginForm2").hide();
        $("#loginForm1").fadeIn("slow");
        $("#gizlilikDiv").hide();
        $("#guvenlikDiv").hide();

    });

    $(".gizlilikLink").click(function () {

        $("#loginForm2").hide();
        $("#gizlilikDiv").fadeIn("slow");
        $("#guvenlikDiv").hide();

    });

    $(".guvenlikLink").click(function () {

        $("#loginForm2").hide();
        $("#gizlilikDiv").hide();
        $("#guvenlikDiv").fadeIn("slow");

    });

    $("#signInBtn2").click(function () {

        $("#guvenlikDiv").hide();
        $("#gizlilikDiv").hide();
        $("#loginForm2").fadeIn("slow");

    });

    $("#signInBtn3").click(function () {

        $("#guvenlikDiv").hide();
        $("#gizlilikDiv").hide();
        $("#loginForm1").hide();
        $("#loginForm2").fadeIn("slow");

    });

    //Sepette Login Pencerelerini açip kapatiyor bitti//	


});

//Modal Pencereyi açmak içim Kullaniliyor .basic class'i verilen sayfalari açiyor.

function sepetClick() {

    jQuery(function ($) {

            $("#basic-modal-content").modal({ onClose: function (dialog) {
                $.modal.close();
            } 
            });

    });
    return false;
}


//HEADER BITTI

var BalonIcerik = "buraya içerik gelicek parametre olarak alıyoruz.";

function displayHelp(variable, spanId) {
    var span = document.getElementById(spanId);
    if (document.getElementById("hlp_" + span.id))
    { document.getElementById("hlp_" + span.id).style.display = "block"; }
    else {
        var helpDiv = document.createElement('div');
        helpDiv.className = "help-div";
        helpDiv.innerHTML = "<div class=\"hlp-top\"></div><div class=\"hlp-content\"><span>" + variable + "</span></div><div class=\"hlp-bottom\"></div>";
        helpDiv.id = "hlp_" + span.id;
        span.appendChild(helpDiv);
        document.getElementById("hlp_" + span.id).style.display = "block";
        helpDiv.onmouseover = function () { displayHelp(variable, spanId); }
        helpDiv.onmouseout = function () { closeHelp(spanId); }
    }
}
function closeHelp(spanId) {
    var span = document.getElementById(spanId);
    if (document.getElementById("hlp_" + span.id)) {
        span.firstChild.nextSibling.style.display = "none";
    }
    else {
        return;
    }
}
function statikHidden() {

    var obj = document.getElementById('statikCon');
    var obj2 = document.getElementById('statikImg');

    if (obj.className == "open-menu") {
        obj.className = "close-menu";
        obj2.src = "localImages/UDImages/left-arrow.gif";

    }

    else {
        if (ajaxCheck == 0) {
            $(document).ready(function () {
                $("#statikCon").load("interactive/getdetay.aspx?fiyat=" + fiyat + "&kdvtoplam=" + kdv);
            });
        }
        ajaxCheck = 1;	
        obj.className = "open-menu";
        obj2.src = "localImages/UDImages/bottom-arrow.gif";

    }

}

//Anket Formu Modal - Fulya Aral

function launchWindow() {

    var bodyCoverHeight = ($('body').height()) - 400;
    $('#coverBody').height(bodyCoverHeight + 'px');
    $('#coverBody').show();

    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

    $('#mask').fadeIn("slow");

    var popMargTop = ($('#iframe').height() + 80) / 2;
    var popMargLeft = ($('#iframe').width() + 80) / 2;

    $('#iframe').css({
        'margin-top': -popMargTop,
        'margin-left': -popMargLeft

    });

    $('#iframe').fadeIn("slow");
}


function errorModal() {

    $(".errorModal").fadeIn().prepend('<a href="javascript:void(0)" class="close"><img src="../img/errorPageClose.png" class="btn_close" title="Close Window" alt="Close" /></a>');

    var popMargTop = ($(".errorModal").height() + 80) / 2;
    var popMargLeft = ($(".errorModal").width() + 80) / 2;

    $(".errorModal").css({
        'margin-top': -popMargTop,
        'margin-left': -popMargLeft
    });

    $('body').append('<div id="fade"></div>');
    $('#fade').css({ 'filter': 'alpha(opacity=80)' }).fadeIn();

    return false;

}

jQuery(function () {

    $('a.close, #fade').live('click', function () {
        $('#fade , .errorModal').fadeOut(function () {
            $('#fade, a.close').remove();
        });

        return false;
    });

});

function errorModal2() {

    $(".errorModal2").fadeIn().prepend('<a href="javascript:void(0)" class="close"><img src="../img/errorPageClose.png" class="btn_close" alt="Kapat" /></a>');

    var popMargTop = ($(".errorModal2").height() + 80) / 2;
    var popMargLeft = ($(".errorModal2").width() + 80) / 2;

    $(".errorModal2").css({
        'margin-top': -popMargTop,
        'margin-left': -popMargLeft
    });

    $('body').append('<div id="fade"></div>');
    $('#fade').css({ 'filter': 'alpha(opacity=80)' }).fadeIn();

    return false;

}
function getRelationProductsHTML(colorId) {
    
    var html = "";
    $.get('/interactive/SolrProxy.aspx?r=' + colorId, function (data) {
        data = eval(data);
        $.each(data.response.docs, function (index) {
           
            if (index >= 0) {
                var cid = 0;
              if (data.response.docs[index].ProductId1 == colorId)
                   cid = data.response.docs[index].ProductId2;
                else
                    cid = data.response.docs[index].ProductId1;
                $.get('/interactive/SolrProxy.aspx?p=' + cid, function (ddata) {
                    ddata = eval(ddata);
                   html += "<div style='text-align:center;font-size:14px;float:left;width:145px;margin:0 60px 0 30px;' class='big-img-container" + ddata.response.docs[0].RenkId + "'><a href='" + ddata.response.docs[0].Furl + "'><img src='/images/urunler/" + ddata.response.docs[0].UrunId + "/" + ddata.response.docs[0].RenkId + "/st_s.jpg' alt='" + ddata.response.docs[0].MarkaAdi + "-" + ddata.response.docs[0].UrunAdi + "' border='0' width='135' height='135' /><strong style='display:block;'>" + ddata.response.docs[0].MarkaAdi + "</strong><span>" + ddata.response.docs[0].UrunAdi + "</span></a></div>";
                    $('#relationContainer').html(html + "<div class='cb'></div>");

               });



            }



        });



    });
    kontrolbenzer();
}

function kontrolbenzer() {
    
    $("#relationContainer").closest('.container-bottom').hide("fast");
}

 $(function() {

    $('a.close, #fade, .errorModal2').live('click', function () {
        $('#fade , .errorModal2').fadeOut(function () {
            $('#fade, a.close').remove();
        });

        return false;
    });
	

});
