<?php
/**
 * $Id: functions.php 116 2010-09-24 08:50:49Z kapsl $
 * @copyright (C) 2007 - 2009 Manuel Kaspar
 * @license GNU/GPL
 */
?>
<script type="text/javascript">
<!--
//Get Configuration Files
acl_edit = '<?php echo $this->mySettings['acl_edit']; ?>';
acl_delete_reorder = '<?php echo $this->mySettings['acl_delete_reorder']; ?>';
acl_new_row = '<?php echo $this->mySettings['acl_new_row']; ?>';
menge = <?php echo $this->mySettings['menge']; ?>;
upcount = <?php echo $this->mySettings['upcount']; ?>;
page = <?php echo $this->mySettings['page']; ?>;
reorderflag = <?php echo $this->mySettings['reorderflag']; ?>;
limit = <?php 
	if ($this->mySettings['limit'] != '')  {
		echo $this->mySettings['limit']; 
	} else {
		echo 0;
	}
?>;
number = '<?php echo $number; ?>';
mytable = $('whoplaystable');
option = 'com_eventtableedit';
openflag = 0;

//Global vars
var tmouseX = 0;
var tmouseY = 0;
IE = document.all&&!window.opera;

//Firefox table fix
if (navigator.userAgent.indexOf("Firefox") != -1) {
    if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
         var ffversion = new Number(RegExp.$1)
         if (ffversion >= 4) {
             reduce = 1;
         } else {
            reduce = 0;
         }
    }
}
else
    reduce = 1;

//Add the neccessary Events to the new table
function initEvents() {
	if (menge != 0) {
		for (q = reduce; q < mytable.rows.length; q++) {
			addClickEvent(q);
			addDeleteEvent(q);
		}
	
		if (acl_new_row) {
			addNewRowEvent();
		}
	}
}

//Add Edit Events on a single row
function addClickEvent(row) {
	//Check ACL
	if (!acl_edit) return;
	
	var mycells = mytable.rows[row].cells;
	var sc = getStartCell();
	var ec = getEndCell(mycells.length);
		
	for (a = sc, v = 0; a < ec; a++, v++) {
		mycells[a].onclick = new Function ("", "openfield(" + (row - reduce) + ", " + v + ");");
	}
}

//Add the Delete Event on a single row
function addDeleteEvent(row) {
	//Check ACL
	if (!acl_delete_reorder) return;
	
	var mycells = mytable.rows[row].cells;
	
	document.getElementsByName('jdelete')[row - reduce].onclick = new Function ("", "deleteRow(" + (row - reduce) + ");");
}

//Ads the click Event to the new row button
function addNewRowEvent(sOr) {
	//Check ACL
	if (!acl_new_row) return;
	
	//Check if a new biggestOrdering is given or to use the start value
	var startbig = <?php echo $absbig; ?>;
	(sOr === undefined) ? biOr = startbig : biOr = sOr;	
	
	$('bnewrow').onclick = new Function ("", "newRow(" + biOr + ");");
}

//Look if the upcounting first row is shown
function getStartCell() {
	if (!upcount) {
		return (1);
	}
	return (0);
}

//Look if the action row is shown
function getEndCell(mlength) {
	if (!acl_delete_reorder) {
		return mlength;
	}
	return (mlength - 1);
}

//Send the new content to the database
function sendData(row, cell, number, id, datatpval) {
	if (datatpval == 'TEXT') {
		loadid = 'loaddivinside';
		mychild = $('popupdiv');
	} else {
		loadid = 'loaddivinsidedate';
		mychild = $('popupdivdate');
	}
	showLoad('popupform', loadid);
	
	var fieldcont = $('textfield').value;
	
	if (datatpval.substring(0, 8) == "dropdown")
	    fieldcont = $('textfield').options[$('textfield').selectedIndex].text;
	
	var fforopen = fieldcont;
	fforopen = replaceIt(fforopen, "\n", "");
	fforopen = replaceIt(fforopen, "\r", "");
	fieldcont = replaceIt(fieldcont, "&", "//()||");
	var url = 'index.php?option=' + option + '&task=ajaxsave';
	var post = "openfield=" + encodeURI(fieldcont) +
				"&ic=" + cell +
				"&oc=" + row +
				"&number=" + number +
				"&id=" + id +
				"&date_switch=" + datatpval;
				
        var myAjax = new Request({
		method: 'post',
                url: url,
		data: post,
		onComplete: function (response) {
			//Remove the open window
			mychild.parentNode.removeChild(mychild);
			
			//Change field value
			var resp = response;
			var changeid = 'evtd' + row + cell;
			
			if (datatpval != "BOOLEAN")
			      $(changeid).innerHTML = resp;
			openflag = 0;
		}
	}).send();
	//myAjax.send();
}

