var curToggleNode = '';














function adaptElementSizeCssDiff(elementId, diffWidth, diffHeight){
  
  var winWidth  = getWidthWindow();
  var winHeight = getHeightWindow();
  var element = document.getElementById(elementId);
  if(winWidth <= 0 || winHeight <= 0){
    window.setTimeout("adaptElementSizeCssDiff('" + elementId + "', " + diffWidth + ", " + diffHeight + ")", 500);
  }
  else if(element){
    if(diffHeight != null){
      var newHeight = winHeight - diffHeight;
      element.style.height = String(newHeight) + 'px';
    }
    if(diffWidth != null){
      var newWidth = winWidth - diffWidth;
      element.style.width = String(newWidth) + 'px';
    }
  }
}










function adaptApplicationSize(elementId, diffWidth, diffHeight){

  var winWidth    = getWidthWindow();
  var winHeight   = getHeightWindow();

  if(diffHeight!='0'){
    document.getElementById(elementId).style.height = String(parseInt(winHeight) - diffHeight) + 'px';
  }
  if(diffWidth!='0'){
    document.getElementById(elementId).style.width = String(parseInt(winWidth) - diffWidth) + 'px';
  }
  
  document.getElementById(elementId).style.display = "block";
}






function getHeightWindow(){


  var winHeight;

  if(ie){
    if(document.documentElement.clientHeight){
      winHeight = document.documentElement.clientHeight;
    }
    else{
    	if(document.body){
      	winHeight = document.body.clientHeight;
      }
      else{
      	winHeight = 0;
      }
    }
  }
  else{
    winHeight = window.innerHeight;
  }
  return winHeight;
}






function getWidthWindow(){
	
  var winWidth;
	
  if(ie){
    if(document.documentElement.clientWidth){
    	winWidth = document.documentElement.clientWidth;
    }
    else{
    	if(document.body){
    		winWidth = document.body.clientWidth;
    	}
    	else{
    		winWidth = 0;
    	}
    }
  }
  else{
    winWidth = window.innerWidth;
  }

  return winWidth;

}








function setClassName(elementId, className){

  if(elementId == ""){
   return;
  }

	if(ie){
    if(document.all[elementId]){
      document.all[elementId].className = className;
    }
	}
	else if(dom){
	  if(document.getElementById(elementId)){
		  document.getElementById(elementId).className = className;
    }
	}
}








function setClassNameObject(object, className){

  object.className = className;
}









function wShowRegister(id, group){
  
  if(!group || group == ''){
    group = 'default';
  }

  var sheet = document.getElementById('wSheetRegister_' + group + '_' + id);
  
  if(sheet){
    var sheets = document.getElementsByTagName('DIV');
    for(var i = 0; i < sheets.length; i++){      
      if(sheets[i].id.substr(0, 14) == 'wSheetRegister'){
        if(sheets[i].id.substr(15, group.length) == group){
          sheets[i].style.display = 'none';
        }
      }
    }
    sheet.style.display = 'block';
    sheet.style.height = String(sheet.parentNode.parentNode.parentNode.offsetHeight) + 'px';
    sheet.style.overflow = 'auto';
    if(ie){
      sheet.style.position = 'relative';
    }

    return true;
  }
  return false;
}




















function wShowProgressPaste(){

}










function wShowMessagebox(id, title, text, buttons, icon, variable){
	initDialog(id, title, text, buttons, icon, variable);
}









function wShowMaskSelectGroup(id, action, data){
  var width = '420';
  var height = '320';
  var name = '';
  var options = '';
  var param = '';
  if(typeof action == 'undefined' || action == ''){
    action = 'showmaskselectgroup';
  }
  if(data){
    for(var key in data[0]){
      if(key == 'width'){
        width = data[0][key];
      } 
      else if(key == 'height'){
        heigth = data[0][key];
      } 
      else if(key == 'name'){
        name = data[0][key];
      } 
      else if(key == 'options'){
        options = data[0][key];
      }
      else{
        param = param + '&' + key + '=' + data[0][key];
      } 
    }
  }
  wOpenWindow('/weblication/grid/scripts/wUsermanager.php?action=' + action + '&id=' + id + param, name, width, height, options);
}









function wShowMaskSelectUser(id, action, data){
  var width = '420';
  var height = '470';
  var name   = '';
  var options = '';
  var param = '';
  if(typeof action == 'undefined' || action == ''){
    action = 'showmaskselectuser';
  }
  if(data){
    for(var key in data[0]){
      if(key == 'name'){
        name = data[0][key];
      } 
      else if(key == 'options'){
        options = data[0][key];
      }
      else{
        param = param + '&' + key + '=' + data[0][key];
      } 
    }
  }
  wOpenWindow('/weblication/grid/scripts/wUsermanager.php?action=' + action + '&id=' + id + param, name, width, height, options);
}









function toggleDisplay(id){

    var element = document.getElementById(id);
    if(element){
      if(element.style.display == 'block'){
        element.style.display = 'none';
      }
      else{
        element.style.display = 'block';
      }
    }
}









function toggleNode(element){
    
    if(curToggleNode != '' && curToggleNode != element){
      curToggleNode.style.display = 'none';
    }

    curToggleNode = element;

    if(element){
      if(element.style.display == 'block'){
        element.style.display = 'none';
      }
      else{
        element.style.display = 'block';
      }
    }
}








