﻿Array.prototype.contains = function(element) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == element) {
            return true;
        }
    }
    return false;
}

function clock(h, m, s) {
    var runTime = new Date();
    var hours = h;
    var minutes = m;
    var seconds = s;
    var shours = h;
    var sminutes = m;
    var sseconds = s;

    if (shours == 0) { shours = "0"; }
    if (sminutes <= 9) { sminutes = "0" + sminutes; }
    if (sseconds <= 9) { sseconds = "0" + sseconds; }
    if (shours <= 9) { shours = "0" + shours; }

    movingtime = "" + shours + ":" + sminutes + ":" + sseconds + "";
    document.getElementById('clock').innerHTML = movingtime;

    if (seconds <= 58) {
        seconds = seconds + 1;
    } else {
        seconds = 0;
        minutes = minutes + 1;
    }

    if (minutes <= 59) {
    } else {
        hours = hours + 1;
    }

    if (hours <= 23) {
        if (minutes == 60) {
            minutes = 0;
        }
    } else if (hours == 24) {
        hours = 0;
        minutes = 0;
    }

    setTimeout("clock(" + hours + "," + minutes + "," + seconds + ")", 1000);
}

function closeopen(ID) {
    var part2 = document.getElementById(ID);
    if (part2.style.display == 'none') {
        h = $('#' + ID).height();
        $('#' + ID).height(1);
        $("#" + ID).show();
        $("#" + ID).animate({ height: h }, 1000);
    } else {
        h = $('#' + ID).height();
        $('#' + ID).animate({ height: '1px' }, 1000,
			    function() {
			        $("#" + ID).hide();
			        $("#" + ID).height(h);
			    }
			    )
    }
}

function findPos(obj) {
    var scrollTop = document.body.scrollTop;

    if (scrollTop == 0) {
        if (window.pageYOffset)
            scrollTop = window.pageYOffset;
        else
            scrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }

    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }

    curtop = curtop - scrollTop;
    return [curleft, curtop];
}

function disableWithAjax(id) {
    var pos = findPos(document.getElementById(id));

    document.getElementById('disablingDiv').style.top = pos[1] + "px";
    document.getElementById('disablingDiv').style.left = pos[0] + "px";
    document.getElementById('disablingDiv').divToHide = id;
    $('#disablingDiv').height($('#' + id).height());
    $('#disablingDiv').width($('#' + id).width());

    $('#disablingDiv').show();
}

function showWithAjax() {
    $('#disablingDiv').hide();
}

function _utf8_encode(string) {
    var utftext = "";
    if (string != null) {
        string = string.replace(/\r\n/g, "\n");

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }
    }
    else {
        utftext = "";
    }

    return utftext;
}

function LoadCoupon() {
    document.getElementById("couponfrm").src = "/IddaaKupon.aspx?ViewType=CouponSystem";
}

function disableCoupon(id) {

}

function enableCoupon() {

}


