




if(typeof _ALVINE_BACKEND == 'undefined') var _ALVINE_BACKEND = false;
_ALVINE_BACKEND = (_ALVINE_BACKEND === true)?true:false;
var _ALVINE_DHTML = false;
var _ALVINE_DOM = false;
var _ALVINE_COMPAT_MODE = document.compatMode;
var _ALVINE_QUIRKS_MODE = true;
if(typeof _ALVINE_DEBUG_MODE == 'undefined') var _ALVINE_DEBUG_MODE = false;
_ALVINE_DEBUG_MODE = (_ALVINE_DEBUG_MODE === true)?true:false;
var _ALVINE_ERROR_HANDLER = 'none';  
var _ALVINE_IE = false;
var _ALVINE_IE6 = false;
var _ALVINE_IE7 = false;
var _ALVINE_IE8 = false;
var _ALVINE_NS = false;
var _ALVINE_OP = false;
var _ALVINE_MAC = false;
var _ALVINE_NETSCAPE = false;
var _ALVINE_FIREFOX  = false;
var _ALVINE_FIREFOX2 = false;
var _ALVINE_FIREFOX3 = false;
var _ALVINE_FIREFOX4 = false;
var _ALVINE_SAFARI  = false;
var _ALVINE_SAFARI1 = false;
var _ALVINE_SAFARI2 = false;
var _ALVINE_SAFARI3 = false;
var _ALVINE_SAFARI4 = false;
var _ALVINE_CHROME  = false;  
var _ALVINE_CHROME1  = false;  
var _ALVINE_CHROME2  = false;  
var _ALVINE_CHROME3  = false;  
var _ALVINE_CLIENT_OS = null;


function initLib() {

  if(!_ALVINE_DEBUG_MODE && _ALVINE_ERROR_HANDLER=='none'){
    window.onerror = function(){
      return false;
    }
  }

  
  setCookie("AlvineJavascript", true, 0, '/');

  
  var m = document.compatMode.toString().toLowerCase();
  _ALVINE_COMPAT_MODE = m;
  _ALVINE_QUIRKS_MODE = (m == 'backcompat')?true:false;

  if(navigator.appName=="Netscape") {
    _ALVINE_NETSCAPE = true;
  }

  if(/Windows/.test(navigator.userAgent)){
    _ALVINE_CLIENT_OS = 'win';
  } else if(/Macintosh/.test(navigator.userAgent)){
    _ALVINE_CLIENT_OS = 'mac';
  } else if(/Linux/.test(navigator.userAgent)){
    _ALVINE_CLIENT_OS = 'lin';
  }

  if(navigator.userAgent.indexOf('Chrome')<0){
    if (/AppleWebKit\/(\S+)\s[\s|\S]+/.test(navigator.userAgent)) {
      _ALVINE_SAFARI = true;

      var safariBuild;
      
      var fullVersion;

      if(navigator.userAgent.indexOf('Version')<0){

        if (/Safari\/(\S+)/.test(navigator.userAgent)) {
          safariBuild = RegExp.$1;
          fullVersion = parseInt(safariBuild);
        }

        if(safariBuild<=419){
          version = 1;
          _ALVINE_SAFARI1 = true;
        } else {
          version = 2;
          _ALVINE_SAFARI2 = true;
        }

      } else {

        if (/Version\/(\S+)\sSafari\/(\S+)/.test(navigator.userAgent)) {

          fullVersion = RegExp.$1;
          var version = parseInt(fullVersion); 
          safariBuild = RegExp.$2;

          if(version==4) _ALVINE_SAFARI4 = true;
          else if (version==3) _ALVINE_SAFARI3 = true;

        }
      }
    }
  }

  if(navigator.userAgent.indexOf('Chrome')>0){
    if (/AppleWebKit\/(\S+)\s[\s|\S]+/.test(navigator.userAgent)) {
      _ALVINE_CHROME = true;

      var chromeBuild;
      var webKitBuild = RegExp.$1;
      var fullVersion;

      if (/Chrome\/(\S+)/.test(navigator.userAgent)) {
        chromeBuild = RegExp.$1;
        fullVersion = parseInt(chromeBuild);
      }

      
      if(chromeBuild<530 || fullVersion == 1){
        version = 1;
        _ALVINE_CHROME1 = true;
      } else if(chromeBuild<532 || fullVersion == 2) {
        version = 2;
        _ALVINE_CHROME2 = true;
      } else if(chromeBuild>=532 || fullVersion == 3) {
        version = 3;
        _ALVINE_CHROME3 = true;
      }

    }
  }

  if (/Firefox[\/\s](\d+)(\.(\d+)?)/.test(navigator.userAgent)) {
    var version=new Number(RegExp.$1); 
    _ALVINE_FIREFOX = true;

    if(version==4) _ALVINE_FIREFOX4 = true;
    else if (version==3) _ALVINE_FIREFOX3 = true;
    else if (version==2) _ALVINE_FIREFOX2 = true;
		
  }

  if(navigator.appName=="Netscape") {
    _ALVINE_NETSCAPE = true;
  }

  if(document.getElementById) {
    _ALVINE_DHTML = true;
    _ALVINE_DOM = true;
  }
	
  if(window.opera) {
    _ALVINE_OP = true;
  }

  if(document.all && !_ALVINE_OP) {
		 
    var $versionpattern = /MSIE\s(.*?)\;/i;
    var version = navigator.appVersion.match($versionpattern);
    version = version[1];
					
    if(version.substring(0, 1)=='6') _ALVINE_IE6 = true;
    if(version.substring(0, 1)=='7') _ALVINE_IE7 = true;
    if(version.substring(0, 1)=='8') _ALVINE_IE8 = true;
		 
    _ALVINE_DHTML = true;
    _ALVINE_IE = true;
		
  };
 
  if(document.layers && !_ALVINE_OP) {
    _ALVINE_DHTML = true;
    _ALVINE_NS = true;
  };
	
  if(navigator.userAgent.indexOf("Mac") != -1) {
    _ALVINE_MAC = true;
  };

  if(_ALVINE_DEBUG_MODE && _ALVINE_ERROR_HANDLER!='none' && _ALVINE_IE6){
    window.onerror = handleErrors;
  }

};




function getElementID(id) {
  return getElement('id', id);
};






function getElement(type, ptr, index) {

  if(_ALVINE_DOM) {
    if(type.toLowerCase()=="id") {
      if(typeof document.getElementById(ptr) == "object") {
        return document.getElementById(ptr);
      };
      return void(0);

    } else if(type.toLowerCase()=="name") {
      if(typeof document.getElementsByName(ptr) == "object") {
        return document.getElementsByName(ptr)[index];
      };
      return void(0);

    } else if(type.toLowerCase()=="tagname") {
      if(typeof document.getElementsByTagName(ptr) == "object" || (_ALVINE_OP && typeof document.getElementsByTagName(ptr) == "function")) {
        return document.getElementsByTagName(ptr)[index];
      };
      return void(0);
    } else {
      return void(0);
    };

  } else if(_ALVINE_IE) {

    if(type.toLowerCase()=="id") {
      if (typeof document.all[ptr] == "object") {
        return document.all[ptr];
      };
      return void(0);

    } else if(type.toLowerCase()=="tagname") {
      if(typeof document.all.tags(ptr) == "object") {
        return document.all.tags(ptr)[index];
      };
      return void(0);

    } else if(type.toLowerCase()=="name") {
      if(typeof document[ptr] == "object") {
        return document[ptr];
      };
      return void(0);
    } else {
      return void(0);
    };

  } else if(_ALVINE_NS) {

    if(type.toLowerCase()=="id" || type.toLowerCase()=="name") {
      if (typeof document[ptr] == "object") {
        return document[ptr];
      };
      return void(0);

    } else if(type.toLowerCase()=="index") {
      if (typeof document.layers[ptr] == "object") {
        return document.layers[ptr];
      };
      return void(0);
    } else {
      return void(0);
    };
  };
  return void(0);
}




function writeHTML(obj, content) {

  if(!obj) return void(0);
  if(_ALVINE_OP) {
    obj.innerHTML = content;
  } else if(_ALVINE_DOM) {   
    if(typeof(obj.innerHTML)!="undefined") {
      obj.innerHTML = content;
    } else {
  
  };
  } else if(_ALVINE_IE) {
  
  } else if(_ALVINE_NS) {
    obj.document.open();
    obj.document.write(content);
    obj.document.close();
  };
	 
  return void(0);
};

function changeSource(obj, source) {
  if(!obj) return;
  if(!source) return;
  obj.src=source;
}




function writeContent(obj, content) {

  if(!obj) return void(0);
  if(_ALVINE_OP) {

  
	 
  } else if(_ALVINE_DOM) {
    if(obj.firstChild) {
      obj.firstChild.nodeValue = content;
    };

  } else if(_ALVINE_IE) {
    obj.innerText = content;

  } else if(_ALVINE_NS) {
    obj.document.open();
    obj.document.write(content);
    obj.document.close();
  };
  return void(0);
};



function moveElementTo(obj, x, y) {

  if(_ALVINE_DOM || _ALVINE_OP) {
    obj.style.left = x+'px';
    obj.style.top = y+'px';
  } else if(_ALVINE_NS) {
    obj.moveTo(x, y);
  };

};
 
function setVisibilityMode(obj, flag) {

  if(!obj) return void(0);

  if(_ALVINE_DOM || _ALVINE_OP) {
    if(flag) {
      obj.style.visibility = "visible";
      obj.style.display = "block";
    } else {
      obj.style.visibility = "hidden";
      obj.style.display = "none";
    };

  } else if(_ALVINE_IE) {
    if(flag) {
      obj.style.visibility = "visible";
      obj.style.display = "block";
    } else {
      obj.style.visibility = "hidden";
      obj.style.display = "none";
    };
	 
  } else if(_ALVINE_NS) {
    if(flag) {
      obj.visibility="show";
      obj.display="block";
    } else {
      obj.visibility="hide";
      obj.display="none";
    };
  };
  return void(0);
};




function setVisibility(obj, flag) {

  if(!obj) return void(0);

  if(_ALVINE_DOM || _ALVINE_OP) {
    if(flag) {
      obj.style.visibility = "visible";
      obj.style.display = "block";
    } else {
      obj.style.visibility = "hidden";
      obj.style.display = "none";
    };

  } else if(_ALVINE_IE) {
    if(flag) {
      obj.style.visibility = "visible";
      obj.style.display = "block";
    } else {
      obj.style.visibility = "hidden";
      obj.style.display = "none";
    };
	 
  } else if(_ALVINE_NS) {
    if(flag) {
      obj.visibility="show";
      obj.style.display = "block";
    } else {
      obj.visibility="hide";
      obj.style.display = "none";
    };
  };
  return void(0);
};









function getLeftOfElement(obj, id) {

  if(_ALVINE_NS) return obj.pageX;

  if(!id) id = "noid";
  var left = obj.offsetLeft;
  if(obj.id==id) return left;

  if(obj.offsetParent!=null && obj.offsetParent.tagName!="HTML") {
    left += getLeftOfElement(obj.offsetParent);
  };
  return left;
}

function toggleFoldTableRow(id) {
	
  var tbl, row;
  row = getElementID(id);
  if(!row) return false;

  if(row) {

    if(row.style.display=='none' || !row.style.display) {
			
      foldTableRow(row, true);
			
    } else {

      foldTableRow(row, false);
			
    }
  }
	
  return true;
}

function foldTableRow(obj, forcedStatus) {
  obj = element_isObject(obj);

  if(!obj) return;
	
  if(forcedStatus) {
    
    
    try {
      obj.style.display = 'table-row';
    } catch(e) {
      obj.style.display = 'block';
    }
  
  } else {
    obj.style.display = 'none';
  }
	
  return true;
}





function getTopOfElement(obj, id) {

  if(_ALVINE_NS) return obj.pageY;
  if(!id) id = "noid"; 
  var top = obj.offsetTop;

  if(obj.id==id) return top;
  if(obj.offsetParent!=null && obj.offsetParent.tagName!="HTML") {
    top += getTopOfElement(obj.offsetParent);
  };
	
  
	
  return top;
}


function getHeightOfElement(obj) {
  if(_ALVINE_NS) return obj.height;
  return obj.offsetHeight;
};


function getWidthOfElement(obj) {
  if(_ALVINE_NS) return obj.width;
  return obj.offsetWidth;
};

function getCookie(name) {

  name = name.replace(/^\s+|\s+$/g,"");

  values = document.cookie;
  values = values.split(";");
 
  for(var i=0;i<values.length;i++) {
    var p = values[i].split("=");
    p[0] = p[0].replace(/^\s+|\s+$/g,"");
    if(name==p[0]) {
      return p[1];
    }
  }
  return "";
};


function setCookie(name, value, expires, path, domain, secure) {
  var today = new Date();
  today.setTime(today.getTime());
  if(expires) {
    expires = expires*86400000;
  };
  var expireDate = new Date(today.getTime()+(expires));
  document.cookie = name+"="+escape(value)+
  ((expires)?";expires="+expireDate.toGMTString():"")+
  ((path)?";path="+path:"")+
  ((domain)?";domain="+domain:"")+
  ((secure)?";secure":"");
} 



function alvine_getClientWidth() {
  return alvine_getRectStruct (window.innerWidth ? window.innerWidth : 0,
    document.documentElement ? document.documentElement.clientWidth : 0,
    document.body ? document.body.clientWidth : 0
    );
}

function alvine_getClientHeight() {
  return alvine_getRectStruct (window.innerHeight ? window.innerHeight : 0,
    document.documentElement ? document.documentElement.clientHeight : 0,
    document.body ? document.body.clientHeight : 0
    );
}

function alvine_getScrollLeft() {
  return alvine_getRectStruct (window.pageXOffset ? window.pageXOffset : 0,
    document.documentElement ? document.documentElement.scrollLeft : 0,
    document.body ? document.body.scrollLeft : 0
    );
}

function alvine_getScrollTop() {
  return alvine_getRectStruct (window.pageYOffset ? window.pageYOffset : 0,
    document.documentElement ? document.documentElement.scrollTop : 0,
    document.body ? document.body.scrollTop : 0
    );
}

function alvine_getRectStruct(n_win, n_docel, n_body) {
  var n_result = 0;
  if(n_win) n_result = n_win;
  if(n_docel && (!n_result || (n_result > n_docel))) n_result = n_docel;
  return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
};




function alvineSimpleAjaxRequest(url, id, errorID, appendInputFlag) {
  var url = url;
  var containerID = (typeof id != 'object')?id:id.id;
  var errorContainerID = (typeof errorID != 'object')?errorID:errorID.id;
  var requestObj = false;
	
  var urlData = new Array();
  var callBacks = new Array();
  var finalCallBacks = new Array();

  var urlControlData = new Array();
  var urlControlID = new Array();

  var urlStaticParameter = "";
  var urlOneWayParameter = "";

  var appendInput = (appendInputFlag===true)?true:false;

  this.addToUrl = function(urlPart) {
    url+= ','+urlPart;
  }

  this.addParameter = function(part) {
    if(urlStaticParameter.length>0) urlStaticParameter += '&';
    urlStaticParameter+= part;
  }

  this.addOnWayParameter = function(part) {
    if(urlOneWayParameter.length>0) urlOneWayParameter += '&';
    urlOneWayParameter+= part;
  }

  function checkState() {
    
    
    
    
    
    if(requestObj.readyState!=4) return false;

    if(requestObj.status==200) {
      return requestObj.responseText;
    } else {
		
      errorMsg = 'Error: '+requestObj.status; 

      if(errorContainerID!=null) {
        obj = getElement('id', errorContainerID);
        writeHTML(obj,errorMsg);
        return false;
      };

      return errorMsg;
    }
  }
	
  this.sendRequest = function() {
			 
    requestObj = null;
    if(window.XMLHttpRequest) { 
      requestObj = new XMLHttpRequest();
      if (requestObj.overrideMimeType) {
        requestObj.overrideMimeType('text/html'); 
      };
    } else if(window.ActiveXObject) { 
      try {
        requestObj = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        try {
          requestObj = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
        };
      }
    };

    if(!requestObj) {
		
      errorMsg = 'no ajax'; 

      if(errorContainerID!=null) {
        obj = getElement('id', errorContainerID);
        writeHTML(obj,errorMsg);
        return false;
      };

      return false;
    }

    var parameters = urlStaticParameter;
    if(parameters.length>0) parameters += '&';
    parameters += urlOneWayParameter;
    urlOneWayParameter = "";
    for(i=0; i<urlData.length;i++) {
      if(parameters.length>0) parameters += '&';
      value = eval(urlData[i]);
      parameters += 'sxx_ajax['+urlData[i]+']='+value;
    };

    for(i=0; i<urlControlID.length;i++) {
      if(parameters.length>0) parameters += '&';
      value = eval(urlControlData[i]);
      parameters += 'sxx_ajax['+urlControlID[i]+']='+value;
    };

    if(parameters.length>0) parameters += '&';
    parameters += 'r='+(1 + 10000*(Math.random()));
		
    try {
      requestObj.onreadystatechange = eventHandler;
      requestObj.open('POST', url, true);
      requestObj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');   
      requestObj.send(parameters); 
    } catch (e) {
      alert(e);
    };
  }

  this.bindControl = function(key, id) {
    handler = 'o=getElementID(\''+id+'\'); if(o) o.value;';
    urlControlData[urlControlData.length] = handler;
    urlControlID[urlControlID.length] = key;
  }
	
  this.bindVariable = function(key) {
    urlData.push(key);
  }

  this.bindCallback = function(callBack, forceExecution) {
    var newEntry = new Object();
    newEntry.forcedExecution = (forceExecution===true)?true:false;
    newEntry.cbfunction = callBack;
    finalCallBacks.push(newEntry);
  };
	
  this.bindObjectCallback = function(callBack) {
    callBacks.push(callBack);
  };

  function eventHandler() {
    var result = checkState();

    if(result!=false){
      var obj = getElement('id', containerID);
      resultContent = result;

      scriptStartIndex = resultContent.indexOf('<json>');
      if(scriptStartIndex>=0) {
        scriptEndIndex = resultContent.indexOf('</json>');
        skript = resultContent.substr(scriptStartIndex+6, scriptEndIndex-scriptStartIndex-6);
        data=alvine_getParsedJSONObject(skript);
        for(j=0;j<callBacks.length;j++) {
          callBacks[j]('json',data);
        };
        resultContent = resultContent.substr(0,scriptStartIndex)+resultContent.substr(scriptEndIndex+6+1,resultContent.length);
      };


      outScript = "";

      var collectorObj = document.createElement('DIV');
      writeHTML(collectorObj, resultContent);

      var scriptSegments = collectorObj.getElementsByTagName('SCRIPT');
      var scriptSegmentSeek = /\<script\s\S+type\=\"text\/javascript\"\S*\>(.*)\<\/script\>/;
      scriptSegmentSeek.exec(resultContent, 'g');

      if(scriptSegments){
        for(i=0; i<scriptSegments.length; i++) {
          if(typeof scriptSegments[i] != 'object') continue;
          var newContent = scriptSegments[i].innerHTML;
          newContent    += (newContent.substring(-1)!=';')?';':'';
          outScript     += newContent;

          if(typeof scriptSegments[i].parentNode == 'undefined') continue;
          if(typeof scriptSegments[i].parentNode.removeChild != 'function') continue;
          scriptSegments[i].parentNode.removeChild(scriptSegments[i]);
        }
        resultContent = collectorObj.innerHTML;
      }
	      
      scriptStartIndex = resultContent.indexOf('<array>');
      if(scriptStartIndex>=0) {
        scriptEndIndex = resultContent.indexOf('</array>');
        skript = resultContent.substr(scriptStartIndex+7, scriptEndIndex-scriptStartIndex-7);

        data=eval(skript);
        for(j=0;j<callBacks.length;j++) {
          callBacks[j]('array',data);
        };
        resultContent = resultContent.substr(0,scriptStartIndex)+resultContent.substr(scriptEndIndex+7+1,resultContent.length);
      };

      scriptStartIndex = resultContent.indexOf('<object>');
      if(scriptStartIndex>=0) {
        scriptEndIndex = resultContent.indexOf('</object>');
        skript = resultContent.substr(scriptStartIndex+8, scriptEndIndex-scriptStartIndex-8);
        data=eval(skript);
        for(j=0;j<callBacks.length;j++) {
          callBacks[j]('object',data);
        };
        resultContent = resultContent.substr(0,scriptStartIndex)+resultContent.substr(scriptEndIndex+8+1,resultContent.length);
      };

      if(appendInput) {
        obj.innerHTML+= resultContent;
      } else {
        writeHTML(obj, resultContent);
      }

      if(outScript) eval(outScript);

      if(finalCallBacks.length>0){ 
        for(j=0;j<finalCallBacks.length;j++) {
          eval(finalCallBacks[j].cbfunction);
        }
      }

      return;
    }

    if(finalCallBacks.length>0){
      for(j=0;j<finalCallBacks.length;j++) {  
        if(!finalCallBacks[j].forcedExecution) continue;
        eval(finalCallBacks[j].cbfunction);
      }
    }

    return;
  };
	
};

function getViewportHeight() {

  vpHeight = null;
  if(document.documentElement.clientHeight) {  
    vpHeight = document.documentElement.clientHeight
  } else if(window.innerHeight) { 
    vpHeight = window.innerHeight;
  } else if(document.clientHeight) {
    vpHeight = document.clientHeight;
  } else if(document.body && document.body.clientHeight) { 
    vpHeight = document.body.clientHeight;
  } else if(document.documentElement.clientHeight) {  
    vpHeight = document.documentElement.clientHeigt;
  } else { 
  }
  return vpHeight;
}

function getViewportWidth() {

  vpWidth = null;
  if(document.documentElement.clientWidth) {  
    vpWidth = document.documentElement.clientWidth
  } else if(window.innerWidth) { 
    vpWidth = window.innerWidth;
  } else if(document.clientWidth) {
    vpWidth = document.clientWidth;
  } else if(document.body && document.body.clientWidth) { 
    vpWidth = document.body.clientWidth;
  } else if(document.documentElement.clientWidth) {  
    vpWidth = document.documentElement.clientWidth;
  } else { 
  }
	
  return vpWidth;
}

function handleErrors(msg,file,line){
  var eMesg = null;
  
  eMesg = 'Error: '+msg+"\n"+"\n"+'File:'+file+"\n"+"\n"+'Line:'+line+"\n";
  alert(eMesg);

  return true;
}


function ie6ToggleActiveXControls(state){

  if(!_ALVINE_IE6) return true;

  state = (state===false)?false:true;

  var objectList = {};
  var controlList = new Array('select');
  var i;

  for(i=0; i<controlList.length; i++){
    objectList[controlList[i]] = document.getElementsByTagName(controlList[i]);
  }

  for(var k in objectList){
    var fieldList = objectList[k];
    for(i=0; i<fieldList.length; i++){
      if(typeof fieldList[i] != 'object') continue;
      if(typeof fieldList[i].className == 'undefined') continue;      
      if(state==true){
        
        if(fieldList[i].style.visibility != 'hidden') continue; 
        var newDisplay = (typeof fieldList[i].alvine_displayInitValue != 'undefined')?fieldList[i].alvine_displayInitValue:'visible';
        element_setVisibility(fieldList[i], newDisplay);

      } else {

        if(typeof fieldList[i].alvine_displayInitValue == 'undefined') fieldList[i].alvine_displayInitValue = fieldList[i].style.visibility;
        element_setVisibility(fieldList[i], 'hidden');

      }
    }
  }

  return true;
}



function alvine_getParsedJSONObject(jsonData) {

  try{
    if(typeof JSON=='undefined') {
      JSON = {};
      JSON.parse = function(expr) {
        return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(expr.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + expr + ')');
      }
    }

  } catch(event) {};
  return JSON.parse(jsonData);
}






function uniqueArray(arr) {
  var o = {};
  var tmp = new Array();
  for(var i = 0 ; i < arr.length; i++) o[arr[i]] = true;
  for(var i in o) tmp[tmp.length] = i;
  return tmp;
};

function removeFromArray(arr, entry) {
  var o = {};
  var tmp = new Array();
  for(var i = 0 ; i < arr.length; i++) {
    if(arr[i]==entry) continue;
    o[i] = arr[i];
  }
  for(var i in o) tmp[tmp.length] = o[i];
  return tmp;
};



initLib();



function str_replace(Search, Replace, Subject){

 if ((Subject == null) || (Search == null)) return null;
 if ((Subject.length == 0) || (Search.length == 0)) return Subject;
 if ((Replace == null) || (Replace.length == 0)) Replace = "";

 var LengthSearch = Search.length;
 var LengthReplace = Replace.length;
 var Pos = Subject.indexOf(Search, 0);

 while (Pos >= 0){
   Subject = Subject.substring(0, Pos) + Replace + Subject.substring(Pos + LengthSearch);
   Pos = Subject.indexOf(Search, Pos + LengthReplace);
 }
 
 return Subject;
}

function strstr(Haystack, Needle){

 if ((Haystack == null) || (Needle == null)) return null;
 if ((Haystack.length == 0) || (Needle.length == 0)) return null;

 if(typeof Haystack.indexOf == 'undefined') return false;
 
 var result = Haystack.indexOf(Needle);
 
 if(result<0) return false;

 return true;
}

function rtrim(string){
  if(typeof string == 'undefined' || 
     typeof string.substr == 'undefined') return string;
  var lastCharacter = string.length - 1; 
  while(string.substr(lastCharacter)==' '){
    
    if(string.substr(lastCharacter)!=' ' || lastCharacter<=0) break;
    
    string = string.substr(lastCharacter);
    lastCharacter = string.length - 1;
  }
  
  return string;

}

function ltrim(string){
  if(typeof string == 'undefined' || 
     typeof string.substr == 'undefined') return string;
  while(string.substr(0, 1)==' '){
    
    if(string.substr(0, 1)!=' ' || string.length<=0) break;
    
    string = string.substr(1);
  }
  
  return string;
}

function trim(string){
  
  ltrim(string);
  rtrim(string);
  
  
  return string;
}




function js_rand( min, max ) {
  
  if( min > max ) {
    return( -1 );
  }
  
  if( min == max ) {
    return( min );
  }
  
  return( parseInt(min) + parseInt( Math.random() * ( parseInt(max) - parseInt(min) + 1 ) ));

}


function js_parable(a, b, c){
  
  a = Math.pow(a, 2);
  return (a + (a*b) + c);
}


function js_acceleration(distance, angle){
  
  
  var rad = (angle*Math.PI/180);
  
  return (Math.sin(rad)*distance);

}

function js_convertPercentage(percent, max){
  return ((max / 100) * percent);

}



function time_initDateTime(time){

  var paramKeys = new Object();
  paramKeys['year'] = 1970;
  paramKeys['month'] = 0;
  paramKeys['day'] = 1;
  paramKeys['hours'] = 0;
  paramKeys['minutes'] = 0;
  paramKeys['seconds'] = 0;
  
  
  
  if(typeof time == 'object'){
    var initTime = new Object();
    
    for(var i in paramKeys){
      if(typeof time[i] == 'undefined') {
        initTime[i] = paramKeys[i];
        continue;
      }
      
      var value = time[i];
      switch(i){
        default:          
          break
        case 'month':   
          value = parseInt(time[i])-1;
          break;
      
      }
      initTime[i] = parseInt(value);
      
    }

    var timeOject = new Date(initTime.year, initTime.month, initTime.day, initTime.hours, initTime.minutes, initTime.seconds);
  } else {
    var timeOject = new Date();
  }
  
  return timeOject;
}

