var Cookie = {
  set: function(name, value, daysToExpire) {
    var expire = '';
    if (daysToExpire != undefined) {
      var d = new Date();
      d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
      expire = '; expires=' + d.toGMTString();
    }
    return (document.cookie = escape(name) + '=' + escape(value || '') + expire + '; path=/');
  },
  get: function(name) {
    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
    return (cookie ? unescape(cookie[2]) : null);
  },
  erase: function(name) {
    var cookie = Cookie.get(name) || true;
    Cookie.set(name, '', -1);
    return cookie;
  },
  accept: function() {
    if (typeof navigator.cookieEnabled == 'boolean') {
      return navigator.cookieEnabled;
    }
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') === '1');
  }
};

var awesomeo = 0;

if (Cookie.get('_sidebar') == '1')
{
    awesomeo = 1;
    // Hide the sidebar at start.
    $('sidebar').hide();
    $('page').style.marginLeft = "0px";
    //$('sidebartoggle').style.color = "#eeeeec;"
    $('sidebartoggle').style.top = "0px";
}

function toggleSidebar()
{
    Effect.toggle('sidebar', 'blind');
    if (awesomeo == 0)
    {
        Cookie.set('_sidebar', '1');
        awesomeo = 1;
        $('page').style.marginLeft = "0px";
        //$('sidebartoggle').style.color = "#eeeeec;"
        $('sidebartoggle').style.top = "0px";
    }
    else
    {
        awesomeo = 0;
        Cookie.erase('_sidebar');
        $('page').style.marginLeft = "175px";
        $('sidebartoggle').style.top = "-50px";
        //$('sidebartoggle').style.color = "#2e3436";
    }
}

function addToList(div, ptxt)
{
    prompttxt = "Value:";
    if (ptxt) {
        prompttxt = ptxt;
    }
    
    var d = prompt(prompttxt, "");
    if (d)
    {
        var e = document.createElement('option');
        e.text = d;
        try
        {
            // W3C
            $(div+"-box").add(e, null);
        }
        catch(ex)
        {
            //alert(ex);
            // IE
            $(div+"-box").add(e);
        }
        
        $(div).value += d + ",";
        
        $((div+"-box")).selectedIndex = $((div+"-box")).options.length - 1;
        
        Effect.Appear(div + '-removebtn');
        new Effect.Highlight(div + '-box');
    }
}

function removeFromList(div)
{
    var start = $(div+"-box").selectedIndex;
    $(div+"-box").remove(start);
    // Current items in array
    var items = $(div).value.split(',');
    items = items.splice(items.length -1, 1);
    $(div).value = items.join(',') + ",";
    if ($(div+"-box").selectedIndex != start)
    {
        //new Effect.Highlight(div);
    }
    
    // Check if there's anymore items left.
    if ($(div+"-box").options.length == 0)
    {
        // Hide the remove button for zaaroo ooptoons.
        Effect.SwitchOff(div + '-removebtn');
    }
    else
    {
        // Update newly selected.
        $(div+"-box").selectedIndex = start - 1;
    }
}