//Open a window to edit a cell
function openfield(row, cell) {
	//Check that only one instance of the window is opened
	if (openflag == 1) return;
	openflag = 1;
		
	showLoad('orderform', 'loaddiv');
	
	var diftips = new Object();
	var diftiptext = new Object();
	diftips['INT'] = '<?php echo JTEXT::_('INTTIPTITLE'); ?>';
	diftips['FLOAT'] = '<?php echo JTEXT::_('FLOATTIPTITLE'); ?>';
	diftips['TIME'] = '<?php echo JTEXT::_('TIMETIPTITLE'); ?>';
	diftiptext['INT'] = '<?php echo JTEXT::_('INTTIP'); ?>';
	diftiptext['FLOAT'] = '<?php echo JTEXT::_('FLOATTIP'); ?>';
	diftiptext['TIME'] = '<?php echo JTEXT::_('TIMETIP'); ?>';
		
	//Get ID and Datatype
	var id = $('rowedit_' + row).value;
	var datatp = $('datatparr').value;
	var datatparr = datatp.split(';');
	var datatpval = datatparr[cell];
		
	var url = 'index.php?option=' + option + '&task=ajaxgetfield&oc=' + row + '&ic=' + cell + '&number=' + number + '&id=' + id + '&date_switch=' + datatpval + '&noCache=' + $time();
	var myAjax = new Request({
		method: 'get',
                url: url,
		onSuccess: function (response) {
			var cellcontent = response;
			
			(datatpval == 'TEXT') ? mydivid = 'popupdiv' : mydivid = 'popupdivdate';
			
			var myform = new Element ('form', {
				'id': 'popupform',
				'name': 'popupform',
				'onsubmit': 'return false'
			});
			var mydiv = new Element ('div', {
				'id': mydivid,
				'events': {
					'mousedown': function () {
						startDrag(this);
					}
				}
			});
						
			$('orderform').appendChild(mydiv).appendChild(myform);
			
			if(datatpval == "BOOLEAN") 
			      $('popupdivdate').style.display = 'none';
			
			if (datatpval == "TEXT") {
			      var tiptitle = '<?php echo JTEXT::_('TEXTTIPTITLE'); ?>';
			      var tiptext = '<?php echo JTEXT::_('TEXTTIP'); ?>';
			      openText(cellcontent);
			      addTip('texttipimg', tiptitle, tiptext);
			} else if (datatpval == "DATE") {
			      var tiptitle = '<?php echo JTEXT::_('DATETIPTITLE'); ?>';
			      var tiptext = '<?php echo JTEXT::_('DATETIP'); ?>';
			      openDate(cellcontent, datatpval, row, cell, number, id);
			      addTip('gentipimg', tiptitle, tiptext);
			      addKeyboard(row, cell, number, id, datatpval);
			} else if (datatpval.substring(0, 8) == "dropdown") {
			      var tiptitle = '<?php echo JTEXT::_('DROPDOWNTIPTITLE'); ?>';
			      var tiptext = '<?php echo JTEXT::_('DROPDOWNTIP'); ?>';
			      var whatdrop = datatpval.substring(9);
			      addDropdown(cellcontent, whatdrop);
			      addTip('gentipimg', tiptitle, tiptext);
			      addKeyboard(row, cell, number, id, datatpval);
			} else if (datatpval == "BOOLEAN") {
			      var tiptitle = '';
			      var tiptext = '';
			      exeYesNo(row, cell, number, id, datatpval, cellcontent);
			      addTip('gentipimg', tiptitle, tiptext);
			}
			else {
			      var tiptitle = diftips[datatpval];
			      var tiptext = diftiptext[datatpval];
			      addInputField(cellcontent);
			      addTip('gentipimg', tiptitle, tiptext);
			      addKeyboard(row, cell, number, id, datatpval);    
			}
			
			addButtons(row, cell, number, id, datatpval, mydivid, 0);
			
			if (datatpval != "BOOLEAN") 
			      $('textfield').focus();
			
			$('textfield').addEvents({
				'mousedown': noDrag,
				'mouseup': yesDrag
			});
			$('tiphover').addEvents({
				'mouseover': showTip,
				'mouseout': hideTip
			});
			
			$('loaddiv').parentNode.removeChild($('loaddiv'));
		}
	}).send();
	//myAjax.request();
}

