﻿
function isValidEmail(strEmail)
{
    validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
    //strEmail = document.forms[0].email.value;

    // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1)
    {
        //alert('A valid e-mail address is required.\nPlease amend and retry');
        return false;
    }
    return true;
}

$(document).ready(function ()
{
    $(".CMSSearchDialogSearchForTextBox,.MasterSearchInput").autocomplete("/CustomPages/DocumentNames.aspx", {
        delay: 400,
        cacheLength: 0,
        scroll: false,
        width: 'auto',
        formatItem: function (data, i, n, value)
        {
            //make the suggestion look nice
            return value.split("::")[0];
        },
        formatResult: function (data, value)
        {
            //only show the suggestions and not the URLs in the list
            return value.split("::")[0];
        }
    }).result(function (event, data, formatted)
    {
        //redirect to the URL in the string
        document.location.href = formatted.split("::")[1];
    });
});

var activeMenu = null;
var hideMenu = null;
var hideStartTime = null;

function MenuMouseOut(param)
{
    if (param != null)
    {
        $('#menuFix').hide(); $(param).find('ul').hide(); if (!$(param).hasClass('MasterTopMenuCMSListMenuHighlightedLI')) $(param).find('a img').attr('src', $(param).find('a img').attr('src').replace(/_on.gif/i, '_off.gif'));
    }
}

function MenuCheckHide()
{
    if (hideStartTime != null && (new Date()).getTime() - hideStartTime.getTime() > 500 && hideMenu != null)
    {
        MenuMouseOut(hideMenu);
        hideMenu = null;
    }
}

setInterval('MenuCheckHide()', 50);