function AddCoupon(code, integrationcode, gametypeid, bettypeid, tdcode, livescore, which) {
    if (document.getElementById(tdcode) != undefined) {
        if (document.getElementById(tdcode).className.indexOf("Selected") > -1) {
            DeleteCoupon(code, gametypeid, integrationcode, tdcode, which);
            return;
        }
    }

    $.ajax({
        type: "POST",
        url: "CouponFunctions.aspx/Add",
        data: "{code: '" + code + "', gametypeid: " + gametypeid + ", integrationcode: '" + integrationcode + "' }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            retval = msg.d;
            document.getElementById("couponfrm").src = "/IddaaKupon.aspx?ViewType=CouponSystem";

            if (retval.Status == 0) {
                if (livescore == undefined || livescore == "FullSize" || livescore == "MainPage") {
                    if (tdcode != undefined) {
                        if (retval.FinalDouble) {
                            if (which != undefined) {

                                id = document.getElementById(retval.FinalDoubleId + "_PopularEvent")
                                if (id != undefined) {
                                    id.className = id.className.replace("Selected", "");
                                }

                                id = document.getElementById(retval.FinalDoubleId + "_LastEvents")
                                if (id != undefined) {
                                    id.className = id.className.replace("Selected", "");
                                }
                            }
                            else if (document.getElementById(tdcode).style.width == "52px") {
                                document.getElementById(retval.FinalDoubleId).className = "tdBulten";
                            }
                            else {
                                document.getElementById(retval.FinalDoubleId).className = "tdBultenFullSize";
                            }

                            id = document.getElementById(retval.FinalDoubleId + "_Detail")

                            if (id != undefined) {
                                id.className = id.className.replace("Selected", "");

                            }
                        }

                        if (document.getElementById(tdcode) != null) {
                            if (which != undefined) {
                                tdcode_ = tdcode.replace("_" + which, "");

                                id = document.getElementById(tdcode_ + "_PopularEvent")
                                if (id != undefined) {
                                    id.className = id.className + "Selected";
                                    //id.style.backgroundColor = "";
                                }

                                id = document.getElementById(tdcode_ + "_LastEvents")
                                if (id != undefined) {
                                    id.className = id.className + "Selected";
                                    //id.style.backgroundColor = "";
                                }
                            }
                            else if (document.getElementById(tdcode).style.width == "52px") {
                                document.getElementById(tdcode).className = "tdBultenSelected";
                                //if (document.getElementById(tdcode).style.backgroundColor != "#ffcc66") {
                                    document.getElementById(tdcode).style.backgroundColor = "";
                                //}
                            }
                            else {
                                document.getElementById(tdcode).className = "tdBultenFullSizeSelected";
                                //if (document.getElementById(tdcode).style.backgroundColor != "#ffcc66") {
                                    document.getElementById(tdcode).style.backgroundColor = "";
                                //}
                            }
                        }
                    }
                }

                // MisliBar Choices
                refreshChoices();
                showInfoBar("add");
            }
            else {
                if (retval.Status == 5) {
                    location.reload();
                    return;
                }

                modalWarning(retval.ErrorMessage);
            }
        },
        error: function(xmlHttpRequest, status, err) {
            modalWarning('Oran Kupona Eklenemedi.');
        }
    });
}

function AddSpecialCoupon(code, integrationcode, gametypeid, bettypeid, tdcode, livescore) {
    if (document.getElementById(tdcode) != undefined)
    {
        if (document.getElementById(tdcode).className == "tdBultenSelected") {
            DeleteCoupon(code, gametypeid, integrationcode, tdcode);
            return;
        }
    }

    $.ajax({
        type: "POST",
        url: "CouponFunctions.aspx/AddSpecial",
        data: "{code: '" + code + "', gametypeid: " + gametypeid + ", integrationcode: '" + integrationcode + "' }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            retval = msg.d;
            document.getElementById("couponfrm").src = "/IddaaKupon.aspx?ViewType=CouponSystem";

            if (retval.Status == 0) {
                if (livescore == undefined || livescore == "FullSize") {
                    if (tdcode != undefined) {
                        if (retval.FinalDouble) {
                            if (document.getElementById(retval.FinalDoubleId) != null) {
                                document.getElementById(retval.FinalDoubleId).className = "tdBulten";
                            }
                        }

                        if (document.getElementById(tdcode) != null) {
                            document.getElementById(tdcode).className = "tdBultenSelected";
                        }
                    }
                }

                // MisliBar Choices
                refreshChoices();
                showInfoBar("add");
            }
            else {
                if (retval.Status == 5) {
                    location.reload();
                    return;
                }

                modalWarning(retval.ErrorMessage);
            }
        },
        error: function(xmlHttpRequest, status, err) {
            modalWarning('Oran Kupona Eklenemedi.');
        }
    });
}

