// global Variables
var currentTheme = "opening";
var currentTransparency = "enabled";

function adjustBackground(){
	for(var i=0; document.getElementsByTagName('img')[i]; i++){
		if(document.getElementsByTagName('img')[i].className == "backgroundimage"){
			if(navigator.appName == "Microsoft Internet Explorer"){
				document.getElementsByTagName('img')[i].style.width = document.body.clientWidth; 
				document.getElementsByTagName('img')[i].style.height = document.body.clientHeight; 

				document.getElementsByTagName('img')[i].parentNode.style.width = document.body.clientWidth; 
				document.getElementsByTagName('img')[i].parentNode.style.height = document.body.clientHeight; 
			}else{
				document.getElementsByTagName('img')[i].style.width = window.innerWidth; 
				document.getElementsByTagName('img')[i].style.height = window.innerHeight; 

				document.getElementsByTagName('img')[i].parentNode.style.width = window.innerWidth; 
				document.getElementsByTagName('img')[i].parentNode.style.height = window.innerHeight; 
			}
		}
	}
}

function adjustWindows(){
	var i=0;
	var currentId;
	var currentElement = document.getElementsByTagName("div")[i];
	while(currentElement != 'undefined' && currentElement != undefined){
		currentId = currentElement.id.split('_')[1];
		if(currentId == "wrapper"){
			if(parseInt(currentElement.style.top) < 0){
				currentElement.style.top = 0;
			}
			if(parseInt(currentElement.style.left) < 0){
				currentElement.style.left = 0;
			}
			if(navigator.appName == "Microsoft Internet Explorer"){
				if(currentElement.firstChild.className == "standardwindow_420x260"){
					if(parseInt(currentElement.style.left) > document.body.clientWidth - 422){
						currentElement.style.left = document.body.clientWidth - 422;
					}
					if(parseInt(currentElement.style.top) > document.body.clientHeight - 263){
						currentElement.style.top = document.body.clientHeight - 263;
					}
				} else {
					if(parseInt(currentElement.style.left) > document.body.clientWidth - 242){
						currentElement.style.left = document.body.clientWidth - 242;
					}
					if(parseInt(currentElement.style.top) > document.body.clientHeight - 203){
						currentElement.style.top = document.body.clientHeight - 203;
					}
				}
			}
			else{
				if(currentElement.firstChild.className == "standardwindow_420x260"){
					if(parseInt(currentElement.style.left) > window.innerWidth - 422){
						currentElement.style.left = window.innerWidth - 422;
					}
					if(parseInt(currentElement.style.top) > window.innerHeight - 263){
						currentElement.style.top = window.innerHeight - 263;
					}
				} else {
					if(parseInt(currentElement.style.left) > window.innerWidth - 242){
						currentElement.style.left = window.innerWidth - 242;
					}
					if(parseInt(currentElement.style.top) > window.innerHeight - 203){
						currentElement.style.top = window.innerHeight - 203;
					}
				}
			}
		}
		i++;
		currentElement = document.getElementsByTagName("div")[i];
	}
}







	/* 
	 *	Description of disableHighlighting()
	 *
	 *  This function disables highlighting on this page. This is necessary 
	 *	because the user has to dubble-click and drag the mouse while 
	 *	holding textlines. That causes the text to be selected and looks 
	 *	like an ugly flicker-effekt.
	 *	
	*/
	function disableHighlighting(){
		/***********************************************
		* Disable select-text script- © Dynamic Drive (www.dynamicdrive.com)
		* This notice MUST stay intact for legal use
		* Visit http://www.dynamicdrive.com/ for full source code
		***********************************************/
	
		//form tags to omit in NS6+:
		var omitformtags=["input", "textarea", "select"]
		
		omitformtags=omitformtags.join("|")
		
		function disableselect(e){
			if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
			return false
		}
		
		function reEnable(){
			return true
		}
		
		if (typeof document.onselectstart!="undefined")
			document.onselectstart=new Function ("return false")
		else{
			document.onmousedown=disableselect
			document.onmouseup=reEnable
		}
	}

	/* 
	 *	Description of disableHighlighting()
	 *
	 *  This function disables highlighting on this page. This is necessary 
	 *	because the user has to dubble-click and drag the mouse while 
	 *	holding textlines. That causes the text to be selected and looks 
	 *	like an ugly flicker-effekt.
	 *	
	*/
	function disablehighlightingforframe(frameId) {
		/***********************************************
		* Disable select-text script- © Dynamic Drive (www.dynamicdrive.com)
		* This notice MUST stay intact for legal use
		* Visit http://www.dynamicdrive.com/ for full source code
		***********************************************/
		
		//ADJUSTED!
	
		//form tags to omit in NS6+:
		var omitformtags=["input", "textarea", "select"]
		
		omitformtags=omitformtags.join("|")
		
		function disableselect(e){
			if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
			return false
		}
		
		function reEnable(){
			return true
		}
		
		if (navigator.appName == "Microsoft Internet Explorer") {
			if (typeof document.onselectstart!="undefined")
				top.document.frames[frameId].document.onselectstart=new Function ("return false")
			else {
				top.document.frames[frameId].document.onmousedown=disableselect
				top.document.frames[frameId].document.onmouseup=reEnable
			}
		} else {
			if (typeof document.onselectstart!="undefined")
				top.document.getElementById(frameId).contentDocument.onselectstart=new Function ("return false")
			else {
				top.document.getElementById(frameId).contentDocument.onmousedown=disableselect
				top.document.getElementById(frameId).contentDocument.onmouseup=reEnable
			}
		}		
	}
	
	
	/* 
	 *	Description of getMaxZIndexPlus(number)
	 *
	 *	@param number	number that is added to the current 
	 *					maximum to get a new maximum. (a 
	 *					little bit unnecessary because it 
	 *					is always called with 1)
	 *
	 *  This function searches for the maximum z-index from 
	 *	the style-attributes of all existing chatwindows 
	 *	and returns the maximum + the argument.
	 *
	*/
	function getMaxZIndexPlus(number){
		var maxZ = 0;
  		var n = 0;
		var temp;
		number = parseInt(number);
		
		while(document.getElementsByTagName('div')[n]){
			var completeId = document.getElementsByTagName('div')[n].id;
			if(completeId.split("_")[1] == "wrapper" && completeId.split("_")[0] != "dragimage"){
				temp = parseInt(document.getElementsByTagName('div')[n].style.zIndex);
		  		if (temp > maxZ){
		  			maxZ = temp;
		  		}
			}
			n++;
  		}
  		
		maxZ = maxZ + number;
		return maxZ;		
	}



	/* 
	 *	Description of maximizeMovableZIndex(targetBuddy)
	 *
	 *	@param targetBuddy		owner of the accordent chatWindow.
	 *							
	 *  This function sets the z-index of the accordant chatWindow 
	 *	1 point higher than the current maximum.
	 *
	*/
	function maximizeMovableZIndex(targetBuddy){
		if(document.getElementById(targetBuddy)){
			document.getElementById(targetBuddy).style.zIndex = getMaxZIndexPlus(1);
		}
	}

	
	//doesn't work, apparently zIndex of image is not taken into account!
	function maximizeMovableZIndexInFrame(targetBuddy, localFrameId){
		if (navigator.appName == "Microsoft Internet Explorer") {
			if(top.document.frames[frameId].document.getElementById(targetBuddy)){
				top.document.frames[frameId].document.getElementById(targetBuddy).style.zIndex = 99999;
			}
		} else {
			if(top.document.getElementById(localFrameId).contentDocument.getElementById(targetBuddy)){
				top.document.getElementById(localFrameId).contentDocument.getElementById(targetBuddy).style.zIndex = 99999;
			}
		}	
		
	}