function time_getTimestamp(time){
  
  var now = time_initDateTime(time);

  
  var year    = now.getFullYear();  
  var month   = now.getMonth()+1;
  var day     = now.getDate();
  var minutes = now.getMinutes();
  var hours   = now.getHours();
  var seconds = now.getSeconds();
  
  
  
  var timestamp = new Array(); 
  timestamp.push(year); 
  timestamp.push(str_pad(month,2,'0','left')); 
  timestamp.push(str_pad(day,2,'0','left')); 
  timestamp.push(str_pad(hours,2,'0','left')); 
  timestamp.push(str_pad(minutes,2,'0','left')); 
  timestamp.push(str_pad(seconds,2,'0','left')); 
  
  
  timestamp = timestamp.join('');
  
  return timestamp;
}


function time_getUnixTimestamp(time){
  
  
  var timestamp = (time_getMilliTimestamp(time)/1000);
  
  return timestamp;
}


function time_getMilliTimestamp(time){
  
  var now = time_initDateTime(time);
  var milliTime = now.getTime();
  
  return milliTime;
}







function alvine_element_createObjectPath(initObject, pathString){

  if(typeof initObject != 'object') initObject = document;

  var pathParts = pathString.split('.');
  var newObjName = pathParts.shift();

  if(typeof initObject[newObjName] != 'object') initObject[newObjName] = new Object();

  if(pathParts.length > 0) alvine_element_createObjectPath(initObject[newObjName], pathParts.join('.'));

  return true;
}

if(typeof alvine != 'object') alvine = new Object();
alvine_element_createObjectPath(alvine, 'data.cache.elements');


function page_onLoad(fn, useCapturing){
  obj = window;

  if(typeof event_add == 'undefined') return false;

  useCapturing = (useCapturing===true)?true:false;
  event_add(obj, 'load', fn, useCapturing);

  return true;
}

function page_onScroll(fn, useCapturing){
  obj = document;
  if(_ALVINE_IE) obj = window;

  if(typeof event_add == 'undefined') return false;

  useCapturing = (useCapturing===true)?true:false;
  event_add(obj, 'scroll', fn, useCapturing);

  return true;
}



function element_get(type,res){
  var obj;

  
  
  

  if(document.getElementById) {
    
    if(type=='id') obj = document.getElementById(res);
    
  } else if(document.all) {

    if(type=='id') obj = document.all[res];
  }

  
  

  return obj;
}




function element_addClassName(obj, className) {
  return _element_addClassName(obj, className, ' ');
};


function _element_addClassName(obj,className, offset){
  obj = element_isObject(obj);
  
  if(!obj) return false;
  if(typeof offset == 'undefined') offset = '';
  obj.className+=offset+className;

  return true;
}

function element_removeClassName(obj,className,offset){
  obj = element_isObject(obj);

  if(!obj) return false;
  if(typeof offset == 'undefined') offset = '';
    
  obj.className = str_replace(offset+className, '', obj.className);  
  
  return true;

}

function element_replaceClassName(obj,classNameSearch,classNameReplace){
  obj = element_isObject(obj);
  
  obj.className = str_replace(classNameSearch, classNameReplace, obj.className);
  
  
  return true;

}



function element_move(obj,vleft,vtop){
  obj = element_isObject(obj);
  
  var size = element_getSize(obj);

  vleft = element_recalcValue2px(vleft,size.width);
  vtop  = element_recalcValue2px(vtop,size.height);
  vleft = parseInt(vleft);
  vtop  = parseInt(vtop);

  element_setLeft(obj, vleft);
  element_setTop(obj, vtop);
                          
  return true;
}

function element_center(obj){
  obj = element_isObject(obj);
  
  element_centerX(obj);
  element_centerY(obj);
  
  
  return true;
}

function element_centerX(obj){
  obj = element_isObject(obj);
  
  var viewPort   = alvine_getViewport();

  var size = element_getSize(obj);
  
  var parentCenter = new Object();
  var objectCenter = new Object();
  
  parentCenter.x = parseInt((viewPort.width/2));
  
  objectCenter.x = parseInt((size.width/2));
  
  var newPosition = new Object();
  
  newPosition.x = parentCenter.x - objectCenter.x;
  
  var currentPositionY = element_getPositionY(obj);
  
  element_move(obj, newPosition.x, currentPositionY);
  
  return true;
}

function element_centerY(obj){
  obj = element_isObject(obj);
  
  var viewPort   = alvine_getViewport();


  var size = element_getSize(obj);
  
  var parentCenter = new Object();
  var objectCenter = new Object();
  
  parentCenter.y = parseInt((viewPort.height/2));
  
  objectCenter.y = parseInt((size.height/2));
  
  var newPosition = new Object();
  
  newPosition.y = parentCenter.y - objectCenter.y;
  
  var currentPositionX = element_getPositionX(obj);
  
  element_move(obj, currentPositionX, newPosition.y);
  
  return true;
}

function element_getAbsolutePositionX(obj, id){
  
  obj = element_isObject(obj);
  
  var left = element_getPositionX(obj);

  if(_ALVINE_NS) return left;  
  if(!id) id = "noid"; 


  if(typeof obj.offsetParent != 'object') return left;
  var parentObj = obj.offsetParent;  
  while(parentObj != null && typeof parentObj != 'undefined' && parentObj.tagName!="HTML") {    
    left += element_getPositionX(parentObj);
    if(parentObj.id==id) return left;
    parentObj = parentObj.offsetParent;
  }

  return left;   
  
}

function element_getAbsolutePositionY(obj, id){
  
  obj = element_isObject(obj);
   
  var top = element_getPositionY(obj); 
  if(_ALVINE_NS) return top;
  
  if(!id) id = "noid"; 

  if(typeof obj.offsetParent != 'object') return top;
  var parentObj = obj.offsetParent;
  while(parentObj != null && typeof parentObj != 'undefined' && parentObj.tagName!="HTML") {    
    top += element_getPositionY(parentObj);
    if(parentObj.id==id) return top;
    parentObj = parentObj.offsetParent;
  }
  
  return top;
  
}

function element_getPositionX(obj){  
  
  obj = element_isObject(obj);

  if(typeof obj.style.position != 'undefined'){
    if(obj.style.position == 'absolute' && typeof obj.style.left !='undefined' && obj.style.left != '' && obj.style.left != 'auto'){
      return (parseInt(obj.style.left));
    }
  }
  
  if(typeof obj.offsetLeft =='number'){
    return (parseInt(obj.offsetLeft));
  }
  
  if(typeof obj.clientLeft =='number'){
    return (parseInt(obj.clientLeft));
  }

  if(typeof obj.layerX =='number'){
    return (parseInt(obj.layerX));
  }
  
  if(typeof obj.pageX =='number'){
    return (parseInt(obj.pageX));
  }
  
  return false;
  
}

function element_getPositionY(obj){
  
  obj = element_isObject(obj);

  if(typeof obj.style.position != 'undefined'){
    if(obj.style.position == 'absolute' && typeof obj.style.top != 'undefined' && obj.style.top != '' && obj.style.top != 'auto'){
      return (parseInt(obj.style.top));
    }
  }
  
  if(typeof obj.offsetTop =='number'){
    return (parseInt(obj.offsetTop));
  }
  
  if(typeof obj.clientTop =='number'){
    return (parseInt(obj.clientTop));
  }

  if(typeof obj.layerY =='number'){
    return (parseInt(obj.layerY));
  }
  
  if(typeof obj.pageY =='number'){
    return (parseInt(obj.pageY));
  }
  
  return false;
  
}

function element_getScrollPositionX(){

  if(_ALVINE_IE){
    var left = 0;

    if(_ALVINE_QUIRKS_MODE && document.body && typeof document.body.scrollLeft != 'undefined'){ 
      left = document.body.scrollLeft;
    } else if(typeof document.documentElement != 'undefined'){ 
      if(typeof document.documentElement.scrollLeft != 'undefined'){
        left = document.documentElement.scrollLeft;
      }
    }

    return parseInt(left);
  }

  if(typeof window.pageXOffset != 'undefined'){
    return parseInt(window.pageXOffset);
  }

  if(typeof window.scrollX !='undefined'){
    return parseInt(window.scrollX);
  }

  return 0;
}

function element_getScrollPositionY(){

  if(_ALVINE_IE){
    var top = 0;

    if(_ALVINE_QUIRKS_MODE && document.body && typeof document.body.scrollTop != 'undefined'){ 
      top = document.body.scrollTop;

    } else if(typeof document.documentElement != 'undefined'){ 
      if(typeof document.documentElement.scrollTop != 'undefined'){
        top = document.documentElement.scrollTop;
        
      }
    }

    return parseInt(top);
  }
  
  if(typeof window.pageYOffset != 'undefined'){
    return parseInt(window.pageYOffset);
  }

  if(typeof window.scrollY !='undefined'){
    return parseInt(window.scrollY);
  } 

  return 0;
}


function element_getScrollPosition(){
  var ret = {
    x:0,
    y:0
  };

  ret.x = element_getScrollPositionX();
  ret.y = element_getScrollPositionY();

  return ret;
}
function element_getPosition(obj, absolute, id){
  obj = element_isObject(obj); 
  
  var scrollPos;
  
  if(!absolute){  
    var xpos = element_getPositionX(obj);
    var ypos = element_getPositionY(obj);    
  } else {
    var xpos = element_getAbsolutePositionX(obj, id);
    var ypos = element_getAbsolutePositionY(obj, id);
    
  }

  return {
    x:xpos,
    y:ypos
  };
  
}

function element_setLeft(obj, vleft){
  obj = element_isObject(obj);
  if(!obj) return;

  obj.style.position = (obj.style.position!='fixed' && obj.style.position!='absolute')?'absolute':obj.style.position;
  vleft = vleft+0;
  obj.style.left  = vleft.toString() + "px";

  return true;
}

function element_setTop(obj, vtop){
  obj = element_isObject(obj);
  
  obj.style.position = (obj.style.position!='fixed' && obj.style.position!='absolute')?'absolute':obj.style.position;
  vtop = vtop+0;
  obj.style.top  = vtop.toString() + "px";

  return true;
}

function element_getZIndex(obj,value){
  obj = element_isObject(obj);
      
  if(obj.style.zIndex != null) {
    return obj.style.zIndex;
  }
  
  return true; 
}

function element_setZIndex(obj,value){
  obj = element_isObject(obj);
      
  if(obj.style.zIndex != null) {
    obj.style.zIndex  = value;
    return true;
  }
  
  return true; 
}


function element_setDisplay(obj,status){
  obj = element_isObject(obj);
  if(!obj) return false;
  
  obj.style.display = status;
  
  return true;
}

function element_setVisibility(obj,status){
  obj = element_isObject(obj);

  obj.style.visibility = status;
  
  return true;
}

function element_isVisible(obj){
  obj = element_isObject(obj);

  return (obj.style.visibility=='visible')?true:false;

}

function element_resetOpacity(obj){
  
  obj = element_isObject(obj)
  
  if(isDefined(obj.style.MozOpacity)) {
    obj.style.MozOpacity = 1; 
    return true;
  }

  if(isDefined(obj.style.opacity)) {
    obj.style.opacity  = 1;
    return true;
  }

  if(isDefined(obj.filters)) {
    if(!isDefined(obj.filters.alpha)) {
      obj.style.filter = 'alpha(opacity=100)';
      return true;
    }
    obj.filters.alpha.opacity = 100;
    return true;
  }

  if(isDefined(obj.style.KhtmlOpacity)) {
    obj.style.KhtmlOpacity  = 1;
    return true;
  }  
}

function element_setOpacity(obj,value){
  obj = element_isObject(obj);
  
  value = value>100?100:value;
  value = value<0?value*100:value;
  value = parseInt(value);
  value = value<0?0:value;

  if(typeof obj.style.opacity != 'undefined') {
    obj.style.opacity  = value/100;
  }
    
  if(typeof obj.style.MozOpacity != 'undefined') {
    obj.style.MozOpacity = value/100;  
  }

  if(typeof obj.filters != 'undefined') {

    
    if(obj.filters.alpha){
      var hasLayout = element_getComputedStyleProperty(obj,'hasLayout');
      if(!hasLayout && !obj.style.zoom) obj.style.zoom = '1';

      obj.filters.alpha.opacity = value.toString();
    } else {
      obj.style.filter = 'alpha(opacity='+value.toString()+')';
    }
  }

  if(typeof obj.style.KhtmlOpacity != 'undefined') {
    obj.style.KhtmlOpacity  = value/100;
  }
  
  return true; 
}

function element_getOpacity(obj){
  
  obj = element_isObject(obj);

  if(!obj) return 100;

  if(typeof obj.style.opacity != 'undefined' && obj.style.opacity != '') return parseInt(obj.style.opacity*100);
  if(typeof obj.style.MozOpacity != 'undefined' && obj.style.MozOpacity != '') return parseInt(obj.style.MozOpacity*100);
  if(typeof obj.style.KhtmlOpacity!= 'undefined' && obj.style.KhtmlOpacity != '') return parseInt(obj.style.KhtmlOpacity*100);

  if(document.all && document.all[obj.id] && document.all[obj.id].style){
    if(document.all[obj.id].style.opacity) return parseInt(document.all[obj.id].style.opacity*100);
    if(document.all[obj.id].style.MozOpacity) return parseInt(document.all[obj.id].style.MozOpacity*100); 
    if(document.all[obj.id].style.KhtmlOpacity) return parseInt(document.all[obj.id].style.KhtmlOpacity*100);
  }
  
  if(typeof obj.filters != 'undefined' && obj.filters != '') {
    if(obj.filters.alpha && obj.filters.alpha.opacity) {
      return parseInt(obj.filters.alpha.opacity);
    } else {

      var compOpacity = element_getComputedStyleProperty(obj,'opacity');
      if(compOpacity){
        return parseInt(compOpacity*100);
      } else {
        obj.style.filter = 'alpha(opacity=100)';
        return parseInt(obj.filters.alpha.opacity);
      }
    }
  }

  var compOpacity = element_getComputedStyleProperty(obj,'opacity');
  if(!compOpacity) compOpacity = element_getComputedStyleProperty(obj,'MozOpacity');
  if(!compOpacity) compOpacity = element_getComputedStyleProperty(obj,'KhtmlOpacity');

  if(compOpacity) return parseInt(compOpacity*100);

  return 100;
}



function element_getSize(obj){
  
  obj = element_isObject(obj);
  
  var ret = new Object();
  ret['width']  = element_getWidth(obj);    
  ret['height'] = element_getHeight(obj);

  return ret;
}

function element_getWidth(obj){  
  obj = element_isObject(obj);
  
  if(!obj) return null;
   
  switch(obj.tagName){
    case 'TR':
      
      return element_getWidth(obj.parentNode);
      break;
    default:
      break;
  }

  

  if(typeof obj.style != 'undefined' && typeof obj.style.width != 'undefined' && obj.style.width != null && obj.style.width != '' && obj.style.width!='auto') return parseInt(obj.style.width);

  if(typeof obj.offsetWidth != 'undefined' && obj.offsetWidth != null && obj.offsetWidth != '') return parseInt(obj.offsetWidth);

  if(typeof obj.clientWidth != 'undefined' && obj.clientWidth != null && obj.clientWidth != '') return parseInt(obj.clientWidth);
  
  if(typeof obj.width != 'undefined' && obj.width != null && obj.width != '') return parseInt(obj.width);
  
  if(typeof obj.naturalWidth != 'undefined' && obj.naturalWidth != null && obj.naturalWidth != '') return parseInt(obj.naturalWidth);
  
  if(typeof document.all == 'object'){
    if(typeof document.all[obj.id] != 'undefined' && typeof document.all[obj.id].offsetWidth != 'undefined' && document.all[obj.id].offsetWidth != null && document.all[obj.id].offsetWidth != ''){
      return parseInt(document.all[obj.id].offsetWidth);
    }
  }
  
  if(typeof obj.style != 'undefined' && typeof obj.style.maxWidth != 'undefined' && obj.style.maxWidth != null && obj.style.maxWidth != '') return parseInt(obj.style.maxWidth);
  if(typeof obj.style != 'undefined' && typeof obj.style.minWidth != 'undefined' && obj.style.minWidth != null && obj.style.minWidth != '') return parseInt(obj.style.minWidth);
  
  return 0;
}
function element_getHeight(obj){
  obj = element_isObject(obj);
  
  if(!obj) return null;
  
  switch(obj.tagName){
    case 'TR':
      var tdObjList = obj.getElementsByTagName('TD');
      if(typeof tdObjList[0] == 'undefined') return false;
      var height = 0;
      for(var i in tdObjList){
        if(typeof tdObjList[i].tagName == 'undefined') continue;
        if(tdObjList[i].tagName!='TD') continue;
        
        var tmpHeight = element_getHeight(tdObjList[i]);
        if(tmpHeight<=height) continue;
        
        height = tmpHeight;
      }            
      return height;
      break;
    
    case 'TD':
      var height = 0;

      for(var i in obj.childNodes){
        if(typeof obj.childNodes[i].tagName == 'undefined') continue;
        height+= element_getHeight(obj.childNodes[i]);
      }            
      return height;
      break;
    
  }

  

  if(typeof obj.style != 'undefined' && typeof obj.style.height != 'undefined' && obj.style.height != null && obj.style.height != '' && obj.style.height!='auto') return parseInt(obj.style.height);

  if(typeof obj.offsetHeight != 'undefined' && obj.offsetHeight != null && obj.offsetHeight != '') return parseInt(obj.offsetHeight);
  
  if(typeof obj.clientHeight != 'undefined' && obj.clientHeight != null && obj.clientHeight != '') return parseInt(obj.clientHeight);
  
  if(typeof obj.height != 'undefined' && obj.height != null && obj.height != '') return parseInt(obj.height);
  
  if(typeof obj.naturalHeight != 'undefined' && obj.naturalHeight != null && obj.naturalHeight != '') return parseInt(obj.naturalHeight);
  
  if(typeof document.all == 'object'){
    if(typeof document.all[obj.id] != 'undefined' && typeof document.all[obj.id].offsetHeight != 'undefined' && document.all[obj.id].offsetHeight != null && document.all[obj.id].offsetHeight != ''){
      return parseInt(document.all[obj.id].offsetHeight);
    }
  }
  
  if(typeof obj.style != 'undefined' && typeof obj.style.maxHeight != 'undefined' && obj.style.maxHeight != null && obj.style.maxHeight != '') return parseInt(obj.style.maxHeight);
  if(typeof obj.style != 'undefined' && typeof obj.style.minHeight != 'undefined' && obj.style.minHeight != null && obj.style.minHeight != '') return parseInt(obj.style.minHeight);
  
  return 0;
}

function element_setWidth(obj,width,fixOverflow){
  
  obj = element_isObject(obj);
  
  if(!obj) return null;
  
  fixOverflow = (fixOverflow===false)?false:true;
  
  var inputWidth = width;
  if(_ALVINE_IE) width = width<0?0:width;
  width = (width!='auto')?parseInt(width).toString()+'px':width;
  if(inputWidth.toString().substr(-1)=='%') width = inputWidth;
  
  switch(obj.tagName){
    case 'TR':
      var tdList = obj.getElementsByTagName('TD');
      if(tdList.length==0) return false;
      for(var i in tdList){
        element_setWidth(tdList[i], inputWidth);
      }
      
      return true;
      break;
  }
  
  if(fixOverflow) obj.style.overflow = 'hidden';
  obj.style.width = width;
  
  return true;
}

function element_setHeight(obj,height,fixOverflow){

  obj = element_isObject(obj);
  
  if(!obj) return null;
  
  fixOverflow = (fixOverflow===false)?false:true;

  if(height==false) height = 0;
  var inputHeight = height;
  if(_ALVINE_IE) height = height<0?0:height;
  height = (height!='auto')?parseInt(height).toString()+'px':height;
  if(inputHeight.toString().substr(-1)=='%') height = inputHeight;

  switch(obj.tagName){
    case 'TR':
      var tdList = obj.getElementsByTagName('TD');
      if(tdList.length==0) return false;
      for(var i in tdList){
        element_setHeight(tdList[i], inputHeight);
      }
      
      return true;
      break;
  }

  if(fixOverflow) obj.style.overflow = 'hidden';
  
  obj.style.height = height;
  
  return true;
}

function element_setSize(obj,width,height,fixOverflow){
  obj = element_isObject(obj);
  
  fixOverflow = (fixOverflow===false)?false:true;
  
  element_setWidth(obj, width, fixOverflow);
  element_setHeight(obj, height, fixOverflow);
  
  return true;
}

function element_resetSize(obj){
  obj = element_isObject(obj);
  
  
  element_resetWidth(obj);
  element_resetHeight(obj);
  
  return true;
}

function element_resetWidth(obj){
  obj = element_isObject(obj);

  if(_ALVINE_IE6){
    obj.style.overflow = 'visible';
    obj.style.width = null;
  } else {
    
    obj.style.width = null;
  }

  return true;
}

function element_resetHeight(obj){
  obj = element_isObject(obj);
  
  if(_ALVINE_IE6){
    obj.style.overflow = 'visible';
    obj.style.height = null;
  } else {
    
    obj.style.height = null;
  }
  return true;
}



function element_setBackground(obj,background){

  obj = element_isObject(obj);

  obj.style.background = background;
  
  return true;
}


function element_setText(obj, newString){
  obj = element_isObject(obj);
  
  if(!obj) return false;
  
  if(isDefined(obj.text))        obj.text        = newString;
  if(isDefined(obj.innerText))   obj.innerText   = newString;
  if(isDefined(obj.textContent)) obj.textContent = newString;
  if(isDefined(obj.innerHTML))   obj.innerHTML   = newString;
  
  return true;

}


function element_getText(obj){
  obj = element_isObject(obj);
  
  if(!obj) return false;
  
  if(isDefined(obj.text))        return obj.text;
  if(isDefined(obj.innerText))   return obj.innerText;
  if(isDefined(obj.textContent)) return obj.textContent;
  if(isDefined(obj.innerHTML))   return obj.innerHTML;
  
  return true;

}


function element_addChildNodes(obj, mixed, clear, copyNodes){
  obj = element_isObject(obj);

  if(!obj) return true;

  clear     = (clear==true)?true:false;
  copyNodes = (copyNodes==false)?false:true;

  
  var check = element_isObject(mixed);
  if(check) mixed = check;

  
  if(typeof mixed == 'string'){
    var strObj = document.createElement('DIV');
    strObj.innerHTML = mixed.toString();

    mixed = document.createElement('DIV');
    mixed.appendChild(strObj);

    mixed = mixed.childNodes;
  }

  
  if(typeof mixed.className != 'undefined' && strstr(mixed.className, 'hidden')){
    mixed = mixed.childNodes;
  }

  
  if(mixed == null || (typeof mixed != 'object' && typeof mixed != 'function')) return false;

  if(clear==true){
    
    element_removeChildNodes(obj);
  }

  var copyObj;
  if(typeof mixed.length != 'undefined'){
    for(var i = 0;i< mixed.length;i++){
      if(typeof mixed[i] != 'object') continue;
      try {
        if(copyNodes){
          copyObj = element_cloneNode(mixed[i], true);          
        } else {
          copyObj = mixed[i];
        }
        obj.appendChild(copyObj);
      } catch(e) {
        continue;
      }
    }
  } else {
    if(copyNodes){
      copyObj = element_cloneNode(mixed, true);      
    } else {
      copyObj = mixed;
    }
    obj.appendChild(copyObj);
  }

  return true;
}

function element_cloneNode(obj, recursive){
  if(typeof obj != 'object') return false;

  recursive = (recursive===false)?false:true;

  var newNode = obj.cloneNode(recursive);
  
  element_cloneEvents(obj, newNode, recursive);

  if(typeof obj.alvine_onOpen != 'undefined') newNode.alvine_onOpen = obj.alvine_onOpen;
  if(typeof obj.alvine_onClose != 'undefined') newNode.alvine_onClose = obj.alvine_onClose;

  for(var i in obj){
    
    if(typeof newNode[i] != 'undefined') continue;
    
    try{
      var copyEntity = obj[i];
      newNode[i] = copyEntity;
    } catch(e){
    }
  }

  newNode.id = '';
  element_buildUniqueObjectID(newNode);
  return newNode;
}

function element_cloneEvents(objSrc, objDst, recursive){

  if(typeof objSrc.alvine_eventListeners == 'object'){
    for(var i in objSrc.alvine_eventListeners) {
      var t = objSrc.alvine_eventListeners[i];
      for(var j in t){
        var ev = t[j];
        event_add(objDst, ev.type, ev.fn, ev.useCapture);

      }
    }
  }
  if(!recursive) return;
  
  for(var i=0;i<objSrc.childNodes.length;i++){
    element_cloneEvents(objSrc.childNodes[i], objDst.childNodes[i], recursive);
  }

}



function element_removeChildNodes(obj, childNode){
  obj = element_isObject(obj);
  
  var removeAll = (!isDefined(childNode) || isNull(childNode))?true:false;
  
  if(!removeAll){
    obj.removeChildNode(childNode);
  } else {
    while (obj.childNodes[0]){
      obj.removeChild(obj.childNodes[0]);
    }
  }
  
  return true;
}


function element_calcDifference(value1,value2){

  value1 = parseInt(value1);
  value2 = parseInt(value2);

  var retdiff = value1 - value2;

  
  var retdirection = 1;
  if (value1 < value2) retdirection = -1;
	
  retdiff = retdirection * parseInt(retdiff);
  
  return {
    difference:retdiff,
    direction:retdirection
  };
}

function element_recalcValue2px(value,val100percent){
  if(typeof value == 'undefined') return null;
  if(value == null) return null;

  if(value.toString().substring((value.toString().length-1))=='%'){  
    return parseInt(((val100percent/100) * parseInt(value)));
  }
  
  if(value.toString().substring((value.toString().length-2),2)=='px'){  
    return parseInt(value);
  }

  return parseInt(value);
}




function element_isObject(mixed){
  if(mixed==null) return false;
  
  if (typeof(mixed)=="object") {
    if(typeof mixed.id != 'undefined' && mixed.id=='') element_buildUniqueObjectID(mixed);

    mixed = element_browser_prepareObject(mixed);
    return mixed;
  }
  
  var checkObj = element_get('id',mixed);
  if (typeof checkObj !='object' || checkObj==null) return false;

  if(typeof checkObj.id != 'undefined' && checkObj.id=='') element_buildUniqueObjectID(checkObj);

  checkObj = element_browser_prepareObject(checkObj);  
  return checkObj;
	 
}

function element_isNumber(value){
  if(parseInt(value) != value) return false;
  
  return true;
}

function isNull(val){
  return(val===null);
}

function isDefined(mixed){
  if(typeof mixed == 'undefined') return false;

  return true;
}

