// = infobox ==========
/*
// Bubblehelp infoboxes, (C) 2002 Klaus Knopper <infobox@knopper.net>
// You can copy/modify and distribute this code under the conditions
// of the GNU GENERAL PUBLIC LICENSE Version 2.
*/
var IWIDTH=250;      // Tip box width
var ns4;             // Are we using Netscape4?
var ie4;             // Are we using Internet Explorer Version 4?
var ie5;             // Are we using Internet Explorer Version 5 and up?
var kon;             // Are we using KDE Konqueror?
var x,y,winW,winH;   // Current help position and main window size
var idiv=null;       // Pointer to infodiv container
var px="px";         // position suffix with "px" in some cases
var iMousoverWidth;  // Width of mousovers content frame
var iMousoverHeight; // Height of mousovers content frame
var xOffset = 0;
var yOffset = 0;
var xScroll = 0;
var yScroll = 0;
var name='infodiv';

function nsfix() {setTimeout("window.onresize = rebrowse", 2000);}

function rebrowse() {window.location.reload();}

function hascss() {return gettip(name)?true:false }

function setSize (_iMousoverWidth, _iMousoverHeight) {
	iMousoverWidth  = _iMousoverWidth;
	iMousoverHeight = _iMousoverHeight;
}

function infoinit() {
 //setSize (_iMousoverWidth, _iMousoverHeight);

 ns4=(document.layers)?true:false, ie4=(document.all)?true:false;
 ie5=((ie4)&&((navigator.userAgent.indexOf('MSIE 5')>0)||(navigator.userAgent.indexOf('MSIE 6')>0)))?true:false;
 kon=(navigator.userAgent.indexOf('konqueror')>0)?true:false;
 x=0;y=0;
 //winW=screen.width;
 //winH=screen.height;

 idiv=null;
 document.onmousemove = mousemove;
 if(ns4&&document.captureEvents) document.captureEvents(Event.MOUSEMOVE);
 // Workaround for just another netscape bug: Fix browser confusion on resize
 // obviously conqueror has a similar problem :-(
 if(ns4||kon){ nsfix() }
 if(ns4) { px=""; }
}

function untip(){
 if(idiv) idiv.visibility=ns4?"hide":"hidden";
 idiv=null;
}

function gettip(name) {
  return (document.layers&&document.layers[name])?document.layers[name]:(document.all&&document.all[name]&&document.all[name].style)?document.all[name].style:document[name]?document[name]:(document.getElementById(name)?document.getElementById(name).style:0);
}

// Prepare tip boxes, but don't show them yet
function maketip(name,title,text){
 if(hascss()) document.write('<div id="'+name+'" name="'+name+'" style="position:absolute; visibility:hidden; z-index:20; top:0'+px+'; left:0'+px+';"><table width='+IWIDTH+' border=0 cellpadding=2 cellspacing=0 bgcolor="#333399"><tr><td class="tiptd"><table width="100%" border=0 cellpadding=0 cellspacing=0><tr><th><span class="ptt"><b><font color="#FFFFFF">'+title+'</font></b></span></th></tr></table><table width="100%" border=0 cellpadding=2 cellspacing=0 bgcolor="#CCCCFF"><tr><td><span class="pst"><font color="#000000">'+text+'</font></span></td></tr></table></td></tr></table></div>'+"\n");
}

