if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
	HTMLElement.prototype.insertAdjacentElement = function
(where,parsedNode)
	{
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling)
this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function
(where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function
(where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
}

// Mouse coordinates capture
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;

var cursorPositionX = 0;
var cursorPositionY = 0;

function getMouseXY(e)
{
	if (IE)
	{ // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else
	{  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}
	cursorPositionX = tempX;
	cursorPositionY = tempY;
	return true;
}

function fixScroll(div)
{
	var s = div.scrollTop;
	div.childNodes[1].focus();
	div.scrollTop = s;
}


function chGFX(id, name)
{
    img = document.getElementById(id);
    
	if(img != null)
	{
	    var str = img.src;
	    var where = str.lastIndexOf('/') + 1;
	    var oldname = str.substring(where);
	    var path = str.substring(0,where);

	    img.src = path + name;
	}
}

	function Set_Cookie( name, value, expires, path, domain, secure )
	{
		// set time, it's in milliseconds
		var today = new Date();
		today.setTime( today.getTime() );

		/*
		if the expires variable is set, make the correct
		expires time, the current script below will set
		it for x number of days, to make it for hours,
		delete * 24, for minutes, delete * 60 * 24
		*/

		if ( expires )
		{
			expires = expires * 1000 * 60 * 60 * 24;
		}

		var expires_date = new Date( today.getTime() + (expires) );

		document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
	} // function Set_Cookie

	function Get_Cookie( name )
	{
		var start = document.cookie.indexOf( name + "=" );
		var len = start + name.length + 1;

		if ((!start) && (name != document.cookie.substring(0, name.length)))
		{
			return null;
		}

		if (start == -1) return null;
		var end = document.cookie.indexOf( ";", len );
		if ( end == -1 ) end = document.cookie.length;
		return unescape( document.cookie.substring( len, end ) );
	}

	function Delete_Cookie( name, path, domain )
	{
		if ( Get_Cookie( name ) ) document.cookie = name + "=" +
		( ( path ) ? ";path=" + path : "") +
		( ( domain ) ? ";domain=" + domain : "" ) +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}


/*
	old?
	
	function dateSelect(path, fieldName, initval)
	{
		window.open(path + "?fieldName=" + fieldName + "&date=" + initval, 'modDial', "top=" + posY(fieldName) + ",screenY=" + posY(fieldName) + ", left=" + posX(fieldName) + ",screenX=" + posX(fieldName) + ",status=no,width=300,height=300");
	}
*/

	function dateSelect(path, fieldName, fieldID, initval, maxValue, minValue)
	{
		var field = document.getElementById(fieldID);
		
		if(field && field.value)
		{
			initval = field.value;
		}
		
		window.open(path + "?minYear=" + minValue + "&maxYear=" + maxValue + "&fieldName=" + fieldName + "&fieldID="+ fieldID +"&date=" + initval, 'dateModDial', "top=" + posY(fieldID) + ",screenY=" + posY(fieldID) + ", left=" + posX(fieldID) + ",screenX=" + posX(fieldID) + ",status=no,width=300,height=300");
	}

	function posX(objectId)
	{
		var o = document.getElementById(objectId)
		oLeft = o.offsetLeft            // Get left position from the parent object
		while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
			oParent = o.offsetParent    // Get parent object reference
			oLeft += oParent.offsetLeft // Add parent left position
			o = oParent
		}
		// Return left postion
		return oLeft
	}

	function posY(objectId)
	{
		var o = document.getElementById(objectId)
		oTop = o.offsetTop            // Get top position from the parent object
		while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
			oParent = o.offsetParent  // Get parent object reference
			oTop += oParent.offsetTop // Add parent top position
			o = oParent
		}
		// Return top position
		return oTop
	}

	// change checkbox checked status

	function chkChk(id)
	{
		var checkbox = document.getElementById(id);

		if(checkbox.checked == true)
			checkbox.checked = false;
		else
			checkbox.checked = true;

		checkbox.focus();
	}

	// Change class name for given object

	function chClass(id, className)
	{
		object = document.getElementById(id);
		object.className = className;
	}

	// Checks or unchecks all checkboxes in form given by id (table actually)

	function checkAll(formId, clear)
	{
		inputs = document.getElementById(formId).getElementsByTagName('input');

		var checkboxes = new Array();

		for (i = 0; i < inputs.length; i++)
		{
			if (!inputs[i].length)
			{
				if (inputs[i].type == 'checkbox')
					checkboxes[checkboxes.length] = inputs[i];
			}
			else
			{
				for(k = 0; k < inputs[i].length; k++)
				{
					if (inputs[i][k].type == 'checkbox')
						checkboxes[checkboxes.length] = inputs[i];
				}
			}
		}

		for (i = 0; i < checkboxes.length; i++)
		{
			if(clear == false)
			{
				if(checkboxes[i].checked == true)
					checkboxes[i].checked = false;
				else
						checkboxes[i].checked = true;
			}
			else
				checkboxes[i].checked = false;

			checkboxes[i].focus();
		}
	} // function checkall

function OpenFile( fileUrl, returnFieldID, postBackFormID )
{
	if(window.top.opener.SetUrl)
	{
		window.top.opener.SetUrl( fileUrl )
	}
		
	if(window.top.opener.document.getElementById(returnFieldID))
	{
		window.top.opener.document.getElementById(returnFieldID).value = fileUrl;
	}
	
	if(window.top.opener.document.forms[postBackFormID])
	{
		window.top.opener.document.forms[postBackFormID].submit();
	}
	
	window.top.close() ;	
	window.top.opener.focus() ;
}

