//****************************************************************//
//****       CSS Layout-Datei             (c) VRN GmbH        ****//
//****       für VRN Fahrplanauskunft      15.01.2008         ****//
//****************************************************************//

//****************************************************************//
//************** global functions and variables ******************//
var dFocus = false;
var hFocus = false;
var mFocus = false;

var reentrant = 0, h = 0, b = 0;

//Das Objekt, das gerade bewegt wird.
var dragobjekt = null;

// Position, an der das Objekt angeklickt wurde.
var dragx = 0;
var dragy = 0;

// Mausposition
var posx = 0;
var posy = 0;



//-------------- find the key by an keyevent ---------------------->
document.onkeydown = findTaste;

//-------------- find the navigator by an mouseevent ---------------------->
if (parseInt(navigator.appVersion)>3) 
{
	document.onmousedown = mouseDown;
	if (navigator.appName=="Netscape") 
		document.captureEvents(Event.mouseDown);
}
//************** global functions and variables ******************//
//****************************************************************//


//----------- set the date (today) in the trip request form --------------->
function set_date()
{
	var day, month, year;
	
	if (document.eingabe.action != 'XSLT_PS_REQUEST2')
	{
		day = document.eingabe.itdDateDay.value;
		month = document.eingabe.itdDateMonth.value;
		year = document.eingabe.itdDateYear.value;

		timeString = day + "." + month + "." + year;
	//	alert(timeString);
		document.eingabe.date.value = timeString;
		}

}
//----------- set the date (today) in the ps request form --------------->
function setdate() {
	var day, month, year, hours, minutes, seconds, ap;
	var intHours, intMinutes, intSeconds, intDay, intMonth, intYear;
	var today;

	today = new Date();

	intHours = today.getHours();
	intMinutes = today.getMinutes();
	intSeconds = today.getSeconds();
	intDay = today.getDate();
	intYear = today.getYear();
	intMonth = today.getMonth() + 1;

	year = '2008';

	if (intDay < 10) {
		day = "0"+intDay;
	} else {
		day = intDay;
	} 

	if (intMonth < 10) {
		month = "0"+intMonth;
	} else {
		month = intMonth;
	} 

	document.eingabe.psParamSampleDay.value = day;
	document.eingabe.psParamSampleMonth.value = month;
	document.eingabe.psParamSampleYear.value = year;
//	alert(year);
}
//----------- set the sample date in the ps request form --------------->
function setsampledate() {

	var date;

	date = document.eingabe.psParamSampleYear.value + document.eingabe.psParamSampleMonth.value + document.eingabe.psParamSampleDay.value;
//	alert (date);
	document.eingabe.psParamSampleDate.value =date;
}
//----------- hide the div for the map --------------->
function nomap()
{		
	divstate = document.getElementById('vrnMap');
	divstate.style.display = "none";
}

