var UNDEF = -1;
var UNDEFINED = -1;

/**
* invokes the onsubmit method of the given form
*/
function validateBeforeSubmit(srcForm)
{
	if(srcForm.onsubmit())
	{
		srcForm.submit();
	}
}

/**
* displays a confirmation prompt. if the user says yes => gets the link
*/
function confirmBeforeGetLink(message, link)
{
	if(confirm(message)) {
		location.href = link;
	}
}

/**
* extracts the filename (without extension) of the given source inputfield
* and writes it into the given destination inputfield
*/
function extractName(srcField, destField)
{
	var fileName;
	var path = new String(srcField.value).replace(/\//, '\\');

	fileName = path.substring(path.lastIndexOf('\\')+1, path.lastIndexOf('.'));
	destField.value = fileName;
}

/**
* checks if extension of filename in the given inputfield
* matches the given extension. if false and message defined, alerts message
*/
function checkFileExtension(srcField, ext, message)
{
	var path = srcField.value;
	if(path == '') {
		return true;
	}
	
	var idx = path.lastIndexOf('.');
	var cmp = path.substring(idx+1, path.length).toUpperCase();
	
	if(typeof ext == "string") {
		arrExt = [ext];
	} else if (typeof ext == "object" && ext.length) {
		arrExt = ext;
	} else {
		return false;
	}

	var boolOK = false;
	for(i = 0; i < arrExt.length; i++)
	{
		if(cmp == arrExt[i].toUpperCase())
		{
			boolOK = true;
			break;
		}
	}
	
	if(!boolOK && message != undefined) {
		alert(message);
	}
	
	return boolOK;
}

/**
* gets keycode from the last occurred key event
*/
function getKeyCode(e)
{
	if(window.event) {
		return window.event.keyCode;
	} else if(e) {
		return e.which;
	} else {
		return 0;
	}
}

function getButtonCode(e)
{
	if(window.event) {
		return window.event.button;
	} else if(e) {
		return e.which;
	} else {
		return 0;
	}
}

function getEventSrc(e)
{
	if(window.event)
	{
		return window.event.srcElement;
	} else if(e) {
		return e.target;
	} else {
		return 0;
	}
}

function getMousePosition(e, screen)
{
	var x,y
	
	if(window.event)
	{
		x = window.event.clientX;
		y = window.event.clientY;
		if(!screen) {
			x += document.body.scrollLeft;
			y += document.body.scrollTop;
		}
	} 
	else if(e)
	{
		if(screen) {
			x = e.screenX;
			y = e.screenY;
		} else {
			x = e.pageX;
			y = e.pageY;
		}
	}
	
	return [x,y];	
}

function parseInteger(a, b)
{
	return isNaN(b = parseInt(a))? 0 : b;
}

function getLayerPosition(objLayer)
{
	var x,y;
	
	if(document.layers)
	{
		x = objLayer.pageX || 0;
		y = objLayer.pageY || 0;
	}
	else
	{
		x = 0;
		y = 0;
		
		while(objLayer)
		{
			x += parseInteger(objLayer.offsetLeft);
			y += parseInteger(objLayer.offsetTop);
			
			objLayer = objLayer.offsetParent || null;
		}
	}
	
	return [x,y];
}

function getLayerDimensions(objLayer)
{
	var w,h;
	
	if(document.layers)
	{
		w = parseInt(objLayer.clip.width || 0);
		h = parseInt(objLayer.clip.height || 0);
	}
	else
	{
		if(objLayer.offsetWidth)
		{
			w = parseInt(objLayer.offsetWidth || 0);
			h = parseInt(objLayer.offsetHeight || 0);
		}
		else if(objLayer.style.pixelWidth)
		{
			w = parseInt(objLayer.style.pixelWidth || 0);
			h = parseInt(objLayer.style.pixelHeight || 0);
		}
		else if(objLayer.style.width)
		{
			w = parseInt(objLayer.style.width || 0);
			h = parseInt(objLayer.style.height || 0);
		}
	}
	
	return [w,h];
}

function setLayerPosition(objLayer, intX, intY) {
	if(document.layers) {
		if(intX != UNDEF) {
			objLayer.left = intX;
		}                  
		if(intY != UNDEF) {
			objLayer.top = intY;
		}                  
	} else {             
		if(intX != UNDEF) {
			objLayer.style.left = intX + "px";
		}                  
		if(intY != UNDEF) {
			objLayer.style.top = intY + "px";
		}                  
	}                    
}

function setTransparency(objLayer, alpha)
{
	if(document.all) {
		if(alpha == 100) {
			objLayer.style.filter = "";
		} else {
			objLayer.style.filter = "Alpha(opacity=" + alpha + ")";
		}
	} else {
		objLayer.style.MozOpacity = alpha/100;
	
	}
}

/**
* prevents user of inputing more than x lines in a textarea
*/

function textarea_checkLineCount(e, objTx, maxLines)
{
	if(getKeyCode(e) == 13)
	{
		var text, i, n, numLines, lastpos;
		
		text = objTx.value;
		n = text.length;
		numLines = 0;
		
		for(i = 0; i < n; i++)
		{
			if(text.charCodeAt(i) == 10)
			{
				++numLines;
				if(numLines == maxLines)
				{
					objTx.value = text.substring(0, i);
					break;
				}
			}
		}
	}
}

/**
* CONVERTs from decimal to hexadecimal
*/
function util_decToHex(dec, pad)
{
	var hex = '';
	while(dec > 0)
	{
		dig = dec & 0xF;
		dig = dig < 10 ? dig+48 : dig+55;
		hex = String.fromCharCode(dig) + hex;
		dec >>= 4;
	}
	
	if(pad) {
		if(hex.length < pad) {
			for(i = hex.length; i < pad; i++) {
				hex = '0' + hex;
			}
		}
	}
	
	return hex;
}

/**
* CONVERTs from hexadecimal to decimal
*/
function util_hexToDec(hex)
{
	var dec = 0;
	for(i = 0; i < hex.length; i++)
	{
		dig = hex.charCodeAt(i);
		dig = dig > 64 ? dig-55 : dig-48;
		dec = (dec << 4) | dig;
	}
	
	return dec;
}

/**
* RETURNs a unique id
*/
function util_getUniqueID()
{
	var now = (new Date()).getTime();
	return util_decToHex(now);
}

/**
* CHECKs if given string is a valid hex color
*/
function util_checkHexColor(hex)
{
	hex = hex.toUpperCase();
	if(hex.length != 6) {
		return false;
	} else {
		for(i = 0; i < hex.length; i++) {
			c = hex.charCodeAt(i);
			if(c < 48 || (c > 57 && c < 65) || c > 70) {
				return false;
			}
		}
	}
	
	return true;
}

function util_hexRGBToDecRGB(hex) {
	var dec = util_hexToDec(hex);
	return [(dec >> 16) & 0xFF, (dec >> 8) & 0xFF, dec & 0xFF];
}

function util_decRGBToGray(rgb) {
	return 0.3*rgb[0] + 0.59*rgb[1] + 0.11*rgb[2];
}

/**
* INCREMENTs the value of the given field by the given step respecting the given maximum
*/
function util_incrementFieldValue(objField, stepval, maxval)
{
	if(isNaN(objField.value))
	{
		objField.value = 0;
		return;
	}
	
	var val = parseInt(objField.value);
	
	if(val + stepval <= maxval)
	{
		objField.value = val + stepval;
	}
}

/**
* DECREMENTs the value of the given field by the given step respecting the given minimum
*/
function util_decrementFieldValue(objField, stepval, minval)
{
	if(isNaN(objField.value))
	{
		objField.value = 0;
		return;
	}
	
	var val = parseInt(objField.value);
	
	if(val - stepval >= minval)
	{
		objField.value = val - stepval;
	}
}

/**
* REMOVEs all selected entries of a list
*/
function util_removeSelectedFromList(objSelect)
{
	var arrTemp = new Array();
	var i, objOpt;
	for(i = 0; i < objSelect.length; i++)
	{
		if(!objSelect.options[i].selected)
		{
			arrTemp[arrTemp.length] = new Array(
				objSelect.options[i].text,
				objSelect.options[i].value
			);
		}
	}
	
	objSelect.options.length = 0;
	for(i = 0; i < arrTemp.length; i++)
	{
		objOpt = new Option(arrTemp[i][0], arrTemp[i][1]);
		objSelect.options[objSelect.options.length] = objOpt;
	}
}

/**
* MOVES selected options from a list to another list
*/
function util_moveSelectedFromList(objSelect, objMoveSelect)
{
	var arrTemp = new Array();
	var i, objOpt;
	for(i = 0; i < objSelect.length; i++)
	{
		if(!objSelect.options[i].selected)
		{
			arrTemp[arrTemp.length] = new Array(
				objSelect.options[i].text,
				objSelect.options[i].value
			);
		}
		else
		{
			objOpt = new Option(objSelect.options[i].text, objSelect.options[i].value);
			objMoveSelect.options[objMoveSelect.options.length] = objOpt;
		}
	}
	
	objSelect.options.length = 0;
	for(i = 0; i < arrTemp.length; i++)
	{
		objOpt = new Option(arrTemp[i][0], arrTemp[i][1]);
		objSelect.options[objSelect.options.length] = objOpt;
	}
}

/**
* WRITES values of given select-list-options to another field value
*/
function util_writeOptionListToField(objSel, objField)
{
	var strVal = "";
	var first = 1;
	for(var i = 0; i < objSel.options.length; i++)
	{
		if(objSel.options[i].selected)
		{
			if(!first) {
				strVal += ",";
			} else {
				first = 0;
			}
			
			strVal += objSel.options[i].value;
		}
	}
	
	objField.value = strVal;
	return true;
}

/**
* RETURNs value of checked option in a radio group
*/
function util_radio_getCheckedValue(objRad)
{
	var i;
	for(i = 0; i < objRad.length; i++)
	{
		if(objRad[i].checked == true)
		{
			return objRad[i].value;
		}
	}
}

/**
* CHECKs if the two given ranges intersect each other
*/
function util_rangeIntersect(s1, e1, s2, e2)
{
	var sstart = s1 > s2 ? s1 : s2; // max of starts
	var send = e1 < e2 ? e1 : e2; // min of ends
	return sstart <= send; // section not empty ? 
}


function toggleClass(elm, c1, c2)
{
	elm.className = elm.className == c1 ? c2 : c1;
}


/*********************************************************************************************************
 * DHTML-API                                                                                             *
 *********************************************************************************************************/

var isCSS, isW3C, isIE4, isNN4;
// initialize upon load to let all browsers establish content objects
function initDHTMLAPI() {
    if (document.images) {
        isCSS = (document.body && document.body.style) ? true : false;
        isW3C = (isCSS && document.getElementById) ? true : false;
        isIE4 = (isCSS && document.all) ? true : false;
        isNN4 = (document.layers) ? true : false;
        isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
        isOpera = (navigator.userAgent.indexOf("Opera") > -1) ? true:false;
        }
}
// set event handler to initialize API
//window.onload = initDHTMLAPI;

// Seek nested NN4 layer from string name
function seekLayer(doc, name) {
    var theObj;
    for (var i = 0; i < doc.layers.length; i++) {
        if (doc.layers[i].name == name) {
            theObj = doc.layers[i];
            break;
        }
        // dive into nested layers if necessary
        if (doc.layers[i].document.layers.length > 0) {
            theObj = seekLayer(document.layers[i].document, name);
        }
    }
    return theObj;
}

// Convert object name string or object reference
// into a valid element object reference
function getRawObject(obj) {
    var theObj;
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        } else if (isIE4) {
            theObj = document.all(obj);
        } else if (isNN4) {
            theObj = seekLayer(document, obj);
        }
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}

