function AjaxObject()
{
	this.noAlerts=0;
	this.activePage = ""; 
	this.wordPopupOpen = false; 
	this.myCallbackDivs = new Array();
	this.currentPage = 1;
	this.sliderName = '';
	this.checkBoxCheck;
	this.formChecker = new Object;
	this.onCompleteFunc = "";
	this.ajax3Started = false;
	this.clicked = '';
	
	function convertParams(JSParams)
	{
		var params = [];
		
		var allParams = JSParams.split("|");
		for (var i = 0; i < allParams.length; i ++)
		{
			var split = allParams[i].split(">");
			if (split[1] != undefined) {
				params[split[0]] = split[1];
				//alert ("set " + split[0] + " = " + split[1]);
			}
		}
		
		return params;
	}
	
	function getNextHighestZindex(obj)
	{
		 var highestIndex = 0;
		 var currentIndex = 0;
		 var elArray = Array();
		 if(obj){ elArray = obj.getElementsByTagName('*'); }else{ elArray = document.getElementsByTagName('*'); }
		 for(var i=0; i < elArray.length; i++){
				if (elArray[i].currentStyle){
					 currentIndex = parseFloat(elArray[i].currentStyle['zIndex']);
				}else if(window.getComputedStyle){
					 currentIndex = parseFloat(document.defaultView.getComputedStyle(elArray[i],null).getPropertyValue('z-index'));
				}
				if(!isNaN(currentIndex) && currentIndex > highestIndex){ highestIndex = currentIndex; }
		 }
		 return(highestIndex+1);
	}
	
	/*-------------------------------
		methodes
	-------------------------------*/
	
	function initAjaxRequest(newRequest)
	{
		if (!newRequest) var newRequest=null;
		try
  		{
  			// Firefox, Opera 8.0+, Safari
  			newRequest = new XMLHttpRequest();
  		}
		catch (e)
  		{
	  		// Internet Explorer
	  		try
 	  	 	{
 	 	  		newRequest = new ActiveXObject("Msxml2.XMLHTTP");
    		}
  			catch (e)
    		{
    			newRequest = new ActiveXObject("Microsoft.XMLHTTP");
    		}
  		}
  	
  		return newRequest;
	}
	
	function storeClick(clickName)
	{
		this.clicked = clickName;
	}
	
	function pageLoad()
	{	
		
		oWidth = $(window).width();
		oHeight = $(window).height();
		
		$("#coverDiv").css("width",oWidth + "px");
		$("#coverDiv").css("height",oHeight + "px");
		$("#coverDiv").css("display","block");
 		$("#coverDiv").css("opacity", 0);
		$("#coverDiv").animate({opacity: 0.7}, 'def');

		oX = ($(window).width()/2) -100;
		oY = ($(window).height()/2) - 150;
		
		$("#loaderMessage").css("left",oX+"px");
		$("#loaderMessage").css("top",oY+"px");
		$("#loaderMessage").css("display","block");
		
		//alert("wot");
		//generalScripts.setTooltip("content::loading...::width::300");
		//alert("yes");
	}
	
	
	function darkenBack(amount)
	{
		if (!amount) amount = 0.7;
		//if (amount != '') amount=amount;
		//else amount=0.7;
		
		oWidth = $(window).width();
		oHeight = $(window).height();
		
	//	coverDiv = document.getElementById('coverDiv');
		 $("#coverDiv").css("width",oWidth + "px");
		 $("#coverDiv").css("height",oHeight + "px");
		 $("#coverDiv").css("display","block");
 		 $("#coverDiv").css("opacity", 0);
		//coverDiv.style.width = oWidth + "px";
	//	coverDiv.style.height = oHeight + "px";
		//coverDiv.style.display = "block"; 
		
		$("#coverDiv").animate({opacity: amount}, 'def');
	}
	
	function clearDarkedBack()
	{

		$("#coverDiv").animate({opacity: 0}, 'def', 'linear', removeDark);

	}
	
	function removeDark()
	{
		 $("#coverDiv").css("display","none");
	
	}
	
	function setPaneWidth(typeName, timesNum)
	{
		$('.' + typeName + '_pane').width($('#' + typeName + '_ShifterContainer').width());
		$('#' +  + typeName + '_ShifterContainer').width($('#' + typeName + '_ShifterContainer').width());
		$('#' +  + typeName + '_Shifter').width(timesNum * $('#' + typeName + '_ShifterContainer').width());
		$('#' +  + typeName + '_ShifterContainer').height($('#' + typeName + '_pane_1').height());
	}
	
	function switchPage(slideName,  dir,maxPage, again, extra)
	{
		
		if (dir=='left'  && !again) this.currentPage++;
		else if (dir=='right') this.currentPage--;
		else 
		{
			this.currentPage=again;
		}
		
		if (dir=='right' || (document.getElementById(slideName+"_pane_"+this.currentPage ) != null && dir=='left' ) )
		{

			var getWidth = $('#' + slideName + "_ShifterContainer").width();
			var maxWidth = $('#' + slideName + "_Shifter").width();	
			var paneWidth = $('.pane').width();	
			var setWidth = 0 - ( (this.currentPage-1) * getWidth);
		//	alert ("getWidth"+getWidth+"|maxWidth"+maxWidth+"|paneWidth"+paneWidth+"|setWidth"+setWidth);

			//alert ('if (setWidth  [' + setWidth +'] <= ( 0 - ( ( maxPage[' + maxPage + '] * paneWidth[' + paneWidth + ']) -paneWidth['+paneWidth+'] ))) | '+  ( 0 - ( (maxPage * paneWidth) -paneWidth) ) );
			
			if (dir=='left' && setWidth >= ( 0 - (maxWidth-paneWidth) ) )
			{
				var newHeight = $('#' + slideName + "_pane_"+this.currentPage).height();
				$('#' + slideName + "_ShifterContainer").animate({height: newHeight}, 20);
				$('#' + slideName + "_Shifter").animate({left: setWidth}, 500);
				
			}
			else if (dir=='right' && setWidth <= 0)
			{
				$('#' + slideName + "_Shifter").animate({left: setWidth}, 500);
				var newHeight = $('#' + slideName + "_pane_"+this.currentPage).height();
				$('#' + slideName + "_ShifterContainer").animate({height: newHeight}, 500);
			}
			if (setWidth <= ( 0 - ( (maxPage * paneWidth) -paneWidth) ) ) 
			{
				document.getElementById(slideName+"_RightInactive").style.display = 'inline';
				document.getElementById(slideName+"_RightActive").style.display = 'none';
			}
			else
			{
				document.getElementById(slideName+"_RightInactive").style.display = 'none';
				document.getElementById(slideName+"_RightActive").style.display = 'inline';
			}
				
			if (setWidth >= 0) 
			{
				document.getElementById(slideName+"_LeftInactive").style.display = 'inline';
				document.getElementById(slideName+"_LeftActive").style.display = 'none';
			}
			else
			{
				document.getElementById(slideName+"_LeftInactive").style.display = 'none';
				document.getElementById(slideName+"_LeftActive").style.display = 'inline';
			}
		}	
		else 
		{
			loadNextSwitch(slideName, this.currentPage, setWidth, maxPage,extra);
		}
		
		
	}
	function loadNextSwitch(slideName, currentPages,setWiddd, maxPaged,extra)
	{
		
		document.getElementById(slideName+"_RightInactive").style.display = 'inline';
		document.getElementById(slideName+"_RightActive").style.display = 'none';
		document.getElementById(slideName+"_LeftInactive").style.display = 'inline';
		document.getElementById(slideName+"_LeftActive").style.display = 'none';
				
		$('#' + slideName+"_pane_"+(currentPages-1)).fadeTo("normal", 0.40);

		xmlHttp = initAjaxRequest();
		xmlHttp.onreadystatechange = switchResponse;
		xmlHttp.open("GET", '?action=giveNextReactions&ajax=1&reactionPage='+currentPages+'&reactionType='+slideName+'&extra='+extra, true);
		xmlHttp.send('');
		sliderName = slideName;
		currentPageNo = currentPages;
		setWidd = setWiddd;
		maxPages = maxPaged
	}
	
	function switchResponse()
	{
		if (xmlHttp.readyState == 4)
		{
			//alert(xmlHttp.responseText);
			var returnObject = eval('(' + xmlHttp.responseText + ')');
			//alert("hoi: "+xmlHttp.responseText);
			
			$('#' + sliderName + "_Shifter").width( currentPageNo * $('#' + sliderName + "_pane_1").width());

			if (document.getElementById(sliderName+"_pane_"+currentPageNo) == null)
			{
				var d = document.getElementById(sliderName + "_Shifter");
				
				var div = document.createElement("DIV");
				div.id = sliderName+"_pane_"+currentPageNo;
				div.className = "pane";
				div.innerHTML = returnObject.content;
				
				d.appendChild(div);		
			}
			$('#' + sliderName+"_pane_"+currentPageNo).width($('#' + sliderName + "_pane_1").width());
			$('#' + sliderName+"_pane_"+(currentPageNo-1)).fadeTo("normal", 1);
			switchPage(sliderName, 'left',maxPages, currentPageNo);
			
			if (returnObject.tooltips)
			{
				generalScripts.registerTooltips(returnObject.tooltips);
			}
		}
		
	}
	
	function stopPageLoad()
	{		
		coverDiv = document.getElementById('coverDiv');
		if (coverDiv)
		{
			coverDiv.parentNode.removeChild(coverDiv);
		}
	}
	
	
	
	function requestPage(file, page, initPage, JSParams) 
	{
		var params = [];
		if (JSParams) params = convertParams(JSParams);
		
		pageLoad();
		if (this.activePage == "") this.activePage = initPage;
		var activePageById = document.getElementById("nav_" + this.activePage)
		if (activePageById) activePageById.className = "";
		var pageById = document.getElementById("nav_" + page);
		if (pageById) pageById.className = "active";
		
		
		this.activePage = page;
		
		if (!params['method'] || params['method'] == "GET")
		{
			params['method'] = "GET";
			params['postData'] = null;
		}
		else if (params['method'] == "POST")
		{
			
			if (!params['postData'] || params['postData'] == "")
			{
				params['postData'] = null;
			
			}
			
			if (params['formID'])
			{
					
				var addPost = getFormAsPost(params['formID']);
				if (params['postData'] == null)
				{
					
					params['postData'] = addPost;
				}
				else
				{
					params['postData'] = params['postData'] + "&" + addPost;
				}
			}
		}
	
		
		xmlHttp = initAjaxRequest();
		xmlHttp.onreadystatechange = responsePage;
		xmlHttp.open(params['method'], file, true);
		if (params['method'] == "POST")
		{
			xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		}
		xmlHttp.send(params['postData']);
	}
	
	function responsePage()
	{
		if (xmlHttp.readyState == 4)
		{			
			var pageObject = eval('(' + xmlHttp.responseText + ')');
			document.getElementById('pageCSS').href = pageObject.cssFile; 
			document.getElementById("content_container").innerHTML = pageObject.content;
			document.getElementById("taskbar").innerHTML = pageObject.taskbar;
			document.getElementById("player").innerHTML = pageObject.player;
			onResizeHandler(document.getElementsByTagName("BODY"));
			stopPageLoad();
			
			
		}
	}
	
	
	function request(file, callback, JSParams, myEvent, initPopup) 
	{
		var params = [];
		if (JSParams) params = convertParams(JSParams);
		
		
		// exceptions for request
		
		var sendRequest = true;
		
		if (params['keycodeExcepts'])
		{
			var codes = params['keycodeExcepts'].split(",");
			for (var i = 0 ; i < codes.length; i++)
			{
				var code = codes[i];
				if (code == myEvent.keyCode) {
					sendRequest = false;
				}
			}
		}
				
		
		
		// start request
		
		if (sendRequest)
		{
			
			if (!params['method'] || params['method'] == "GET")
			{
				params['method'] = "GET";
				params['postData'] = null;
			}
			else if (params['method'] == "POST")
			{
				
				if (!params['postData'] || params['postData'] == "")
				{
					params['postData'] = null;
				}
				
				if (params['formID'])
				{
					var addPost = getFormAsPost(params['formID']);
					if (params['postData'] == null)
					{
						
						params['postData'] = addPost;
					}
					else
					{
						params['postData'] = params['postData'] + "&" + addPost;
					}
				}
			}
			
			if (params['onComplete']) {
				this.onCompleteFunc = params['onComplete'];
			}
			
			xmlHttp = initAjaxRequest();
			xmlHttp.onreadystatechange = response;
			xmlHttp.open(params['method'], file, true);
			if (params['method'] == "POST") xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			
			xmlHttp.send(params['postData']);
			
			
			// check callback(s) / divs
			myInitPopup = initPopup;
			if (callback != '') 
			{
				var callbackArray = callback.split("|");
				
				myDiv = callbackArray;
				myParams = params;
				for (var i = 0 ; i < myDiv.length; i++)
				{
					var loadContent = "<div style='text-align:center;margin:5px;'><img src=\"http://media.edufrysk.com/icons/loader.gif\" /></div>";
					
					if (params['hideOnLoad']) document.getElementById(myDiv[i]).style.display = 'none';
					
					if (params['loadText']) loadContent = params['loadText'];
					
					if (loadContent != "[none]")
					{
						document.getElementById(myDiv[i]).innerHTML = loadContent;
					}
					
					
					if (this.myCallbackDivs[myDiv[i]]) {
						//alert("myCallbackDivs[" + myDiv[i] + "] = " + this.myCallbackDivs[myDiv[i]] + " -> abort()");
						oldRequest = this.myCallbackDivs[myDiv[i]];
						oldRequest.onreadystatechange = function () {};
						oldRequest.abort();
						this.myCallbackDivs[myDiv[i]] = null;
					}
					this.myCallbackDivs[myDiv[i]] = xmlHttp;
				}
			}
			
		}
		else
		{
			//alert("exception interrupted " + callback);
		}
	}
	
	
	function response()
	{
		if (xmlHttp.readyState == 4)
		{
			//alert(xmlHttp.responseText);
			var returnObject = eval('(' + xmlHttp.responseText + ')');
			
			if (returnObject.alerts) giveAlert(returnObject.alerts);
			if ( returnObject.content != '' && returnObject.content != null  && myInitPopup != '' && myInitPopup != undefined) 
			{
				ajaxObject.givePopup('', myInitPopup, true, 'center>1');
				myParams['center'] = true;
			}
			if (myDiv.length == 1)
			{
				
				document.getElementById(myDiv[0]).innerHTML = returnObject.content;
				
				
				if (myParams['center']) 
				{
	
					posLeft =  ($(window).width()/2) -  (document.getElementById(myDiv[0]).offsetWidth/2);
					document.getElementById(myDiv[0]).style.left = posLeft + "px";
				}
				
			}
			else
			{
				for (var i = 0 ; i < myDiv.length; i++)
				{
					document.getElementById(myDiv[i]).innerHTML = returnObject["content"][i]["content"];
					
					if (myParams['center']) 
					{
						posTop = ($(window).height()/2) -  ($('#' + myDiv[i]).height/2);
						posLeft =   ($(window).width()/2) - ($('#' + myDiv[i]).width/2);
						document.getElementById(myDiv[i]).style.top = posTop + "px";
						document.getElementById(myDiv[i]).style.left = posLeft + "px";
					}
				}
			}
			
			if (returnObject.tooltips)
			{
				generalScripts.registerTooltips(returnObject.tooltips);
			}
			
			if (returnObject.focus)
			{
				//alert("jeej " + returnObject.focus);
				$('#' + returnObject.focus).focus();
			}
			
			if (ajaxObject.onCompleteFunc != "") {
				eval(ajaxObject.onCompleteFunc);
			}
			
		}
	}
	
	function makeInitPopup()
	{
		//givePopup('', 'initPopupDiv', true, 'center>1')
		request("?action=giveInitPopup&ajax=1", 'initPopupDiv', '', '', 'initPopupDiv') 
	}
	
	
	function giveAlert (alertText)
	{
		d = document.getElementById("alerts");
		div = document.createElement("DIV");
		div.id = "alert"+ajaxObject.noAlerts;
		div.className = "alert";
		div.style.display = "block";
		d.appendChild(div);		
		div.onclick = function (){ closeAlert("alert"+ajaxObject.noAlerts)}
		
		
		div.innerHTML = alertText+'<div class="alertClose" onclick="javascript: ajaxObject.closeAlert(\''+"alert"+ajaxObject.noAlerts+'\')"></div>';
		
	//	if ($('#' + "alerts").height() > 0) var newheight = $('#' + "alerts").height() + $('#' + "alert"+ajaxObject.noAlerts).height() ;
		//else var newheight = $('#' + "alert"+ajaxObject.noAlerts).height() ;
	//	$('#' + "alerts").animate({height: newheight + "px"}, 200);
		ajaxObject.noAlerts++;
	}
	
	function closeAlert(closeID)
	{
		$('#' + closeID).hide("slow");
	}
	
	function checkChilds(obj,times)
	{
		
		
		var postData = "";
		
	
	//	for (j = 0; j < obj.childNodes.length; j ++)
	//	{
			
			
			postData += checkChildAsForm(obj.childNodes[times]);
			
			if (obj.childNodes[times].childNodes.length > 0) postData += checkChilds(obj.childNodes[times],0);
			
	//	}
		times++;
		if (obj.childNodes.length > times) postData += checkChilds(obj,times);
		return postData;
	}
	
	function getFormAsPost(objName)
	{
		var postData = "";
		
		obj = document.getElementById(objName);
		//postData += checkChild(obj, "den beginne");
		postData += checkChilds(obj,0);
		
		
		
    return postData;
   }
	
	
	function checkChild(node)
	{
		var rtrn = "";
				
		for (i = 0; i < node.childNodes.length; i ++)
		{
			var tag = node.childNodes[i].tagName;
			document.getElementById("traceDiv").innerHTML += "gevonden: " + tag + "<br />";
			document.getElementById("traceDiv").style.display = "block";
				
			if (tag == "INPUT" || tag == "SELECT" || tag == "TEXTAREA") 
			{
				rtrn += checkChildAsForm(node.childNodes[i], node.tagName);
			} 
			else if (tag == "DIV" || tag == "TABLE" || tag == "TR" || tag == "TD" || tag == "TBODY") 
			{
				rtrn += checkChild(node.childNodes[i], node.tagName);
			} 
			else if (tag == undefined) 
			{
				rtrn += "";
			}
		}
		return rtrn;
	}
   
  
  
  
	function checkChildAsForm(node, par)
	{
		var rtrn = "";
				
		if (node.tagName == "INPUT")
		{
			if (node.type == "text" || node.type == "password" ) {
				rtrn += node.name + "=" + node.value + "&";
			}
			if ( node.type == "submit" || node.type == "button") {
				if (ajaxObject.clicked == node.name)
				{
					rtrn += node.name + "=" + node.value + "&";
				}
			}
			if (node.type == "hidden") {
				rtrn += node.name + "=" + node.value + "&";
			}
			
			if (node.type == "checkbox") {
				//alert("checkbox");
				if (node.checked) {
					if (node.name.slice(-2) == "[]") 
					{
						node.name = node.name.slice(0,-2);
						rtrn += node.name + "=" + node.value  + "&";
					}
					else
					{
						rtrn += node.name + "=" + node.value + "&";
					}
				}
			}
			
			if (node.type == "radio") {
				//alert("radio");
				if (node.checked) {
					//alert(node + " " + node.name + " " + node.value);
					rtrn += node.name + "=" + node.value + "&";
				}
			}
		}
		
		if (node.tagName == "SELECT") {
			if (node.multiple == true)
			{
				var selectString = '';
				for (var j = 0; j < node.options.length; j ++) {
					if (node.options[j].selected) {
						selectString +=  node.options[j].value + "|";
					}
				}
				if (selectString != '') rtrn += node.name + "=" + selectString + "&";
			}
			else
			{
				rtrn += node.name + "=" + node.options[node.selectedIndex].value + "&";
			}
		}
			
		if (node.tagName == "TEXTAREA") {
			rtrn += node.name + "=" + node.value + "&";
		}

		return rtrn;
	}

	function StringtoXML(text){
		if (window.ActiveXObject){
			var doc=new ActiveXObject('Microsoft.XMLDOM');
			doc.async='false';
			doc.loadXML(text);
		} else {
			var parser=new DOMParser();
			var doc=parser.parseFromString(text,'text/xml');
		}
		return doc;
	}

	function showPopup(divID)
	{
		div = document.getElementById(divID);
		
		if (!div)
		{
			d = document.getElementsByTagName("BODY")[0];
			div = document.createElement("DIV");
			div.id = divID;
			div.className = "popup";
			div.style.position = "absolute";
			div.style.display = "block";
			d.appendChild(div);		
			div.style.zIndex = getNextHighestZindex();
		}
		else
		{
			div.style.display = "block";
			div.className = "popup";
			div.style.zIndex = getNextHighestZindex();
		}	
		return div;
	}
	
	function showPopupCenter(divID)
	{
		div = document.getElementById(divID);
		
		if (!div)
		{
			d = document.getElementById("topcontainer");
			div = document.createElement("DIV");
			div.id = divID;
			div.className = "popup";
			div.style.position = "absolute";
			div.style.display = "block";
			d.appendChild(div);		
		}
		else
		{
			div.style.display = "block";
			div.className = "popup";
		}	
		return div;
	}
	
	function hidePopup(divID)
	{
		div = document.getElementById(divID);
		div.style.display = "none";
		/*
		if (div)
		{
			div.style.display = "none";
		}
		*/
	}
	
	function giveTranslation(translation, ele)
	{	
		if (this.wordPopupOpen == false)
		{
			div = showPopup("translationDiv");
			
			div.innerHTML = '<div class="translationContent">'+translation+'</div>';
			
			var divLeftPX = ele.clientX +5;
			if ( ( divLeftPX + div.offsetWidth ) > window.outerWidth) divLeftPX -= ( (divLeftPX + div.offsetWidth + 20) - window.outerWidth );
			var divTopPX = ele.clientY - (div.offsetHeight + 20) + $(document).scrollTop() ; ;
			
			div.style.left = divLeftPX + "px";
			div.style.top = divTopPX + "px";
		}
	}
	
	function giveWordPopup()
	{	
		this.wordPopupOpen = true;
		startDrag("translationDiv");
		
	}
	
	function givePopup(ele, popupDiv, skipDrag, JSParams, myEvent)
	{
		
		var params = [];
		if (JSParams) params = convertParams(JSParams);
		if (params['darken']) 
		{
			darkenBack(params['darken']);
		}
		
		if (params['center']) div = showPopupCenter(popupDiv);
		else div = showPopup(popupDiv);
		div.innerHTML = '';
		
		var posTop = 0;
		var posLeft = 0;
		
		// left
		
		if (params['absLeft']) {
			
			posLeft = params['absLeft'];
		} else if (ele != '') {
			var divLeftPX = ele.clientX +5;
			if ( ( divLeftPX + div.offsetWidth ) > window.outerWidth) divLeftPX -= ( (divLeftPX + div.offsetWidth + 20) - window.outerWidth );
			posLeft = divLeftPX;
		}
		
		// top
		
		if (params['absTop']) {
			posTop = params['absTop'];
		} else if (ele != '') {
			var divTopPX = ele.clientY - (div.offsetHeight + 20) ;
			if ( ( divTopPX + div.offsetHeight ) > window.outerHeight) divTopPX -= ( (divTopPX + div.offsetHeight + 20) - window.outerHeight );
			posTop = divTopPX;
		}
		
		// center
		if (params['center']) 
		{
			div.className=div.className+ " centerPopup";
			//posTop = $(window).height()/4 + $(document).scrollTop() ;
			//posLeft =  window.outerWidth / 3;
			posLeft =  $(window).width() / 3;
		}
		
		if (params['connectTo'])
		{
			connectDiv = document.getElementById(params['connectTo']);
			pos = generalScripts.getObjectPosition(params['connectTo']);
			if (!params['lineOut']) params['lineOut'] = 'right';
			if (params['lineOut'] == 'right') {
				posLeft = (pos[0] + connectDiv.offsetWidth);
				posTop = (pos[1]);
			} else if (params['lineOut'] == 'bottom') {
				posLeft = (pos[0]);
				posTop = (pos[1] + connectDiv.offsetHeight);
			} else if (params['lineOut'] == 'top') {
				posLeft = (pos[0]);
				posTop = (pos[1] - connectDiv.offsetHeight);
			} else if (params['lineOut'] == 'left') {
				posLeft = (pos[0] - connectDiv.offsetWidth);
				posTop = (pos[1]);
			} else if (params['lineOut'] == 'bottom-left') {
				posLeft = (pos[0] - div.offsetWidth);
				posTop = (pos[1] + connectDiv.offsetHeight);
			}
		}
		
		// corrections
		
		if (params['corrLeft']) posLeft += parseInt(params['corrLeft']);
		if (params['corrTop']) posTop += parseInt(params['corrTop']);
	
		
		// set position
		//div.style.top = posTop + "px";
		div.style.left = posLeft + "px";
		
		
		
		if (skipDrag != true )startDrag(popupDiv);
		//if (params['mouseOut']) div.onmouseout = closePopup(popupDiv);
		if (params['hover']) $('#' + popupDiv).hover(function(){ /* mouseover */ }, function(){ tester() });
		
	}
	
	function closePopup(popupDiv)
	{
		hidePopup(popupDiv);
	}
	
	function tester()
	{
		alert("tester");
	}
	
	function giveMemoWordPopup(ele)
	{
		div = showPopup("translationDiv");
		div.innerHTML = '';
		var divLeftPX = ele.clientX +5;
		if ( ( divLeftPX + div.offsetWidth ) > window.outerWidth) divLeftPX -= ( (divLeftPX + div.offsetWidth + 20) - window.outerWidth );
		var divTopPX = ele.clientY - (div.offsetHeight + 20) ;
		
		div.style.left = divLeftPX + "px";
		div.style.top = divTopPX + "px";
		
		this.wordPopupOpen = true;	
	}
	
	function closeWordPopup()
	{
		if (this.wordPopupOpen == true)
		{
			this.wordPopupOpen = false;
			hidePopup("translationDiv");
		}
	}
	
	function removeTranslation()
	{
		if (this.wordPopupOpen == false)
		{
			hidePopup("translationDiv");
		}
	}
	function playAudio(surl, target)
	{
		document.getElementById(target).innerHTML="<embed src='"+surl+"' hidden=true autostart=true loop=false>";
	}
	
	function startDrag(targetDiv)
	{
		$(function() {
			$("#"+targetDiv + " > h1").draggable();
		});

	}
	
	function startFlash(width,height,flashMovie,quality,align,play,loop,scale,wmode,devicefont,menu,allowFullScreen,salign,flashvars)
	{
		
		if (AC_FL_RunContent == 0) 
		{
			alert("This page requires AC_RunActiveContent.js.");
		} 
		else 
		{
			AC_FL_RunContent(
				"codebase", "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0",
				"width", width,
				"height", height,
				"src",  flashMovie,
				"quality", quality,
				"pluginspage", "http://www.macromedia.com/go/getflashplayer",
				"align", align,
				"play", play,
				"loop", loop,
				"scale", scale,
				"wmode", wmode,
				"devicefont", devicefont,
				"id", flashMovie,
				"name", flashMovie,
				"menu", menu,
				"allowFullScreen", allowFullScreen,
				"allowScriptAccess","sameDomain",
				"movie",  flashMovie,
				"base", "",
				"salign", salign,
				"flashvars", flashvars
			); //end AC code
		}
		
	}
	
	function flashObject(width,height,flashMovie,quality,align,play,loop,scale,wmode,devicefont,menu,allowFullScreen,salign,flashvars)
	{
		if (AC_FL_RunContent == 0) 
		{
			alert("This page requires AC_RunActiveContent.js.");
		} 
		else 
		{
			AC_FL_RunContent(
				"codebase", "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0",
				"width", width,
				"height", height,
				"src", flashMovie,
				"quality", quality,
				"pluginspage", "http://www.macromedia.com/go/getflashplayer",
				"align", align,
				"play", play,
				"loop", loop,
				"scale", scale,
				"wmode", wmode,
				"devicefont", devicefont,
				"id", flashMovie,
				"name", flashMovie,
				"menu", menu,
				"allowFullScreen", allowFullScreen,
				"allowScriptAccess","sameDomain",
				"movie", flashMovie,
				"salign", salign,
				"flashvars", flashvars
			); //end AC code
		}
	}
	
	function showFeedback(fieldname)
	{
		$(".feedbackSpan").addClass("hidden"); 
		$("#"+fieldname+"span").removeClass("hidden"); 
	}
	this.showFeedback = showFeedback
	
	
	function checkStatusForm(formName, formCheckParam)
	{
	
		var status = "false";
		for (var i in formCheckParam)
		{
			if (formCheckParam[i]=="true") status = "true";
		}

		if (status == "true") 
		{
			$(".button_"+formName).attr("disabled", "true"); 
			if($(".button_"+formName).css('opacity') == 1) 
			{
				$(".button_"+formName).css('opacity', "0.4")
				//$(".button_"+formName).fadeTo("normal", 0.4);
			}
		}
		else 
		{
			$(".button_"+formName).removeAttr("disabled");
//			if($(".button_"+formName).css('opacity') < 1) $(".button_"+formName).fadeTo("normal", 1);
				if($(".button_"+formName).css('opacity') < 1) $(".button_"+formName).css('opacity', "1")

		}
	}
	
	function checkStatusFormAct(formName, formCheckParam)
	{
		checkStatusForm(formName, formCheckParam);
		
	}
	
	function checkFieldResponse()
	{
	
		if (xmlHttp3.readyState == 4)
		{
			ajaxObject.ajax3Started = false;
			var returnObject = eval('(' + xmlHttp3.responseText + ')');
			if (returnObject.status == "true") 
			{
				var returnDivInfo = document.getElementById(fieldNameGive+"span");
				returnDivInfo.innerHTML =  returnObject.content;
				$("#"+fieldNameGive).addClass("error");
				$("#"+fieldNameGive).removeClass("success");
				/*
				var returnDiv = document.getElementById("feedback_error_"+fieldNameGive);
				var returnDivCorrect = document.getElementById("feedback_correct_"+fieldNameGive);
				var returnDivInfo = document.getElementById("feedback_info_"+fieldNameGive);
				returnDiv.style.display = "block";
				returnDivCorrect.style.display = "none";
				returnDivInfo.style.display = "none";
				returnDiv.innerHTML = returnObject.content;
				*/
			}
			else 
			{
				var returnDivInfo = document.getElementById(fieldNameGive+"span");
				returnDivInfo.innerHTML =  returnObject.content;
				$("#"+fieldNameGive).removeClass("error");
				$("#"+fieldNameGive).addClass("success");
				/*
				var returnDiv = document.getElementById("feedback_error_"+fieldNameGive);
				var returnDivCorrect = document.getElementById("feedback_correct_"+fieldNameGive);
				var returnDivInfo = document.getElementById("feedback_info_"+fieldNameGive);
				returnDivCorrect.style.display = "block";
				returnDiv.style.display = "none";
				returnDivInfo.style.display = "none";
				returnDivCorrect.innerHTML = returnObject.content;
				*/
				var saveField = new Object;
				
				saveField = ajaxObject.formChecker;
				
				saveField[fieldNameGive] = "false";
				ajaxObject.checkStatusFormAct(formNameGive,saveField);
			}
		}	
		
	}
	
	function checkField(fieldName, formName, type, value, rules, feedbackTextsSource, showAlways)
	{
	
	//	alert("fieldName: "+fieldName + " | formName: " + formName+ " | type: " +  type+ " | value:" +  value+ " | rules:" +  rules+ " | feedbackTextsSource: " +  feedbackTextsSource);
		var allRulesSource = rules.split("|");
		var allRules = [];
		var countAllRules = 0;
		for (var i = 0; i < allRulesSource.length; i ++)
		{
			
			var split = allRulesSource[i].split(">");
			
			allRules[split[0]] = split[1];
			countAllRules++;
		}
		var feedbackTextsSplit = feedbackTextsSource.split("|");
		var feedbackTexts = [];
		for (var i = 0; i < feedbackTextsSplit.length; i ++)
		{
			
			var split2 = feedbackTextsSplit[i].split(">");
			
			feedbackTexts[split2[0]] = URLDecode(split2[1]);
		}
		
		var error = "";
		var info = "";
		
		for (var i=0 ; i < countAllRules ; i++)
		{
			switch (type)
			{
				case 'hidden':
					break;
				case 'captcha':
					if (allRules['required'] && value.length == 0) 
					{
						//error = feedbackTexts['isRequired'];
						if (this.ajax3Started == true) 
						{
							xmlHttp3.abort(); 
							this.ajax3Started = false;
						}
						info = feedbackTexts['isRequired'];
						break;
					}
					break;
				case 'text':
					if (allRules['required'] && value.length == 0) 
					{
						//error = feedbackTexts['isRequired'];
						if (this.ajax3Started == true) 
						{
							xmlHttp3.abort(); 
							this.ajax3Started = false;
						}
						info = feedbackTexts['isRequired'];
						break;
					}
					else if (allRules['min'] && value.length < allRules['min'] && value.length > 0) 
					{
						error = feedbackTexts['errorInputMin'];
						if (this.ajax3Started == true) 
						{
							xmlHttp3.abort(); 
							this.ajax3Started = false;
						}
						break;
					}
					else if (allRules['max'] && value.length > allRules['max']) 
					{
						error = feedbackTexts['errorInputMax'];
						break;
					}
					else if (allRules['mail'] && value.length > 0) 
					{
						if (this.ajax3Started == true) 
						{
							xmlHttp3.abort(); 
							this.ajax3Started = false;
						}
						var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
						if (filter.test(value))
						{
						}
						else
						{
							error = feedbackTexts['mailNotValid'];
						}
						break;
					}
					else if (allRules['value'] && value != allRules['value']) 
					{
						error = feedbackTexts['errorInputValue'];
						break;
					}
					else if (allRules['action'] && value != '') 
					{	
						if (this.ajax3Started == true) 
						{
							xmlHttp3.abort(); 
							this.ajax3Started = false;
						}
						info = feedbackTexts['action'];
						xmlHttp3 = initAjaxRequest();
						this.ajax3Started = true;
						xmlHttp3.onreadystatechange = checkFieldResponse;
						xmlHttp3.open("GET", '?action='+allRules['action']+'&value='+value+'&ajax=1', true);
						fieldNameGive = fieldName;
						formNameGive = formName;
						xmlHttp3.send('');
						break;
					}
					break;
				case 'password':
					if (allRules['required'] && value.length == 0) 
					{
						//error = feedbackTexts['isRequired'];
						//xmlHttp3.abort(); 
						info = feedbackTexts['isRequired'];
						break;
					}
					else if (allRules['min'] && value.length < allRules['min'] && value.length > 0) 
					{
						error = feedbackTexts['errorInputMin'];
						if (this.ajax3Started == true) 
						{
							xmlHttp3.abort(); 
							this.ajax3Started = false;
						}
						break;
					}
					else if (allRules['max'] && value.length > allRules['max']) 
					{
						error = feedbackTexts['errorInputMax'];
						break;
					}
					else if (allRules['value'] && value != allRules['value']) 
					{
						error = feedbackTexts['errorInputValue'];
						break;
					}
					break;
				case 'radio':
					break;
				case 'textarea':
					if (allRules['required'] && value.length == 0) error = feedbackTexts['isRequired'];
					else if (allRules['min'] && value.length < allRules['min'] && value.length > 0) error = feedbackTexts['errorInputMin'];
					else if (allRules['max'] && value.length > allRules['max']) error = feedbackTexts['errorInputMax'];
					else if (allRules['value'] && value != allRules['value']) error = feedbackTexts['errorInputValue'];
					else if (allRules['action'] && $value != '') 
					{
						
						info = feedbackTexts['processingInput'];
						var	processAction= initAjaxRequest();
						processAction.onreadystatechange = checkFieldResponse;
						processAction.open("GET", '?action='+allRules['action']+'&ajax=1', true);
						fieldNameGive = formName;
						formCheckerGive = this.formCheckerGive;
						processAction.send('');
						/*
						$actionData = $this->vars->get['dataManager']->getAction($rule['action'], 'name');
						
						$actionOutput =  $this->vars->get['actionManager']->processAction(array('action' => $actionData) );
						
						if ($actionOutput) $error = $actionOutput['content'];
						*/					
					}
					break;
				case 'select':
					if (allRules['value'] && value != allRules['value']) error = feedbackTexts['errorSelectValue'];
					break;
				case 'checkbox':
					if (allRules['checked'] == undefined && value != allRules['checked']) error = feedbackTexts['errorCheckbox']; 
					break;
			}
		}
		
		var saveField = new Object;
		saveField = this.formChecker;
		
		if (error != "" || info != '') 
		{
			saveField[fieldName] = "true";
		}
		else
		{
			saveField[fieldName] = "false";
		}
		checkStatusForm(formName,saveField);
		if (info != '') 
		{
			if (showAlways == 1) $("#"+fieldName+"span").slideDown();
			else $("#"+fieldName+"span").slideUp();
			$("#"+fieldName).removeClass("error");
			$("#"+fieldName).removeClass("success");
			/*
			var returnDiv = document.getElementById("feedback_error_"+fieldName);
			var returnDivCorrect = document.getElementById("feedback_correct_"+fieldName);
			var returnDivInfo = document.getElementById("feedback_info_"+fieldName);
			returnDivInfo.style.display = "block";
			returnDivCorrect.style.display = "none";
			returnDiv.style.display = "none";
			returnDivInfo.innerHTML = info;
			*/
		}
		else if (error != '') 
		{
			var returnDivInfo = document.getElementById(fieldName+"span");
			returnDivInfo.innerHTML = error;
			$("#"+fieldName+"span").slideDown();
			$("#"+fieldName).addClass("error");
			$("#"+fieldName).removeClass("success");
			/*
			var returnDiv = document.getElementById("feedback_error_"+fieldName);
			var returnDivCorrect = document.getElementById("feedback_correct_"+fieldName);
			var returnDivInfo = document.getElementById("feedback_info_"+fieldName);
			returnDiv.style.display = "block";
			returnDivCorrect.style.display = "none";
			returnDivInfo.style.display = "none";
			returnDiv.innerHTML = error;
			*/
		}
		else 
		{
			if (showAlways == 1) $("#"+fieldName+"span").slideDown();
			else $("#"+fieldName+"span").slideUp();
			$("#"+fieldName).removeClass("error");
			$("#"+fieldName).addClass("success");
			/*
			var returnDiv = document.getElementById("feedback_error_"+fieldName);
			var returnDivCorrect = document.getElementById("feedback_correct_"+fieldName);
			var returnDivInfo = document.getElementById("feedback_info_"+fieldName);
			returnDivCorrect.style.display = "block";
			returnDiv.style.display = "none";
			returnDivInfo.style.display = "none";
			returnDivCorrect.innerHTML = feedbackTexts['ok'];
			*/
		}
		
			
	}
	
	function checkSentenceDictee(id, targetDiv, sentenceNum)
	{
		
		var loadContent = "<img src=\"http://media.edufrysk.com/icons/loader.gif\" />";
		
		document.getElementById(targetDiv).innerHTML = loadContent;
		
		var sentence= document.getElementById(id).value
		xmlHttp = initAjaxRequest();

		xmlHttp.onreadystatechange = checkSentenceDicteeResponse;
		

		xmlHttp.open("POST", '?action=checkSentenceNow&contentOnly=1&currentSentence='+sentenceNum, true);
		myTargetDiv = targetDiv;
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		
		xmlHttp.send('sentence=' + sentence);
	}
	
	function checkSentenceDicteeResponse()
	{
		if (xmlHttp.readyState == 4)
		{
				
			document.getElementById(myTargetDiv).innerHTML = xmlHttp.responseText;
		}
		
	}
	

	
	function URLDecode(url) //function decode URL
{
// Replace + with ' '
// Replace %xx with equivalent character
// Put [ERROR] in output if %xx is invalid.
var HEXCHARS = "0123456789ABCDEFabcdef";
var encoded = url;
var plaintext = "";
var i = 0;
while (i < encoded.length) {
var ch = encoded.charAt(i);
if (ch == "+") {
plaintext += " ";
i++;
} else if (ch == "%") {
if (i < (encoded.length-2)
&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
plaintext += unescape( encoded.substr(i,3) );
i += 3;
} else {
alert( 'Bad escape combination near ...' + encoded.substr(i) );
plaintext += "%[ERROR]";
i++;
}
} else {
plaintext += ch;
i++;
}
} // while

return plaintext;
}; 
	/*-------------------------------
		properties
	-------------------------------*/
	
	
	// public methodes
	this.clearDarkedBack = clearDarkedBack;
	this.storeClick = storeClick
	this.checkSentenceDictee = checkSentenceDictee;
	this.darkenBack = darkenBack;
	this.checkStatusFormAct = checkStatusFormAct;
	this.checkField = checkField;
	this.makeInitPopup = makeInitPopup;
	this.setPaneWidth = setPaneWidth;
	this.switchPage = switchPage;
	this.giveTranslation = giveTranslation;
	this.removeTranslation = removeTranslation;
	this.request = request;
	this.closeWordPopup = closeWordPopup;
	this.giveWordPopup = giveWordPopup;
	this.givePopup = givePopup;
	this.showPopup = showPopup;
	this.closePopup = closePopup;
	this.giveMemoWordPopup = giveMemoWordPopup;
	this.requestPage = requestPage;
	this.StringtoXML = StringtoXML;
	this.playAudio = playAudio;
	this.startFlash = startFlash;
	this.flashObject = flashObject;
	this.pageLoad = pageLoad;
	this.closeAlert = closeAlert;
	this.giveAlert = giveAlert;
	
}