//----------- check the input of the form, submit the form with nothing --------------->
function check_value()
{
	var mapusage = document.eingabe.itdLPxx_mapusage.value;
	if(! (mapusage == 'stt' || mapusage == 'ttb' || mapusage == 'rop' || mapusage == 'dm' || mapusage == 'ss')){
		if (document.eingabe.nameState_origin.value == 'empty')
		{
			var nameorigin = document.eingabe.name_origin.value;
		}
		if (document.eingabe.nameState_destination.value  == 'empty')
		{
			var namedestination = document.eingabe.name_destination.value;
		}
		if (document.eingabe.nameState_via.value  == 'empty')
		{
			var namevia = document.eingabe.name_via.value;
		}
	
		if (nameorigin == 'hier eintragen: Ort, Haltestelle oder Adresse oder interessanter Punkt (POI)' || nameorigin == 'Enter: Place, Stop, Address or Point of Interest (POI)' || nameorigin == 'Saisir ici : lieu, arrêt ou adresse ou point d\'intérêt (POI)' || nameorigin == 'qui inserire: località, fermata o indirizzo o punto interessante (POI)')
		{
			document.eingabe.name_origin.value = '';
		}
	
		if (namedestination == 'hier eintragen: Ort, Haltestelle oder Adresse oder interessanter Punkt (POI)' || namedestination == 'Enter: Place, Stop, Address or Point of Interest (POI)' || namedestination == 'Saisir ici : lieu, arrêt ou adresse ou point d\'intérêt (POI)' || namedestination == 'qui inserire: località, fermata o indirizzo o punto interessante (POI)')
		{
			document.eingabe.name_destination.value = '';
		}
		
		if (namevia == 'hier eintragen: Ort, Haltestelle oder Adresse oder interessanter Punkt (POI)' || namevia == 'Enter: Place, Stop, Address or Point of Interest (POI)' || namevia == 'Saisir ici : lieu, arrêt ou adresse ou point d\'intérêt (POI)' || namevia == 'qui inserire: località, fermata o indirizzo o punto interessante (POI)')
		{
			document.eingabe.name_via.value = '';
		}
	} else if (document.eingabe.itdLPxx_mapusage.value == 'stt'){
		if (document.eingabe.nameState_stt.value == 'empty')
		{
			var namestt = document.eingabe.name_stt.value;
		}
		if (namestt == 'hier eintragen: Ort, Haltestelle' || namestt == 'Enter: Place, Stop' || namestt == 'Saisir ici : lieu, arrêt' || namestt == 'qui inserire: località, fermata')
		{
			document.eingabe.name_stt.value = '';
		}
	} else if (document.eingabe.itdLPxx_mapusage.value == 'ttb'){
		if (document.eingabe.nameState_ttb.value == 'empty')
		{
			var namettb = document.eingabe.name_ttb.value;
		}
		if (namettb == 'hier eintragen: Ort, Haltestelle')
		{
			document.eingabe.name_ttb.value = '';
		}
	} else if (document.eingabe.itdLPxx_mapusage.value == 'rop'){
		if (document.eingabe.nameState_rop.value == 'empty')
		{
			var namerop = document.eingabe.name_rop.value;
		}
		if (namerop == 'hier eintragen: Ort, Haltestelle')
		{
			document.eingabe.name_rop.value = '';
		}
	} else if (document.eingabe.itdLPxx_mapusage.value == 'dm'){
		if (document.eingabe.nameState_dm.value == 'empty')
		{
			var namedm = document.eingabe.name_dm.value;
		}
		if (namedm == 'hier eintragen: Ort, Haltestelle oder Adresse oder interessanter Punkt (POI)')
		{
			document.eingabe.name_dm.value = '';
		}
	} else if (document.eingabe.itdLPxx_mapusage.value == 'ss'){
		if (document.eingabe.nameState_ss.value == 'empty')
		{
			var namess = document.eingabe.name_ss.value;
		}
		if (namess == 'hier eintragen: Ort, Haltestelle')
		{
			document.eingabe.name_ss.value = '';
		}
	}
}

//----------- check the input of the form, submit the form with nothing (PS TRIP) --------------->
function check_value_2()
{
	var mapusage = document.eingabe.itdLPxx_mapusage.value;

	if (document.eingabe.nameState_origin.value == 'empty')
	{
		var nameorigin = document.eingabe.name_origin.value;
	}
	if (document.eingabe.nameState_destination.value  == 'empty')
	{
		var namedestination = document.eingabe.name_destination.value;
	}
		
	if (nameorigin == 'hier eintragen: Ort, Haltestelle oder Adresse oder interessanter Punkt (POI)')
	{
		document.eingabe.name_origin.value = '';
	}
	
	if (namedestination == 'hier eintragen: Ort, Haltestelle oder Adresse oder interessanter Punkt (POI)')
	{
		document.eingabe.name_destination.value = '';
	}
}