// Convert object name string or object reference
// into a valid style (or NN4 layer) reference
function getObject(obj) {
    var theObj = getRawObject(obj);
    if (theObj && isCSS) {
        theObj = theObj.style;
    }
    return theObj;
}

// Position an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0;
            theObj.left = x + units;
            theObj.top = y + units;
        } else if (isNN4) {
            theObj.moveTo(x,y);
        }
    }
}

// Move an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0;
            theObj.left = getObjectLeft(obj) + deltaX + units;
            theObj.top = getObjectTop(obj) + deltaY + units;
        } else if (isNN4) {
            theObj.moveBy(deltaX, deltaY);
        }
    }
}

// Set the z-order of an object
function setZIndex(obj, zOrder) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.zIndex = zOrder;
    }
}

// Set the background color of an object
function setBGColor(obj, color) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isNN4) {
            theObj.bgColor = color;
        } else if (isCSS) {
            theObj.backgroundColor = color;
        }
    }
}

// Set the visibility of an object to visible
function show(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "visible";
    }
}

// Set the visibility of an object to hidden
function hide(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "hidden";
    }
}

// Retrieve the x coordinate of a positionable object
function getObjectLeft(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
     if (elem.offsetLeft) {
        result = elem.offsetLeft;
    } else if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("left");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.left;
    } else if (elem.style) {
        result = elem.style.left;
    } else if (isNN4) {
        result = elem.left;
    }
    return parseInt(result);
}