function tip(content, name) {
	if (!name) name = 'infodiv';
	getLayer(name).innerHTML = '<table bgcolor="#cccccc" cellspacing="1" cellpadding="2"><tr><td bgcolor="#eeeeee" nowrap="nowrap">'+content+'</td></tr></table>';
	iMousoverWidth = getLayer(name).offsetWidth;
	iMousoverHeight = getLayer(name).offsetHeight;
 if (self.innerHeight) { // all except Explorer
         winW = self.innerWidth;
         winH = self.innerHeight;
 } else if (document.documentElement && document.documentElement.clientHeight) {
         // Explorer 6 Strict Mode
         winW = document.documentElement.clientWidth;
         winH = document.documentElement.clientHeight;
 } else if (document.body) { // other Explorers
         winW = document.body.clientWidth;
         winH = document.body.clientHeight;
 }
 
 	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		yScroll = window.pageYOffset;
		xScroll = window.pageXOffset;
	} else if( document.documentElement && (typeof(document.documentElement.scrollLeft)=='number')) {
		//IE6 standards compliant mode
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if( document.body && (typeof(document.body.scrollLeft)=='number')) {
		//DOM compliant
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}
	yOffset = y - yScroll;
	xOffset = x - xScroll;
	
 if (!winW) {
   winW=800;
   winH=600;
 }
 winW-=10;
 winH-=10;
 

 if(hascss()){
  if(idiv) untip();
  idiv=gettip(name);
  if (idiv) {
   //winW=(window.innerWidth)? window.innerWidth+window.pageXOffset-16:document.body.offsetWidth-20;
   //winH=(window.innerHeight)?window.innerHeight+window.pageYOffset  :document.body.offsetHeight;
   if(x<=0||y<=0) { // konqueror can't get mouse position
    x=(winW-IWIDTH)/2+xOffset; 
	y=(winH-50)/2+yOffset; // middle of window
   }
   showtip();
   return true;
  }
  return false;
 }
}

function showtip() {
  idiv.left=(((xOffset+iMousoverWidth)<winW)?x+12:x-iMousoverWidth-3)+px;
  idiv.top=(((yOffset+iMousoverHeight)<winH)?y+12:y-iMousoverHeight-3)+px;

  idiv.visibility=ns4?"show":"visible";
  window.status="idiv="+idiv+"X:"+(idiv.left?idiv.left:"NAN")+", Y:"+(idiv.top?idiv.top:"NAN")+", x:"+x+", y:"+y;
}

function mousemove(e){
try {
 if(e)   {x=e.pageX?e.pageX:e.clientX?e.clientX:0; y=e.pageY?e.pageY:e.clientY?e.clientY:0;}
 else if(event) {x=event.clientX; y=event.clientY;}
 else {x=0; y=0;}
} catch (e) {
// do nothing
}

 if (self.screen.pixelDepth) {
   //Mozilla 1.6        Safari 1.0        Opera 7.50        Netscape
 } else {
   //Explorer 5 Windows        Explorer 6 Windows        Explorer 5.2 Mac
   //alert(document.body.scrollTop + " " + document.documentElement.scrollTop);
    x+=xScroll;
    y+=yScroll;
 }

 /*if((ie4||ie5) && document.documentElement) {// Workaround for scroll offset of IE
    x+=document.body.scrollLeft;
    y+=document.body.scrollTop;
 }*/
 if(idiv) showtip();
}

// Initialize after loading the page
//window.onload=infoinit;

// EOF infobox.js


// = PHPLiveX ========================
//YAHOO.namespace("example.container");

var PHPLiveXOutput = '';
function PHPLiveX_reload(element) {
	document.getElementById(element).innerHTML = PHPLiveXOutput;
	YAHOO.example.container.panel1 = new YAHOO.widget.Panel(element, {
		//constraintoviewport:true,
		effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.25}
	});
	YAHOO.example.container.panel1.render();
	YAHOO.example.container.panel1.show();
}

function PHPLiveX(type, target, mode, preload, method) {
	this.TYPE = type;
	this.MODE = mode;
	this.TARGET = target;
	this.PRELOAD = preload;
	this.METHOD = method;
	this.output = '';
	this.VIEW_STYLE = 'block';
	
	this.onStartLoading = '';
	this.onFinishLoading = '';
	this.funcArgs='';
}

PHPLiveX.prototype.outputAnimate = function(output) {
	if (!this.TARGET) return;
	var oTarget = document.getElementById(this.TARGET);
	var oTargetContainer = document.getElementById(this.TARGET+'_container');
	oTarget.style.zIndex = 10;
	oTarget.innerHTML = output;
	if (oTargetContainer) {
		oTargetContainer.style.visibility = "visible";
		oTargetContainer.style.display='block';
	} else {
		oTarget.style.visibility = "visible";
		oTarget.style.display='block';
	}
	return;

	oTarget.style.visibility = "hidden";
	oTarget.innerHTML = output;

	YAHOO.example.container.overlay1 = new YAHOO.widget.Overlay(this.TARGET, {
	//var overlay1 = new YAHOO.widget.Overlay(this.TARGET, {
		effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5}
	});

	oTarget.style.overlay = false;
	YAHOO.example.container.overlay1.render();
	YAHOO.example.container.overlay1.show();
	//overlay1.render();
	//overlay1.show();
	oTarget.style.position = "relative";
	return true;
}

