﻿$(document).ready(function() {

    var COOKIE_TAB = 'selectedTab';

    $('input.date').datepicker({
        dateFormat: "dd.mm.yy"
    });

    $('input.daterange').datepicker({ dateFormat: "dd.mm.yy", rangeSelect: true, firstDay: 1 });

    var $tabs = $(".tabs > ul").tabs({
        select: function(e, ui) {
            $.cookie(COOKIE_TAB, ui.panel.id, { path: '/', expires: 100 });
        }


    });

    if ($.cookie(COOKIE_TAB) != "") {
        $tabs.tabs('select', $.cookie(COOKIE_TAB)); // switch to third tab
    }

    $("#addmilestone").click(function(event) {
        event.preventDefault();
        $.modal('<iframe style="height:400px;width:100%;border:none;" src="KullaniciListele.aspx"></iframe>', { width: 120 });
    });
    $("#feedback").click(function(event) {
        event.preventDefault();
        $.modal('<iframe style="height:400px;width:100%;border:none;" src="/MoEF_IPAProjectsWEB/Feedback"></iframe>', { width: 120 });
    });

    $(".taskedit").click(function(event) {
        event.preventDefault();
        $.modal('<iframe style="height:400px;width:100%;border:none;" src="/MoEF_IPAProjectsWEB/Projects/Tasks/TaskEdit.aspx?tID=' + this.id + '"></iframe>', { width: 120 });
    });

    $(".todoedit").click(function(event) {
        event.preventDefault();
        $.modal('<iframe style="height:400px;width:100%;border:none;" src="/MoEF_IPAProjectsWEB/Calendar/TodoEdit.aspx?tUN=' + this.id + '"></iframe>', { width: 120 });
    });
    
     $(".popupsatissart").click(function(event) {
        event.preventDefault();
        $.modal('<iframe style="height:400px;width:100%;border:none;" src="genpopup.aspx?xMode=deneme&cID=02bc3616-b46c-4716-aa5f-a29cee74e63f"></iframe>', { width: 120 });
    });


    $(function() {
        $('.GenelTooltip').tooltip({
            track: true,
            delay: 0,
            showURL: false,
            showBody: " - ",
            fade: 350
        });
    });



    $(".parentprojecttoggle").click(function(event) {
        event.preventDefault();
        $("." + $(this)[0].id).toggle("");
        if ($(this).hasClass("closed")) {
            $(this).addClass("opened").removeClass("closed");
            $(this)[0].src = "/MoEF_IPAProjectsWEB/images/icons/up.png";
        }
        else {

            $(this).addClass("closed").removeClass("opened");
            $(this)[0].src = "/MoEF_IPAProjectsWEB/images/icons/down.png";
        }
    });

    $(".rootimg").click(function(event) {
        event.preventDefault();
        $("#" + $(this)[0].id).parent().find("ul").toggle("");

    });


    $(".confirm").click(function(event) {

        if (confirm("Bu işlemi yapmak istediğize emin misiniz?")) {
            return true;
        }
        else {
            event.preventDefault();
            return false;
        }

    });


    $(".calendar").contextMenu({
        menu: 'myMenu'
    },
			    function(action, el, pos) {

			        if (action == "edit") {

			            $.modal('<iframe style="height:400px;width:100%;border:none;" src="/MoEF_IPAProjectsWEB/Calendar/TodoEdit.aspx?pID=' + this.id + '"></iframe>', { width: 120 });
			        } else if (action == "cut") {
			            $.modal('<iframe style="height:400px;width:100%;border:none;" src="/MoEF_IPAProjectsWEB/Calendar/Events.aspx?pID=' + this.id + '"></iframe>', { width: 120 });
			        }
			        
//			        alert(
//						'Action: ' + action + '\n\n' +
//						'Element ID: ' + $(el).attr('id') + '\n\n' +
//						'X: ' + pos.x + '  Y: ' + pos.y + ' (relative to element)\n\n' +
//						'X: ' + pos.docX + '  Y: ' + pos.docY + ' (relative to document)'
//						);
						
			    });


    // Show menu when #myDiv is clicked

    // bunlari sonra itemlari secmek icin kullanacagim.. 

    $("#myDiv").contextMenu({
        menu: 'myMenu'
    },
					function(action, el, pos) {
					    alert(
						'Action: ' + action + '\n\n' +
						'Element ID: ' + $(el).attr('id') + '\n\n' +
						'X: ' + pos.x + '  Y: ' + pos.y + ' (relative to element)\n\n' +
						'X: ' + pos.docX + '  Y: ' + pos.docY + ' (relative to document)'
						);
					});

    // Show menu when a list item is clicked
    $("#myList UL LI").contextMenu({
        menu: 'myMenu'
    }, function(action, el, pos) {
        alert(
						'Action: ' + action + '\n\n' +
						'Element text: ' + $(el).text() + '\n\n' +
						'X: ' + pos.x + '  Y: ' + pos.y + ' (relative to element)\n\n' +
						'X: ' + pos.docX + '  Y: ' + pos.docY + ' (relative to document)'
						);
    });

    // Disable menus
    $("#disableMenus").click(function() {
        $('#myDiv, #myList UL LI').disableContextMenu();
        $(this).attr('disabled', true);
        $("#enableMenus").attr('disabled', false);
    });

    // Enable menus
    $("#enableMenus").click(function() {
        $('#myDiv, #myList UL LI').enableContextMenu();
        $(this).attr('disabled', true);
        $("#disableMenus").attr('disabled', false);
    });

    // Disable cut/copy
    $("#disableItems").click(function() {
        $('#myMenu').disableContextMenuItems('#cut,#copy');
        $(this).attr('disabled', true);
        $("#enableItems").attr('disabled', false);
    });

    // Enable cut/copy
    $("#enableItems").click(function() {
        $('#myMenu').enableContextMenuItems('#cut,#copy');
        $(this).attr('disabled', true);
        $("#disableItems").attr('disabled', false);
    });


});
