// JavaScript Document
//
// YAAADI v0.1.0 - YetAnotherAjaxAndDomInterface
//
// written by Sebastian Peter Wolbring - except where quoted
//
// DomInterface pseudo class is based on:
// DOMhelp 1.0
// written by Chris Heilmann
// http://www.wait-till-i.com
//
// YAAADI is licensed under The MIT Licence
//
//
// TODO: description of this file
//
//
//
//
// The MIT License
// 
// Copyright (c) 2008 Sebastian Peter Wolbring
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

// call globalFunctions.js in the (x)xhtml document in advance to be able to use the global functions within YAAADI.js

Microtime.mtStart();

// initialise objects
var yDomInterface 				 = new DomInterface();
var yNodeHelper 				 = new NodeHelper();
var yAjaxInterface 				 = new AjaxInterface();
var yAjaxInstanceResponseHandler = new AjaxInstanceResponseHandler();

// initialise vars and arrays
var toLinkAlreadyClicked = false;
var classNodes 			 = new Array();
var idNodes	   			 = new Array();

// collect all nodes with class or id
var allNodes = document.getElementsByTagName('*');
// loop through all nodes and find class and id nodes
classNodes = yNodeHelper.loopThroughAllNodes(allNodes, "class");
idNodes    = yNodeHelper.loopThroughAllNodes(allNodes, "id");

