/**
 * Add an eventHandler to a node
 * 
 * @version 1.0
 * @param object obj The node at which event will be added
 * @param string evType Which event will be called
 * @param string fn The function that will be called
 * @param boolean useCapture
 */
function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
}


function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}




function initObj() {      
      this.path = 'js/';       
}

initObj.prototype.load = function(param) {       
	
      init.param = param;      
}

initObj.prototype.call = function() {         
	    
      if(extJs) return true;
        
      for(var i = 0; i < init.param.length; i++) {
            eval(init.param[i] + 'Prot = new ' + init.param[i] + '()');        
      }         
}

extJs = false;
var init = new initObj();
var initParam = new Array(); 
var initFunctions = new Array();

if(!extJs) addEvent(window, 'load', init.call, false);
/**
 * Checks if an value is contained in an array
 * 
 * @version 1.0
 * @param object obj The value to check for
 */
Array.prototype.contains = function(obj) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == obj) {
			return true;
		}
	}
	return false;
}

/**
 * deletes an element from an array
 * 
 * @version 1.0
 * @param object obj The value to remove
 */
Array.prototype.remove = function(obj) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == obj) {
			this.splice(i,1);
		}
	}
}
/**
 * Add the node to the DOM-Tree
 * 
 * @version 1.0
 * @param string sep The seperator of the keyValuePairs
 * @param string split How the name and the value is seperated
 * @return array
 */
String.prototype.toAttributes = function(sep, split) {

      att = new Object();
      keyValuePairs = new Array();        

      if(this.length > 0) var q = this;
      else var q = null;
            
      if(q) {
            for(var i=0; i < q.split(sep).length; i++) {
                  keyValuePairs[i] = q.split(sep)[i];
                  
            }
            
            for(var i=0; i < keyValuePairs.length; i++) {
                  
                  if(keyValuePairs[i].split(split)[0].indexOf('[]') != -1) {
                        if(typeof(att[keyValuePairs[i].split(split)[0]]) != 'object') {
                              att[keyValuePairs[i].split(split)[0]] = new Array();                              
                        }                
                        
                        att[keyValuePairs[i].split(split)[0]][att[keyValuePairs[i].split(split)[0]].length] = keyValuePairs[i].split(split)[1];                              
                  } else {             
                        var splitArray = keyValuePairs[i].split(split);
                        splitArray.shift();

                        att[keyValuePairs[i].split(split)[0]] = splitArray.join(split);
                  }
            }
            
      }
            
      return att;

}
/*
 */
document.getElementsByClass = function(cssName) {

}

/**
 * Get all elements that have a certain css class attached to them
 * 
 * @version 1.0
 * @param string type The type of node (ex. <div>)
 * @param string cssName The classname to search for
 * @return array
 */
document.getElementsByNameClass = function(type, cssName) {

      var ret = new Array();
      var elements =  document.getElementsByTagName(type);
      
      for(var i = 0; i < elements.length; i++) {
      	if(elements[i].className.indexOf(cssName) != -1) {        	     
                  ret.push(elements[i]); 
            }
      }

      return ret;
}

/**
 * Get all elements that have a certain value in the id
 * 
 * @version 1.0
 * @param string type The type of node (ex. <div>)
 * @param string cssName The classname to search for
 * @return array
 */
document.getElementsByTypeId = function(type, cssName) {

      var ret = new Array();
      var elements =  document.getElementsByTagName(type);
      
      for(var i = 0; i < elements.length; i++) {                 
      	if(elements[i].className.indexOf(cssName) != -1) {        	     
                  ret.push(elements[i]); 
            }
      }

      return ret;
}

/**
 * Line up all elements of a certain cssName and give them equal width
 * 
 * @version 1.0
 * @param string label The css class that will be adjusted
 */