// Retrieve the y coordinate of a positionable object
function getObjectTop(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetTop) {
        result = elem.offsetTop;
    } else if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("top");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.top;
    } else if (elem.style) {
        result = elem.style.top;
    } else if (isNN4) {
        result = elem.top;
    }
    return parseInt(result);
}

// Retrieve the rendered width of an element
function getObjectWidth(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetWidth) {
        result = elem.offsetWidth;
    } else if (elem.clip && elem.clip.width) {
        result = elem.clip.width;
    } else if (elem.style && elem.style.pixelWidth) {
        result = elem.style.pixelWidth;
    }
    return parseInt(result);
}

// Retrieve the rendered height of an element
function getObjectHeight(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetHeight) {
        result = elem.offsetHeight;
    } else if (elem.clip && elem.clip.height) {
        result = elem.clip.height;
    } else if (elem.style && elem.style.pixelHeight) {
        result = elem.style.pixelHeight;
    }
    return parseInt(result);
}


// Return the available content width space in browser window
function getInsideWindowWidth() {
    if (window.innerWidth) {
        return window.innerWidth;
    } else if (isIE6CSS) {
        // measure the html element's clientWidth
        return document.body.parentElement.clientWidth;
    } else if (document.body && document.body.clientWidth) {
        return document.body.clientWidth;
    }
    return 0;
}
// Return the available content height space in browser window
function getInsideWindowHeight() {
    if (window.innerHeight) {
        return window.innerHeight;
    } else if (isIE6CSS) {
        // measure the html element's clientHeight
        return document.body.parentElement.clientHeight;
    } else if (document.body && document.body.clientHeight) {
        return document.body.clientHeight;
    }
    return 0;
}

