﻿///<reference path="jquery-1.3.2-vsdoc2.js" />
var rndJqueryServiceName;
var rndMainPath;

///JQuery'in başlangıç noktasıdır.
///Sayfa'da JQuery'i kullanılırsa DOM hazır olduğunda bu fonksiyonlar çağrılır.
$(document).ready(function () {

    try {
        rndJqueryServiceName = jQuery.url.attr("protocol") + "://" + jQuery.url.attr("host") + "/RndJqueryService.svc/";
        rndMainPath = jQuery.url.attr("protocol") + "://" + jQuery.url.attr("host") + "/";
        if (jQuery.url.attr("host") == "localhost") {
            rndJqueryServiceName = jQuery.url.attr("protocol") + "://" + jQuery.url.attr("host") + "/ETBoyner/RndJqueryService.svc/";
            rndMainPath = jQuery.url.attr("protocol") + "://" + jQuery.url.attr("host") + "/ETBoyner";
        }
    }
    catch (err) { /*alert(err); */ }
    //Ajax ve jQuery çakışmasını engelle    
    PreventConflictBetweenAjaxAndJquery();
    //Sadece rakam girilmesini sağla
    InsertOnlyNumberIntoTextbox();
    //Maxlength'den daha fazla karakter girilmesini engelle
    PreventMoreCharacterThanMaxLength();

    //$("div[divColors=true]").css("opacity", "1.0");
});




///Joe Doe - 20.01.2010
///Sayfada number=true olarak attribute verilen textboxlara sadece numara girilebilir.
function InsertOnlyNumberIntoTextbox() {
    $('input[number=true]').keypress(function (e) {
        return (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) ? false : true;
    });
}

///jQuery kullanılan sayfa da Ajax Control Toolkit de kullanılırsa Jquery çalışmamaya başlıyor.
///Bunu engellemek için bu fonksiyon kullanılmalıdır.
function PreventConflictBetweenAjaxAndJquery() {
    try {
        //        var prm = Sys.WebForms.PageRequestManager.getInstance();
        //        prm.add_endRequest(EndRequestHandler);
        //        prm.add_beginRequest(BeginRequestHandler);
    }
    catch (err) { }
}

///Ajax Control Toolkit çakışmasını engellemek yazılan fonksiyonlar.
function BeginRequestHandler(sender, args) {

}

function EndRequestHandler(sender, args) {
    InsertOnlyNumberIntoTextbox();
    PreventMoreCharacterThanMaxLength();
}

///Joe Doe - 18/02/2010
///Üye kayıt sayfasında evlilik statüsü değiştirildiğinde Evlilik Tarihi Panelini açar veya kapar.
function ChangedMarialStatus(sender, pnlLbl, pnlDdl) {
    if ($("#" + sender).val() == "Married") {
        $("#" + pnlLbl).show();
        $("#" + pnlDdl).show();
    }
    else {
        $("#" + pnlLbl).hide();
        $("#" + pnlDdl).hide();
    }
}

///Joe Doe - 18/02/2010
///Üye kayıt sayfasında şehir değiştirildiğinde Telefon
function ChangedPhoneNumber(sender, target) {
    var deger = $("#" + sender).val();
    var phoneCode = $("#" + sender + " option[value='" + deger + "']").attr('phonecode');
    $("#" + target).html("+90-(" + phoneCode + ")");
}

//Joe Doe
//15.02.2010 - Pazartesi - 09:28
//FirmID'si 38 olan firmada DepartmantList'de Açılan Childların Renkleri Mavi; Diğer üyeler siyah yapılmalı.
function ColumbiaDepartmentList() {
    var subsubHas = $("#departmentList a[subsub=true]").html();
    var subHas = $("#departmentList a[sub=true]").html();
    var mainHas = $("#departmentList a[main=true]").html();

    if (subsubHas != null) {
        $("#departmentList a[subsub=true]").parent().removeClass();
        $("#departmentList a[subsub=true]").parent().addClass("child");
        $("#departmentList a[sub=true]").parent().removeClass();
        $("#departmentList a[sub=true]").parent().addClass("theother");
        $("#departmentList a[sub=true]").parent().css("margin-left", "15px");
        $("#departmentList a[main=true]").parent().removeClass();
        $("#departmentList a[main=true]").parent().addClass("theother");
    }
    else if (subHas != null) {
        $("#departmentList a[sub=true]").parent().removeClass();
        $("#departmentList a[sub=true]").parent().addClass("child");
        $("#departmentList a[main=true]").parent().removeClass();
        $("#departmentList a[main=true]").parent().addClass("theother");
    }
    else {
        $("#departmentList a[main=true]").parent().removeClass();
        $("#departmentList a[main=true]").parent().addClass("child");
    }
}

///Joe Doe - 19/02/2010
///textbox veya textarea ya attribute olarak maxlength verilir.
///maxlength'den daha fazla karakter girilmesi engellenmiş olunur.
function PreventMoreCharacterThanMaxLength() {
    $("textarea[maxlength]").keypress(function (event) {

        var key = event.which;

        //all keys including return.
        if (key >= 33 || key == 13) {
            var maxLength = $(this).attr("maxlength");
            var length = this.value.length;
            if (length >= maxLength) {

                event.preventDefault();
            }
        }
    });

    $("input[maxlength]").keypress(function (event) {

        var key = event.which;

        //all keys including return.
        if (key >= 33 || key == 13) {
            var maxLength = $(this).attr("maxlength");
            var length = this.value.length;
            if (length >= maxLength) {

                event.preventDefault();
            }
        }
    });
}

///Joe Doe - 24/02/2010
///FirmID'si 39 olan firmada 'de Department/ShowAllProducts.aspx sayfasında sol tarafta çıkan ProductFilter kontrolu için yazıldı.
///Filtreleme işlemleri için. Ajax ile veri istenip sol tarafta gösterme işlemi.
//{"size":["L","M","S","XXS"],"length":["28","27","25","34"],"waist":["40","48","49","50"],"color":["Kırmızı","Mavi","Yeşil","Mürekkep"]}
var jsonResultStart = '{';

var jsonSizeStart = '"size":[';
var jsonSize = '';
var jsonSizeEnd = ']';

var jsonLengthStart = '"length":[';
var jsonLength = '';
var jsonLengthEnd = ']';

var jsonWaistStart = '"waist":[';
var jsonWaist = '';
var jsonWaistEnd = ']';

var jsonColorStart = '"color":[';
var jsonColor = '';
var jsonColorEnd = ']';

var jsonMoneyStart = '"money":[';
var jsonMoney = '';
var jsonMoneyEnd = ']';

var jsonResultEnd = '}';
var effectDuration = 300;
var requestAfterWaitTime = 1000;
var timer;
var sections = { "size": 0, "waist": 1, "length": 2, "color": 3, "money": 4, "reset": 5 };

function BindOnClickMethodForProductFilter() {
    $(".product_feature .beden li").click(function () {
        MakeInvisibleRequestDataByAjaxAndMakeVisible(sections.size, $(this));
    });

    $(".product_feature .boy li").click(function () {
        MakeInvisibleRequestDataByAjaxAndMakeVisible(sections.length, $(this));
    });

    $(".product_feature .bel li").click(function () {
        MakeInvisibleRequestDataByAjaxAndMakeVisible(sections.waist, $(this));
    });

    $(".product_feature .renk li").click(function () {
        MakeInvisibleRequestDataByAjaxAndMakeVisible(sections.color, $(this));
    });

    //ProductFilter.ascx kontrolunde Reset tuşu için aşağıdaki kod bloğu yazıldı.
    $("#" + GetIdOfResetButton()).click(function () {
        MakeInvisibleRequestDataByAjaxAndMakeVisible(sections.reset, $(this));
    });
}


function GetMoneySliderValueWhenChanging(event, ui) {
    $("#amount").html(ui.values[0] + ' TL - ' + ui.values[1] + ' TL');

    MakeInvisibleRequestDataByAjaxAndMakeVisible(sections.money, ui);
}

function MakeInvisibleRequestDataByAjaxAndMakeVisible(choice, element) {
    if (choice != 5 && choice != 4)
        element.toggleClass("selected");

    var size = "";
    if (choice != 4)
        size = element.attr("size");

    $("#" + GetIdOfPnlListProductCustom()).fadeTo(effectDuration, 0, function () {
        var message = $("#" + GetIdOfPnlListProductCustom()).attr("message");
        $("#" + GetIdOfPnlListProductCustom()).html("<div style=\"width: 100%; height: 500px; text-align: center; vertical-align: middle;color: rgb(0, 175, 255);background-color:White;\" id=\"loading\">" +
        "<img border=\"0\" src=\"" + rndMainPath + "/media/img_general/loading.gif\"" +
            "style=\"margin-top: 175px;\"><br><span>" + message + "</span></div>");
        $("#" + GetIdOfPnlListProductCustom()).css("opacity", "1.0");
        $("#" + GetIdOfPnlListProductCustom()).css("background-color", "white");
        //içeriği temizle
        //        $("#loading").show("fast");
        switch (choice) {
            case 0:
                {
                    var index = jsonSize.indexOf('"' + size + '",', 0);

                    if (index < 0)
                        jsonSize += '"' + size + '",';
                    else
                        jsonSize = jsonSize.replace('"' + size + '",', '');
                    break;
                }
            case 1:
                {
                    //Seçilen li'nin değerini bir diziye al.                        
                    var index = jsonWaist.indexOf('"' + size + '",', 0);

                    if (index < 0)
                        jsonWaist += '"' + size + '",';
                    else
                        jsonWaist = jsonWaist.replace('"' + size + '",', '');
                    break;
                }
            case 2:
                {
                    var index = jsonLength.indexOf('"' + size + '",', 0);

                    if (index < 0)
                        jsonLength += '"' + size + '",';
                    else
                        jsonLength = jsonLength.replace('"' + size + '",', '');
                    break;
                }
            case 3:
                {
                    var index = jsonColor.indexOf('"' + size + '",', 0);

                    if (index < 0)
                        jsonColor += '"' + size + '",';
                    else
                        jsonColor = jsonColor.replace('"' + size + '",', '');
                    break;
                }
            case 4:
                {
                    jsonMoney = '"' + element.values[0] + '","' + element.values[1] + '"';
                    break;
                }
            case 5:
                {
                    jsonSize = '';
                    jsonLength = '';
                    jsonWaist = '';
                    jsonColor = '';
                    jsonMoney = '';

                    //Slider'ı baslangıc konumuna taşı.
                    var max = $("#slider-range").slider('option', 'max');
                    var min = $("#slider-range").slider('option', 'min');

                    $("#slider-range").slider('option', 'values', [min, max]);

                    $("#amount").html(min + ' TL - ' + max + ' TL');

                    //seçili olanları alır selected olanları kaldırır.
                    $(".selected").toggleClass("selected");
                    break;
                }
        }
        //Sağ tarafta yer alan Div'i görünüş olarak kaybet. Ajax ile istekde bulun.  Gelen HTML'i sayfaya yazdır.
        //requestAfterWaitTime süresi sonunda istek gönder.
        window.clearTimeout(timer);
        timer = window.setTimeout(GetAndSetDataForFilter, requestAfterWaitTime);
    });
}