function AddSpecialCouponLive(betid, code, integrationcode, gametypeid, bettypeid, tdcode, redirect) {
//    if (document.getElementById(tdcode) != undefined) {
//        if (document.getElementById(tdcode).className == "tdBultenSelected") {
//            DeleteCoupon(code, gametypeid, integrationcode, tdcode);
//            return;
//        }
//    }

    $.ajax({
        type: "POST",
        url: "CouponFunctions.aspx/AddSpecialLive",
        data: "{betid: " + betid + ", code: '" + code + "', gametypeid: " + gametypeid + ", integrationcode: '" + integrationcode + "' }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            retval = msg.d;
            if (redirect == undefined) {
                document.getElementById("couponfrm").src = "/IddaaKupon.aspx?ViewType=CouponSystem";
            }

            if (retval.Status == 0) {
                if (redirect != undefined) {
                    window.location = "CanliIddaa.aspx?BetId=" + betid;
                }
                else {
                    // MisliBar Choices
                    refreshChoices();
                    showInfoBar("add");
                }

                //                if (tdcode != undefined) {
                //                    if (document.getElementById(tdcode) != null) {
                //                        document.getElementById(tdcode).className = "tdBultenSelected";
                //                    }
                //                }

            }
            else {
                if (retval.Status == 5) {
                    location.reload();
                    return;
                }

                //modalWarning(retval.ErrorMessage);
                document.getElementById("couponfrm").src = "/IddaaKupon.aspx?ViewType=CouponCalculate&Status=2&ErrorMessage=" + escape(_utf8_encode(retval.ErrorMessage)) + "&ErrorCode=" + escape(_utf8_encode(retval.ErrorCode));
            }
        },
        error: function(xmlHttpRequest, status, err) {
            modalWarning('Oran Kupona Eklenemedi.');
        }
    });
}

function GetCoupon() {
    document.getElementById("couponfrm").src = "/IddaaKupon.aspx?ViewType=CouponSystem";
}

function DeleteCoupon(code, gametypeid, integrationcode, tdcode, which) {
    $.ajax({
        type: "POST",
        url: "CouponFunctions.aspx/Delete",
        data: "{code: '" + code + "', gametypeid: " + gametypeid + ", integrationcode: '" + integrationcode + "' }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            retval = msg.d;
            if (retval.Status == 5) {
                location.reload();
                return;
            }

            var cpnfrm = document.getElementById("couponfrm");
            if (cpnfrm)
                cpnfrm.src = "/IddaaKupon.aspx?ViewType=CouponSystem";

            if (tdcode != undefined) {

                id = document.getElementById(tdcode + "_PopularEvent")
                if (id != undefined) {
                    id.className = id.className.replace("Selected", "");
                }

                id = document.getElementById(tdcode + "_LastEvents")
                if (id != undefined) {
                    id.className = id.className.replace("Selected", "");
                }

                id = document.getElementById(tdcode + "_Detail")
                //alert(tdcode + " - " + id + " (TDelete)")
                if (id != undefined) {
                    id.className = id.className.replace("Selected", "");
                    //document.getElementById(tdcode).className = document.getElementById(tdcode).className.replace("Selected", "");
                }

                //}else 
                if (document.getElementById(tdcode) != null) {
                    document.getElementById(tdcode).className = document.getElementById(tdcode).className.replace("Selected", "");
                }
                
                if (document.getElementById("isIddaaListesi") != undefined) {
                    OpenDeleteControl(code, integrationcode, gametypeid);
                }
            }

            // MisliBar Choices
            refreshChoices();
            showInfoBar("delete");
        },
        error: function(xmlHttpRequest, status, err) {
            modalWarning('Oran Silinemedi.');
        }
    });
}

function DeleteAllCoupon() {
    $.ajax({
        type: "POST",
        url: "CouponFunctions.aspx/DeleteAll",
        data: "{ }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            retval = msg.d;
            if (retval.Status == 5) {
                location.reload();
                return;
            }
            document.getElementById("couponfrm").src = "/IddaaKupon.aspx?ViewType=CouponSystem";

            var obj = $(".tdBultenSelected");
            obj.removeClass("tdBultenSelected");
            obj.addClass("tdBulten");

            var objnew = $(".tdBultenSelected_yeni");
            objnew.removeClass("tdBultenSelected_yeni");
            objnew.addClass("tdBulten");
            
            var objFullSize = $(".tdBultenFullSizeSelected");
            objFullSize.removeClass("tdBultenFullSizeSelected");
            objFullSize.addClass("tdBultenFullSize");

            var objFullSize = $(".tdRightCokSatanlar1MainSelected");
            objFullSize.removeClass("tdRightCokSatanlar1MainSelected");
            objFullSize.addClass("tdRightCokSatanlar1Main");

            var objFullSize = $(".tdRightCokSatanlar2MainSelected");
            objFullSize.removeClass("tdRightCokSatanlar2MainSelected");
            objFullSize.addClass("tdRightCokSatanlar2Main");

            var objFullSize = $(".tdRightCokSatanlarEnYuksekMainSelected");
            objFullSize.removeClass("tdRightCokSatanlarEnYuksekMainSelected");
            objFullSize.addClass("tdRightCokSatanlarEnYuksekMain");

            // MisliBar Choices
            refreshChoices();
            showInfoBar("delete");
        },
        error: function(xmlHttpRequest, status, err) {
            modalWarning('Oranlar Silinemedi.');
        }
    });
}