function toggleCheckBox(object){
  if(typeof object == 'object' && object != null && object.nodeName == 'IMG'){
    var result = object.src.search(/checkbox.gif/);
    if(result != -1){
      object.src = '/weblication/grid/gui/wImages/icon_small/checkbox_selected.gif';
    }
    else{
      object.src = '/weblication/grid/gui/wImages/icon_small/checkbox.gif';
    }
  }
}






function enableButtonDefault(id){

  var button = document.getElementById('wButton_'+id);
  if(button){
    button.className = 'wButton';
  }
}






function disableButtonDefault(id){
  var button = document.getElementById('wButton_'+id);
  if(button){
    button.className = 'wButtonDisabled';
  }
}






function hideButtonDefault(id){
  var button = document.getElementById('wButton_'+id);
  if(button){
    button.className = 'wButtonHidden';
  }
}






function selectButtonDefault(id){
  var button = document.getElementById('wButton_'+id);
  if(button){
    button.className = 'wButtonSelected';
  }
}








function toggleDisplayElement(elementId){

  if(document.getElementById(elementId)){
    if(document.getElementById(elementId).style.display == 'none'){
      document.getElementById(elementId).style.display = 'block';
    }
    else{
      document.getElementById(elementId).style.display = 'none';
    }
  }
}








function displayElement(elementId){
  
  if(document.getElementById(elementId)){    
    document.getElementById(elementId).style.display = 'block';
  }
}








function hideElement(elementId){

  if(document.getElementById(elementId)){
    document.getElementById(elementId).style.display = 'none';
  }
}








function wSetStyleClass(className, styleName, styleValue){

  if(ie){
    var lastStyleSheet = document.styleSheets[document.styleSheets.length - 1];
    lastStyleSheet.addRule (className, styleName + ':' + styleValue);
  }
  else{
    var lastStyleSheet = document.styleSheets[document.styleSheets.length - 1];
    lastStyleSheet.insertRule('.' + className + '{' + styleName + ':' + styleValue + '}', lastStyleSheet.cssRules.length);
  }
}

function wAdaptElementSizeToElement(elementInnerId, elementOuterId, marginTop, marginRight, marginBottom, marginLeft, offsetTop){
  var elementInner = document.getElementById(elementInnerId);
  var elementOuter = document.getElementById(elementOuterId);


  if(elementInner){
    if(elementOuter){
      if(elementInner.nextSibling && elementInner.nextSibling.nodeType == 3){
        elementInner.nextSibling.parentNode.removeChild(elementInner.nextSibling);
      }
      elementInner.style.marginTop    = String(marginTop) + 'px';
      elementInner.style.marginRight  = String(marginRight) + 'px';
      elementInner.style.marginBottom = String(marginBottom) + 'px';
      elementInner.style.marginLeft   = String(marginLeft) + 'px';



      var heightInner               = parseInt(elementOuter.clientHeight) - marginTop - marginBottom - offsetTop;


      elementInner.style.height     = String(heightInner) + 'px';
      elementInner.style.width      = String(elementOuter.clientWidth) + 'px';
      elementInner.style.visibility = '';

    }
  }
}

function closeMask(){

  if(parent){
    if(parent.name == 'wInnerMain'){
      parent.closeTab();
    }
    else{
      top.close();
    }
  }
  else{
    top.close();
  }
}








function cancleBubble(e){
  if(ie){
    window.event.cancelBubble =  true;  
  }
  else{
    if(typeof e.stopPropagation == 'function'){
      e.stopPropagation();
    }
  }
}








function wInitSelectObject(name, id, sourcename){
  if(wSelectObject[0][name] == null || typeof wSelectObject[0][name] != 'object'){
    wSelectObject[0][name] = new wSelect(name, id, sourcename);
  }
  
  wCurSelectObjectName = name;
}


function option_hideList_onMouseDown(evt){ 
	if(ie){
		wSelectObject[0][wCurSelectObjectName].onmousedown(evt);
  }
  else{
    wSelectObject[0][wCurSelectObjectName].onmousedown(evt);
  }
}

function option_hideList_onMouseScroll(evt){
	if(ie){
		wSelectObject[0][wCurSelectObjectName].onmousedown(event);
	}
	else{    	
  	wSelectObject[0][wCurSelectObjectName].onscroll(evt);
	}
}

