﻿
// Global variables
var ApplicationUrl;
var DropDownLoadingText;

// Set application url
$(document).ready(function ()
{
    ApplicationUrl = $('#hidApplicationUrl').val();
    DropDownLoadingText = $('#LoadingString').val();
});

$(document).ready(function ()
{
    $('ul#HPFadeImages').innerfade({
        speed: 3000,
        timeout: 5000,
        type: 'sequence',
        containerheight: '711px'
    });
});

$(document).ready(function ()
{
    $('#HPSlider').HPLoopedSlider({
        autoStart: 10000,
        restart: 20000,
        autoHeight: 1
    });
});

//Tarihce Menu
$(document).ready(function ()
{
    $("#TarihceTopMenu ul ul a").each(function ()
    {
        var url = $(this).attr("href");
        url = url.substr(url.length - 9, 4);
        $(this).attr("href", "#Year" + url);
    });
    var $li = $(".TarihceTopMenuCMSListMenuHighlightedLI");
    $ul = $li.children("ul");
    if ($li.length > 0 && $ul.length > 0)
    {
        var pos = $li.position();
        $ul.css({ left: "0px", top: "0px", position: "absolute" });
        var l = Math.min(pos.left + 15, 645 - $ul.width());
        $ul.css({ left: l + "px", top: (50) + "px" });
        $ul.show();
    }
});

// Footer Menu
$(document).ready(function ()
{
    $('#FooterMenuBox div.BoxContent').hover(function ()
    {
        // Hover effect
        $(this).stop().animate({ top: 0, height: 120 }, "fast");
        $(this).addClass('pretty-hover');
    }, function ()
    {
        $(this).stop().animate({ top: 120, height: 125 }, "fast");
    }).each(function ()
    {
        // Make whole thing a 'link'
        $(this).css({ cursor: "pointer" }).click(function ()
        {
            //document.location.href = $(this).find("a").attr("href");
        });
    });
});

// Bize Ulaşın Formu
$(document).ready(function ()
{
    $('#BizeUlasinFormu .FormButton').attr('src', $('#BizeUlasinGonderImageUrl').val());
});

// E-Bulletin
$(document).ready(function ()
{
    $("#contactLink").click(function ()
    {
        var off = $("#contactLink").offset();

        if ($("#outer").length > 0)
        {
            off = { left: 513, top: 8 };
        }
        else
        {
            off.left += -160;
        }

        $("#contactForm").css({ left: off.left, top: off.top + $("#contactLink").height() });

        if ($("#contactForm").is(":hidden"))
        {
            $("#contactForm").slideDown("slow");
        }
        else
        {
            $("#contactForm").slideUp("slow");
        }
    });

    var emailGirinText = $("#EmailGirinText").val();
    var alreadySubscribed = $("#AlreadySubscribedText").val();
    var notAnEmailText = $("#NotAnEmailText").val();

    $("#NewsletterEmail").val(emailGirinText);

    $("#NewsletterEmail").focus(function ()
    {
        if ($(this).val() == emailGirinText)
        {
            $(this).val("")
        }
    });

    $("#NewsletterEmail").blur(function ()
    {
        if ($(this).val() == "")
        {
            $(this).val(emailGirinText)
        }
    });

    $("#NewsletterGonderImage").click(function ()
    {
        // Disable input
        StartSaveSubscriberProcessProgress();

        $.get(ApplicationUrl + "/WebMethods/SaveEmailForNewsletter.aspx", { action: 'SaveEmailForNewsletter', email: $("#NewsletterEmail").val() }, function (result)
        {
            if (result == "Success")
            {
                alert("E-bültenimize başarıyla kaydoldunuz...");
                $("#NewsletterEmail").val(emailGirinText);
                closeForm();
            }
            else if (result == "NotAnEmail")
            {
                alert(notAnEmailText);
            }
            else if (result == "AlreadySubscibed")
            {
                alert(alreadySubscribed);
            }
        });

        //        $.ajax({
        //            type: "POST",
        //            url: ApplicationUrl + "/WebMethods/SaveEmailForNewsletter.aspx/SaveEmailForNewsletter",
        //            data: "{ 'email' : '" + $("#NewsletterEmail").val() + "' }",
        //            contentType: "application/json; charset=utf-8",
        //            dataType: "json",
        //            success: function(msg)
        //            {
        //                if (msg.d.IsSuccessful)
        //                {
        //                    alert("E-bültenimize başarıyla kaydoldunuz...");
        //                    $("#NewsletterEmail").val(emailGirinText);
        //                    closeForm();
        //                }
        //                else
        //                {
        //                    if (msg.d.ErrorMessage == "NotAnEmail")
        //                    {
        //                        alert(notAnEmailText);
        //                        //$("#NewsletterEmail").val(notAnEmailText);
        //                    }
        //                    else if (msg.d.ErrorMessage == "AlreadySubscibed")
        //                    {
        //                        //$("#NewsletterEmail").val();
        //                    }
        //                    //alert(msg.d.ErrorMessage);
        //                }
        //            },
        //            error: function(xmlHttpRequest, textStatus, errorThrown)
        //            {
        //                //alert(textStatus + ", " + errorThrown + ", " + xmlHttpRequest);
        //            }
        //        });

        EndSaveSubscriberProcessProgress();
    });
});