///Ürün Listeleme sayfasında ürünün özelliklerine tıkladıkça productImage resmini değiştiren method. 
function ChangeProductImage(productImageId, imageSrc, productSpec) {
    $("#" + productImageId).attr("src", imageSrc);
    var str = productSpec.toString();
    var index = str.lastIndexOf("_", str.length);
    var searchedstr = str.substring(0, index);

    $("img[id*=" + searchedstr + "]").removeClass("productSpecSelected");
    $("#" + productSpec).addClass("productSpecSelected");
}

///
function ShowProductDetailDiv(id) {
    $("#" + id).fadeTo(500, 1, function () { });
}


///
function HideProductDetailDiv(id) {
    $("#" + id).hide();
}

function SetUniqueRadioButton(id, rb) {
    $("input[id*=" + id + "]").attr("checked", false);
    $(rb).attr("checked", true);
}

function GetProductsByPaging(pageIndex) {
    var searchText = $("#pagenumbers").attr("searchtext");
    var allowPaging = true;
    var pageSize = $("#pagenumbers").attr("pagesize");

    $("#" + GetIDofPnlListProduct()).fadeTo(effectDuration, 0, function () {
        var message = $("#" + GetIDofPnlListProduct()).attr("message");
        $("#" + GetIDofPnlListProduct()).html("<div style=\"width: 100%; height: 500px; text-align: center; vertical-align: middle;color: rgb(0, 175, 255);\" id=\"loading\">" +
        "<img border=\"0\" src=\"" + rndMainPath + "/media/img_general/loading.gif\"" +
            "style=\"margin-top: 175px;\"><br><span>" + message + "</span></div>");
        $("#" + GetIDofPnlListProduct()).css("opacity", "1.0");


        var url = rndJqueryServiceName + "GetProductsByPageIndex";
        var data = jsonResultStart + '"searchText":"' + searchText + '","allowPaging":' + allowPaging + ',"pageSize":' + pageSize + ',"pageIndex":' + pageIndex + jsonResultEnd;
        DataManagement(url, data, function (result) {
            $("#" + GetIDofPnlListProduct()).html(result.GetProductsByPageIndexResult);
            $("#" + GetIDofPnlListProduct()).fadeTo(effectDuration, 1, function () { });
        });
    });
}

//RndJQueryLib.js dosageında SetFilterAgain() adlı method bulunmaktadır.
//Bu method site içerisinde son yapılan filtrelemeleri Session da tutmaktadır.
//Tekrar o departmana girildiğinde son yaptığınız filtrelemeyi sisteme uygulamaktadır.

//Bu methodun çağrıldığı yer ise FirmaID'si 39 olan firmanın klasorunde yer alan ProductFilter.ascx
function SetFilterAgain() {
    var url = rndJqueryServiceName + "GetFilterOptionsFromSession";
    var data = '{"departmentId":"' + GetDepartmentID() + '"}';

    DataManagement(url, data, function (result) {
        if (result.GetFilterOptionsFromSessionResult != null) {
            $("#" + GetIdOfPnlListProductCustom()).fadeTo(effectDuration, 0.0, function () {
                var message = $("#" + GetIdOfPnlListProductCustom()).attr("message");
                $("#" + GetIdOfPnlListProductCustom()).html("<div style=\"width: 100%; height: 500px; text-align: center; vertical-align: middle;color: rgb(0, 175, 255);\" id=\"loading\">" +
        "<img height=\"90px\" alt=\"\" width=\"90px\" src=\"" + rndMainPath + "/media/img_general/loading.gif\"" +
            "style=\"margin-top: 175px;\"><br><span>" + message + "</span></div>");
                $("#" + GetIdOfPnlListProductCustom()).css("opacity", "1.0");

                //{"size":["L","M","S","XXS"],"length":["28","27","25","34"],"waist":["40","48","49","50"],"color":["Kırmızı","Mavi","Yeşil","Mürekkep"]}
                var size = result.GetFilterOptionsFromSessionResult.size;
                var color = result.GetFilterOptionsFromSessionResult.color;
                var waist = result.GetFilterOptionsFromSessionResult.waist;
                var length = result.GetFilterOptionsFromSessionResult.length;
                var minMoney = result.GetFilterOptionsFromSessionResult.minMoney;
                var maxMoney = result.GetFilterOptionsFromSessionResult.maxMoney;
                jsonSize = '';
                jsonColor = '';
                jsonLength = '';
                jsonWaist = '';

                for (i = 0; i < size.length; i = i + 1) {
                    jsonSize += '"' + size[i] + '",';
                    $("td[class=beden] ul li[size=" + size[i] + "]").addClass("selected");
                }

                for (i = 0; i < color.length; i = i + 1) {
                    jsonColor += '"' + color[i] + '",';
                    $("td[class=renk] ul li[size=" + color[i] + "]").addClass("selected");
                }

                for (i = 0; i < length.length; i = i + 1) {
                    jsonLength += '"' + length[i] + '",';
                    $("td[class=boy] ul li[size=" + length[i] + "]").addClass("selected");
                }

                for (i = 0; i < waist.length; i = i + 1) {
                    jsonWaist += '"' + waist[i] + '",';
                    $("td[class=bel] ul li[size=" + waist[i] + "]").addClass("selected");
                }
                if (minMoney != "" && maxMoney != "") {
                    jsonMoney = '"' + minMoney + '","' + maxMoney + '"';
                    $("#slider-range").slider('option', 'values', [minMoney, maxMoney]);
                    $("#amount").html(minMoney + ' TL - ' + maxMoney + ' TL');
                }

                GetAndSetDataForFilter();
            });
        }
    });
}

///
function GetAndSetDataForFilter() {
    var url = rndJqueryServiceName + "GetProductsByFilter";
    var data = jsonResultStart + jsonSizeStart + jsonSize.substring(0, jsonSize.length - 1) + jsonSizeEnd + ',' +
                jsonLengthStart + jsonLength.substring(0, jsonLength.length - 1) + jsonLengthEnd + ',' +
                jsonWaistStart + jsonWaist.substring(0, jsonWaist.length - 1) + jsonWaistEnd + ',' +
                jsonColorStart + jsonColor.substring(0, jsonColor.length - 1) + jsonColorEnd + ',' +
                jsonMoneyStart + jsonMoney + jsonMoneyEnd +
                ',"departmentId":' + GetDepartmentID() + jsonResultEnd;
    DataManagement(url, data, function (result) {
        $("#" + GetIdOfPnlListProductCustom()).fadeTo(effectDuration, 1.0, function () {
            $("#" + GetIdOfPnlListProductCustom()).html(result.GetProductsByFilterResult);
        });
    });
}