function wSelect(name, id, namesource){
  
  this.name 	= name;
  this.listId = id;
  this.namesource = namesource;
  this.scrollElement = null;
  this.positioned = false;
   
  this.construct = new function(){}
  
  this.setEvents = function(){
    
    if(!ie){
      if(this.scrollElement != null){
        this.scrollElement.onscroll = function(e){ option_hideList_onMouseScroll(e); }
      }
      else{
        window.onscroll = function(e){ option_hideList_onMouseScroll(e); };
      }
      window.onmousedown = function(e){ option_hideList_onMouseDown(e); };

    } 
    else{

      document.onmousedown = function(){ option_hideList_onMouseDown(event); }
      if(this.scrollElement != null){
        this.scrollElement.onscroll = function(){ option_hideList_onMouseScroll(event); }
      }
      else{
        window.onscroll = function(){ option_hideList_onMouseScroll(event); }
      }
    }
    
  };
  
  this.onscroll = function(evt){
    
  	if(ie && evt.srcElement){
      var id = evt.srcElement.id;
    }
    else if(!ie){
      var id = evt.target.id;
    }
    
    if(id){
      var regExp = '/^' + this.listId + '_/';
      var idTemp = id.match(eval(regExp));
      
      if(id.replace(/^\s+|\s+$/, '') == this.listId.replace(/^\s+|\s+$/, '')){
      	idTemp = true;
      }
    }
    
    if(idTemp == '' || idTemp == null || id == ''){
      if(document.getElementById(this.listId)){
        document.getElementById(this.listId).style.display = 'none';                              
      }
  		window.onscroll = null;
			this.default_img_onclick(document.getElementById(this.listId + "_img"));
		}
    
	};
	
	this.onmousedown = function(evt){
	  
	  if(ie){
      var id = evt.srcElement.id;
    }
    else{
      var id = evt.target.id;
    }
    
    var regExp = '/^.*' + this.listId + '_/';
    var idTemp = id.match(eval(regExp));
    
    if(id.replace(/^\s+|\s+$/, '') == this.listId.replace(/^\s+|\s+$/, '')){
    	idTemp = true;
    }
    
    if(idTemp == '' || idTemp == null || id == ''){
      if(document.getElementById(this.listId)){
        document.getElementById(this.listId).style.display = 'none';  
      }  
      if(window.removeEventListener){
	      eval('window.removeEventListener("MouseDown", option_hideList_onMouseDown, false );');
	    }
	    else{
	     	if(document.detachEvent){
	      	eval('document.detachEvent("onmousedown", option_hideList_onMouseDown);');
	      }
	      document.onmousedown = null;
	    }
	    this.default_img_onclick(document.getElementById(this.listId + "_img"));
    }
	};
  
  this.default_itemList_onClick = function(listObject, object){
    
    if(listObject.nodeType != 1){
      listObject = listObject.nextSibling;
    }
    
    this.default_img_onclick(document.getElementById(this.listId + "_img"));
    if(listObject.style.display == 'block'){
      listObject.style.display = 'none';
    }
    else{
      if(!ie || ieVers > 6){
        listObject.style.width   = (object.offsetWidth - 7) + 'px';
      }
      else if(ie){
        if(ieVers < 7){
          listObject.style.width   = (object.offsetWidth - 2) + 'px';
        }
      }
      listObject.style.display = 'block';
    }

    var listHeight = null;
    if(listHeight == null){
      listHeight = listObject.offsetHeight;
    }
    
    if(typeof diffHeight == 'undefined'){
      var diffHeight = 0;
    }
    if(typeof windowHeight == 'undefined'){
      var windowHeight = getHeightWindow();
    }
    
    var scrollTop = 0;    
    if(this.scrollElement == null){
      var element = object;
      while(this.scrollElement == null && element.parentNode){
        element = element.parentNode;
        if(element.scrollTop != 0 && typeof element.scrollTop == 'number' && element.scrollTop != null){
          this.scrollElement = element;
        }
      }
    }
    
    if(this.scrollElement != null){
      if(scrollTop != this.scrollElement.scrollTop){
        this.positioned = false;
      }
      scrollTop = this.scrollElement.scrollTop;
    }
    
    if(!this.positioned){
      scrollTop = 0;
    }
    
    var tempX = listHeight + listObject.offsetTop;
     
    if(tempX > (windowHeight + scrollTop - diffHeight)){
      var tempListHeight = windowHeight - tempX - diffHeight;
      if(tempListHeight > 60){
        listObject.style.height = tempListHeight + 'px';
      }
      else{
        if(ie){
          listObject.style.top = (listObject.offsetTop - listObject.offsetHeight - (object.offsetHeight - object.offsetTop - 3)) + 'px';
        }
        else{

          listObject.style.top = (listObject.offsetTop - listHeight - object.offsetHeight + 3) + 'px';
        }
      }
      this.positioned = true;
    }
    else{
      if(!this.positioned){
        listObject.style.top = '';
      }
    }
    
    if(listObject.offsetLeft < object.offsetLeft && (listObject.offsetLeft != 0 && object.offsetLeft != 0)){
      listObject.style.left = object.offsetLeft + 'px';
    }
    this.setEvents();
	
	};
	
	this.default_img_onclick = function(imgObject) {
    
    if(imgObject.nodeType != 1){
	    imgObject = imgObject.nextSibling;
	  }
    
		if(typeof imgObject == 'object' && imgObject.nodeName == 'IMG'){
		  var regEx = /\/(\w*).gif$/;
  		regEx.exec(imgObject.src);
			if(RegExp.$1 == "open"){
			  imgObject.src = imgObject.src.replace(/open.gif$/, 'open.gif');
			}
			else{
			  imgObject.src = imgObject.src.replace(/close.gif$/, 'open.gif');
			} 
		}
	};
	
  this.default_item_setValue = function(listObject, displayValue, value, bubble){
   
	  var dom = new wDomX();
    var object = dom.wGetFirstChild(listObject.parentNode);
    var inputSelect = dom.wGetElementByName(this.name + '_display', object);
    
    inputSelect.value = displayValue;
    
    var inputSelect = dom.wGetElementByName(this.name, object);
    if(typeof inputSelect == 'undefined'){      
      var inputSelect = dom.wGetElementByName(this.namesource, object);  
    }

    if(bubble == 'undefined' || bubble != false){
      inputSelect.value = value;
      inputSelect.onclick();
    }
    
		listObject.style.display = 'none';
    
	};
	
	this.closeSelect = function(){
     if(document.getElementById(this.listId)){
        document.getElementById(this.listId).style.display = 'none';
     }                              
	};
	
	this.icon_itemList_onClick = function(listObject, object){
     
	   wCurSelectObjectName = this.name;
	  
		if(listObject.nodeType != 1){
     	listObject = listObject.nextSibling;
   	}
    
   	if(listObject.style.display == 'block'){
     	listObject.style.display = 'none';
   	}
   	else{
     	listObject.style.display = 'block';
     	listObject.style.width = String(object.offsetWidth - 2) + 'px';
     	listObject.style.marginTop = '-1px';
   	}
   
    if((listObject.offsetHeight + listObject.offsetTop) > document.documentElement.clientHeight){
      listObject.style.height = (document.documentElement.clientHeight - listObject.offsetTop -1) + 'px';
    }
   	this.setEvents();
   
	};
	
	this.icon_item_setValue = function(listObject, displayValue, value, imgSrc){
    
    var dom = new wDomX();
    var object = dom.wGetFirstChild(listObject.parentNode);
    
    var imgSelect = dom.wGetElementById(this.listId + '_iconSelect', object);
    var imgObject = dom.wGetFirstChild(imgSelect);
    imgObject.src = imgSrc;
    
    var inputSelect = dom.wGetElementByName(this.name + '_display', object);
    inputSelect.value = displayValue;
    var inputSelect = dom.wGetElementByName(this.name, object);
    inputSelect.value = value;
    inputSelect.onclick();
    
    listObject.style.display = 'none';
	
	};
  
  this.setDisabled = function(){

    var inputSelect = document.getElementById(this.listId + "_input_display");
    if(typeof inputSelect == 'object' && inputSelect != null){
      inputSelect.disabled = "disabled";
      inputSelect.style.cursor = 'default';
    }
    
    var tableObject = document.getElementById(this.listId + "_display");
    if(typeof tableObject == 'object' && tableObject != null){ 
      tableObject.onclick = null;
      tableObject.style.cursor = 'default';
    }
    
    var iconSelect =  document.getElementById(this.listId + "_iconSelect");
    if(typeof iconSelect == 'object' && iconSelect != null){ 
      iconSelect.style.cursor = 'default';
      iconSelect.className = iconSelect.className + ' wDisabled';
      iconSelect.onmouseover = null;
      iconSelect.onmouseout = null;
    }
    
    var imgContainer =  document.getElementById(this.listId + "_imgContainer");
    if(typeof imgContainer == 'object' && imgContainer != null){ 
      imgContainer.style.cursor = 'default';
      imgContainer.className = imgContainer.className + ' wDisabled';
      imgContainer.onmouseover = null;
      imgContainer.onmouseout = null;
    }
    
  };
  
  this.change_text_setValue = function(listObject, value){
  
    var dom = new wDomX();
    var object = dom.wGetFirstChild(listObject.parentNode);
    
    var inputSelect = dom.wGetElementByName(this.name, object);
    
    if(typeof inputSelect == 'undefined'){      
      var inputSelect = dom.wGetElementByName(this.namesource, object);  
    }
    
    inputSelect.value = value;


    
  };
 	
}








