function simulatedClick(target, options) 
{
  var event = target.ownerDocument.createEvent('MouseEvents'),
      options = options || {};

  //Set your default options to the right of ||
  var opts = {
      type: options.type                  || 'click',
      canBubble:options.canBubble             || true,
      cancelable:options.cancelable           || true,
      view:options.view                       || target.ownerDocument.defaultView, 
      detail:options.detail                   || 1,
      screenX:options.screenX                 || 0, //The coordinates within the entire page
      screenY:options.screenY                 || 0,
      clientX:options.clientX                 || 0, //The coordinates within the viewport
      clientY:options.clientY                 || 0,
      ctrlKey:options.ctrlKey                 || false,
      altKey:options.altKey                   || false,
      shiftKey:options.shiftKey               || false,
      metaKey:options.metaKey                 || false, //I *think* 'meta' is 'Cmd/Apple' on Mac, and 'Windows key' on Win. Not sure, though!
      button:options.button                   || 0, //0 = left, 1 = middle, 2 = right
      relatedTarget:options.relatedTarget     || null,
  }

  //Pass in the options
  event.initMouseEvent(
      opts.type,
      opts.canBubble,
      opts.cancelable,
      opts.view, 
      opts.detail,
      opts.screenX,
      opts.screenY,
      opts.clientX,
      opts.clientY,
      opts.ctrlKey,
      opts.altKey,
      opts.shiftKey,
      opts.metaKey,
      opts.button,
      opts.relatedTarget
  );

  //Fire the event
  target.dispatchEvent(event);
}

// -------------------------------------------------------------------------------------------------
function updateTextLimitCounter(form, maxlimit) 
{
  var currentListText = $(form).find("#fmTextContent");
  var currentListTextCounter = $(form).find("#fmCharacterCount")
  
  var entryText = currentListText.val();
  
  if (entryText.length > maxlimit)                            // if the current length is more than allowed
    currentListText.val( entryText.substring(0, maxlimit) );  // trim it back
  
  currentListTextCounter.val( (maxlimit - entryText.length) );
}

// -------------------------------------------------------------------------------------------------
function UIInputButton_disableForAjax(domButton)
{
  if (domButton != undefined)
  {
    // disable the button handler, to disable it for the duration of the AJAX post
    var prevOnclick = $(domButton).attr('onclick'); 
    $(domButton).attr('onclick','');
    
    // switch to a little progress indicator
    var prevHTMLContents = $(domButton).html();
    $(domButton).html('<img src="images/ajax-loader-fb.gif"/>');
    $(domButton).fadeTo('fast', 0.5);
     
    // grab the text to send
    var domTextWindow = $(domButton).siblings('form').children('#fmTextContent');
    var messageText = domTextWindow.val();
    domTextWindow.attr('readonly','readonly');

    // check for and support image posts
    if (messageText == undefined)
    {
      var sketchCanvas = $('#UISketchCanvas').get(0);
      if (sketchCanvas != undefined)
      {
        messageText = sketchCanvas.toDataURL('image/png');
      }
    }

    var resultArray = new Array();
    resultArray['DomTextWindow'] = domTextWindow;
    resultArray['PrevOnclick'] = prevOnclick;
    resultArray['PrevHTMLContents'] = prevHTMLContents;
    resultArray['MessageText'] = messageText;
    
    return resultArray;
  }
}

// -------------------------------------------------------------------------------------------------
function RewireTheFuckingButtons()
{
  $('.button').filter('a').each(function(index, elem) 
  {
    if ($(this).attr('title'))
    {
      var evalCode = $(this).attr('title');
      $(this).click(function(ev){
        eval( evalCode );
        ev.preventDefault();
        ev.stopPropagation();
      });
      
      $(this).removeAttr('title');
      $(this).attr('href', '#');
      $(this).attr('tabindex', 0);
    }
  });
  
  $(document).delegate('.ui-dialog', 'keyup', function(e) {
        var tagName = e.target.tagName.toLowerCase();

        tagName = (tagName === 'input' && e.target.type === 'button') ? 'button' : tagName;

        if (e.which === $.ui.keyCode.ENTER && tagName !== 'textarea' && tagName !== 'select' && tagName !== 'button') {
            $(this).find('.ui-dialog-buttonset button').eq(0).trigger('click');

            return false;
        }
    });
}

// -------------------------------------------------------------------------------------------------
function NotifyThatThereIsNewNews()
{
  $(function() {

    $('html, body').animate(
    {
      scrollTop: 0
    }, 1000);
    
    $("<div id='news-dialog' title='Oh My God You Guys'><p>There's new <a href='news.php' style='color:blue !important;'>news</a>!</p></div>").dialog({
        autoOpen: true,
        modal: true,
        resizable: false,
        width: 250});

  });
}

