﻿/*
o-----------------------------------------------------------o
| Kocak Gayrimenkul Bankasi - 2008 2009                     |
| Alper Ozcetin                                             |
| http://www.alperozcetin.com                               |
|-----------------------------------------------------------|
| Drag Extender Control from DropThings (c) Omar AL Zabir   |
| http://www.codeplex.com/dropthings                        |
o-----------------------------------------------------------o
*/

function kocak_dashboard_ondrop(sender, e) {
    var container = e.get_container();
    var item = e.get_droppedItem();
    var position = e.get_position();

    //alert( String.format( "Container: {0}, Item: {1}, Position: {2}", container.className, item.id, position ) );

    var instanceId = parseInt(document.getElementById(item.id + "_instanceId").value);

    var columnNo;
    switch (container.className) {
        case "widget_kolon_1": columnNo = 0; break;
        case "widget_kolon_2": columnNo = 1; break;
        case "widget_kolon_3": columnNo = 2; break;
    }

    kocak_dashboard.kocak_widget_tasi(instanceId, columnNo, position, kocak_widget_sonuc_al);
}

function kocak_dashboard_kapat(e) {
    var instanceId = parseInt(document.getElementById(e + "_instanceId").value);

    kocak_dashboard.kocak_widget_kapat(instanceId, function(sonuc_veri) { if (sonuc_veri == 1) $hide(e); else { kocak_widget_sonuc_al(sonuc_veri); alert("Bu alanı kapatabilmeniz için oturum açmalısınız!"); } });
}

function kocak_dashboard_gizlegoster() {
}



$(document).ready(function() {
    $(".widget_gizlebtn").click(function() {
        var goster = 0;

        if ($(this).parent().parent().parent().find(".kocak_widget_icerik_head").css("display") == "none") {
            $(this).parent().parent().parent().find(".kocak_widget_icerik_head").css("display", "");
            $(this).parent().parent().parent().find(".kocak_widget_icerik").hide();
            $(this).parent().parent().parent().find(".kocak_widget_bar").hide();
            $(this).parent().parent().parent().find(".kocak_widget_secenekler").hide();
            if ($(this).parent().parent().parent().find("script").size() > 0) {
                $(this).parent().parent().parent().find(".kocak_widget_icerik").show();
                $(this).parent().parent().parent().find(".kocak_widget_bar").show();
                $(this).parent().parent().parent().find(".kocak_widget_secenekler").show();
            } else {
                $(this).parent().parent().parent().find(".kocak_widget_icerik").slideDown("normal");
                $(this).parent().parent().parent().find(".kocak_widget_bar").slideDown("normal");
                $(this).parent().parent().parent().find(".kocak_widget_secenekler").slideDown("normal");
            }
            $(this).addClass("widget_gizlebtn_eksi");
            $(this).removeClass("widget_gizlebtn_arti");
            goster = 1;
        } else if ($(this).parent().parent().parent().find(".kocak_widget_icerik").is(":hidden")) {
            if ($(this).parent().parent().parent().find("script").size() > 0) {
                $(this).parent().parent().parent().find(".kocak_widget_icerik").show();
                $(this).parent().parent().parent().find(".kocak_widget_bar").show();
                $(this).parent().parent().parent().find(".kocak_widget_secenekler").show();
            } else {
                $(this).parent().parent().parent().find(".kocak_widget_icerik").slideDown("normal");
                $(this).parent().parent().parent().find(".kocak_widget_bar").slideDown("normal");
                $(this).parent().parent().parent().find(".kocak_widget_secenekler").slideDown("normal");
            }
            $(this).removeClass("widget_gizlebtn_arti");
            $(this).addClass("widget_gizlebtn_eksi");
            goster = 1;
        } else {
            if ($(this).parent().parent().parent().find("script").size() > 0) {
                $(this).parent().parent().parent().find(".kocak_widget_icerik").hide();
                $(this).parent().parent().parent().find(".kocak_widget_bar").hide();
                $(this).parent().parent().parent().find(".kocak_widget_secenekler").hide();
            } else {
                $(this).parent().parent().parent().find(".kocak_widget_icerik").slideUp("normal");
                $(this).parent().parent().parent().find(".kocak_widget_bar").slideUp("normal");
                $(this).parent().parent().parent().find(".kocak_widget_secenekler").slideUp("normal");
            }
            $(this).addClass("widget_gizlebtn_arti");
            $(this).removeClass("widget_gizlebtn_eksi");
            goster = 0;
        }

        var instanceId = parseInt(document.getElementById($(this).parent().parent().parent().attr("id") + "_instanceId").value);
        kocak_dashboard.kocak_widget_gizlegoster(instanceId, goster,
                    function(sonuc_veri) { if (sonuc_veri != 1) { kocak_widget_sonuc_al(sonuc_veri); } }
        );

    });

});