//----------- clear the value of the input form (not standard) --------------->
function clear_value(obj)
{
	if (obj.value == 'hier eintragen: Ort, Haltestelle oder Adresse oder interessanter Punkt (POI)' || obj.value == 'Enter: Place, Stop, Address or Point of Interest (POI)' || obj.value == 'Saisir ici : lieu, arrêt ou adresse ou point d\'intérêt (POI)' || obj.value == 'qui inserire: località, fermata o indirizzo o punto interessante (POI)')
	{
		obj.value = '';
	} else if (obj.value == 'hier eintragen: Ort, Haltestelle' || obj.value == 'Enter: Place, Stop' || obj.value == 'Saisir ici : lieu, arrêt' || obj.value == 'qui inserire: località, fermata')
	{
		obj.value = '';
	}
}

//----------- check the date input of the form and submit --------------->
function submit_date()
{
	var mydate = document.eingabe.date.value;

	splitString = mydate.split(".");

	document.eingabe.itdDateDay.value=splitString[0];
	document.eingabe.itdDateMonth.value=splitString[1];
	document.eingabe.itdDateYear.value=splitString[2];
}

//----------- set the focus of an object --------------->
function setFocus(obj)
{
	var panel = document.getElementById(obj);
	if (panel)
		panel.focus();
	else {
		return true;
	}
}

//----------- set the css class of an object --------------->
function change_color(id,klasse) 
{
	document.getElementById(id).className = klasse;
}

//----------- change the date by one day (up or down) --------------->
function dateUpDown(upOrDown) { 
	var tag;
	var monat;
	var jahr;

	date = document.eingabe.date.value;
	splitString = date.split(".");

	tag = splitString[0];
	monat = splitString[1];
	jahr = splitString[2];

	var jahrIntWert = parseInt(jahr);

	if (jahrIntWert >= 0 && jahrIntWert <= 75)
	{ 
		jahrIntWert = 2000 + jahrIntWert; 
	} else {
		if (jahrIntWert > 75 && jahrIntWert <= 99)
		{ 
			jahrIntWert = 1900 + jahrIntWert; 
		}
	}

	monat = monat - 1;  

	heute = new Date(jahrIntWert, monat, tag);
	var millisecunden = heute.getTime();

	if (upOrDown == 'up')
	{ millisecunden = millisecunden + (24*60*60*1000); }

	if (upOrDown == 'down' )
	{ 
		millisecunden = millisecunden - (24*60*60*1000); 
	}

	heute.setTime(millisecunden);

	tag = heute.getDate();
	if (tag > 0 && tag < 10)
	{ 
		tag = "0"+tag; 
	}

	monat = heute.getMonth() + 1;
	if (monat > 0 && monat < 10)
	{ 
		monat = "0"+monat; 
	}

	jahr = "" + heute.getFullYear();

	document.eingabe.date.value = tag + "." + monat + "." + jahr;
}

//----------- change the time by one hour (up or down) --------------->
function hour(upOrDown)
 { 
	var hour;
	var minute;
	var tag;
	var monat;
	var jahr;

	date = document.eingabe.date.value;
	hour = document.eingabe.itdTimeHour.value;
	minute = document.eingabe.itdTimeMinute.value;

	splitString = date.split(".");

	tag = splitString[0];
	monat = splitString[1];
	jahr = splitString[2];

	var jahrIntWert = parseInt(jahr);

	if (jahrIntWert >= 0 && jahrIntWert <= 75)
	{ 
		jahrIntWert = 2000 + jahrIntWert; 
	} else {
		if (jahrIntWert > 75 && jahrIntWert <= 99)
		{ 
			jahrIntWert = 1900 + jahrIntWert; 
		}
	}

	monat = monat - 1;  

	heute = new Date(jahrIntWert, monat, tag, hour, minute);
	var millisecunden = heute.getTime();

	if (upOrDown == 'up_hour')
	{ 
		millisecunden = millisecunden + (60*60*1000); 
	}

	if (upOrDown == 'down_hour' )
	{ 
		millisecunden = millisecunden - (60*60*1000); 
	}

	if (upOrDown == 'up_minute')
	{ 
		millisecunden = millisecunden + (60*1000); 
	}

	if (upOrDown == 'down_minute' )
	{ 
		millisecunden = millisecunden - (60*1000); 
	}

	heute.setTime(millisecunden);

	hour = heute.getHours();
	if (hour >= 0 && hour < 10)
	{ 
		hour = "0"+hour; 
	}

	minute = heute.getMinutes();
	if (minute >= 0 && minute < 10)
	{ 
		minute = "0"+minute; 
	}
	
	document.eingabe.itdTimeHour.value = hour;
	document.eingabe.itdTimeMinute.value = minute;
}