function ChangeTypeCoupon(typid) {
    $.ajax({
        type: "POST",
        url: "CouponFunctions.aspx/ChangeType",
        data: "{ typeid: " + typid + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            retval = msg.d;
            if (retval.Status == 5) {
                location.reload();
                return;
            }
            document.getElementById("couponfrm").src = "/IddaaKupon.aspx?ViewType=CouponSystem";
        },
        error: function(xmlHttpRequest, status, err) {
            modalWarning('Tip Değiştirilemedi.');
        }
    });
}

function ToogleBanko(code, gametypeid, integrationcode) {
    $.ajax({
        type: "POST",
        url: "CouponFunctions.aspx/ToogleBanko",
        data: "{code: '" + code + "', gametypeid: " + gametypeid + ", integrationcode: '" + integrationcode + "' }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            retval = msg.d;
            if (retval.Status == 5) {
                location.reload();
                return;
            }

            document.getElementById("couponfrm").src = "/IddaaKupon.aspx?ViewType=CouponSystem";
        },
        error: function(xmlHttpRequest, status, err) {
            enableCoupon('dCoupon');
            modalWarning('Banko Yapılamadı.');
        }
    });
}

function CalculateCoupon(coupontype, system, multiply, gamecolumns, maxodd, multiplecoupon) {
    $.ajax({
        type: "POST",
        url: "CouponFunctions.aspx/CalculateCoupon",
        data: "{coupontype: " + coupontype + ", system: '" + system + "', multiply: " + multiply + ", gamecolumns: " + gamecolumns + ", maxodd: " + maxodd + ", multiplecoupon: " + multiplecoupon + " }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            retval = msg.d;

            if (retval.Status == 5) {
                location.reload();
                return;
            }

            document.getElementById("couponfrm").src = "/IddaaKupon.aspx?ViewType=CouponCalculate&Status=" + retval.Status + "&ErrorMessage=" + escape(_utf8_encode(retval.ErrorMessage)) + "&ErrorCode=" + escape(_utf8_encode(retval.ErrorCode));
        },
        error: function(xmlHttpRequest, status, err) {
            modalWarning('Kupon Hesaplanamadı.');
        }
    });
}

function SaveCoupon(save, bonus) {
    scroll(0, 0);
    $.ajax({
        type: "POST",
        url: "CouponFunctions.aspx/SaveCoupon",
        data: "{savecoupon: " + save + ", bonus : " + bonus + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            retval = msg.d;
            if (retval.Status == 5) {
                location.reload();
                return;
            }

            document.getElementById("couponfrm").src = "/IddaaKupon.aspx?ViewType=CouponSave&Status=" + retval.Status + "&SaveCoupon=" + retval.SaveCoupon + "&ErrorMessage=" + escape(_utf8_encode(retval.ErrorMessage)) + "&ErrorCode=" + escape(_utf8_encode(retval.ErrorCode)) + "&MultipleCoupon=" + retval.MultipleCoupon;
            if (save == 0) {
                var obj = $(".tdBultenSelected");
                obj.removeClass("tdBultenSelected");
                obj.addClass("tdBulten");

                var objFullSize = $(".tdBultenFullSizeSelected");
                objFullSize.removeClass("tdBultenFullSizeSelected");
                objFullSize.addClass("tdBultenFullSize");
            }
        },
        error: function(xmlHttpRequest, status, err) {
            modalWarning('Kupon Saklanamadı.');
        }
    });
}