function wFileselector(id){
  this.id = id;
 
	this.onSelect = function(file){
	   document.getElementById(this.id).value = file;
	};
}








function getDirFile(file){
  var dirFile = file.replace(/(.*\/)[^\/]*/, '$1');
  return dirFile;
}

function markRowObjectListExtended(id){

  var idRowOuter = 'itemOuterRow_' + id;
  var rowOuter = document.getElementById(idRowOuter);
  if(rowOuter){
    rowOuter.style.backgroundColor = '#f0f0f0';
    var positionRow = 0;
    var positionTop = 0;
    var isBeforeCurrent = true;
    for(var i = 0; i < rowOuter.parentNode.childNodes.length; i++){
      if(isBeforeCurrent){

        positionTop += 21;
        if(rowOuter.parentNode.childNodes[i] == rowOuter){
          isBeforeCurrent = false;
        }
      }
    }

    if(positionTop > 320){
      document.getElementById('wObjectListExtendedMain').scrollTop = positionTop - 160;
    }
  }
}








function wSelectObjectMultiExtended(multiple, id){
  this.id = id;
  if(multiple == 1){
    this.selObjects = new Array();
  }
  else{
    this.selObjects = '';
  }
  this.objectInfo    = new Array();
  this.objectInfo[0] = new Object();
  this.replaceIndex    = new Array();
  this.replaceIndex[0] = new Object();
    
  this.selectObject = function(value, caption, type){
    if(typeof this.selObjects == 'object'){
      this.selObjects.push(value);
    }
    else{
      var temp = this.selObjects;
      this.selObjects = value;
      this.toggleObject(temp);
    } 
    
    if(typeof this.objectInfo[0][value] != 'object'){
      var tempInfo = new Array();
      tempInfo[0] = new Object();
      tempInfo[0]['caption'] = caption;    
      tempInfo[0]['type'] = type;
      this.objectInfo[0][value] = tempInfo;    
    }
    this.toggleObject(value);

  };
  
  this.removeObject = function(value){
    if(this.isSelected(value)){
      if(typeof this.selObjects == 'object'){
        var tempObject = new Array();
        var tempObjectInfo = new Array();
        tempObjectInfo[0] = new Object();
        for(var i = 0; i < this.selObjects.length; i++){
          if(this.selObjects[i] != value){
            tempObject[i] = this.selObjects[i];
            tempObjectInfo[0] = this.objectInfo[0][this.selObjects[i]];
          }
        }
        this.selObjects = tempObject;
        this.objectInfo[0] = tempObjectInfo[0];
      }
      else{ 
        this.selObjects = '';
      } 
      this.toggleObject(value);
      return true;
    }
    return false;
  };
  
  this.removeAll = function(){
    this.selObjects = new Array();  
  };
  
  this.getOptionsAsStr = function(){
    var objectStr = '';
    if(typeof this.selObjects == 'object'){
      for(var i = 0; i < this.selObjects.length; i++){
        if(objectStr != ''){
          objectStr = objectStr + "|"; 
        }
        objectStr = objectStr + this.selObjects[i];
      }
    }
    return objectStr;
  };
  
  this.isSelected = function(value){
    if(typeof this.selObjects == 'object'){
      for(var i = 0; i < this.selObjects.length; i++){
        if(this.selObjects[i] == value){
          return true;
        }
      }
    }
    else{ 
      if(this.selObjects == value){
        return true;
      }
    } 
    return false;
  };
  
  this.getSelectedObjects = function(){
    return this.selObjects; 
  };
  
  this.getSelectedObjectsInfo = function(value, info){
    if(value != '' && info != '' && typeof this.objectInfo[0][value] == 'object'){
      return this.objectInfo[0][value][0][info];  
    }
    return '';
  };
  
  this.toggleObject = function(value){
    var object = document.getElementById(this.id + value);
    if(typeof object == 'object' && object != null){
      if(this.isSelected(value)){
        object.style.backgroundColor = '#DDEFFF';
      }
      else{
        object.style.backgroundColor = '';
      }
    }
  };
  
  this.addObjectInfo = function(value, id, entry, replaceIndex){
    this.objectInfo[0][value][0][id] = entry;
    if(replaceIndex){
      this.replaceIndex[0][id] = replaceIndex;  
    }
  }; 
  
  this.addToListExt = function(rootObject, value){
    
    if(typeof rootObject == 'object' && rootObject != null){
      var object = this.getSelectedObjects();
      if(value != ''){
        object = value;
      }
      var caption = this.getSelectedObjectsInfo(this.getSelectedObjects(), 'caption');
      var icon = this.getSelectedObjectsInfo(this.getSelectedObjects(), 'icon');
      var tableSelectObject = rootObject;
      var trObjects                   = tableSelectObject.getElementsByTagName('TR');
      var newObject                   = trObjects[trObjects.length - 1].cloneNode(true);
      newObject = this.replace(newObject, value);
      
      var isEmpty   = false;
      var tableRows = tableSelectObject.getElementsByTagName('TR');
      if(tableRows.length){
          isEmpty = true;
      }

      var lastIndex = tableSelectObject.getElementsByTagName('TR').length - 1;
      var tempNode = tableSelectObject.getElementsByTagName('TR')[lastIndex].cloneNode(true);
      tableSelectObject.getElementsByTagName('TR')[lastIndex].parentNode.replaceChild(newObject, tableSelectObject.getElementsByTagName('TR')[lastIndex]);
      tableSelectObject.getElementsByTagName('TBODY')[0].appendChild(tempNode);
    }
  };

  this.replaceListExt = function(rootObject, value){
    if(typeof rootObject == 'object' && rootObject != null){
      var tableSelectObject = rootObject;
      var trObjects                   = tableSelectObject.getElementsByTagName('TR');
      var newObject                   = trObjects[trObjects.length - 1].cloneNode(true);
      
      newObject = this.replace(newObject, value);
      
      var replaceObject = null;
      var object = this.getSelectedObjects();
      for(var i = 0; i < trObjects.length; i++){
        if(trObjects[i].id == object){
          replaceObject = trObjects[i];
        }
      }
      if(typeof replaceObject == 'object' && replaceObject != null){
        replaceObject.parentNode.replaceChild(newObject, replaceObject);
      } 
    }  
  };
  
  this.replace = function(newObject, value){
      var object = this.getSelectedObjects();
      if(value != ''){
        object = value;
      }
      
      var caption = this.getSelectedObjectsInfo(this.getSelectedObjects(), 'caption');
      var icon = this.getSelectedObjectsInfo(this.getSelectedObjects(), 'icon');
      newObject.id                    = object;
      newObject.className             = '';
      
      var wChildNodes = newObject.getElementsByTagName('INPUT');
      for(var i = 0; i < wChildNodes.length; i++){
        wChildNodes[i].name  = wChildNodes[i].name.replace('W_PRETMP_', '');
        wChildNodes[i].value = wChildNodes[i].value.replace(/\[W_ID\]/, object);
        wChildNodes[i].value = wChildNodes[i].value.replace(/\[W_CAPTION\]/, caption);
        
        for(var index in this.replaceIndex[0]){
          var regExp = "/\\[" + this.replaceIndex[0][index] + "\\]/";
          wChildNodes[i].value = wChildNodes[i].value.replace(eval(regExp), this.getSelectedObjectsInfo(this.getSelectedObjects(), index));
        }        
        
        wChildNodes[i].id    = wChildNodes[i].id.replace(/\[W_ID\]/, object);

      }

      var wChildNodes = newObject.getElementsByTagName('DIV');
      for(var i = 0; i < wChildNodes.length; i++){
        wChildNodes[i].innerHTML = wChildNodes[i].innerHTML.replace(/\[W_CAPTION\]/, caption);
        wChildNodes[i].innerHTML = wChildNodes[i].innerHTML.replace(/\[W_ID\]/, object);
        for(var index in this.replaceIndex[0]){
          var regExp = "/\\[" + this.replaceIndex[0][index] + "\\]/";
          wChildNodes[i].innerHTML = wChildNodes[i].innerHTML.replace(eval(regExp), this.getSelectedObjectsInfo(this.getSelectedObjects(), index));
        }        

      }
      
      var wChildNodes = newObject.getElementsByTagName('A');
      for(var i = 0; i < wChildNodes.length; i++){
        wChildNodes[i].href = wChildNodes[i].href.replace(/\[W_ID\]/g, object);
        wChildNodes[i].id   = wChildNodes[i].id.replace(/\[W_ID\]/, object);
      }

      var wChildNodes = newObject.getElementsByTagName('IMG');
      for(var i = 0; i < wChildNodes.length; i++){
        src = decodeURI(wChildNodes[i].src);
        if(wChildNodes[i].src != src.replace(/\[W_ICON\]/, '')){
          wChildNodes[i].src = icon;
        }
        wChildNodes[i].id  = wChildNodes[i].id.replace(/\[W_ID\]/, object);
      }
      
      return newObject;

  };
  
}








