
var higherObj;
var higherOffset;
var lowerObj;
var lowerOffset;
var splitObj;
var splitOffset;
var running;


function docObj(objID)
{
	if (document.getElementById) dobj = document.getElementById(objID);
	else if (document.all) dobj = document.all[objID];
	return dobj;
}

function limitText(objID, txtLen, warn)
{
	var text = docObj(objID).value;
	if (txtLen > 0 && txtLen < String(text).length)
	{
		setValue(objID, text.substr(0, txtLen));
		text = "Der Text wurde auf " + txtLen + " Zeichen gekürzt: \n";
		text += docObj(objID).value;
		if (warn) alert (text);
	}
}

function dataExchange(formID, requestSource, requestField, requestTarget)
{
	setValue("formAction", "dataExchangeRequest");
	setValue("dataExchangeRequestFieldName", requestField);
	setValue("dataExchangeClient", requestSource);
	docObj(formID).action = requestTarget;
	docObj(formID).target = "_parent";
	docObj(formID).submit();
}

function dataExchangePropagate(formID, propagateTarget, propagateField)
{
	setValue("formAction", "dataExchangeResponse");
	setValue("dataExchangeResponseFieldName", propagateField);
	docObj(formID).action = propagateTarget;
	docObj(formID).target = "_parent";
	docObj(formID).submit();
}

function dateAddDays(inDate, diffDays)
{
	if(!diffDays == '' && !isNaN(diffDays))
	{
		diffDays = parseInt(diffDays, 10);
		var inArr = inDate.split(' ');
		var dateArr = inArr[0].split('.');
		var d = new Date;
		d.setFullYear(parseInt(dateArr[2],10));
		d.setMonth(parseInt(dateArr[1],10) - 1);
		d.setDate(parseInt(dateArr[0],10));
		d.setHours(0, 0, 0, 0)
		d.setDate(d.getDate() + diffDays);
		dateArr[0] = d.getDate();
		dateArr[0] = (dateArr[0] < 10 ? "0" : "") + dateArr[0];
		dateArr[1] = d.getMonth()+1;
		dateArr[1] = (dateArr[1] < 10 ? "0" : "") + dateArr[1];
		dateArr[2] = d.getFullYear();
		inArr[0] = dateArr.join('.');
		inDate = inArr.join(' ');
	}
	return inDate;
}

function setValue(objID, objValue)
{
	docObj(objID).value = objValue;
}

function splitterActionStop(Event)
{
	window.onmouseup = "";
	window.onmousemove = "";
	window.releaseEvents(Event.MOUSEMOVE);
	window.releaseEvents(Event.MOUSEUP);
	running = 0;
	lowerObj = "";
	splitObj = "";
	higherObj = "";
	lowerOffset = -1;
	splitOffset = -1;
	higherOffset = -1;
}

function splitterHorActionSet(Event)
{
	var xPos = Event.clientX;
	var wl = parseInt(docObj(lowerObj).style.width);
	if(running == 0)
	{
		lowerOffset = wl - xPos;
		splitOffset = parseInt(docObj(splitObj).style.left) - xPos;
		higherOffset = parseInt(docObj(higherObj).style.left) - xPos;
		running = 1;
	}

	wl = lowerOffset + xPos;
	if (wl > 0)
	{
		docObj(lowerObj).style.width = wl + "px";
		docObj(splitObj).style.left = (splitOffset + xPos) + "px";
		docObj(higherObj).style.left = (higherOffset + xPos) + "px";
	}
}

function splitterHorActionStart(leftObj, splitter, rightObj)
{
	lowerObj = leftObj;
	splitObj = splitter;
	higherObj = rightObj;
	running = 0;
	window.captureEvents(Event.MOUSEUP);
	window.onmouseup = splitterActionStop;
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove = splitterHorActionSet;
}

function splitterVerActionSet(Event)
{
	var yPos = Event.clientY;
	var hl = parseInt(docObj(lowerObj).style.height);
	if(running == 0)
	{
		lowerOffset = hl - yPos;
		splitOffset = parseInt(docObj(splitObj).style.top) - yPos;
		higherOffset = parseInt(docObj(higherObj).style.top) - yPos;
		running = 1;
	}

	hl = lowerOffset + yPos;
	if (hl > 0)
	{
		docObj(lowerObj).style.height = hl + "px";
		docObj(splitObj).style.top = (splitOffset + yPos) + "px";
		docObj(higherObj).style.top = (higherOffset + yPos) + "px";
	}
}

function splitterVerActionStart(topObj, splitter, bottomObj)
{
	lowerObj = topObj;
	splitObj = splitter;
	higherObj = bottomObj;
	running = 0;
	window.captureEvents(Event.MOUSEUP);
	window.onmouseup = splitterActionStop;
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove = splitterVerActionSet;
}

function submitValue(formID, objID, objValue)
{
	setValue(objID, objValue);
	docObj(formID).submit();
}