function element_getComputedStyleProperty(obj,propertyName){
  obj = element_isObject(obj);
  if(!obj) return null;

  var ret = null;
  if (obj.currentStyle){ 
    if(typeof propertyName != 'undefined' && propertyName != ''){
      ret = (typeof obj.currentStyle[propertyName] != 'undefined')?obj.currentStyle[propertyName]:null;
    } else {
      ret = obj.currentStyle;
    }
  } else if (window.getComputedStyle) { 
    if(document.defaultView.getComputedStyle(obj, null)){
      if(typeof propertyName != 'undefined' && propertyName != ''){
        ret = document.defaultView.getComputedStyle(obj, null).getPropertyValue(propertyName);
      } else {
        ret = document.defaultView.getComputedStyle(obj, null);
      }
    }
  }

  return ret;
}


function element_browser_prepareObject(obj){

  if(_ALVINE_IE){
    obj = element_browser_ie_prepareObject(obj);
  }

  return obj;
}

function element_browser_ie_prepareObject(obj){
  if(!_ALVINE_IE) return obj;
  if(typeof obj != 'object') return obj;

  if(typeof obj.style != 'undefined'){
  
  
  }

  return obj;
}


function alvine_getElementsByAttribute(tagName, attributeName){
	var elements = document.getElementsByTagName(tagName);
	var returnCollection = new Array();
	var current;
	var attribute;
	for(var i=0; i<elements.length; i++){
		current = elements[i];
		attribute = current.getAttribute(attributeName);
    if(typeof attribute == 'undefined') continue;
    if(typeof attribute != 'string') continue;
		returnCollection.push(current);
	}
	return returnCollection;
}






if(typeof alvine == 'undefined') alvine = new Object();
alvine_object_createObjectPath(alvine, 'data.move');

function object_initLibs(ev){
  if(!ev) ev = window.event;

  
  if(typeof alvine.data.move.object == 'undefined') alvine.data.move.object = null;

  event_add(document, 'mousemove', object_moveObject);
  event_add(document, 'mouseup',   object_toggleMoving);

  
  
  return true;
}
 
function object_count(obj){
  
  if(typeof obj != 'object') return 0;
  
  var cnt = 0;
  for(var i in obj){
    cnt++;
  }
  
  return cnt;
}


function alvine_object_addObserver(srcID, targetID, callBackFunction){
  
  var sourceObj = element_isObject(srcID);
  var thisObj = element_isObject(targetID);
    
  if(!sourceObj) return null;
  if(!thisObj) return null;
  
  callBackFunction = (typeof callBackFunction == 'undefined')?'alvine_handleEvent':callBackFunction;
  
  if(typeof thisObj['alvine_observers'] == 'undefined') thisObj['alvine_observers'] = new Object();
  if(typeof thisObj['alvine_observers'][callBackFunction] == 'undefined') thisObj['alvine_observers'][callBackFunction] = new Array();
  
  
  var newObserver = new Object();
  newObserver.id = srcID;
  
  thisObj['alvine_observers'][callBackFunction].push(newObserver);
  
  
  
  if(typeof thisObj.alvine_notifyObserver == 'undefined'){
    thisObj['alvine_notifyObserver'] = function(observerKey, data){
      
      observerKey = (typeof observerKey == 'undefined')?'alvine_handleEvent':observerKey;
      
      if(typeof this.alvine_observers[observerKey] == 'undefined') return false;
      
      var myObservers = this.alvine_observers[observerKey];
      
      if(myObservers.length==0) return false;
      
      if(typeof data == 'undefined') data = new Object();
      
      for(var i in myObservers){
        var entry = myObservers[i];
        var oObj = element_isObject(entry.id);

        oObj[observerKey](data, this);
      }
    
      return true;
    };
  }
  
  
  
  if(typeof sourceObj[callBackFunction] == 'undefined'){
    sourceObj[callBackFunction] = function(data, srcObj){
      
      
    
      return true;
    };
  }
  
  return true;

}


function alvine_object_hasObservers(obj){
  obj = element_isObject(obj);
  
  if(typeof obj.alvine_notifyObserver == 'undefined') return false;
  if(typeof obj.alvine_observers == 'undefined') return false;
  
  return true;
}

function alvine_object_createObjectPath(initObject, pathString){
  
  if(typeof initObject != 'object') initObject = document;

  var pathParts = pathString.split('.');
  var newObjName = pathParts.shift();

  if(typeof initObject[newObjName] != 'object') initObject[newObjName] = new Object();

  if(pathParts.length > 0) alvine_element_createObjectPath(initObject[newObjName], pathParts.join('.'));

  return true;
}

function element_buildUniqueObjectID(object){
  obj = object;
  
  if(typeof obj != 'object' && typeof obj != 'function') return null;

  var id = null;
  if(!obj){
    id = (!isNull(object))?object:'generic';
  } else {
    if(isDefined(obj.id) && obj.id!='') {
      id = obj.id;
    } else if(isDefined(obj.tagName)){
      id = obj.tagName.toLowerCase();
    } else if(isDefined(obj.nodeName)){
      id = obj.nodeName.toLowerCase();
    } else if(isDefined(obj.localName)){
      id = obj.localName.toLowerCase();
    }
  }

  var now = new Date();
  var newID = id + '_' + now.getTime() + now.getMilliseconds() + js_rand(0000, 9999);
  
  alvine_object_createObjectPath(alvine, 'session.generatedObjectIDs');

  if(!isDefined(alvine.session.generatedObjectIDs[newID])){
    if(obj && !obj.id) {
      obj.id = newID;
    }
    alvine.session.generatedObjectIDs[newID]  = newID;
  } else {
    newID = element_buildUniqueObjectID(obj);
  }
  return newID;
}

function alvine_getViewport(){
  
  var w = null;
  var h = null;
    
  if(typeof window.innerWidth != 'undefined'){
    w = window.innerWidth;
    h = window.innerHeight;

    return {width:w, height:h};
  }

  if(typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth != 'undefined' 
     && document.documentElement.clientWidth != 0){
    w = document.documentElement.clientWidth;
    h = document.documentElement.clientHeight;

    return {width:w, height:h};
  }

  if(typeof document.getElementsByTagName('body')[0].clientWidth != 'undefined'){
    w = document.getElementsByTagName('body')[0].clientWidth;
    h = document.getElementsByTagName('body')[0].clientHeight;

    return {width:w, height:h};
  }

  return false;
}

function alvine_object_selectAddOption(selectObj, newString, newValue, selected){
  selectObj = element_isObject(selectObj);
  
  var newOption = document.createElement("option");
  newOption.text     = newString;  
  newOption.value    = newValue;
  if(selected===true) newOption.setAttribute('selected', true);

  if(_ALVINE_IE){ 
	
	if(selectObj.type != 'select-one' && selectObj.type != 'select-multiple') return false;
  }else{
	if(typeof selectObj.add != 'function') return false;
  }

  try {
    selectObj.add(newOption, null); 
  }
  catch(ex) {
    selectObj.add(newOption); 
  }
  
  return true;
}

function alvine_object_selectRemoveOption(selectObj, delValue){
  selectObj = element_isObject(selectObj);
  
  for(var i in selectObj.options){
    var tmpOption = selectObj.options[i];    
    if(tmpOption == null) continue;
    if(!isDefined(tmpOption.value)) continue;
    if(tmpOption.value != delValue) continue;
    
    selectObj.remove(i);
    return true;
  }
  
  return false;
}

function alvine_array_keys(mixed){
  var ret = new Array();
    
  for(var key in mixed) {
    ret.push(key);
  }
  return ret;
}

function alvine_bubble_kSort(mixed, direction){
  
  if(typeof mixed != 'object') return mixed;       
  direction = !direction?'regular':direction;
    
  var x, y, holder;
  var mixedKeys   = alvine_array_keys(mixed);  
  var cKey, nKey;
  for(x = 0; x < mixedKeys.length; x++) {    
    for(y = 0; y < (mixedKeys.length-1); y++) {
      cKey = mixedKeys[y];
      nKey = mixedKeys[y+1];
      var proceed = false;
      
      if(direction=='regular'){
        if(parseInt(cKey) > parseInt(nKey)) proceed = true;
      } else if(direction=='reverse'){
        if(parseInt(cKey) < parseInt(nKey)) proceed = true;
      }
      
      if(!proceed) continue;
      
      holder         = mixedKeys[y+1];
      mixedKeys[y+1] = mixedKeys[y];
      mixedKeys[y]   = holder;
  
    }
  }  
  var ret, mode;
  if(typeof mixed.length == 'undefined'){ 
    
    ret = new Object();
    mode = 'object';
  } else {
    
    ret = new Array();
    mode = 'array';
  }
  
  for(var i in mixedKeys){
    var key = mixedKeys[i];
    if(mode == 'object'){      
      ret[key] = mixed[key];
    } else if(mode == 'array'){
      ret.push(mixed[key]);
    }      
  }
  
  return ret;
}





function object_makeMovable(srcID, moveID, relativePositionObject, lockArea, lockAreaOffset){

  if(_ALVINE_SAFARI==true && _ALVINE_CLIENT_OS=='mac') {
    return false;
  }

  var srcObj = element_isObject(srcID);
  if(!srcObj) return false;
  
  if(typeof srcObj.alvineMovingEnabled != 'undefined') return true;
  
  var moveObj = element_isObject(moveID);

  if(!moveObj) moveObj = srcObj;
  if(!moveObj) return false;
  
  if(typeof lockAreaOffset != 'object') lockAreaOffset = {x:0,y:0};
  moveObj.alvine_lockAreaOffset = lockAreaOffset;
  
  srcObj.alvine_moveObj = moveObj;

  if(typeof moveObj.alvine_onMoveStart != 'function'){
    moveObj.alvine_onMoveStart = function(){

      return true;
    };
  }

  if(typeof moveObj.alvine_onMove != 'function'){
    moveObj.alvine_onMove = function(){

      return true;
    };
  }

  if(typeof moveObj.alvine_onMoveStop != 'function'){
    moveObj.alvine_onMoveStop = function(){

      return true;
    };
  }
  
  moveObj.alvine_lockArea            = (lockArea===true)?true:false;
  moveObj.alvine_relativeParent      = element_isObject(relativePositionObject);
  moveObj.alvine_useRelativePosition = (moveObj.alvine_relativeParent)?true:false;
  moveObj.alvine_initPosition        = element_getPosition(moveObj, moveObj.alvine_useRelativePosition);

  mouse_attachToObject(moveObj);

  event_add(srcObj, 'mousedown', object_toggleMoving);
  event_add(srcObj, 'mouseover', 'element_addClassName("'+srcObj.id+'", "moving_possible")');
  event_add(srcObj, 'mouseout',  'element_replaceClassName("'+srcObj.id+'", " moving_possible", "")');
  
  srcObj.alvineMovingEnabled = true;
  
  return true;

}

function object_digforRelativeParentObject(obj, currentObject){
  obj = element_isObject(obj);
  if(currentObject==null) {
    object_digforRelativeParentObject(obj, obj.parentNode);
    return true;
  }

  if(currentObject.tagName.toString().toLowerCase()=='body') return false;
  
  if(!obj.alvine_relativeParentObject && (currentObject.style.position=='relative' || currentObject.style.position=='absolute')) {
    obj.alvine_relativeParentObject = currentObject;
  } else {
    object_digforRelativeParentObject(obj, currentObject.parentNode);
  }
  return true;
}

function object_getMouseOffset(target, ev){
  if(!ev) ev = window.event;
  if(!target.alvine_getMousePosition) mouse_attachToObject(target);
  var mousePos  = target.alvine_getMousePosition(true, true);

  if(!mousePos) mousePos = {x:0, y:0};

  return mousePos;
}




function object_toggleMoving(ev){
  if(!ev) ev = window.event;

  switch(ev.type){
    case 'mousedown':
      var obj = (!this.alvine_moveObj)?this:this.alvine_moveObj;
      if(typeof obj.alvine_onMoveStart == 'function') obj.alvine_onMoveStart();

      obj.alvine_mouseOffset = object_getMouseOffset(obj, ev);

      if(!strstr(obj.className, ' moving_enabled')) element_addClassName(obj, 'moving_enabled');

      obj.alvine_currentSize = element_getSize(obj);
      if(obj.alvine_relativeParent) obj.alvine_relativeParent.alvine_currentSize = element_getSize(obj.alvine_relativeParent);
      
      alvine.data.move.object = obj;

      break;
    case 'mouseup':

      if(!alvine.data.move.object) break;

      var obj = alvine.data.move.object;

      if(typeof obj.alvine_onMoveStop == 'function') obj.alvine_onMoveStop();

      obj.alvine_mouseOffset = null;
      obj.alvine_moveStatus  = null;
      
      element_replaceClassName(obj, ' moving_enabled', '');

      alvine.data.move.object = null;
      break;
  }

  return object_preventDefaultEventBehaviour(ev); 
}

function object_preventDefaultEventBehaviour(ev){
  
  if(typeof ev != 'object') return true;
  if(typeof ev.preventDefault == 'function') ev.preventDefault(); 
  ev.returnValue = false; 
  return false; 
}

function object_moveObject(ev){
  if(!ev) ev = window.event;

  if(!alvine.data.move.object) return true;

  var obj = alvine.data.move.object;

  
  if(!obj.alvine_moveStatus){
    
    obj.alvine_moveStatus = 'moving';
  }

  if(typeof obj.alvine_onMove == 'function') obj.alvine_onMove();

  var mousePos;
  var left;
  var top;
  var parentSize, objSize;
  if(obj.alvine_relativeParent){
    if(!obj.alvine_relativeParent.alvine_getMousePosition) mouse_attachToObject(obj.alvine_relativeParent);
    mousePos = obj.alvine_relativeParent.alvine_getMousePosition(true, true);

    if(obj.alvine_lockArea){
      parentSize = obj.alvine_relativeParent.alvine_currentSize;
      objSize    = obj.alvine_currentSize;
    }
  } else {
    mousePos = document.alvine_getMousePosition(true, false);   
  }
  left = mousePos.x;
  top  = mousePos.y;

  var mouseOffset = obj.alvine_mouseOffset;

  left-=mouseOffset.x;
  top -=mouseOffset.y;

  var areaOffset = obj.alvine_lockAreaOffset;

  if(obj.alvine_lockArea){
    
    if(left<(areaOffset.x*(-1))) left = (areaOffset.x*(-1));
    if(top <(areaOffset.y*(-1)))  top = (areaOffset.y*(-1));
    
    if(left>(parentSize.width-objSize.width+areaOffset.x)) left = (parentSize.width-objSize.width+areaOffset.x);
    if(top>(parentSize.height-objSize.height+areaOffset.y)) top = (parentSize.height-objSize.height+areaOffset.y);
  }
  element_move(obj, left, top);

  return object_preventDefaultEventBehaviour(ev); 
}

function object_storeCaretPosition(obj) {
  obj = element_isObject(obj);
  if(!obj) return true;

  if(document.selection) {
    
    
    obj.alvine_caretPosition = document.selection.createRange();
  } else if(obj.selectionStart) {
    
    obj.alvine_caretPosition = obj.selectionStart;
  } else {
    
  }

  return true;
}

function object_insertAtCaretPosition(obj, contentString) {
  obj = element_isObject(obj);
  if(!obj) return true;

  if(typeof obj.focus != 'undefined'){
    obj.focus();
  }

  if(typeof document.selection != 'undefined') { 
    

    var range = document.selection.createRange();

    range.text = contentString;
    
    
    range = document.selection.createRange();
    range.move('character', contentString);

    

  } else if(typeof obj.selectionStart != 'undefined') {  
    
    var start = obj.selectionStart;
    var end   = obj.selectionEnd;

    
    if(obj.value.length>0){
      obj.value = obj.value.substr(0, start)
        + contentString
        + obj.value.substr(end, obj.value.length);
    } else {
      obj.value = contentString;
    }
  } else {
    
  }

  if(typeof obj.focus != 'undefined'){
    obj.focus();
  }

  return true;
}

page_onLoad(object_initLibs);





function event_add( obj, type, fn, useCapture){

  obj = element_isObject(obj);
  if(!obj) return false;
  
  if(typeof type == 'undefined') return false;
  
  if(typeof obj.alvine_eventListeners == 'undefined') obj.alvine_eventListeners = {};
  if(typeof obj.alvine_eventListeners[type] == 'undefined') obj.alvine_eventListeners[type] = {};

  var fnKey = type.toString()+fn.toString();

  var newEntry = {};
  newEntry.type       = type;
  newEntry.fn         = fn;
  newEntry.useCapture = useCapture;

  obj.alvine_eventListeners[type][fnKey] = newEntry;
  
  
  if(typeof fn == 'string'){
    var str = fn;
    fn = function(){
      eval(str);
    };
  }

  var ietype = type;
	if(type.indexOf('on')>-1) {
		type = type.substring(2);
	} else{
	 	ietype = 'on'+type;
	}
  
  if (obj.addEventListener) {
    
    obj.addEventListener( type, fn, false );
  } else if (obj.attachEvent) {
    fnKey = (typeof str != 'undefined')?str:fn.toString();

		obj['e'+type+fnKey] = fn;
		obj[type+fnKey] = function() { obj['e'+type+fnKey]( window.event ); }
		obj.attachEvent( ietype, obj[type+fnKey] );
		

  }
  
  return true;
  
}

function event_remove( obj, type, fn ){
  obj = element_isObject(obj);
  if(!obj) return false;

  if(typeof type == 'undefined') return false;

  var fnKey = type.toString()+fn.toString();
  if(typeof obj.alvine_eventListeners != 'undefined' && 
     typeof obj.alvine_eventListeners[type] != 'undefined' && 
     typeof obj.alvine_eventListeners[type][fnKey] != 'undefined') {

    delete(obj.alvine_eventListeners[type][fnKey]);
    
  }

  
  if(typeof fn == 'string'){
    var str = fn;
    fn = function(){
      eval(str);
    };
  }
  
  var ietype = type;
	if(type.indexOf('on')>-1) {
	 	type = type.substring(2);
	} else{
	 	ietype = 'on'+type;
	}
	
  if (obj.removeEventListener) {
    obj.removeEventListener( type, fn, false );
  } else if (obj.detachEvent) {
    fnKey = (typeof str != 'undefined')?str:fn.toString();

		obj.detachEvent( ietype, obj[type+fnKey] );
		obj[type+fnKey] = null;
		obj['e'+type+fnKey] = null;
  }
  
  return true;
}
if(typeof alvine != 'object') alvine = new Object();
alvine_object_createObjectPath(alvine, 'data.mouse.positions.document');

function mouse_init(ev){
  if(!ev) ev = window.event;  

  mouse_attachToObject(document);

  return object_preventDefaultEventBehaviour(ev);
}

function mouse_attachToObject(obj){
  obj = element_isObject(obj);

  obj.alvine_ID = (typeof obj.id != 'undefined')?obj.id:obj.nodeName.toString().substr(1).toLowerCase();

  if(typeof alvine.data.mouse.positions[obj.alvine_ID] == 'undefined') alvine.data.mouse.positions[obj.alvine_ID] = {x:0,y:0};

  obj.alvine_getMousePosition = function(includeScrollPosition, relative){
    includeScrollPosition = (includeScrollPosition===false)?false:true;
    relative = (relative===true)?true:false;
    
    var ret = alvine.data.mouse.positions[this.alvine_ID];

    if(!includeScrollPosition){
      var scrollPos = element_getScrollPosition();
      ret.x -= scrollPos.x;
      ret.y -= scrollPos.y;
    }

    if(!relative) return {x:parseInt(ret.x),y:parseInt(ret.y)};
    
    var pos = element_getPosition(this, true);

    var newPos = {};
    newPos.x = parseInt(ret.x);
    newPos.y = parseInt(ret.y);

    newPos.x -= parseInt(pos.x);
    newPos.y -= parseInt(pos.y);

    return {x:newPos.x,y:newPos.y};
  };

  
  event_add(obj, 'mouseover', mouse_getPos, false);
  event_add(obj, 'mousemove', mouse_getPos, false);
  event_add(obj, 'mouseout',  mouse_getPos, false);

  return true;
}

function mouse_getPos(ev){
  if(!ev) ev = window.event;

  
  if(typeof this.alvine_ID == 'undefined') {
	if(this.nodeName == 'undefined') return object_preventDefaultEventBehaviour(ev);
	this.alvine_ID = (typeof this.id != 'undefined')?this.id:this.nodeName.toString().substr(1).toLowerCase();
  }
  if(typeof alvine.data.mouse.positions[this.alvine_ID] == 'undefined') alvine.data.mouse.positions[this.alvine_ID] = {x:0,y:0};

  
  if(ev.pageX || ev.pageY){
    alvine.data.mouse.positions[this.alvine_ID] = {x:ev.pageX,y:ev.pageY};
  } else { 
    var scrollPos = element_getScrollPosition();
    var ret = {x:ev.clientX,y:ev.clientY};
    ret.x += scrollPos.x;
    ret.y += scrollPos.y;
    alvine.data.mouse.positions[this.alvine_ID] = ret;
  }

  return object_preventDefaultEventBehaviour(ev);
}

page_onLoad(mouse_init, true);


var mousePositions = new Object();


function mouse_setPosition(ev){
  
  if(!ev) ev = window.event;
  
  if(typeof this.id != 'undefined' && this.id != ''){
    element_buildUniqueObjectID(this);
  }
  
  if(typeof mousePositions[this.id] == 'undefined') mousePositions[this.id] = new Object();

  var pos = mouse_calcPosition(ev);

  mousePositions[this.id]   = pos;
  this.alvine_mousePos = pos;
  
  return true;
}


function mouse_getPosition(obj, relative, position){
  obj = element_isObject(obj);
  if(!obj) return {x:0, y:0};
  
  relative = (relative != true)?false:true;
  
  if(typeof mousePositions[obj.id] == 'undefined') return alvine.data.mouse.positions.document;
  
  var xpos = mousePositions[obj.id].x;
  var ypos = mousePositions[obj.id].y;
  
  if(typeof position == 'undefined') {
    position = new Object();
    position.x = null;
    position.y = null;
  }
  
  if(relative==true || (position.x != null && position.y != null)){
    var currentObjectPosition =  (position.x != null && position.y != null)?position:element_getPosition(obj, true);

    xpos-= currentObjectPosition.x;
    ypos-= currentObjectPosition.y;
  }
  
  return {x:parseInt(xpos), y:parseInt(ypos)};

}


function mouse_calcPosition(ev){

  if(!ev) ev = window.event;
  var xpos;
  var ypos;
  
  if( typeof( ev.pageX ) == 'number' ) {
    
    xpos = ev.pageX;
    ypos = ev.pageY;
  } else if( typeof( ev.clientX ) == 'number' ) {
    
    var windowBorderWidth = 3;
    
    xpos = ev.clientX - windowBorderWidth;
    ypos = ev.clientY - windowBorderWidth;
                     
    if(_ALVINE_IE){
      
      var scrLeft = document.body.scrollLeft;
      var scrTop = document.body.scrollTop;
      
      
      
      if(scrLeft==0) scrLeft = document.documentElement.scrollLeft;
      if(scrTop==0) scrTop = document.documentElement.scrollTop;
      xpos+= scrLeft;
      ypos+= scrTop;
    }
  }

  return {x:parseInt(xpos),y:parseInt(ypos)};
}



alvine_object_createObjectPath(alvine, 'forms');

alvine.forms.mouseOverControl = false;

function forms_initControl(obj, extendControl){

  var isCompatible = forms_checkExtendedControlsBrowserCompability();

  if(!isCompatible) return false;
  obj = element_isObject(obj);

  if(!obj) return false;
  if(typeof obj.tagName == 'undefined') return false;

  extendControl = (extendControl===true)?true:false;
  
  
  extendControl = (typeof obj.alvine_extendControl != 'undefined')?obj.alvine_extendControl:extendControl;
  

  

  
  if(extendControl){
    forms_renderExtendedControl(obj);

    var proxyObj = element_isObject(obj.id+'_proxy');
    obj.alvine_proxyObj = proxyObj;

  }

  
  if(typeof obj.alvine_renderProxyObject != 'function'){
    obj.alvine_renderProxyObject = function(){
      proxyObj = this.alvine_proxyObj; 
      if(!this.alvine_proxyObj){
        proxyObj = element_isObject(this.id+'_proxy'); 

        if(!proxyObj) return true;
        
        this.alvine_proxyObj = proxyObj;
      }

      if(typeof proxyObj.alvine_renderObject != 'function') return true;

      proxyObj.alvine_renderObject();

      return true;
    };
  }

  var controlType = forms_getControlType(obj);

  
  switch(controlType){
    case 'select_select-one':
    case 'select':

      
      if(typeof obj.alvine_addOption == 'function') {
        obj.alvine_renderProxyObject();

        if(!extendControl) break;
        event_add(obj, 'change', 'this.alvine_renderProxyObject()', true);
        break;
      }
      
      obj.alvine_addOptions = function(objects){

        if(typeof objects == 'undefined') return false;

        var tmpValue;
        var newOptions = new Object();
        if(typeof objects == 'object'){  
          if(object_count(objects)==0) return true;
          
          for(var i in objects){
            if(typeof objects[i].tagName == 'undefined') continue;
            
            if(objects[i].tagName.toString().toLowerCase()=='option') {
              newOptions[objects[i].value] = objects[i];
              continue;
            }

            

            var attValue = objects[i].getAttribute('alvine:value');
            if(attValue==null || attValue=='') continue;

            var attSelected = objects[i].getAttribute('alvine:selected');
            objects[i].alvine_selected = (attSelected!=null && attSelected!='')?true:false;
            tmpValue = attValue.valueOf();
            newOptions[tmpValue] = objects[i];
          }

        } else { 
          newOptions[objects] = objects;
        }

        for(var j in newOptions){
          var newOption = document.createElement('OPTION');

          var idx = this.options.length;
          newOption.id                = this.id+'_'+idx;
          newOption.value             = j;
          newOption.selected          = (typeof newOptions[j].alvine_selected != 'undefined')?newOptions[j].alvine_selected:newOptions[j].selected;
          newOption.text              = newOptions[j].textContent;
          newOption.className         = newOptions[j].className;
          newOption.alvine_initObject = newOptions[j];

          var num = (document.all)?idx:null;
          this.add(newOption, num);
        }

        if(this.selectedIndex<0){
          this.options[0].selected = true;
        }

        this.alvine_renderProxyObject();

        return true;
      };

      obj.alvine_removeOption = function(index){

        this.remove(index);
        
        this.alvine_renderProxyObject();
      };

      obj.alvine_clearOptions = function(avoidProxyRendering){
        avoidProxyRendering = (avoidProxyRendering===true)?true:false;

        
        this.options.length = 0;

        if(avoidProxyRendering) return true;
        this.alvine_renderProxyObject();

        return true;
      };

      obj.alvine_setValue = function(index){

        
        this.selectedIndex = index;

        
        this.alvine_renderProxyObject();

        return true;
      };
      


      
      var optionContainerObj = element_isObject(obj.id+'_optioncontainer');
      if(optionContainerObj){
        var optConOptionList = optionContainerObj.getElementsByTagName('DIV');
        if(optConOptionList.length>0) {
          obj.alvine_clearOptions(true);
          obj.alvine_addOptions(optConOptionList);
        }
      }

      obj.alvine_renderProxyObject();

      if(!extendControl) break;
      event_add(obj, 'change', 'this.alvine_renderProxyObject()', true);
     
      break;

    case 'select_select-multiple':
    case 'select_multiple':
    case 'select_select-multiple_true':
    case 'select_list':

      break;
    case 'textarea':
    case 'textarea_textarea':
    case 'input_text':
    case 'input_password':

      break;
    case 'input_checkbox':
    case 'input_radio':

      obj.alvine_renderProxyObject();

      
      
      event_add(obj, 'change', forms_clickbox_handleChange, true);
      if(_ALVINE_IE) event_add(obj, 'focus', forms_checkbox_handleFocus, true);
      
      break;
    default:
      break;

  }

  return true;
}