function wSelectMultipleX(id){
  this.id     = id; 
  this.object = null; 
  this.objectExt = new Array();
  this.selectAll = false;
  
  this.wSetObjectExtData = function(value, key, data){
    if(this.objectExt[0] == null){
      this.objectExt[0] = new Object();
    }
    if(this.objectExt[0][value] == null){
      this.objectExt[0][value] = new Array();
      this.objectExt[0][value][0] = new Object();
    }
    this.objectExt[0][value][0][key] = data;
  }
  
  this.wSetObjectExt = function(value, data){
    if(this.objectExt[0] == null){
      this.objectExt[0] = new Object();
    }
    if(this.objectExt[0][value] == null){
      this.objectExt[0][value] = new Array();
    }
    this.objectExt[0][value] = data;
  }
  
  this.wGetObjectExt = function(value, key){
    if(this.objectExt[0] != null){
      if(key != null){
        if(this.objectExt[0][value] != null && this.objectExt[0][value][0] != null){
          return this.objectExt[0][value][0][key];
        }
      }
      return this.objectExt[0][value];
    }
    return null; 
  }
  
  this.wSetStateByValue = function(value, state){
    this.object = document.getElementById(this.id);
    if(typeof this.object == 'object' && this.object.tagName == 'SELECT' && this.object.type == 'select-multiple'){
      if(this.object.options.length == 0){
        return false;
      }
      for(var i = 0; i < this.object.options.length; i++){
        if(this.object.options[i].value == value){
          if(ie){
            this.object.options[i].setAttribute("selected", state);
          }
          else{
            this.object.options[i].selected = state;
          }
          return true;
        }
      } 
    }
    return false;
  };
  
  this.wValueIsSet = function(value){
    this.object = document.getElementById(this.id);
    if(typeof this.object == 'object' && this.object.nodeName == 'SELECT'){
      for(var i = 0; i < this.object.options.length; i++){
        if(this.object.options[i].value == value && this.object.options[i].selected == true){
          return true;
        }
      } 
    }
    return false;
  };
  
  this.wGetIndex = function(value){
    this.object = document.getElementById(this.id);
    if(typeof this.object == 'object' && this.object.nodeName == 'SELECT'){
      for(var i = 0; i < this.object.options.length; i++){
        if(this.object.options[i].value == value){
          return i;
        }
      } 
    }
    return false;
  };  
  
  this.wAddOption = function(value, text, state){
    this.object = document.getElementById(this.id);
    if(typeof this.object == 'object' && this.object.nodeName == 'SELECT'){
      var option = document.createElement("option");
      if(state){
        if(ie){
          option.setAttribute("selected", state);
        }
        else{
          option.selected = state;
        }
      }
      this.object.appendChild(option);
      this.object.options[this.object.options.length - 1].value = value;
      this.object.options[this.object.options.length - 1].appendChild(document.createTextNode(text));
      return true;
    }
    return false;
  };
  
  this.wDeleteOption = function(value){
    this.object = document.getElementById(this.id);
    if(typeof this.object == 'object' && this.object.tagName == 'SELECT'){
      for(var i = 0; i < this.object.options.length; i++){
        if(this.object.options[i].value == value){
          this.object.options[i].parentNode.removeChild(this.object.options[i]);
          return true;
        }
      } 
    }
    return false;
  };
  
  this.wGetOptions = function(){
    this.object = document.getElementById(this.id);
    return this.object.options;
  };
  
  this.wGetOption = function(i){
    this.object = document.getElementById(this.id);
    return this.object.options[i];
  };
  
  this.wGetOptionValue = function(i){
    this.object = document.getElementById(this.id);
    return this.object.options[i].value;
  };
  
  this.wGetOptionsAsArray = function(onlySelected){
    this.object = this.object = document.getElementById(this.id);
    var selected = new Array();
    if(typeof this.object == 'object' && this.object.tagName == 'SELECT'){
      for(var i = 0; i < this.object.options.length; i++){
        if(!onlySelected || this.object.options[i].selected == 'true'){
          selected.push(this.object.options[i].value); 
        }
      } 
    }
    return selected;
  }
  
  this.wImportOptions = function(options){
    this.object = document.getElementById(this.id);
    for(var i = 0; i < options.length; i++){
      this.wImportOption(options[i]);
    }
  }
  
  this.wRemoveOptions = function(options){
    this.object = document.getElementById(this.id);
    for(var i = 0; i < options.length; i++){
      this.wDeleteOption(options[i].value);
    }
  }
  
  this.wRemoveAllOptions = function(){
    this.object = document.getElementById(this.id);
    var clonedNode = this.object.cloneNode(false);
    this.object.parentNode.replaceChild(clonedNode, this.object);
  }
  
  this.wImportOption = function(option){
    this.object = document.getElementById(this.id);  
    var val = option.value;
    eval('var Ausdruck = /="?' + val + '"\s/');
    if(Ausdruck.exec(this.object.innerHTML) == null){
      this.object.appendChild(option.cloneNode(true));
    }
  }

  this.wSetSelectAll = function(status){
    this.selectAll = true;
    if(status === false){
      this.selectAll = false;
    }
  }
  
  this.wAllSelected = function(){
    return this.selectAll;
  }
  
  this.isSthSelected = function(){
    var options = this.wGetOptions();
    for(var i = 0; i < options.length; i++){
      if(options[i].selected === true){
        return true;
      }
    }
    return false; 
  }
}