document.adjustForm = function(label) {

	var labels = document.getElementsByTagName('label');
	var changeDiv = new Array();
	var length = 0;
	
	for(var i = 0; i < labels.length; i++) {
		var css = labels[i].className;
		if(css.indexOf(label) != -1) {                             	
			length = (labels[i].offsetWidth - 5 > length) ? labels[i].offsetWidth - 5 : length;
			changeDiv.push(labels[i]);
		}
	}

      if(length == 0) length = 150;

	for(var i = 0; i < changeDiv.length; i++) {
		changeDiv[i].style.width = length;
	}

}

document.attachClass = function(elements, cssName) {

}


/*
 */
initParam.push('domMan');

/**
 * Object that can create DOM nodes of any kind
 * Configurable through att which features all the settings of the node
 * 
 * @version 1.0
 * @param string type Which HTML-Tag will be created
 * @param object att The attributes that will be set
 * @param object parent The parentnode where the created node will be attached
 */
function domMan(type, att, parent) {
      
      this.type = type;
      this.att = att;
      this.parent = parent;
      
      if(this.tags.contains(type)) {
            this.node = this.create(type);                                                
            if(typeof(att) == "object") this.setAttributes(att);
      
            if(typeof(parent) == "object") this.append(parent);
            
      }
      else if(typeof(type) == "object") {
            this.node = type;
      }
}

/**
 * The allowed HTML-Tags as array
 */
domMan.prototype.tags = "address applet area a base basefont big blockquote body br b caption center cite code dd dfn dir div dl dt em font form h1 h2 h3 h4 h5 h6 head hr html img input isindex i kbd label link li map menu meta ol option param pre p samp script select small span strike strong style sub sup table tbody td textarea th title tr tt ul u var".split(" ");

/**
 * Create the node
 * 
 * @version 1.0
 * @param string type Which HTML-Tag will be created
 */
domMan.prototype.create = function(type) {
       return document.createElement(type);
}

/**
 * Sets the attributes of the node, has special handling for eventHandlers
 * 
 * @version 1.0
 * @param object att The attributes
 */
domMan.prototype.setAttributes = function(att) {

      handler = "onAbort onBlur onChange onClick onDblClick onError onFocus onKeydown onKeypress onKeyup onLoad onMousedown onMousemove onMouseout onMouseover onMouseUp onReset onSelect onSubmit onUnload".split(" ");

      for(var i in att) {
            if(handler.contains(i)) this.setHandler(i, att[i]);
            else if(i == 'innerHTML') this.node.innerHTML = att[i];
            else if(i == 'class') this.node.className = att[i];
            else this.node.setAttribute(i, att[i]);
             
      }
}

/**
 * Sets the eventHandlers
 * 
 * @version 1.0
 * @param string handler Which handler will be set
 * @param string call The function to call when event sets off
 */
domMan.prototype.setHandler = function(handler, call) {

      //addEvent(this.node, 'submit', new Function(call), false);
      switch(handler) {            
            case 'onAbort':
            this.node.onabort = new Function(call);
            break;
            case 'onBlur': 
            this.node.onblur = new Function(call);
            break;
            case 'onChange': 
            this.node.onchange = new Function(call);
            break;
            case 'onClick':
            this.node.onclick = new Function(call);
            break;
            case 'onDblClick':
            this.node.ondblclick = new Function(call);
            break;
            case 'onError':
            this.node.onerror = new Function(call);
            break;
            case 'onFocus':
            this.node.onfocus = new Function(call);
            break;
            case 'onKeydown':
            this.node.onkeydown = new Function(call);
            break;
            case 'onKeypress':
            this.node.onkeypress = new Function(call);
            break;
            case 'onKeyup':
            this.node.onkeyup = new Function(call);
            break;
            case 'onLoad':
            this.node.onload = new Function(call);
            break;
            case 'onMousedown':
            this.node.onmousedown = new Function(call);
            break;
            case 'onMousemove':
            this.node.onmousemove = new Function(call);
            break;
            case 'onMouseout':
            this.node.onmouseout = new Function(call);
            break;
            case 'onMouseover':
            this.node.onmouseover = new Function(call);
            break;
            case 'onMouseUp':
            this.node.onmouseup = new Function(call);
            break;
            case 'onReset':
            this.node.onreset = new Function(call);
            break;
            case 'onSelect':
            this.node.onselect = new Function(call);
            break;
            case 'onSubmit':
            this.node.onsubmit = new Function(call);      
            break;
            case 'onUnload':
            this.node.onunload = new Function(call);
            break;
      }

      
      //node = new Function(call);
      //alert(this.node.onsubmit);

}