function AddPredefinedCoupon(couponid) {
    var oIframe = document.getElementById('couponfrm');
    var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
    if (oDoc.document) oDoc = oDoc.document;

    if (oDoc.getElementById("couponBetCount") != undefined) {
        if (oDoc.getElementById("couponBetCount").value != "0") {
            if (!confirm('Kuponunuzdaki Etkinlikler Silinecek Emin Misiniz?')) {
                return;
            }
        }
    }

    $.ajax({
        type: "POST",
        url: "CouponFunctions.aspx/AddPredefinedCoupon",
        data: "{couponid: " + couponid + " }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            retval = msg.d;
            if (retval.Status == 5) {
                location.reload();
                return;
            }

            document.getElementById("couponfrm").src = "/IddaaKupon.aspx?ViewType=CouponSystem";

            var obj = $(".tdBultenSelected");
            obj.removeClass("tdBultenSelected");
            obj.addClass("tdBulten");

            var objFullSize = $(".tdBultenFullSizeSelected");
            objFullSize.removeClass("tdBultenFullSizeSelected");
            objFullSize.addClass("tdBultenFullSize");

            // MisliBar Choices
            refreshChoices();
            showInfoBar("add");
        },
        error: function(xmlHttpRequest, status, err) {
            enableCoupon('dCoupon');
            modalWarning('Hazır Kupon Eklenemedi.');
        }
    });
}

function AddCouponNoteToMyCoupon(couponnoteid, memberid) {
    var oIframe = document.getElementById('couponfrm');
    var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
    if (oDoc.document) oDoc = oDoc.document;

    if (oDoc.getElementById("couponBetCount") != undefined) {
        if (oDoc.getElementById("couponBetCount").value != "0") {
            if (!confirm('Kuponunuzdaki Etkinlikler Silinecek Emin Misiniz?')) {
                return;
            }
        }
    }

    $.ajax({
        type: "POST",
        url: "CouponFunctions.aspx/AddCouponNoteToMyCoupon",
        data: "{couponnoteid : " + couponnoteid + ", memberid : " + memberid + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            retval = msg.d;
            if (retval.Status == 5) {
                location.reload();
                return;
            }

            document.getElementById("couponfrm").src = "/IddaaKupon.aspx?ViewType=CouponSystem";

            var obj = $(".tdBultenSelected");
            obj.removeClass("tdBultenSelected");
            obj.addClass("tdBulten");

            var objFullSize = $(".tdBultenFullSizeSelected");
            objFullSize.removeClass("tdBultenFullSizeSelected");
            objFullSize.addClass("tdBultenFullSize");

            // MisliBar Choices
            refreshChoices();
            showInfoBar("add");
        },
        error: function(xmlHttpRequest, status, err) {
            enableCoupon('dCoupon');
            modalWarning('Kupon Sisteme Eklenemedi.');
        }
    });
}

function reSize() {
    //    if (document.getElementById("couponfrm") != undefined) {
    //        var oBody = document.getElementById("couponfrm").document.body;
    //        var oFrame = document.getElementById("couponfrm");

    //        oFrame.style.height = oBody.scrollHeight + (oBody.offsetHeight - oBody.clientHeight);
    //    }
}


var CurrentColumnCount = 0;
var tjkOnLoad = false;
var tjkFirstRequest = true;
var isTjkCouponEmpty = true;