function wListX(id){

  this.id     = id; 
  this.object = null; 
  this.listObjects = new Array();
    
  this.constructor = function(){
    this.object = document.getElementById(this.id);
    this.listObjects[0] = new Object();
  }
  
  this.wAddListNode = function(id, node){
    node.id = id;
    this.listObjects[0][id] = node;
    this.object.parentNode.appendChild(node);
  };
  
  this.wRemoveListEntry = function(id){
    this.listObjects[0][id].parentNode.removeChild(this.listObjects[0][id]);
  };
  
}








function wDomX(){

  this.wGetElementById = function(id, domObject){
    
    var childs  = domObject.childNodes;
    var element = null;
    if(childs.length > 0){
      for(var i = 0; i < childs.length; i++){
        if(childs[i].nodeName != "SCRIPT" && childs[i].nodeType == 1){

          if(id == childs[i].id){
            return childs[i];
          }
          if(childs[i].hasChildNodes() ){
            element = this.wGetElementById(id, childs[i]);
          }
          if(element != null){
            return element;
          }
        }
      }
    }
    else{
      return element;
    }
  };
  
  this.wGetElementByName = function(name, domObject){
    
    var childs  = domObject.childNodes;
    var element = null;
    if(childs.length > 0){
      for(var i = 0; i < childs.length; i++){
        if(childs[i].nodeName != "SCRIPT" && childs[i].nodeType == 1){
          if(name == childs[i].name){
            return childs[i];
          }
          if(childs[i].hasChildNodes() ){
            element = this.wGetElementByName(name, childs[i]);
          }
          if(element != null){
            return element;
          }
        }
      }
    }
    else{
      return element;
    }
  };

  this.wGetFirstChild = function(object){
    if(object == null || typeof object != 'object'){
      return false;
    }
    if(object.firstChild.nodeType != 1){
      return object.firstChild.nextSibling;
    }
    return object.firstChild;
  };
  
  this.wGetPreviousSibling = function(object){
    if(object == null || typeof object != 'object'){
      return false;
    }
    if(object.previousSibling.nodeType != 1){
      return object.previousSibling.previousSibling;
    }
    return object.previousSibling;
  };
  
  this.wGetNextSibling = function(object){
    if(object == null || typeof object != 'object'){
      return false;
    }
    if(object.nextSibling != null && object.nextSibling.nodeType != 1){
      return object.nextSibling.previousSibling;
    }
    return object.nextSibling;
  };  
  
  this.wGetParentNodeId = function(parentId, domObject){
    var parentNode = domObject.parentNode;
    
    while (parentNode != null && parentNode.id != null && parentNode.id != parentId) {
      parentNode = parentNode.parentNode;
    }
    if(parentNode == null){
      return false;
    }
    return parentNode;
  };
  
  this.wGetParentNodeTagName = function(parent, domObject){
    
    var parentNode = domObject.parentNode;
      
    while (parentNode != null && parentNode.tagName != parent) {
      parentNode = parentNode.parentNode;
    }
    if(parentNode == null){
      return false;
    }
    return parentNode;
  };

  this.wGetInputByValue = function(name, value){

    var inputs = document.getElementsByName(name);
    for(var i = 0; i < inputs.length && i < 20; i++){
      if(inputs.item(i).value == value){
        return inputs.item(i);
      }
    }
    return false;
  };

}