function openText(cellcontent) {
	var myfield = new Element ('textarea', {
		'id': 'textfield',
		'name': 'textfield',
		'rows': '9',
		'cols': '68'
	});	
	myfield.innerHTML = cellcontent;
	$('popupform').appendChild(myfield);
}

function openDate(cellcontent, datatpval, row, cell, number, id) {
	var langclear = '<?php echo JTEXT::_('CLEAR'); ?>';
	var calsrc = '<?php echo $this->baseurl; ?>/templates/system/images/calendar.png';
	var myinput = new Element ('input', {
		'id': 'textfield',
		'type': 'text',
		'value': cellcontent,
		'name': 'mycal',
		'readonly': 'readonly'
	});
	var calimg = new Element ('img', {
		'id': 'mycal2_img',
		'class': 'calendar',
		'alt': 'Calendar',
		'src': calsrc	
	});
	var calspan = new Element ('span', {
		'id': 'clearspan',
		'events': {
			'click': function () {
				$('textfield').value = '';
			}
		}
	});
	calspan.innerHTML = langclear;
	
	$('popupform').appendChild(myinput);
	$('popupform').appendChild(calimg);
	$('popupform').appendChild(calspan);
	
	//Reinitalize the Joomla-Calendar for the dynamically added date-picker
	Calendar.setup({
		inputField     :    "textfield",
		ifFormat       :    "%Y-%m-%d",
		showsTime      :    false,
		button         :    "mycal2_img",
		align		   :    "BR"
	});
}

function addInputField(wcont) {
	var myinput = new Element ('input', {
		'id': 'textfield',
		'type': 'text',
		'value': wcont,
		'name': 'myfield'
	});
	
	$('popupform').appendChild(myinput);
}

//Dropdown
function addDropdown(wcont, whatdrop) {
	    var opt = [];
	    var selind = 0;
	    
	    <?php
	    echo "var dropop = new Array(";
	    for ($a = 0; $a < count($this->mySettings['drpoints']); $a++) {
		  echo "[";
		  for ($b = 1; $b < count($this->mySettings['drpoints'][$a]); $b++) {
			echo '"' . $this->mySettings['drpoints'][$a][$b] . '"';
			
			if ($b != count($this->mySettings['drpoints'][$a]) - 1)
			      echo ',';
		  }
		  echo "]";
		  
		  if ($a != count($this->mySettings['drpoints']) -1)
			echo ',';
	    }
	    echo ");";
	    ?>
	    
	    //If dropdown was deleted in backend
	    if (dropop[whatdrop-1] == null) {
		  alert('<?php echo JTEXT::_('ERR_DROPDOWN_DELETED'); ?>');
		  return false;
	    }
	    
	    var mydrop = new Element('select', {
		  'id': 'textfield',
		  'name': 'dropfield'
	    });
	    
	    //Insert empty first option
	    opt[0] = new Element('option');
	    mydrop.appendChild(opt[0]);
	    
	    for (a = 0; a < dropop[whatdrop-1].length; a++) {
		  if (dropop[whatdrop-1][a] == wcont)
			selind = a + 1;
		  
		  opt[a+1] = new Element('option');
		  opt[a+1].innerHTML = dropop[whatdrop-1][a];
		  mydrop.appendChild(opt[a+1]);
	    }
	    
	    $('popupform').appendChild(mydrop);
	    $('popupform').dropfield.options[selind].selected = true;
}

//Change the status of a yes-no field
function exeYesNo(row, cell, number, id, datatpval, wcont) {
      //Decide what value the field has
      var aw = wcont;
      
      if (aw >= 1) {
	    aw = -1;
      } else if (typeof(aw) == "undefined" || aw == null || aw == "") {
	    aw = 0;	   
      } else if (aw == -1 || aw == 0) {
	    aw++;
      } else {
	    aw = -1;
      }
      
      
      var hidtext = new Element('input', {
	    'type': 'hidden',
	    'id': 'textfield',
	    'value': aw
      });
      $('popupform').appendChild(hidtext);
      
      sendData(row, cell, number, id, datatpval);
      
      var changeid = 'evtd' + row + cell;
      var imgsrc = '<img src="';
						      
      if (aw == 0) {
	    imgsrc += '<?php echo $this->baseurl; ?>/components/com_eventtableedit/template/images/cross.png';
      }
      else if (aw == 1) {
	    imgsrc +=  '<?php echo $this->baseurl; ?>/components/com_eventtableedit/template/images/tick.png';
      }
      imgsrc += '">';
      $(changeid).innerHTML = imgsrc;
      
      if (aw == -1) 
	    $(changeid).innerHTML = "&nbsp;";
}