/*********************************************************************************************************
 * XHTML-API                                                                                             *
 *********************************************************************************************************/
 
var aXmlHttp = new Array();
var aXmlResponse = new Array();
function xmlResult()
{
    for(var i=0;i<aXmlHttp.length;i++)
    {
        if(aXmlHttp[i] && aXmlHttp[i][0] && aXmlHttp[i][0].readyState==4&&aXmlHttp[i][0].responseText)
        {
            //must null out record before calling function in case
            //function invokes another xmlHttpRequest.
            var f = aXmlHttp[i][1];
            var s = aXmlHttp[i][0].responseText;
            aXmlHttp[i][0] = null;
            aXmlHttp[i][1] = null;
            aXmlHttp[i] = null;
            f(s);
        }
    }
}

// u -> url
// f -> callback
function call(u,f)
{
    var idx = aXmlHttp.length;
    for(var i=0; i<idx;i++)
    if (aXmlHttp[i] == null)
    {
        idx = i;
        break;
    }
    aXmlHttp[idx]=new Array(2);
    aXmlHttp[idx][0] = getXMLHTTP();
    aXmlHttp[idx][1] = f;
    if(aXmlHttp[idx])
    {
        aXmlHttp[idx][0].open("GET",u,true);
        aXmlHttp[idx][0].onreadystatechange=xmlResult;
        aXmlHttp[idx][0].send(null);
    }
}

function getXMLHTTP()
{
    var A=null;
    try
    {
        A=new ActiveXObject("Msxml2.XMLHTTP")
    }
    catch(e)
    {
        try
        {
            A=new ActiveXObject("Microsoft.XMLHTTP")
        }
        catch(oc)
        {
            A=null
        }
    }
    if(!A && typeof XMLHttpRequest != "undefined")
    {
        A=new XMLHttpRequest()
    }
    return A
}

