/**
 *
 * basic stuff
 * we love you, too
 *
 * prototype extention
 *
 *
 * notice.info('save done');
 * notice.error('error);
 * notice.wait();
 *
 * @author $Author: rieger $
 *
 * @version $Id: basic.js 2409 2010-11-13 17:53:54Z rieger $
 *
 * @copyright $Date: 2010-11-13 18:53:54 +0100 (Sat, 13 Nov 2010) $ October Labs
 *
 */
// Firebug workrout für ie foo ;)
if (! window.console) {
	var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
	"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

	window.console = {};
	for (var i = 0; i < names.length; ++i)
		window.console[names[i]] = function() {}
}

function get_anchor() {
  var anchor = document.location.hash.substring(1) ; // url.hash.substring(1);
  return anchor;
}

var ElementHelper = {
  removeChilds: function(element){
    element = $(element);
    while (element.hasChildNodes()) {
      var delNode = element.firstChild;
      element.removeChild(delNode);
    }
    return element;
  },

  getAncher: function(element){
    element = $(element);
    var result = '';
    if (element.href != '') {
      var matches = element.href.match(/#(.+)$/);
      if (matches && matches.length == 2)
        result = matches[1];
    }
    return result;
  },
  
  /**
   * add (string) myValue in textarea or input on curent pos
   */
  insertAtCursor: function(element, myValue) {  
    element = $(element);    
    if (document.selection) {
      //IE support
      element.focus();
      sel = document.selection.createRange();
      sel.text = myValue;
    } else { 
      // MOZILLA/NETSCAPE support
      if (element.selectionStart || element.selectionStart == '0') {      
        var startPos = element.selectionStart;
        var endPos = element.selectionEnd;
        element.value = element.value.substring(0, startPos)
          + myValue
          + element.value.substring(endPos, element.value.length);
      } else {
        element.value += myValue;
      }
    }
  }
  
}

Element.addMethods(ElementHelper);


