﻿	/*
		author: sebastian arndt
		
		notice:
		
			-> the members of the classes (variables) must be in lowercase and should named like this:
			
				m_xxxxx
	*/

	/*
		all avaible action are listed here
	*/
	
	var objActions = new Array();

	/*
		returns the description of a event
	*/
	function GetEventDescription(iEventID) {
		switch(iEventID) {
			case "1":
				return "(Mausklick)";
			break;	
			case "2":
				return "(Mausbewegung)";
			break;
			case 1:
				return "(Mausklick)";
			break;	
			case 2:
				return "(Mausbewegung)";
			break;
			default:
				alert('error in this.iEventID ("' + iEventID + '")');
		}
	}
	/*
		creates a action from a given array
		
		parameter:
			arActionArray - the array (generated by toArray)
	*/
	function CreateActionFromArray(arActionArray) {
		return eval(" new " + arActionArray["m_szconstructor"] + "(arActionArray);"); 
	}
	
	/*
		converts a action into a array
		
		paremter:
			objAction - the action object
	*/
	function ConvertActionToArray(objAction) {
		var arResult = new Array();
		for(objKey in objAction) {
			if(objKey.substr(0,2) == "m_") {
				arResult[objKey] = objAction[objKey];
			}
		}
		return arResult;
	}
	
	/*
		copies the array values into a object
	*/
	function ConvertArrayToObject(objAction,arArray) {
		for(objKey in arArray) {
			objAction[objKey] = arArray[objKey];
		}
	}
	
	/*
		if the variable is a array
	*/
	function isArray(objArray) {
		try {
			if(objArray.length == undefined) return false;
			return true;
		} catch(e) {
			return false;
		}
	}
	
	/*
		info action
		
		parameter:
			iEventID - the event id (can also be a array with the given variables)
			szInfo - the info text to show
	*/
	function Action_Info(iEventID,szInfo) {
		this.m_szconstructor = "Action_Info";
		if(isArray(iEventID) || (iEventID instanceof Object)) {			
			ConvertArrayToObject(this,iEventID);		
		} else {		
			this.m_ieventid = iEventID;
			this.m_szinfo = szInfo;
			this.m_itype = 3;
		}
	
		this.toArray = Action_Info_toArray;
		this.GetActionDescription = Action_Info_GetActionDescription;
		this.Execute = Action_Info_Execute;
	}
	
	function Action_Info_toArray() {
		return ConvertActionToArray(this);
	}
	
	function Action_Info_GetActionDescription() {
		var szResult = "";
		szResult += "Infotext anzeigen " + GetEventDescription(this.m_ieventid);
		return szResult;
	}
	
	
	function Action_Info_Execute(objExtra, objSource, iLeft, iRight) {

		var t = document.getElementById('mnu_tooltip');
		var infotext = this.m_szinfo;
	
		objSource.onmousemove = function (evt) {

			var x = (document.all) ? window.event.x + document.body.scrollLeft : evt.pageX;
			var y = (document.all) ? window.event.y + document.body.scrollTop  : evt.pageY;
			
			t.innerHTML = infotext;
			
			t.style.left    = (x + 20) + 'px';
			t.style.top     = (y + 5) + 'px';
			t.style.display = 'block';
			
		};

		objSource.onmouseout = function (evt) {
			t.innerHTML = '';
			t.style.display = 'none';
		};

	}
	
	/*
		parameter:
			iEventID - the event id
			szLink - the link url
			iLinkID - the link id
			szTarget - the link target
			iTargetID - the link target id
	*/
	function Action_Link(iEventID,szLink,iLinkID,szTarget,iTargetID) {

		this.m_szConstructor = "Action_Link";
		if(isArray(iEventID) || (iEventID instanceof Object)) {
			ConvertArrayToObject(this,iEventID);	
		} else {	
			this.m_ieventid = iEventID;
			this.m_szlink = szLink;
			this.m_ilinkid = iLinkID;
			this.m_itype = 1;
		}
	
		this.GetActionDescription = Action_Link_GetActionDescription;
		this.toString = Action_Link_toString;
		this.toArray = Action_Link_toArray;
		this.Execute = Action_Link_Execute;
	}
	
	function Action_Link_Execute(objExtra,objSource,iLeft,iRight) {
		window.open(objExtra.szURL,objExtra.szTarget);
	}
	
	function Action_Link_toArray() {
		return ConvertActionToArray(this);
	}
	
	function Action_Link_toString() {
		return "Action Link [object]";
	}

	function Action_Link_GetActionDescription() {
		var szResult = "";
		szResult += "Link ausführen " + GetEventDescription(this.m_ieventid);
		return szResult;
	}
	
	/*
		expand action	
	*/
	function Action_Expand(iEventID) {
		this.m_szconstructor = "Action_Expand";	
		if(isArray(iEventID) || (iEventID instanceof Object)) {
			ConvertArrayToObject(this,iEventID);		
		} else  {
			this.m_ieventid = iEventID;
			this.m_itype = 2;
		}
		
		this.toArray = Action_Expand_toArray;
		this.GetActionDescription = Action_Expand_GetActionDescription;	
		this.Execute = Action_Expand_Execute;
	}

	function Action_Expand_Execute(objExtra,objSource,iLeft,iRight) {
		var szExpanded = "document.all.node_span_" + iLeft + ".className";
		if(szExpanded == objExtra.szHidden) {
			eval("document.all.node_span_" + iLeft + ".className = objExtra.szNormal;");
		} else {	
			eval("document.all.node_span_" + iLeft + ".className = objExtra.szHidden;");
		} 
	}
	
	function Action_Expand_GetActionDescription() {
		var szResult = "";
		szResult += "Menüpunkte aufklappen " + GetEventDescription(this.m_ieventid);
		return szResult;
	}
	
	function Action_Expand_toArray() {
		return ConvertActionToArray(this);
	}
