﻿function MM_reloadPage(init) {  //reloads the window if Nav4 resized
    if (init == true) with (navigator) {
        if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
            document.MM_pgW = innerWidth; document.MM_pgH = innerHeight; onresize = MM_reloadPage;
        }
    }
    else if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function reSize() {
    try {
        var oBody = document.body;
        var height = oBody.scrollHeight;
        parent.document.getElementById("ifrm").setAttribute("height", height);
    }
    catch (e) {
        window.status = 'Error: ' + e.number + '; ' + e.description;
    }
}

function enable_next(id) {
    prev = parseInt(id) - 1;

    if ($('#ddl_' + id).val() == "0") {
        for (var i = id; i < count; i++) {
            $('#ddl_' + id).attr("disabled", true);
        }
    }

    if ($('#ddl_' + prev).val() != "0") {

        $('#ddl_' + id).removeAttr("disabled");
    }
    else {
        $('#ddl_' + id).attr("disabled", true);

        for (var j = id; j < count; j++) {
            $('#ddl_' + j).val("0");
            $('#ddl_' + j).attr("disabled", true);
        }
    }
}

function fill_selects() {
    count = parseInt($('#HorseCount').val());
    count = count + 1;

    var x = 0;

    $('select[name="select_at"]').each(function() {
        $(this).append($("<option></option>").attr("value", (0)).text("--"));

        for (var i = 1; i < count; i++) {
            $(this).append($("<option></option>").attr("value", (i)).text(i));
        }

        if (secilenler[x] != "" && secilenler[x] != null) {
            $(this).removeAttr("disabled");
            $(this).val(secilenler[x]);
            x++;
        }
    });

    refresh_selects();
    enable_next((parseInt(x) + 1));
}

function katlari(type) {
    katlar = $('#hdnMultiple').val();
    dontkatlar = $('#hdnDontMultiple').val();
    gtype = $('#hdn_gametype').val();
    cbox = document.getElementById("cb_multiple")

    var hdnGameTypeMaster = document.getElementById("ctl00_center_CouponMaster_hdnGameType");
    if (hdnGameTypeMaster == null)
        hdnGameTypeMaster = document.getElementById("ctl00_hdnGameType");
    if (cbox.checked) {
        $('#hdn_gametype').val(katlar);
        if (hdnGameTypeMaster) {
            switch (gtype) {
                case "8":
                    hdnGameTypeMaster.value = "Sıralı İkili Bahis Komple";
                    break;
                case "11":
                    hdnGameTypeMaster.value = "Üçlü Bahis Komple";
                    break;
                case "12":
                    hdnGameTypeMaster.value = "Üçlü Bahis Komp. (Vrg.)";
                    break;
                case "13":
                    hdnGameTypeMaster.value = "Tabela Bahis Komple";
                    break;
                case "14":
                    hdnGameTypeMaster.value = "Tabela Bahis Komp. (Vrg.)";
                    break;
                case "9":
                    hdnGameTypeMaster.value = "Sıralı İkili Komp. (Vrg.)"
                    break;
                default:
                    break;
            }
        }
    }
    else {
        $('#hdn_gametype').val(dontkatlar);
        if (hdnGameTypeMaster) {
            switch (gtype) {
                case "20":
                    hdnGameTypeMaster.value = "Üçlü Bahis";
                    break;
                case "21":
                    hdnGameTypeMaster.value = "Tabela Bahis";
                    break;
                case "22":
                    hdnGameTypeMaster.value = "Sıralı İkili Bahis";
                    break;
                case "23":
                    hdnGameTypeMaster.value = "Üçlü Bahis Virgüllü";
                    break;
                case "24":
                    hdnGameTypeMaster.value = "Tabela Bahis Virgüllü";
                    break;
                case "25":
                    hdnGameTypeMaster.value = "Sıralı İkili Virgüllü"
                    break;
                default:
                    break;
            }
        }
    }

    ngtype = $('#hdn_gametype').val();

    calculate(ngtype, type, '');
}

function set_options(value) {
    spl = value.toString().split('|');
    $('#hdnracecount').val(spl[0]);
    $('#hdn_columncount').val(spl[1]);
    $('#hdn_columnprice').val(spl[2]);
    $('#hdn_gametype').val(spl[3]);
    $('#hdn_minprice').val(spl[4]);
    $('#hdn_maxprice').val(spl[5]);
    if (spl[6] == "True") {
        $('#tr_system').show();
        checkSystem();
    }
    else {
        $('#tr_system').hide();
    }
}

function ekle(ayakno, atno) {
    cbox = document.getElementById("cb_" + ayakno + "_" + atno);
    a = $('#a_' + ayakno + '_' + atno);

    if (cbox != undefined) {
        isselected = cbox.checked;
        if (isselected) {
            cbox.checked = false;
            a.html("Ekle");
        }
        else {
            cbox.checked = true;
            a.html("Cikar");
        }
    }

    gametype = $('#hdn_gametype').val();
    coupontype = $('#CouponType').val();
    calculate(gametype, coupontype, '');
}

function hepsiniSec(index) {
    cbLength = 0;
    selectedCbLength = 0;
    $('input[name="cb_ganyan"]').each(function() {
        _id = $(this).attr("id");
        spl = _id.split('_');
        if (spl[1] == index) {
            if (!($(this).attr("disabled"))) {
                if (spl[2] != "S") {
                    cbLength++;
                }
            }
            isselected = $(this).attr("status");
            if (isselected == undefined)
                isselected = document.getElementById(_id).checked;
            if (isselected) {
                if (!($(this).attr("disabled"))) {
                    if (spl[2] != "S") {
                        selectedCbLength++;
                    }
                }
            }
        }
    });

    if (selectedCbLength == cbLength) {
        $('input[name="cb_ganyan"]').each(function() {
            _id = $(this).attr("id");
            spl = _id.split('_');

            if (spl[1] == index) {
                if (!($(this).attr("disabled"))) {
                    if (spl[2] != "S")
                        document.getElementById(_id).checked = false;
                }
            }
        });
    }
    else {
        $('input[name="cb_ganyan"]').each(function() {
            _id = $(this).attr("id");
            spl = _id.split('_');

            if (spl[1] == index) {
                isselected = $(this).attr("status");
                if (isselected == undefined)
                    isselected = document.getElementById(_id).checked;
                if (!isselected) {
                    if (!($(this).attr("disabled"))) {
                        if (spl[2] != "S") {
                            document.getElementById(_id).checked = true;
                            selectedCbLength++;
                        }
                    }
                }
            }
        });
    }

    checkSystem();

    gametype = $('#hdn_gametype').val();
    coupontype = $('#CouponType').val();

    calculate(gametype, coupontype, '');
}

function checkSystem() {
    checkCount = 0;
    $('input[name="cb_ganyan"]').each(function() {
        id = $(this).attr("id");
        spl = id.split('_');
        if (spl[2] == "S") {
            var i = document.getElementById(id);
            if (i != undefined) {
                checked = i.checked;
                if (checked)
                    checkCount++;
            }
        }
    });

    if (checkCount > 0) {
        $('#tr_bahisSayisi').hide();
        $('#tr_tutar').hide();
        if (document.getElementById("imgSecim") != undefined) {
            document.getElementById("imgSecim").src = "/images/titles/miktarSecimi.jpg";
        }

    }
    else {
        $('#tr_bahisSayisi').show();
        $('#tr_tutar').show();
        if (document.getElementById("imgSecim") != undefined) {
            document.getElementById("imgSecim").src = "/images/titles/misliSecimi.jpg";
        }
    }
}