function setTJKCouponInfos(choices, bettype, columnmultiply, multiply) {

    var tjkChoicesBar = $('#tjk-choices-bar-container');
    var tjkNoRecord = $('#tjkNoRecord');
    var spnTJKGameType = $('#spnTJKGameType');
    var spnTJKHorseCount = $('#spnTJKHorseCount');
    var tjkNoRecordContainer = $('#ctl00_misliBar1_mbTjkChoices_pnlTJKNoRecord');
    var tjkRecordContainer = $('#ctl00_misliBar1_mbTjkChoices_pnlTJKRecord');

    var columnCount = 0;
    if (choices != "") {
        var strChoices = choices.split('|');
        var length = strChoices.length;
        for (var i = 0; i < length; i++) {
            if (strChoices[i] != "") {
                var strHorses = strChoices[i].split(',');
                columnCount += strHorses.length;
            }
        }

        if (tjkFirstRequest) {
            if (tjkOnLoad) {
                CurrentColumnCount = columnCount;
                tjkFirstRequest = false;
            }
        }
        if (CurrentColumnCount > 0 && columnCount < CurrentColumnCount) {
            showInfoBar("delete")
        }
        else if (columnCount > CurrentColumnCount) {
            showInfoBar("add");
        }
        CurrentColumnCount = columnCount;

        if (columnCount > 0) {
            tjkNoRecordContainer.css("display", "none");
            tjkNoRecord.css("display", "none");
            tjkRecordContainer.css("display", "");
            spnTJKGameType.html(bettype);

            if (choices.indexOf('S') != -1) {
                spnTJKHorseCount.html("Miktar : " + multiply);
            }
            else {

                spnTJKHorseCount.html("Kolon : " + columnmultiply);
            }
            isTjkCouponEmpty = false;
        }
        else {
            isTjkCouponEmpty = true;
            tjkNoRecordContainer.css("display", "");
            tjkNoRecord.css("display", "");
            tjkRecordContainer.css("display", "none");
            tjkChoicesBar.css("display", "none");
            spnTJKGameType.html("");
            spnTJKHorseCount.html("");
        }
    }
    else {
        isTjkCouponEmpty = true;
        tjkNoRecordContainer.css("display", "");
        tjkNoRecord.css("display", "");
        tjkRecordContainer.css("display", "none");
        tjkChoicesBar.css("display", "none");
        spnTJKGameType.html("");
        spnTJKHorseCount.html("");
    }
}

function getTJKCouponChoiceDetails() {
    var hdnTjkCouponChoices = document.getElementById("hdn_tjkcouponchoices");
    if (hdnTjkCouponChoices) {
        GetTjkCouponChoicesFromPage();
    }
    else {
        var tjkCouponChoices = $('#tjk-coupon-choices');
        var tjkCouponChoicesLoading = $('#tjk-coupon-choices-loading');

        $.ajax({
            type: "POST",
            url: "/Default.aspx/GetCouponChoicesFromSession",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                retval = msg.d;
                if (retval != "") {
                    tjkCouponChoices.html(retval);
                    tjkCouponChoicesLoading.hide();
                }
            },
            error: function(xmlHttpRequest, status, err) {

            }
        });
    }
}

function showTJKCouponChoices() {
    var tjkChoicesBar = $('#tjk-choices-bar-container');
    isVisible = tjkChoicesBar.css("display");
    if (isVisible != "none") {
        tjkChoicesBar.css("display", "none");
    }
    else {
        tjkChoicesBar.css("display", "");
        getTJKCouponChoiceDetails();
    }
}

function closeTJKCouponChoices() {
    var tjkChoicesBar = $('#tjk-choices-bar-container');
    tjkChoicesBar.css("display", "none");
}

function goToTjkCoupon() {
    var hdnTjkCouponChoices = document.getElementById("hdn_tjkcouponchoices");
    if (!hdnTjkCouponChoices) {
        window.location.href = "/tjk-at-yarisi-bahis";
    }
}



function showChoices() {

    choicesBar = $('#choices-bar-container');
    aCoupon = $('#a-coupon');
    isVisible = choicesBar.css("display");

    if (isVisible != "none") {
        choicesBar.css("display", "none");
        aCoupon.attr("class", "a-nonselected");
    }
    else {
        choicesBar.css("display", "");
        aCoupon.attr("class", "a-selected");
        getChoiceDetails();
    }
}

function closeChoices() {

    var hdnIsStatistic = document.getElementById("ctl00_hdnIsStatistic");
    var couponfrm = document.getElementById("couponfrm");

    if (!couponfrm && hdnIsStatistic && hdnIsStatistic.value == "1") {
        window.location.href = "/iddaa-maclari";
    }
    else {

        window.location.href = '#couponfrm';
        choicesBar = $('#choices-bar-container');
        aCoupon = $('#a-coupon');
        choicesBar.css("display", "none");
        aCoupon.attr("class", "a-nonselected");
    }
}

