﻿$(document).ready(function () {

    InitializeMenu();
    setTimeout("LiteralGizle()", 3000);
});

function ReadMessage(id) {
    var html = '<iframe frameborder="0" scrolling="auto" width="489" height="500" src="KullaniciKayitPopUp.aspx?ID=' + id + '"></iframe>';
    $('#message_box').show();
    $('#message_body').show().css({ 'width': '489', 'left': (($(window).width() - 489) / 2), 'top': (($(window).height() - 489) / 2) }).html(html);
    $('#message_close').show().css({ 'left': (($(window).width() / 2) + 245), 'top': (($(window).height() - 489) / 2) - 15 });
    $('body').css('overflow', 'hidden');
}

function ReadIK(id) {
    var html = '<iframe frameborder="0" scrolling="auto" width="800" height="500" src="ReadIK.aspx?ID=' + id + '"></iframe>';
    $('#message_box').show();
    $('#message_body').show().css({ 'width': '800px', 'left': (($(window).width() - 800) / 2), 'top': (($(window).height() - 500) / 2) }).html(html);
    $('#message_close').show().css({ 'left': (($(window).width() / 2) + 395), 'top': (($(window).height() - 500) / 2) - 15 });
    $('body').css('overflow', 'hidden');
}


function HideMessage() {
    window.location.reload();
}

function ShowDateTime() {
    var tarih = new Date();
    $('.tarih').html(tarih.format("dddd dd mmmm yyyy HH:MM:ss"));
    setTimeout('ShowDateTime()', 1000);
}

function OpenImageDialog() {
    ref = $('.cke_dialog_ui_input_text input:eq(0)').attr('id');
    window.open('dialogs/ImageBrowser.aspx?ref=' + ref, 'ImageBrowser', 'width=500,height=500,scrollbars=1;');
}

function LiteralGizle() {
    $(".alert_success").remove();
    $(".alert_error").remove();
}
function FormAcKapa(id) {
    $("#div1").attr({ 'class': 'pasivediv' });
    $("#div2").attr({ 'class': 'pasivediv' });
    $("#div3").attr({ 'class': 'pasivediv' });
    $("#div" + id).attr({ 'class': 'activediv' });
}
function SetTableHeaders(headers) {
    for (i = 0; i < headers.length; i++) {
        $('table.data thead tr th:eq(' + i + ')').html(headers[i]);
    }
}
function InitializeMenu() {
    var urls = document.URL.split('/');
    var page = urls[urls.length - 1];
    var menu = '';
    var locations = [
    ['Sepetim.aspx', '#main_eticaret'],
    ['Siparislerim.aspx', '#main_eticaret'],
    ['GelenSiparislerim.aspx', '#main_eticaret'],
    ['GelenSpettekiUrunler.aspx', '#main_eticaret'],
    ['YeniEticaretIlanlarim.aspx', '#main_eticaret'],
    ['HesapBilgilerim.aspx', '#main_eticaret'],
    ['ElemanIlaniVer.aspx', '#main_ik'],
    ['IsIlaniVer.aspx', '#main_ik'],
    ['ElemanIlanlarim.aspx', '#main_ik'],
    ['IsIlanlarim.aspx', '#main_ik'],
    ['GelenElemanIlanlarim.aspx', '#main_ik'],
    ['GelenIsIlanlarim.aspx', '#main_ik'],
    ['EmlakIlaniVer.aspx', '#main_emlakilanlarim'],
    ['EmlakIlanlarim.aspx', '#main_emlakilanlarim'],
    ['OtoIlaniVer.aspx', '#main_otoilanlarim'],
    ['OtoIlanlarim.aspx', '#main_otoilanlarim'],
    ['YemekSepetim.aspx', '#yemek_siparislerim'],
    ['YemekSiparislerim.aspx', '#yemek_siparislerim'],
    ['GelenYemekSiparislerim.aspx', '#yemek_siparislerim'],
    ['YemekSiparisiGuncelle.aspx', '#yemek_siparislerim'],
    ['YemekHesapBilgilerim.aspx', '#yemek_siparislerim'],
    ['IsKulubuIsIlaniVer.aspx', '#main_iskulubu'],
    ['IsKulubuIsIlanlarim.aspx', '#main_iskulubu'],
    ['UcretsizKitapBirak.aspx', '#main_bomerangkitap'],
    ['UcretsizKitapIste.aspx', '#main_bomerangkitap']
    ];

    for (var i = 0; i < locations.length; i++) {
        if (page.indexOf(locations[i][0]) > -1) {
            menu = locations[i][1];
            break;
        }
    }

    if (menu != '') {
        $(menu).parent().find('ul').show();
    }

    var slideSpeed = 300;

    $('#main_menu li a').click(function () {
        if ($(this).parent().find('ul li').length > 0) {
            clicked = $(this).parent().find('ul');
            if (clicked.css('display') == 'none') {
                clicked.slideDown(slideSpeed);
                for (var i = 0; i < $(this).parent().parent().find('li ul').length; i++) {
                    selected = $(this).parent().parent().find('li ul:eq(' + i + ')');
                    if (selected.html() != clicked.html()) {
                        selected.slideUp(slideSpeed);
                    }
                }
            }
            else {
                clicked.slideUp(slideSpeed);
            }
        }
    });
}
function Temizle(t) {
    if (t.value == "Kullanıcı Adı" || t.value == "Username")
        t.value = "";
}
function TemizleSifre(t) {
    if (t.value == "Şifre" || t.value == "Password") {
        t.value = "";
    }
}
function popupOpen() {
    $(".popup").css("display", "block");
    $(".popupbg").css("display", "block");
}
function popupClose() {
    $(".popup").css("display", "none");
    $(".popupbg").css("display", "none");
}
$(document).ready(function () {
    $(".popupbg").click(function () {
        $(this).css("display", "none");
        $(".popup").css("display", "none");
    });

    if ($(".popup").css("display") == "block") {
        var mTop = (screen.height - $(".popup").height()) / 2
        var mLeft = (screen.width - $(".popup").width()) / 2
        $(".popup").css("left", mLeft);
        $(".popup").css("top", mTop);

    }
});