function drawNull(s)
{
    eval(s);
    return false;
}

/**
* COORDINATE-CONVERSIONS
*/
var COORD_WGS84 = 0;
var COORD_CH1903 = 1;

function util_convertCoordinates(inputType, inputValues, outputType)
{
	var longitude = 0.0;	// in degrees
	var latitude = 0.0;
	
	switch(inputType)
	{
			
		case COORD_WGS84:
			longitutde = inputValues[0];
			latitude = inputValues[1];
			break;
			
		case COORD_CH1903:
				/* conversion-approximation-formula from swisstopo.ch
				 * (http://www.swisstopo.ch/pub/down/basics/geo/system/ch1903_wgs84_de.pdf)
				 */
				
				/* origin bern (0/0) and values in kilometers */
			var y = (inputValues[0] - 600000) / 1000000;
			var x = (inputValues[1] - 200000) / 1000000;

				/* compute longitude and latitude in unity [10000"] */ 
			var x2 = x*x;
			var y2 = y*y;
			var x3 = x2*x;
			var y3 = y2*y;
			
			var l =			2.6779094
							+		4.728982 		* y
							+		0.791484 		* y			* x
							+		0.1306			* y			* x2
							-		0.0436			* y3;
			
			var p = 		16.9023892
							+		3.238272 						* x
							-		0.270978 		* y2
							-		0.002528 						* x2
							-		0.0447 			* y2		* x
							-		0.0140							* x3;
			
				/* convert to degreees */
			longitude = l * 100 / 36;
			latitude = p * 100 / 36;
			break;
			
		default:
			return UNDEF;
	}
	
	switch(outputType)
	{
		case COORD_WGS84:
			return [longitude,latitude];
			break;
			
		case COORD_CH1903:
				/* conversion-approximation-formula from swisstopo.ch
				 * (http://www.swisstopo.ch/pub/down/basics/geo/system/ch1903_wgs84_de.pdf)
				 */
				 
				/* origin bern (0/0) and values in unity [10000"] */
			var l = (longitude - 26782.5) / 10000;
			var p = (latitude - 169028.66) / 10000;
			
				/* compute swissgrid */
			var l2 = l*l;
			var p2 = p*p;
			var l3 = l2*l;
			var p3 = p2*p;
			
			var y =			600072.37 
    					+		211455.93		* l 
    					-		10938.51		* l			* p
    					-		0.36				* l			* p2
    					-		44.54				* l3;
    					
    	var x =			200147.07 
    					+		308807.95						* p 
    					+		3745.25			* l2
    					+		76.63								* p2 
    					-		194.56			* l2		* p
    					+		119.79							* p3
    	
    	return [y,x];
			break;
		
		default:
			return UNDEF;
	}
}

function util_getDegDecParts(degrees)
{
	var deg, min, sec, t;
	
	deg = Math.floor(degrees);
	t =  60.0 * (degrees - deg);
	min = Math.floor(t);
	t = 60.0 * (t - min);
	sec = t.toFixed(2);
	
	return [deg,min,sec];
}

/**
* Überprüft das Event-Objekt und "repariert" es, wenn möglich
*/
function util_fixEventObj(e)
{
	if(!e) {
		e = (event) ? event : null;
	}
	return e;
}

/**
* Fügt den angegebenen Event-Handler zum Element hinzu
*/
function util_addEventHandler(el, type, fn)
{
	if(el.addEventListener)
	{
			/* W3C-Modell */
		el.addEventListener(type, fn, false);
	}
	else if (el.attachEvent)
	{
			/* Microsoft-Modell */
		el["e"+type+fn] = fn;
		el[type+fn] = function() { el["e"+type+fn](window.event); }
		el.attachEvent("on"+type, el[type+fn]);
	}
	else
	{
			/* Inline-Modell */
		if(el["on"+type] == null)
		{
			el["on"+type] = util_inlineEventHandler;
			el[type+"_inlinefunc"] = [fn];
		}
		else
		{
			var idx = el[type+"_inlinefunc"].length;
			el[type+"_inlinefunc"][idx] = fn;
		}
	}
}