// create a nodeInterface for each idNode and assign the corresponding node - the nodeInterface-var is called like the id name - e.g.:  <div id="someId">  results in the var oSomeId
yNodeHelper.buildNodeVars(idNodes["id"], "id");
// same with class nodes
yNodeHelper.buildNodeVars(classNodes["className"], "class");



	
	/* sendToBox - begin */
	
		if (typeof(oToLink) != "undefined") {
		
			yAjaxInterface.spawnAjaxInstance(0, "sendToBox");
			function setToLink() {
				oToLink.onclick = function() {
					if(toLinkAlreadyClicked == false) {
						var query = this.getAttribute("href").split("?")[1];
						var url = "http://"+window.location.href.split("/")[2]+"/addressee.php?"+query;
						toLinkAlreadyClicked = true;
						return !yAjaxInterface.runAjax(url, "sendToBox");
					} else {
						return false;
					}
				}
			}
			setToLink();
			
		}
		
	/* sendToBox - end */




	/* expand and hide left navigation subpoints - begin */

		function NaviManipulator() {
			// check DOM support when instantiating
			if(!document.getElementById || !document.getElementsByTagName || !document.createTextNode) {return;}

			// properties (accessible by all methods inside this object)
			
			// the following property is set to access public methods within this object by using self.publicmethod - cannot be done by using this.publicmethod
			var self = this;

			// methods
			this.setLeftNaviBandSwitch = function(triggerNode, count){
				triggerNode.firstChild.onclick = function() {
					if(getCookie(("leftNavi" + count)) == 0) {
						var cookieState = getCookie("leftNavi" + count);
						if(cookieState == null) {
							return true;
						} else {
							self.setUnfoldedState(triggerNode, count);
							setCookie(("leftNavi" + count), 1, 10);
							return false;
						}
					} else {
						var cookieState = getCookie("leftNavi" + count);
						if(cookieState == null) {
							return true;
						} else {
							self.setFoldedState(triggerNode, count);
							setCookie(("leftNavi" + count), 0, 10);
							return false;
						}
					}
				}
			}
		


			this.setUnfoldedState = function(triggerNode, count) {
				var mFatherBandSwitch = triggerNode.parentNode;
				var mGrandfatherBandSwitch = triggerNode.parentNode.parentNode;

				window["mAunt" + count] = yDomInterface.closestSibling(mFatherBandSwitch, -1);
				if(window["mAunt" + count]) {
					if(window["mAunt" + count].firstChild.firstChild.nodeType == 3) {
						window["mAunt" + count].firstChild.firstChild.nodeValue = "-";
					}
				}

				mGrandfatherBandSwitch.appendChild(window["mUncle" + count]);
				// return false removes the href onclick target from leftNaviBandSwitch
				return false;
			}
			
			
			this.setFoldedState = function(triggerNode, count) {
				//setCookie(("leftNavi" + count), 0, 10);
				var mFatherBandSwitch = triggerNode.parentNode;
				var mGrandfatherBandSwitch = triggerNode.parentNode.parentNode;

				mAunt = yDomInterface.closestSibling(mFatherBandSwitch, -1);
				if(mAunt) {
					if(mAunt.firstChild.firstChild.nodeType == 3) {
						mAunt.firstChild.firstChild.nodeValue = "+";
					}
				}

				window["mUncle" + count] = yDomInterface.closestSibling(mFatherBandSwitch, 1);
				if(window["mUncle" + count]) {
					mGrandfatherBandSwitch.removeChild(window["mUncle" + count]);
					// return false removes the href onclick target from leftNaviBandSwitch
					return false;
				} else {
					// if there aint an uncle - return true - follows the link (fallback)
					return true;
				}
			}
			
			
		}


		function manipulateNavi(nodeArray) {
			for (i=0; i<nodeArray.length; i++){
				//window["o" + firstCharToUpperCase(idNodes["id"][i])] = yDomInterface.getNodeBy("id", idNodes["id"][i], idNodes["tagName"][i]);
				window["manipulatedNavi_" + i]  = new NaviManipulator();
				window["manipulatedNavi_" + i].setLeftNaviBandSwitch(nodeArray[i], i);
				if(i > 0) {
					 // initially set navi-fold-state
					 if(getCookie(("leftNavi" + i)) != 1) {
					 	setCookie(("leftNavi" + i), 0, 10);
					 }
					 
					 if(getCookie(("leftNavi" + i)) == 0) {
					    //setCookie(("leftNavi" + i), 1, 10);
						window["manipulatedNavi_" + i].setFoldedState(nodeArray[i], i);
					 } else {
					 	window["manipulatedNavi_" + i].setFoldedState(nodeArray[i], i);
					    window["manipulatedNavi_" + i].setUnfoldedState(nodeArray[i], i);
					 }
				} else {
					if (getCookie("myProfileSwitch") == null) {
						setCookie("myProfileSwitch", 1, 10);
						setCookie(("leftNavi" + i), 1, 10);
						window["manipulatedNavi_" + i].setFoldedState(nodeArray[i], i);
						window["manipulatedNavi_" + i].setUnfoldedState(nodeArray[i], i);
					} else {
					
					
						 if(getCookie(("leftNavi" + i)) == 0) {
						    //setCookie(("leftNavi" + i), 1, 10);
							window["manipulatedNavi_" + i].setFoldedState(nodeArray[i], i);
						 } else {
						 	window["manipulatedNavi_" + i].setFoldedState(nodeArray[i], i);
						    window["manipulatedNavi_" + i].setUnfoldedState(nodeArray[i], i);
						 }
					
					
					}
				}
			}
		}


		// push all trigger nodes of the left navigation into an array
		var leftNaviArray = new Array();
		if (typeof(oLeftNaviMyProfileSwitch) != "undefined") {
			leftNaviArray.push(oLeftNaviMyProfileSwitch);
		}
		if (typeof(oLeftNaviMyMusicSwitch) != "undefined") {
			leftNaviArray.push(oLeftNaviMyMusicSwitch);
		}
		for(i=0; i<5; i++) {
			if (typeof(window["oLeftNaviBandSwitch_" + i]) != "undefined") {
				leftNaviArray.push(window["oLeftNaviBandSwitch_" + i]);
			}
		}
		// if there is a navi to manipulate -> do it		
		if(leftNaviArray.length > 0) {
			manipulateNavi(leftNaviArray);
		}

	/* expand and hide left navigation subpoints - end */




	/* bannerCode - begin */
	
		function manipulateBannerCodeOutput(bannerID) {
			if ((typeof(window["o" + bannerID + "link"]) != "undefined") && (typeof(window["o" + bannerID + "code"]) != "undefined")) {
				var codeDiv = window["o" + bannerID + "code"];
				window["o" + bannerID + "code"].parentNode.removeChild(window["o" + bannerID + "code"]);
			
				//yAjaxInterface.spawnAjaxInstance(0, "sendToBox");
				function setLink(link) {
					link.onclick = function() {
						if(typeof(bannerLinkAlreadyClicked) == "undefined") {bannerLinkAlreadyClicked = false;} 

						if(bannerLinkAlreadyClicked == false) {
							// create <div id="newLayerDivFrame"> </div>
							mNewLayerCodeDivFrame = document.createElement("div");
						    mNewLayerCodeDivFrame.setAttribute("id", "newLayerCodeDivFrame");
						    // append <div id="newLayerDivFrame"> </div>  to  <div id="newLayerDivContainer"> </div>
						    oCodeContainerDiv.appendChild(mNewLayerCodeDivFrame);
						
							  // create <div id="newLayerDiv"> </div>
						    mNewLayerCodeDiv = document.createElement("div");
						    mNewLayerCodeDiv.setAttribute("id", "newLayerCodeDiv");
						    // append <div id="newLayerDiv"> </div>  to  <div id="mNewLayerDivFrame"> </div>
						    mNewLayerCodeDivFrame.appendChild(mNewLayerCodeDiv);
						    
						    // create <a href="#">schliessen</a>
						    var mCloseLink = yDomInterface.createLink("#", "schliessen");

						    // assign closing functionality to the close-link -> will remove newLayerDiv
						    mCloseLink.onclick = function() {
								bannerLinkAlreadyClicked = false;
						    	mNewLayerCodeDivFrame.parentNode.removeChild(mNewLayerCodeDivFrame);
						    	return true;
						    }
							mNewLayerCodeDiv.appendChild(codeDiv); 	
						    mNewLayerCodeDiv.appendChild(mCloseLink);
						    bannerLinkAlreadyClicked = true;
							return true;
						}
					}
				}
				setLink(window["o" + bannerID + "link"]);
			}
		}
				
		
		// DO IT: set banner code handlers
		var bannerArray = [8015, 8831, 11032, 14132, 17742, 14158, 17756, 34272, 46860, 70090];

		for (var i = 0; i < bannerArray.length; ++i) {
			var bannerID = bannerArray[i];
			//window["m" + bannerArray[i]] = {'id':bannerArray[i], 'alreadyClicked':false};
			
			manipulateBannerCodeOutput(bannerID);
		}



		
	/* bannerCode - end */








	/* Forum foldout - begin */

	// new Class SubForum
	var SubForum = function(count) {
		var count = count;
		this.setLink = function() {
			var aLink = new Element('a', { 'class': 'foo', href: "#" + count }).update("[zeige Inhalte] &nbsp; ");
			var forumSubHeaderAreaRows = $$('.forumSubHeaderAreaRow' + count);
			var subForumInsertBefore = $('subForumInsertBefore' + count);
			var contents = new Array();
			for(var i=0; i<forumSubHeaderAreaRows.length; i++) {
				contents.push(forumSubHeaderAreaRows[i].remove());
			}
			
			aLink.onclick = function() {
				for(var i=0; i<contents.length; i++) {
					subForumInsertBefore.parentNode.insertBefore(contents[i], subForumInsertBefore);
				}
				aLink.remove();
				return false;
			}
			
			if(typeof(window["oForumSubHeaderAreaTriggerTd" + count]) != "undefined") {
				window["oForumSubHeaderAreaTriggerTd" + count].appendChild(aLink)
			}
		}
	}

	// TODO: set this subForumIdCount dynamically and use it in the following loop as max
	// var subForumIdCount = new Array(0, 1, 2, 3);
	
	var subForumArray = new Array();

	for(var i=0; i<100; i++) {
		if((typeof(window["oForumSubHeaderAreaTriggerTd" + i]) != "undefined") && typeof(oForumHomeTable) != "undefined") {
			subForumArray[i] = new SubForum(i);
			subForumArray[i].setLink();
		}
	}