/*
Copyright Vassilis Petroulias [DRDigit]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var B64 = {
    alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
    lookup: null,
    ie: /MSIE /.test(navigator.userAgent),
    ieo: /MSIE [67]/.test(navigator.userAgent),
    encode: function (s) {
        var buffer = B64.toUtf8(s),
            position = -1,
            len = buffer.length,
            nan1, nan2, enc = [, , , ];
        if (B64.ie) {
            var result = [];
            while (++position < len) {
                nan1 = buffer[position + 1], nan2 = buffer[position + 2];
                enc[0] = buffer[position] >> 2;
                enc[1] = ((buffer[position] & 3) << 4) | (buffer[++position] >> 4);
                if (isNaN(nan1)) enc[2] = enc[3] = 64;
                else {
                    enc[2] = ((buffer[position] & 15) << 2) | (buffer[++position] >> 6);
                    enc[3] = (isNaN(nan2)) ? 64 : buffer[position] & 63;
                }
                result.push(B64.alphabet[enc[0]], B64.alphabet[enc[1]], B64.alphabet[enc[2]], B64.alphabet[enc[3]]);
            }
            return result.join('');
        } else {
            result = '';
            while (++position < len) {
                nan1 = buffer[position + 1], nan2 = buffer[position + 2];
                enc[0] = buffer[position] >> 2;
                enc[1] = ((buffer[position] & 3) << 4) | (buffer[++position] >> 4);
                if (isNaN(nan1)) enc[2] = enc[3] = 64;
                else {
                    enc[2] = ((buffer[position] & 15) << 2) | (buffer[++position] >> 6);
                    enc[3] = (isNaN(nan2)) ? 64 : buffer[position] & 63;
                }
                result += B64.alphabet[enc[0]] + B64.alphabet[enc[1]] + B64.alphabet[enc[2]] + B64.alphabet[enc[3]];
            }
            return result;
        }
    },
    decode: function (s) {
        var buffer = B64.fromUtf8(s),
            position = 0,
            len = buffer.length;
        if (B64.ieo) {
            result = [];
            while (position < len) {
                if (buffer[position] < 128) result.push(String.fromCharCode(buffer[position++]));
                else if (buffer[position] > 191 && buffer[position] < 224) result.push(String.fromCharCode(((buffer[position++] & 31) << 6) | (buffer[position++] & 63)));
                else result.push(String.fromCharCode(((buffer[position++] & 15) << 12) | ((buffer[position++] & 63) << 6) | (buffer[position++] & 63)));
            }
            return result.join('');
        } else {
            result = '';
            while (position < len) {
                if (buffer[position] < 128) result += String.fromCharCode(buffer[position++]);
                else if (buffer[position] > 191 && buffer[position] < 224) result += String.fromCharCode(((buffer[position++] & 31) << 6) | (buffer[position++] & 63));
                else result += String.fromCharCode(((buffer[position++] & 15) << 12) | ((buffer[position++] & 63) << 6) | (buffer[position++] & 63));
            }
            return result;
        }
    },
    toUtf8: function (s) {
        var position = -1,
            len = s.length,
            chr, buffer = [];
        if (/^[\x00-\x7f]*$/.test(s)) while (++position < len)
        buffer.push(s.charCodeAt(position));
        else while (++position < len) {
            chr = s.charCodeAt(position);
            if (chr < 128) buffer.push(chr);
            else if (chr < 2048) buffer.push((chr >> 6) | 192, (chr & 63) | 128);
            else buffer.push((chr >> 12) | 224, ((chr >> 6) & 63) | 128, (chr & 63) | 128);
        }
        return buffer;
    },
    fromUtf8: function (s) {
        var position = -1,
            len, buffer = [],
            enc = [, , , ];
        if (!B64.lookup) {
            len = B64.alphabet.length;
            B64.lookup = {};
            while (++position < len)
            B64.lookup[B64.alphabet[position]] = position;
            position = -1;
        }
        len = s.length;
        while (position < len) {
            enc[0] = B64.lookup[s.charAt(++position)];
            enc[1] = B64.lookup[s.charAt(++position)];
            buffer.push((enc[0] << 2) | (enc[1] >> 4));
            enc[2] = B64.lookup[s.charAt(++position)];
            if (enc[2] == 64) break;
            buffer.push(((enc[1] & 15) << 4) | (enc[2] >> 2));
            enc[3] = B64.lookup[s.charAt(++position)];
            if (enc[3] == 64) break;
            buffer.push(((enc[2] & 3) << 6) | enc[3]);
        }
        return buffer;
    }
};