/**
 * Add the node to the DOM-Tree
 * 
 * @version 1.0
 * @param object parent The parentnode
 */
domMan.prototype.append = function(parent) {  
      parent.appendChild(this.node);
}

/**
 * Get rid of a created node
 * 
 * @version 1.0
 */
domMan.prototype.remove = function() {
      this.node.parentNode.removeChild(this.node);
}


/**
 * Get rid of a created node
 * 
 * @version 1.0
 */
domMan.prototype.addEventListener = function() {
    
}


/*
 */
initParam.push('lang');

/**
 * Handle the client side language pack
 * 
 * @version 1.0
 */
function lang() {      
      this.enterPassword = '';
      this.passwordCorrect = '';
      this.passwordFalse = '';
        
      this.itemMenuedit = '{img.editIcon} ';
      this.itemMenuview = '{img.viewIcon} ';
      this.itemMenudelete = '{img.deleteIcon} ';      
      this.itemMenunew = '<img src="/imageCache/1/" class="icon" alt="" /> ';            
      this.itemMenusub = '{img.subfolderIcon} ';        
      this.itemMenumodule = '{img.openfolderIcon} '; 

      
this.itemMenu_module1 = '{img.moduleIcon_1} {lang.moduleName_1}';
this.itemMenu_module2 = '{img.moduleIcon_2} {lang.moduleName_2}';
this.itemMenu_module3 = '{img.moduleIcon_3} {lang.moduleName_3}';
this.itemMenu_module4 = '{img.moduleIcon_4} {lang.moduleName_4}';
this.itemMenu_module5 = '{img.moduleIcon_5} {lang.moduleName_5}';
this.itemMenu_module6 = '<img src="/imageCache/25/" class="icon" alt="" /> {lang.moduleName_6}';
this.itemMenu_module7 = '{img.moduleIcon_7} {lang.moduleName_7}';
this.itemMenu_module8 = '{img.moduleIcon_8} {lang.moduleName_8}';
this.itemMenu_module9 = '{img.moduleIcon_9} {lang.moduleName_9}';
this.itemMenu_module10 = '{img.moduleIcon_10} {lang.moduleName_10}';
this.itemMenu_module11 = '{img.moduleIcon_11} {lang.moduleName_11}';
this.itemMenu_module12 = '{img.moduleIcon_12} {lang.moduleName_12}';
this.itemMenu_module13 = '{img.moduleIcon_13} ';
this.itemMenu_module14 = '{img.moduleIcon_14} ';
this.itemMenu_module15 = '{img.moduleIcon_15} ';
this.itemMenu_module16 = '{img.moduleIcon_16} ';
this.itemMenu_module17 = '{img.moduleIcon_17} ';
this.itemMenu_module18 = '{img.moduleIcon_18} {lang.moduleName_18}';
this.itemMenu_module19 = '{img.moduleIcon_19} {lang.moduleName_19}';
this.itemMenu_module20 = '{img.moduleIcon_20} {lang.moduleName_20}';
this.itemMenu_module21 = '{img.moduleIcon_21} ';
this.itemMenu_module22 = '{img.moduleIcon_22} ';
this.itemMenu_module23 = '{img.moduleIcon_23} ';
this.itemMenu_module24 = '{img.moduleIcon_24} {lang.moduleName_24}';
this.itemMenu_module25 = '{img.moduleIcon_25} {lang.moduleName_25}';
this.itemMenu_module26 = '{img.moduleIcon_26} {lang.moduleName_26}';
this.itemMenu_module27 = '{img.moduleIcon_27} ';
this.itemMenu_module28 = '{img.moduleIcon_28} ';
this.itemMenu_module29 = '{img.moduleIcon_29} {lang.moduleName_29}';
this.itemMenu_module30 = '{img.moduleIcon_30} {lang.moduleName_30}';
this.itemMenu_module31 = '{img.moduleIcon_31} ';
this.itemMenu_module32 = '{img.moduleIcon_32} {lang.moduleName_32}';
this.itemMenu_module33 = '{img.moduleIcon_33} {lang.moduleName_33}';
this.itemMenu_module34 = '{img.moduleIcon_34} ';
this.itemMenu_module35 = '{img.moduleIcon_35} ';
this.itemMenu_module36 = '{img.moduleIcon_36} ';
this.itemMenu_module37 = '{img.moduleIcon_37} ';
this.itemMenu_module38 = '{img.moduleIcon_38} ';
this.itemMenu_module39 = '{img.moduleIcon_39} ';
this.itemMenu_module40 = '{img.moduleIcon_40} ';
this.itemMenu_module41 = '{img.moduleIcon_41} ';
this.itemMenu_module42 = '{img.moduleIcon_42} ';
this.itemMenu_module43 = '{img.moduleIcon_43} ';
this.itemMenu_module44 = '{img.moduleIcon_44} ';
this.itemMenu_module45 = '{img.moduleIcon_45} ';
this.itemMenu_module46 = '{img.moduleIcon_46} ';
this.itemMenu_module47 = '{img.moduleIcon_47} ';
this.itemMenu_module48 = '{img.moduleIcon_48} ';
this.itemMenu_module49 = '{img.moduleIcon_49} ';
this.itemMenu_module50 = '{img.moduleIcon_50} ';
this.itemMenu_module51 = '{img.moduleIcon_51} ';
this.itemMenu_module52 = '{img.moduleIcon_52} ';
this.itemMenu_module53 = '{img.moduleIcon_53} ';
this.itemMenu_module54 = '{img.moduleIcon_54} ';
      
      this.userIcon_w = '{img.selectWorld}';
      this.userIcon_g = '{img.moduleIcon_19}';
      this.userIcon_u = '{img.moduleIcon_5}';

      this.parameterIcon = '<img src="/imageCache/25/" class="icon" alt="" />';      
      
      
      this.userRemove = '{img.deleteIcon}';
      this.name = '';
                  
      this.extractArchive = '';                  
                  
      this.fileBrowse = '<img src="/imageCache/7/" class="icon" alt="" />';
      
      this.tableFilter = '<img src="/imageCache/21/" class="icon" alt="" />';
      
      this.root = '' //'Wurzel';
      
      this.requiredField = '';
      this.requiredMissing = '';
      
      this.back = '';
      this.forward = '';
      this.page = '';    
      this.image = '';
      this.of = '';
      this.closeImg = ' <img src="/imageCache/41/" class="icon" alt="" />';
      
}




/**
 * Handles global vars
 *
 */
 
var conWebDir = '/robots.txt/../';
var conWebPresDir = '/robots.txt/';
var conImageDir = 'imageCache/';

var conUserLang = 'robots.txt';
/*
 */
initParam.push('layoutObj');

layoutObj = function() {
      this.init();
}

layoutObj.prototype.init = function() {
      this.setTableStyles();
}

/**
 * sets for each table cellspacing and cellpadding to zero, because it cannot be changed by css
 * 
 * @version 1.0
 */
layoutObj.prototype.setTableStyles = function() {
      
      var tables = document.getElementsByTagName('table');
      
      for(var i = 0; i < tables.length; i++) {
            tables[i].cellSpacing = (tables[i].cellSpacing == '') ? 0 : tables[i].cellSpacing;
            tables[i].cellPadding = (tables[i].cellPadding == '') ? 2 : tables[i].cellPadding;
      }
      
}