function DataManagement(Url, Data, Success) {
    $.ajax({
        url: Url, //rndJqueryServiceName + "GetProductsByFilter",
        type: "POST",
        contentType: "application/json",
        data: Data,
        dataType: "json",
        complete: function () {
        },
        success: Success,
        error: function (xhr, ajaxOptions, thrownError) {
            if (xhr.status == "500")
                $('#one').jGrowl($(".JsCodeErrorMessage").text());

            else
                $('#one').jGrowl($(".JsConnectionErrorMessage").text());
        }
    });
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
//Genel Fonksiyonlar//sertaç yıldırım
////////////////////////////////////////////////////////////////////////////////////////////////////

function SearchKeyPress(e) {
    var code = (e.keyCode ? e.keyCode : e.which);
    if (code == 13) {
        if (jQuery.trim($('.search_field').val()).length > 0) {
            window.location = rndMainPath + "/UrunArama.aspx?searchText=" + escape($('input[search_field=true]').val());
        }
        return false;
    }
}

function Search() {
    if (jQuery.trim($('input[search_field=true]').val()).length > 0) {
        window.location = rndMainPath + "/UrunArama.aspx?searchText=" + escape($('input[search_field=true]').val());
    }
}


function validate(email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = email;
    if (reg.test(address) == false) {
        return false;
    }
    else
        return true;
}

/////////////////////////////////////////////////////////////
//Ürün Detay Sayfası Script
////////////////////////////////////////////////////////////
$(document).ready(function () {
    //Image Zoom
    var options =
        {
            title: false,
            zoomWidth: 250,
            zoomHeight: 250,
            xOffset: 10,
            yOffset: 60,
            lens: true,
            preloadText: 'Yükleniyor'
            //zoomType:'reverse'
        }
    if ($(".jqzoom").text() != null)
        $(".jqzoom").jqzoom(options);

    //First Spec.
    $(".sizeButtonNoStock").click(function () {
        return false;
    });
    $(".sizeButton").click(function () {
        if ($(this).attr("relationSecond") != null) {
            $("div[panelSecondSpecs=true]").hide();
            $(".panelSecondSpecs_" + $(this).attr("relationSecond")).show();

        }
        //Resim Değişiminde Seçimler Sıfırlanır.
        $(".sizeButtonSelected").attr("class", "sizeButton");
        $(".sizeButtonSecondSelected").attr("class", "sizeButtonSecond");
        $("input[AddBasket=true]").attr("disabled", "true");
        $("span[lblProductSecondSpecLabel=true]").html("");

        $(".sizeButtonSelected").attr("class", "sizeButton");
        $(".sizeButtonSelected").removeAttr("selected");
        $(this).attr("class", "sizeButtonSelected");

        $(this).attr("selected", "true");
        $("#txtSelectedSpec").val($(this).attr("val"));

        //Direction Listelemelerde radio button olduğu için return false seçmeyi engelliyor.
        if ($(this).attr("type") != "radio")
            return false;
        else
            return true;
    });

    $(".sizeButton").mouseover(function () {
        if ($(this).attr("class") == "sizeButton")
            $(this).removeAttr("selected");
        $(this).attr("class", "sizeButtonSelected");
        return false;
    });

    $(".sizeButton").mouseout(function () {
        if ($(this).attr("selected") != "true") {
            $(this).attr("class", "sizeButton");
            $(this).removeAttr("selected");
        }
        return false;
    });

    //Second Spec.
    $(".sizeButtonSecondNoStock").click(function () {
        return false;
    });
    $(".sizeButtonSecond").click(function () {

        $(".sizeButtonSecondSelected").attr("class", "sizeButtonSecond");
        $(".sizeButtonSecondSelected").removeAttr("selected");
        $(this).attr("class", "sizeButtonSecondSelected");
        $(this).attr("selected", "true");
        $("#txtSelectedSpec").val($(this).attr("val"));
        return false;
    });

    $(".sizeButtonSecond").mouseover(function () {
        if ($(this).attr("class") == "sizeButtonSecond")
            $(this).removeAttr("selected");
        $(this).attr("class", "sizeButtonSecondSelected");
        return false;
    });

    $(".sizeButtonSecond").mouseout(function () {
        if ($(this).attr("selected") != "true") {
            $(this).attr("class", "sizeButton");
            $(this).removeAttr("selected");
        }
        return false;
    });

    //Özelikler Seçilince Sepete Ekleme Aktif Olması İçin
    if ($(".sizeButtonSecond").attr("val") != null && $(".sizeButton").attr("val") != null) {
        $("input[AddBasket=true]").attr("disabled", "true");

        $(".sizeButton").click(function () {
            if ($(".sizeButtonSecondSelected").attr("val") != null) {
                $("input[AddBasket=true]").removeAttr("disabled");
                try {
                    if (ProductPrice != null) {
                        var key = "'" + $(".sizeButtonSelected").attr("val") + "'";
                        var deger = ProductPrice[eval(key)];
                        $("span[id$=lblPriceOutput]").text(deger);
                    }
                } catch (err) { }
            }
        });
        $(".sizeButtonSecond").click(function () {
            if ($(".sizeButtonSelected").attr("val") != null) {
                $("input[AddBasket=true]").removeAttr("disabled");
                try {
                    if (ProductPrice != null) {
                        var key = "'" + $(".sizeButtonSelected").attr("val") + "_" + $(".sizeButtonSecondSelected").attr("val") + "'";
                        var deger = ProductPrice[eval(key)];
                        $("span[id$=lblPriceOutput]").text(deger);
                    }
                } catch (err) { }
            }
        });
    }
    else if ($(".sizeButtonSecond").attr("val") == null && $(".sizeButton").attr("val") != null) {
        $("input[AddBasket=true]").attr("disabled", "true");
        $(".sizeButton").click(function () {
            $("input[AddBasket=true]").removeAttr("disabled");
        });
    }
    else if ($(".sizeButtonSecond").attr("val") == null && $(".sizeButton").attr("val") == null) {

    }

    //Sepet Ekle ve Açılma Animasyonu
    $("input[AddBasket=true]").click(function () {
        AddBasket();
        return false;
    });
    //Ürün İkinci Özelliğini Pasif Yapma
    $("div[panelsecondspecs=true]").children().each(function (index, value) {
        $(this).attr("disabled", "disabled");
    });
    //Ürün İkinci Özelliğini Aktif Yapma
    $(".sizeButton").click(function () {
        $("div[panelsecondspecs=true]").children().each(function (index, value) {
            $(this).removeAttr("disabled");
        });
    });
});
$(document).ready(function () {
    try {
        $('.search_field').autocomplete(rndJqueryServiceName + 'ProductSearch', {
            dataType: 'json',
            parse: function (data) {
                var rows = new Array();
                for (var i = 0; i < data["SearchProductResult"].length; i++) {
                    rows[i] = { data: data["SearchProductResult"][i], value: data["SearchProductResult"][i], result: data["SearchProductResult"][i] };
                }
                return rows;
            },
            formatItem: function (row, i, n) {
                return row;
            },
            width: 150,
            minChars: 2,
            mustMatch: false,
            selectFirst: false
        }).result(function (event, item) {
            window.location = rndMainPath + "/UrunArama.aspx?searchText=" + $('input[search_field=true]').val();
        });


        //Modal Pop-up
        $('a[id$=hlnProductSuggestion]').click(newModal);

    } catch (err) {

    }

});

function BasketState() {
    $(window).scrollTo(0, { duration: 2000 });
    $(".megamenu").show();
    $("#timer").oneTime(8000, function () {
        $(".megamenu_detail").animate({ height: "0px" }, 1200);
        $(".megamenu").hide();
    });
}

function BasketLinkState(obj) {
    $("#timer").oneTime(600, function () {
        $.ajax({
            url: rndJqueryServiceName + "GetBasket",
            type: "POST",
            contentType: "application/json",
            dataType: "json",
            success: function (data) {
                if (data["GetBasketResult"] != null) {
                    $("img[productimage=true]").attr("src", data["GetBasketResult"]["Image"]);
                    $("div[productname=true]").text(data["GetBasketResult"]["Name"]);
                    $("label[productcolor=true]").text(data["GetBasketResult"]["Color"]);
                    $("label[productsize=true]").text(data["GetBasketResult"]["Size"]);
                    $("label[productquantity=true]").text(data["GetBasketResult"]["Quantity"]);
                    $("label[productprice=true]").text(data["GetBasketResult"]["Price"] + " " + data["GetBasketResult"]["PriceType"]);
                    $("label[basketquantity=true]").text(data["GetBasketResult"]["ProductQuantity"]);
                    $(".lblBasketQuantity").text(data["GetBasketResult"]["ProductQuantity"]);
                    $("label[basketprice=true]").text(data["GetBasketResult"]["TotalPrice"] + " " + data["GetBasketResult"]["PriceType"]);

                    if ($("label[productsize=true]").text() == "" || $("label[productsize=true]").text() == "-----") {
                        $("tr[productsize=true]").hide();
                    }
                    if ($("label[productcolor=true]").text() == "" || $("label[productcolor=true]").text() == "-----") {
                        $("tr[productcolor=true]").hide();
                    }

                    $(".megamenu").show();
                }
                else {
                    $(".megamenu").hide();
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                if (xhr.status == "500")
                    $('#one').jGrowl($(".JsCodeErrorMessage").text());
                else
                    $('#one').jGrowl($(".JsConnectionErrorMessage").text());
            }
        });
        $("#timer").stopTime();

    });
}

function BasketClose() {
    $("#timer").stopTime();
    $("#timer").oneTime(8000, function () {
        $(".megamenu_detail").animate({ height: "0px" }, 1200);
        $(".megamenu").hide();
    });
}

function AddBasket() {
    if ($("input[AddBasket=true]").attr("disabled") == "true") {
        MessageEffect("Özellik Seçiniz!");
    }

    UpdateProgress(true);

    MessageEffectToObject($("span[Waiting=true]"));
    AddBasketButtonDisabled();
    var productDescriptionID = $(".txtProductInfo").val();
    var colorSpecId = ($(".sizeButtonSelected").attr("val") != null) ? $(".sizeButtonSelected").attr("val") : 0;
    var firstSpecID = ($(".sizeButtonSecondSelected").attr("val") != null) ? $(".sizeButtonSecondSelected").attr("val") : 0;
    var Quantity = $(".Quantity").val();

    //Özelliği Olmayan Ürün İçin Kullanılır.
    if ($(".sizeButtonSelected").attr("val") == null && $(".sizeButtonSecondSelected").attr("val") == null) {
        colorSpecId = $(".txtProductInfoNoSpec").val().split("_")[0];
        firstSpecID = $(".txtProductInfoNoSpec").val().split("_")[1];
    }

    $.ajax({
        url: rndJqueryServiceName + "AddBasket",
        type: "POST",
        contentType: "application/json",
        data: '{"productDescriptionID":"' + productDescriptionID + '","quantity":"' + Quantity + '","colorSpecId":"' + colorSpecId + '","firstSpecID":"' + firstSpecID + '"}',
        dataType: "json",
        complete: function () {
            UpdateProgress(false);
        },
        success: function (data) {
            $("span[Waiting=true]").hide();
            if (data["AddBasketResult"] != "0") {
                GetBasket();
                ProductSpecSelectClear();
                MessageEffectToObject($("span[AddToBasketSucceed=true]"));
                $(".sizeButtonSelected").attr("class", "sizeButton");
                $(".sizeButtonSecondSelected").attr("class", "sizeButtonSecond");
            }
            else {
                $("input[AddBasket=true]").removeAttr("disabled");
                MessageEffectToObject($("span[AddToBasketNotSucceed=true]"));
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            if (xhr.status == "500" || xhr.status == "400" || xhr.status == "404")
                $('#one').jGrowl($(".JsCodeErrorMessage").text());
            else
                $('#one').jGrowl($(".JsConnectionErrorMessage").text());
            MessageEffectToObject($("span[AddToBasketNotSucceed=true]"));
        }
    });

    //Direction Listelemelerde Radio Button Seçililirği Kaldırılır.
    if ($(".sizeButtonSelected").attr("type") == "radio") {
        $(".sizeButtonSelected").removeAttr("checked");
    }
}
function AddToShoppingList() {
    UpdateProgress(true);
    var productID = $(".txtProductInfo").val();
    $.ajax({
        url: rndJqueryServiceName + "AddToShoppingList",
        type: "POST",
        contentType: "application/json",
        data: '{"productDescriptionID":"' + productID + '"}',
        dataType: "json",
        complete: function () {
            UpdateProgress(false);
        },
        success: function (data) {
            if (data["AddToShoppingListResult"] == true) {
                $("span[AddToShoppingListSucceed=true]").show();
                $("a[id*=btnAddToShoppingList]").hide();
            }
            else {
                $("span[AddToShoppingListNotSucceed=true]").show();
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            if (xhr.status == "500")
                $('#one').jGrowl($(".JsCodeErrorMessage").text());
            else
                $('#one').jGrowl($(".JsConnectionErrorMessage").text());
        }
    });
    return false;
}

function ProductSuggestionPopupState(value) {
    try {
        if (value) {
            $(".modalPopup").show();
        }
        else {
            $("span[productSuggestionValidation=true]").hide();
            Boxy.get(".modalPopup").hide();
        }
    }
    catch (err) { alert(err); }
}

function newModal() {
    new Boxy($(".modalPopup"), {
        modal: true, behaviours: function (c) {
            c.find('a:first').click(function () {
                newModal();
            });
        }
    });
};

function ProductSuggestionSend() {
    var productDescriptionID = $("input[productDescriptionID=true]").val();
    var fromNameSurname = ($("input[fromNameSurname=true]").val() == null) ? "" : $("input[fromNameSurname=true]").val();
    var fromEMail = ($("input[fromEMail=true]").val() == null) ? "" : $("input[fromEMail=true]").val();
    var toNameSurname = $("input[toNameSurname=true]").val();
    var toEMail = $("input[toEMail=true]").val();
    var message = $("textarea[message=true]").val();

    if (validate(toEMail) == false || jQuery.trim(toNameSurname).length == 0 || jQuery.trim(message).length == 0) {
        $("span[productSuggestionValidation=true]").show();
        return false;
    }
    else
        $("span[productSuggestionValidation=true]").hide();
    UpdateProgress(true);

    $("span[productSuggestionWait=true]").show();
    $("span[productSuggestionValidation=true]").hide();
    $("#ProductSuggestionSendResult").remove();
    $("button[id$=BtnProductSuggestionSend]").attr("disabled", "true");

    $.ajax({
        url: rndJqueryServiceName + "ProductSuggestionSend",
        type: "POST",
        contentType: "application/json",
        data: '{"productDescriptionID":"' + productDescriptionID + '","fromNameSurname":"' + fromNameSurname + '","fromEMail":"' + fromEMail + '","toNameSurname":"' + toNameSurname + '","toEMail":"' + toEMail + '","message":"' + message + '"}',
        dataType: "json",
        complete: function () {
            UpdateProgress(false);
        },
        success: function (data) {
            if (data["ProductSuggestionSendResult"] == true) {
                Boxy.get(".modalPopup").hide();
                $("input[fromNameSurname=true]").val("");
                $("input[fromEMail=true]").val("");
                $("input[toNameSurname=true]").val("");
                $("input[toEMail=true]").val("");
                $("textarea[message=true]").val("");
            }
            else {
                $("button[id$=BtnProductSuggestionSend]").removeAttr("disabled");
                $("span[productSuggestionWait=true]").after("<label id='ProductSuggestionSendResult'>Mail Gönderilemedi!</label>");
                MessageEffectToObject($("#ProductSuggestionSendResult"));
            }
            $("span[productSuggestionWait=true]").hide();
        },
        error: function (xhr, ajaxOptions, thrownError) {
            if (xhr.status == "500")
                $('#one').jGrowl($(".JsCodeErrorMessage").text());
            else
                $('#one').jGrowl($(".JsConnectionErrorMessage").text());
        }
    });
    return false;
}

function AddNewsLetterMember() {

    var email = $("input[email=true]");

    if (validate(email.val()) == false) {
        MessageEffectToObject($("span[revEmail=true]"));
        return false;
    }
    else
        $("span[revEmail=true]").hide();

    UpdateProgress(true);

    $("span[newlettermessage=true]").show();
    $.ajax({
        url: rndJqueryServiceName + "AddNewsLetterMember",
        type: "POST",
        contentType: "application/json",
        data: '{"email":"' + email.val() + '"}',
        dataType: "json",
        complete: function () {
            UpdateProgress(false);
        },
        success: function (data) {

            $("span[newlettermessage=true]").hide();

            if (data["AddNewsLetterMemberResult"] == 0) {
                //Kaydedilemezse
            } else if (data["AddNewsLetterMemberResult"] == 1) {
                MessageEffectToObject($("span[succecss=true]"));
                email.val("");
            }
            else if (data["AddNewsLetterMemberResult"] == 2) {
                MessageEffectToObject($("span[beforeRecord=true]"));
                email.val("");
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            if (xhr.status == "500")
                $('#one').jGrowl($(".JsCodeErrorMessage").text());
            else
                $('#one').jGrowl($(".JsConnectionErrorMessage").text());
        }
    });
    return false;
}

function MessageEffect(msj) {
    $("#message").show();
    $("#message").html(msj);
    $("#message").oneTime(6000, function () {
        $("#message").hide();
    });
}

function MessageEffectToObject(obj) {
    $(obj).show();
    $(obj).oneTime(6000, function () {
        $(obj).hide();
    });
}

function AddBasketButtonDisabled() {
    if ($(".sizeButtonSecond").attr("val") != null && $(".sizeButton").attr("val") != null) {
        $("input[AddBasket=true]").attr("disabled", "true");
    }
    else if ($(".sizeButtonSecond").attr("val") == null && $(".sizeButton").attr("val") != null) {
        $("input[AddBasket=true]").attr("disabled", "true");
    }
    else if ($(".sizeButtonSecond").attr("val") == null && $(".sizeButton").attr("val") == null) {

    }
}

var GetBasketRequest = true;
function GetBasket() {
    if (GetBasketRequest) {
        GetBasketRequest = false;
        UpdateProgress(true);
        try {
            $.ajax({
                url: rndJqueryServiceName + "GetBasket",
                type: "POST",
                contentType: "application/json",
                dataType: "json",
                complete: function () {
                    UpdateProgress(false);
                },
                success: function (data) {
                    GetBasketRequest = true;
                    if (data["GetBasketResult"] != null) {
                        BasketState();
                        $("img[productimage=true]").attr("src", data["GetBasketResult"]["Image"]);
                        $("img[productimage=true]").attr("alt", data["GetBasketResult"]["Name"]);
                        $("div[productname=true]").text(data["GetBasketResult"]["Name"]);
                        $("label[productcolor=true]").text(data["GetBasketResult"]["Color"]);
                        $("label[productsize=true]").text(data["GetBasketResult"]["Size"]);
                        $("label[productquantity=true]").text(data["GetBasketResult"]["Quantity"]);
                        $("label[productprice=true]").text(data["GetBasketResult"]["Price"] + " " + data["GetBasketResult"]["PriceType"]);
                        $("label[basketquantity=true]").text(data["GetBasketResult"]["ProductQuantity"]);
                        $(".lblBasketQuantity").text(data["GetBasketResult"]["ProductQuantity"]);
                        $("label[basketprice=true]").text(data["GetBasketResult"]["TotalPrice"] + " " + data["GetBasketResult"]["PriceType"]);

                        if ($("label[productsize=true]").text() == "" || $("label[productsize=true]").text() == "-----") {
                            $("tr[productsize=true]").hide();
                        }
                        if ($("label[productcolor=true]").text() == "" || $("label[productcolor=true]").text() == "-----") {
                            $("tr[productcolor=true]").hide();
                        }
                    }
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    if (xhr.status == "500")
                        $('#one').jGrowl($(".JsCodeErrorMessage").text());
                    else
                        $('#one').jGrowl($(".JsConnectionErrorMessage").text());
                }
            });
        } catch (err) {

        }
    }
}

function UpdateProgress(value) {
    if (value)
        $("#MainUpdateProgress").show();
    else
        $("#MainUpdateProgress").hide();
}

function GetProductExtraImages(productDescriptionID, firstSpecialityID) {
    UpdateProgress(true);
    $.ajax({
        url: rndJqueryServiceName + "GetProductOtherImages",
        type: "POST",
        contentType: "application/json",
        data: '{"productDescriptionID":"' + productDescriptionID + '","firstSpecialityID":"' + firstSpecialityID + '"}',
        dataType: "json",
        complete: function () {
            UpdateProgress(false);
        },
        success: function (data) {
            if (data["GetProductOtherImagesResult"] != "<tbody></tbody>") {
                $(".pnlOtherProductImages").show();
                $("span[OtherProductImagesNo=true]").hide();
                $("#dlsOtherProductImages").html(data["GetProductOtherImagesResult"]);
                //alert(data["GetProductOtherImagesResult"]);
            }
            else {
                $("span[OtherProductImagesNo=true]").show();
                $("#ctl00_ContentPlaceHolder1_Productdetail1_dlsOtherProductImages").html("");
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            if (xhr.status == "500")
                $('#one').jGrowl($(".JsCodeErrorMessage").text());
            else
                $('#one').jGrowl($(".JsConnectionErrorMessage").text());
        }
    });
}

function ProductSpecSelect(obj) {
    try {
        if ($(obj).attr("ColorPictures") == "true") {
            if ($(".sizeButtonSecond").attr("val") != null) {
                $("span[lblClickColorPictures=true]").text($(obj).attr("title") + " rengini seçtiniz. Lütfen " + $("span[lblProductSecondSpecLabel=true]").attr("labeltext").split(" ")[1] + " seçiniz.");
            }
            else
                $("span[lblClickColorPictures=true]").text($(obj).attr("title") + " rengini seçtiniz. Lütfen adet seçip sepete ekleye basınız.");
        }
        else {
            if ($(".sizeButtonSecond").attr("val") != null) {

                if ($(obj).attr("class") != "sizeButtonSecondNoStock") {
                    if ($(obj).text().split("x").length > 1)
                        $("span[lblProductSecondSpecLabel=true]").text($(obj).text().split("x")[0] + " " + $("span[lblProductSecondSpecLabel=true]").attr("labeltext").split(" ")[1] + " " + $(obj).text().split("x")[1] + " Boy seçtiniz. Lütfen adet seçip sepete ekleye basınız.");
                    else
                        $("span[lblProductSecondSpecLabel=true]").text($(obj).text() + " " + $("span[lblProductSecondSpecLabel=true]").attr("labeltext").split(" ")[1] + " seçtiniz. Lütfen adet seçip sepete ekleye basınız.");
                }
            }
            else {
                if ($(obj).text().split("x").length > 1) {
                    $("span[lblProductFirstSpecLabel=true]").text($(obj).text().split("x")[0] + " " + String($("span[lblProductFirstSpecLabel=true]").attr("labeltext")).replace("&rsaquo;", "") + " " + $(obj).text().split("x")[1] + " Boy seçtiniz. Lütfen adet seçip sepete ekleye basınız.");
                }
                else
                    $("span[lblProductFirstSpecLabel=true]").text($(obj).text() + " " + $("span[lblProductFirstSpecLabel=true]").attr("labeltext").split(" ")[1] + " seçtiniz. Lütfen adet seçip sepete ekleye basınız.");
            }
        }
    } catch (err) { }
}
function ProductSpecSelectClear() {
    $("span[lblClickColorPictures=true]").html("");
    $("span[lblProductFirstSpecLabel=true]").html("");
    $("span[lblProductSecondSpecLabel=true]").html("");
}
///////////////////////////////////////////////////////////////
///////Departman Sayfası
//////////////////////////////////////////////////////////////
$(document).ready(function () {
    //First Relation Spec.
    $(".sizeButtonFirstRelationnNoStock").click(function () {
        return false;
    });
    $(".sizeButtonFirstRelation").click(function () {
        $(".sizeButtonFirstRelationSelected").filter("[line=" + $(this).attr("line") + "]").attr("class", "sizeButtonFirstRelation");
        $(".sizeButtonFirstRelationSelected").filter("[line=" + $(this).attr("line") + "]").removeAttr("selected");
        $(this).attr("class", "sizeButtonFirstRelationSelected");
        $(this).attr("selected", "true");
        return false;
    });


    $(".sizeButtonFirstRelation").mouseover(function () {
        if ($(this).filter("[line=" + $(this).attr("line") + "]").attr("class") == "sizeButtonFirstRelation")
            $(this).filter("[line=" + $(this).attr("line") + "]").removeAttr("selected");
        $(this).filter("[line=" + $(this).attr("line") + "]").attr("class", "sizeButtonFirstRelationSelected");
        return false;
    });

    $(".sizeButtonFirstRelation").mouseout(function () {
        if ($(this).filter("[line=" + $(this).attr("line") + "]").attr("selected") != "true") {
            $(this).filter("[line=" + $(this).attr("line") + "]").attr("class", "sizeButtonFirstRelation");
            $(this).filter("[line=" + $(this).attr("line") + "]").removeAttr("selected");
        }
        return false;
    });

    //Second Relation Spec.
    $(".sizeButtonSecondRelationNoStock").click(function () {
        return false;
    });
    $(".sizeButtonSecondRelation").click(function () {
        $(".sizeButtonSecondRelationSelected").filter("[line=" + $(this).attr("line") + "]").attr("class", "sizeButtonSecondRelation");
        $(".sizeButtonSecondRelationSelected").filter("[line=" + $(this).attr("line") + "]").removeAttr("selected");
        $(this).filter("[line=" + $(this).attr("line") + "]").attr("class", "sizeButtonSecondRelationSelected");
        $(this).filter("[line=" + $(this).attr("line") + "]").attr("selected", "true");
        return false;
    });


    $(".sizeButtonSecondRelation").mouseover(function () {
        if ($(this).filter("[line=" + $(this).attr("line") + "]").attr("class") == "sizeButtonSecondRelation")
            $(this).filter("[line=" + $(this).attr("line") + "]").removeAttr("selected");
        $(this).filter("[line=" + $(this).attr("line") + "]").attr("class", "sizeButtonSecondRelationSelected");
        return false;
    });

    $(".sizeButtonSecondRelation").mouseout(function () {
        if ($(this).filter("[line=" + $(this).attr("line") + "]").attr("selected") != "true") {
            $(this).filter("[line=" + $(this).attr("line") + "]").attr("class", "sizeButtonSecondRelation");
            $(this).filter("[line=" + $(this).attr("line") + "]").removeAttr("selected");
        }
        return false;
    });

    $("input[AddBasketRelation=true]").click(function () {
        if ($("input[AddBasketRelation=true]").filter("[line=" + $(this).attr("line") + "]").attr("disabled") == "true") {
            $("#message").html("Özellik Seçiniz!");
        }
        AddBasketRelation($(this));
        return false;
    });

    //Ürün İkinci Özelliğini Pasif Yapma
    $("div[panelsecondspecsrelation=true]").children().each(function (index, value) {
        $(this).attr("disabled", "disabled");
    });
});

function ProductRelationSpecState(obj) {
    var line = $(obj).attr("line");
    if ($(".sizeButtonSecondRelation").filter("[line=" + line + "]").attr("val") != null && $(".sizeButtonFirstRelation").filter("[line=" + line + "]").attr("val") != null) {


        //Ürün İkinci Özelliğini Aktif Yapma
        $("div[panelsecondspecsrelation=true]").find("button[line=" + line + "]").each(function (index, value) {
            if ($(this).attr("line") == line)
                $(this).filter("[line=" + line + "]").removeAttr("disabled");
        });

        //Resim Değişiminde Seçimler Sıfırlanır.
        //$(".sizeButtonSecondRelationSelected").filter("[line=" + line + "]").attr("class", "sizeButtonSecondRelation");
        //$("input[AddBasketRelation=true]").filter("[line=" + line + "]").attr("disabled", "true");

        if ($(".sizeButtonSecondRelationSelected").filter("[line=" + line + "]").attr("val") != null && $(".sizeButtonFirstRelationSelected").filter("[line=" + line + "]").attr("val") != null) {
            $("input[AddBasketRelation=true]").filter("[line=" + line + "]").removeAttr("disabled");
        }


    }
    else if ($(".sizeButtonSecondRelation").filter("[line=" + line + "]").attr("val") == null && $(".sizeButtonFirstRelation").filter("[line=" + line + "]").attr("val") != null) {
        if ($(".sizeButtonFirstRelationSelected").filter("[line=" + line + "]").attr("val") != null) {
            $("input[AddBasketRelation=true]").filter("[line=" + line + "]").removeAttr("disabled");
        }
    }

    //Renk Seçimi İle Bağlantılı Özelliklerin Aktifliği
    if ($(obj).filter("[line=" + line + "]").attr("ProductRelationSecond") != null) {
        $("div[panelsecondspecsrelation=true]").filter("[line=" + line + "]").hide();
        $("div[panelsecondspecsrelation=true]").filter("[line=" + line + "]").filter("[class=panelSecondSpecsRelation_" + $(obj).attr("line_row") + "]").show();
    }
}

function MessageEffectRelation(msj, obj) {
    $(obj).show();
    $(obj).html(msj);
    $(obj).oneTime(6000, function () {
        $(obj).hide();
    });
}


function AddBasketRelationButtonDisabled(obj) {
    if ($(".sizeButtonRelationSecond").filter("[line=" + $(obj).attr("line") + "]").attr("val") != null && $(".sizeButtonFirstRelation").filter("[line=" + $(obj).attr("line") + "]").attr("val") != null) {
        $(obj).filter("[line=" + $(obj).attr("line") + "]").attr("disabled", "true");
    }
    else if ($(".sizeButtonRelationSecond").filter("[line=" + $(obj).attr("line") + "]").attr("val") == null && $(".sizeButtonFirstRelation").filter("[line=" + $(obj).attr("line") + "]").attr("val") != null) {
        $(obj).filter("[line=" + $(obj).attr("line") + "]").attr("disabled", "true");
    }
    else if ($(".sizeButtonRelationSecond").filter("[line=" + $(obj).attr("line") + "]").attr("val") == null && $(".sizeButtonFirstRelation").filter("[line=" + $(obj).attr("line") + "]").attr("val") == null) {

    }
}

function AddBasketRelation(obj) {

    var productDescriptionID = $("table[ProductRelationParent=true]").find("input[line=" + $(obj).attr("line") + "]");
    var message = $("table[ProductRelationParent=true]").find("span[line=" + $(obj).attr("line") + "]");
    var quantity = $("table[ProductRelationParent=true]").find("select[line=" + $(obj).attr("line") + "]");
    var colorSpecId = 0;

    if ($("table[ProductRelationParent=true]").find("img[line=" + $(obj).attr("line") + "]") != null) {
        $("table[ProductRelationParent=true]").find("img[line=" + $(obj).attr("line") + "]").each(function (index, value) {
            if ($(this).attr("class") == "sizeButtonFirstRelationSelected") {
                colorSpecId = $(this).attr("val");
            }
        });
    }
    if ($("table[ProductRelationParent=true]").find("button[line=" + $(obj).attr("line") + "]") != null) {
        $("table[ProductRelationParent=true]").find("button[line=" + $(obj).attr("line") + "]").each(function (index, value) {
            if ($(this).attr("class") == "sizeButtonFirstRelationSelected") {
                colorSpecId = $(this).attr("val");
            }
        });
    }

    var firstSpecID = 0;

    if ($("table[ProductRelationParent=true]").find("img[line=" + $(obj).attr("line") + "]") != null) {
        $("table[ProductRelationParent=true]").find("img[line=" + $(obj).attr("line") + "]").each(function (index, value) {
            if ($(this).attr("class") == "sizeButtonSecondRelationSelected") {
                firstSpecID = $(this).attr("val");
            }
        });
    }
    if ($("table[ProductRelationParent=true]").find("button[line=" + $(obj).attr("line") + "]") != null) {
        $("table[ProductRelationParent=true]").find("button[line=" + $(obj).attr("line") + "]").each(function (index, value) {
            if ($(this).attr("class") == "sizeButtonSecondRelationSelected") {
                firstSpecID = $(this).attr("val");
            }
        });
    }

    //Özelliği Olmayan Ürün İçin Kullanılır.
    if (colorSpecId == 0 && firstSpecID == 0) {
        $("table[ProductRelationParent=true]").find("input[line=" + $(obj).attr("line") + "]").each(function (index, value) {
            if (index == 1) {
                colorSpecId = $(this).val().split("_")[0];
                firstSpecID = $(this).val().split("_")[1];
                return false;
            }
        });
    }

    UpdateProgress(true);
    $(message).html("Lütfen Bekleyiniz...");
    AddBasketRelationButtonDisabled(obj);

    var productID = $(productDescriptionID).val();
    var Quantity = $(quantity).val();

    $.ajax({
        url: rndJqueryServiceName + "AddBasket",
        type: "POST",
        contentType: "application/json",
        data: '{"productID":"' + productID + '","quantity":"' + Quantity + '","colorSpecId":"' + colorSpecId + '","firstSpecID":"' + firstSpecID + '"}',
        dataType: "json",
        complete: function () {
            UpdateProgress(false);
        },
        success: function (data) {
            if (data["AddBasketResult"] != "0") {

                GetBasketCount();
                MessageEffectRelation("Ürün Eklendi.", message);
                $(".sizeButtonFirstRelationSelected").filter("img[line=" + $(obj).attr("line") + "]").attr("class", "sizeButtonFirstRelation");
                $(".sizeButtonFirstRelationSelected").filter("button[line=" + $(obj).attr("line") + "]").attr("class", "sizeButtonFirstRelation");
                $(".sizeButtonSecondRelationSelected").filter("button[line=" + $(obj).attr("line") + "]").attr("class", "sizeButtonSecondRelation");
            }
            else {
                $(obj).filter("[line=" + $(this).attr("line") + "]").removeAttr("disabled");
                MessageEffectRelation("Ürün Eklenemedi.", message);
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            if (xhr.status == "500")
                $('#one').jGrowl($(".JsCodeErrorMessage").text());
            else
                $('#one').jGrowl($(".JsConnectionErrorMessage").text());
            $("input[AddBasketRelation=true]").removeAttr("disabled");
            MessageEffectRelation("Ürün Eklenemedi.", message);
        }
    });
}

function GetBasketCount() {
    UpdateProgress(true);
    $.ajax({
        url: rndJqueryServiceName + "GetBasket",
        type: "POST",
        contentType: "application/json",
        dataType: "json",
        complete: function () {
            UpdateProgress(false);
        },
        success: function (data) {
            if (data["GetBasketResult"] != null) {
                $(".lblBasketQuantity").text(data["GetBasketResult"]["ProductQuantity"]);
            }
            else
                $(".lblBasketQuantity").text("0");
        },
        error: function (xhr, ajaxOptions, thrownError) {
            if (xhr.status == "500")
                $('#one').jGrowl($(".JsCodeErrorMessage").text());
            else
                $('#one').jGrowl($(".JsConnectionErrorMessage").text());
        }
    });
}


///Sepetim Sayfası
function ClearBasket_Click() {
    UpdateProgress(true);
    $('#ctl00_MainUpdateProgress').fadeIn();
   
    return false;
}

function SetClassForBasketTable() {
    var i = 0;
    $("tr[id$=trProduct]").each(function (index1) {
        if ($(this).css("display") != "none") {
            var tr_class = (i % 2 == 0) ? "urunbg" : "";
            //alert($(this).css("display"));
            $(this).find("td").each(function (index2) {
                if ($(this).attr("class") != "line")
                    $(this).attr("class", tr_class);
                var button = $(this).find("input[type='submit'] ");
                if (button != null)
                    button.attr("index", i);
            });
            i++;
        }
    });
}

//Sepette seçilen ürün Siler
function DeleteBasketDetail(_clientid) {
    UpdateProgress(true);
    
    return false;
}

function UpdateBasket() {
    UpdateProgress(true);

    var quantity = "";

    $("table[id$=member] tr td .textfield").each(function () {
        if ($(this).attr("value") != null && $(this).attr("value") != "") {
            quantity += $(this).val() + ";";
        }
    });
    quantity = quantity.substr(0, quantity.length - 1);
    quantity += "";
    $.ajax({
        url: rndJqueryServiceName + "UpdateBasket",
        type: "POST",
        contentType: "application/json",
        data: '{"numbers":"' + quantity + '"}',
        dataType: "json",
        success: function (data) {
            if (data["UpdateBasketResult"] != null) {
                var price = data["UpdateBasketResult"];
                GetUpdatedBasketHtml(price);
                GetBasketCount();
            }
            else {
                alert("Güncellemede Hata");
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            if (xhr.status == "500")
                $('#one').jGrowl($(".JsCodeErrorMessage").text());
            else
                $('#one').jGrowl($(".JsConnectionErrorMessage").text());
            UpdateProgress(false);
            MessageEffectToObject($("span[AddToBasketNotSucceed=true]"));
        }
    });
    return false;
}

function CalculateMobileGiftCoupon() {

    UpdateProgress(true);
    var txtDiscountCouponText = $("input[TxtMobileGiftCouponText=true]").val();

    $.ajax({
        url: rndJqueryServiceName + "CalculateDiscountCoupon",
        type: "POST",
        contentType: "application/json",
        data: '{"txtDiscountCouponText":"' + txtDiscountCouponText + '"}',
        dataType: "json",
        complete: function () {
            UpdateProgress(false);
        },
        success: function (data) {

            if (data["CalculateDiscountCouponResult"] != null) {
                //lblDiscountCouponErrorLabelText
                $("span[lblMobileGiftCouponErrorLabelText=true]").html(data["CalculateDiscountCouponResult"]["lblDiscountCouponErrorLabelText"]);

                $("span[id$=TotalDiscount]").html(data["CalculateDiscountCouponResult"]["TotalDiscount"]);
                //TxtDiscountCouponText
                $("span[TxtDiscountCouponText=true]").html(data["CalculateDiscountCouponResult"]["TxtDiscountCouponText"]);

                //lblDiscountCouponErrorLabelVisible
                if (data["CalculateDiscountCouponResult"]["lblDiscountCouponErrorLabelVisible"])
                    $("span[lblMobileGiftCouponErrorLabelText=true]").show();
                else
                    $("span[lblMobileGiftCouponErrorLabelText=true]").hide();

                //lblDiscountCouponErrorLabelValidCodeVisible
                if (data["CalculateDiscountCouponResult"]["lblDiscountCouponErrorLabelValidCodeVisible"])
                    $("span[lblMobileGiftCouponErrorLabelValidCodeVisible=true]").show();
                else
                    $("span[lblMobileGiftCouponErrorLabelValidCodeVisible=true]").hide();

                //pnlPaymentCreditVisible
                if (data["CalculateDiscountCouponResult"]["pnlPaymentCreditVisible"])
                    $("span[pnlPaymentCreditVisible=true]").show();
                else
                    $("span[pnlPaymentCreditVisible=true]").hide();

                //pnlPaymentTransferVisible
                if (data["CalculateDiscountCouponResult"]["pnlPaymentTransferVisible"])
                    $("span[pnlPaymentTransferVisible=true]").show();
                else
                    $("span[pnlPaymentTransferVisible=true]").hide();

                //pnlPhonePaymentVisible
                if (data["CalculateDiscountCouponResult"]["pnlPhonePaymentVisible"])
                    $("span[pnlPhonePaymentVisible=true]").show();
                else
                    $("span[pnlPhonePaymentVisible=true]").hide();

                //trPaymentTypeVisible
                if (data["CalculateDiscountCouponResult"]["trPaymentTypeVisible"])
                    $("span[trPaymentTypeVisible=true]").show();
                else
                    $("span[trPaymentTypeVisible=true]").hide();

                //lblPriceExp1Visible
                if (data["CalculateDiscountCouponResult"]["lblPriceExp1Visible"])
                    $("span[lblPriceExp1Visible=true]").show();
                else
                    $("span[lblPriceExp1Visible=true]").hide();

                //lblPriceExp2Visible
                if (data["CalculateDiscountCouponResult"]["lblPriceExp2Visible"])
                    $("span[lblPriceExp2Visible=true]").show();
                else
                    $("span[lblPriceExp2Visible=true]").hide();

                //lblPriceExp3Visible
                if (data["CalculateDiscountCouponResult"]["lblPriceExp3Visible"])
                    $("span[lblPriceExp3Visible=true]").show();
                else
                    $("span[lblPriceExp3Visible=true]").hide();

                //rdbtnHVChecked
                if (data["CalculateDiscountCouponResult"]["rdbtnHVChecked"])
                    $("span[rdbtnHVChecked=true]").attr("checked");
                else
                    $("span[rdbtnHVChecked=true]").removeAttr("checked");

                //rdbtnKRChecked
                if (data["CalculateDiscountCouponResult"]["rdbtnKRChecked"])
                    $("span[rdbtnKRChecked=true]").attr("checked");
                else
                    $("span[rdbtnKRChecked=true]").removeAttr("checked");

                //rdbtnTlfChecked
                if (data["CalculateDiscountCouponResult"]["rdbtnTlfChecked"])
                    $("span[rdbtnTlfChecked=true]").attr("checked");
                else
                    $("span[rdbtnTlfChecked=true]").removeAttr("checked");

                if (data["CalculateDiscountCouponResult"]["isApproved"])
                    CalculateShownPrice();
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            if (xhr.status == "500")
                $('#one').jGrowl($(".JsCodeErrorMessage").text());
            else
                $('#one').jGrowl($(".JsConnectionErrorMessage").text());
        }

    });
    return false;
}

function CalculateDiscountCoupon() {

    UpdateProgress(true);
    var txtDiscountCouponText = $("input[TxtDiscountCouponText=true]").val();

    $.ajax({
        url: rndJqueryServiceName + "CalculateDiscountCoupon",
        type: "POST",
        contentType: "application/json",
        data: '{"txtDiscountCouponText":"' + txtDiscountCouponText + '"}',
        dataType: "json",
        complete: function () {
            UpdateProgress(false);
        },
        success: function (data) {

            if (data["CalculateDiscountCouponResult"] != null) {
                //lblDiscountCouponErrorLabelText
                $("span[lblDiscountCouponErrorLabelText=true]").html(data["CalculateDiscountCouponResult"]["lblDiscountCouponErrorLabelText"]);

                $("span[id$=TotalDiscount]").html(data["CalculateDiscountCouponResult"]["TotalDiscount"]);
                //TxtDiscountCouponText
                $("span[TxtDiscountCouponText=true]").html(data["CalculateDiscountCouponResult"]["TxtDiscountCouponText"]);

                //lblDiscountCouponErrorLabelVisible
                if (data["CalculateDiscountCouponResult"]["lblDiscountCouponErrorLabelVisible"])
                    $("span[lblDiscountCouponErrorLabelVisible=true]").show();
                else
                    $("span[lblDiscountCouponErrorLabelVisible=true]").hide();

                //lblDiscountCouponErrorLabelValidCodeVisible
                if (data["CalculateDiscountCouponResult"]["lblDiscountCouponErrorLabelValidCodeVisible"])
                    $("span[lblDiscountCouponErrorLabelValidCodeVisible=true]").show();
                else
                    $("span[lblDiscountCouponErrorLabelValidCodeVisible=true]").hide();

                //pnlPaymentCreditVisible
                if (data["CalculateDiscountCouponResult"]["pnlPaymentCreditVisible"])
                    $("span[pnlPaymentCreditVisible=true]").show();
                else
                    $("span[pnlPaymentCreditVisible=true]").hide();

                //pnlPaymentTransferVisible
                if (data["CalculateDiscountCouponResult"]["pnlPaymentTransferVisible"])
                    $("span[pnlPaymentTransferVisible=true]").show();
                else
                    $("span[pnlPaymentTransferVisible=true]").hide();

                //pnlPhonePaymentVisible
                if (data["CalculateDiscountCouponResult"]["pnlPhonePaymentVisible"])
                    $("span[pnlPhonePaymentVisible=true]").show();
                else
                    $("span[pnlPhonePaymentVisible=true]").hide();

                //trPaymentTypeVisible
                if (data["CalculateDiscountCouponResult"]["trPaymentTypeVisible"])
                    $("span[trPaymentTypeVisible=true]").show();
                else
                    $("span[trPaymentTypeVisible=true]").hide();

                //lblPriceExp1Visible
                if (data["CalculateDiscountCouponResult"]["lblPriceExp1Visible"])
                    $("span[lblPriceExp1Visible=true]").show();
                else
                    $("span[lblPriceExp1Visible=true]").hide();

                //lblPriceExp2Visible
                if (data["CalculateDiscountCouponResult"]["lblPriceExp2Visible"])
                    $("span[lblPriceExp2Visible=true]").show();
                else
                    $("span[lblPriceExp2Visible=true]").hide();

                //lblPriceExp3Visible
                if (data["CalculateDiscountCouponResult"]["lblPriceExp3Visible"])
                    $("span[lblPriceExp3Visible=true]").show();
                else
                    $("span[lblPriceExp3Visible=true]").hide();

                //rdbtnHVChecked
                if (data["CalculateDiscountCouponResult"]["rdbtnHVChecked"])
                    $("span[rdbtnHVChecked=true]").attr("checked");
                else
                    $("span[rdbtnHVChecked=true]").removeAttr("checked");

                //rdbtnKRChecked
                if (data["CalculateDiscountCouponResult"]["rdbtnKRChecked"])
                    $("span[rdbtnKRChecked=true]").attr("checked");
                else
                    $("span[rdbtnKRChecked=true]").removeAttr("checked");

                //rdbtnTlfChecked
                if (data["CalculateDiscountCouponResult"]["rdbtnTlfChecked"])
                    $("span[rdbtnTlfChecked=true]").attr("checked");
                else
                    $("span[rdbtnTlfChecked=true]").removeAttr("checked");

                if (data["CalculateDiscountCouponResult"]["isApproved"])
                    CalculateShownPrice();
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            if (xhr.status == "500")
                $('#one').jGrowl($(".JsCodeErrorMessage").text());
            else
                $('#one').jGrowl($(".JsConnectionErrorMessage").text());
        }

    });
    return false;
}


function CalculateShownPrice() {
    // $(".classAdi"),$("#classAdi"),$("label[sertac=true]")
    // $(".classAdi").val() -- input
    // $("label[sertac=true]").text(), $("label[sertac=true]").html()
    // $("select[dropdownlist=true] :selected").val("0")

    UpdateProgress(true);
    var rdbtnHV = ($("#ctl00_ContentPlaceHolder1_rdbtnHV").attr("checked") != null) ? $("#ctl00_ContentPlaceHolder1_rdbtnHV").attr("checked") : false;
    var rdbtnKR = ($("#ctl00_ContentPlaceHolder1_rdbtnKR").attr("checked") != null) ? $("#ctl00_ContentPlaceHolder1_rdbtnKR").attr("checked") : false;
    var cmbCreditCardInstallment = ($("#cmbBankInstallment").val() != null) ? $("#cmbBankInstallment").val() : "";
    var cmbCreditCardBank = $("select[cmbCreditCardBank=true]").val();
    var paymentCardCVCText = $("input[paymentCardCVCText=true]").val();
    var cardNumberBox = $("input[cardNumberBox=true]").val();
    var paymentCardSKTMonthList = $("select[paymentCardSKTMonthList=true]").val();
    var paymentCardSKTYearList = $("select[paymentCardSKTYearList=true]").val();

    $.ajax({
        url: rndJqueryServiceName + "CalculateShownPrice",
        type: "POST",
        contentType: "application/json",
        data: '{"rdbtnHV":"' + rdbtnHV + '","rdbtnKR":"' + rdbtnKR + '","cmbCreditCardInstallment":"' + cmbCreditCardInstallment + '","cmbCreditCardBank":"' + cmbCreditCardBank + '","paymentCardCVCText":"' + paymentCardCVCText + '","cardNumberBox":"' + cardNumberBox + '","paymentCardSKTMonthList":"' + paymentCardSKTMonthList + '","paymentCardSKTYearList":"' + paymentCardSKTYearList + '"}',
        dataType: "json",
        complete: function () {
            UpdateProgress(false);
        },
        success: function (data) {
            if (data["CalculateShownPriceResult"] != null) {

                ///lblDiscountCouponErrorLabelVisible
                if (data["CalculateShownPriceResult"]["lblDiscountCouponErrorLabelVisible"])
                    $("span[lblDiscountCouponErrorLabelVisible=true]").show();
                else
                    $("span[lblDiscountCouponErrorLabelVisible=true]").hide();

                ///lblRemittanceTotalSecondaryVisible
                if (data["CalculateShownPriceResult"]["lblRemittanceTotalSecondaryVisible"])
                    $("span[lblRemittanceTotalSecondaryVisible=true]").show();
                else
                    $("span[lblRemittanceTotalSecondaryVisible=true]").hide();

                ///totalPurchasePriceSecondaryVisible
                if (data["CalculateShownPriceResult"]["totalPurchasePriceSecondaryVisible"])
                    $("span[totalPurchasePriceSecondaryVisible=true]").show();
                else
                    $("span[totalPurchasePriceSecondaryVisible=true]").hide();

                ///totalPurchasePriceTextVisible
                if (data["CalculateShownPriceResult"]["totalPurchasePriceTextVisible"])
                    $("span[totalPurchasePriceTextVisible=true]").show();
                else
                    $("span[totalPurchasePriceTextVisible=true]").hide();

                ///lblRemittanceTotalVisible
                if (data["CalculateShownPriceResult"]["lblRemittanceTotalVisible"])
                    $("span[lblRemittanceTotalVisible=true]").show();
                else
                    $("span[lblRemittanceTotalVisible=true]").hide();

                //totalPurchasePriceText
                $("span[totalPurchasePriceText=true]").html(data["CalculateShownPriceResult"]["totalPurchasePriceText"]);
                //totalPaymentPerMonthText
                $("span[totalPaymentPerMonthText=true]").html(data["CalculateShownPriceResult"]["totalPaymentPerMonthText"]);
                //totalPurchasePriceSecondaryText
                $("span[totalPurchasePriceSecondaryText=true]").html(data["CalculateShownPriceResult"]["totalPurchasePriceSecondaryText"]);
                //creditCardErrorText
                $("span[creditCardErrorText=true]").html(data["CalculateShownPriceResult"]["creditCardErrorText"]);

                //lblDiscountCardText
                $("span[lblDiscountCardText=true]").html(data["CalculateShownPriceResult"]["lblDiscountCardText"]);
                //lblPriceExp1Text
                $("span[lblPriceExp1Text=true]").html(data["CalculateShownPriceResult"]["lblPriceExp1Text"]);
                //lblRemittanceTotalText
                $("span[lblRemittanceTotalText=true]").html(data["CalculateShownPriceResult"]["lblRemittanceTotalText"]);
                //lblRemittanceTotalSecondaryText
                $("span[lblRemittanceTotalSecondaryText=true]").html(data["CalculateShownPriceResult"]["lblRemittanceTotalSecondaryText"]);

                $("span[id$=_TotalPrice]").html(data["CalculateShownPriceResult"]["lblRemittanceTotalSecondaryText"]);
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            if (xhr.status == "500")
                $('#one').jGrowl($(".JsCodeErrorMessage").text());
            else
                $('#one').jGrowl($(".JsConnectionErrorMessage").text());
        }
    });
}

function PaymentTypeVisible() {
    var rdbtnHV = ($("#ctl00_ContentPlaceHolder1_rdbtnHV:radio:checked").attr("checked") != null) ? $("#ctl00_ContentPlaceHolder1_rdbtnHV:radio:checked").attr("checked") : false;
    var rdbtnKR = ($("#ctl00_ContentPlaceHolder1_rdbtnKR:radio:checked").attr("checked") != null) ? $("#ctl00_ContentPlaceHolder1_rdbtnKR:radio:checked").attr("checked") : false;
    var rdbtnTlf = ($("#ctl00_ContentPlaceHolder1_rdbtnTlf:radio:checked").attr("checked") != null) ? $("#ctl00_ContentPlaceHolder1_rdbtnTlf:radio:checked").attr("checked") : false;
    var checkOutPaymentType = "";

    if (rdbtnHV == true) {
        $("#ctl00_ContentPlaceHolder1_pnlPaymentTransfer").show();
        $("#ctl00_ContentPlaceHolder1_pnlPaymentCredit").hide();
        $("#ctl00_ContentPlaceHolder1_pnlPhonePayment").hide();
        $("#ctl00_ContentPlaceHolder1_tdPayment").css("padding-left", "180px");
        checkOutPaymentType = "HV";
    }
    else if (rdbtnKR == true) {
        $("#ctl00_ContentPlaceHolder1_pnlPaymentTransfer").hide();
        $("#ctl00_ContentPlaceHolder1_pnlPaymentCredit").show();
        $("#ctl00_ContentPlaceHolder1_pnlPhonePayment").hide();
        $("#ctl00_ContentPlaceHolder1_tdPayment").css("padding-left", "280px");
        checkOutPaymentType = "KR";
    }
    else if (rdbtnTlf == true) {
        $("#ctl00_ContentPlaceHolder1_pnlPaymentTransfer").hide();
        $("#ctl00_ContentPlaceHolder1_pnlPaymentCredit").hide();
        $("#ctl00_ContentPlaceHolder1_pnlPhonePayment").show();
        $("#ctl00_ContentPlaceHolder1_tdPayment").css("padding-left", "50px");
        checkOutPaymentType = "Phone";
    }

    $.ajax({
        url: rndJqueryServiceName + "SessionAddCheckOutPaymentType",
        type: "POST",
        contentType: "application/json",
        data: '{"checkOutPaymentType":"' + checkOutPaymentType + '"}',
        dataType: "json",
        complete: function () {
            UpdateProgress(false);
        },
        success: function (data) {

        },
        error: function (xhr, ajaxOptions, thrownError) {
            if (xhr.status == "500")
                $('#one').jGrowl($(".JsCodeErrorMessage").text());
            else
                $('#one').jGrowl($(".JsConnectionErrorMessage").text());
        }
    });
}
function Focused(success, beforeRecord, yourEmail) {
    $("#" + success).hide("slow");
    $("#" + beforeRecord).hide("slow");
    $("#" + yourEmail).hide("slow");
}

function SetUniqueRadioButton(nameregex, current) {
    re = new RegExp(nameregex);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio') { if (re.test(elm.name)) { elm.checked = false; } }
    }
    current.checked = true;
}
function ShowHide() {
    if (document.getElementById("trValidator").style.display != "none")
        document.getElementById("trValidator").style.display = "none"
    else
        document.getElementById("trValidator").style.display = "block"
}

//DropDownList lerde child ddl kontrolü
$(document).ready(function () {
    $("[SaleProduct]").hide();
    $("[SaleProduct]").click(function () {
        var lblControlId = $(this).attr("productLbl");
        var clearddlid = $(this).attr("clearddl");
        var lblControl = $("[id$='" + lblControlId + "']");
        var clearddl = $("[id$='" + clearddlid + "']");
        var productDescriptionID = lblControl.attr("PDID");
        var Quantity = "1";
        var colorSpecId = lblControl.attr("FSID");
        var firstSpecID = lblControl.attr("SSID");
        $.ajax({
            url: rndJqueryServiceName + "AddBasket",
            type: "POST",
            contentType: "application/json",
            data: '{"productDescriptionID":"' + productDescriptionID + '","quantity":"' + Quantity + '","colorSpecId":"' + colorSpecId + '","firstSpecID":"' + firstSpecID + '"}',
            dataType: "json",
            success: function (data) {
                $("span[Waiting=true]").hide();
                if (data["AddBasketResult"] != "0") {
                    GetBasket();
                    ProductSpecSelectClear();
                    MessageEffectToObject($("span[AddToBasketSucceed=true]"));
                    $(".sizeButtonSelected").attr("class", "sizeButton");
                    $(".sizeButtonSecondSelected").attr("class", "sizeButtonSecond");
                    $("div[id$=pnlCableSelect]").fadeOut(1500);
                }
                else {
                    $("input[AddBasket=true]").removeAttr("disabled");
                    MessageEffectToObject($("span[AddToBasketNotSucceed=true]"));
                    lblControl.text("Ürün Eklenemedi");
                }


            },
            error: function (xhr, ajaxOptions, thrownError) {
                if (xhr.status == "500")
                    $('#one').jGrowl($(".JsCodeErrorMessage").text());
                else
                    $('#one').jGrowl($(".JsConnectionErrorMessage").text());
                MessageEffectToObject($("span[AddToBasketNotSucceed=true]"));
            }
        });

    });
    $("select[ProductClear]").change(function () { ChangeProductLabel($("select[ProductClear]")); });
    //    $("select[ProductClear]").click(function() { ChangeProductLabel($("select[ProductClear]")); });

    $("select[ddlProduct]").change(function () { ChangeDDLProduct($("select[ddlProduct]")); });
    //    $("select[ddlProduct]").click(function() { ChangeDDLProduct($("select[ddlProduct]")); });

    $.each($("select[ddlChanger]"), function (i) {
        $(this).change(function () { DDLChanger(this); });
        //        $(this).click(function() { DDLChanger(this); });
    });

});

function DDLChanger(ddlMaster) {
    if ($(ddlMaster).attr("ddlChanger") == null || $(ddlMaster).attr("ddlChanger") == "") {
        return;
    }

    var service = rndJqueryServiceName + $(ddlMaster).attr("ddlChanger");
    var methodName = $(ddlMaster).attr("ddlChanger") + "Result";
    var ddlTargetId = $(ddlMaster).attr("target");
    var ddlTarget = $("[id$='" + ddlTargetId + "']");
    var childList = $(ddlMaster).attr("child");
    var ary = null;
    if (childList != null && childList != "") {
        ary = childList.split(",");
    }

    $(ddlTarget.selector + " > option").remove();
    if (ary != null) {
        $.each(ary, function (i) {
            var ddl = $("[id$='" + this + "']");
            $(ddl.selector + " > option").remove();
        });
    }

    var SelectedValue = $(ddlMaster).val();
    if (SelectedValue != null && SelectedValue != "0") {
        $.ajax({
            type: "POST",
            url: service,
            data: '{"deger":"' + SelectedValue + '"}',
            contentType: "application/json; charset=utf-8;",
            dataType: "json",
            success: function (msg) {
                $.each(msg[methodName], function (i) {
                    ddlTarget.append("<option value='" + this.Value + "'>" + this.Text + "</option>");
                });
                if (msg[methodName].length == 1) {
                    DDLChanger(ddlTarget);
                    if (ddlTarget.selector == "[id$='ddlProduct']") {
                        ChangeDDLProduct(ddlTarget);
                    }
                }

                ddlTarget.attr("disabled", "");
                if (ary != null) {
                    $.each(ary, function (i) {
                        var ddl = $("[id$='" + this + "']");
                        ddl.attr("disabled", "");
                    });
                }
            },
            error: function () {
                alert("Hata Oluştu.1");
            }
        });

    }
}
function ChangeProductLabel(ddlProduct) {
    var lblTargetId = $(ddlProduct).attr("ProductClear");
    var lblTarget = $("[id$='" + lblTargetId + "']");
    $(lblTarget).text("....");
    $(lblTarget).attr("PDID", "").removeAttr();
    $(lblTarget).attr("FSID", "").removeAttr();
    $(lblTarget).attr("SSID", "").removeAttr();
    $("[SaleProduct]").fadeOut("slow");

}
function ChangeDDLProduct(ddlProduct) {
    var ddlMaster = $(ddlProduct);
    var service = rndJqueryServiceName + ddlMaster.attr("ddlProduct");
    var value = ddlMaster.val();
    var methodName = $(ddlProduct).attr("ddlProduct") + "Result";
    var lblTargetId = $(ddlProduct).attr("target");
    var lblTarget = $("[id$='" + lblTargetId + "']");
    $(lblTarget).text("....");
    $(lblTarget).attr("PDID", "").removeAttr();
    $(lblTarget).attr("FSID", "").removeAttr();
    $(lblTarget).attr("SSID", "").removeAttr();
    if (value != "0" && value != "") {
        $.ajax({
            type: "POST",
            url: service,
            data: '{"deger":"' + value + '"}',
            contentType: "application/json; charset=utf-8;",
            dataType: "json",
            success: function (msg) {
                var ary = msg[methodName].split("|");

                $(lblTarget).attr("PDID", ary[1]);
                $(lblTarget).attr("FSID", ary[2]);
                $(lblTarget).attr("SSID", ary[3]);
                $(lblTarget).text(ary[0]);
                $("[SaleProduct]").fadeIn("slow");

            }
        });
    }
    else {
        $(lblTarget).text("Ürün Seçilmedi");
        $(lblTarget).attr("PDID", "").removeAttr();
        $(lblTarget).attr("FSID", "").removeAttr();
        $(lblTarget).attr("SSID", "").removeAttr();
        $("[SaleProduct]").fadeOut("slow");

    }

}

////////////////////////////////////////////
//Department Fill
///////////////////////////////////////////
$(document).ready(function () {
    if (jQuery.url.attr("host") == "localhost") {

        if ((jQuery.url.segment(1) == "Departman" || jQuery.url.segment(1) == "Department" || jQuery.url.segment(1) == "Urun" || jQuery.url.segment(1) == "Product") && jQuery.url.segment(jQuery.url.segment() - 2) != null)
            res = GetDepartmant(jQuery.url.segment(jQuery.url.segment() - 2));
    }
    else {
        if ((jQuery.url.segment(0) == "Departman" || jQuery.url.segment(0) == "Department" || jQuery.url.segment(0) == "Urun" || jQuery.url.segment(0) == "Product") && jQuery.url.segment(jQuery.url.segment() - 2) != null)
            res = GetDepartmant(jQuery.url.segment(jQuery.url.segment() - 2));
    }
});

function GetDepartmant(depId) {
    $.ajax({
        url: rndJqueryServiceName + "GetDepartmentByDepId",
        type: "POST",
        contentType: "application/json",
        dataType: "json",
        data: '{"depId":"' + depId + '"}',
        success: function (data) {
            $("#menu_head_child").dataBind("<DepartmentHeader>k__BackingField", data["GetDepartmentByDepIdResult"], ">");

            $("#menu_repeat_child").dataBind("DepartmentList", data["GetDepartmentByDepIdResult"]["<DepartmentChild>k__BackingField"], "");
            $("#menu_repeat_parent").dataBind("DepartmentList", data["GetDepartmentByDepIdResult"]["<DepartmentParent>k__BackingField"], "");
            $("#menu_repeat_master").dataBind("DepartmentList", data["GetDepartmentByDepIdResult"]["<DepartmentMaster>k__BackingField"], "");

            pName = ' ';
            if (data["GetDepartmentByDepIdResult"]["<DepartmentParent>k__BackingField"] != null)
                pName = data["GetDepartmentByDepIdResult"]["<DepartmentParent>k__BackingField"].Name;
            $("#menu_head_parent").text(pName);
            

            mName = ' ';
            if (data["GetDepartmentByDepIdResult"]["<DepartmentMaster>k__BackingField"] != null)            
                mName = data["GetDepartmentByDepIdResult"]["<DepartmentMaster>k__BackingField"].Name;
            $("#menu_head_master").text(mName);

           
            
        },
        error: function (xhr, ajaxOptions, thrownError) {

        }
    });
}




////////////////////////////////////////////////////
//HtmlDataEngine
//Version:1.0
//Sertaç Yıldırım (07.07.2010)
////////////////////////////////////////////////////
jQuery.fn.dataBind = function (key, jsonData, separator) {
    Bind(key, $(this), jsonData, separator);
}

function Bind(key, obj, data, separator) {
    try {

        var htmlData = $(obj).html();
        var htmlDataCache = $(obj).clone();
        htmlDataCache.html("");
        var cloneHmtlData = $(obj).clone();
        var firstHtmlData = $(obj).clone();

        $(obj).children().attr("base","true");
        $(obj).children().hide();
        
        if ($(obj).html() == null || data == null || data[key] == null) { return false; }

        $.each(data[key], function (ke, value) {
            //row
            index = 1;
            cloneHmtlData = firstHtmlData.clone();
            $.each(value, function (ke1, value1) {
                //column

                //relation obje
                if (typeof (value1) == "object") {
                    $.each(value1, function (ke11, value11) {
                        //relation object row
                        var subcache = $(firstHtmlData).find('div[subrepeat=' + ke1 + ']').html();
                        if (subcache != null) {
                            $.each(value11, function (ke111, value111) {
                                //relation object column
                                var oldValue = new RegExp("\\[" + ke111 + "\\]", "g");
                                subcache = subcache.replace(oldValue, value111);
                            });
                            $(cloneHmtlData).find('div[subrepeat=' + ke1 + ']').children().remove();
                            $(cloneHmtlData).find('div[subrepeat=' + ke1 + ']').append(subcache);
                        }
                    });
                }
                //column
                else {
                    var oldValue = new RegExp("\\[" + ke1 + "\\]", "g");
                    var rowIndexValue = new RegExp("\\[rowIndex\\]", "g");
                    cloneHmtlData.html(cloneHmtlData.html().replace(oldValue, value1).replace(rowIndexValue, ke + 1));
                }
                index++;
            });

            //binded object 
            if (ke == 0) { }
            if (ke < data[key].length - 1 && data[key].length > 1)
                $(htmlDataCache).append($(cloneHmtlData).html() + separator);
            else
                $(htmlDataCache).append($(cloneHmtlData).html());
        });
        $(obj).html($(htmlDataCache).html());
    } catch (e) {
        jsLog(e);
    }
}

function jsLog(message) {
    try {
        console.log("%s: %o", message, this);

    } catch (e) {

    }
}
