


$(document).ready(function() {



    // ScrollTo

    jQuery.fn.extend({
        scrollTo: function(speed, easing) {
            return this.each(function() {
                var targetOffset = $(this).offset().top;
                $('html,body').animate({ scrollTop: targetOffset }, speed, easing);
            });
        }
    });

    //social.setTitle(document.title);
    social.setTitle("adios - " + $(this).find("h1").text());
    social.setURL(document.location);

    // Jifr

    jfr$('h1').jfr({
        src: webRoot + '/_swf/jifr.swf',
        css: [
            '* { color: #008ea5; text-align: left; font-size: 36px; letter-spacing:-1px;   }',
            'a { color: #008ea5; text-decoration: none; letter-spacing:-1px; }',
            'a:hover { text-decoration: underline; letter-spacing:-1px; }'
            ]
    });
    $.jfr.render();


    // BreadCrumb

    $(".content .breadcrumb span:first-child a").css({
        paddingLeft: "20px",
        backgroundImage: "none",
        textDecoration: "underline"

    });





    $(".breadcrumb span:last-child a").css("text-decoration", "none");

    $(".breadcrumb span.selected a").removeAttr("href");

    var breadcrumbLength = $(".breadcrumb span").length;



    //    if (breadcrumbLength < 2) {
    //        $(".breadcrumb span").css("display", "none");
    //    }



    //Set Footer

    setTimeout(setFooter, 100);


    function setFooter() {
        if ($(".footer").length > 0) {

            function onResizeHandler() {
                if ($(window).height() > ($(".wrapper").outerHeight() + $(".footer").outerHeight()))
                    $(".footer").css("margin-top", $(window).height() - $(".wrapper").outerHeight() - $(".footer").outerHeight() + "px").css('margin-bottom', '0px');
                else
                    $(".footer").css("margin-top", "0px");
            }
            onResizeHandler();
            $(".footer").css("display", "block");
            window.onresize = onResizeHandler;
        }
    }

    //PNG fix

    //$('img[src$=.png]').ifixpng();


    // Table Style

    $(".wrapper .rightCont .content .listing .tableCont table tr td:last-child").css("border-right", "none");
    $(".wrapper .rightCont .content .listing .tableCont table tr th:last-child").css("border-right", "none");
    $(".wrapper .rightCont .content .listing .tableCont table tr:last-child td").css("border-bottom", "none");
    $(".wrapper .rightCont .content .listing .tableCont table tr:last-child th").css("border-bottom", "none");


    //SSS Script

    $(".faqItem .faqTitle a").click(function() {
        // soru indeksi getiriliyor
        var _index = $(".faqItem .faqTitle a").index(this);
        // eger ayni soruya tiklaniyorsa, false donuyoruz
        if ($(".faqItem").eq(_index).hasClass("active")) {
            $(".faqItem").eq(_index).removeClass("active")
            $(".faqItem .faqContent").eq(_index).slideUp("slow");
            return false;
        }
        // tüm elementlerde dolasip, class temizleyip slideup yapiliyor
        $(".faqItem").each(function() {
            $(this).removeClass("active");
        })
        $(".faqContent").each(function() {
            $(this).slideUp("slow");
        })

        $(".faqItem").eq(_index).addClass("active");
        $($(".faqItem .faqContent").eq(_index)).slideToggle("slow");
        // linki disable etmek icin return false
        return false;
    });

});

function PopItUp(src, w, h, s) {
    if (s) w = w + 17;
    if (w) {
        Popwin = window.open(src, "pop_up", "toolbar=0,width=" + w + ", height=" + h + ", location=0, directories=0, status=1, scrollbars=" + s + ", menubar=0, resizable=0, copyhistory=0");
        //Popwin.focus();
    }
    else {
        window.location = src
    }
}

function BindValToControl(control, val, isCustomSelect) {

    if (control.attr('type') == 'text') {
        control.val(val);
    } else if (control.is('select')) {



        if (isCustomSelect)
            control.parents(".jquery-selectbox").unselectbox();


        control.empty();
        control.prepend('<option value="">' + val + '</option>');
        //control.val('');  IE6PROBLEM
        if (!isCustomSelect)
            control.focus();

        if (isCustomSelect)
            control.selectbox();

    } else if (control.is('password')) {
        control.val(val);
    }
}

String.prototype.format = function() {
    var pattern = /\{\d+\}/g;
    var args = arguments;
    return this.replace(pattern, function(capture) { return args[capture.match(/\d+/)]; });
}


