function formatTime ( time ) {
    var remainder;
    var hours = time / ( 60 * 60 );
    remainder = hours - (Math.floor ( hours ));
    hours = Math.floor ( hours );
    var minutes = remainder * 60;
    remainder = minutes - (Math.floor ( minutes ));
    minutes = Math.floor ( minutes );
    var seconds = remainder * 60;
    remainder = seconds - (Math.floor ( seconds ));
    seconds = Math.floor ( seconds );
    var hString = hours < 10 ? "0" + hours : "" + hours;
    var mString = minutes < 10 ? "0" + minutes : "" + minutes;
    var sString = seconds < 10 ? "0" + seconds : "" + seconds;
    if ( time < 0 || isNaN(time)) return "00:00";
    if ( hours > 0 )    {
        return hString + ":" + mString + ":" + sString;
    }else{
        return mString + ":" + sString;
    }
}

String.prototype.between = function(prefix, suffix) {
  s = this;
  var i = s.indexOf(prefix);
  if (i >= 0) {
    s = s.substring(i + prefix.length);
  }
  else {
    return '';
  }
  if (suffix) {
    i = s.indexOf(suffix);
    if (i >= 0) {
      s = s.substring(0, i);
    }
    else {
      return '';
    }
  }
  return s;
}

if(!Array.indexOf){
    Array.prototype.indexOf = function(obj){
        for(var i=0; i<this.length; i++){
            if(this[i]==obj){
                return i;
            }
        }
        return -1;
    }
}

if(!Array.sortOn){
    Array.prototype.sortOn = function($key){
        this.sort(
                function(a, b){
                    return (a[$key] > b[$key]) - (a[$key] < b[$key]);
                }
            );
    };
};

function foreach($haystack, $callback){
    for(var i in $haystack){
        if(typeof($haystack[i]) != 'function'){
            $callback(i, $haystack[i]);
        };
    };
};

function stripHTML(html) {
    return $('<div>' + html + '</div>').text();
}

function defaultInputTextBoxes(){
    $('input[type=text]').unbind('focus');
    $('input[type=text]').unbind('blur');

    $('input[type=text]').each(function(){
        $(this).attr('default', $(this).val());
    });

    $('input[type=text]').focus(function(){
        if($(this).val() == $(this).attr('default')){
            $(this).val('');
        };
    });

    $('input[type=text]').blur(function(){
        if($(this).val() == ''){
            $(this).val($(this).attr('default'));
        };
    });
};


function applyPlaceholderTextSupport(){
    var _phSupport = 'placeholder' in (document.createElement('input'));

    // apply to all textfields with defined type
    $('input[type=text]').each(function(){
        // save ref
        var _ref = $(this);

        if(_ref.hasClass('no-placeholder'))
            return false;

        // html5
        if(_phSupport){
            this.placeholder    =   this.value;
            this.value      =   '';
        }else{
        // old school
            _ref.data('placeholder', this.value);
            _ref.focus(function(){if(this.value==_ref.data('placeholder')){this.value='';};})
                .blur(function(){ if(this.value==''){this.value=_ref.data('placeholder')};});
        };
    });
};