/*	
	subForumArray[1] = new SubForum(1);
	subForumArray[1].setLink();
	
	subForumArray[2] = new SubForum(2);
	subForumArray[2].setLink();
*/	

	/* Forum foldout - end */
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/* previewElement - begin */
	
	
	
	
	
	
	/* previewElement - end */
	
	
	




	
	/* // only debug code - show all ajax instances:
	var tempAjaxInterfaceArray = yAjaxInterface.getAjaxInstanceArray();
	for(i=0; i<tempAjaxInterfaceArray.length; i++){
		alert(tempAjaxInterfaceArray[i]);
	}
	*/






/************************************************************************************************************
	 _____                  _____       _             __               
	|  __ \                |_   _|     | |           / _|              
	| |  | | ___  _ __ ___   | |  _ __ | |_ ___ _ __| |_ __ _  ___ ___ 
	| |  | |/ _ \| '_ ` _ \  | | | '_ \| __/ _ \ '__|  _/ _` |/ __/ _ \
	| |__| | (_) | | | | | |_| |_| | | | ||  __/ |  | || (_| | (_|  __/
	|_____/ \___/|_| |_| |_|_____|_| |_|\__\___|_|  |_| \__,_|\___\___|

*************************************************************************************************************/



function DomInterface() {
	// check DOM support when instantiating
	if(!document.getElementById || !document.getElementsByTagName || !document.createTextNode) {return;}
	
	// properties (accessible by all methods inside this object)

	// methods

	//	function getElementsByClassName: Written by Jonathan Snook, http://www.snook.ca/jonathan - Add-ons by Robert Nyman, http://www.robertnyman.com - Revised version May 11th 2007
	//  To get all a elements in the document with a "info-links" class:   getElementsByClassName("info-links", "a", document);
	this.getElementsByClassName = function(className, tag, elm){
		var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
		var tag = tag || "*";
		var elm = elm || document;
		var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
		var returnElements = [];
		var current;
		var length = elements.length;
		for(var i=0; i<length; i++){
			current = elements[i];
			if(testClass.test(current.className)){
				returnElements.push(current);
			}	
		}
		return returnElements;
	}


	this.getNodeBy = function(selectorType, selectorName, tagName) {
		if(selectorType == "id") {
			return document.getElementById(selectorName);
		} else if(selectorType == "class") {
			elm = document;
			return getElementsByClassName(selectorName, tagName, elm);
		}
		
		// todo: implement the following...
		//
		// document.getElementsByTagName(name)
	
	}



	this.firstSibling = function(nodeInterface) {
		// selectorType must be id  --- TODO: implement check, if is id node
		var tempNode = nodeInterface.parentNode.firstChild;
		while((tempNode.nodeType != 1) && (tempNode.nextSibling != null)){
			tempNode = tempNode.nextSibling;
		}
		if(tempNode.nodeType == 1) {return tempNode;} else {return false;}
	}	


	this.lastSibling = function(nodeInterface) {
		// selectorType must be id  --- TODO: implement check, if is id node
		var tempNode = nodeInterface.parentNode.lastChild;
		while((tempNode.nodeType != 1) && (tempNode.previousSibling != null)){
			tempNode = tempNode.previousSibling;
		}
		if(tempNode.nodeType == 1) {return tempNode;} else {return false;}
	}


	this.closestSibling = function(nodeInterface, direction) {
		var tempObj;
		if(direction==-1 && nodeInterface.previousSibling!=null) {
			tempObj=nodeInterface.previousSibling;
			while(tempObj.nodeType!=1 && tempObj.previousSibling!=null) {
				 tempObj=tempObj.previousSibling;
			}
		} else if(direction==1 && nodeInterface.nextSibling!=null) {
			tempObj=nodeInterface.nextSibling;
			while(tempObj.nodeType!=1 && tempObj.nextSibling!=null) {
				 tempObj=tempObj.nextSibling;
			}
		}
		if (typeof(tempObj) == "undefined") {return false;}
		return tempObj.nodeType==1?tempObj:false;
	}




	this.createNElement = function(tag, attribute, setAttributeTo) {
		
		var tempObj=document.createElement(tag);
		if (typeof(attribute) != "undefined") {
			if (typeof(setAttributeTo) == "undefined") {var setAttributeTo = ""}
			tempObj.setAttribute(attribute, setAttributeTo);
		}
		return tempObj;
	}





	this.createLink = function(href, text, selectorType, selectorName) {
		if (typeof(selectorType) == "undefined") {selectorType = undefined; selectorName = undefined;}
		if (typeof(selectorName) == "undefined") {selectorType = undefined; selectorName = undefined;}
		
		var tempObj=document.createElement('a');
		tempObj.appendChild(document.createTextNode(text));
		tempObj.setAttribute('href', href);
		
		if ((typeof(selectorType) != "undefined") && (typeof(selectorName) != "undefined")) {
			tempObj.setAttribute(selectorType, selectorName);
		}
		
		return tempObj;
	}



	this.createTextElm = function(tagName, text, selectorType, selectorName) {
		if (typeof(selectorType) == "undefined") {selectorType = undefined; selectorName = undefined;}
		if (typeof(selectorName) == "undefined") {selectorType = undefined; selectorName = undefined;}
		
		//addressDiv.setAttribute("id", "addressesDiv");
		

		
		var tempObj=document.createElement(tagName);
		tempObj.appendChild(document.createTextNode(text));
		
		
		if ((typeof(selectorType) != "undefined") && (typeof(selectorName) != "undefined")) {
			tempObj.setAttribute(selectorType, selectorName);
		}
		
		return tempObj;
	}


	this.getText = function(nodeInterface) {
		if(!nodeInterface.hasChildNodes()) {return false;}
		var reg = /^\s+$/;
		var tempNode = nodeInterface.firstChild;		
		while((tempNode.nodeType != 3) && (tempNode.nextSibling != null) || (reg.test(tempNode.nodeValue))) {
			tempNode=tempNode.nextSibling;
		}
		if(tempNode.nodeType == 3) {return tempNode.nodeValue;} else {return false;}
	}
	

	this.replaceText = function(nodeInterface, text) {
		if(!nodeInterface.hasChildNodes()) {return false;}	
		var reg = /^\s+$/;
		var tempNode = nodeInterface.firstChild;
		while((tempNode.nodeType != 3) && (tempNode.nextSibling != null) || (reg.test(tempNode.nodeValue))) {
			tempNode=tempNode.nextSibling;
		}
		if(tempNode.nodeType == 3) {tempNode.nodeValue = text;} else {return false;}
	}

	
}