function wUserInputHandler(id){
  
  this.userInputs = new Array();
  this.currentId  = null;
  this.id = id;
  this.changeUserName = false;
  this.currUserName = '';
  this.evtObj = new Array();
  
  this.wUserInputHandler = function(){
    this.userInputs[0] = new Object();
    this.evtObj[0] = new Object();
  }
  this.wUserInputHandler();
  
  this.wAppendUserInput = function(id, filterType){
    if(this.userInputs[0][id] == null){
      this.userInputs[0][id] = document.getElementById(id);  
      this.userInputs[0]['display_' + id] = document.getElementById('display_' + id);  
      this.userInputs[0]['filterType_' + id] = filterType;  
    }
  };
  
  this.wSetUserName = function(id){
    if(id == null){
      var id = this.currentId;
    }
    var input = this.userInputs[0][id];
    if(input && input.value != ''){
      var url = '/weblication/grid/scripts/wUsermanager.php?action=getuserdisplayname&user=' + input.value;
      getUrlResponseObject(id, url, this, 'getDisplayName');
    }
  };
  
  this.wShowSelectUser = function(id){
    if(id != null){
      this.currentId = id;
    }
    var filterType = this.userInputs[0]['filterType_' + this.currentId];
    var url = '/weblication/grid/scripts/wUsermanager.php?action=showuseradministrationusers&pageType=dialog&editType=1&templatePrefix=simpleUserSelection&filterType=0&filterTypeValue=' + filterType + '&id=' + this.id;
    wOpenWindow(url, '', '420', '470', '');
  }
  
  this.wRemoveUser = function(id){
    try{
      this.currentId = id;
      this.userInputs[0][id].value = '';
      this.userInputs[0]['display_' + id].value = '';
    }
    catch(e){}
  }
  
  this.wSelectUser = function(user, caption, check){
    
    try{
      if(check === true){
        var filterType = this.userInputs[0]['filterType_' + this.currentId];
        var url = '/weblication/grid/scripts/wUsermanager.php?action=checkuserexistsext&user=' + user + "&filterType=" + filterType;
        getUrlResponseObject(user + "|" + caption , url, this, 'wSelectUser_checkExists');
      }
      this.userInputs[0][this.currentId].value = user;
      if(caption == ''){
        caption = user;
      }
      this.userInputs[0]['display_' + this.currentId].value = caption;
      return true;
    }
    catch(e){
      alert(e + " " + this.currentId + " " + user );
      return false;
    }
  }
  
  this.response = function(callId, responseText, result){
    try{
      if(result == 'getDisplayName'){
        if(responseText != ''){
          this.userInputs[0]['display_' + callId].value = responseText;
        }
        else{
          this.userInputs[0]['display_' + callId].value = this.userInputs[0][callId].value;
        }
      }
      else if(result == 'wSelectUser_checkExists'){
        if(responseText == '1'){
          var userData = callId.split('|');
          this.wSelectUser(userData[0], userData[1]);                  
        }
        else{
          if(!TEXT_MESSAGEBOX_CHECKUSEREXISTS){
            TEXT_MESSAGEBOX_CHECKUSEREXISTS = 'Der angegebene Benutzername exisitert nicht. Klicken Sie auf Ja um die Benutzerauswahl anzuzeigen.'; 
          }  
          wShowMessagebox('userNotSet', '', TEXT_MESSAGEBOX_CHECKUSEREXISTS, 'YESNO', 'loading');
          this.wResetEvent('onmousedown');
        }
      }
    }
    catch(e){}
  }
  
  this.wSetEvent = function(id, obj, evt, evtFunc){
    this.changeUserName = true;
    this.currUserName = obj.value;
    this.currentId = id;
    eval('obj.' + evt + ' = ' + evtFunc);
    this.evtObj[0][evt] = obj;
    
  };
  
  this.wChangeUserName = function(user){
    if(this.userInputs[0]['display_' + this.currentId].value != '' && this.changeUserName && user != this.currUserName){
      this.wSelectUser(user, '', true);
      this.wSetUserName();
    }
    this.wResetEvent('onkeydown');
    this.wResetEvent('onmousedown');
  }
  
  this.wResetEvent = function(evt){
    this.changeUserName = false;
    if(this.evtObj[0][evt] != null){
      eval('this.evtObj[0][evt]' + '.' + evt + ' = null');
    }
  };
  
  this.wFocusCurrObject = function(){
    this.userInputs[0]['display_' + this.currentId].focus();
    userInputHandlerObj.wRemoveUser(this.currentId);
  }
  
  this.onkeydown = function(evt){
    var keyKode = '';
    var inputObject = null;
    if(ie){
      keyCode  = evt.keyCode;
    }
    else{
      keyCode  = evt.keyCode;
      evt.target.style.color = "#000000";
      inputObject = evt.target;
    }
    
    if(keyCode == 13){
      this.wChangeUserName(inputObject.value);
    }
  }
  
  this.onmousedown = function(evt){
    var evtObject = null; 
    if(ie){
    }
    else{
      evtObject = evt.target;
    }
    if(evtObject.id != 'display_' + this.currentId){
       this.wChangeUserName(this.userInputs[0][this.currentId].value);
    }
    else{
      this.wResetEvent('onmousedown');
    }
  }
 
}