function DocumentReady()
{

    $('.TabMenuContainer').click(function ()
    {
        $('.TabMenu .On').removeClass('On').addClass('Off');
        $('.TabContent').hide();
        $(this).removeClass('Off').addClass('On');
        $('#tab_' + $(this).attr('id')).show();
    });
    $('.TabMenuContainer:first').click();

    if ($('#tab_BasindaBuKitap').size() <= 0) $('#BasindaBuKitap').hide();
    if ($('#tab_Video').size() <= 0) $('#Video').hide();

    /* Güncel Kitaplar Slider */
    $('#loopedSlider').loopedSlider({ autoStart: 5000, restart: 5000 });
    $('.GuncelKitaplar #loopedSlider .details').attr('href', $('.GuncelKitaplar #loopedSlider .GuncelKitap:eq(0) .Title a').attr('href'));

    /* Search Box String */
    if (!$('.MasterSearchInput').val()) $('.MasterSearchInput').val('Sitede');
    $('.MasterSearchInput').focus(function () { if ($(this).val() == 'Sitede') $(this).val(''); });
    $('.MasterSearchInput').blur(function () { if ($(this).val() == '') $(this).val('Sitede'); });

    /* Top Menu Hover */
    var menuFix = "<div id='menuFix' style='background-color:white; height:5px; width:50px; position:absolute; z-index:10'></div>";
    $(menuFix).appendTo($('.MasterTopMenu:first'));
    $('#menuFix').hide();
    $('.MasterTopMenu #menuElem > li > ul').each(function () { $(this).css('left', $(this).parent().offset().left + 1); $(this).css('top', $(this).parent().offset().top + ($.browser.msie && $.browser.version >= '8.0' ? 34 : 37)) });
    $('.MasterTopMenu #menuElem > li:eq(3) > ul').prepend('<img class="TopMenuHeader" src="/app_themes/sufi/topmenuHaberler_h.gif">');
    $('.MasterTopMenu #menuElem > li:eq(3) > ul').append('<img class="TopMenuFooter" src="/app_themes/custom/topmenuHaberler_f.gif">');
    $('.MasterTopMenu #menuElem > li:eq(1) > ul').prepend('<img class="TopMenuHeader" src="/app_themes/sufi/topmenuKitaplar_h.gif">');
    $('.MasterTopMenu #menuElem > li:eq(1) > ul').append('<img class="TopMenuFooter" src="/app_themes/custom/topmenuHaberler_f.gif">');
    $('.MasterTopMenu #menuElem > li:eq(1) > ul').width(120);
    $('.MasterTopMenu #menuElem > li').mouseover(function ()
    {
        if (activeMenu != this)
            MenuMouseOut(activeMenu);
        activeMenu = this;
        if (hideMenu = this)
            hideMenu = null;
        if ($(this).find('ul').length)
        {
            $('#menuFix').css('left', ($(this).offset().left + 2) + 'px');
            $('#menuFix').css('top', ($(this).parent().parent().offset().top + 28) + 'px');
            $('#menuFix').css('width', ($(this).width() - 21) + 'px');
            $('#menuFix').show();
            var $ul = $(this).find('ul');
            $ul.css('left', $ul.parent().offset().left + 1);
            $ul.css('top', $ul.parent().offset().top + ($.browser.msie && $.browser.version >= '8.0' ? 34 : 37));
        }
        $(this).find('ul').show(); $(this).find('a img').attr('src', $(this).find('a img').attr('src').replace(/_off.gif/i, '_on.gif'))
    });

    $('.MasterTopMenu #menuElem > li').mouseout(function ()
    {
        hideMenu = this;
        hideStartTime = new Date();
    });

    /* Kitap Right Block */
    $('.KitapRightBlocks .Title').css('backgroundImage', 'url(/App_Themes/Custom/griback_off.gif)');
    $('.KitapRightBlocks .InnerContent').hide();

    $('.KitapRightBlocks .Title').click(function ()
    {
        ResetRightBlock();
        $(this).css('backgroundImage', 'url(/App_Themes/Sufi/griback_on.gif)');
        $(this).parent().find('.InnerContent').show('fast');
    });
    $('.KitapRightBlocks .Title:first').click();
    $('.KitapRightBlocks .Title:first').css('paddingTop', '4px');
    $('.KitapRightBlocks .Title:first').css('height', '31px');
    $('.FirstAjaxContent').appendTo($('.ContentBody div:first'));

    $('.YazarLetters .Letter').click(function () { ResetYazarList($(this).text(), this) });
    $('.YazarLetters .Letter:first').click();

    $('#YazarList2 > div').click(function ()
    {
        $('#YazarList > div').removeClass('ListOn');
        $(this).addClass('ListOn');
        var Url = $(this).attr('NodeAliasPath') + ".aspx";
        $.ajax({
            type: "GET",
            url: Url,
            dataType: "html",
            success: function (html)
            {
                var $a = $(html);
                alert($a.html());
                $("#AjaxContent").html(html);
                // alert($("#AjaxContent").html());
                alert(html);
            }
        });
    });

    if ($('#Son5EtkinlikContent').length == 0 && $('.Son5HaberContainer').length != 0) $('.Son5HaberContainer:first').parent().parent().parent().remove();
    else
    {
        $('#Son5EtkinlikContent').appendTo($('#EtkinlikHaberleri'));
        $('#Son5BasintaTimasContent').appendTo($('#BasindaTimas'));
        $('#Son5RoportajContent').appendTo($('#Roportajlar'));
        $('.Son5HaberContainer .YeniCikanlarContainer:even').after('<div class="Son5HaberSep" style="float:left; margin:16px; width:1px;background-image:url(/App_Themes/Custom/ver.gif);background-repeat:repeat-y;"></div>');
        $('.Son5HaberSep').height($('.Son5HaberSep').parent().height() - 20);
    }
    $('#fix_email').each(function () { if (!isValidEmail($(this).html())) $(this).parent().hide(); });
    $('#fix_url').each(function () { if ($(this).html() == 'http://www..' || $(this).html() == '') $(this).parent().hide(); });
    $('.NewsText a').attr('target', '_blank');

    /*Kitap Yorumları Formu */
    if ($('#KitapYorumlariForm').length == 0) $('#EndOfOkuyucuYorumlari').html('Yorum yazabilmek için <b onclick="UyeGirisi()" style="color:#a8b700; cursor:pointer;">üye girişi</b> yapmalısınız.<br><br>');
    else $('#KitapYorumlariForm').prependTo($('#EndOfOkuyucuYorumlari'));
    $('.EditingFormTable tr > td').attr('valign', 'top');

    $('#YazarinDigerKitaplari').html($('#YazarinDigerKitaplariContainer').html());
    $('a.LeftMenuCMSListMenuLinkHighlighted').css('color', '#a8b700');
    $('.CMSSearchDialogSearchForTextBox').attr("style", "width:150px; height:18px; padding:4px; border:1px solid #DFDFDF;");
    $('.CMSSearchDialogSearchForTextBox').parent().parent().find('td').css('height', '40px');
    $('.CMSSearchDialogSearchModeDropDownList').css('width', '190px');
    $('.CMSSearchDialogSearchForLabel,.CMSSearchDialogSearchModeLabel').css('fontWeight', 'bold');
    $('.Line').each(function ()
    {
        if ($(this).find('span').html() == '') $(this).remove();
    });
    $('#SayfaTVContainer').appendTo($('#SayfaTV'));
    if (!$('#SayfaTV').length) $('#SayfaTVContainer').hide();

    if ($('#SayfaTVResim').length) $('#SayfaTVLatest a').click(function () { $('#SayfaTVResim img:first').fadeOut('fast'); $('#SayfaTVResim img:first').attr('src', $(this).attr('resim')); $('#SayfaTVResim img:first').fadeIn('fast'); $('#SayfaTVResim').attr('href', $(this).attr('href')); return false; });
    $('.lightbox').lightBox({
        imageLoading: '/App_Themes/Custom/lightbox/lightbox-ico-loading.gif',
        imageBtnClose: '/App_Themes/Custom/lightbox/lightbox-btn-close.gif',
        imageBlank: '/App_Themes/Custom/lightbox/lightbox-blank.gif'
    });
    //if ($('#tab_BasindaBuKitap').html() == null) $('#BasindaBuKitap').hide();
    if ($('.signoutButton').length) $('#BlogYorumUyeGirisi').hide();
    $('.FAQLink').click(function () { $('.FAQ').hide(); $('#FAQ' + $(this).attr('id').replace(/FAQLink/i, '')).show(); return false; });

    var b = '';
    $.each($.browser, function (i, val)
    {
        if (i == 'safari' && val == true) { b = 'safari'; }
        if (i == 'opera' && val == true) { b = 'opera'; }
        if (i == 'msie' && val == 7) { b = 'msie'; }
        if (i == 'mozilla' && val == true) { b = 'mozilla'; }
        if (i == 'chrome' && val == true) { b = 'chrome'; }
    });

    if (b == 'mozilla')
    {
        $('.signinButton').css({ 'top': '-2px' });
    }
    if (b == 'opera')
    {
        $('.signinButton').css({ 'top': '-2px' });
    }
    if (b == 'safari')
    {
        $('.signinButton').css({ 'top': '-2px' });
    }
    if (b == 'chrome')
    {
        $('.signinButton').css({ 'bottom': '-2px' });
    }
}

