/**
 * 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 = 'Bitte Passwort eingeben';
      this.passwordCorrect = 'Das Passwort ist korrekt';
      this.passwordFalse = 'Das Passwort ist falsch';
        
      this.itemMenuedit = '<img src="/imageCache/17/" class="icon" alt="Bearbeiten" /> Bearbeiten';
      this.itemMenuview = '<img src="/imageCache/23/" class="icon" alt="Ansehen" /> Ansehen';
      this.itemMenudelete = '<img src="/imageCache/22/" class="icon" alt="Löschen" /> Löschen';      
      this.itemMenunew = '<img src="/imageCache/1/" class="icon" alt="Neuen Inhalt erzeugen" /> Neu erstellen';            
      this.itemMenusub = '<img src="/imageCache/51/" class="icon" alt="Neuer Unterordner" /> Neuer Unterordner';        
      this.itemMenumodule = '<img src="/imageCache/19/" class="icon" alt="Ordner öffnen" /> Ordner öffnen'; 

      
this.itemMenu_module1 = '<img src="/imageCache/31/" class="icon" alt="Module" /> {lang.moduleName_1}';
this.itemMenu_module2 = '<img src="/imageCache/32/" class="icon" alt="moduleInputs" /> {lang.moduleName_2}';
this.itemMenu_module3 = '<img src="/imageCache/30/" class="icon" alt="Komponenten" /> {lang.moduleName_3}';
this.itemMenu_module4 = '<img src="/imageCache/24/" class="icon" alt="Language" /> {lang.moduleName_4}';
this.itemMenu_module5 = '<img src="/imageCache/16/" class="icon" alt="userData" /> {lang.moduleName_5}';
this.itemMenu_module6 = '<img src="/imageCache/25/" class="icon" alt="presences" /> {lang.moduleName_6}';
this.itemMenu_module7 = '{img.moduleIcon_7} {lang.moduleName_7}';
this.itemMenu_module8 = '<img src="/imageCache/26/" class="icon" alt="content" /> {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 src="/imageCache/2/" class="icon" alt="Text" /> Normaler Text';
this.itemMenu_module14 = '<img src="/imageCache/27/" class="icon" alt="News" /> News';
this.itemMenu_module15 = '<img src="/imageCache/28/" class="icon" alt="Administration" /> Administration';
this.itemMenu_module16 = '<img src="/imageCache/29/" class="icon" alt="Navigatoren" /> Navigator';
this.itemMenu_module17 = '<img src="/imageCache/30/" class="icon" alt="Formular" /> Formular';
this.itemMenu_module18 = '<img src="/imageCache/30/" class="icon" alt="Komponenten" /> {lang.moduleName_18}';
this.itemMenu_module19 = '<img src="/imageCache/15/" class="icon" alt="userGroups" /> {lang.moduleName_19}';
this.itemMenu_module20 = '{img.moduleIcon_20} {lang.moduleName_20}';
this.itemMenu_module21 = '<img src="/imageCache/36/" class="icon" alt="Konstante" /> Konstante';
this.itemMenu_module22 = '<img src="/imageCache/37/" class="icon" alt="Script-Code" /> Script-Code';
this.itemMenu_module23 = '<img src="/imageCache/38/" class="icon" alt="templatesLists" /> Auflistung';
this.itemMenu_module24 = '<img src="/imageCache/30/" class="icon" alt="Komponenten" /> {lang.moduleName_24}';
this.itemMenu_module25 = '<img src="/imageCache/37/" class="icon" alt="Fortgeschritten" /> {lang.moduleName_25}';
this.itemMenu_module26 = '{img.moduleIcon_26} {lang.moduleName_26}';
this.itemMenu_module28 = '<img src="/imageCache/42/" class="icon" alt="Vorlage Bild" /> Bild';
this.itemMenu_module29 = '<img src="/imageCache/25/" class="icon" alt="Präsenz Alias" /> {lang.moduleName_29}';
this.itemMenu_module30 = '<img src="/imageCache/32/" class="icon" alt="Parameter" /> {lang.moduleName_30}';
this.itemMenu_module31 = '<img src="/imageCache/43/" class="icon" alt="Benachrichtigung" /> Benachrichtigung';
this.itemMenu_module32 = '{img.moduleIcon_32} {lang.moduleName_32}';
this.itemMenu_module33 = '<img src="/imageCache/56/" class="icon" alt="Backup" /> {lang.moduleName_33}';
this.itemMenu_module34 = '<img src="/imageCache/31/" class="icon" alt="Hook" /> Hook Funktion';
this.itemMenu_module35 = '<img src="/imageCache/30/" class="icon" alt="Inhaltscontainer" /> Inhaltscontainer';
this.itemMenu_module36 = '<img src="/imageCache/58/" class="icon" alt="Metatags" /> Metatags';
this.itemMenu_module37 = '<img src="/imageCache/61/" class="icon" alt="Referenzen Box" /> Referenzen Box';
this.itemMenu_module38 = '<img src="/imageCache/68/" class="icon" alt="CS Inhaltsseite" /> CS Inhaltsseite';
this.itemMenu_module39 = '<img src="/imageCache/69/" class="icon" alt="Newsletterabonnent" /> Newsletter';
this.itemMenu_module40 = '<img src="/imageCache/31/" class="icon" alt="Hook" /> Hook Funktion';
this.itemMenu_module41 = '<img src="/imageCache/15/" class="icon" alt="CS Ansprechpartner" /> CS Ansprechpartner';
this.itemMenu_module42 = '<img src="/imageCache/128/" class="icon" alt="CS Gebrauchtmarkt" /> CS Gebrauchtmarkt';
this.itemMenu_module43 = '<img src="/imageCache/128/" class="icon" alt="C/S Gebrauchmarkt" /> C/S Gebrauchmarkt';
this.itemMenu_module44 = '<img src="/imageCache/15/" class="icon" alt="Partner" /> Partner';
this.itemMenu_module45 = '{img.moduleIcon_45} FEHLT';
this.itemMenu_module46 = '{img.moduleIcon_46} Projekte';
this.itemMenu_module47 = '{img.moduleIcon_47} Projekt Kategorien';
this.itemMenu_module48 = '{img.moduleIcon_48} News';
this.itemMenu_module49 = '{img.moduleIcon_49} FEHLT';
      
      this.userIcon_w = '<img src="/imageCache/20/" class="icon" alt="selectWorld" />';
      this.userIcon_g = '<img src="/imageCache/15/" class="icon" alt="userGroups" />';
      this.userIcon_u = '<img src="/imageCache/16/" class="icon" alt="userData" />';

      this.parameterIcon = '<img src="/imageCache/25/" class="icon" alt="presences" />';      
      
      
      this.userRemove = '<img src="/imageCache/22/" class="icon" alt="Löschen" />';
      this.name = 'Name';
                  
      this.extractArchive = 'Archiv in diesen Ordner entpacken';                  
                  
      this.fileBrowse = '<img src="/imageCache/7/" class="icon" alt="Datei Selector" />';
      
      this.tableFilter = '<img src="/imageCache/21/" class="icon" alt="tableFilter" />';
      
      this.root = 'Wurzelknoten' //'Wurzel';
      
      this.requiredField = 'Pflichtfeld bitte ausfüllen!';
      this.requiredMissing = 'Es sind nicht alle Pflichtfelder ausgefüllt!';
      
      this.back = 'Zurück';
      this.forward = 'Weiter';
      this.page = 'Seite';    
      this.image = 'Bild';
      this.of = 'von';
      this.closeImg = 'Schließen <img src="/imageCache/41/" class="icon" alt="Schließen" />';
      
      this.uploadFiles = '{lang.uploadFiles}';
      
}




/**
 * Handles global vars
 *
 */
 
var conWebDir = '/';
var conWebPresDir = '/';
var conImageDir = 'imageCache/';

var conUserLang = 'DE';
/*
 */
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;
      }
      
}
/** */
switchDisplay = function(id) {
    
    var el = document.getElementById(id);
    
    el.style.display = (el.style.display == 'none') ? 'block' : 'none';        
}

