// JavaScript Document


try {
	if (bee4me) {
		
	}
} catch(error) {
	bee4me = [] ;
	bee4me.screen = [] ;
}

/**
 *	Dummy function for document.getElementById
 */
function $(el) {
	if(typeof el == 'object') return el ;
	
	return document.getElementById(el) ;
}


/**
 *	Disable the border on all checkboxes.
 * IE shows a border around checkboxes when a border is defined for the INPUT tag.
 */
function repairCheckboxDesign() {
	var arInput=document.getElementsByTagName("input");

	 for(var i=0;i<arInput.length;i++){
			if(arInput[i].type.toLowerCase()=="checkbox"){
				arInput[i].style.border="none";
		 }
	 }
}

/*
	Transformiert Content einer XML File mit Darstellung aus einem XSL File
*/
function renderXMLXSLContent(xmlfile,xslfile) {

	var transform;
	
	if (typeof ActiveXObject != "undefined") {
		transform = xmlfile.transformNode(xslfile);
	} else {
		var xsl = new XSLTProcessor();
		xsl.importStylesheet(xslfile);
		var fragment=xsl.transformToFragment(xmlfile, document);
		if( fragment.childNodes.length>0 )
		  transform = fragment.childNodes[0].innerHTML;
		else
			alert("error");
	}
	
	delete xmlfile ;
	delete xslfile ;
	
	return transform;
}

/**
 *	Parses the innerHTML for scripts and executes them
 */
function execJSFromHTML(el) {
	if (typeof el == 'object') {
		st = el.getElementsByTagName('SCRIPT');
	} else {
		st = document.getElementById(el).getElementsByTagName('SCRIPT');
	}
	var strExec;
	for(var i=0;i<st.length; i++) {     
		if (!IE) {
			strExec = st[i].textContent;
		} 	else {
			strExec = st[i].text;
		}
		try {
			eval(strExec);
		} catch(e) {
			alert(e.message+"\n"+e.lineNumber+"\n"+e.filename);
			alert(strExec) ;
		}
	}
}


function getKeyfromString(stringy) {
	
	tmp = stringy.split('__');
	if(tmp.length) {
		x = tmp.length - 1;
		uid = tmp[x];
	} else {
		uid = tmp;
	}
	return uid;
}


// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
//document.onmousemove = getMouseXY;

/*
 * Retrieves the Real XY - Position of the mouse event...
 */
var	tempX = 0;
var	tempY = 0;
function getMouseXY(e) {
	
	  if (IE) { // grab the x-y pos.s if browser is IE
			tempX = event.clientX + document.body.scrollLeft
			tempY = event.clientY + document.body.scrollTop
	  } else {  // grab the x-y pos.s if browser is NS
			tempX = e.pageX
			tempY = e.pageY
	  }  
	  // catch possible negative values in NS4
	  if (tempX < 0){tempX = 0}
	  if (tempY < 0){tempY = 0}  
	  if(top.bee4me && top.bee4me.screen) {
		  top.bee4me.screen.mouseX = tempX;
		  top.bee4me.screen.mouseY = tempY;
	  }
	  
	  return false;
}


/*	EventCache Version 1.0
	Copyright 2005 Mark Wubben

	Provides a way for automagically removing events from nodes and thus preventing memory leakage.
	See <http://novemberborn.net/javascript/event-cache> for more information.
	
	This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/
/*	Event Cache uses an anonymous function to create a hidden scope chain.
	This is to prevent scoping issues. */
var EventCache = function(){
	var listEvents = [];
	
	return {
		listEvents : listEvents,
	
		add : function(node, sEventName, fHandler, bCapture){
			listEvents.push(arguments);
		},
	
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				
				/* From this point on we need the event names to be prefixed with 'on" */
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				
				item[0][item[1]] = null;
			};
		}
	};
}();


/*
 * Adds an Event to whatever you want
 */
function addEvent(obj, evType, fn){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, true);
		result = true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		result = r;
	} else {
		return false;
	}
	
	EventCache.add(obj,evType,fn) ;
	
	return result ;
}

addEvent(window,'unload',EventCache.flush) ;

/*
 * Gets the real windowWidth()
 * 
 */