function EndSaveSubscriberProcessProgress()
{
    $("#NewsletterEmail").removeAttr("disabled");
    $("#NewsletterGonderImage").removeAttr("disabled");
}

function StartSaveSubscriberProcessProgress()
{
    $("#NewsletterEmail").attr("disabled", "disabled");
    $("#NewsletterGonderImage").attr("disabled", "disabled");
}

function closeForm()
{
    //$("#messageSent").show("slow");
    setTimeout('$("#messageSent").hide();$("#contactForm").slideUp("slow")', 0);
}
function CloseFormCross()
{
    setTimeout('$("#messageSent").hide();$("#contactForm").slideUp("slow")', 0);
}


/*================ Kataloglar Sayfası ================*/

function ShowAppropriatePanel()
{
    if ($('#rdbFonksiyon').is(':checked'))
    {
        $('#lblFonksiyon').css('font-weight', 'bold');
        $('#lblSeri').css('font-weight', 'normal');

        $('#OnceFonksiyonSonraSeriPanel').show();
        $('#OnceSeriSonraFonksiyonPanel').hide();

        $('#FonksiyonSeri_Fonksiyon').dropDownProgressStart();
        $('#FonksiyonSeri_Seri').disable();

        $.get(ApplicationUrl + "/WebMethods/KataloglarSayfasi.aspx", { action: 'GetFonksiyonlarForKatalog', katalogAliasPath: $("#KatalogDropDown").val() }, function (data)
        {
            $('#FonksiyonSeri_Fonksiyon').html(data);
            $('#FonksiyonSeri_Fonksiyon').dropDownProgressEnd();
        });

        //        // Load fonksiyonlar
        //        $.ajax({
        //            type: "POST",
        //            url: ApplicationUrl + "/WebMethods/KataloglarSayfasi.aspx/GetFonksiyonlarForKatalog",
        //            data: "{ 'katalogAliasPath' : '" + $("#KatalogDropDown").val() + "' }",
        //            contentType: "application/json; charset=utf-8",
        //            dataType: "json",
        //            success: function(msg)
        //            {
        //                $('#FonksiyonSeri_Fonksiyon').html(msg.d);
        //                $('#FonksiyonSeri_Fonksiyon').dropDownProgressEnd();
        //            },
        //            error: function(xmlHttpRequest, textStatus, errorThrown)
        //            {
        //                //alert(textStatus + ", " + errorThrown + ", " + xmlHttpRequest);
        //            }
        //        });
    }
    else
    {
        $('#lblFonksiyon').css('font-weight', 'normal');
        $('#lblSeri').css('font-weight', 'bold');

        $('#OnceFonksiyonSonraSeriPanel').hide();
        $('#OnceSeriSonraFonksiyonPanel').show();

        $('#SeriFonksiyon_Seri').dropDownProgressStart();
        $('#SeriFonksiyon_Fonksiyon').disable();

        $.get(ApplicationUrl + "/WebMethods/KataloglarSayfasi.aspx", { action: 'GetSerilerForKatalog', katalogAliasPath: $("#KatalogDropDown").val() }, function (data)
        {
            $('#SeriFonksiyon_Seri').html(data);
            $('#SeriFonksiyon_Seri').dropDownProgressEnd();
        });

        //        // Load seriler
        //        $.ajax({
        //            type: "POST",
        //            url: ApplicationUrl + "/WebMethods/KataloglarSayfasi.aspx/GetSerilerForKatalog",
        //            data: "{ 'katalogAliasPath' : '" + $("#KatalogDropDown").val() + "' }",
        //            contentType: "application/json; charset=utf-8",
        //            dataType: "json",
        //            success: function(msg)
        //            {
        //                $('#SeriFonksiyon_Seri').html(msg.d);
        //                $('#SeriFonksiyon_Seri').dropDownProgressEnd();
        //            },
        //            error: function(xmlHttpRequest, textStatus, errorThrown)
        //            {
        //                //alert(textStatus + ", " + errorThrown + ", " + xmlHttpRequest);
        //            }
        //        });
    }

    SetUrunleriGosterButtonVisibility();
}