function hidemenu()
{
	var leftbar = document.getElementById("manaSidebar");
	var img = document.getElementById("framesplitter").src;

	if(leftbar.className == 'hide')
	{
		leftbar.className = 'manaSidebar';
		var re = new RegExp ('framesplitter_reverse', 'gi');
		var newimg = img.replace(re, 'framesplitter');
		document.getElementById('framesplitter').src = newimg;
		document.cookie = "leftbar=open";
		return false;
	}
	else 
	{
		leftbar.className = 'hide';
		var re = new RegExp ('framesplitter', 'gi');
		var newimg = img.replace(re, 'framesplitter_reverse');
		document.getElementById('framesplitter').src = newimg;
		document.cookie = "leftbar=closed";
		return false;
	}
}

// Drag sidebar width
var startpos, diffpos=0;
var erlaubt = false;

function Position(Ereignis)
{
	if (!document.all)
		startpos = Ereignis.pageX + diffpos;
	else
		startpos = window.event.x + diffpos;

	erlaubt = true;
	return false;
}

function Aktion(Ereignis)
{
	erlaubt = false;
	return false;
}

function NeuPos(Ereignis)
{
	if (erlaubt)
	{
		if (!document.all)
			jetztpos = Ereignis.pageX;
		else
			jetztpos = window.event.x;
			
		diffpos = startpos-jetztpos;
		
		document.getElementById("manaSidebar").style.width = startpos - diffpos + "px";
	}
	return false;	
}

function setevent()
{
	document.getElementById("manaSplit").onmousedown = Position;
	document.onmouseup = Aktion;
	document.onmousemove = NeuPos;
	return true;
}

function checkSubIfParentChecked(parentid, subid)
{
	table = document.getElementById(subid);
	inputs = table.getElementsByTagName('input');

	var checkboxes = new Array();
		
	for (i = 0; i < inputs.length; i++)
	{
		if (!inputs[i].length)
		{
			if (inputs[i].type == 'checkbox')
			{
				checkboxes[checkboxes.length] = inputs[i];
			}
		}
		else
		{
			for(k = 0; k < inputs[i].length; k++)
			{
				if (inputs[i][k].type == 'checkbox')
				{
			    	checkboxes[checkboxes.length] = inputs[i];
			    }
			}
		}
	}
				
	for (i = 0; i < checkboxes.length; i++)
	{
		checkboxes[i].checked = document.getElementById(parentid).checked;
	}
} // function checkall

function toggleDisplay(id, usedisp)
{
	layer = document.getElementById(id);
	
	if(layer != null)
	{
	    display = layer.style.display;

	    if(usedisp == null)
		    usedisp = 'block';
    		
	    if(display == 'none')
	    {
		    layer.style.display = usedisp;	
	    }
	    else
	    {
		    layer.style.display = 'none';
	    }
	}
}


// popup menu 

function deleteLayer(id)
{
	if(document.getElementById(id))
	{
		document.getElementById(id).innerHTML = '';
		document.getElementById(id).outerHTML = '';
	}
}

function killPanel(time, id)
{
	setTimeout("deleteLayer('" + id + "')", time);
}

function layerFocus(item, alternateitem)
{
	if(document.all)
		document.getElementById(item).focus();
	else
		document.getElementById(alternateitem).focus();
}

function createPopupPanelDelay(id,item)
{
	var top = item.offsetTop;
	var left = item.offsetLeft + item.offsetWidth;

	setTimeout("createPopupPanel('" + id + "'," + top + "," + left + ")", 1000);
}

function getElement(id)
{
    return document.getElementById(id);
}

function createPopupPanelFromPanel(panelID, panelFromID, stempX, stempY)
{
    var panelFrom = getElement(panelFromID);
    
    if(panelFrom != null)
    {
        var html = new String(panelFrom.innerHTML);
        html = html.replace(/none/g, "block");
        createPopupPanel(html, panelID, stempX, stempY);
    }
}

function createPopupPanel(html, panelID, stempX, stempY)
{
    if(stempX == null)
        stempX = cursorPositionX;
    
    if(stempY == null)
	    stempY = cursorPositionY;

	deleteLayer(panelID);
			
	var newLayer = '<div id="' + panelID + '" onBlur="killPanel(500, \'' + panelID + '\');" style="position: absolute; top: ' + stempY + 'px; left: ' + stempX + 'px;"><a name="checkPanel" id="checkPanel" onBlur="killPanel(500, \'' + panelID + '\');"></a>' + html;

	document.body.insertAdjacentHTML('beforeEnd', newLayer);
    layerFocus(panelID, 'checkPanel');
}
			
function MReturnWindow(windowPath, returnFieldID, width, height)
{
	if(width == '' || width == null)
	{
		width = 800;
	}
	
	if(height == '' || height == null)
	{
		height = 600;
	}
	
	if(windowPath.indexOf("?") == -1)
	{
		windowPath = windowPath + "?";
	}
	else
	{
		windowPath = windowPath + "&";
	}
			
	window.open(windowPath + "returnFieldID=" + returnFieldID, 'MReturnWindow', "status=no,width=" + width + ",height=" + height);
}

function writeFlash(id, data)
{
	document.getElementById(id).innerHTML = data;
}