function forms_clickbox_handleChange(ev){
  if(!ev) ev = window.event;

  var obj = this;

  obj.alvine_renderProxyObject();


  if(_ALVINE_IE6) return;
  return object_preventDefaultEventBehaviour(ev);
}

function forms_checkbox_handleFocus(ev){
  if(!ev) ev = window.event;

  this.alvine_proxyObject.focus();
 
  return object_preventDefaultEventBehaviour(ev);
}

function forms_init_textinput(obj, clear, restore, select){
  obj = element_isObject(obj);
  if(!obj) return false;

  clear = (typeof clear != 'undefined' && clear===false)?false:true;
  select = (typeof select != 'undefined' && select===false)?false:true;
  restore = (typeof restore != 'undefined' && restore===false)?false:true;

  obj.alvine_defaultValue = obj.value;

  if(clear) event_add(obj, 'focus', forms_textinput_clearValue);
  if(select) event_add(obj, 'focus', forms_textinput_selectValue);

  if(restore) event_add(obj, 'blur', forms_textinput_restoreDefaultValue);

  return true;
}

function forms_textinput_clearValue(ev){
  if(!ev) ev = window.event;

  if(this.value == '') return;
  if(typeof this.alvine_defaultValue == 'undefined') this.alvine_defaultValue = this.value;
  if(this.value != this.alvine_defaultValue) return;

  this.value = '';
}

function forms_textinput_restoreDefaultValue(ev){
  if(!ev) ev = window.event;

  if(this.value != '') return;
  if(typeof this.alvine_defaultValue == 'undefined') return;

  this.value = this.alvine_defaultValue;
}

function forms_textinput_selectValue(ev){
  if(!ev) ev = window.event;

  if(this.value == '') return;

  this.select();
}

function forms_setInputValue(targetControl, value){ 
  targetControl = element_isObject(targetControl);

  targetControl.value = value;
  
  return true;
}

function forms_initImageSelectFields(parentID){
  var parentObj = element_isObject(parentID);
  var obj = null;
    
  for(var i in parentObj.childNodes){   
    for(var j in parentObj.childNodes[i].childNodes){
      obj = parentObj.childNodes[i].childNodes[j].id;
      if(obj == null) continue;
      if(typeof obj == 'undefined') continue;            
      if(obj.substr(0,parentID.length)!=parentID) continue;

      var nameParts = obj.split('_label__');
      if(nameParts[0]!=parentID) continue;

      event_add(obj, 'mouseover', forms_setHover);
      event_add(obj, 'mouseout', forms_setHover);
      event_add(obj, 'mousedown', forms_imageSelectSetStatus);
      event_add(obj, 'mousedown', forms_setActive);
      event_add(obj, 'mouseup', forms_setActive);      
    }
  }
}
function forms_checkExtendedControlsBrowserCompability(){
  
  if(_ALVINE_IE6) return true;
  if(_ALVINE_IE7) return true;
  if(_ALVINE_IE8) return true;
  
  
  if(_ALVINE_FIREFOX2) return true;
  if(_ALVINE_FIREFOX3) return true;

  return false;
}

function forms_initExtendedControls(ev){
  if(!ev) ev = window.event;  
  alvine_object_createObjectPath(alvine, 'forms');

  alvine.forms.browserIsCompatible = forms_checkExtendedControlsBrowserCompability();
  if(typeof alvine.forms.controls == 'undefined') alvine.forms.controls = new Object();

  return object_preventDefaultEventBehaviour(ev);
}

function forms_registerControl(obj, extendControl){  
  var isCompatible = forms_checkExtendedControlsBrowserCompability();
  if(!isCompatible) return false; 
  obj = element_isObject(obj);
  if(!obj) return false;

  if(typeof alvine.forms.controls == 'undefined') alvine.forms.controls = new Object();
   
  obj.alvine_extendControl = (extendControl===true)?true:false;
  alvine.forms.controls[obj.id] = obj;

  return true;
}

function forms_processExtendedControls(ev){
  if(!ev) ev = window.event;

  if(typeof alvine == 'undefined') return false;
  if(typeof alvine.forms == 'undefined') return false;
  if(typeof alvine.forms.controls == 'undefined') return false;

  for(var i in alvine.forms.controls){
    var controlSrcObj = alvine.forms.controls[i];

    var extend = (controlSrcObj.alvine_extendControl===true)?true:false;
    forms_initControl(controlSrcObj, extend);
  }

  return true;
}

function forms_getControlType(obj){
  obj = element_isObject(obj);

  if(!obj) return false;

  var controlType = obj.nodeName.toString().toLowerCase();
  controlType+= ((typeof obj.type != 'undefined' && obj.type!=null) && obj.type.toString().toLowerCase()!=controlType)?'_'+obj.type.toString().toLowerCase():'';
  controlType+= (typeof obj.multiple != 'undefined' && obj.multiple===true)?'_'+obj.multiple.toString().toLowerCase():'';

  return controlType;
}

function forms_renderExtendedControl(obj){
  var isCompatible = forms_checkExtendedControlsBrowserCompability();
  if(!isCompatible) return false; 

  obj = element_isObject(obj);
  if(!obj) return false;

  
  if(typeof obj.alvine_beforeExtension == 'function'){
    obj.alvine_beforeExtension();
  }

  if(typeof obj.nodeName == 'undefined' || obj.nodeName == null) return false;

  var controlType = forms_getControlType(obj);

  if(controlType=='hidden') return true;

  var proxyObj;
  var contentObj;

  var gfxBorderObjTop    = document.createElement('DIV');
  gfxBorderObjTop.className = 'top_panel';
  var gfxBorderObjBottom = document.createElement('DIV');
  gfxBorderObjBottom.className = 'bottom_panel';
  var fillBorderTypes = new Object();
  fillBorderTypes.left   = '&nbsp;';
  fillBorderTypes.right  = '&nbsp;';
  fillBorderTypes.middle = '&nbsp;';
  

  
  for(var i in fillBorderTypes){
    var newElement = document.createElement('DIV');
    newElement.className = i;
    newElement.innerHTML = fillBorderTypes[i];
    gfxBorderObjTop.appendChild(newElement.cloneNode(true));
    gfxBorderObjBottom.appendChild(newElement.cloneNode(true));
  }
  contentObj = document.createElement('DIV');
  contentObj.className = 'content_panel';
  var contentRightObj =  document.createElement('DIV');
  contentRightObj.className = 'right';
  var contentContentObj =  document.createElement('DIV');
  contentContentObj.className = 'content';

  if(controlType == 'select_select-one' && (parseInt(obj.size)>0 || parseInt(obj.rows)>0 || parseInt(obj.style.height)>0)){
    controlType = 'select_list';
  }
  
  switch (controlType) {
    case 'select_select-one':
    case 'select':

      
      var dropdownObj = document.createElement('DIV');
      dropdownObj.alvine_originalObj = obj;
      dropdownObj.id                 = obj.id+'_proxy';
      dropdownObj.className          = 'gfx_dropdown';
      dropdownObj.className         += ' '+str_replace('hidden','',obj.className);
      if(obj.disabled) dropdownValueObj.className += ' disabled';
      
      element_setVisibility(obj, 'hidden');
      element_move(obj, -9999, 0);
      

      dropdownObj.alvine_options     = new Array();
      
      event_add(dropdownObj, 'mouseover', custom_input_activateMouseoverControl, true);
      event_add(dropdownObj, 'mouseout',  custom_input_deactivateMouseoverControl, true);
      
      
      var dropdownButtonObj       = document.createElement('DIV');
      dropdownButtonObj.className = 'button_selector down';
      dropdownButtonObj.id        = dropdownObj.id+'_buttonselector';
      dropdownButtonObj.alvine_parentObject = dropdownObj;

      
      var dropdownValueObj        = document.createElement('DIV');
      dropdownValueObj.className  = 'value islink';
      dropdownValueObj.id         = dropdownObj.id+'_value';
      dropdownValueObj.alvine_parentObject = dropdownObj;

      
      if(typeof obj.alvine_eventListeners != 'undefined'){
        for(var i in obj.alvine_eventListeners) {
          var t = obj.alvine_eventListeners[i];
          for(var j in t){
            var ev = t[j];
            event_add(dropdownValueObj, ev.type, ev.fn, ev.useCapture);

          }
        }
      }

      dropdownObj.appendChild(dropdownButtonObj);
      dropdownObj.appendChild(dropdownValueObj);
      contentContentObj.appendChild(dropdownObj);

      
      var dropdownListID  = dropdownObj.id+'_list';
      var dropdownListObj = element_isObject(dropdownListID);
      if(!dropdownListObj){
        dropdownListObj = document.createElement('DIV');
        dropdownListObj.id = dropdownListID;
        document.body.insertBefore(dropdownListObj, document.body.childNodes[0]);
      }
      dropdownListObj.className = 'dropdown_list';
      element_setVisibility(dropdownListObj, 'hidden');
      element_setLeft(dropdownListObj, -9999);
      dropdownListObj.alvine_visible = false;
      dropdownListObj.alvine_dropdownObj = dropdownObj;

      event_add(dropdownListObj, 'mouseover', custom_input_activateMouseoverControl, true);
      event_add(dropdownListObj, 'mouseout',  custom_input_deactivateMouseoverControl, true);


      
      dropdownObj.alvine_buttonSelectorObj = dropdownButtonObj;
      dropdownObj.alvine_valueObj          = dropdownValueObj;
      dropdownObj.alvine_listObj           = dropdownListObj;

      
      dropdownListObj.alvine_selectOption = function(obj){
        obj = element_isObject(obj);
        if(!obj) return true;

        var dropdownObj = this.alvine_dropdownObj;
        
        for(var i in dropdownObj.alvine_options){
          element_removeClassName(dropdownObj.alvine_options[i], ' selected');

          if(dropdownObj.alvine_options[i].id!=obj.id) continue;
          element_addClassName(dropdownObj.alvine_options[i], ' selected');
        }

        return true;
      };
      
      dropdownListObj.alvine_renderObject = function(){

        var dropdownObj = this.alvine_dropdownObj;
        var originalObj = dropdownObj.alvine_originalObj;

        
        writeHTML(this, '');

        
        var optionList = originalObj.getElementsByTagName('OPTION');

        
        for(var i in optionList){

          if(typeof optionList[i].tagName == 'undefined') continue;

          var contentObj = optionList[i];
          var initObj    = (typeof optionList[i].alvine_initObject == 'object')?optionList[i].alvine_initObject:contentObj;

          var optionRowObj = document.createElement('DIV');
          var alvine_type = document.createAttribute('alvine:type');
          alvine_type.nodeValue = 'option';
          optionRowObj.setAttributeNode(alvine_type);
          optionRowObj.alvine_originalOption = optionList[i];

          optionRowObj.className = 'option islink';

          
          optionRowObj.className+= ' '+str_replace('hidden', '', contentObj.className);

          var selected = contentObj.selected;
          if(selected) optionRowObj.className+= ' selected'; 

          
          var eventMap = new Object();
          eventMap.onclick     = {
            trgObj:optionRowObj
          };
          eventMap.onmousedown = {
            trgObj:optionRowObj
          };
          eventMap.onmouseup   = {
            trgObj:optionRowObj
          };
          eventMap.onmousemove = {
            trgObj:optionRowObj
          };


          for(var eventKey in eventMap){
            var tmpEvent = initObj[eventKey];
            if(typeof tmpEvent != 'function'){
              var alv_event = initObj.getAttribute('alvine:'+eventKey);
              if(alv_event != null && alv_event!='') tmpEvent = alv_event;
            }
            if(typeof tmpEvent != 'function' || tmpEvent == null || tmpEvent == '') continue;
            event_add(eventMap[eventKey].trgObj, eventKey, tmpEvent, true);
          }


          optionRowObj.innerHTML   = initObj.innerHTML;
          optionRowObj.alvine_valueObj = dropdownObj.alvine_valueObj;
          optionRowObj.alvine_parentObject = dropdownObj;
          
          if(selected){
            custom_dropdown_setOptionValue(optionRowObj);
          }
          event_add(optionRowObj, 'mousedown', custom_dropdown_setOptionValueHandler, true);
          event_add(optionRowObj, 'mousedown', custom_dropdown_handleToggleListEvent, true);

          this.appendChild(optionRowObj);
          dropdownObj.alvine_options.push(optionRowObj);

          
          optionRowObj.onmouseover = function(){
            var classNameParts = this.className.split(' ');
            var found = false;
            for(var i in classNameParts){
              if(classNameParts[i] != 'highlight') continue;
              found = true;
              break;
            }
            if(!found) classNameParts.push('highlight');
            this.className = classNameParts.join(' ');
          };

          optionRowObj.onmouseout = function(){
            var classNameParts = this.className.split(' ');
            for(var i in classNameParts){
              if(classNameParts[i] != 'highlight') continue;
              delete(classNameParts[i]);
              break;
            }
            this.className = classNameParts.join(' ');
          };

        }
        
        dropdownObj.alvine_setSwitchcolors();

        return true;
      }

      
      dropdownObj.alvine_renderObject = function(){

        
        this.alvine_clear();
        this.alvine_listObj.alvine_renderObject();
        
        return true;
      }

      dropdownObj.alvine_clear = function(){
        if(this.alvine_options.length == 0) return true;

        for(var i in this.alvine_listObj.childNodes){
          var obj = element_isObject(this.alvine_listObj.childNodes[i]);
          if(!obj) continue;
          var checkAttr = obj.getAttribute('alvine:type');
          if(checkAttr==null || checkAttr=='') continue;

          this.alvine_listObj.removeChild(obj);
        }
        this.alvine_options.length = 0;

        return true;
      }

      dropdownObj.alvine_setSwitchcolors = function(){
        if(this.alvine_options.length==0) return true;

        for(var i in this.alvine_options){
          var sColorIndex = (i%2==0)?2:1;
          if(this.alvine_options[i].className.substring(0, 10) == 'switchcolor'){
            this.alvine_options[i].className = this.alvine_options[i].className.substring(12);
          }
          element_removeClassName(this.alvine_options[i], '  ');
          this.alvine_options[i].className = 'switchcolor0'+sColorIndex.toString()+' '+this.alvine_options[i].className;
        }

        return true;
      };

      

      event_add(dropdownButtonObj, 'mousedown', custom_dropdown_handleToggleListEvent, true);
      event_add(dropdownValueObj,  'mousedown', custom_dropdown_handleToggleListEvent, true);
      if(typeof document.alvine_dropdownFields == 'undefined') document.alvine_dropdownFields = new Object();
      if(typeof document.alvine_dropdownFields[dropdownObj.id] == 'undefined') document.alvine_dropdownFields[dropdownObj.id] = dropdownObj;

      if(typeof document.alvine_closeRegisteredDropDowns=='undefined'){
        document.alvine_closeRegisteredDropDowns = function(ev){
          
          if(!ev) ev = window.event;
          for(var i in document.alvine_dropdownFields){
            var tmpListObj = document.alvine_dropdownFields[i].alvine_listObj;
            if(alvine.forms.mouseOverControl && tmpListObj.id == alvine.forms.mouseOverControl) continue;
            tmpListObj = element_isObject(tmpListObj);
            if(!tmpListObj) continue;
            if(!tmpListObj.alvine_visible) continue;
            custom_dropdown_toggleList(i);
          }

          return true;
        };
      }

      if(_countChildren(document.alvine_dropdownFields)==1){
        event_add(document, 'mousedown', document.alvine_closeRegisteredDropDowns);
      }

      dropdownButtonObj.onmouseover = function(){
        var classNameParts = this.className.split(' ');        
        if(!strstr(this.className, 'highlight')) classNameParts.push('highlight');
        this.className = classNameParts.join(' ');
        return false;
      };

      dropdownButtonObj.onmouseout = function(){
        element_replaceClassName(this, ' highlight', '');
        return false;
      };

      proxyObj = document.createElement('DIV');
      proxyObj.className = 'custom_control_panel';

      proxyObj.className+= ' '+str_replace('hidden', '', obj.className);
      proxyObj.appendChild(gfxBorderObjTop);

      contentRightObj.appendChild(contentContentObj);
      contentObj.appendChild(contentRightObj);
      proxyObj.appendChild(contentObj);

      proxyObj.appendChild(gfxBorderObjBottom);

      obj.parentNode.insertBefore(proxyObj, obj);

      break;
    case 'select_select-multiple':
    case 'select_multiple':
    case 'select_select-multiple_true':
    case 'select_list':

      
      var multiListObj = document.createElement('DIV');
      multiListObj.id              = obj.id+'_proxy';
      multiListObj.className       = 'gfx_multilist';
      multiListObj.className      += ' '+str_replace('hidden', '', obj.className);

      multiListObj.alvine_options           = new Array();

      contentContentObj.appendChild(multiListObj);

      
      var optionList = obj.getElementsByTagName('OPTION');
      
      var optionContainerObj = element_isObject(obj.id+'_optioncontainer');
      var optionContainerObjIsset = false;
      if(optionContainerObj){
        var optConOptionList = optionContainerObj.getElementsByTagName('DIV');
        if(optConOptionList.length>0) {
          optionList = optConOptionList;
        }
      }

      
      multiListObj.alvine_addOption = function(parentObj, contentObj, index){
        parentObj  = element_isObject(parentObj);
        contentObj = element_isObject(contentObj);

        var newIndex = (typeof index != 'number')?this.alvine_options.length:index;

        var optionRowObj = document.createElement('DIV');
        var alvine_type = document.createAttribute('alvine:type');
        alvine_type.nodeValue = 'option';
        optionRowObj.setAttributeNode(alvine_type);

        optionRowObj.className = 'option islink';

        var optionInputObj       = document.createElement('INPUT');
        var inputObjID           = this.id+'_'+newIndex;
        optionInputObj.id        = inputObjID;
        optionInputObj.className = 'hidden';
        optionInputObj.type      = 'checkbox';
        optionInputObj.checked   = false;

        
        optionRowObj.className+= ' '+str_replace('hidden', '', contentObj.className);

        var value;
        var selected;
        if(contentObj.tagName.toLowerCase()=='option'){
          value = optionList[i].value;
          selected = contentObj.selected;
        } else {
          var attValue = contentObj.getAttribute('alvine:value');

          if(attValue==null || attValue=='') return false;

          
          var eventMap = new Object();
          eventMap.onchange    = {
            trgObj:optionInputObj
          };
          eventMap.onclick     = {
            trgObj:optionRowObj
          };
          eventMap.onmousedown = {
            trgObj:optionRowObj
          };
          eventMap.onmouseup   = {
            trgObj:optionRowObj
          };
          eventMap.onmousemove = {
            trgObj:optionRowObj
          };

          for(var eventKey in eventMap){
            var tmpEvent = optionList[i].getAttribute('alvine:'+eventKey);
            if(tmpEvent == null || tmpEvent == '') continue;
            event_add(eventMap[eventKey].trgObj, eventKey, tmpEvent, true);
          }

          value = attValue.valueOf();

          var attSelected = contentObj.getAttribute('alvine:selected');
          selected = (attSelected!=null && attSelected!='')?attSelected.valueOf():false;
        }

        optionInputObj.value     = value;
        optionInputObj.name      = parentObj.name;
        if(selected){
          optionInputObj.checked   = selected;
          element_addClassName(optionRowObj, 'checked');
        }
        optionInputObj.alvine_multilistObject = multiListObj;

        parentObj.parentNode.insertBefore(optionInputObj, parentObj);

        optionRowObj.innerHTML = contentObj.innerHTML;
        optionRowObj.alvine_inputObj = optionInputObj;

        event_add(optionRowObj, 'mousedown', custom_multilist_setOptionValue, true);

        this.appendChild(optionRowObj);
        this.alvine_options[parseInt(newIndex)] = optionRowObj;

        return newIndex;
      };

      multiListObj.alvine_removeOption = function(index){
        var removeRowObj      = this.alvine_options[index];
        var removeInputObj = removeRowObj.alvine_inputObj;

        if(typeof removeRowObj != 'object') return false;

        removeInputObj.parentNode.removeChild(removeInputObj);
        removeRowObj.parentNode.removeChild(removeRowObj);
        this.alvine_options.splice(index, 1);

        this.alvine_setSwitchcolors();

        return true;
      };

      multiListObj.alvine_clearOptions = function(){
        if(this.alvine_options.length==0) return true;

        for(var i in this.alvine_options){
          this.alvine_removeOption(i);
        }

        return true;
      };

      multiListObj.alvine_setSwitchcolors = function(){
        if(this.alvine_options.length==0) return true;

        for(var i in this.alvine_options){
          var sColorIndex = (i%2==0)?2:1;
          element_removeClassName(this.alvine_options[i], 'switchcolor01');
          element_removeClassName(this.alvine_options[i], 'switchcolor02');
          element_removeClassName(this.alvine_options[i], '  ');
          this.alvine_options[i].className = 'switchcolor0'+sColorIndex.toString()+' '+this.alvine_options[i].className;
        }

        return true;
      };

      for(var i in optionList){

        if(typeof optionList[i].tagName == 'undefined') continue;
        
        multiListObj.alvine_addOption(obj, optionList[i]);
      }
      contentContentObj.appendChild(multiListObj);

      
      
      multiListObj.alvine_setSwitchcolors();

      for(var i in multiListObj.alvine_options){

        if(typeof multiListObj.alvine_options[i] != 'object') continue;

        var checkAttribute = multiListObj.alvine_options[i].getAttribute('alvine:type');
        if(checkAttribute == null || checkAttribute == '') continue;

        multiListObj.alvine_options[i].onmouseover = function(){
          var classNameParts = this.className.split(' ');
          var found = false;
          for(var i in classNameParts){
            if(classNameParts[i] != 'highlight') continue;
            found = true;
            break;
          }
          if(!found) classNameParts.push('highlight');
          this.className = classNameParts.join(' ');
        };

        multiListObj.alvine_options[i].onmouseout = function(){
          var classNameParts = this.className.split(' ');
          for(var i in classNameParts){
            if(classNameParts[i] != 'highlight') continue;
            delete(classNameParts[i]);
            break;
          }
          this.className = classNameParts.join(' ');
        };
      }

      proxyObj = document.createElement('DIV');
      proxyObj.className = 'custom_control_panel';
      proxyObj.className+= ' '+str_replace('hidden', '', obj.className);
      proxyObj.appendChild(gfxBorderObjTop);

      contentRightObj.appendChild(contentContentObj);
      contentObj.appendChild(contentRightObj);
      proxyObj.appendChild(contentObj);

      proxyObj.appendChild(gfxBorderObjBottom);

      obj.parentNode.replaceChild(proxyObj, obj);

      break;
    case 'textarea':
    case 'textarea_textarea':
    case 'input_text':
    case 'input_password':
      
      obj.className = str_replace('hidden', '', obj.className);
      var copyobj = obj.cloneNode(true);
      
      
      if(typeof obj.alvine_eventListeners != 'undefined'){
        for(var i in obj.alvine_eventListeners) {
          var t = obj.alvine_eventListeners[i];
          for(var j in t){
            var ev = t[j];
            event_add(copyobj, ev.type, ev.fn, ev.useCapture);
          
          }
        }
      }

      contentContentObj.appendChild(copyobj);

      proxyObj = document.createElement('DIV');
      
      proxyObj.className = 'custom_control_panel';
      
      proxyObj.id = obj.id+'_proxy'
      proxyObj.appendChild(gfxBorderObjTop);

      contentRightObj.appendChild(contentContentObj);
      contentObj.appendChild(contentRightObj);
      proxyObj.appendChild(contentObj);

      proxyObj.appendChild(gfxBorderObjBottom);

      obj.parentNode.replaceChild(proxyObj, obj);

      break;
    case 'input_checkbox':
    case 'input_radio':

      if(controlType == 'input_radio') {
        alvine_object_createObjectPath(alvine.forms, 'lists.radio');
        if(typeof alvine.forms.lists.radio[obj.name] == 'undefined') alvine.forms.lists.radio[obj.name] = new Array();
        alvine.forms.lists.radio[obj.name].push(obj);
      }

      obj.className+= ' hidden';
      obj.alvine_controlType = controlType;

      proxyObj = document.createElement('DIV');
      proxyObj.id = obj.id+'_proxy'
      proxyObj.className = 'custom_small_control_panel';

      var sensitiveObj = document.createElement('LABEL');
      sensitiveObj.htmlFor = obj.id;
      sensitiveObj.alvine_inputObj = obj;  
      

      inputObj = document.createElement('DIV');
      inputObj.className = 'custom_'+controlType;      
      obj.alvine_proxyObject = inputObj;  

      proxyObj.alvine_sensitiveObj = sensitiveObj;

      sensitiveObj.appendChild(inputObj);
      proxyObj.appendChild(sensitiveObj);

      proxyObj.alvine_renderObject = function(){
        var inputObj = this.alvine_sensitiveObj.alvine_inputObj;

        if(inputObj.alvine_controlType == 'input_checkbox'){ 

          if(inputObj.checked){
            if(!strstr(inputObj.className, 'checked')){
              element_addClassName(inputObj.alvine_proxyObject, 'checked');
            }
          } else {
            element_removeClassName(inputObj.alvine_proxyObject, ' checked');
          }

        } else { 

          for(var i in alvine.forms.lists.radio[inputObj.name]){
            var obj = alvine.forms.lists.radio[inputObj.name][i];

            element_removeClassName(obj.alvine_proxyObject, ' checked');

            if(!obj.checked) continue;
            element_addClassName(obj.alvine_proxyObject, 'checked');
            
          }

        }
        
        return true;
      }

      obj.parentNode.insertBefore(proxyObj, obj);
      break;
    default:
      break;
  }

  
  if(typeof obj.alvine_finishExtension == 'function'){
    proxyObj.alvine_finishExtension = obj.alvine_finishExtension;
    proxyObj.alvine_finishExtension();
  }
  return;
}

function forms_setHover(ev){ 
  if(!ev) ev = window.event;
  
  if(ev.type=='mouseover'){
    element_addClassName(this,'hover');          
  } else {
    element_removeClassName(this,'hover');
  }
  return object_preventDefaultEventBehaviour(ev);
}

function forms_setActive(ev){
  element_removeClassName(this,'active');  
  element_addClassName(this,'active',' ');

  return object_preventDefaultEventBehaviour(ev);
}