PHPLiveX.prototype.outputNew = function(output) {
	return this.outputAnimate(output);
	var oTarget = document.getElementById(this.TARGET);
	oTarget.style.zIndex = 15;

	oTarget.style.visibility = "hidden";
	oTarget.innerHTML = output;
	//YAHOO.example.container.panel1 = new YAHOO.widget.Panel(this.TARGET, {
	var panel1 = new YAHOO.widget.Panel(this.TARGET, {
		//constraintoviewport:true,
		effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.25}
	});
	//YAHOO.example.container.panel1.render();
	//YAHOO.example.container.panel1.show();
	panel1.render();
	panel1.show();
	oTarget.style.zIndex = 15;
}

PHPLiveX.prototype.GetSpecialChars = function(str){
//return unescape(str);
return str;
}
PHPLiveX.prototype.EscapeSpecialChars = function(str){
return str;
}
PHPLiveX.prototype.ShowError = function(errorMsg){
	if(errorMsg != "") {
		alert('PHPLiveX Error: '+errorMsg);
	return false;
		} else {
	return true;
}
}
PHPLiveX.prototype.GetXmlHttp = function() {
	objXmlHttp = false;
	if (window.XMLHttpRequest) {
		objXmlHttp = new XMLHttpRequest();
		if (objXmlHttp.overrideMimeType) {
			//objXmlHttp.overrideMimeType('text/xml');
			objXmlHttp.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) {
		try {
			objXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				objXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	
	if (!objXmlHttp) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	return objXmlHttp;
}

PHPLiveX.prototype.CreatePreloading = function() {
	if (this.PRELOAD!=null) {
		showLayer(this.PRELOAD);
	}
	if (this.onStartLoading) {
		try {
			eval(this.onStartLoading);
		} catch(e){
			//alert(e+"\n\n"+this.onStartLoading);
		}
	}
	this.onStartLoading = '';
}

PHPLiveX.prototype.ClearPreloading = function() {
	if (this.PRELOAD!=null) {
		hideLayer(this.PRELOAD);
	}
	if (this.onFinishLoading) {
		try {
			eval(this.onFinishLoading);
		} catch (e) {
			alert(e+"\n\nonFinishLoading:"+this.onFinishLoading+"\n\nTarget: "+this.TARGET+"\n\nArgs: "+this.funcArgs);
		}
	}
	this.onFinishLoading = '';
}

PHPLiveX.prototype.CreateOutput = function(funcName, funcArgs, funcUrl) {
	this.funcArgs = funcArgs;
	var data = "funcName=" + escape(funcName);
	var args = new Array();
	if(funcUrl == null){ funcUrl = "/ajax.html"; }
	if(funcArgs != ""){
	/*
		if(funcArgs.indexOf(",") != -1){
			args = funcArgs.split(",");
			for (i=0;i<args.length;i++) data += "&funcArgs[]=" + escape(args[i]);
		}else{
		*/
			data += "&funcArgs[]=" + encodeURIComponent(funcArgs);
		//}
	}
	var parentObject = this;
	var XmlHttp = this.GetXmlHttp();
	var ajaxType = false;
	if(this.TYPE != "r") ajaxType = true;
	if(this.METHOD == "get"){
		if(funcUrl.indexOf("?") != -1){
		XmlHttp.open("GET", funcUrl + "&" + this.EscapeSpecialChars(data), ajaxType);
		}else{
		XmlHttp.open("GET", funcUrl + "?" + this.EscapeSpecialChars(data), ajaxType);
		}
	}else{
	XmlHttp.open("post", funcUrl, ajaxType); }
	XmlHttp.setRequestHeader("Method", this.METHOD + " " + funcUrl + " HTTP/1.1");
	XmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
/*	XmlHttp.setRequestHeader("Pragma", "no-cache");
	XmlHttp.setRequestHeader("Cache-Control", "must-revalidate");
	XmlHttp.setRequestHeader("Cache-Control", "no-cache");
	XmlHttp.setRequestHeader("Cache-Control", "no-store");*/
	if(this.TYPE != "r") {
	this.CreatePreloading();
	XmlHttp.onreadystatechange = function() {
		if(XmlHttp.readyState == 0) {
			XmlHttp.abort();
			parentObject.ClearPreloading();
		} else if(XmlHttp.readyState == 4) {
			var output = parentObject.GetSpecialChars(XmlHttp.responseText);
			//var outparts = output.split("<phplivex>");
			//output = outparts[outparts.length-1].split("</phplivex>")[0];

			/*If JS Code Exists*/
			var jscode = "";
			var parts = output.match(/<script[^>]*>(.|\n|\t|\r)*?<\/script>/gi);
			if(parts){
				for(i=0;i<parts.length;i++) {
					//jscode += parts[i].replace(/<script[^>]*>|<\/script>/gi, "");
					jscode += parts[i].replace(/<script[^>]*>|<\/script>/gi, "");
					output = output.replace(parts[i], "");
				}
			}

			if(parentObject.TYPE == "e") {
				parentObject.ClearPreloading();
				return; 
			} else if(!parentObject.TARGET) {
				// do nothing
			} else if(parentObject.TARGET == "alert") {
				alert(output);
			} else if(parentObject.MODE == "aw") {
				document.getElementById(parentObject.TARGET).innerHTML += output;
				showLayer(parentObject.TARGET);
			} else if(parentObject.MODE == "rw") {
				if (!document) {
					//var document = top;
				}
				try {
					document.getElementById(parentObject.TARGET).innerHTML = output;
				} catch (e) {
				//
				}
				showLayer(parentObject.TARGET, parentObject.VIEW_STYLE);
			} else if(parentObject.MODE == "animate") {
				parentObject.outputAnimate(output);
				showLayer(parentObject.TARGET);
			} else if(parentObject.MODE == "new") {
				parentObject.outputNew(output);
				showLayer(parentObject.TARGET);
			}
			if(jscode != ""){
				var script = document.createElement("script");
				script.type = 'text/javascript'; 
				script.lang = 'javascript';
				script.text = jscode;
				document.getElementsByTagName('head')[0].appendChild(script);
			}
			parentObject.ClearPreloading();
		}
	}
	
	if(this.METHOD == "get"){ XmlHttp.send(null); }
	else{ XmlHttp.send(this.EscapeSpecialChars(data)); }
	}else{
		if(this.METHOD == "get"){ XmlHttp.send(null); }
		else{ XmlHttp.send(this.EscapeSpecialChars(data)); }
		var output = this.GetSpecialChars(XmlHttp.responseText);
		//var outparts = output.split("<phplivex>");
		//output = outparts[outparts.length-1].split("</phplivex>")[0];
		
		/*If JS Code Exists*/
		var jscode = "";
		var parts = output.match(/<script[^>]*>(.|\n|\t|\r)*?<\/script>/gi);
		if(parts){
			for(i=0;i<parts.length;i++){
				jscode += parts[i].replace(/<script[^>]*>|<\/script>/gi, "");
				output = output.replace(parts[i], "");
			}
		}
		if(jscode != ""){
			var script = document.createElement("script");
			script.type = 'text/javascript'; 
			script.lang = 'javascript';
			script.text = jscode;
			document.getElementsByTagName('head')[0].appendChild(script);
		}
		
		return output;
	}
}
function runAjax() {
	var args = new Array(); var plx_args = new Array();
	var plxType = "e"; var plxTarget = null;
	var plxMode = "rw"; var plxPreload = null;
	var plxMethod = "post";
	for(i=0;i<runAjax.arguments.length;i++){ args[i] = runAjax.arguments[i]; }
	if(args[args.length-1].indexOf(",") != -1){ plx_args = args[args.length-1].split(","); }
	else{ plx_args[0] = args[args.length-1]; }
	for(i=0;i<plx_args.length;i++) {
		if(plx_args[i].indexOf("type=") != -1){
		plxType = plx_args[i].substr(5);
		}else if(plx_args[i].indexOf("target=") != -1){
		plxTarget = plx_args[i].substr(7);
		plxType = "print";
		}else if(plx_args[i].indexOf("mode=") != -1){
		plxMode = plx_args[i].substr(5);
		}else if(plx_args[i].indexOf("preload=") != -1){
		plxPreload = plx_args[i].substr(8);
		}else if(plx_args[i].indexOf("method=") != -1){
		plxMethod = plx_args[i].substr(7);
		}
	}
	args.splice(args.length-1, 1);
	var FuncArgs = args.join();
	var PLX_runAjax = new PHPLiveX(plxType, plxTarget, plxMode, plxPreload, plxMethod);

	//try {
		if(plxType == "r"){ 
			return PLX_runAjax.CreateOutput("runAjax", FuncArgs,"/ajax.html");
		} else {
			PLX_runAjax.CreateOutput("runAjax", FuncArgs,"/ajax.html");
		}
	//} catch(ex) {
	//	PLX_runAjax.ShowError(ex);
	//}
}



// = utils =========================


function utils() {}
utils.enterPressed = function(e) {
	var keynum;
	if(window.event) { // IE
		keynum = e.keyCode;
	}
	else if(e.which) { // Netscape/Firefox/Opera
		keynum = e.which;
	}
	return keynum==13;
}

function showLayer(sElementId, type) {
	try {
		if (!type) {
			type = 'block';
		}
		var ele = document.getElementById(sElementId);
		ele.style.visibility="visible";
		ele.style.display=type;
	} catch(e) {
		alert('not exists: '+sElementId);
	}
}

function hideLayer(sElementId) {
	try {
		var ele = document.getElementById(sElementId);
		ele.style.visibility="hidden";
		ele.style.display="none";
	} catch(e) {
		alert('not exists: '+sElementId);
	}
}

function isLayerVisible(sElementId) {
	var ele = getLayer(sElementId);
	return (ele.style.visibility!='hidden') && (ele.style.display != 'none');
}

function getLayer(id) {
	return document.getElementById(id);
}

function getLayers(id) {
	return document.getElementsByName(id);
}

function switchLayer(sElementId, style) {
	if (document.getElementById(sElementId).style.display=='none')
		showLayer(sElementId, style);
	else
		hideLayer(sElementId);
}

function addElement(sElements, sElement, separator) {
	if (!sElements) {
		sElements = '';
	} else {
		sElements = unescape(sElements);
	}
	if (!separator) {
		separator = '|';
	}
	if (!sElements) {
		return sElement;
	}
	var aElements = sElements.split(separator);
	var i;
	for (i=0; i<aElements.length; i++) {
		if (aElements[i] == sElement) {
			return sElements;
		}
	}
	aElements[i] = sElement;

	sElements = '';
	for (i=0; i<aElements.length; i++) {
		sElements += aElements[i];
		if (aElements.length != (i+1)) {
			sElements += separator;
		}
	}
	return sElements;
}

function delElement(sElements, sElement, separator) {
	if (!sElements) {
		sElements = '';
	} else {
		sElements = unescape(sElements);
	}
	if (!separator) {
		separator = '|';
	}
	if (!sElements || (sElements == sElement)) {
		return '';
	}
	var aElements = sElements.split(separator);
	var i;
	var j=0;
	var aNewElements = new Array();
	for (i=0; i<aElements.length; i++) {
		if (aElements[i]!=sElement) {
			aNewElements[j++] = aElements[i];
		}
	}

	var sElements = '';
	for (i=0; i<aNewElements.length; i++) {
		sElements += aNewElements[i];
		if (aNewElements.length != (i+1)) {
			sElements += separator;
		}
	}
	return sElements;
}

function switchElement(sElements, sElement, separator) {
	if (!separator) {
		separator = '|';
	}
	if (!sElements) {
		return sElement;
	}
	var aElements = sElements.split(separator);
	var i;
	for (i=0; i<aElements.length; i++) {
		if (aElements[i] == sElement) {
			return delElement(sElements, sElement, separator);
		}
	}
	return addElement(sElements, sElement, separator);
}

function findPos(sElement) {
	var obj = getLayer(sElement);
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

/*
xmin, ymin, xmax, ymax
*/
function getElementRec(sElement) {
	var objInitial = obj = getLayer(sElement);
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop,(curleft+objInitial.offsetWidth),(curtop+objInitial.offsetHeight)];
}

/*
xmin, ymin, xmax, ymax
*/
function getWindowRec() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [scrOfX, scrOfY, (scrOfX + myWidth), (scrOfY + myHeight)];
}

function fillLayerByAnother(sLayerForFilling, sLayerToFill) {
	var oLayerForFilling = getLayer(sLayerForFilling);
	var oLayerToFill = getLayer(sLayerToFill);
	aLeftTop = findPos(sLayerForFilling);
	oLayerToFill.style.left = aLeftTop[0]+'px';
	oLayerToFill.style.top = aLeftTop[1]+'px';
	oLayerToFill.style.width = oLayerForFilling.offsetWidth+'px';
	oLayerToFill.style.height = oLayerForFilling.offsetHeight+'px'; 
	oLayerToFill.style.visibility = 'visible';
	oLayerToFill.style.display = 'block';
}

function putOneLayerInTheMiddleOfAnother(sMainLayerId, sTopLayerId) {
	var oMainLayerId = getLayer(sMainLayerId);
	var oTopLayerId = getLayer(sTopLayerId);
	var aLeftTop = findPos(sMainLayerId);
	
	
	var iXCenter = aLeftTop[0] + Math.round(oMainLayerId.offsetWidth / 2);
	var iYCenter = aLeftTop[1] + Math.round(oMainLayerId.offsetHeight / 2);

	oTopLayerId.style.left = Math.round(iXCenter-oTopLayerId.offsetWidth/2)+'px';
	oTopLayerId.style.top = Math.round(iYCenter-oTopLayerId.offsetHeight/2)+'px';
	oTopLayerId.style.visibility = 'visible';
	oTopLayerId.style.display = 'block';
}

function putLayerOnTheCenter(sLayerId) {
	var oLayerId = getLayer(sLayerId);
	var aWindowRec = getWindowRec();
	//var aLeftTop = findPos(sMainLayerId);
	var iX = Math.round((aWindowRec[2] - aWindowRec[0])/2 - oLayerId.offsetWidth / 2);
	var iY = Math.round((aWindowRec[3] - aWindowRec[1])/2 - oLayerId.offsetHeight / 2);
	oLayerId.style.top = iY+'px';
	oLayerId.style.left = iX+'px';
	//alert(iX+' '+iY);
}

function putOneLayerInTheVisibleMiddleOfAnother(sMainLayerId, sTopLayerId) {
	var oMainLayerId = getLayer(sMainLayerId);
	var oTopLayerId  = getLayer(sTopLayerId);
	var aElementRec  = getElementRec(sMainLayerId);
	var aWindowRec   = getWindowRec();
	//alert(aElementRec.toSource()+" && "+aWindowRec.toSource());
	
	var aVisibleRec  = getIntersectedRec(aElementRec, aWindowRec);
	//alert(aWindowRec.toSource()+"\n"+aElementRec.toSource()+"\n"+aVisibleRec.toSource());
	
	if (aVisibleRec)  {
		oTopLayerId.style.visibility = 'visible';
		oTopLayerId.style.display = 'block';

		var iXCenter = Math.round((aVisibleRec[0] + aVisibleRec[2]) / 2);
		var iYCenter = Math.round((aVisibleRec[1] + aVisibleRec[3]) / 2);

		oTopLayerId.style.left = Math.round(iXCenter-oTopLayerId.offsetWidth/2)+'px';
		oTopLayerId.style.top = Math.round(iYCenter-oTopLayerId.offsetHeight/2)+'px';
	}
}


/**
 * returning intersected rectangle
 * @see SpatialObject::intersect()
 * @param oblect $oRectangle instance of class Rectangle
 * @return boolean
 */
function getIntersectedRec (aRectangle1, aRectangle2) {
	var xmin = ymin = xmax = ymax = null;
	if (aRectangle1[0]>aRectangle2[0])
		xmin=aRectangle1[0];
	else
		xmin=aRectangle2[0];

	if (aRectangle1[2]<aRectangle2[2])
		xmax=aRectangle1[2];
	else
		xmax=aRectangle2[2];


	if (aRectangle1[1]>aRectangle2[1])
		ymin=aRectangle1[1];
	else
		ymin=aRectangle2[1];

	if (aRectangle1[3]<aRectangle2[3])
		ymax=aRectangle1[3];
	else
		ymax=aRectangle2[3];

	if ((xmin<=xmax) && (ymin<=ymax))
		return [xmin, ymin, xmax, ymax];
	else 
		return false;
}

function disableAnchor(obj, sClassName) {
    var href = obj.getAttribute("href");
    if (href && href != "" && href != null){
       obj.setAttribute('href_bak', href);
    }
    obj.removeAttribute('href');
	if (sClassName) {
		obj.className = sClassName;
	} else {
		obj.setAttribute('color_bak', obj.style.color);
		obj.style.color = 'gray';
		obj.style.fontWeight='bold';
	}
}

function enableAnchor(obj, sClassName) {
	var href = obj.getAttribute("href");
	if (href) {
		obj.setAttribute('href_bak', href);
		return;
	}
	if (!obj.attributes['href_bak']) {
		return;
	}
    obj.setAttribute('href', obj.attributes['href_bak'].nodeValue);
    obj.style.color="#333";
	if (sClassName) {
		obj.className = sClassName;
	} else {
		if (obj.attributes['color_bak']) {
			obj.style.color = obj.attributes['color_bak'];
		} else {
			obj.style.color = obj.style.color;
		}
	}
}

var _previouslySelectedObject = document.createElement('a');
function selectElement(obj) {
	_previouslySelectedObject.style.fontWeight='';
	obj.style.fontWeight='bold';
	_previouslySelectedObject.style.color='';	
	obj.style.color='#BB2F1F';
	_previouslySelectedObject = obj;
}

var _previouslySelectedA = 0;
function selectElementA(obj) {
	if (_previouslySelectedA) {
		enableAnchor(_previouslySelectedA);
	}
	disableAnchor(obj);
	_previouslySelectedA = obj;
}


// = module =======================

function AjaxModule() {
	this.sParams;
	this.aParams = new Array();
	this.aSavedParams = new Array();
	this.REQUEST_URI;
	this.onStartLoading = '';
	this.onFinishLoading = '';

	this.init = function() {
		this.aParams = new Array();
		this.aSavedParams = new Array();
		this.sParams = document.location.hash;
		this.REQUEST_URI = document.location.href;
		if (this.REQUEST_URI.indexOf('#')>0) {
			this.sParams = this.REQUEST_URI.substring ((this.REQUEST_URI.indexOf('#')+1), this.REQUEST_URI.length);
			this.string2params(this.sParams);
			this.REQUEST_URI = this.REQUEST_URI.substring (0, this.REQUEST_URI.indexOf('#'));
		}
	}

	this.initPHPLiveX = function(target, preload) {
		var oPHPLiveX = new PHPLiveX();
		oPHPLiveX.TYPE    = 'print';
		oPHPLiveX.MODE    = 'rw';
		oPHPLiveX.TARGET  = target;
		oPHPLiveX.PRELOAD = preload;
		oPHPLiveX.METHOD  = 'post';

		oPHPLiveX.onStartLoading  = this.onStartLoading;
		oPHPLiveX.onFinishLoading = this.onFinishLoading;

		return oPHPLiveX;
	}
	
	this.setParam = function(name, value) {
		this.aParams[name] = value;
		if (this.aSavedParams[name]!=undefined) {
			this.aSavedParams[name] = value;
		}
	}
	
	this.setSaved = function(name, value) {
		if (value==undefined) {
			if (!this.aSavedParams[name] && this.aParams[name]) {
				this.aSavedParams[name] = this.aParams[name];
			}
		} else {
			this.aParams[name] = this.aSavedParams[name] = value;
		}
	}

	this.setParamBeginingWith = function(sBeginWith, value) {
		var iLength = sBeginWith.length;
		for (key in this.aParams) {
			if (key.substring(0, iLength) == sBeginWith) {
				this.setParam(key, value);
			}
		}
	}

	this.renderParamsForRun = function(sTemplateOutput, bNotUri) {
		this.renderLocation();
		if (bNotUri) {
			return this.params2string()+'sTemplateOutput='+sTemplateOutput;
		}
		return this.params2string()+'sTemplateOutput='+sTemplateOutput+'&REQUEST_URI='+this.URLEncode(this.REQUEST_URI);
	}

	this.run = function(sTemplateOutput, target, preload) {
		var oPHPLiveX = this.initPHPLiveX(target, preload);
		var sLocation = this.renderParamsForRun(sTemplateOutput);
		oPHPLiveX.CreateOutput("runAjax", sLocation, "/ajax.html");
		this.onStartLoading='';
		this.onFinishLoading='';
	}

	this.runModule = function(sModule, target, preload) {
		this.renderLocation();
		var params = this.params2string()+'name='+sModule;
		var oPHPLiveX = this.initPHPLiveX(target, preload);
		oPHPLiveX.CreateOutput("runAjax", params, "/ajax.html");
		this.onStartLoading='';
		this.onFinishLoading='';
	}

	this.runModuleBlank = function(sModule, sParams, target, preload, bReturn, VIEW_STYLE) {
		var params = sParams+'&name='+sModule;
		var oPHPLiveX = this.initPHPLiveX(target, preload);
		if (bReturn) {
			oPHPLiveX.TYPE='r';
		}
		if (VIEW_STYLE) {
			oPHPLiveX.VIEW_STYLE = VIEW_STYLE
		}

		var output = oPHPLiveX.CreateOutput("runAjax", params, "/ajax.html");
		this.onStartLoading='';
		this.onFinishLoading='';
		return output;
	}

	this.renderLocation = function () {
		this.sParams = this.params2string();
		if (this.sParams) {
			document.location.hash = this.sParams;
			this.sParams = document.location.hash;
			window.history[window.history.length]=this.REQUEST_URI + this.sParams;

			if (typeof(urchinTracker) == 'function') {
				urchinTracker(document.location.href);
			}			
		}
	}

	this.params2string = function() {
		var sParams = '';
		for (key in this.aParams) {
			if (this.aSavedParams[key] == undefined) {
				sParams += key+"="+this.aParams[key]+"&";
			}
		}
		for (key in this.aSavedParams) {
			sParams += key+"="+this.aSavedParams[key]+"&";
			this.aParams[key] = this.aSavedParams[key];
		}
		return sParams;
	}
	
	
	this.reset = function() {
		this.aParams = new Array();
		for (key in this.aSavedParams) {
			this.aParams[key] = this.aSavedParams[key];
		}
	}
	
	this.string2params = function(s) {
		var iDelimeterPosition = 0;
		var sQueryPart = '';
		while ((iDelimeterPosition = s.indexOf('&'))>0) {
			this.string2param(s.substring(0, iDelimeterPosition));
			s = s.substring((iDelimeterPosition+1), s.length);
		}
		this.string2param(s);
	}
	
	this.string2param = function(s) {
		var iDelimeterPosition = s.indexOf('=');
		var key = '';
		var val = '';
		if (iDelimeterPosition>0) {
			key = s.substring(0, iDelimeterPosition);
			val = s.substring((iDelimeterPosition+1), s.length);
			this.setParam(key, val);
		}
	}
	
	
	this.URLEncode = function(plaintext) {
		// The Javascript escape and unescape functions do not correspond
		// with what browsers actually do...
		var SAFECHARS = "0123456789" +					// Numeric
						"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
						"abcdefghijklmnopqrstuvwxyz" +
						"-_.!~*'()";					// RFC2396 Mark characters
		var HEX = "0123456789ABCDEF";
	
		var encoded = "";
		for (var i = 0; i < plaintext.length; i++ ) {
			var ch = plaintext.charAt(i);
			if (ch == " ") {
				encoded += "+";				// x-www-urlencoded, rather than %20
			} else if (SAFECHARS.indexOf(ch) != -1) {
				encoded += ch;
			} else {
				var charCode = ch.charCodeAt(0);
				if (charCode > 255) {
					alert( "Unicode Character '" 
							+ ch 
							+ "' cannot be encoded using standard URL encoding.\n" +
							  "(URL encoding only supports 8-bit characters.)\n" +
							  "A space (+) will be substituted." );
					encoded += "+";
				} else {
					encoded += "%";
					encoded += HEX.charAt((charCode >> 4) & 0xF);
					encoded += HEX.charAt(charCode & 0xF);
				}
			}
		} // for
	
		return encoded;
	};

	this.URLDecode = function(encoded) {
	   // Replace + with ' '
	   // Replace %xx with equivalent character
	   // Put [ERROR] in output if %xx is invalid.
	   var HEXCHARS = "0123456789ABCDEFabcdef"; 
	   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;
	}
	this.init();
}

var oAjaxModule = new AjaxModule();