function $hide(id) {
    document.getElementById(id).style.display = "none";
}

function pageUnload() {

}

function kocak_widget_sonuc_al(sonuc_veri) {
    if (sonuc_veri == -1)
        alert("Serviste bir hata oluştu!");
    else if (sonuc_veri == 0 && document.getElementById("kocak_widget_oturum_uyari").value == "0") {
        //alert("Bu işlemin kalıcı olması için oturum açmalısınız!");
        document.getElementById("kocak_widget_oturum_uyari").value = "1";
    }
    return sonuc_veri;
}

function kontrol_ac_kapat(id) {
    if (document.getElementById(id).className == "kocak_masaustu_kontrol kocak_masaustu_kontrol_kapali")
        document.getElementById(id).className = "kocak_masaustu_kontrol kocak_masaustu_kontrol_acik";
    else
        document.getElementById(id).className = "kocak_masaustu_kontrol kocak_masaustu_kontrol_kapali";
}


/*
function showHelp()
{
var request = new Sys.Net.WebRequest();
request.set_httpVerb("GET");
request.set_url('help.aspx');
request.add_completed( function( executor )
{
if (executor.get_responseAvailable()) 
{
var helpDiv = $get('HelpDiv');
var helpLink = $get('HelpLink');
            
var helpLinkBounds = Sys.UI.DomElement.getBounds(helpLink);
            
helpDiv.style.top = (helpLinkBounds.y + helpLinkBounds.height) + "px";
            
var content = executor.get_responseData();
helpDiv.innerHTML = content;
helpDiv.style.display = "block";                       
}
});
    
var executor = new Sys.Net.XMLHttpExecutor();
request.set_executor(executor); 
executor.executeRequest();
}
*/
var Utility =
{
    // change to display:none
    nodisplay: function(e) {
        if (typeof e == "object") e.style.display = "none"; else if ($get(e) != null) $get(e).style.display = "none";
    },
    // change to display:block
    display: function(e, inline) {
        if (typeof e == "object") e.style.display = (inline ? "inline" : "block"); else if ($get(e) != null) $get(e).style.display = (inline ? "inline" : "block");
    },
    getContentHeight: function() {
        if (document.body && document.body.offsetHeight) {
            return document.body.offsetHeight;
        }
    },


    blockUI: function() {
        Utility.display('blockUI');
        var blockUI = $get('blockUI');

        if (blockUI != null) // it will be null if called from CompactFramework
            blockUI.style.height = Math.max(Utility.getContentHeight(), 1000) + "px";
    },

    unblockUI: function() {
        Utility.nodisplay('blockUI');
    }
};

var DeleteWarning =
{
    yesCallback: null,
    noCallback: null,
    _initialized: false,
    init: function() {
        if (DeleteWarning._initialized) return;

        var hiddenHtmlTextArea = $get('DeleteConfirmPopupPlaceholder');
        var html = hiddenHtmlTextArea.value;
        var div = document.createElement('div');
        div.innerHTML = html;
        document.body.appendChild(div);

        DeleteWarning._initialized = true;
    },
    show: function(yesCallback, noCallback) {
        DeleteWarning.init();

        Utility.blockUI();

        var popup = $get('DeleteConfirmPopup');
        Utility.display(popup);

        DeleteWarning.yesCallback = yesCallback;
        DeleteWarning.noCallback = noCallback;

        $addHandler($get("DeleteConfirmPopup_Yes"), 'click', DeleteWarning._yesHandler);
        $addHandler($get("DeleteConfirmPopup_No"), 'click', DeleteWarning._noHandler);
    },
    hide: function() {
        DeleteWarning.init();

        var popup = $get('DeleteConfirmPopup');
        Utility.nodisplay(popup);

        $clearHandlers($get('DeleteConfirmPopup_Yes'));

        Utility.unblockUI();

    },
    _yesHandler: function() {
        DeleteWarning.hide();
        DeleteWarning.yesCallback();
    },
    _noHandler: function() {
        DeleteWarning.hide();
        DeleteWarning.noCallback();
    }
};