//Built an tooltip - because normal joomla tooltips doesn't work with dynamically added Elements
function addTip(tclass, tiptitle, tiptext) {

	var srcimg = '<?php echo $this->baseurl; ?>/includes/js/ThemeOffice/tooltip.png';
	var newtip = new Element ('img', {
		'id': 'tiphover',
		'class': tclass,
		'src': srcimg
	});
	var tooldiv = new Element ('div', {
		'id': 'mytip',
		'class': 'tool-tip',
		'style': 'visibility: hidden;'
	});
	var innerdiv = new Element ('div');
	var tooltitle = new Element ('div', {
		'class': 'tool-title'
	});
	var headspan = new Element ('span');
	headspan.setHTML(tiptitle); 
	var textdiv = new Element ('div', {
		'class': 'tool-text'
	});
	var textspan = new Element ('span');
	textspan.setHTML(tiptext);
	
	$('popupform').appendChild(newtip);
	$('popupform').appendChild(tooldiv).appendChild(innerdiv).appendChild(tooltitle).appendChild(headspan).parentNode.parentNode.appendChild(textdiv).appendChild(textspan);
	
	//For IE
	hideTip();
}

//Makes it possible to send the content by pressing enter
function addKeyboard(row, cell, number, id, datatpval) {

	window.document.onkeydown = function(e) {
		if(!e) e = window.event; 
		if (e.keyCode == '13') {
			if (checkValues(datatpval)) {
				sendData(row, cell, number, id, datatpval);
				removeKeyboard();
			}
			return false;
		}
	}
}

//Removes the keyboard event
function removeKeyboard() {
	window.document.onkeydown = null;
}

//Add the OK- and Cancel-Button
function addButtons(row, cell, number, id, datatpval, toid, eventmethod) {
	var okbutton = new Element ('div', {
		'id': 'popupbutton',
		'events': {
			'click': function () {
				//For the edit events
				if (eventmethod == 0) {
					if (checkValues(datatpval)) {
						sendData(row, cell, number, id, datatpval);
						removeKeyboard();
					}
				} else if (eventmethod == 1) {
					//For the delete window
					deleteRowExe(row);
					removeKeyboard();
				}
			}
		}
	});
	var cancelbutton = new Element ('div', {
		'id': 'popupbutton2',
		'events': {
			'click': function () {
				var mychild = $(toid);
				mychild.parentNode.removeChild(mychild);
				openflag = 0;
				removeKeyboard();
			}
		}
	});	
	
	$(toid).appendChild(okbutton);
	$(toid).appendChild(cancelbutton);
}

function checkValues(datatpval) {
	var tf = $('textfield');
	var tvalue = tf.value;
	
	if (tvalue == "") return true;
	
	switch (datatpval) {
		case 'INT':
			var err1 = '<?php echo JTEXT::_('ERR_NO_INT'); ?>';
			var parsed = parseInt(tvalue);
			
			if (isNaN(parsed)) {
				tf.value = err1;
				return false;
			}
			break;
		case 'FLOAT':
			var err1 = '<?php echo JTEXT::_('ERR_NO_FLOAT'); ?>';
			var parsed = tvalue.replace(',', '.');
			parsed = parseFloat(parsed);
			
			if (isNaN(parsed)) {
				tf.value = err1;
				return false;
			}
			break;
		case 'TIME':
			var err1 = '<?php echo JTEXT::_('ERR_NO_TIME'); ?>';
			var parsed = tvalue;
			isTime = true;
			parr = tvalue.split(':');
			
			if (parr.length < 2 || parr.length > 3) {
				isTime = false;
			}
			for (g = 0; g < parr.length; g++) {
				pcheck = parseInt(parr[g]);
				if (isNaN(pcheck)) {
					isTime = false;
				} else if (g > 0) {
					if (parr[g] < 0 || parr[g] > 60) {
						isTime = false;
					}
				}
			}			
										
			if (!isTime) {
				tf.value = err1;
				return false;
			}
			break;
		default:
			return true;
	}
	
	tf.value = parsed;
	return true;
}