function getChoices() {
    choiceInfo = $('#bar-coupon');
    choicesBar = $('#choices-bar-container');
    isVisible = choicesBar.css("display");

    $.ajax({
        type: "POST",
        url: "CouponFunctions.aspx/GetChoices",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            retval = msg.d;
            if (retval != "") {
                choiceInfo.html(retval);

                aCoupon = $('#a-coupon');
                if (isVisible != "none") {
                    aCoupon.attr("class", "a-selected");
                }

                var noRecord = document.getElementById("ctl00_noRecord");
                if (!noRecord)
                    noRecord = document.getElementById("ctl00_misliBar1_mbChoices_noRecord");

                if (noRecord && noRecord.style.display == "") {

                    var dvTJKBarContainer = document.getElementById("ctl00_misliBar1_mbTjkChoices_dvTJKBarContainer");
                    if (dvTJKBarContainer != undefined) {
                        $('#ctl00_misliBar1_mbTjkChoices_dvTJKBarContainer').css("display", "");

                        var iddaaBarContainer = document.getElementById("ctl00_dvIddaaBarContainer");
                        if (!iddaaBarContainer)
                            iddaaBarContainer = document.getElementById("ctl00_misliBar1_mbChoices_dvIddaaBarContainer");

                        if (iddaaBarContainer)
                            iddaaBarContainer.style.display = "none";
                    }
                }
                else {
                    var dvTJKBarContainer = $('#ctl00_misliBar1_mbTjkChoices_dvTJKBarContainer');
                    var dvIddaaBarContainer = $('#ctl00_misliBar1_mbChoices_dvIddaaBarContainer');
                    var tjkChoicesDetails = $('#tjk-choices-bar-container');

                    if (tjkChoicesDetails && tjkChoicesDetails.css("display"))
                        tjkChoicesDetails.css("display", "none");

                    if (dvTJKBarContainer && dvTJKBarContainer.css("display"))
                        dvTJKBarContainer.css("display", "none");

                    if (dvIddaaBarContainer && !dvIddaaBarContainer.css("display")) {
                        dvIddaaBarContainer.css("display", "");
                    }
                }
            }
        },
        error: function(xmlHttpRequest, status, err) {

        }
    });
}

function getChoiceDetails() {
    choiceDetails = $('#choice-details');
    dLoading = $('#choices-loading');

    $.ajax({
        type: "POST",
        url: "CouponFunctions.aspx/GetChoiceDetails",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            retval = msg.d;
            if (retval != "") {
                choiceDetails.html(retval);
                dLoading.hide();
            }
        },
        error: function(xmlHttpRequest, status, err) {

        }
    });
}

function refreshChoices() {
    getChoices();
    isVisible = $('#choices-bar-container').css("display");
    if (isVisible != "none") {
        getChoiceDetails();
    }
}

function showDeleteButton(id, type) {
    closeButton = $('#close-it-' + id);
    if (type == "1") { closeButton.show(); }
    else { closeButton.hide(); }
}

function showInfoBar(type) {
    infoBar = $('#info-bar-container');
    if (type == "add") {
        infoBar.css("background-color", "#66CC33");
        infoBar.html("Kupona Eklendi");
    }
    else {
        infoBar.css("background-color", "#A53333");
        infoBar.html("Kupondan Silindi");
    }
    infoBar.fadeIn();
    setTimeout("infoBar.fadeOut();", 2000);
}

function setUserInfo(value) {
    sUserInfo = $('#spnUserInfo');
    sUserInfo.html(value);
}

function GetNewCommunityCoupons(pageno) {
    if (pageno != -1) {
        $.ajax({
            type: "POST",
            url: "/Default.aspx/GetNewCommunityCoupons",
            data: "{pageno : " + pageno + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                $('#communityCoupons').html(msg.d);
            },
            error: function(xmlHttpRequest, status, err) {

            }
        });
    }
}