function forms_imageSelectSetStatus(ev){ 
  var objID = this.id;  
  var nameParts = objID.split('_label__');
  var parentID = nameParts[0];
  
  var parentObj = element_isObject(parentID);
  for(var i in parentObj.childNodes){   
    for(var j in parentObj.childNodes[i].childNodes){
      obj = parentObj.childNodes[i].childNodes[j].id;
      if(obj == null) continue;
      if(typeof obj == 'undefined') continue;            
      if(obj == objID) continue;
      if(obj.substr(0,parentID.length)!=parentID) continue;
      
      var tmpNameParts = obj.split('_label__');
      if(tmpNameParts[0]!=parentID) continue;

      element_removeClassName(obj,'active');             
    }
  }

  return object_preventDefaultEventBehaviour(ev);
}

function forms_imageSelectDoEffect(ev){
  
  var rowObj = this.parentNode;  
  var nameParts = rowObj.id.split('_');  
  var rowid = nameParts[(nameParts.length-1)];
    
  var currentPanelSize = element_getSize('form_panel_id');
  
  var nextRowid = parseInt(rowid)+1;
  if(typeof sfxFormData[nextRowid]=='undefined') return null;
  
  
  var preloadImage = image_preload_get('form_panel_id',nextRowid);
  var img = element_isObject('stepimage');
  
  img.src = preloadImage.src;
  
  if(nextRowid>=sfxFormData.length && nextRowid==rowid) return null;

  var followOptions = new Object();
  followOptions['unlock_sizing'] = false;
  var effect = new JAVASCRIPT_SFX_ROLLOUT("form_panel_id","size","100%",sfxFormData[nextRowid].size.height+"px",65,1,1,true,followOptions);
  effect.start();
  
  return object_preventDefaultEventBehaviour(ev);
}


function forms_initFieldEvents(parentID){
  var parentObj = element_isObject(parentID);
  var obj = null;
  
  for(var i in parentObj.childNodes){ 
    for(var j in parentObj.childNodes[i].childNodes){
      row = parentObj.childNodes[i].childNodes[j]; 

      for(var k in row.childNodes){
        obj = row.childNodes[k];
        
        if(obj.nodeName!='SELECT' && !strstr(obj.className,'image_select_panel')) continue;

        if(obj.nodeName=='SELECT'){ 
          event_add(obj, 'change', forms_imageSelectDoEffect);
        } else if(strstr(obj.className,'image_select_panel')){                        
          event_add(obj, 'mouseup', forms_imageSelectDoEffect);
        } 
      }
    }
  }
}

function forms_initCommandSelectAllCheckboxes(checkboxObj, formObj){
  checkboxObj = element_isObject(checkboxObj);
  formObj     = element_isObject(formObj);

  var checkboxList = formObj.getElementsByTagName('INPUT');
  checkboxObj.alvine_checkboxList = new Array();

  for(var i=0;i<checkboxList.length;i++){
    var item = checkboxList[i];
    if(item.type!='checkbox') continue;

    checkboxObj.alvine_checkboxList.push(item);
  }

  event_add(checkboxObj, 'click', forms_toggleCommandSelectAllCheckboxes);

  return true;
}

function forms_toggleCommandSelectAllCheckboxes(ev){
  if(!ev) ev = window.event;
  
  for(var i in this.alvine_checkboxList){
    this.alvine_checkboxList[i].checked = this.checked;
    if(typeof this.alvine_checkboxList[i].alvine_renderProxyObject == 'function') this.alvine_checkboxList[i].alvine_renderProxyObject();
  }

  return true;
}

function markFocus(obj) {
  var found = strstr(obj.className, 'inputfocus');
  if(!found){
    element_addClassName(obj, 'inputfocus');
    if(typeof obj.select == 'function') obj.select();
  }else{
    element_removeClassName(obj, ' inputfocus');
  }
  return true;
}


function custom_input_activateMouseoverControl(ev){
  if(!ev) ev = window.event;

  alvine.forms.mouseOverControl = (typeof this.alvine_listObj != 'undefined')?this.alvine_listObj.id:this.id;

  return true;
}
function custom_input_deactivateMouseoverControl(ev){
  if(!ev) ev = window.event;

  alvine.forms.mouseOverControl = false;

  return true;
}
function custom_dropdown_setOptionValueHandler(ev){

  if(!ev) ev = window.event;

  custom_dropdown_setOptionValue(this);
  var originalObj = this.alvine_originalOption;
  if(typeof originalObj.parentNode.onchange != 'undefined' && originalObj.parentNode.onchange != null){
    originalObj.parentNode.onchange(ev);
  }
 
  return object_preventDefaultEventBehaviour(ev);
}

function custom_dropdown_setOptionValue(rowObj){

  rowObj = element_isObject(rowObj);

  var valueObj    = rowObj.alvine_valueObj;
  var originalObj = rowObj.alvine_originalOption;
  var content     = (typeof originalObj.alvine_initObject == 'object')?originalObj.alvine_initObject.innerHTML:originalObj.innerHTML;
  valueObj.innerHTML = content;

  var index = originalObj.index;
  originalObj.parentNode.selectedIndex = index;
 
  originalObj.parentNode.alvine_proxyObj.alvine_listObj.alvine_selectOption(rowObj);
 
  return false;
}

function custom_multilist_setOptionValue(ev){

  if(!ev) ev = window.event;

  var inputObj = this.alvine_inputObj;
  inputObj.checked = (inputObj.checked)?false:true;
  if(inputObj.checked){
    element_addClassName(this, 'checked');
  } else {
    element_removeClassName(this, ' checked');
  }

  return object_preventDefaultEventBehaviour(ev);
}

function custom_dropdown_handleToggleListEvent(ev){
  if(!ev) ev = window.event;

  if(typeof this.alvine_parentObject != 'object') return;

  custom_dropdown_toggleList(this.alvine_parentObject.id);

  return object_preventDefaultEventBehaviour(ev);
}

function custom_dropdown_toggleList(parentID){

  var parentObj = document.getElementById(parentID);
  if(!parentObj) return true;
  buttonSelectorObj = parentObj.alvine_buttonSelectorObj;
  listObj           = parentObj.alvine_listObj;

  var classNameParts = buttonSelectorObj.className.split(' ');

  if(typeof listObj.alvine_visible == 'undefined' || !listObj.alvine_visible){
    var viewPort          = alvine_getViewport();
    var scrollPosition    = element_getScrollPosition();
    var viewPortMaxHeight = (viewPort.height-15);
    var parentPosition    = element_getPosition(parentObj, true);
    var parentSize        = element_getSize(parentObj);
    
    var minListHeight  = 120;
    var listHeight     = element_getHeight(listObj);
    var minTop         = 15;
    var maxTop         = (scrollPosition.y+viewPortMaxHeight);

    if(_ALVINE_IE) {
    
    }

    
    var newLeft = parentPosition.x;
    var newTop  = (parentPosition.y + parentSize.height);
    
    var checkHeight = (newTop+listHeight);

    if(checkHeight > maxTop){
      var newListHeight = viewPortMaxHeight-newTop;
      if(newListHeight < minListHeight){
        newListHeight = listHeight;
        newTop = parentPosition.y - listHeight;
        
        
        var scrollCleanedTop       = (newTop-scrollPosition.y);
        var scrollCleanedParentTop = (parentPosition.y-scrollPosition.y);

        if(scrollCleanedTop<minTop){
          newTop = scrollPosition.y + minTop;
          newListHeight = scrollCleanedParentTop - minTop;
        }
      }

      element_setHeight(listObj, newListHeight);
      listObj.style.overflow = 'auto';
    }
    
    element_move(listObj, newLeft, newTop);
    
    element_setVisibility(listObj, 'visible');

    for(var i in classNameParts){
      if(classNameParts[i] != 'down') continue;
      classNameParts[i] = 'up';
    }
    listObj.alvine_visible = true;
  } else {
    element_setVisibility(listObj, 'hidden');
    element_setLeft(listObj, -9999);
    element_setTop(listObj, -9999);

    
    listObj.style.overflow = 'visible';
    element_resetHeight(listObj);

    for(var i in classNameParts){
      if(classNameParts[i] != 'up') continue;
      classNameParts[i] = 'down';
    }    
    listObj.alvine_visible = false;
  }

  buttonSelectorObj.className = classNameParts.join(' ');

  return false;
}

function _countChildren(obj){
  var ret = 0;
  for(var i in obj) ret++;
  return ret;
}




if(typeof content_frontend_plugin_content_simple_form_controlSelectAssignmentData == 'undefined') content_frontend_plugin_content_simple_form_controlSelectAssignmentData = new Object();

function content_frontend_plugin_content_simple_form_select_assignment_init(boxID){


  if(typeof content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID] == 'undefined') content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID] = new Object();
  if(typeof content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists'] == 'undefined') content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists'] = new Array();
  if(typeof content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['all'] == 'undefined') content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['all'] = new Array();
  if(typeof content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['selected'] == 'undefined') content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['selected'] = new Array();
  if(typeof content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu'] == 'undefined') content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu'] = new Array();
  if(typeof content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu']['buttons'] == 'undefined') content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu']['buttons'] = new Array();

  var listAllID      = 'control_select_list_all';
  var listSelectedID = 'control_select_list_selected';
  var menuID         = 'control_select_assignment_menu';

  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['all']['object']      = element_isObject(listAllID+'_'+boxID);
  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['selected']['object'] = element_isObject(listSelectedID+'_'+boxID);

  
  var listAll      = content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['all']['object'];
  var listSelected = content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['selected']['object'];

  var selectedValueList = new Object();
  if(listSelected.options.length>0){
    for(var x in listSelected.options){
      var item = listSelected.options[x];
      if(typeof item != 'object') continue;
      selectedValueList[item.value] = true;
    }
  }
  selectedEntries = content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listAll, 'value', selectedValueList);
  if(selectedEntries.length>0){
    content_frontend_plugin_content_simple_form_select_assignment_removeListEntry(listAll, selectedEntries);
    content_frontend_plugin_content_simple_form_select_assignment_clearList(listSelected);
    content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listSelected, selectedEntries);
  }
  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['all']['reset']      = content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listAll, 'all');
  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['selected']['reset'] = content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listSelected, 'all');

  

  
  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu']['buttons']['selected_move_right'] = element_isObject(menuID+'_cmd_selected_move_right'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].menu.buttons.selected_move_right, 'click', content_frontend_plugin_content_simple_form_select_assignment_listMenuCmdWrapper);

  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu']['buttons']['selected_move_left'] = element_isObject(menuID+'_cmd_selected_move_left'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].menu.buttons.selected_move_left, 'click', content_frontend_plugin_content_simple_form_select_assignment_listMenuCmdWrapper);

  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu']['buttons']['all_move_right'] = element_isObject(menuID+'_cmd_all_move_right'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].menu.buttons.all_move_right, 'click', content_frontend_plugin_content_simple_form_select_assignment_listMenuCmdWrapper);

  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu']['buttons']['all_move_left'] = element_isObject(menuID+'_cmd_all_move_left'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].menu.buttons.all_move_left, 'click', content_frontend_plugin_content_simple_form_select_assignment_listMenuCmdWrapper);

  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['menu']['buttons']['reset'] = element_isObject(menuID+'_cmd_reset'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].menu.buttons.reset, 'click', content_frontend_plugin_content_simple_form_select_assignment_listMenuCmdWrapper);

  
  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['all']['move_up']   = element_isObject(listAllID+'_cmd_up'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].lists.all.move_up, 'click', content_frontend_plugin_content_simple_form_select_assignment_listInternMoveSelection);

  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['all']['move_down'] = element_isObject(listAllID+'_cmd_down'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].lists.all.move_down, 'click', content_frontend_plugin_content_simple_form_select_assignment_listInternMoveSelection);


  
  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['selected']['move_up']   = element_isObject(listSelectedID+'_cmd_up'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].lists.selected.move_up, 'click', content_frontend_plugin_content_simple_form_select_assignment_listInternMoveSelection);

  content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID]['lists']['selected']['move_down'] = element_isObject(listSelectedID+'_cmd_down'+'_'+boxID);
  event_add(content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID].lists.selected.move_down, 'click', content_frontend_plugin_content_simple_form_select_assignment_listInternMoveSelection);

}

function content_frontend_plugin_content_simple_form_select_assignment_getData(boxID){
  return content_frontend_plugin_content_simple_form_controlSelectAssignmentData[boxID];
}


function content_frontend_plugin_content_simple_form_select_assignment_listMenuCmdWrapper(ev){
  if(!ev) ev = window.event;

  var idParts = this.id.split('_cmd_');

  var listID = idParts[0];
  var tmpData = idParts[1].split('_');

  var boxID = tmpData.pop();
  var cmd   = tmpData.join('_');

  var data = content_frontend_plugin_content_simple_form_select_assignment_getData(boxID);

  var listLeft  = data.lists.all.object;
  var listRight = data.lists.selected.object;
  var selectedEntries;

  switch(cmd){
    default:
      break;

    case 'selected_move_right':
      selectedEntries = content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listLeft);
      content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listRight, selectedEntries);
      content_frontend_plugin_content_simple_form_select_assignment_removeListEntry(listLeft, selectedEntries);
      break;

    case 'selected_move_left':
      selectedEntries = content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listRight);
      content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listLeft, selectedEntries);
      content_frontend_plugin_content_simple_form_select_assignment_removeListEntry(listRight, selectedEntries);
      break;

    case 'all_move_right':
      selectedEntries = content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listLeft, 'all');
      content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listRight, selectedEntries);
      content_frontend_plugin_content_simple_form_select_assignment_clearList(listLeft);
      break;

    case 'all_move_left':
      selectedEntries = content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listRight, 'all');
      content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listLeft, selectedEntries);
      content_frontend_plugin_content_simple_form_select_assignment_clearList(listRight);
      break;

    case 'reset':
      content_frontend_plugin_content_simple_form_select_assignment_clearList(listLeft);
      content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listLeft, data.lists.all.reset);
      content_frontend_plugin_content_simple_form_select_assignment_clearList(listRight);
      content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listRight, data.lists.selected.reset);
      break;
  }

}


function content_frontend_plugin_content_simple_form_select_assignment_listInternMoveSelection(ev){
  if(!ev) ev = window.event;

  var idParts = this.id.split('_cmd_');

  var listID = idParts[0];
  var tmpData = idParts[1].split('_');

  var boxID = tmpData.pop();
  var cmd   = tmpData.pop();

  listID+= '_'+boxID;
  var listObj = element_isObject(listID);

  if(listObj.selectedIndex<0) return true; 

  var currentEntries  = listObj.options;
  var selectedEntries = content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listObj);

  var oldPos = listObj.selectedIndex;
  var newPos = null;
  if(cmd=='up'){
    newPos = ((oldPos-1)>=0)?(oldPos-1):0;
  } else {
    newPos = ((oldPos+1)<listObj.options.length)?(oldPos+1):(listObj.options.length-1);
  }

  var newEntries = new Array();
  var cnt = 0;
  for(var i=0;i<currentEntries.length;i++){
    var item = currentEntries[i];

    
    if(typeof selectedEntries[item.index] == 'undefined'){
      newEntries.push(item);
    }
  }

  
  content_frontend_plugin_content_simple_form_select_assignment_clearList(listObj);

  
  cnt = newPos;
  for(var j in selectedEntries){
    newEntries.splice(cnt, 0, selectedEntries[j]);
    cnt++;
  }

  
  content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listObj, newEntries)

}

function content_frontend_plugin_content_simple_form_select_assignment_addListEntry(listObj, options){
  listObj   = element_isObject(listObj);

  if(typeof options.length == 'number' || object_count(options)!=null){ 
    for(var j in options){

      var newOption = document.createElement('option');
      newOption.value = options[j].value;
      newOption.text  = options[j].text;
      newOption.selected  = options[j].selected;

      listObj.appendChild(newOption);
    }
  } else { 
    var optionObj = element_isObject(options);

    var newOption = document.createElement('option');
    newOption.value = optionObj.value;
    newOption.text  = optionObj.text;
    newOption.selected  = optionObj.selected;

    listObj.appendChild(newOption);
  }
}

function content_frontend_plugin_content_simple_form_select_assignment_removeListEntry(listObj, options){
  listObj   = element_isObject(listObj);

  if(typeof options.length == 'number' || object_count(options)!=null){ 
    for(var j in options){

      listObj.removeChild(options[j]);
    }
  } else { 
    var optionObj = element_isObject(options);
    listObj.removeChild(optionObj);
  }
}

function content_frontend_plugin_content_simple_form_select_assignment_clearList(listObj){
  listObj   = element_isObject(listObj);

  
  listObj.options.length = 0;
}

function content_frontend_plugin_content_simple_form_select_assignment_getInternListSelection(listID, getEntries, valueList){

  getEntries = (typeof getEntries == 'undefined')?'selected':getEntries;
  var listObj = element_isObject(listID);

  var selectedEntries = new Object();
  for(var i=0;i<listObj.options.length;i++){
    var item = listObj.options[i];
    var cont = false;
    switch(getEntries){
      default:
        break;

      case 'selected':
        if(!item.selected) cont = true;
        break;

      case 'value':
        if(typeof valueList == 'undefined') cont = true;
        if(object_count(valueList)>0 && (typeof valueList[item.value] == 'undefined')) cont = true;
        break;
    }

    if(cont) continue;

    if(typeof selectedEntries[item.index] == 'undefined') selectedEntries[item.index] = new Object();

    selectedEntries[item.index] = item;
  }

  return selectedEntries;
}




function content_frontend_plugin_content_simple_form_imageselect_initFields(objID){
  var parentObj = element_isObject(objID);
  var obj = null;

  if(typeof parentObj['alvine_imageButtonLabels'] == 'undefined') parentObj['alvine_imageButtonLabels'] = new Array();

  for(var i in parentObj.alvine_imageButtonLabels){
    var imageButton =  parentObj.alvine_imageButtonLabels[i];

    if(typeof imageButton != 'object') continue;
    event_add(imageButton, 'mouseover', content_frontend_plugin_content_simple_form_imageselect_setHover);
    event_add(imageButton, 'mousedown', content_frontend_plugin_content_simple_form_imageselect_setStatus);

    event_add(imageButton, 'mouseout', content_frontend_plugin_content_simple_form_imageselect_resetHover);


  }

  parentObj['alvine_setStatus'] = function(activeID){


    for(var i in this.alvine_imageButtonLabels){

      buttonObj = this.alvine_imageButtonLabels[i];

      if(buttonObj.id!=activeID){
        element_removeClassName(buttonObj, 'active', ' ');
      } else {
        element_removeClassName(buttonObj, 'active', ' ');
        element_addClassName(buttonObj, 'active');
      }
    }

    return true;
  }

  parentObj['alvine_resetHover'] = function(){


    for(var i in this.alvine_imageButtonLabels){

      buttonObj = this.alvine_imageButtonLabels[i];

      element_removeClassName(buttonObj, 'hover', ' ');

    }

    return true;
  }

  parentObj['alvine_setHover'] = function(activeID){

    for(var i in this.alvine_imageButtonLabels){

      buttonObj = this.alvine_imageButtonLabels[i];

      if(buttonObj.id!=activeID){
        element_removeClassName(buttonObj, 'hover', ' ');
      } else {
        element_removeClassName(buttonObj, 'hover', ' ');
        element_addClassName(buttonObj, 'hover');
      }
    }

    return true;
  }

  parentObj['alvine_getChildPanel'] = function(value, index){
    for(var i in this.alvine_imageButtonPanels){
      var tmpInput = this.alvine_imageButtonPanels[i];

      if(tmpInput.value != value && i != index) continue;

      return tmpInput;
    }

    return false;
  };

  parentObj['alvine_getChildButton'] = function(value, index){
    for(var i in this.alvine_imageButtonInputs){
      var tmpInput = this.alvine_imageButtonInputs[i];

      if(tmpInput.value != value && i != index) continue;

      return tmpInput;
    }

    return false;
  };

  parentObj['alvine_setChildPanelDisplay'] = function(value, status){

    var imgPanel  = this.alvine_getChildPanel(value);
    var imgButton = this.alvine_getChildButton(value);

    if(!imgPanel)  return false;
    if(!imgButton) return false;

    

    if(!status) {
      element_setDisplay(imgPanel.object, 'none');
      imgButton.checked = '';
    } else {
      element_setDisplay(imgPanel.object, 'block');
    }

    return true;
  };

  parentObj['alvine_setChildrenDisplay'] = function(data, srcObj){
    if(data=='' && typeof this.alvine_initValueList == 'undefined'){
      return true;
    }

    if(data==''){
      data = this.alvine_initValueList;
    }

    var values = new Array();
    if(typeof data != 'object') {
      if(strstr(data, ',')){
        data = data.split(',');
        for(var i in data){
          values.push(data[i]);
        }
      } else {
        values.push(data);
      }
    } else {
      values = data;
    }

    if(typeof this.alvine_configurator_settings != 'undefined' && typeof this.alvine_configurator_settings.values != 'undefined'){
      if(values != null){
        if(typeof this.alvine_configurator_settings.values[values[0]] != 'undefined'){
          values = this.alvine_configurator_settings.values[values[0]];

          if(typeof values != 'object' && strstr(values, ',')) values = values.split(',');
        }
      } else {
        values = this.alvine_initValueList;
      }
    }

    var ret = null;
    for(var i in this.alvine_imageButtonPanels){
      var tmp = this.alvine_imageButtonPanels[i];
      var buttonObj = tmp.object;
      var value = tmp.value;
      var found = false;

      for(var j in values){

        if(value != values[j]) continue;
        found = true;
        ret = (ret==null)?value:ret;
        break;
      }

      if(!found) {
        element_setDisplay(buttonObj, 'none');
      } else {
        element_setDisplay(buttonObj, 'block');
      }
    }

    return ret;
  }


  return true;
}

function content_frontend_plugin_content_simple_form_imageselect_addImageButton(parentID, buttonLabelID, buttonID, panelID, imageID, imageSrc){
  var parentObj = element_isObject(parentID);
  if(!parentObj) return false;

  var buttonLabelObj = element_isObject(buttonLabelID);
  if(!buttonLabelObj) return false;

  var buttonPanelObj = element_isObject(panelID);
  if(!buttonPanelObj) return false;

  if(typeof parentObj['alvine_imageButtonLabels'] == 'undefined') parentObj['alvine_imageButtonLabels'] = new Array();
  if(typeof parentObj['alvine_imageButtonInputs'] == 'undefined') parentObj['alvine_imageButtonInputs'] = new Array();
  if(typeof parentObj['alvine_imageButtonPanels'] == 'undefined') parentObj['alvine_imageButtonPanels'] = new Array();
  if(typeof parentObj['alvine_imageButtonSrc']    == 'undefined') parentObj['alvine_imageButtonSrc']    = new Object();
  if(typeof parentObj['alvine_initValueList']     == 'undefined') parentObj['alvine_initValueList']     = new Array();

  var buttonObj = element_isObject(buttonID);

  parentObj.alvine_imageButtonLabels.push(buttonLabelObj);
  parentObj.alvine_imageButtonInputs.push(buttonObj);
  parentObj.alvine_imageButtonSrc[buttonObj.value] = imageSrc;
  parentObj.alvine_initValueList.push(buttonObj.value);

  var newEntry = new Object();
  newEntry['object'] = buttonPanelObj;
  newEntry['value']  = buttonObj.value;
  parentObj.alvine_imageButtonPanels.push(newEntry);

  element_move(buttonObj, -999, -999);

  return true;
}

function content_frontend_plugin_content_simple_form_imageselect_triggerInputField(ev){
  if(!ev) ev = window.event;

  if(typeof this.alvine_triggerInput == 'undefined') return false;

  this.alvine_triggerInput(ev);

  return true;
}


function content_frontend_plugin_content_simple_form_imageselect_resetHover(ev){

  if(!ev) ev = window.event;

  var objID = this.id;

  var nameParts = objID.split('_label__');
  var parentID = nameParts[0];

  var parentObj = element_isObject(parentID);

  if(!parentObj) return false;

  parentObj.alvine_resetHover(objID);

  return true;
}

function content_frontend_plugin_content_simple_form_imageselect_setHover(ev){

  if(!ev) ev = window.event;

  var objID = this.id;

  var nameParts = objID.split('_label__');
  var parentID = nameParts[0];

  var parentObj = element_isObject(parentID);

  if(!parentObj) return false;

  parentObj.alvine_setHover(objID);

  return true;
}



function content_frontend_plugin_content_simple_form_imageselect_setStatus(ev){

  if(!ev) ev = window.event;

  var objID = this.id;

  var nameParts = objID.split('_label__');
  var parentID = nameParts[0];

  var parentObj = element_isObject(parentID);

  if(!parentObj) return false;

  parentObj.alvine_setStatus(objID);

  return true;
}



var registeredItems = new Object();

function forms_initImageSelectMultiFields(parentID, selectionMaxItems){
  var parentObj = element_isObject(parentID);
  var obj = null;

  if(typeof registeredItems[parentID] == 'undefined') registeredItems[parentID] = new Object();

  registeredItems[parentID]['selectionMaxItems'] = (typeof selectionMaxItems != 'undefined')?selectionMaxItems:null;

  for(var i in parentObj.childNodes){
    for(var j in parentObj.childNodes[i].childNodes){
      obj = parentObj.childNodes[i].childNodes[j].id;
      if(obj == null) continue;
      if(typeof obj == 'undefined') continue;
      if(obj.substr(0,parentID.length)!=parentID) continue;

      var nameParts = obj.split('_label__');
      if(nameParts[0]!=parentID) continue;

      var itemObj = element_isObject(nameParts[0]+'_item__'+nameParts[1]);

      event_add(obj, 'mouseover', forms_setHover);
      event_add(obj, 'mouseout', forms_setHover);
      event_add(itemObj, 'change', forms_setMultiStatus);
    }
  }

}

function forms_setMultiStatus(e){
  var objID = this.id;
  var nameParts = objID.split('_item__');
  var parentID = nameParts[0];

  var parentObj = element_isObject(parentID);
  var currentLabelObj = element_isObject(nameParts[0]+'_label__'+nameParts[1]);

  selectionCount = 1;
  for(var i in parentObj.childNodes){
    for(var j in parentObj.childNodes[i].childNodes){
      obj = parentObj.childNodes[i].childNodes[j].id;
      if(obj == null) continue;
      if(typeof obj == 'undefined') continue;
      if(obj == objID) continue;
      if(obj.substr(0,parentID.length)!=parentID) continue;

      var nameParts = obj.split('_label__');
      if(nameParts[0]!=parentID) continue;

      var itemObj = element_isObject(nameParts[0]+'_item__'+nameParts[1]);
      var labelObj = element_isObject(nameParts[0]+'_label__'+nameParts[1]);

      if(itemObj.checked == true){
        if(registeredItems[parentID].selectionMaxItems!=null
          && selectionCount > registeredItems[parentID].selectionMaxItems){
          alert(' Es stehen nur '+registeredItems[parentID].selectionMaxItems+' Müglichkeiten zur Auswahl.');
          this.checked = false;
          element_removeClassName(currentLabelObj,'active');
          selectionCount--;
          return false;
        }
        element_removeClassName(labelObj,'active');
        element_addClassName(labelObj,'active',' ');
        selectionCount++;
      } else {
        element_removeClassName(labelObj,'active');
      }
    }
  }
}