/************************************************************************************************************
	 _   _           _      _    _      _                 
	| \ | |         | |    | |  | |    | |                
	|  \| | ___   __| | ___| |__| | ___| |_ __   ___ _ __ 
	| . ` |/ _ \ / _` |/ _ \  __  |/ _ \ | '_ \ / _ \ '__|
	| |\  | (_) | (_| |  __/ |  | |  __/ | |_) |  __/ |   
	|_| \_|\___/ \__,_|\___|_|  |_|\___|_| .__/ \___|_|   
	                                     | |              
	                                     |_|    
*************************************************************************************************************/



function NodeHelper() {
	// With the help of NodeHelper all tags of the html document that have a class or id are collected. After collecting - vars are automatically created for each of those tags and are called "oIdName". At last using the yDomInterface.getNodeBy is used to assign the corresponding nodes to the vars.
	
	// check DOM support when instantiating
	if(!document.getElementById || !document.getElementsByTagName || !document.createTextNode) {return;}


	// properties (accessible by all methods inside this object)
	var resultArray = new Array();
	resultArray["id"] = new Array();
	resultArray["className"] = new Array();
	resultArray["tagName"] = new Array();
	

	// methods

	// allNodes should initially be caught by declaring   var allNodes	= document.getElementsByTagName('*');   - the classOrId-Flag accepts "class" or "id"
	this.loopThroughAllNodes = function(allNodes, classOrId) {

		for (i=0; i<allNodes.length; i++){
			if (classOrId == "class") {
				// if elements has a className value
				if (allNodes[i].className != "") {
					// push result names into an array
					resultArray["className"].push(allNodes[i].className);
					resultArray["tagName"].push(allNodes[i].tagName.toLowerCase());
				}
			} else {  // if (classOrId == "id")
				// if elements has an id value
				if (allNodes[i].id != "") {
					// push result names into an array
					resultArray["id"].push(allNodes[i].id);
					resultArray["tagName"].push(allNodes[i].tagName.toLowerCase());
				}
			}
		}
		// return array with all class or id nodes 	
		return resultArray;
	}
	
	
	// create a var for each idNode and assign the corresponding node - the var is called like the id name - e.g.:  <div id="someId">  results in the var oSomeId
	this.buildNodeVars = function(nodeArray, classOrId) {
		if(classOrId == "class") {
			for (i=0; i<idNodes["id"].length; i++){
				window["o" + firstCharToUpperCase(idNodes["id"][i])] = yDomInterface.getNodeBy("id", idNodes["id"][i], idNodes["tagName"][i]);
			}
		} else {
			
		}
	}


}