function flash(w, h, u, t)
{
    document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='" + w + "' height='" + h + "'><param name='movie' value='" + u + "'><param name='quality' value='high'>");
    if (t == "y")
    {
        document.write("<param name='wmode' value='transparent'>");
    }
    document.write("<embed wmode='transparent' src='" + u + "' quality='high' type='application/x-shockwave-flash' width='" + w + "' height='" + h + "'></embed></object>");
}


function UyeGirisi()
{
    var iframe = $('<iframe frameborder="0" id="UyeGirisiIframe" style="opacity:1;filter:alpha(opacity=100);z-index:10;"></frame>');
    var darkDiv = $('<div id="darkDiv" onclick="UyeGirisiKapat();" style="position:absolute; width:100%; background-color:black; opacity:0.8;filter:alpha(opacity=80); z-index:5; left:0px; top:0px;"></div>');
    $(darkDiv).css('height', $(document).height() + 'px');
    $(iframe).attr({ 'src': '/Uyelik-Islemleri/Uye-Girisi.aspx', 'width': '585', 'height': '360' }).css({ 'zIndex': '10', 'position': 'absolute', 'top': '145px', 'border': '3px solid #a8b700', 'left': ($('.MasterContainer').offset().left + 192) + 'px', 'scrolling': 'no' });
    $(iframe).appendTo($('body'));
    $(darkDiv).appendTo($('body'));
}

function UyeGirisiKapat()
{
    var obj = window.top.document.getElementById('UyeGirisiIframe');
    var darkDiv = window.top.document.getElementById('darkDiv');
    $(obj).remove();
    $(darkDiv).remove();
}

function ResetYazarList(Letter, obj)
{
    return;
    $('#YazarList div').hide();
    if (Letter.length > 1) $('#YazarList div').show();
    else $('#YazarList div[Title^=' + Letter + ']').show();
    $('.YazarLetters .Letter').removeClass('ListOn');
    $(obj).addClass('ListOn');
}

function ResetRightBlock()
{
    $('.KitapRightBlocks .Title').css('backgroundImage', 'url(/App_Themes/Custom/griback_off.gif)');
    $('.KitapRightBlocks .InnerContent').hide('fast');
}