function SetUrunleriGosterButtonVisibility()
{
    if ($('#rdbFonksiyon').is(':checked'))
    {
        /* Fonksiyon seçiliyse */

        if ($('#FonksiyonSeri_Fonksiyon :selected').attr('kategori') == 'true')
        {
            $('#UrunleriGoster').show();
        }
        else if ($('#FonksiyonSeri_Fonksiyon').val() == null || $('#FonksiyonSeri_Fonksiyon').val() == '' || $('#FonksiyonSeri_Fonksiyon').val() == DropDownLoadingText)
        {
            // Fonksiyon: Fonksiyon seçin...
            // Fonksiyon: Yükleniyor...
            $('#UrunleriGoster').hide();
        }
        else if ($('#FonksiyonSeri_Seri').val() == null || $('#FonksiyonSeri_Seri').val() == DropDownLoadingText)
        {
            // Seri: Yükleniyor...
            $('#UrunleriGoster').hide();
        }
        else
        {
            $('#UrunleriGoster').show();
        }
    }
    else
    {
        /* Seri seçiliyse */

        if ($('#SeriFonksiyon_Seri').val() == null || $('#SeriFonksiyon_Seri').val() == '' || $('#SeriFonksiyon_Seri').val() == DropDownLoadingText)
        {
            $('#UrunleriGoster').hide();
        }
        else if ($('#SeriFonksiyon_Fonksiyon').val() == null || $('#SeriFonksiyon_Fonksiyon').val() == DropDownLoadingText)
        {
            $('#UrunleriGoster').hide();
        }
        else
        {
            $('#UrunleriGoster').show();
        }
    }
}