/************************************************************************************************************
          _            _____       _             __               
    /\   (_)          |_   _|     | |           / _|              
   /  \   _  __ ___  __ | |  _ __ | |_ ___ _ __| |_ __ _  ___ ___ 
  / /\ \ | |/ _` \ \/ / | | | '_ \| __/ _ \ '__|  _/ _` |/ __/ _ \
 / ____ \| | (_| |>  < _| |_| | | | ||  __/ |  | || (_| | (_|  __/
/_/    \_\ |\__,_/_/\_\_____|_| |_|\__\___|_|  |_| \__,_|\___\___|
        _/ |                                                      
       |__/        
*************************************************************************************************************/



function AjaxInterface() {
	
	// check DOM support when instantiating
	if(!document.getElementById || !document.getElementsByTagName || !document.createTextNode) {return;}

	// properties (accessible by all methods inside this object)
	var ajaxInstanceArray = new Array();
	

	// methods

	this.spawnAjaxInstance = function(i, nameOfInstance){
		ajaxInstanceArray[i] = nameOfInstance;
	}


	this.getAjaxInstanceArray = function() {
		return ajaxInstanceArray;		
	}


	this.runAjax = function(serverScriptFilePath, ajaxInstance, async) {
		// set value for optional param if not set
		if (typeof(async) == "undefined") {async = true;}
		var xmlHttp = this.getHTTPObject();
		if (xmlHttp) {
			// in case of
			xmlHttp.onreadystatechange = function() {
				yAjaxInterface.handleRequestStateChange(xmlHttp, ajaxInstance);
			};
			xmlHttp.open("GET", serverScriptFilePath, async);
			xmlHttp.send(null);
			return true;
		} else {
			return false;
		}
	}


	this.getHTTPObject = function() {
		var xmlHttp = false;
		if (window.XMLHttpRequest) {
			xmlHttp = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			try {
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					xmlHttp = false;
				}
			}
		}
		return xmlHttp;
	}
	

	this.handleRequestStateChange = function(xmlHttp, ajaxInstance) {
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200 || xmlHttp.status == 304) {
	
				// after the readyState is 4
				// - which means that the server has completed sending a response -
				// and the status of the server message is 200 or 304
				// - which both indicate the success of the request to the server -
				// just do something with your updated xmlHttp:

	
				// switch between the different ajax instances
				// the called methods are located in the AjaxInstanceResponseHandler class
	
				switch (ajaxInstance) {
					case "sendToBox":			yAjaxInstanceResponseHandler.sendToBox(xmlHttp);
												break;
												
					default:					alert("oops");
												break;
				}
	
	
				// possible responses:
				// DOMString getAllResponseHeaders();
				// DOMString getResponseHeader(in DOMString header);
				// readonly attribute DOMString responseText;
				// readonly attribute Document responseXML;
				// readonly attribute unsigned short status;
				// readonly attribute DOMString statusText;
	
			}
		}
	}


}