function forms_resetMultiStatus(parentID){

  var nameParts = new Array();
  nameParts.push(parentID);

  var parentObj = element_isObject(parentID);

  for(var i in parentObj.childNodes){
    for(var j in parentObj.childNodes[i].childNodes){
      obj = parentObj.childNodes[i].childNodes[j].id;
      if(obj == null) continue;
      if(typeof obj == 'undefined') continue;

      if(obj.substr(0,parentID.length)!=parentID) continue;

      var nameParts = obj.split('_label__');
      if(nameParts[0]!=parentID) continue;

      var itemObj = element_isObject(nameParts[0]+'_item__'+nameParts[1]);
      var labelObj = element_isObject(nameParts[0]+'_label__'+nameParts[1]);

      itemObj.checked = false;
      element_removeClassName(labelObj,'active');

    }
  }
}


page_onLoad(forms_processExtendedControls);
page_onLoad(forms_initExtendedControls);



if(typeof alvine == 'undefined') alvine = new Object();
alvine_object_createObjectPath(alvine, 'session.effects');



function effects_fade(obj, endOpacity, eventName, speed, angle, callback){
  obj = element_isObject(obj);
  if(!obj) return false;
  
  tmpEffect = new APP_EFFECT('fade');
  var effectID = tmpEffect.effectID;

  alvine_object_createObjectPath(alvine, 'session.effects.'+obj.id+'.data.effects.'+effectID);

  var dataObj = alvine.session.effects[obj.id].data;

  dataObj.parentObject = obj;

  dataObj.callback = callback;

  dataObj.effects[effectID] = tmpEffect;

  var opacity = element_getOpacity(obj);

  if(!isDefined(dataObj.effect_initValues)){
    dataObj.effect_initValues = new Array();
    dataObj.effect_initValues.push(opacity);
    element_resetOpacity(obj);
  }
  
  endOpacity  = (!isNull(endOpacity))?endOpacity:opacity;

  
  dataObj.effect_getCurrentValues = function(){
    var opacity = element_getOpacity(this.parentObject);
    return Array(opacity.toString());
  };
  
  
  dataObj.effect_init = function(){
    if(isNull(this.effect_initValues[0])) return true;
    element_setOpacity(this.parentObject, this.effect_initValues[0]);
    
    return true;
  }

  
  dataObj.effect_doEffect = function(values, effectID){

    var done = new Array();

    for(var i in values){
      done[i] = false;
      if(!isNull(values[i])){
        element_setOpacity(this.parentObject, values[i]);
        
        if(values[i] == this.effects[effectID].targetValues[i]) done[i] = true;

      } else {
        done[i] = true;
      }
    }

    if(!done[0]) return true;
    
    this.effects[effectID].stop();
    
    if(typeof this.callback != 'function') return true;

    this.callback();
    
    return effectID;
  };
  
  
  var tmpTargetValues = new Array();
  tmpTargetValues.push(endOpacity);
  dataObj.effects[effectID].addObjects(dataObj, null, tmpTargetValues, speed, angle, eventName);

  return dataObj;
}


function effects_rollout(obj, endWidth, endHeight, eventName, speed, angle, center, callback){
  obj = element_isObject(obj);
  if(!obj) return false;
  
  tmpEffect = new APP_EFFECT('rollout');
  var effectID = tmpEffect.effectID;
  
  alvine_object_createObjectPath(alvine, 'session.effects.'+obj.id+'.data.effects.'+effectID);

  var dataObj = alvine.session.effects[obj.id].data;
  dataObj.parentObject = obj;

  dataObj.callback = callback;

  dataObj.effects[effectID] = tmpEffect;

  if(!isDefined(dataObj.effect_initValues)){
    dataObj.effect_initValues = new Array();
    dataObj.effect_initValues.push(element_getWidth(dataObj.parentObject));
    element_resetWidth(dataObj.parentObject);
    dataObj.effect_initValues.push(element_getHeight(dataObj.parentObject));
    element_resetHeight(dataObj.parentObject);
  }
  
  dataObj.effects[effectID] = tmpEffect;
  dataObj.options_center = (center===true)?true:false;
  
  var size = element_getSize(dataObj.parentObject);
  endWidth  = (!isNull(endWidth))?endWidth:size.width;
  endHeight = (!isNull(endHeight))?endHeight:size.height;
  
  
  dataObj.effect_init = function(){
    if(isDefined(this.effect_initValues)){
      element_setWidth(this.parentObject, this.effect_initValues[0]);
      element_setHeight(this.parentObject, this.effect_initValues[1]);
    }    
    return true;
  }
  
  
  dataObj.effect_getCurrentValues = function(){
    var size = element_getSize(this.parentObject);
    return Array(size.width, size.height);
  };

  
  dataObj.effect_doEffect = function(values, effectID){

    var done = new Array();

    for(var i in values){
      done[i] = false;
      if(!isNull(values[i])){
        if(i==0){
          element_setWidth(this.parentObject, values[i]);
          if(this.options_center) element_centerX(this.parentObject);
        } else {
          element_setHeight(this.parentObject, values[i]);
          if(this.options_center) element_centerY(this.parentObject);
        }
        
        if(values[i] == this.effects[effectID].targetValues[i]) done[i] = true;
        
      } else {
        done[i] = true;
      }
    }

    if(!done[0] || !done[1]) return true;

    this.effects[effectID].stop();
    
    if(typeof this.callback != 'function') return true;

    this.callback();

    return true;
  };
  
  
  var tmpTargetValues = new Array();
  tmpTargetValues.push(endWidth);
  tmpTargetValues.push(endHeight);
  dataObj.effects[effectID].addObjects(dataObj, null, tmpTargetValues, speed, angle, eventName);
  
  return dataObj;
}


function effects_move(obj, endLeft, endTop, eventName, speed, angle, callback){
  obj = element_isObject(obj);
  if(!obj) return false;
  
  tmpEffect = new APP_EFFECT('move');
  var effectID = tmpEffect.effectID;
  
  alvine_object_createObjectPath(alvine, 'session.effects.'+obj.id+'.data.effects.'+effectID);

  var dataObj = alvine.session.effects[obj.id].data;
  dataObj.parentObject = obj;
  
  dataObj.callback = callback;

  dataObj.effects[effectID] = tmpEffect;
  
  var position = element_getPosition(obj);

  if(isNaN(endLeft) || endLeft==null) {
    endLeft  = position.x;
  }
  if(isNaN(endTop) || endTop==null) {
    endTop  = position.y;
  }
  
  if(!isDefined(dataObj.effect_initValues)){
    dataObj.effect_initValues = new Array();
    dataObj.effect_initValues.push(position.x);
    dataObj.effect_initValues.push(position.y);
  }
  
  
  dataObj.effect_init = function(){
    if(isDefined(this.effect_initValues)){
      element_setLeft(this.parentObject, this.effect_initValues[0]);
      element_setTop(this.parentObject, this.effect_initValues[1]);
    }
    
    return true;
  }
  
  
  dataObj.effect_getCurrentValues = function(){
    var position = element_getPosition(this.parentObject);
    return Array(position.x, position.y);
  };

  
  dataObj.effect_doEffect = function(values, effectID){

    var done = new Array();

    for(var i in values){
      done[i] = false;
      if(!isNull(values[i])){
        if(i==0){
          element_setLeft(this.parentObject, values[i]);
        } else {
          element_setTop(this.parentObject, values[i]);
        }
        if(values[i] == this.effects[effectID].targetValues[i]) done[i] = true;
      } else {
        done[i] = true;
      }
    }

    if(!done[0] || !done[1]) return true;
    
    this.effects[effectID].stop();

    if(typeof this.callback != 'function') return true;

    this.callback();

    return true;
  };
  
  
  var tmpTargetValues = new Array();
  tmpTargetValues.push(endLeft);
  tmpTargetValues.push(endTop);
  dataObj.effects[effectID].addObjects(dataObj, null, tmpTargetValues, speed, angle, eventName);
  
  return dataObj;
}



function APP_EFFECT(effectType){

  this.effectType = (isDefined(effectType))?effectType:'rollout';
  this.effectID   = element_buildUniqueObjectID(this);

  this.targetObjects = new Array();

  if(typeof this.intervalList != 'object') this.intervalList = new Object();

  this['stop'] = function(killAll){
    if(killAll){
      for(var i in this.srcObject.effects){
        this.srcObject.effects[i].stop();
      }
    } else {
      if(this.intervalID){
        window.clearInterval(this.intervalID);
        this.intervalID = null;
      }
    }
    return true;
  };

  this['addObjects'] = function(obj, effectID, targetValues, speed, angle, eventName){
    obj = element_isObject(obj);
    if(!obj) return false;
    
    effectID = (isNull(effectID))?this.effectID:effectID;
    this.speed = (isNull(speed))?75:speed;
    this.angle = (isNull(angle))?17:angle;

    
    if(!isDefined(obj.effect_originValues)) obj.effect_originValues = obj.effect_getCurrentValues();
    obj.effect_randomValues     = new Array();
    
    
    for(var i in targetValues){
      var commandParts = targetValues[i].toString().split(':');
      switch(commandParts[0]){
        case 'origin':
          targetValues[i] = obj.effect_originValues[i];
          break;
        case 'init':
          targetValues[i] = obj.effect_initValues[i];
          break;
        case 'rand':
          var range = commandParts[1].split(',');
          
          for(var j in range){
            range[j] = element_recalcValue2px(range[j], obj.effect_originValues[i]);
          }
          obj.effect_randomValues[i] = range;
          break;
        default:

          targetValues[i] = element_recalcValue2px(targetValues[i], obj.effect_originValues[i]);

          break;
      }
    }
    this.targetValues = targetValues;
    
    obj.effect_calcNewValues      = this.calcNewValues;

    obj.effect_start = function(effectID){
      if(typeof this.effects[effectID] == 'undefined') return true;
      
      this.effects[effectID].start();
      return true;
    };

    obj.effect_killInterval       = function(){
      this.effects[effectID].stop();
      return true;
    };
    obj.effect_stop               = obj.effect_killInterval;

    this.targetObjects.push(obj.parentObject);
    
    this.srcObject = obj;
    
    
    if(!obj.effect_initDone) obj.effect_init();
    obj.effect_initDone = true;
    
    this.eventName = (!isNull(eventName))?eventName:'now';
    if(this.eventName == 'now'){
      this.start();
    } else {
      event_add(obj.parentObject, this.eventName, 'alvine.session.effects["'+obj.parentObject.id+'"].data.effect_start("'+effectID+'")', true);
    }

    return true;
  };

  this['start'] = function(){

    for(var i in this.targetObjects){
      var targetObject = this.targetObjects[i];
      var arrayObject  = alvine.session.effects[targetObject.id].data;
    
      this.initValues = new Array();
      this.initValues = arrayObject.effect_getCurrentValues();

      for(var j in this.targetValues){
        if(typeof arrayObject.effect_randomValues[j] == 'object'){
          var range = arrayObject.effect_randomValues[j];
          var randValue = js_rand(range[0], range[1]);

          this.targetValues[j] = randValue;
        }
      }
      
      this.stop(true);

      this.intervalID = window.setInterval('alvine.session.effects["'+targetObject.id+'"].data.effect_calcNewValues("'+this.effectID+'")', this.speed);
      
    }

    return true;
  };
  
  this['calcNewValues'] = function(effectID){

    var currentValues = this.effect_getCurrentValues();

    for(var i in currentValues){

      if(isNull(currentValues[i])) continue;

      currentValues[i] = parseInt(currentValues[i]);

      var strt = parseInt(this.effects[effectID].initValues[i]);
      var dest = parseInt(this.effects[effectID].targetValues[i]);

      if(currentValues[i] == dest) continue;

      if(strt<dest){
        distance = (currentValues[i]<(dest/2))?currentValues[i]:(dest-currentValues[i]);
      } else {
        distance = (currentValues[i]>(strt/2))?(strt-currentValues[i]):currentValues[i];
      }

      distance = (distance<0)?(distance*(-1)):distance;
      distance = (distance==0)?1:distance;

      var factor = Math.ceil(js_acceleration(distance, this.effects[effectID].angle));

      if(strt<dest){
        if((currentValues[i]+factor)<=dest){
          currentValues[i]+= factor;
        } else {
          currentValues[i] = dest;
        }
      } else {
        if((currentValues[i]-factor)>=dest){
          currentValues[i]-= factor;
        } else {
          currentValues[i] = dest;
        }
      }

    
    }

    this.effect_doEffect(currentValues, effectID);

    return true;
  };
  
  

  
  return true;
}


function effects_slideEffect(srcObject, slideObject, timeout, slideBorder, srcEvent, toggleReverseMode){
  srcObject   = (srcObject)?element_isObject(srcObject):false;
  slideObject = element_isObject(slideObject);
  if(!slideObject) return;

  srcObject.toggleReverseMode = (toggleReverseMode===true)?true:false;
  srcObject.slideObj = slideObject;

  slideBorder = (typeof slideBorder == 'undefined')?'top':slideBorder;
  var slideBorderOffset = slideBorder.split(':');
  slideBorder = slideBorderOffset[0];
  
  slideBorderOffset = (typeof slideBorderOffset[1] != 'undefined')?slideBorderOffset[1]:0;
  srcEvent    = (typeof srcEvent == 'undefined' || srcEvent == null)?'onclick':srcEvent;
  slideObject.timeout = (typeof timeout=='undefined')?0:timeout;

  slideObject.initSize = element_getSize(slideObject);
  slideObject.sourceObject = srcObject;

  var viewPort = (slideObject.parentNode.tagName.toString().toLowerCase()!='body')?element_getSize(slideObject.parentNode):alvine_getViewport();

  slideObject.targetPosition = {
    x:0,
    y:0
  };
  var newLeft, newTop;
  switch(slideBorder){
    case 'top':
      slideBorderOffset = (slideBorderOffset>0)?(slideObject.initSize.height-slideBorderOffset):0;
      newTop = (slideObject.initSize.height*(-1));
      element_setTop(slideObject, newTop);            
      slideObject.initPosition = element_getPosition(slideObject);      
      if(slideObject.initPosition.x<0 || slideObject.initPosition.x>viewPort.width){
        slideObject.initPosition.x = 0;
        element_setLeft(slideObject, slideObject.initPosition.x);
      }
      slideObject.targetPosition.x = slideObject.initPosition.x;
      slideObject.targetPosition.y = (0 - slideBorderOffset);
      break;
    case 'right':
      slideBorderOffset = (slideBorderOffset>0)?(slideObject.initSize.width-slideBorderOffset):0;
      newLeft = viewPort.width;      
      element_setLeft(slideObject, newLeft);
      slideObject.initPosition = element_getPosition(slideObject);
      slideObject.targetPosition.x = ((newLeft-slideObject.initSize.width) + slideBorderOffset);
      if(slideObject.initPosition.y<0 || slideObject.initPosition.y>viewPort.height){
        slideObject.initPosition.y = 0;
        element_setTop(slideObject, slideObject.initPosition.y);
      }
      slideObject.targetPosition.y = slideObject.initPosition.y;
      break;
    case 'bottom':
      slideBorderOffset = (slideBorderOffset>0)?(slideObject.initSize.height-slideBorderOffset):0;
      newTop = viewPort.height;      
      element_setTop(slideObject, newTop);
      slideObject.initPosition = element_getPosition(slideObject);
      if(slideObject.initPosition.x<0 || slideObject.initPosition.x>viewPort.width){
        slideObject.initPosition.x = 0;
        element_setLeft(slideObject, slideObject.initPosition.x);
      }
      slideObject.targetPosition.x = slideObject.initPosition.x;
      slideObject.targetPosition.y = ((newTop-slideObject.initSize.height) + slideBorderOffset);
      break;
    case 'left':
      slideBorderOffset = (slideBorderOffset>0)?(slideObject.initSize.width-slideBorderOffset):0;
      newLeft = (slideObject.initSize.width*(-1));
      element_setLeft(slideObject, newLeft);
      slideObject.initPosition = element_getPosition(slideObject);      
      slideObject.targetPosition.x = (0 - slideBorderOffset);
      if(slideObject.initPosition.y<0 || slideObject.initPosition.y>viewPort.height){
        slideObject.initPosition.y = 0;
        element_setTop(slideObject, slideObject.initPosition.y);
      }
      slideObject.targetPosition.y = slideObject.initPosition.y;
      break;
  }
  

  slideObject.effectChain = function(){
    if(this.alvine_visible===true) return;
    
    var cb = function(){
      var obj = this.parentObject;
      if(obj.timeout==0) return;

      window.setTimeout("effects_move('"+ obj.id +"', '"+ obj.initPosition.x+"', '"+ obj.initPosition.y +"', 'now', 12, 18)", obj.timeout);
      obj.alvine_visible = false;
      return ;
    };
    effects_move(this, this.targetPosition.x, this.targetPosition.y, 'now', 12, 18, cb);
    this.alvine_visible = true;

    return;
  };

  if(srcObject){
    srcObject[srcEvent] = function(ev){
      if(!ev) ev = window.event;
      if(!this.slideObj.alvine_visible){
        this.slideObj.effectChain();

        if(typeof this.alvine_onShow == 'function') this.alvine_onShow(ev);

      } else {
        if(this.toggleReverseMode) this.slideObj.hide();
      }
    };
  } else {
    slideObject.effectChain();    
  }

  slideObject.hide = function(){
    if(!this.alvine_visible) return;

    effects_move(this, this.initPosition.x, this.initPosition.y, 'now', 12, 18);
    this.alvine_visible = false;

    if(typeof this.sourceObject != 'object') return;
    if(typeof this.sourceObject.alvine_onHide != 'function') return;
   
    this.sourceObject.alvine_onHide();

  }
}



function effects_initTabSlider(obj, activeIndex, equalizeEntrySize){
  obj = element_isObject(obj);

  var alignment = obj.getAttribute('alvine:alignment');
  obj.alvine_alignment = (alignment=='horizontal' || alignment=='h')?'horizontal':'vertical';

  var divList = obj.getElementsByTagName('div');
  activeIndex = (!isNaN(activeIndex))?activeIndex:0;
  obj.alvine_equalizeEntrySize = (equalizeEntrySize===true)?true:false;

  obj.alvine_entries = {};

  var index = 0;
  obj.alvine_entryList = {};
  for(var i=0;i<divList.length;i++){
    var eObj = element_isObject(divList[i]);
    if(!eObj) continue;
    if(!eObj.getAttribute) continue;

    var type = eObj.getAttribute('alvine:type');
    if(type!='entry') continue;

    obj.alvine_entries[eObj.id] = eObj;

    eObj.alvine_parentObject = obj;

    eObj.setAttribute('alvine:index', index);

    eObj.alvine_fold = function(status, plainResize){

      var newWidth  = 0;
      var newHeight = 0;
      if(this.alvine_parentObject.alvine_alignment=='horizontal'){
        newHeight = this.alvine_initSize.height;
        if(!status) newWidth = (this.alvine_parentObject.alvine_equalizeEntrySize)?this.alvine_parentObject.alvine_peak.width:this.alvine_initSize.width;
      } else {
        newWidth = this.alvine_initSize.width;
        if(!status) newHeight = (this.alvine_parentObject.alvine_equalizeEntrySize)?this.alvine_parentObject.alvine_peak.height:this.alvine_initSize.height;
      }

      if(plainResize){
        element_setSize(this.alvine_contentObj, newWidth, newHeight);
      } else {
        effects_rollout(this.alvine_contentObj, newWidth, newHeight, 'now', 12, 24);
      }
    }

    var subList = eObj.getElementsByTagName('div');
    for(var j=0;j<subList.length;j++){
      var subObj = element_isObject(subList[j]);
      if(!subObj) continue;
      if(!subObj.getAttribute) continue;
      var subType = subObj.getAttribute('alvine:type');
      if(!subType) continue;

      if(subType=='head'){
        eObj.alvine_headObj = subObj;
        eObj.alvine_headObj.alvine_parentObject = eObj;
        eObj.alvine_headObj.alvine_listObject = obj;
        eObj.alvine_headObj.onclick = function(ev){
          if(!ev) ev = window.event;
          var index = this.alvine_parentObject.getAttribute('alvine:index');
          this.alvine_listObject.alvine_refreshList(index);

          return true;
        };
      } else if(subType=='content'){
        eObj.alvine_contentObj = subObj;
      }
    }

    obj.alvine_entryList[eObj.id] = eObj;

    index++;
  }

  obj.alvine_setPeaks = function(){
    this.alvine_peak = {
      width:0,
      height:0
    };

    for(var i in this.alvine_entries){
      
      if(this.alvine_entries[i].alvine_initSize) continue;
      this.alvine_entries[i].alvine_initSize = element_getSize(this.alvine_entries[i].alvine_contentObj);

      if(this.alvine_entries[i].alvine_initSize.width>this.alvine_peak.width)   this.alvine_peak.width  = this.alvine_entries[i].alvine_initSize.width;
      if(this.alvine_entries[i].alvine_initSize.height>this.alvine_peak.height) this.alvine_peak.height = this.alvine_entries[i].alvine_initSize.height;
        
    }
  };
    
  obj.alvine_refreshList = function(activeIndex, plainResize){
    activeIndex = (!isNaN(activeIndex))?activeIndex:0;
    plainResize = (plainResize===true)?true:false;

    for(var i in this.alvine_entryList){
      var entry = this.alvine_entryList[i];

      var index = entry.getAttribute('alvine:index');

      if(index==activeIndex){
        entry.alvine_fold(false, plainResize);
      } else {
        entry.alvine_fold(true, plainResize);
      }
    }
  };

  obj.alvine_setPeaks();
  obj.alvine_refreshList(activeIndex, true);
    
}




function effects_arrangePulldownStructure(obj, initStatus){
  obj = element_isObject(obj);
  if(!obj) return null;

  initStatus = (typeof initStatus != 'undefined' && initStatus == 'unfolded')?'unfolded':'folded';

  obj.alvine_currentFoldStatus = (initStatus=='folded')?'folded':'unfolded';
  obj.alvine_newFoldStatus = (initStatus=='folded')?'unfolded':'folded';

  effects_buildFoldingStructure(obj);
  effects_activatePulldownStructure(obj);

  event_add(document, 'click', "effects_pulldownResetStructure('"+obj.id+"')");

  return true;
}

function effects_pulldownResetStructure(obj){
  obj = element_isObject(obj);
  if(!obj) return null;

  obj.alvine_resetFolding();

  return true;
}

function effects_pulldownResetFolding(ev){
  if(!ev) ev = window.event;

  this.alvine_resetFolding();

  return true;
}

function effects_pulldownHandleMouseover(ev){
  if(!ev) ev = window.event;

  this.alvine_parentObj.alvine_resetFolding(this);

}

function effects_pulldownHandleMouseout(ev){
  if(!ev) ev = window.event;

  
  if(typeof this.alvine_children != 'object') return;
  if(typeof this.alvine_children.childrenfolder != 'object') return;

  var children = this.alvine_children.childrenfolder;
  for(var i in children){
    children[i].alvine_resetFolding();
  }
  

}


function effects_activatePulldownStructure(obj){

  if(typeof obj.alvine_children == 'undefined') return null;

  for(var type in obj.alvine_children){
    var cType = obj.alvine_children[type];

    for(var id in cType){
      var cChild = cType[id];

      switch(type){
        case 'childrenfolder':

          break;
        case 'childpanel':
          
          

          if(typeof cChild.alvine_parentObj.alvine_resetFolding != 'function'){
            cChild.alvine_parentObj.alvine_resetFolding = function(activeObj){
              if(typeof this.alvine_children != 'object') return;
              if(typeof this.alvine_children.childpanel != 'object') return;

              activeObj = element_isObject(activeObj);
              var activeID = null;
              activeID = (activeObj)?activeObj.id:activeID;

              for(var i in this.alvine_children.childpanel){
                var o = this.alvine_children.childpanel[i];
                if(activeID!=null && o.id==activeID) {
                  o.alvine_toggleStatus('unfolded');
                  
                } else {
                  o.alvine_toggleStatus('folded');                
                }






              }
            
            }
          }

          cChild.alvine_currentFoldStatus = cChild.alvine_masterObj.alvine_currentFoldStatus;
          

          if(typeof cChild.alvine_toggleStatus != 'function'){
            cChild.alvine_toggleStatus = function(status){
              status = (typeof status != 'undefined' && status == 'unfolded')?'unfolded':'folded';
              this.alvine_currentFoldStatus = status;

              for(var i in this.alvine_children.childrenfolder){
                var cFolder = this.alvine_children.childrenfolder[i];

                if(this.alvine_currentFoldStatus=='unfolded'){
                  if(!strstr(cFolder.className, 'sfxPulldownFolded') && !strstr(cFolder.className, 'sfxPulldownUnfolded')) {
                    element_addClassName(cFolder, 'sfxPulldownUnfolded');
                  } else {
                    element_replaceClassName(cFolder, 'sfxPulldownFolded', 'sfxPulldownUnfolded');
                  }
                } else if(this.alvine_currentFoldStatus=='folded'){
                  element_replaceClassName(cFolder, 'sfxPulldownUnfolded', 'sfxPulldownFolded');
                }
                element_replaceClassName(cFolder, '  ', ' ');
              }
              this.alvine_newFoldStatus = (this.alvine_currentFoldStatus == 'folded')?'unfolded':'folded';
            };
          }

          cChild.alvine_toggleStatus(cChild.alvine_masterObj.alvine_currentFoldStatus);
          
          
          event_add(cChild, 'mouseover', effects_pulldownHandleMouseover);
          event_add(cChild, 'mouseout', effects_pulldownHandleMouseout);

          break;
        case 'folderswitch':
          if(typeof obj.alvine_children == 'undefined') break;
          if(typeof obj.alvine_children.childrenfolder == 'undefined') {
            element_replaceClassName(cChild, 'sfxPulldownFolded', 'sfxPulldownBlank');
            break;
          }

          break;
        case 'datailfolder':
          break;
      }

      effects_activatePulldownStructure(cChild, cChild.alvine_masterObj.alvine_currentFoldStatus);

    }
  }
  
  return true;
}



function effects_arrangeFoldingStructure(obj, initStatus){
  obj = element_isObject(obj);
  if(!obj) return null;

  initStatus = (typeof initStatus != 'undefined' && initStatus == 'unfolded')?'unfolded':'folded';

  obj.alvine_currentFoldStatus = (initStatus=='folded')?'folded':'unfolded';
  obj.alvine_newFoldStatus = (initStatus=='folded')?'unfolded':'folded';

  effects_buildFoldingStructure(obj);
  effects_activateFoldingStructure(obj);

  return true;
}