$(document).ready(function ()
{
    $('#SeriFonksiyonSecmePaneli').hide();

    $('#KatalogDropDown').dropDownProgressStart();

    var randomToPreventCache = new Date().getTime();

    $.get(ApplicationUrl + "/WebMethods/KataloglarSayfasi.aspx?r=" + randomToPreventCache, { action: 'GetKataloglar' }, function (data)
    {
        $('#KatalogDropDown').html(data);
        $('#KatalogDropDown').dropDownProgressEnd();
    });

    //    // Load Kataloglar
    //    $.ajax({
    //        type: "POST",
    //        url: ApplicationUrl + "/WebMethods/KataloglarSayfasi.aspx/X",
    //        data: "{ }",
    //        contentType: "application/json; charset=utf-8",
    //        dataType: "json",
    //        success: function(msg)
    //        {
    //            alert(msg);
    //            //$('#KatalogDropDown').html(msg.d);
    //            //$('#KatalogDropDown').dropDownProgressEnd();
    //        },
    //        error: function(xmlHttpRequest, textStatus, errorThrown)
    //        {
    //            alert(textStatus + ", " + errorThrown + ", " + xmlHttpRequest);
    //        }
    //    });

    $('#KatalogDropDown').change(function ()
    {
        if ($(this).val() == '')
        {
            $('#SeriFonksiyonSecmePaneli').hide();
        }
        else
        {
            $('#SeriFonksiyonSecmePaneli').show();
            ShowAppropriatePanel();
        }
    });

    $('#rdbFonksiyon').click(function ()
    {
        ShowAppropriatePanel();
    });

    $('#rdbSeri').click(function ()
    {
        ShowAppropriatePanel();
    });

    $('#FonksiyonSeri_Fonksiyon').change(function ()
    {
        if ($('#FonksiyonSeri_Fonksiyon :selected').attr('kategori') == '' || $('#FonksiyonSeri_Fonksiyon :selected').attr('kategori') == 'true')
        {
            $('#FonksiyonSeri_Seri').hide();
        }
        else if ($('#FonksiyonSeri_Fonksiyon :selected').attr('kategori') == 'false')
        {
            $('#FonksiyonSeri_Seri').show();
            $('#FonksiyonSeri_Seri').dropDownProgressStart();

            $.get(ApplicationUrl + "/WebMethods/KataloglarSayfasi.aspx", { action: 'GetSerilerForFonksiyon', katalogAliasPath: $("#KatalogDropDown").val(), fonksiyonAlias: $('#FonksiyonSeri_Fonksiyon').val() }, function (data)
            {
                $('#FonksiyonSeri_Seri').html(data);
                $('#FonksiyonSeri_Seri').dropDownProgressEnd();
            });

            //            // Load seriler for fonksiyon
            //            $.ajax({
            //                type: "POST",
            //                url: ApplicationUrl + "/WebMethods/KataloglarSayfasi.aspx/GetSerilerForFonksiyon",
            //                data: "{ 'fonksiyonAlias' : '" + $('#FonksiyonSeri_Fonksiyon').val() + "', 'katalogAliasPath' : '" + $('#KatalogDropDown').val() + "' }",
            //                contentType: "application/json; charset=utf-8",
            //                dataType: "json",
            //                success: function(msg)
            //                {
            //                    $('#FonksiyonSeri_Seri').html(msg.d);
            //                    $('#FonksiyonSeri_Seri').dropDownProgressEnd();
            //                },
            //                error: function(xmlHttpRequest, textStatus, errorThrown)
            //                {
            //                    alert(textStatus + ", " + errorThrown + ", " + xmlHttpRequest.toString());
            //                }
            //            });
        }

        SetUrunleriGosterButtonVisibility();
    });

    $('#FonksiyonSeri_Seri').change(function ()
    {
        SetUrunleriGosterButtonVisibility();
    });

    $('#SeriFonksiyon_Seri').change(function ()
    {
        $('#SeriFonksiyon_Fonksiyon').dropDownProgressStart();

        $.get(ApplicationUrl + "/WebMethods/KataloglarSayfasi.aspx", { action: 'GetFonksiyonlarForSeri', katalogAliasPath: $("#KatalogDropDown").val(), seriNodeAlias: $('#SeriFonksiyon_Seri').val() }, function (data)
        {
            $('#SeriFonksiyon_Fonksiyon').html(data);
            $('#SeriFonksiyon_Fonksiyon').dropDownProgressEnd();
        });

        //        // Load fonksiyonlar for seri
        //        $.ajax({
        //            type: "POST",
        //            url: ApplicationUrl + "/WebMethods/KataloglarSayfasi.aspx/GetFonksiyonlarForSeri",
        //            data: "{ 'seriNodeAlias' : '" + $('#SeriFonksiyon_Seri').val() + "', 'katalogAliasPath' : '" + $("#KatalogDropDown").val() + "' }",
        //            contentType: "application/json; charset=utf-8",
        //            dataType: "json",
        //            success: function(msg)
        //            {
        //                $('#SeriFonksiyon_Fonksiyon').html(msg.d);
        //                $('#SeriFonksiyon_Fonksiyon').dropDownProgressEnd();
        //            },
        //            error: function(xmlHttpRequest, textStatus, errorThrown)
        //            {
        //                alert(textStatus + ", " + errorThrown + ", " + xmlHttpRequest.toString());
        //            }
        //        });

        SetUrunleriGosterButtonVisibility();
    });

    $('#SeriFonksiyon_Fonksiyon').change(function ()
    {
        SetUrunleriGosterButtonVisibility();
    });

    $('#UrunleriGoster').click(function ()
    {
        if ($('#OnceFonksiyonSonraSeriPanel').is(':visible'))
        {
            if ($('#FonksiyonSeri_Fonksiyon').val() == '')
            {
                alert('Lütfen fonksiyon ve/veya seri seçin...');
            }
            else
            {
                var fonksiyonSayfasiUrl = ApplicationUrl + $('#KatalogDropDown').val() + '/Fonksiyonlar.aspx';

                if ($('#FonksiyonSeri_Fonksiyon :selected').attr('kategori') == 'true')
                {
                    // Fonksiyon kategori sayfasını aç
                    document.location = fonksiyonSayfasiUrl + '?fonksiyonKategori=' + $('#FonksiyonSeri_Fonksiyon').val();
                }
                else
                {
                    if ($('#FonksiyonSeri_Seri').val() == '')
                    {
                        // Tüm seriler
                        document.location = fonksiyonSayfasiUrl + '?fonksiyon=' + $('#FonksiyonSeri_Fonksiyon').val();
                    }
                    else
                    {
                        // belli seri
                        document.location = fonksiyonSayfasiUrl + '?fonksiyon=' + $('#FonksiyonSeri_Fonksiyon').val() + '&seri=' + $('#FonksiyonSeri_Seri').val();
                    }
                }
            }
        }
        else
        {
            if ($('#SeriFonksiyon_Seri').val() == '')
            {
                alert('Lütfen fonksiyon ve/veya seri seçin...');
            }
            else
            {
                var seriSayfasiUrl = ApplicationUrl + $('#KatalogDropDown').val() + '/' + $('#SeriFonksiyon_Seri').val() + '.aspx';

                if ($('#SeriFonksiyon_Fonksiyon').val() == '')
                {
                    document.location = seriSayfasiUrl;
                }
                else
                {
                    document.location = seriSayfasiUrl + '?fonksiyon=' + $('#SeriFonksiyon_Fonksiyon').val();
                }
            }
        }
    });
});

/* pasabahce jquery extensions */
jQuery.fn.dropDownProgressStart = function ()
{
    $('#LutfenBekleyiniz').show();
    this.dropDownLoadingStart(DropDownLoadingText);

    //$('#UrunleriGoster').hide();
};

jQuery.fn.dropDownProgressEnd = function ()
{
    $('#LutfenBekleyiniz').hide();
    this.dropDownLoadingEnd();

    SetUrunleriGosterButtonVisibility();
    //$('#UrunleriGoster').show();
};