function activateCB (cb,val) {
  var allCB = document.getElementsByName(cb).length;
  for (i = 0; i < allCB; i++) {
    var curCBVar = document.getElementsByName(cb)[i].value;
    if(curCBVar == val) {
      if(document.getElementsByName(cb)[i].checked != true) {
        document.getElementsByName(cb)[i].checked = true;
      }
      else {
        document.getElementsByName(cb)[i].checked = false;
      }
    }
  }
}








function removeNoneChars(prefix){

  var currentInput = document.getElementById(prefix);
  var valueBefore  = currentInput.value;
  var valueAfter   = valueBefore.toLowerCase();
  
  valueAfter = valueAfter.replace(/[ä]/g, 'ae');
  valueAfter = valueAfter.replace(/[ö]/g, 'oe');
  valueAfter = valueAfter.replace(/[ü]/g, 'ue');
  valueAfter = valueAfter.replace(/[ß]/g, 'ss');          
  valueAfter = valueAfter.replace(/[^a-zA-Z0-9-_\.]/g, '');             
  
  var diffLength = valueAfter.length - valueBefore.length;
  
  if(valueAfter != valueBefore){
		if(ie){
		  var currentRange = document.selection.createRange();
		  currentRange.collapse(true);
		  var selectionPos   = currentRange.getBookmark().charCodeAt(2) - 2;
		  currentInput.value = valueAfter;
		  var currentRange   = currentInput.createTextRange();
		  currentRange.collapse(true);
		  currentRange.moveStart("character", selectionPos + diffLength);
		  currentRange.moveEnd("character", 0);
		  currentRange.select(); 
		}
		else{
		  var selectionPos = currentInput.selectionStart;              
		  currentInput.value = valueAfter;	 
		  currentInput.setSelectionRange(selectionPos + diffLength, selectionPos +  diffLength);     
		}             
  } 
}