/**
* Entfernt den angegebenen Event-Handler vom Element
*/
function util_removeEventHandler(el, type, fn)
{
	if(el.removeEventListener)
	{
			/* W3C-Modell */
		el.removeEventListener(type, fn, false);
	}
	else if(el.attachEvent)
	{
			/* Microsoft-Modell */
		el.detachEvent("on"+type, el[type+fn]);
	}
	else
	{
			/* Inline-Modell */
		if(el[type+"_inlinefunc"])
		{
			var idx = util_inArray(el[type+"_inlinefunc"], fn);
			if(idx !== false) {
				util_removeFromArray(el[type+"_inlinefunc"], idx);
			}
			if(el[type+"_inlinefunc"].length == 0) {
				el[type+"_inlinefunc"] = null;
			}
			el["on"+type] = null;
		}
	}
}

/**
* Führt die zu einem Element hinzugefügten Event-Handler beim Inline-Modell aus.
*/
function util_inlineEventHandler(e)
{
	e = util_fixEventObj(e);
	var aFunc = this[e.type + "_inlinefunc"];
	for(var i = 0; i < aFunc.length; i++) {
		aFunc[i](e);
	}
}

/**
* Überprüft ob der übergebene Wert im übergebenen Array vorkommt
*/
function util_inArray(aSearch, val)
{
	for(var i = 0; i < aSearch.length; i++)
	{
		if(aSearch[i] == val) {
			return i;
		}
	}
	
	return false;
}

/**
* Entfernt den eingegebenen Eintrag (Index) vom übergebenen Array
*/
function util_removeFromArray(aOrig, idx)
{
	var len = aOrig.length-1;
	for(var i = idx; i < len; i++)
	{
		aOrig[i] = aOrig[i+1];
	}
		
	aOrig.length--;
	return aOrig;
}

/**
* Setzt den Maus-Cursor für ein Element auf den angegebene Wert
*/
function util_setObjectCursor(el, cursor)
{
	if(cursor && cursor.length && typeof cursor == 'object')
	{
		for(var i = 0; i < cursor.length; i++)
		{
			el.style.cursor = cursor[i];
			if(el.style.cursor == cursor[i])
			{
				break;
			}
		}
		return true;
	}
	else if(typeof cursor == 'string')
	{
		el.style.cursor = cursor;
		return true;
	}
	
	el.style.cursor = 'auto';
}

/**
 * ensures safe priting of a string in javascript
 */
function util_makeJavaScriptSafe(input)
{
	input = input.replace(/"/g, '\"');
	input = input.replace(/'/g, "\'");
	input = input.replace(/\r/g, "\\r");
	input = input.replace(/\n/g, "\\n");
	return input;
}

/**
* Entfernt alle Kindknoten eines HTML-Elements
*/
function util_elementRemoveAllChildNodes(el)
{
	if(el.hasChildNodes())
	{
		while(el.hasChildNodes())
		{
			el.removeChild(el.firstChild);
		}
	}
}

/**
* Parsed einen Listenstring und gibt ein Array zurück
*/
function util_parseDelimitedString(sIn, cDelim)
{
	var aRet = [];
	
	for(var i = 0; i < sIn.length; )
	{
		var s = i;
		var e = s;
		
		var c = sIn.charAt(i);
		if(c == '"' || c == "'")
		{
			s++;
			e = sIn.indexOf(c, s);
			var val = sIn.substring(s, e);
			aRet[aRet.length] = val;
			
			s = e;
			e = sIn.indexOf(cDelim, s);
			if(e == -1) {
				e = sIn.length;
			}
		}
		else
		{
			e = sIn.indexOf(cDelim, s);
			if(e == -1) {
				e = sIn.length;
			}
			var val = sIn.substring(s, e);
			aRet[aRet.length] = val;
		}
		
		i = e+1;
	}
	
	return aRet;
}

/**
* Generiert aus einem übergebenen Formular einen URL-Query-String
*/
function util_formToQueryString(frm)
{
	var queryString = "";
	for(var i = 0; i < frm.elements.length; i++)
	{
		if(i > 0) {
			queryString += "&";
		}
		
		queryString += encodeURIComponent(frm.elements[i].name) + "=" + encodeURIComponent(frm.elements[i].value);
	}
	return queryString;
}