function showTip(ereignis) {
	//Get current mouse-position
	var tmouseX = (IE) ? window.event.clientX : ereignis.pageX;
	var tmouseY = (IE) ? window.event.clientY : ereignis.pageY;
	$('mytip').style.visibility = 'visible';
	var offX = tmouseX - $('tiphover').offsetLeft;
	var offY = tmouseY - $('tiphover').offsetTop;
								   
	//Give Element new coordiantes
	$('mytip').style.left = (tmouseX - offX + 20) + "px";
	$('mytip').style.top = (tmouseY - offY + 20) + "px";   
}
						
function hideTip(ereignis) {
	$('mytip').style.visibility = 'hidden';
}

//Show the AJAX-Loading Symbol
function showLoad(appendid, loadid) {
	var loaddiv = new Element ('div', {
		'id': loadid
	});
	var loadimg = new Element ('img', {
		'src': '<?php echo $this->baseurl; ?>/components/' + option + '/template/images/ajax-loader.gif'
	});
	
	//Looks nicer inside the date-box
	try {
		$('tiphover').style.display = 'none';
	} catch (e) {}
				
	$(appendid).appendChild(loaddiv).appendChild(loadimg);
}

function deleteRow(row) {
	if (openflag == 1) return;
	openflag = 1;
	
	showLoad('orderform', 'loaddiv');
	var dodelete = '<?php echo JTEXT::_('REALLY_DELETE'); ?>';
	
	var mydiv = new Element ('div', {
		'id': 'popupdivdate',
		'events': {
			'mousedown': function () {
				startDrag(this);
			}
		}
	});
	mydiv.innerHTML = '<b>' + dodelete + '</b>';
	
	$('orderform').appendChild(mydiv);
	addButtons(row, '', '', '', '', 'popupdivdate', 1);	
	
	$('loaddiv').parentNode.removeChild($('loaddiv'));
}

function deleteRowExe(row) {
	showLoad('popupdivdate', 'loaddivinsidedate');
	
	var id = $('rowedit_' + row).value;
	var url = 'index.php?option=' + option + '&task=deleteExe&number=' + number + '&id=' + id + '_noCache=' + $time();
	var myAjax = new Request({
		method: 'get',
                url: url,
		onComplete: function (response) {
			//Delete the row
			$('evtd' + row + '0').parentNode.setAttribute('id', 'markDelete');
			$('markDelete').parentNode.removeChild($('markDelete'));
			
			//Delete the hidden field
			$('rowedit_' + row).parentNode.removeChild($('rowedit_' + row));
			
			var trvalue = 'linecolor1';
			var trvalue2 = 'linecolor2';
			
			//Update the table
			for (w = reduce, l = 0; w < (mytable.rows.length); w++, l++) {
				//Update the linecolors
				(((w - reduce) % 2) == 0) ? atr = trvalue : atr = trvalue2;
				mytable.rows[w].className = atr;
				
				//Update first row upcount
				if (upcount == 0) {
					mytable.rows[w].cells[0].className = 'evtdupcount' + l;
					mytable.rows[w].cells[0].innerHTML = ((page - 1) * limit) + l + 1;
				}
				
				if (acl_delete_reorder) {
				        if (reorderflag == 0) {
						//Update the ordering input field
						var inputof = getElementsByClassName('ordering')[w - reduce];
						inputof.id = 'sortieren_' + l;
						inputof.name = 'sortieren_' + l;
					}
					
					//Update hidden id field
					var hiddenif = getElementsByClassName('hiddenrowe')[w - reduce];
					hiddenif.id = 'rowedit_' + l;
					hiddenif.name = 'rowedit_' + l;
				}
				
				//Update class and id of the single cells
				mycells = mytable.rows[w].cells;
				for (c = getStartCell(), d = 0; c < getEndCell(mycells.length); c++, d++) {
					mycells[c].id = 'evtd' + l + d;
					mycells[c].className = 'evtd' + l + d;
				}
				
				//Update the Delete Event
				addDeleteEvent(w);
				
				//Update the single Cell-Edit-Events
				addClickEvent(w);
			}
			//Get the biggest ordering number to give it to the Event for new rows
			var biggestOrdering = response;
			addNewRowEvent(biggestOrdering);
			
			$('popupdivdate').parentNode.removeChild($('popupdivdate'));
			openflag = 0;
		}
	}).send();
	//myAjax.request();
}