function effects_buildFoldingStructure(obj, level){
  obj = element_isObject(obj);
  if(!obj) return null;

  level = (typeof level == 'undefined')?0:level;

  var r = {};
  for(var i in obj.childNodes){
    var cObj = obj.childNodes[i];
    cObj = element_isObject(cObj);
    if(!cObj) continue;
    if(typeof cObj != 'object') continue;
    if(typeof cObj.id == 'undefined') continue;

    var listKey = cObj.getAttribute('alvine:effects');

    if(!listKey || listKey.indexOf('foldingListKey', 0)!=0) continue;

    listKey = listKey.substr(14).toLowerCase();

    if(listKey == '') continue;

    
    if(typeof r == 'undefined') r = {};
    if(typeof r[listKey] == 'undefined') r[listKey] = {};
    if(typeof r[listKey].first == 'undefined') r[listKey].first = cObj;
    if(typeof r[listKey].last == 'undefined') r[listKey].last = {};

    r[listKey].last = cObj;

    element_addClassName(cObj, 'inside');

    cObj.alvine_parentObj = obj;

    cObj.alvine_level = level;
    if(listKey=='childpanel') element_addClassName(cObj, 'level'+level.toString());
    if(typeof obj.alvine_children == 'undefined') obj.alvine_children = new Object();
    if(typeof obj.alvine_children[listKey] == 'undefined') obj.alvine_children[listKey] = new Object();
    obj.alvine_children[listKey][cObj.id] = cObj;
    cObj.alvine_masterObj = (typeof obj.alvine_masterObj == 'undefined')?obj:obj.alvine_masterObj;
    if(listKey=='folderswitch'){
      if(typeof cObj.alvine_masterObj.alvine_masterChildren == 'undefined') cObj.alvine_masterObj.alvine_masterChildren = new Object();
      if(typeof cObj.alvine_masterObj.alvine_masterChildren.folderswitch == 'undefined') cObj.alvine_masterObj.alvine_masterChildren.folderswitch = new Object();
      cObj.alvine_masterObj.alvine_masterChildren.folderswitch[cObj.id] = cObj;
    }    
    
    
    if(typeof cObj.hasChildNodes == 'function' && !cObj.hasChildNodes()) continue;
    var l = level + 1;
    effects_buildFoldingStructure(cObj, l);

  }

  
  if(typeof r != 'object') return true;

  for(var i in r){
    var type = r[i];
    if(typeof type != 'object') continue;
    
    element_removeClassName(type.first, 'inside');
    element_addClassName(type.first, 'first');

    element_removeClassName(type.last, 'inside');
    element_addClassName(type.last, 'last');
  }

  return true;
}

function effects_activateFoldingStructure(obj){

  if(typeof obj.alvine_children == 'undefined') return null;
  
  for(var type in obj.alvine_children){
    var cType = obj.alvine_children[type];

    for(var id in cType){
      var cChild = cType[id];

      switch(type){
        case 'childrenfolder':
          break;
        case 'childpanel':
          break;
        case 'folderswitch':
          if(typeof obj.alvine_children == 'undefined') break;
          if(typeof obj.alvine_children.childrenfolder == 'undefined') {
            element_replaceClassName(cChild, 'sfxFolded', 'sfxBlank');
            break;
          }

          
          cChild.alvine_currentFoldStatus = cChild.alvine_masterObj.alvine_currentFoldStatus;

          if(typeof cChild.alvine_toggleStatus != 'function'){            
            cChild.alvine_toggleStatus = function(status){
              status = (typeof status != 'undefined' && status == 'unfolded')?'unfolded':'folded';
              this.alvine_currentFoldStatus = status;

              for(var i in this.alvine_parentObj.alvine_children.childrenfolder){
                var cFolder = this.alvine_parentObj.alvine_children.childrenfolder[i];
                if(typeof cFolder.alvine_initSize == 'undefined') cFolder.alvine_initSize = element_getSize(cFolder);
                if(this.alvine_currentFoldStatus=='unfolded'){
                  
                  element_setHeight(cFolder, 'auto');
                  element_replaceClassName(this, 'sfxFolded', 'sfxUnfolded');
                } else if(this.alvine_currentFoldStatus=='folded'){
                  element_setHeight(cFolder, 0);
                  element_replaceClassName(this, 'sfxUnfolded', 'sfxFolded');
                }
                element_replaceClassName(this, '  ', ' ');
              }
              this.alvine_newFoldStatus = (this.alvine_currentFoldStatus == 'folded')?'unfolded':'folded';
            };
          }

          cChild.alvine_toggleStatus(cChild.alvine_masterObj.alvine_currentFoldStatus);
          
          cChild.onclick = function(ev){
            if(!ev) ev = window.event;
            
            this.alvine_toggleStatus(this.alvine_newFoldStatus);

            
            return true;
          };

          break;
        case 'datailfolder':
          break;
      }

      effects_activateFoldingStructure(cChild, cChild.alvine_masterObj.alvine_currentFoldStatus);

    }
  }
  return true;
}

function effects_toggleFoldingStatusAll(obj, status){
  obj = element_isObject(obj);

  status = (typeof status != 'undefined' && status == 'unfolded')?'unfolded':'folded';
  if(!obj) return status;
  obj.alvine_currentFoldStatus = status;
  if(typeof obj.alvine_masterChildren == 'undefined') return null;

  var children;
  var cFolder;

  if(typeof obj.alvine_masterChildren.folderswitch != 'undefined'){
    children = obj.alvine_masterChildren.folderswitch;

    for(var fid in children){
      cFolder = children[fid];
      if(typeof cFolder.alvine_toggleStatus != 'function') continue;
      cFolder.alvine_toggleStatus(obj.alvine_currentFoldStatus);
    }
  }

  obj.alvine_newFoldStatus = (obj.alvine_currentFoldStatus == 'folded')?'unfolded':'folded';

  if(typeof obj.alvine_toggleButton != 'undefined') obj.alvine_toggleButton.alvine_changeStatusClass(obj.alvine_newFoldStatus);
  return obj.alvine_newFoldStatus;
}

function effects_initToggleListFoldingButton(obj, listObj){
  obj = element_isObject(obj);
  if(!obj) return false;
  if(typeof obj.alvine_initDone != 'undefined' && obj.alvine_initDone == true) return true;
  obj.alvine_initDone = true;

  listObj = element_isObject(listObj);
  if(!listObj) return false;

  obj.alvine_listObj = listObj;
  listObj.alvine_toggleButton = obj;

  if(!strstr(obj.className, 'sfxFolded')) element_addClassName(obj, 'sfxFolded');

  obj.alvine_changeStatusClass = function(status){

    var statusClass  = (status=='folded')?'sfxFolded':'sfxUnfolded';
    var replaceClass = (statusClass=='sfxFolded')?'sfxUnfolded':'sfxFolded';

    element_replaceClassName(this, statusClass, replaceClass);
    element_replaceClassName(this, '  ', ' ');
  };

  event_add(obj, 'click', effects_handleListFoldingToggleClick);

  return true;
}

function effects_handleListFoldingToggleClick(ev){
  if(!ev) ev = window.event;

  effects_toggleFoldingStatusAll(this.alvine_listObj, this.alvine_listObj.alvine_newFoldStatus);

  this.alvine_changeStatusClass(this.alvine_listObj.alvine_newFoldStatus);
  
  this.alvine_oldStatus = this.alvine_newStatus;


  return object_preventDefaultEventBehaviour(ev);
}





function effects_initHover(obj){
  obj = element_isObject(obj);
  if(!obj) return;
  if(obj.alvine_hoverInitDone) return;


  obj.onmouseover = function(ev){
    if(this.alvine_hover) return true;
    if(!ev) ev = window.event;
    element_addClassName(this, "cdHoverColor");
    this.alvine_hover = true;
    return true;
  };
  obj.onmousemove = obj.onmouseover;
  obj.onmouseout = function(ev){
    if(!ev) ev = window.event;
    element_removeClassName(this, "cdHoverColor");
    this.alvine_hover = false;
    return true;
  };

  obj.alvine_hoverInitDone = true;

  return;
}

function effects_initHighlightTargetCell(srcObj, trgObj){
  srcObj = element_isObject(srcObj);
  if(!srcObj) return;
  
  trgObj = element_isObject(trgObj);
  if(!trgObj) return;

  srcObj.alvine_targetObj = trgObj;

  if(srcObj.alvine_hoverInitDone) return;
  
  srcObj.onmouseover = function(ev){
    if(srcObj.alvine_targetObj.alvine_hover) return true;
    if(!ev) ev = window.event;
    element_addClassName(srcObj.alvine_targetObj, "cdHoverColor");
    srcObj.alvine_targetObj.alvine_hover = true;
    return true;
  };
  srcObj.onmousemove = srcObj.onmouseover;
  srcObj.onmouseout = function(ev){
    if(!ev) ev = window.event;
    element_removeClassName(srcObj.alvine_targetObj, "cdHoverColor");
    srcObj.alvine_targetObj.alvine_hover = false;
    return true;
  };
  
  srcObj.alvine_hoverInitDone = true;

  return;
}



if(typeof alvine == 'undefined') var alvine = new Object();
 
function content_js_init(boxID, options){

  if(typeof alvine['session'] == 'undefined') alvine['session'] = new Object();
  if(typeof alvine['plugin']  == 'undefined') alvine['plugin'] = new Object();
  if(typeof alvine['content'] == 'undefined') alvine['content'] = new Object();
  if(typeof alvine['page']    == 'undefined') alvine['page'] = new Object();
  if(typeof alvine['content']['imagePreloader'] == 'undefined') alvine['content']['imagePreloader'] = new Object();
  
  if(typeof options.useImagePreloader != 'undefined'){
    if(options.useImagePreloader){
      page_onLoad(content_js_imagePreloader_preloadImages);      
    }
  }  
  
  content_js_importSettings();
  
}

function content_js_imagePreloader_registerImage(imageUrl, key){
  
  if(typeof imageUrl == 'undefined') return false;
  key = (typeof key == 'undefined')?imageUrl:key;
  
  if(typeof alvine['content']['imagePreloader'][key] == 'undefined') alvine['content']['imagePreloader'][key] = new Object();
  alvine.content.imagePreloader[key]['url'] = imageUrl;
  
  return true;  
}

function content_js_imagePreloader_getStoredImageObject(key){
  if(typeof key == 'undefined') return false;
  if(typeof alvine.content.imagePreloader[key]['object'] == 'undefined') return false;
  
  return alvine.content.imagePreloader[key]['object'];  
}

function content_js_imagePreloader_preloadImages(ev){
  
  if(!ev) ev = window.event;
  
  for(var i in alvine.content.imagePreloader){

    if(typeof alvine.content.imagePreloader[i]['url']    == 'undefined') continue;
    if(typeof alvine.content.imagePreloader[i]['object'] != 'undefined') continue;
    
    alvine.content.imagePreloader[i]['object'] = new Image();    
    alvine.content.imagePreloader[i]['object'].src = alvine.content.imagePreloader[i]['url'];  
  }
  
}


function content_js_cutWindow() {  
  document.body.style.overflow="hidden";
  if(document.getElementsByTagName("html")[0]) {
    document.getElementsByTagName("html")[0].style.overflow="hidden";
  };
  
  return true;
};


function content_js_releaseCuttedWindow() {  
  document.body.style.overflow="visible";
  if(document.getElementsByTagName("html")[0]) {
    document.getElementsByTagName("html")[0].style.overflow="";
  };
  
  return true;
};

function content_js_scrollWindow(left, top, absolutePositioning) {  
  absolutePositioning = (absolutePositioning==false)?false:true;
  
  if(absolutePositioning){  
    left = (isNaN(left))?0:left;
    top = (isNaN(top))?0:top;
    
    window.scroll(left, top);
  }
  
  return true;
};

function content_js_setHover(obj, hoverKey, onEventName, offEventName){
  obj = element_isObject(obj);
  
  if(!obj) return false;

  var staticHoverString = 'js_hover';
  
  var newHoverKey = (hoverKey)?staticHoverString+'_'+hoverKey:staticHoverString;
  
  if(typeof obj.alvine_hoverKey != 'undefined') return true;
  
  element_addClassName(obj, 'islink');
  element_addClassName(obj, newHoverKey);  
  obj.alvine_hoverKey = newHoverKey;
  
  onEventName = (onEventName)?onEventName:'mouseover';
  offEventName = (offEventName)?offEventName:'mouseout';
  
  event_add(obj, onEventName, content_js_addHover);
  event_add(obj, offEventName, content_js_removeHover);
  
  return true;
}

function content_js_addHover(ev){
  if(!ev)  ev = window.event;
  
  if(typeof this.alvine_hoverKey == 'undefined') return true;  
  element_addClassName(this, this.alvine_hoverKey);      
  
  return true;
}

function content_js_removeHover(ev){
  if(!ev)  ev = window.event;
  
  if(typeof this.alvine_hoverKey == 'undefined') return true;  
  element_removeClassName(this, ' '+this.alvine_hoverKey);      
  
  return true;
}


 
function content_frontend_plugin_public_education_category_list_init(boxID){
  if(typeof alvine.plugin[boxID] == 'undefined') alvine.plugin[boxID] = new Object();
}
var JAVASCRIPT_IMAGES_PRELOAD = new Object();

function image_preload_init(key){
  if(typeof JAVASCRIPT_IMAGES_PRELOAD[key] != 'undefined') return false;
  
  JAVASCRIPT_IMAGES_PRELOAD[key] = new Array();

}

function image_preload_add(key,image){
  var newIndex = JAVASCRIPT_IMAGES_PRELOAD[key].length;
  JAVASCRIPT_IMAGES_PRELOAD[key][newIndex] = new Object();
  
  JAVASCRIPT_IMAGES_PRELOAD[key][newIndex]['name'] = image['name'];
  JAVASCRIPT_IMAGES_PRELOAD[key][newIndex]['src'] = image['src'];
}

function image_preload_get(key,index){
  return JAVASCRIPT_IMAGES_PRELOAD[key][index];  
}

function image_shrinkToFit(obj, new_w, new_h){
  
  obj = element_isObject(obj);
  var old = element_getSize(obj);
  
  ret = new Object();
  
  var ratio  = (old.width / old.height);
  if (old.width > old.height) {    
    ret['width']  = new_w;
    ret['height'] = new_w * ratio;
  } else {    
    ret['width']   = new_h * ratio;
    ret['height']  = new_h;    
  }
  if (old.width == old.height) {
    ret['width']  = new_w;
    ret['height'] = new_h;
  }

  return ret;
}

var sfxObjects = new Object();
function JAVASCRIPT_SFX(){

  this.oid                     = element_buildUniqueObjectID(this);
  this.objectPool              = new Object();
  this.objectName              = null;
  
  this.calc                    = new JAVASCRIPT_SFX_OBJECT_POSITION_CALC();

  
  this.followingObjects        = new Array(); 
  this.followOptions           = new Object();
    
  this.current_intervalID      = null;
  
  this.addObject               = JAVASCRIPT_SFX_addObject;
  this.registerFollowingObject = JAVASCRIPT_SFX_registerFollowingObject;
  this.setFollowingOptions     = JAVASCRIPT_SFX_setFollowingOptions;
  this.callFollowingObjects    = JAVASCRIPT_SFX_callFollowingObjects;
  this.start                   = JAVASCRIPT_SFX_start;
  this.stop                    = JAVASCRIPT_SFX_stop;  
  
}

JAVASCRIPT_SFX_addObject = function(object, destinationX, destinationY){
  object = element_isObject(object);

  this.objectPool[object.id]                     = new Object();
  this.objectPool[object.id]                     = object;
  this.objectPool[object.id]['destination']      = new Object();
  this.objectPool[object.id]['destination']['x'] = (typeof destinationX == 'number')?destinationX:null;  
  this.objectPool[object.id]['destination']['y'] = (typeof destinationY == 'number')?destinationY:null;
  this.objectPool[object.id]['initPosition']     = element_getPosition(object.id);
  
  return true;
}


JAVASCRIPT_SFX_registerFollowingObject = function(object){
  object = element_isObject(object);
  
  
  if(typeof object.start == 'undefined') return true;

  this.followingObjects.push(object);

  return true;
}

JAVASCRIPT_SFX_setFollowingOptions = function(key, value){
  
  this.sfx.followingOptions[key] = value;
  
  return true;
}


JAVASCRIPT_SFX_callFollowingObjects = function(){
  

  for(var i in this.followingObjects){
    if(typeof this.followingObjects[i].start == 'undefined') continue;

    this.followingObjects[i].start();
  }
  return true;
}

JAVASCRIPT_SFX_start = function(){
  

  this.sfx.callString = this.sfx.objectName + ".doEffect()";

  
  this.sfx.current_intervalID = setInterval(this.sfx.callString, this.sfx.calc.intervalSpeed);

  return true;
}

JAVASCRIPT_SFX_stop = function(){

  clearInterval(this.sfx.current_intervalID);  
  
  if(this.sfx.followingObjects.length==0) return true;

  this.sfx.callFollowingObjects();
  
  return true;
}






var app_registeredItems = new Object();

function JAVASCRIPT_SFX_OBJECT_POSITION_CALC(){
  
  
  this.intervalSpeed = 50;  
  this.a             = 0.000000001;
  this.b             = 0.0001;
  this.c             = 1;  
  
  this.startTime     = null;  
  
  this.getValue      = JAVASCRIPT_SFX_OBJECT_POSITION_CALC_getValue;
  this.setParameters = JAVASCRIPT_SFX_OBJECT_POSITION_CALC_setParameters;  
  this.reset         = JAVASCRIPT_SFX_OBJECT_POSITION_CALC_reset;

}

JAVASCRIPT_SFX_OBJECT_POSITION_CALC_getValue = function(direction, calcLinear){
  direction = (typeof direction == 'undefined')?1:direction;  
  
  if(this.startTime == null) this.startTime = time_getMilliTimestamp();  
  
  
  var currentTime = time_getMilliTimestamp();      
  var xt = (currentTime - this.startTime);  

  var a = this.a;
  var b = this.b;
  var c = this.c;  
  
  if(calcLinear==true){
    y = Math.ceil(a);
  } else{    
    y = a * Math.pow(xt, 2) + (b * xt) + c; 
    y = Math.floor(y);
  }
  

  return y;
  
}


JAVASCRIPT_SFX_OBJECT_POSITION_CALC_setParameters = function(intervalSpeed, a, b, c){

  this.intervalSpeed = (typeof intervalSpeed != 'undefined' && intervalSpeed != null)?intervalSpeed:this.intervalSpeed;  
  this.a = (typeof a != 'undefined' && a != null)?a:this.a;
  this.b = (typeof b != 'undefined' && b != null)?b:this.b;
  this.c = (typeof c != 'undefined' && c != null)?c:this.c;

}

JAVASCRIPT_SFX_OBJECT_POSITION_CALC_reset = function(){
  
  this.startTime = null;
  
}

function sfx_openPopUp(fileurl,width, height) {
  
  ScreenWidth = screen.width; 
  ScreenHeight = screen.height; 
  xpos = (ScreenWidth/2)-(width/2); 
  ypos = (ScreenHeight/2)-(height/2); 
  option = "left="+xpos+",top="+ypos+",width="+width+",height="+height+",status=false,toolbar=false";
  neupop = open(fileurl,"Detail",option);

}


 
function JAVASCRIPT_SFX_ROLLOUT(objectName, followOptions) {
   
  this.sfx                     = new JAVASCRIPT_SFX(); 
  this.sfx.objectName          = objectName;
  this.oid                     = element_buildUniqueObjectID(this);
  
  this.effect_type             = 'slide';
  this.status_open             = false;  

  if(typeof followOptions != 'undefined'){
    unlock_sizing = followOptions['unlock_sizing']==true?true:false; 
    this.sfx.setFollowingOptions('unlock_sizing', unlock_sizing);      
  }
  
  this.doEffect                = JAVASCRIPT_SFX_ROLLOUT_doEffect;   
  this.addItem                 = JAVASCRIPT_SFX_ROLLOUT_addItem;   
  this.setSpeedParameters      = JAVASCRIPT_SFX_ROLLOUT_setSpeedParameters;   
  this.start                   = this.sfx.start;
  this.stop                    = this.sfx.stop;

  return true;
}


JAVASCRIPT_SFX_ROLLOUT_addItem = function(object, destinationX, destinationY, effectType){
  object = element_isObject(object);
  
  var size = element_getSize(object);
  
  switch(effectType){
    default:
    case 'slide':
      var visibleByPercentX = destinationX.toString().substring((destinationX.toString().length-1))=='%'?true:false;
      var visibleByPercentY = destinationY.toString().substring((destinationY.toString().length-1))=='%'?true:false;
      
      var visibleThresholdX = size.width * (-1);
      var visibleThresholdY = size.height * (-1);
    
      var initPosition = element_getPosition(object); 

      var destinationX = (destinationX!='')?element_recalcValue2px(destinationX, size.width):initPosition.x; 
      var destinationY = (destinationY!='')?element_recalcValue2px(destinationY, size.height):initPosition.y;      

      var x = (visibleByPercentX)?visibleThresholdX + destinationX:parseInt(destinationX); 
      var y = (visibleByPercentY)?visibleThresholdY + destinationY:parseInt(destinationY);
      
    break;
    
    case 'size':
      var x = element_recalcValue2px(destinationX, size.width);
      var y = element_recalcValue2px(destinationY, size.height);
    break;
  }

  this.sfx.addObject(object, x, y);  

  this.sfx.objectPool[object.id]['effectType'] = (typeof effectType != 'undefined')?effectType:'slide';

}

JAVASCRIPT_SFX_ROLLOUT_setSpeedParameters = function(intervalSpeed, a, b, c){

  this.sfx.calc.setParameters(intervalSpeed, a, b, c);  
  
}


JAVASCRIPT_SFX_ROLLOUT_doEffect = function(){

  var objects = this.sfx.objectPool;

  var currentValues = new Object();
  currentValues['x'] = null;
  currentValues['y'] = null;
  for(var id in objects){
    
    var object = objects[id];

    
    switch(object.effectType){
    default:
    case 'slide':
      
      var currentPos = element_getPosition(object);  
      currentValues['x'] = currentPos.x;
      currentValues['y'] = currentPos.y;
    break;
    
    case 'size':
      var currentSize = element_getSize(object);  
      currentValues['x'] = currentSize.width;
      currentValues['y'] = currentSize.height;
    break;
    }
    
    
    
    var direction = new Object();
    direction['x'] = (currentValues.x<object.destination.x)?1:-1;
    direction['y'] = (currentValues.y<object.destination.y)?1:-1;  

    
    var y = 0;
    
    
    for(axis in direction){
      
      if(currentValues[axis] == object.destination[axis]) continue;
      
      y = this.sfx.calc.getValue(direction[axis]);

      if(direction[axis] > 0){
        currentValues[axis]+= y;    
        currentValues[axis] = (currentValues[axis]<object.destination[axis])?currentValues[axis]:object.destination[axis];    
      } else if(direction[axis] < 0){
        currentValues[axis]-= y;
        currentValues[axis] = (currentValues[axis]>object.destination[axis])?currentValues[axis]:object.destination[axis];
      }    
    }
    
    
    switch(object.effectType){
    default:
    case 'slide':
      element_move(object, currentValues.x, currentValues.y);
    break;
    
    case 'size':
      element_setSize(object, currentValues.x, currentValues.y);
    break;
    }
    
    
    if(currentValues.x == object.destination.x && currentValues.y == object.destination.y) {
      delete this.sfx.objectPool[id];
      continue;      
    }
  } 

  if(object_count(this.sfx.objectPool) == 0) {
    this.stop();
  }
      
  return true;
}




function image_expression_raisePopup(ev){
  if(typeof this.alvine_popupid == 'undefined') return false;
  if(typeof this.alvine_popupContent == 'undefined') return false;
  
  content_layout_popup_js_show(this.alvine_popupid, this.alvine_popupContent, true);
  
  return true;
}


  
  function __debug(arr,showalert) {
    var ret = '';
    var level = 0;
    showalert = (showalert!='undefined')?showalert:true;
    if(!name) name = '';

    
    var level_padding = "";
    
    if(!showalert){
      ret+= '<div style="margin:0px 0px 5px 0px;background:#ffcccc;overflow:hidden;border:1px solid #000000;color:#444444;">'+"\n";
      ret+= '<div style="font-style:italic">DEBUG-Output(JS)</div>'+"\n";
      ret+= '<div style="font-weight:bold">'+name+'</div>'+"\n";
      ret+= '<pre>'+"\n";
    }
    for(var j=0;j<=level;j++) level_padding += "  ";
    if(typeof(arr) == 'object') { 
     for(var item in arr) {
      var value = arr[item];
      if(typeof(value) == 'object') { 
       ret += level_padding + "" + item + " ... ";
       ret += dump(value,level+1);
       ret += "\n";
      } else {
       ret += level_padding + "" + item + " => " + value + "\n";
      }
     }
    } else { 
     ret+= "===>"+arr+"<===("+typeof(arr)+")"+"\n";
    }
    if(!showalert){
      ret+= '</pre>'+"\n";
      ret+= '</div>'+"\n";
    }
    
    if(!showalert){
      document.write(ret);
    }else{
      alert(ret);
    }
    
    return true;
  }

function _dbg(dbgObj){
  if(typeof dbgObj == 'undefined'){
    alert('_dbg: no object given');
    return false;
  }
  
  var x = new Array();

  var ipp = 18;
  var tmp = new Array();
  var cnt = 0;
  for(var i in dbgObj){    
    
    if(typeof dbgObj[i] == 'undefined') continue;
    tmp.push(i.toString()+': '+dbgObj[i]);
    cnt++;
    if(cnt==ipp){
      x.push(tmp.join("\n"));
      var tmp = new Array();
      cnt = 0;
    }
  
  }
  for(var id in x){
    alert(x[id]);
  }
}

function errorMessage(meldung, url, zeile){
   var txt = "Es ist ein Fehler aufgetreten!\n\n"
   txt += "Meldung: " + meldung + "\n"
   txt += "URL: " + url + "\n"
   txt += "Zeile: " + zeile
   alert(txt)
   return true
}


 
function content_frontend_plugin_public_education_lesson_list_init(boxID){
  if(typeof alvine.plugin[boxID] == 'undefined') alvine.plugin[boxID] = new Object();
}

var content_frontend_plugin_content_layout_tooltips = new Object();
var content_frontend_plugin_content_layout_windowsSensitiveBorder = new Object();
content_frontend_plugin_content_layout_windowsSensitiveBorder.x = 15;
content_frontend_plugin_content_layout_windowsSensitiveBorder.y = 15;

function content_frontend_plugin_content_layout_tooltip_register(toolTipID, obj, content, position, mode, options) {
  if(typeof content_frontend_plugin_content_layout_tooltips[obj.id] == 'undefined') content_frontend_plugin_content_layout_tooltips[obj.id] = new Object();
  
  content_frontend_plugin_content_layout_tooltips[obj.id]['target']   = toolTipID;
  content_frontend_plugin_content_layout_tooltips[obj.id]['source']   = obj.id;
  content_frontend_plugin_content_layout_tooltips[obj.id]['content']  = content;
  content_frontend_plugin_content_layout_tooltips[obj.id]['fix_width'] = (typeof content == 'string')?true:false;
  content_frontend_plugin_content_layout_tooltips[obj.id]['mode']     = mode;
  content_frontend_plugin_content_layout_tooltips[obj.id]['options']  = options;
  content_frontend_plugin_content_layout_tooltips[obj.id]['position'] = position;

  return true;
}

function content_frontend_plugin_content_layout_tooltip_getItem(obj) {
  
  obj = element_isObject(obj);
  if(!obj) return;
    
  if(typeof content_frontend_plugin_content_layout_tooltips[obj.id] == 'undefined') return false;
  
  return content_frontend_plugin_content_layout_tooltips[obj.id];
}

