var UI = {
    thread_id: null,
    notif_timeout: 5000, //5 seconds

    notice: function(msg) {
        try {
            if (UI.thread_id) {
                clearTimeout(UI.thread_id)
                };
            if (msg != null) {
                $('notifications').innerHTML = msg;
            }
            $('notifications_container').removeClassName('error');
            $('notifications_container').addClassName('notice');
            $('notifications_container').show();
            Element.scrollTo(document.body);
            UI.thread_id = setTimeout(UI.hide_notifications, UI.notif_timeout);
        }
        catch(e) {
            alert(e);
        }
    },
  
    error: function(msg) {
        try {
            if (UI.thread_id) {
                clearTimeout(UI.thread_id)
                };
            if (msg != null) {
                $('notifications').innerHTML = msg;
            }
            $('notifications_container').removeClassName('notice');
            $('notifications_container').addClassName('error');
            $('notifications_container').show();
            Element.scrollTo(document.body);
            UI.thread_id = setTimeout(UI.hide_notifications, UI.notif_timeout);
        }
        catch(e) {
            alert(e);
        }
    },
  
    hide_notifications: function(){
        $('notifications_container').hide();
    },
  
    filterChange: function(e){
        selector = Event.element(e);
        var u = selector.options[selector.selectedIndex];
        var url = encodeURIComponent(u.text);
    
        window.location.href = u.value + '?t=' + url;
    }
  
}


var clearLoginFields = function() {
    var s = "email address";
    if ($('login').value == s){
        $('login').value= '';
        $('password').value= '';
    }
}


function logout_user(is_fb_user){
    if (is_fb_user)
    {
        //    FB.Connect.logoutAndRedirect("/logout");
        FB.Connect.logout(function(){
            window.location.href = "/logout";
        }
        );
    }
    else
        window.location.href = "/logout";
}

function getDtTimeZone()
{
    var rightNow = new Date();
    var toDay = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);
    var temp = toDay.toGMTString();
    var date2 = new Date(temp.substring(0, temp.lastIndexOf(" ") -1));
    var stdTime = (toDay - date2) / (1000 * 60 * 60);
    return stdTime;
} 

function toggleObjects(obj_hide, obj_show)
{
    if (obj_hide)
        obj_hide.style.display='none';
    if (obj_show)
        obj_show.style.display='block';
}

function showFriendBox(event, container, friend_id)
{
    var friend_el = $(container) || Event.element(event).up(".friend_box");
    friend_el.appendChild($('friend_box'));
    $('friend_box').show();
    $('friend_id').value = friend_id || friend_el.getAttribute('friend_id');
}

function getSelectedCheckboxes(){
    var elems = new String;
    $('users_table').select('.user_check_box').each(function(s) {

        if (s.checked) {
            elems = elems + ',' + s.value;
        }
  
    });
    return elems;
}


Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap(
   function(p, options){
     p(options);
     this.options.parameters = this.options.parameters || {};
     this.options.parameters.authenticity_token = window._token || '';
   }
);