function windowWidth() {
	if (window.innerWidth) {
		return window.innerWidth;
	} else if (document.body && document.body.offsetWidth) {
		return document.body.offsetWidth;
	} else {
		return 0;
	}
	
}

/*
 * Gets the real Window Height
 * 
 */
function windowHeight() {
	if (window.innerHeight) {
		return window.innerHeight;
	} else if (document.body && document.body.offsetHeight) {
		return document.body.offsetHeight;
	} else {
		return 0;
	}
}


/*
 * Changes the display state of an element. If the element has display=block it is set to none
 * and vice versa.
 */
function Toggle(item,frame,forcetype) {

	if((typeof item) == "object") {
		obj = item;
	} else {
		if (!frame) {
			obj = document.getElementById(item);
		} else {
			frame_obj = eval('content.'+frame) ;
			obj = frame_obj.document.getElementById(item) ;
		}
	}
	
	if(forcetype) {
		if (!obj) {
			alert(item) ;
		}
		obj.style.display = forcetype;
		
	} else {
	
		if(obj.style.display != "none") {
			obj.style.display = "none";
		} else {
			obj.style.display = "block";
		}
		
	}
}


/**
 *	Toggle is already defined in rico!!!
 */
function beeToggle(item,frame,forcetype) {

	if((typeof item) == "object") {
		obj = item;
	} else {
		if (!frame) {
			obj = document.getElementById(item);
		} else {
			frame_obj = eval('content.'+frame) ;
			obj = frame_obj.document.getElementById(item) ;
		}
	}
	
	if(forcetype) {
		if (!obj) {
			alert(item) ;
		}
		obj.style.display = forcetype;
		
	} else {
	
		if(obj.style.display != "none") {
			obj.style.display = "none";
		} else {
			obj.style.display = "block";
		}
		
	}
}


/*
 * @var globalSelectorItem Stores the last element that triggered the Timeout
 */
var globalSelectorItem = "";
/*
 * @var selectorTimeOut Reference to the selectortimeout
 */
var selectorTimeOut = "";
/**
 * Sets a timeout for an item. If the time ran out, the item changes its display the forcetype.
 *
 * @param string item The id of the Item
 * @param string forcetype Can be block or none
 * @param frame The frame that contains the item
 *
 */
function setSelectorTimeout(item, forcetype, frame) {
	if(globalSelectorItem == item) {
	} else if (globalSelectorItem) {
		Toggle(globalSelectorItem,frame,"none");
	}
	globalSelectorItem=item; 
	globalSelectorForceType=forcetype;
	myframe = frame ;
	selectorTimeOut = window.setInterval("Toggle(globalSelectorItem, myframe, globalSelectorForceType)",1000);
	
}

/*
 * Cancel a selectortimeout. The var that references the selectortimeout is selectorTimeOut
 */
function cancelSelectorTimeout() {
	window.clearInterval(selectorTimeOut);
}



function inList(list,item) {
	if (list == '') {
		return false ;
	}
	
	listArray = String(list).split(',') ;
	
	for (var i = 0; i < listArray.length; i++) {
		if (listArray[i] == item) {
			return true ;
		}
	}
	
	return false ;
}


function removeFromList(list,item) {
	if (list == '') {
		return '' ;
	}
	
	newList = [] ;
	listArray = String(list).split(',') ;
	
	for (var i = 0; i < listArray.length; i++) {
		if (listArray[i] != item) {
			newList[newList.length] = listArray[i] ;
		}
	}
	
	return newList.join(',') ;
}


/**
 * Change a style in the Stylesheets of the Document.
 * The Styles have to reside in allstyles. If the style doesn't exist it is added
 * and written into allstyles
 */
var allstyles = [] ;
function changeStyle(name,property,value) {
	// We use the last Stylesheet
	myStylesheet = document.styleSheets[document.styleSheets.length - 1] ;
	
	if (myStylesheet.insertRule) {
		myStylesheet.insertRule(name + '{ ' + property + ':' + value + ' }',myStylesheet.cssRules.length) ;
	} else if (myStylesheet.addRule) {
		myStylesheet.addRule(name,property +':'+value) ;
	}
	
}


function linkControl() {
	
}