//----------- find the position of a object --------------->
function findPosition(obj)
{
	imgOffsetTop=0;imgOffsetLeft=0;

	do 
	{
		imgOffsetTop+=obj.offsetTop;
		imgOffsetLeft+=obj.offsetLeft;
		obj=obj.offsetParent;
	} while (obj.tagName != "BODY" && obj);
}

//----------- find the key code by an key event --------------->
function findTaste(Ereignis) 
{
	if (!Ereignis)
		Ereignis = window.event;
	if (Ereignis.which) {
		Tastencode = Ereignis.which;
	} else if (Ereignis.keyCode) {
		Tastencode = Ereignis.keyCode;
	}
	findkey(Tastencode);
}

//----------- submit a function by keycode --------------->
function findkey(Tastencode)
{
	if ((Tastencode == 38) && (dFocus == true))
	{
		dateUpDown('up');
	}

	if ((Tastencode == 40) && (dFocus == true))
	{
		dateUpDown('down');
	}

	if ((Tastencode == 38) && (hFocus == true))
	{
		hour('up_hour');
	}
	
	if ((Tastencode == 40) && (hFocus == true))
	{
		hour('down_hour');
	}

	if ((Tastencode == 38) && (mFocus == true))
	{
		hour('up_minute');
	}
	
	if ((Tastencode == 40) && (mFocus == true))
	{
		hour('down_minute');
	}
	if ((Tastencode == 13) && ((document.eingabe.itdLPxx_mapusage.value == "Trip") || (document.eingabe.itdLPxx_mapusage.value == "dm")))
	{
		if (document.forms[1].itdLPxx_options.value == 0)
		{
			check_value_2();
		} else {
			check_value();
		}
		submit_date();
		document.eingabe.submit();
	}
	if ((Tastencode == 13) && (document.eingabe.itdLPxx_mapusage.value == "ps_Trip"))
	{
		check_value_2();
		setsampledate();
		document.eingabe.submit();
	}
	if ((Tastencode == 113) && (document.eingabe.itdLPxx_mapusage.value == "Trip"))
	{
		location.href="XSLT_TRIP_REQUEST2?language=de";
	}
	if ((Tastencode == 13) && ((document.eingabe.itdLPxx_mapusage.value == "stt") || (document.eingabe.itdLPxx_mapusage.value == "ttb") || (document.eingabe.itdLPxx_mapusage.value == "rop") || (document.eingabe.itdLPxx_mapusage.value == "ss")))
	{
		check_value();
		document.eingabe.submit();
	}
	if ((Tastencode == 113) && (document.eingabe.itdLPxx_mapusage.value == "stt"))
	{
		location.href="XSLT_STT_REQUEST?language=de";
	}
	if ((Tastencode == 113) && (document.eingabe.itdLPxx_mapusage.value == "ttb"))
	{
		location.href="XSLT_TTB_REQUEST?language=de";
	}
	if ((Tastencode == 113) && (document.eingabe.itdLPxx_mapusage.value == "rop"))
	{
		location.href="XSLT_TTB_REQUEST?language=de";
	}
	if ((Tastencode == 113) && (document.eingabe.itdLPxx_mapusage.value == "dm"))
	{
		location.href="XSLT_DM_REQUEST?language=de";
	}
	if ((Tastencode == 113) && (document.eingabe.itdLPxx_mapusage.value == "ss"))
	{
		location.href="XSLT_SCREEN_SAVER_REQUEST?language=de";
	}

//	alert(event.keyCode+' : '+String.fromCharCode(event.keyCode));
}