function newRow(biOr) {
	showLoad('orderform', 'loaddiv');
	
	biOr = parseInt(biOr) + 1;
	var url = 'index.php?option=' + option + '&task=ajaxnewrow&number=' + number + '&biggestOrdering=' + biOr + '_noCache=' + $time();
	var myAjax = new Request({
		method: 'get',
                url: url,
		onComplete: function (response) {
			
			//Get number of cells
			var datatp = $('datatparr').value;
			var datatparr = datatp.split(';');
			var mycells = datatparr.length;
			
			if (acl_delete_reorder) 
				mycells++;
			if (!upcount)
				mycells++;
						
			var id = response;
			var myrows = mytable.rows.length;
			var startcell = getStartCell();
			var endcell = getEndCell(mycells);
			var myrowsr = myrows - reduce;
										
			//Insert Row at the end and define linecolor
			mytable.insertRow(-1);
			var lc = 'linecolor';
			var ther = parseInt(myrows);
			(((ther - reduce) % 2) == 0) ? lc += '1' : lc += '2';
			mytable.rows[ther].className = lc;			
			
			//Insert Cells
			for (a = 0; a < mycells; a++) {
				mytable.rows[myrows].insertCell(-1);
			}
			
			//Optional first row
			if (startcell == 1) {
				var firstr = mytable.rows[myrows].cells[0];
				firstr.setAttribute('id', 'evtdupcount' + myrowsr, true);
				firstr.innerHTML = ((page - 1) * limit) + myrows + 1 - reduce;
			}
			
			//Normal cells
			for (a = startcell, b = 0; a < endcell; a++, b++) {
				var pathc = mytable.rows[myrows].cells[a];
				pathc.setAttribute('id', 'evtd' + myrowsr + b);
				pathc.setAttribute('class', 'evtd' + myrowsr + b);
				pathc.innerHTML = '&nbsp;';			
			}
			
			//Action cell
			if (acl_delete_reorder) {
				var dspan = new Element ('span', {
					'id': 'jdelete',
					'name': 'jdelete'
				});
				var dimg = new Element ('img', {
					'src': '<?php echo $this->baseurl; ?>/components/' + option + '/template/images/publish_x.png',
					'border': '0'
				});
				var rinput = new Element ('input', {
					'type': 'text',
					'id': 'sortieren_' + myrowsr,
					'name': 'sortieren_' + myrowsr,
					'class': 'ordering',
					'size': '1',
					'value': biOr
				});
				
			
				var apath = mytable.rows[myrows].cells[mycells -1];
				apath.appendChild(dspan).appendChild(dimg);
				apath.appendChild(rinput);
			}
			
			//Add the hidden field
			var idhid = new Element ('input', {
				'type': 'hidden',
				'id': 'rowedit_' + myrowsr,
				'name': 'rowedit_' + myrowsr,
				'class': 'hiddenrowe',
				'value': id
			});
			$('hidearea').appendChild(idhid);
			
			//Add Events
			addClickEvent(myrows);
			addDeleteEvent(myrows);
			
			//Update Event of the New-Row Button
			addNewRowEvent(biOr);
			
			$('loaddiv').parentNode.removeChild($('loaddiv'));
		}
	}).send();
	//myAjax.request();
}

function replaceIt(string,suchen,ersetzen) {
	var ausgabe = string;
	
	while (ausgabe.indexOf(suchen)>-1) {
		var pos= ausgabe.indexOf(suchen);
		ausgabe = (ausgabe.substring(0, pos) + ersetzen + ausgabe.substring((pos + suchen.length), ausgabe.length));
	}
	
	return ausgabe;
}

function getElementsByClassName(c) {
	var array = [];
	var tags = document.getElementsByTagName("*");
	
	for (var i = 0, len = tags.length; i < len; i++) {
		if (tags[i].className == c) {
			array[array.length] = tags[i];
		}
	}
	return array;
}

window.addEvent('load', function() {
	initEvents();
	document.onmousemove = doDrag;  // call doDrag, when mouse is moved
    document.onmouseup = stopDrag;  // call stopDrag, when mouse is released
});

-->
</script>