function disableElm(objElm) {

    var waitingText = 'Lütfen bekleyiniz ...';

    $.each(objElm, function(e) {

        var sControl = $('[name="' + this.source + '"]');   //Source Control
        var tControl = $('[name="' + this.target + '"]');   //Target Control

        //INIT

        //Clear Control Items
        tControl.empty();
        tControl.val('');

        //Bind Empty Text
        BindValToControl(tControl, objElm[e].emptytext);

        //Disable Control
        if (objElm[e].disable)
            tControl.attr('disabled', true);



        if (objElm[e].customselect)
            sControl.selectbox();

        sControl.unbind('change').bind('change', function() {

            if (objElm[e].change != null) {
                if (sControl.attr('disabled') || sControl.val() == null || sControl.val() == '' || sControl.val().length == 0) {

                    if (objElm[e].disable && tControl.attr('disabled') != true)
                        tControl.attr('disabled', true).change();

                    if (objElm[e].clear)
                        BindValToControl(tControl, '', true);

                    if (objElm[e].emptytext != null && objElm[e].emptytext != '' && objElm[e].emptytext.length > 0)
                        BindValToControl(tControl, objElm[e].emptytext, true);


                } else {

                    BindValToControl(tControl, waitingText, objElm[e].customselect);

                    objElm[e].change(function() {
                        if (tControl.attr('disabled'))
                            tControl.attr('disabled', false);

                        if (objElm[e].fullytext != null)
                            BindValToControl(tControl, objElm[e].fullytext, true);
                    }, function() {
                        if (objElm[e].customselect) {

                            tControl.parents(".jquery-selectbox").unselectbox();
                            tControl.selectbox();

                        }

                    });

                    if (e != objElm.length - 1)
                        tControl.attr('disabled', true).change();
                }
            }
        });



    });

}


function GenerateClientPager(intActivePageIndex, intRowCount, onClickEvent, PageSize, PagerWidth, context) {
    var strHtml = "";
    ReportActivePageIndex = intActivePageIndex;
    var intPageCount = Math.ceil(intRowCount / PageSize);
    if (intPageCount > 1) {
        step = parseInt(PagerWidth / 2);
        intStart = intActivePageIndex - (step);
        intFinish = intActivePageIndex + (step);

        if (intActivePageIndex >= 1 && intActivePageIndex <= step + 1) {
            intStart = 1;
            intFinish = PagerWidth;
        }
        else
            if (intActivePageIndex >= (intPageCount - step) && intActivePageIndex <= intPageCount) {
            intStart = intPageCount - PagerWidth + 1;
            intFinish = intPageCount;
        }

        if (intStart < 1)
            intStart = 1;

        if (intFinish > intPageCount)
            intFinish = intPageCount;

        for (i = intStart; i <= intFinish && i <= intPageCount; i++) {

            if (intActivePageIndex != i)
                strHtml += "<a href=\"javascript:;\" onclick=\"" + onClickEvent.replace(/{Index}/g, i) + "\">" + i + "</a>";
            else
                strHtml += "<a href=\"javascript:;\" class=\"selected\"  onclick=\"return false;\">" + i + "</a>";

        }

        //if (PagerWidth < intPageCount) {
        var movePreviousEvent = "";
        if (intActivePageIndex > 1) {
            movePreviousEvent = "onclick=\"" + onClickEvent.replace("{Index}", intActivePageIndex - 1) + "\"";
        }
        strHtml = "<a class=\"first\" href=\"javascript:;\" " + movePreviousEvent + "><img src=\"" + webRoot + "/_i/img_pagePrevious.gif\" alt=\"Geri\" /></a>" + strHtml;
        var moveNextEvent = "";
        if (intActivePageIndex < intPageCount) {
            moveNextEvent = "onclick=\"" + onClickEvent.replace("{Index}", intActivePageIndex + 1) + "\"";
        }
        strHtml += "<a class=\"last\" href=\"javascript:;\"  " + moveNextEvent + " ><img src=\"" + webRoot + "/_i/img_pageForward.gif\" alt=\"İleri\" /></a></a>";
        //}
    }
    var pagerDiv = $(context);
    pagerDiv.empty();
    pagerDiv.html(strHtml);
    return strHtml;
}


function getCenter(pwidth, pheight) {
    wwidth = screen.width;
    wheigth = screen.height;
    lpos = (wwidth - pwidth) / 2;
    tpos = (wheigth - pheight) / 2;
    return lpos, tpos;
}


function PopItUp(src, w, h, s) {
    if (s) w = w + 17;
    getCenter(w, h);
    Popwin = window.open(src, "pop_up", "toolbar=0,width=" + w + ", height=" + h + ", left=" + lpos + ", top=" + tpos + "; location=0, directories=0, status=1, scrollbars=" + s + ", menubar=0, resizable=1, copyhistory=0");
    Popwin.focus();
    //return false;
}