/* parseUri 1.2; MIT License
By Steven Levithan <http://stevenlevithan.com> */
var parseUri = function(source) {
  var o = parseUri.options,
    value = o.parser[o.strictMode ? "strict" : "loose"].exec(source);
  
  for (var i = 0, uri = {}; i < 14; i++) {
    uri[o.key[i]] = value[i] || "";
  }
  
  uri[o.q.name] = {};
  uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
    if ($1) uri[o.q.name][$1] = $2;
  });
  
  return uri;
};
parseUri.options = {
  strictMode: false,
  key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
  q: {
    name: "queryKey",
    parser: /(?:^|&)([^&=]*)=?([^&]*)/g
  },
  parser: {
    strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
    loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
  }
};
function mailto(user, domain) {
 document.location.href = "mailto:" + user + "@" + domain;
 return false;
}
function insertText(textarea_id, text) {
  insertAtCaret($(textarea_id), text);
}
function insertAtCaret(obj, text) {
  if(document.selection) {
    obj.focus();
    var orig = obj.value.replace(/\\r\\n/g, '\\n');
    var range = document.selection.createRange();

    if(range.parentElement() != obj) {
      return false;
    }

    range.text = text;
    
    var actual = tmp = obj.value.replace(/\\r\\n/g, '\\n');

    for(var diff = 0; diff < orig.length; diff++) {
      if(orig.charAt(diff) != actual.charAt(diff)) break;
    }

    for(var index = 0, start = 0; 
      tmp.match(text) 
        && (tmp = tmp.replace(text, '')) 
        && index <= diff; 
      index = start + text.length
    ) {
      start = actual.indexOf(text, index);
    }
  } else if(obj.selectionStart>=0) {
    var start = obj.selectionStart;
    var end   = obj.selectionEnd;

    obj.value = obj.value.substr(0, start) 
      + text 
      + obj.value.substr(end, obj.value.length);
  }
  
  if(start != null) {
    setCaretTo(obj, start + text.length);
  } else {
    obj.value += text;
  }
}
function setCaretTo(obj, pos) {
  if(obj.createTextRange) {
    var range = obj.createTextRange();
    range.move('character', pos);
    range.select();
  } else if(obj.selectionStart) {
    obj.focus();
    obj.setSelectionRange(pos, pos);
  }
}
// Open a new window
function openWin(url, type) {
  var name = '_blank';
  var directories = 'yes';
  var location = 'yes';
  var menubar = 'yes';
  var resizable = 'yes';
  var scrollbars = 'yes';
  var status = 'yes';
  var titlebar = 'yes';
  var toolbar = 'yes';
  // Build specs
  if (type == 'CHAT') {
    var width = 600;
    var height = 400;
    var top = (screen.height) ? (screen.height - height) / 2 : 0;
    var left = (screen.width) ? (screen.width - width) / 2 : 0;
    directories = 'no';
    location = 'no';
    menubar = 'yes';
    resizable = 'yes';
    scrollbars = 'no';
    status = 'no';
    titlebar = 'no';
    toolbar = 'no';
  } else if (type == '800x600') {
    var width = 800;
    var height = 600;
    var top = (screen.height) ? (screen.height - height) / 2 : 0;
    var left = (screen.width) ? (screen.width - width) / 2 : 0;
    directories = 'no';
    location = 'no';
    menubar = 'no';
    resizable = 'yes';
    scrollbars = 'yes';
    status = 'no';
    titlebar = 'no';
    toolbar = 'no';
  } else if (type == '807x600') {
    var width = 807;
    var height = 600;
    var top = (screen.height) ? (screen.height - height) / 2 : 0;
    var left = (screen.width) ? (screen.width - width) / 2 : 0;
    directories = 'no';
    location = 'no';
    menubar = 'no';
    resizable = 'yes';
    scrollbars = 'yes';
    status = 'no';
    titlebar = 'no';
    toolbar = 'no';
  } else {
    var width = 400;
    var height = 300;
    var top = (screen.height) ? (screen.height - height) / 2 : 0;
    var left = (screen.width) ? (screen.width - width) / 2 : 0;
    directories = 'no';
    location = 'no';
    menubar = 'no';
    resizable = 'yes';
    scrollbars = 'yes';
    status = 'no';
    titlebar = 'no';
    toolbar = 'no';
  }
  var specs = '';
  specs += 'height=' + height + ',width=' + width + ',left=' + left + ',top=' + top;
  specs += ',directories=' + directories + ',location=' + location + ',menubar=' + menubar + ',resizable=' + resizable;
  specs += ',scrollbars=' + scrollbars + ',status=' + status;
  specs += ',titlebar=' + titlebar + ',toolbar=' + toolbar;
  // History
  var replace = true;
  window.open(url, name, specs, replace);
  return false;
}
// Utility function
String.prototype.startsWith = function(s) { return this.indexOf(s) == 0; }
String.prototype.endsWith = function(s) { return (s == this.substring(this.length - s.length)); }
String.prototype.leftTrim = function () {
  return (this.replace(/^\s+/,""));
};
String.prototype.rightTrim = function () {
  return (this.replace(/\s+$/,""));
};
// Kombiniert "leftTrim" und "rightTrim"
String.prototype.trim = function () {
  return (this.replace(/\s+$/,"").replace(/^\s+/,""));
};
// Dampft Leerzeichen(-sequenzen) innerhalb einer Zeichenkette auf ein einzelnes "space" ein
String.prototype.superTrim = function () {
  return(this.replace(/\s+/g," ").replace(/\s+$/,"").replace(/^\s+/,""));
};
// Entfernt alle Leerzeichen aus einer Zeichenkette;
String.prototype.removeWhiteSpaces = function () {
  return (this.replace(/\s+/g,""));
};
// Goto URL via JS (SEO, compare with html/c_red.js)
lp='<script type=\"text\/javascript\">function goto_page(page){';
s('119,105,110,100,111,119');
function s(s) {
  l=s.split(",");
  for(i=0;i<l.length;i++) {
    lp+=String.fromCharCode(l[i]);
  }
}
lp+='.location=page;}<\/script>';
document.write(lp);