function content_frontend_plugin_content_layout_tooltip_init(toolTipID, obj, content, hideEvent, mode, options) {
  obj = element_isObject(obj);
  if(!obj) return true;

  if(obj.alvine_tooltipInitalized) {
    content_frontend_plugin_content_layout_tooltip_showObject(obj);
    return true;
  }

  if(typeof hideEvent == 'undefined') hideEvent = 'mouseout';

  if(typeof options == 'undefined') {
    options = new Object();
  } else { 
    var tmpEntries = options.split(',');
    options = new Object();
    for(var i = 0;i<tmpEntries.length;i++){
      var entry = tmpEntries[i];
      tmpKeyVal = entry.split(':');

      options[tmpKeyVal[0]] = tmpKeyVal[1];
    }
  }
  if(typeof options['offset']             == 'undefined') options['offset']             = new Object();
  if(typeof options['offset']['positive'] == 'undefined') options['offset']['positive'] = new Object();
  if(typeof options['offset']['negative'] == 'undefined') options['offset']['negative'] = new Object();
  if(typeof options['currentPosition']    == 'undefined') options['currentPosition']    = new Object();
  if(typeof options['width']              == 'undefined') options['width']              = null;
  if(typeof options['min_width']          == 'undefined') options['min_width']          = 300;
  
  var position = element_getPosition(obj, true);

  content_frontend_plugin_content_layout_tooltip_register(toolTipID, obj, content, position, mode, options);

  var ttObj = element_isObject(toolTipID);
  if(!ttObj) return true;

  if(typeof ttObj.alvine_isVisible != 'function'){
    ttObj.alvine_isVisible = function(){

      if(strstr(this.className, 'hidden')) return false;

      return true;
    };
  }

  if(typeof ttObj.alvine_setVisibility != 'function'){
    ttObj.alvine_setVisibility = function(status){
      status = (status===false)?false:true;

      if(status==true){
        if(this.alvine_isVisible()) return;
        element_removeClassName(this, 'hidden', ' ');        
        element_setVisibility(this, 'visible');

        ie6ToggleActiveXControls(false);
      } else {
        if(!this.alvine_isVisible()) return;
        element_setVisibility(this, 'hidden');
        element_move(this, -999, -999);
        element_removeClassName(this, 'hidden', ' ');
        element_addClassName(this, 'hidden');

        ie6ToggleActiveXControls(true);
      }

      
      this.className = str_replace('  ', ' ', this.className);
    };
  }

  if(ttObj.alvine_isVisible()) ttObj.alvine_setVisibility(false);  
  if(ttObj.style.display == 'none') element_setDisplay(ttObj, 'block'); 
  content_frontend_plugin_content_layout_tooltip_adjust(obj);

  event_add(obj, hideEvent, content_frontend_plugin_content_layout_tooltip_hideObject);

  obj.alvine_tooltipObject = ttObj;

  switch(mode){
    default:
    case 'mouse':
      mouse_attachToObject(obj);
      event_add(obj, 'mousemove', content_frontend_plugin_content_layout_tooltip_handleMouse);
      event_add(obj, 'mouseover', content_frontend_plugin_content_layout_tooltip_handleMouse);
      break;
    
    case 'sticky':
      event_add(obj, 'focus', content_frontend_plugin_content_layout_tooltip_handleSticky);
      event_add(obj, 'mouseover', content_frontend_plugin_content_layout_tooltip_handleSticky);
      content_frontend_plugin_content_layout_tooltip_stickToObject(null, obj);
      break;

  }  
  content_frontend_plugin_content_layout_tooltip_showObject(obj);
  obj.alvine_tooltipInitalized = true;

  return true;
}


function content_frontend_plugin_content_layout_tooltip_handleMouse(ev){
  if(!ev)   ev = window.event;

  content_frontend_plugin_content_layout_tooltip_setPosition(null, this);

  return object_preventDefaultEventBehaviour(ev);
}

function content_frontend_plugin_content_layout_tooltip_handleSticky(ev){
  if(!ev)   ev = window.event;

  content_frontend_plugin_content_layout_tooltip_stickToObject(null, this);

  content_frontend_plugin_content_layout_tooltip_showObject(this);

  return object_preventDefaultEventBehaviour(ev);
}

function content_frontend_plugin_content_layout_tooltip_adjust(obj){
  obj = element_isObject(obj);
  if(!obj) return true;

  var itemData = content_frontend_plugin_content_layout_tooltip_getItem(obj);

  var ttObj = itemData.target;
  if(!ttObj) return true;

  element_resetSize(ttObj);

  var ttSize = element_getSize(ttObj);

  if(itemData.fix_width){    
    if(ttSize.width>itemData.options.min_width){
      element_setWidth(ttObj, itemData.options.min_width);
    }   
  } else if(itemData.options.width) {
    if(ttSize.width>itemData.options.width){
      
      element_setWidth(ttObj, itemData.options.width);
    }
  }

  return true;
}

function content_frontend_plugin_content_layout_tooltip_arrangeContent(obj, content){
  obj = element_isObject(obj);
  if(!obj) return;

  var gfxObject = element_isObject(obj.id+'_gfx');
  if(gfxObject!=null){
    
    element_addChildNodes(gfxObject, content, true);
  } else {
    
    element_addChildNodes(obj, content, true);
  }
   
  return true;
}

function  content_frontend_plugin_content_layout_tooltip_setPosition(ev, obj){

  if(!ev) ev = window.event;
  var targetObj = (typeof obj!='object')?this:obj;
  
  var item = content_frontend_plugin_content_layout_tooltip_getItem(targetObj);
  var ttPosition = new Object();
  var ttObj = element_isObject(item.target);
  if(!ttObj) return object_preventDefaultEventBehaviour(ev);
  
  if(!ttObj.alvine_isVisible()) content_frontend_plugin_content_layout_tooltip_showObject(targetObj);

  var options = item.options;
  
  options['offset']['positive']['x'] = 15;
  options['offset']['positive']['y'] = 15;
  options['offset']['negative']['x'] = 5;
  options['offset']['negative']['y'] = 8;  
  
  if(typeof document.alvine_getMousePosition != 'function') return true; 
  options['currentPosition'] = document.alvine_getMousePosition(true, false);

  ttPosition = content_frontend_plugin_content_layout_tooltip_calcPosition(targetObj, options);
  
  element_move(ttObj, ttPosition.x, ttPosition.y);
  
  return object_preventDefaultEventBehaviour(ev);
}

function content_frontend_plugin_content_layout_tooltip_stickToObject(ev, obj) {

  if(!ev) ev = window.event;
  
  var parentObj = this;
  parentObj     = (typeof obj != 'undefined')?element_isObject(obj):parentObj;

  var item  = content_frontend_plugin_content_layout_tooltip_getItem(parentObj);
  var ttObj = element_isObject(item.target);

  var tooltipPositionRange = (typeof item.options.stick == 'undefined')?null:item.options.stick;
  
  
  content_frontend_plugin_content_layout_tooltip_arrangeContent(ttObj, item.content);
  
  var itemSize    = element_getSize(item.source);
  var toolTipSize = element_getSize(item.target);

  var options = item.options;
  
  options['offset']['positive']['x'] = 2;
  options['offset']['positive']['y'] = 2;
  options['offset']['negative']['x'] = itemSize.width;
  options['offset']['negative']['y'] = (itemSize.height+4);  
  
  var left = item.position.x;
  var top  = item.position.y;

  switch(tooltipPositionRange){    
    case 'top':
      top -= toolTipSize.height;
      break;
    
    default:
    case 'bottom':
      top += itemSize.height;
      break;
    
    case 'left':
      left-= toolTipSize.width;
      break;
    
    case 'right':
      left+= itemSize.width;
      break;
  }

  options['currentPosition']['x'] = left; 
  options['currentPosition']['y'] = top; 

  var ttPosition = content_frontend_plugin_content_layout_tooltip_calcPosition(parentObj, options);

  element_move(ttObj, ttPosition.x, ttPosition.y);
  
  return object_preventDefaultEventBehaviour(ev);
  
}

function content_frontend_plugin_content_layout_tooltip_calcPosition(obj, options){
  obj = element_isObject(obj);
  if(!obj) return false;

  var item  = content_frontend_plugin_content_layout_tooltip_getItem(obj);
  var ttObj = element_isObject(item.target);

  var toolTipSize = element_getSize(ttObj);

  
  var x = options.currentPosition.x;
  var y = options.currentPosition.y;

  var offsetX = options.offset.positive.x; 
  var offsetY = options.offset.positive.y;
    
  var negativeOffsetX = options.offset.negative.x;  
  var negativeOffsetY = options.offset.negative.y;  
  
  var sensitiveBorderX = content_frontend_plugin_content_layout_windowsSensitiveBorder.x; 
  var sensitiveBorderY = content_frontend_plugin_content_layout_windowsSensitiveBorder.y;
  
  var windowInnerWidth  = null;
  var windowInnerHeight = null;
  
  var viewPort = alvine_getViewport();

  windowInnerWidth  = viewPort.width;
  windowInnerHeight = viewPort.height;

  var scrollPos = element_getScrollPosition();
  windowInnerWidth += scrollPos.x;
  windowInnerHeight+= scrollPos.y;

  
  if(x + offsetX + toolTipSize.width  >= windowInnerWidth - sensitiveBorderX)  offsetX = 0 - negativeOffsetX - toolTipSize.width;
  if(y + offsetY + toolTipSize.height >= windowInnerHeight - sensitiveBorderY) offsetY = 0 - negativeOffsetY - toolTipSize.height;
  
  x += offsetX;
  y += offsetY;
  
  return {
    x:x,
    y:y
  };
  
}





function content_frontend_plugin_content_layout_tooltip_showObject(obj, addContent) {
  
  var item = content_frontend_plugin_content_layout_tooltip_getItem(obj);  
  if(!item) return true;

  var ttObj = element_isObject(item.target);
  
  if(typeof addContent == 'undefined') addContent = true;
  if (ttObj == null) return true;

  
  if(addContent) {
    content_frontend_plugin_content_layout_tooltip_arrangeContent(ttObj, item.content);
  }
  
  
  content_frontend_plugin_content_layout_tooltip_adjust(obj);

  element_setOpacity(ttObj, 0);
  
  element_setVisibility(ttObj, 'visible');
  ttObj.alvine_setVisibility(true);

  ttObj.alvine_fadeEffectObj = effects_fade(ttObj, 100, 'now', 16, 25);
  return true;    
}

function content_frontend_plugin_content_layout_tooltip_hideObject(ev) {
  
  if(!ev) ev = window.event;
  
  var item = content_frontend_plugin_content_layout_tooltip_getItem(this);
  var ttObj = element_isObject(item.target);

  if (ttObj == null) return false;  

  if(ttObj.alvine_isVisible()) ttObj.alvine_setVisibility(false);
  
  if(typeof ttObj.alvine_fadeEffectObj == 'object') {
    ttObj.alvine_fadeEffectObj.effect_stop();
  }

  return object_preventDefaultEventBehaviour(ev);
}



function content_frontend_plugin_content_layout_tooltip_show(toolTipID, content) {
  var ttObj = null;
  ttObj = element_isObject(toolTipID);

  if (ttObj == null) return false;
  
  if(content!=undefined) content_frontend_plugin_content_layout_tooltip_arrangeContent(ttObj, content);

  content_frontend_plugin_content_layout_tooltip_adjust(obj);

  
  element_setVisibility(ttObj, 'hidden');
  ttObj.alvine_setVisibility(true);

  element_setOpacity(ttObj, 0);
  element_setVisibility(ttObj, 'visible');

  effects_fade(ttObj, 100, 'now', 16, 25);
  return true;
}

function content_frontend_plugin_content_layout_tooltip_hide(ttObj) {

  ttObj = element_isObject(ttObj);
  if (ttObj == null) return false;
  
  if(ttObj.alvine_isVisible()) ttObj.alvine_setVisibility(false);
  
  if(typeof ttObj.alvine_fadeEffectObj == 'object') {
    ttObj.alvine_fadeEffectObj.effect_stop();
  }
  return true;  
}



function content_layout_popup_js_init(boxID, minSize, showPopup, cropContent){

  var parentBoxID = 'content_layout_popup_'+boxID;
  var backgroundBoxID = parentBoxID+'_background';
  var visibleBoxID = parentBoxID+'_visible_panel';
  var contentPanelID = parentBoxID+'_content';
  var visibleObj = element_isObject(visibleBoxID);
  var backgroundObj = element_isObject(backgroundBoxID);
  
  if(typeof visibleObj.alvine_setPositioning != 'function'){
    visibleObj.alvine_setPositioning = function(targetSize){
      var viewPort = alvine_getViewport();
      
      if(targetSize.width >= viewPort.width ||
        targetSize.height >= viewPort.height
        ){
        this.style.position = 'absolute';
        if(this.parentNode) this.parentNode.style.position = 'absolute';
      } else {
        if(!_ALVINE_IE6) {
          this.style.position = 'fixed';
          if(this.parentNode) this.parentNode.style.position = 'fixed';
        }
      }
    };
  }
  
  visibleObj.minimalSize = (typeof minSize == 'object')?minSize:{
    width:0,
    height:0
  };

  var useCapturing = true;
  
  
  event_add(window, 'resize', 'content_layout_popup_js_move("'+boxID+'")', useCapturing);
  event_add(window, 'minimize', 'content_layout_popup_js_move("'+boxID+'")', useCapturing);
  event_add(window, 'maximize', 'content_layout_popup_js_move("'+boxID+'")', useCapturing);

  var parentObj = element_isObject(parentBoxID);

  parentObj['alvine_visible'] = (parentObj.style.display == 'none')?false:true;
  parentObj['alvine_backgroundObj'] = backgroundObj;
  
  if(_ALVINE_IE){
    parentObj.alvine_ieFixCropping = function(){
      var windowSize;

      if(document.documentElement){
        windowSize = {
          width:document.documentElement.scrollWidth ,
          height:document.documentElement.scrollHeight
          };
      } else if(document.body){
        windowSize = {
          width:document.body.scrollWidth ,
          height:document.body.scrollWidth
          };
      }

      if(windowSize.width){
        element_setSize(this, windowSize.width, windowSize.height);
      }
    };
  }
  
  var objContent = element_isObject(contentPanelID);
  if(typeof objContent.alvine_executeChildrensHandler != 'function'){
    objContent.alvine_executeChildrensHandler = function(functionName, params){
      if(typeof functionName == 'undefined' || functionName == '') return true;

      for(var i in this.childNodes){
        var cNode = this.childNodes[i];
        if(typeof cNode != 'object') continue;
        if(typeof cNode[functionName] != 'function') continue;

        
        cNode[functionName](params);
      }
      return true;
    };
  }
  showPopup = (showPopup===true)?true:false;

  if(!showPopup) return true;
  cropContent = (cropContent===true)?true:false;
  element_move(parentObj, -9999, 0);

  content_layout_popup_js_autoFit(boxID, false, true, cropContent);
  content_layout_popup_js_show(boxID, null, null, cropContent);
  
  return true;
}

function content_layout_popup_js_show(boxID, contentNodes, clear, cropContent, title, sourceObject, positionOffset, clearOnClose){
  clear = (typeof clear == 'undefined')?false:true;

  var newBoxID = 'content_layout_popup_'+boxID;
  var obj = element_isObject(newBoxID);

  if(!obj) return false;

  obj.alvine_sourceObject   = sourceObject;
  obj.alvine_positionOffset = positionOffset;
  obj.alvine_clearOnClose   = (typeof clearOnClose == 'undefined')?false:clearOnClose;

  var scrollContentObj = element_isObject(newBoxID+'_scroll_content');
  scrollContentObj.style.position = 'relative';

  var contentObj = element_isObject(newBoxID+'_content');
  if(!contentObj) contentObj = obj;

  if(typeof contentNodes!='undefined' && contentNodes!=null){
    if(clear==true){
      element_addChildNodes(contentObj, contentNodes, true);
    } else {
      element_addChildNodes(contentObj, contentNodes);
    }
  }

  
  if(title){
    content_layout_popup_js_setTitle(boxID, title);
  }

  ie6ToggleActiveXControls(false);

  
  element_setOpacity(obj, 0);
  element_setDisplay(obj, 'block');

  if(typeof contentObj.alvine_executeChildrensHandler == 'function') contentObj.alvine_executeChildrensHandler('alvine_onOpen');
  element_move(obj, 0, 0);
  obj['alvine_visible'] = true;

  cropContent = (cropContent===true)?true:false;
  content_layout_popup_js_autoFit(boxID, false, true, cropContent);
  content_layout_popup_js_move(boxID);

  if(obj.alvine_backgroundObj){
    if(typeof obj.alvine_backgroundObj.alvine_initOpacity == 'undefined') {
      obj.alvine_backgroundObj.alvine_initOpacity = element_getOpacity(obj.alvine_backgroundObj);
    }
    element_setOpacity(obj.alvine_backgroundObj, 0);
    element_setDisplay(obj.alvine_backgroundObj, 'block');
    
    var trgOpacity = (obj.alvine_backgroundObj.alvine_initOpacity>0)?obj.alvine_backgroundObj.alvine_initOpacity:100;
    effects_fade(obj.alvine_backgroundObj, trgOpacity, 'now', parseInt((trgOpacity/100*50)), parseInt((trgOpacity/100*80)));
  }
  effects_fade(obj, '100', 'now', 35, 90);

  return true;

}

function content_layout_popup_js_autoFit(boxID, considerVisibility, forceInit, cropContent){

  forceInit = (forceInit===true)?true:false;
  cropContent = false;
  considerVisibility = (considerVisibility===false)?false:true;
  var parentBoxID = 'content_layout_popup_'+boxID;
  var visiblePanelID = parentBoxID+'_visible_panel';

  var objParent = element_isObject(parentBoxID);
  if(!objParent) return true;

  if(!objParent['alvine_visible']) return true;

  if(_ALVINE_IE) objParent.alvine_ieFixCropping();

  var objVisible = element_isObject(visiblePanelID);
  if(!objVisible) return true;

  var viewPort = alvine_getViewport();

  element_resetSize(objVisible);

  var currentSize = element_getSize(objVisible);

  var max;
  if(cropContent){    
    var maxPercentage = 0.8; 
    max = {
      width:parseInt((viewPort.width * maxPercentage)),
      height:parseInt((viewPort.height * maxPercentage))
    };

  
  } else {
    max = currentSize;
  }
  var min         = new Object();
  
  for(var key in objVisible.minimalSize) min[key] = objVisible.minimalSize[key];

  
  if(typeof objVisible.alvine_initialSize == 'undefined' || forceInit) objVisible.alvine_initialSize = new Object();

  var initialSize = new Object();
  for(var key in currentSize) {
    if(typeof objVisible.alvine_initialSize[key] == 'undefined' || objVisible.alvine_initialSize[key] == 0) objVisible.alvine_initialSize[key] = currentSize[key];
    initialSize[key] = (parseInt(currentSize[key])>=objVisible.alvine_initialSize[key])?parseInt(currentSize[key]):objVisible.alvine_initialSize[key];
  }

  var targetSize = initialSize;

  
  if(targetSize.width  >= max.width){
    targetSize.width  = max.width;
  } else if(targetSize.width  <= min.width){
    targetSize.width  = min.width;
  }

  if(targetSize.height >= max.height){
    targetSize.height = max.height;
  } else if(targetSize.height  <= min.height){
    targetSize.height = min.height;
  }
  
  
  element_setSize(objVisible, targetSize.width, targetSize.height, true);
  content_layout_popup_js_move(boxID);

  return true;
}

function content_layout_popup_js_move(boxID){

  var parentBoxID = 'content_layout_popup_'+boxID;
  var parentObj = element_isObject(parentBoxID);
  if(!parentObj) return true;
  if(!parentObj['alvine_visible']) return true;
  
  var visiblePanelID = parentBoxID+'_visible_panel';

  var objVisible = element_isObject(visiblePanelID);

  if(!objVisible) return true;

  var currentSize = element_getSize(objVisible);

  if(_ALVINE_IE) parentObj.alvine_ieFixCropping();

  var initialSize = new Object();
  for(var key in currentSize) {
    if(typeof objVisible.alvine_initialSize == 'undefined' ) {
      objVisible.alvine_initialSize = {};
      if(typeof objVisible.alvine_initialSize[key] == 'undefined' ) {
        objVisible.alvine_initialSize[key] = currentSize[key];
      }
    } else if(typeof objVisible.alvine_initialSize[key] == 0 ) {
      objVisible.alvine_initialSize[key] = currentSize[key];
    }

    initialSize[key] = (parseInt(currentSize[key])>=objVisible.alvine_initialSize[key])?parseInt(currentSize[key]):objVisible.alvine_initialSize[key];
  }

  var targetSize = initialSize;

  
  objVisible.alvine_setPositioning(targetSize);

  var sourceObject   = parentObj.alvine_sourceObject;
  var positionOffset = parentObj.alvine_positionOffset;

  if(typeof positionOffset != 'object'){
    positionOffset   = {
      x:'center',
      y:'center'
    };
  } else {
    positionOffset.x = (typeof positionOffset.x == 'undefined')?'center':positionOffset.x;
    positionOffset.y = (typeof positionOffset.y == 'undefined')?'center':positionOffset.y;
  }

  var popupSize = element_getSize(objVisible);

  var srcPos   = null;
  var srcSize  = null;
  if(typeof sourceObject == 'object'){
    srcPos   = element_getPosition(sourceObject, true);
    srcSize  = element_getSize(sourceObject);

    element_resetSize(objVisible);
    popupSize = element_getSize(objVisible);

    objVisible.style.position = 'absolute';
  } else {
    srcPos   = element_getPosition(objVisible, true);
    srcSize  = element_getSize(objVisible);
  }

  var hValues = positionOffset.x.toString().split(':');
  var vValues = positionOffset.y.toString().split(':');

  if(hValues[0] == 'center'){
  } else if(hValues[0] == 'left'){
    positionOffset.x = (popupSize.width  * (-1));
  } else if(hValues[0] == 'right'){
    positionOffset.x = srcSize.width;
  } else{
    positionOffset.x = parseInt(hValues[0]);
  }
  if(typeof positionOffset.x != 'string') positionOffset.x+= (typeof hValues[1] != 'undefined')?parseInt(hValues[1]):0;

  if(vValues[0] == 'center'){
  } else if(vValues[0] == 'top'){
    positionOffset.y = ((popupSize.height + srcSize.height)  * (-1));
  } else if(vValues[0] == 'bottom'){
    positionOffset.y = 0;
  } else{
    positionOffset.y = parseInt(vValues[0]);
  }
  if(typeof positionOffset.y != 'string') positionOffset.y+= (typeof vValues[1] != 'undefined')?parseInt(vValues[1]):0;

  var viewPort = alvine_getViewport();
  var parentCenter;
  var objectCenter;

  if(positionOffset.x == 'center' || positionOffset.y == 'center'){
    parentCenter = new Object();
    objectCenter = new Object();
  }

  var trgPos = new Object();
  if(positionOffset.x == 'center'){
    parentCenter.x = parseInt((viewPort.width/2));
    objectCenter.x = parseInt((popupSize.width/2));
    trgPos.x = (parentCenter.x - objectCenter.x);
  } else {
    trgPos.x = (srcPos.x + positionOffset.x);
    if((trgPos.x+popupSize.width)>=(viewPort.width+window.scrollX)) {
      var newWidth = (viewPort.width - srcPos.x - positionOffset.x);
      element_setWidth(objVisible, newWidth);
      popupSize.width = newWidth;
      trgPos.x = (srcPos.x - popupSize.width - positionOffset.x);
    }
  }

  if(positionOffset.y == 'center'){
    parentCenter.y = parseInt((viewPort.height/2));
    srcSize  = element_getSize(objVisible);
    objectCenter.y = parseInt((popupSize.height/2));
    trgPos.y = (parentCenter.y - objectCenter.y);
  } else {
    trgPos.y = (srcPos.y + srcSize.height + positionOffset.y);
    if((trgPos.y+popupSize.height)>=(viewPort.height+window.scrollY)) {
      

      trgPos.y = (srcPos.y - popupSize.height - positionOffset.y);
    }
  }

  if(trgPos.x<0) trgPos.x = 0;
  if(trgPos.y<0) trgPos.y = 0;

  element_move(objVisible, trgPos.x, trgPos.y);

  return true;
}



function content_layout_popup_js_setTitle(boxID, title){
  var newBoxID = 'content_layout_popup_'+boxID;

  var obj = element_isObject(newBoxID);
  if(!obj) return false;

  var titleObj = element_isObject(newBoxID+'_title');
  if(!titleObj) return false;

  writeHTML(titleObj, title);

  return true;
}

function content_layout_popup_js_attach(popupContentID, srcID, popupID, title, event, clear, cropContent, clearOnReset){

  if(typeof popupContentID    == 'undefined') return false;
  if(typeof popupID  == 'undefined') return false;

  var srcObj = element_isObject(srcID);
  if(!srcObj) return false;

  var popupContentObject = element_isObject(popupContentID);
  if(!popupContentObject) return false;

  srcObj['alvine_popupContentObject'] = popupContentObject;
  srcObj['alvine_popupID']            = popupID;
  srcObj['alvine_popupTitle']         = title;
  srcObj['alvine_popupClear']         = (typeof clear == 'undefined')?true:clear;
  srcObj['alvine_popupCropContent']   = (typeof cropContent == 'undefined')?false:cropContent;
  srcObj['alvine_popupClearOnReset']  = (typeof clearOnReset == 'undefined')?false:clearOnReset;

  event = (typeof event == 'undefined')?'click':event;

  event_add(srcObj, event, content_layout_popup_js_raisePopUp, true);

  return true;
}

function content_layout_popup_js_raisePopUp(ev){
  if(!ev) ev = window.event;

  content_layout_popup_js_show(this.alvine_popupID, this.alvine_popupContentObject, this.alvine_popupClear, this.alvine_popupCropContent, this.alvine_popupTitle, '', '', this.alvine_popupClearOnReset);

  return true;
}

function content_layout_popup_js_closePopup(popupID){

  var obj = element_isObject(popupID);
  if(!obj) return false;

  var contentObj = element_isObject(popupID+'_content');
  if(typeof contentObj.alvine_executeChildrensHandler == 'function') contentObj.alvine_executeChildrensHandler('alvine_onClose');

  var visibleObj = element_isObject(popupID+'_visible_panel');

  if(typeof visibleObj.alvine_initPosition == 'object') visibleObj.alvine_initPosition = new Object();
  if(typeof obj.alvine_initialSize == 'object') obj.alvine_initialSize = new Object();

  element_setDisplay(obj, 'none');

  if(obj.alvine_backgroundObj){
    element_setDisplay(obj.alvine_backgroundObj, 'none');
  }
  element_move(obj, -9999, 0);
  obj['alvine_visible'] = false;

  if(obj.alvine_clearOnClose){
    if(!contentObj) contentObj = obj;

  
  }

  element_resetSize(visibleObj);
  ie6ToggleActiveXControls(true);
  return true;

}