//----------- find the server an make output by an mouse event --------------->
function mouseDown(e) 
{
	var altPressed=0;
	var ServerID = document.eingabe.Server.value;
	var SessionID = document.eingabe.sessionID.value;
	var ServerURL;

	if (ServerID=="VRN9_Test")
	{
		ServerURL = "http://efa9-test.vrn.de/basf/XSLT_TRIP_REQUEST2";
	}
	else if (ServerID=="VRN9_1")
	{
		ServerURL = "http://efa9-1.vrn.de/basf/XSLT_TRIP_REQUEST2";
	}
	else if (ServerID=="VRN9_2")
	{
		ServerURL = "http://efa9-2.vrn.de/basf/XSLT_TRIP_REQUEST2";
	}
	else if (ServerID=="VRN9_3")
	{
		ServerURL = "http://efa9-3.vrn.de/basf/XSLT_TRIP_REQUEST2";
	}
	else if (ServerID=="VRN9_4")
	{
		ServerURL = "http://efa9-4.vrn.de/basf/XSLT_TRIP_REQUEST2";
	} else {
		ServerURL = "";
	}

	SessionID = ServerURL + "?sessionID=" + SessionID + "&command=formatToXML";

	if (parseInt(navigator.appVersion)>3) 
	{
		if (navigator.appName=="Netscape") 
		{
			shiftPressed=e.shiftKey;
			altPressed  =e.altKey;
			ctrlPressed =e.ctrlKey;
		} 
		else 	
		{
			shiftPressed=event.shiftKey;
			altPressed  =event.altKey;
			ctrlPressed =event.ctrlKey;
//			self.status=""
//			+  "shiftKey="+event.shiftKey 
//			+", altKey="  +event.altKey 
//			+", ctrlKey=" +event.ctrlKey 
		}
	
//	alert (code);

	if (altPressed)
	{
		alert ("Fahrplanauskunft wurde auf " + ServerID + " berechnet...");
		window.clipboardData.setData('Text', SessionID);
	}
}
	return true;
}

//----------- show the panel in the trip request anwser --------------->
function showPanel(pos)
{
	var pos= pos;
	var panel = document.getElementById('route_panel_' + pos);

	if (panel)
	{
    document.getElementById('mark_row_' + pos).className="row_8";
    document.getElementById('print_trip_' + pos).checked = true;
    panel.style.display = "block";
    document.getElementById('show_rp_' + pos).style.display ="none";
		document.getElementById('hide_rp_' + pos).style.display ="inline";
		document.getElementById('route_ani_' + pos).style.display ="inline";
	}
}

//----------- hide the panel in the trip request anwser --------------->
function hidePanel2(pos)
{
	var pos= pos;
	var panel = document.getElementById('route_panel_' + pos);

	if (panel)
	{
    document.getElementById('mark_row_' + pos).className ="row_6";
    document.getElementById('print_trip_' + pos).checked = false;
		panel.style.display = "none";
		document.getElementById('show_rp_' + pos).style.display ="inline";
		document.getElementById('hide_rp_' + pos).style.display ="none";
		document.getElementById('route_ani_' + pos).style.display ="none";
	}
}

function hide_id(obj)
{
	document.getElementById(obj).style.display ="none";
}

function show_id(obj)
{
	document.getElementById(obj).style.display ="inline";
}