/************************************************************************************************************
          _____ _____                                      _    _                 _ _           
    /\   |_   _|  __ \                                    | |  | |               | | |          
   /  \    | | | |__) |___  ___ _ __   ___  _ __  ___  ___| |__| | __ _ _ __   __| | | ___ _ __ 
  / /\ \   | | |  _  // _ \/ __| '_ \ / _ \| '_ \/ __|/ _ \  __  |/ _` | '_ \ / _` | |/ _ \ '__|
 / ____ \ _| |_| | \ \  __/\__ \ |_) | (_) | | | \__ \  __/ |  | | (_| | | | | (_| | |  __/ |   
/_/    \_\_____|_|  \_\___||___/ .__/ \___/|_| |_|___/\___|_|  |_|\__,_|_| |_|\__,_|_|\___|_|   
                               | |                                                              
                               |_|                               
*************************************************************************************************************/




function AjaxInstanceResponseHandler() {
	
	// check DOM support when instantiating
	if(!document.getElementById || !document.getElementsByTagName || !document.createTextNode) {return;}

	// properies (accessible by all methods inside this object)

	// methods

	this.sendToBox = function(xmlHttp) {
		// create <div id="newLayerDivFrame"> </div>
		mNewLayerDivFrame = document.createElement("div");
	    mNewLayerDivFrame.setAttribute("id", "newLayerDivFrame");
	    // append <div id="newLayerDivFrame"> </div>  to  <div id="newLayerDivContainer"> </div>
	    oNewLayerDivContainer.appendChild(mNewLayerDivFrame);
	
		  // create <div id="newLayerDiv"> </div>
	    mNewLayerDiv = document.createElement("div");
	    mNewLayerDiv.setAttribute("id", "newLayerDiv");
	    // append <div id="newLayerDiv"> </div>  to  <div id="mNewLayerDivFrame"> </div>
	    mNewLayerDivFrame.appendChild(mNewLayerDiv);
	    
	    // create <a href="#">schliessen</a>
	    var mCloseLink = yDomInterface.createLink("#", "schliessen");
	    // assign closing functionality to the close-link -> will remove newLayerDiv
	    mCloseLink.onclick = function() {
			toLinkAlreadyClicked = false;
	    	mNewLayerDivFrame.parentNode.removeChild(mNewLayerDivFrame);
	    	setToLink();
	    	return false;
	    }
	    // append <a href="#">close</a>  to  <div id="newLayerDiv"> </div>
	    mNewLayerDiv.appendChild(mCloseLink);
	    
	    var newlineOne = document.createElement("br");
		mNewLayerDiv.appendChild(newlineOne);
	    
	    // fill 
		var data 		= xmlHttp.responseXML;
		var allFriends 	= data.getElementsByTagName("friend");
		var mFriendLink	= new Array();
		var newline		= new Array();
		
		for(i=0; i<allFriends.length; i++) {
			mFriendLink[i] = yDomInterface.createLink("#", allFriends[i].firstChild.nodeValue, "class", "friendLink");
			mFriendLink[i].setAttribute("name", allFriends[i].firstChild.nodeValue)
			mNewLayerDiv.appendChild(mFriendLink[i]);
			
			newline[i] = document.createElement("br");
			mNewLayerDiv.appendChild(newline[i]);
			
			mFriendLink[i].onclick = function() {
				var friendsName = this.name;
				var reg = /\w/;
				if (oAjaxRecipientField.value.search(reg)) {
					oAjaxRecipientField.value+=stripSpaces(friendsName);
				} else {
					oAjaxRecipientField.value+=", "+stripSpaces(friendsName);	
				}
				return false;
			};
		}
	}


}







// alert(Microtime.mtStop());
