function addNew(gdate) {
    var d = new Date(gdate);
    var y = d.getFullYear();
    var m = d.getMonth();
    var g = d.getDate();
   
var hours = d.getHours();
var mins = d.getMinutes();
    $('#yil').val(y);
    $('#ay').val(m+1);
    $('#gun').val(g);

    $('#saat').val(hours);
    $('#dakika').val(mins);    

    $("#newEvent").dialog({
                bgiframe: true,
                buttons: {  "Close": function() { $(this).dialog("destroy"); }, 
                            "Save": function() { 
                                        saveNew('save');
                                        $(this).dialog("destroy"); 
                                    } 
                        }, 
                closeOnEscape: true,
                modal:true, 
                title: 'New'
                            });
}

function saveNew(act) {
    var a = document.getElementById('saat').value + ':' + document.getElementById('dakika').value + ':00';
    var b = document.getElementById('yil').value + '-' + document.getElementById('ay').value + '-' + document.getElementById('gun').value;
    var c = document.getElementById('twitt').value;
    var d = document.getElementById('eventId').value;
$.ajax({
        type: 'POST',
        url: 'xml_event.php',
        data: 'c='+c+'&b='+b+'&a='+a+'&act='+act+'&userid='+userid+'&event='+d,
        success: function(ajaxCevap) {
            if (ajaxCevap=='ok') {
                document.location='.';
            } else if(ajaxCevap=='date') {
		showBox("You can't save entry before now!");
	    } else if(ajaxCevap=='time') {
		showBox("You can't save entry for same time");
	    }
            }
        });
}

function showBox(message) {
	    $('#msgBox').html(message);
	    $("#msgBox").dialog({
                bgiframe: true,
                buttons: {  "Close": function() { $(this).dialog("destroy"); }
                        }, 
                closeOnEscape: true,
                modal:true, 
                title: 'Message'
                            });

}

function eventBox(id,twitt,oDate) {

    var d = new Date(oDate);
    var y = d.getFullYear();
    var m = d.getMonth();
    var g = d.getDate();
   
    $('#yil').val(y);
    $('#ay').val(m+1);
    $('#gun').val(g);
    
    $("#eventId").val(id);
    $("#twitt").val(twitt);
    //Mon Aug 10 2009 13:44:00 GMT+0300 (EET)
    oDate = new String(oDate);
    var spDate = oDate.split(" ");
    var spTime = spDate[4].split(":");
    $("#saat").val(spTime[0]);
    $("#dakika").val(spTime[1]);

    $("#newEvent").dialog({
                bgiframe: true,
                buttons: {  "Close": function() { $(this).dialog("destroy"); }, 
                            "Save": function() { 
                                        saveNew('update');
                                        $(this).dialog("destroy"); 
                                    },
                            "Delete": function() {saveNew('delete'); $(this).dialog("destroy");}
                        }, 
                closeOnEscape: true,
                modal:true, 
                title: 'Edit'
                            });
}

function saveGMT() {
     $("#timeZone").dialog({
                bgiframe: true,
                buttons: {"Save": function() {  
                $.ajax({
                    type: 'POST',
                    url: 'xml_save_gmt.php',
                    data: 'userid='+userid+'&gmt='+$('#sel_timezoneoffset').val(),
                    success: function(ajaxCevap) {
                            $(this).dialog("destroy");
                        }
                    });
         $(this).dialog("destroy");
                    }
                        }, 
                closeOnEscape: false,
                modal:true, 
                title: 'Select Time Zone'
                            });

}

function loadTimeFeed() {
$.ajax({
        type: 'POST',
        url: 'xml_time_feed.php',
        data: 'homePage=yes',
        success: function(ajaxCevap) {
            $("#hp_time").html(ajaxCevap);
            $("#hp_time").animate({ backgroundColor: "red" }, 1000);
            $("#hp_time").animate({ backgroundColor: "" }, 1000);

            }
        });
$.ajax({
        type: 'POST',
        url: 'xml_last_users.php',
        data: 'homePage=yes',
        success: function(ajaxCevap) {
            $("#hp_last").html(ajaxCevap);
            }
        });

}