//----------- show the panel fare/tickets in the trip request anwser --------------->
function showID(obj)
{
	var test= obj.id;
	var position = test.substring(9, 11);

	var img = document.getElementById(obj.id);
	var panel = document.getElementById('zonePanel' + position);
	var imgpanel = document.getElementById('zonePanelimg' + position);

	findPosition(img);
	var objLeft = imgOffsetLeft -228;
		//	alert(objLeft);
	var objTop  = imgOffsetTop  + 20;
		//	alert(objTop);
	
	if (panel)  
	{
		panel.style.left = objLeft + "px";
		panel.style.top  = objTop + "px";
		panel.style.display = "inline";
		panel.style.color = "black";
		panel.style.padding = "5px";
		panel.style.background = "#d8eac7";
		panel.style.border = "solid 1px";
		Drag.init(panel);
	}

	var objLeft2 = imgOffsetLeft + 118;
		//	alert(objLeft);
	var objTop2  = imgOffsetTop  + 30;
		//	alert(objTop);

	if (imgpanel)
	{
		imgpanel.style.left = objLeft2 + "px";
		imgpanel.style.top  = objTop2 + "px";
		imgpanel.style.display = "inline";
	}
}

//----------- hide the panel fare/tickets in the trip request anwser --------------->
function hidePanel(pos)
{
	var pos= pos;
	var panel = document.getElementById('zonePanel' + pos);
	var imgpanel = document.getElementById('zonePanelimg' + pos);

	if (panel)
	{
		panel.style.display = "none";
	}
	if (imgpanel)
	{
		imgpanel.style.display = "none";
	}
}

//----------- drag and drop the panel fare/tickets in the trip request anwser --------------->
function div_blende(id, breite, hoehe, aktion)
{ 
	if( ! reentrant ) 
	{
		reentrant = 1;    
		var move = 0, 
		element = document.getElementById(id);        
		
		if( aktion == 'ein' ) 
		{
			if(h < hoehe )
			{ 
				h += 20; move++ 
			}
			if(b < breite)
			{ 
				b += 20; 
				move++ 
			}
			element.style.visibility = 'visible';    
			element.style.display = 'inline';    
		} else if( aktion == 'aus' ) {
			if(h > 0 )
			{ 
				h -= 20; 
				move++ 
			}
			if(b > 0 )
			{ 
				b -= 20; 
				move++ 
			}
			element.style.visibility = (b > 0 && h > 0) ? 'visible' : 'hidden';    
		}
		if( move ) 
		{
			element.style.height =  h + 'px';       
			element.style.width  =  b + 'px';       
			window.setTimeout( function(){ div_blende(id,hoehe,breite,aktion) }, 20 );
		}
		reentrant = 0; 
	}
}


var Drag = {
	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;
		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;
		o.root = oRoot && oRoot != null ? oRoot : o ;
		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;
		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;
		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);
		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;
		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}
		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}
		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;
		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;
		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;
		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)
		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;
		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

function draginit() {
 // Initialisierung der Überwachung der Events

  document.onmousemove = drag;
  document.onmouseup = dragstop;
}


function dragstart(element) {
   //Wird aufgerufen, wenn ein Objekt bewegt werden soll.

  dragobjekt = element;
  dragx = posx - dragobjekt.offsetLeft;
  dragy = posy - dragobjekt.offsetTop;
}


function dragstop() {
  //Wird aufgerufen, wenn ein Objekt nicht mehr bewegt werden soll.

  dragobjekt=null;
}


function drag(ereignis) {
  //Wird aufgerufen, wenn die Maus bewegt wird und bewegt bei Bedarf das Objekt.

  posx = document.all ? window.event.clientX : ereignis.pageX;
  posy = document.all ? window.event.clientY : ereignis.pageY;
  if(dragobjekt != null) {
    dragobjekt.style.left = (posx - dragx) + "px";
    dragobjekt.style.top = (posy - dragy) + "px";
  }
}

