function showTicketFlagList(e, firmenID)
{
	($('flagTicketListDiv')) ? $('flagTicketListDiv').remove() : true;
	var ImgElement = Event.element(e);
	if (ImgElement)
	{
		var divElement = document.createElement('div');
		divElement.id = 'flagTicketListDiv';
		document.body.appendChild(divElement);
		divElement.style.top = ImgElement.cumulativeOffset()[1] + ImgElement.getHeight() + 'px';
		divElement.style.left = ImgElement.cumulativeOffset()[0] + ImgElement.getWidth() + 'px';
		divElement.innerHTML = show_load(true);
		var url = 'ajax/srv/ticket_ajax.php?t=showTicketListFlags&firmenID='+encodeURIComponent(firmenID);
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (t)
				{
					divElement.innerHTML = t.responseText;
				}
			}
		);
	}
}

function closeTicketFlagList()
{
	($('flagTicketListDiv')) ? $('flagTicketListDiv').remove() : true;
}

function showFlagsZN(mt, typ, firmenID)
{
	var ele = null;
	switch (typ)
	{
		case 'zentrale':
			($('zentrale_flag_img_'+mt)) ? ele = $('zentrale_flag_img_'+mt) : true;
			break;
		case 'niederlassung':
			($('niederlassung_flag_img_'+mt)) ? ele = $('niederlassung_flag_img_'+mt) : true;
			break;
	}
	if (ele)
	{
		$('znDiv').style.left = ele.cumulativeOffset()[0] + ele.getWidth()+'px';
		$('znDiv').style.top = ele.cumulativeOffset()[1] + ele.getHeight()+'px';
		$('znDiv').innerHTML = '<div style="padding: 5px; border-bottom: 1px solid #999;"><img src=\"media/hp/ajaxrequest.gif\"></div>';
		$('znDiv').show();
		var url = 'ajax/srv/zn.php?t='+encodeURIComponent(typ)+'&f='+encodeURIComponent(firmenID);
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (transport)
				{
					var response = transport.responseXML;
					var zn_stylesheet = loadStyleSheet('ajax/zn.xsl');
					parseStyleSheet(zn_stylesheet, response, $('znDiv'));
				}
			}
		);
	}
}

function showHideMenu(menuName, what)
{
	var menu_obj = null;
	var menu_div_obj = null;
	var menu_div_inner_obj = null;
	var container_obj = $('banner_table');
	switch (menuName)
	{
		case 'ticket':
		case 'firma':
		case 'wawi':
		case 'geraete':
		case 'support':
		case 'admin':
			menu_div_obj = $(menuName);
			menu_obj = $('td_menu_'+menuName);
			menu_div_inner_obj = $(menuName+'_table_menu');
			break;
	}
	if (menu_obj && menu_div_obj && container_obj && menu_div_inner_obj)
	{
		var table_r = container_obj.offsetWidth + container_obj.cumulativeOffset()[0];
		var div_r = menu_obj.cumulativeOffset()[0] + parseInt(menu_div_inner_obj.width);
		
		menu_div_obj.style.top = menu_obj.cumulativeOffset()[1] + menu_obj.offsetHeight;
		if (div_r > table_r)
		{
			menu_div_obj.style.left = (menu_obj.cumulativeOffset()[0] - 1) - (div_r - table_r) + 2;
		}
		else
		{
			menu_div_obj.style.left = menu_obj.cumulativeOffset()[0] - 1;
		}
		if (what == true)
		{
			menu_obj.className = 'menu_bg';
			menu_div_obj.show();
		}
		else
		{
			menu_obj.className = 'menu_bg2';
			menu_div_obj.hide();
		}
	}
}

function togglePW(field)
{
	$(field).className = ($(field).className == 'pwHidden') ? 'pwVisible' : 'pwHidden';
}

function listTogglePW(id)
{
	if ($('pwHid_' + id).visible() == true) {
		$('pwVis_' + id).show();
		$('pwHid_' + id).hide();
		$('pwField_' + id).show();
	} else {
		$('pwVis_' + id).hide();
		$('pwHid_' + id).show();
		$('pwField_' + id).hide();
	}
}

function ajax_delete_item(typ, id, trID, async)
{
	async = (async == false) ? false : true;
	var ret = false;
	new Ajax.Request('ajax/srv/delete_ajax.php?t=' + encodeURIComponent(typ) + '&id=' + encodeURIComponent(id), {
		asynchronous: async,
		onSuccess: function(trans) {
			var json = trans.responseText.evalJSON();
			if (json.frage != '') {
				if (confirm(json.frage)) {
					new Ajax.Request('ajax/srv/delete_ajax.php?t=' + encodeURIComponent(typ) + '&id=' + encodeURIComponent(id) + '&s=do', {
						asynchronous: async,
						onSuccess: function(trans2) {
							if (trID != '') {
								$(trID).remove();
							}
							ret = true;
						}
					});
				}
			} else {
				if (json.fehler != '') {
					alert(json.fehler);
				}
			}
		}
	});
	return ret;
}

function komponente_kopieren(kompID, zugewiesen, reloadpage)
{
	var ret = false;
	if (confirm(getLang("dev", "pcComp_copy")))
	{
		var zuweisung_behalten = 'false';
		if (zugewiesen == "true")
		{
			if (confirm(getLang("dev", "pcComp_copyAssigned")))
			{
				zuweisung_behalten = 'true';
			}
		}
		var url = 'ajax/srv/komponente_kopieren.php?id='+encodeURIComponent(kompID)+
							'&zuweisung='+encodeURIComponent(zuweisung_behalten);
		new Ajax.Request(url,
			{
				method: 'get',
				onSuccess: function (transport)
				{
					var response = transport.responseText;
					if (response == 'ok')
					{
						alert(getLang("dev", "pcComp_copyOK"));
						ret = true;
						if (reloadpage == true)
						{
							location.reload();
						}
					}
					else
					{
						alert(getLang("dev", "pcComp_copyErr"));
					}
				}
			}
		);
	}
	return ret;
}

function showKompRows(rowID)
{
	var rows = $$('tr.komp_tr_'+rowID);
	if (rows)
	{
		for (var i = 0; i < rows.length; i++)
		{
			rows[i].show();
		}
	}
	var toggleimg = $('komp_toggle_img_'+rowID);
	var togglehref = $('komp_toggle_href_'+rowID);
	if (toggleimg && togglehref)
	{
		toggleimg.src = 'media/katbrowser/tree1.gif';
		togglehref.onclick = function (event)
		{
			hideKompRows(rowID);
			return false;
		}
	}
}

function hideKompRows(rowID)
{
	var rows = $$('tr.komp_tr_'+rowID);
	if (rows)
	{
		for (var i = 0; i < rows.length; i++)
		{
			rows[i].hide();
		}
	}
	var toggleimg = $('komp_toggle_img_'+rowID);
	var togglehref = $('komp_toggle_href_'+rowID);
	if (toggleimg && togglehref)
	{
		toggleimg.src = 'media/katbrowser/tree2.gif';
		togglehref.onclick = function (event)
		{
			showKompRows(rowID);
			return false;
		}
	}
}

function showAllKompRows()
{
	var rows = $$('tr.komp_toggle_row');
	if (rows)
	{
		for (var i = 0; i < rows.length; i++)
		{
			rows[i].show();
		}
	}
	var rowIDs = $$('input.komp_toggle_id');
	if (rowIDs)
	{
		for (var i = 0; i < rowIDs.length; i++)
		{
			showKompRows(rowIDs[i].value);
		}
	}
}

function hideAllKompRows()
{
	var rows = $$('tr.komp_toggle_row');
	if (rows)
	{
		for (var i = 0; i < rows.length; i++)
		{
			rows[i].hide();
		}
	}
	var rowIDs = $$('input.komp_toggle_id');
	if (rowIDs)
	{
		for (var i = 0; i < rowIDs.length; i++)
		{
			hideKompRows(rowIDs[i].value);
		}
	}
}

function sa_saveCheckboxesInSession(firmenID)
{
	var verb_arr = $$('input.verbuchen_checkbox');
	var verb_ids = new Array();
	if (verb_arr.length > 0)
	{
		for (var i = 0; i < verb_arr.length; i++)
		{
			if (verb_arr[i].checked == true)
			{
				verb_ids[i] = verb_arr[i].value;
			}
		}
	}
	if (verb_ids.length > 0)
	{
		var url = 'ajax/srv/sa_saveCheckboxesInSession.php';
		new Ajax.Request(url,
			{
				method: 'post',
				asynchronous: false,
				postBody: 'verb_ids='+encodeURIComponent(verb_ids)+'&firmenID='+encodeURIComponent(firmenID),
				onSuccess: function (transport) {}
			}
		);
	}
	return true;
}

function trimString(theString)
{
	var newString = theString.replace(/^ +/, '');
	newString = newString.replace(/ +$/, '');
	return newString;
}

function toggleDokuContainer(dokuID)
{
	if ($('moveDokuContainer') && $('moveDokuContainer_dokuID'))
	{
		$('moveDokuContainer').toggle();
		$('moveDokuContainer_dokuID').innerHTML = dokuID;
		if ($('moveDokuContainer').style.display != 'none')
		{
			b_loadBrowser('doku', 'doku2', '', '', '', '', 'move');
		}
	}
}

function switchTaskSerie(divID, sectionID)
{
	($('taskSerieTaeglichContainer_'+divID)) ? $('taskSerieTaeglichContainer_'+divID).hide() : true;
	($('taskSerieWoechentlichContainer_'+divID)) ? $('taskSerieWoechentlichContainer_'+divID).hide() : true;
	($('taskSerieMonatlichContainer_'+divID)) ? $('taskSerieMonatlichContainer_'+divID).hide() : true;
	($('taskSerieJaehrlichContainer_'+divID)) ? $('taskSerieJaehrlichContainer_'+divID).hide() : true;
	($('taskSerieNaviLink_0_'+divID)) ? $('taskSerieNaviLink_0_'+divID).className = 'switch_no_selected2' : true;
	($('taskSerieNaviLink_1_'+divID)) ? $('taskSerieNaviLink_1_'+divID).className = 'switch_no_selected2' : true;
	($('taskSerieNaviLink_2_'+divID)) ? $('taskSerieNaviLink_2_'+divID).className = 'switch_no_selected2' : true;
	($('taskSerieNaviLink_3_'+divID)) ? $('taskSerieNaviLink_3_'+divID).className = 'switch_no_selected2' : true;
	switch (sectionID)
	{
		case '1':
			($('taskSerieWoechentlichContainer_'+divID)) ? $('taskSerieWoechentlichContainer_'+divID).show() : true;
			($('taskSerie_serieTyp_'+divID)) ? $('taskSerie_serieTyp_'+divID).value = 1 : true;
			($('taskSerieNaviLink_1_'+divID)) ? $('taskSerieNaviLink_1_'+divID).className = 'switch_selected2' : true;
			break;
		case '2':
			($('taskSerieMonatlichContainer_'+divID)) ? $('taskSerieMonatlichContainer_'+divID).show() : true;
			($('taskSerie_serieTyp_'+divID)) ? $('taskSerie_serieTyp_'+divID).value = 2 : true;
			($('taskSerieNaviLink_2_'+divID)) ? $('taskSerieNaviLink_2_'+divID).className = 'switch_selected2' : true;
			break;
		case '3':
			($('taskSerieJaehrlichContainer_'+divID)) ? $('taskSerieJaehrlichContainer_'+divID).show() : true;
			($('taskSerie_serieTyp_'+divID)) ? $('taskSerie_serieTyp_'+divID).value = 3 : true;
			($('taskSerieNaviLink_3_'+divID)) ? $('taskSerieNaviLink_3_'+divID).className = 'switch_selected2' : true;
			break;
		default:
			($('taskSerieTaeglichContainer_'+divID)) ? $('taskSerieTaeglichContainer_'+divID).show() : true;
			($('taskSerie_serieTyp_'+divID)) ? $('taskSerie_serieTyp_'+divID).value = 0 : true;
			($('taskSerieNaviLink_0_'+divID)) ? $('taskSerieNaviLink_0_'+divID).className = 'switch_selected2' : true;
			break;
	}
}

function check_date_len(fieldID)
{
	var ret = true;
	if ($(fieldID))
	{
		if ($(fieldID).value.search(/^[0-9]{6}$/) == -1)
		{
			ret = false;
		}
	}
	return ret;
}

function askDeleteMail()
{
	if (confirm(getLang("bug", "edit_delEmail")))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function removeValue(fieldID)
{
	if ($(fieldID))
	{
		$(fieldID).value = '';
	}
}

function encodeString(form)
{
	form.loginPW.value = hex_md5(form.loginPW.value);
}

function TT(e, what, divtext)
{
	if ($('ttdiv'))
	{
  	switch (what)
  	{
  		case true:
  			$('ttdiv').innerHTML = divtext;
  			$('ttdiv').style.left = (Event.pointerX(e)+15)+'px';
  			$('ttdiv').style.top = (Event.pointerY(e)+15)+'px';
  			$('ttdiv').show();
  			break;
  		case false:
  			$('ttdiv').hide();
  			$('ttdiv').innerHTML = '';
  			break;
  	}
	}
}

function v4_showMenu(what)
{
	var rightOutline = $('v4_pageContainer').cumulativeOffset()[0] + $('v4_pageContainer').getWidth()-1;
	//rightOutline -= (Prototype.Browser.IE) ? 11 : 3;
	var addTopHeight = 1;
	if (navigator.userAgent.match(/MSIE 8.0/) || navigator.userAgent.match(/Opera/)) {
		addTopHeight = 0;
	}
	switch (what)
	{
		case 'info':
			if ($('v4_menuLinkInfo') && $('v4_infoMenu'))
			{
				if ($('v4_menuLinkInfoHref'))
				{
					$('v4_menuLinkInfoHref').style.backgroundPosition = 'bottom';
				}
				if ($('v4_menuLinkInfo').cumulativeOffset()[0] + $('v4_infoMenu').getWidth() > rightOutline)
				{
					$('v4_infoMenu').style.left = (rightOutline-$('v4_infoMenu').getWidth())+'px';
				}
				else
				{
					$('v4_infoMenu').style.left = $('v4_menuLinkInfo').cumulativeOffset()[0]+'px';
				}
				$('v4_infoMenu').style.top = ($('v4_menuLinkInfo').cumulativeOffset()[1]+$('v4_menuLinkInfo').getHeight()+addTopHeight)+'px';
				$('v4_infoMenu').show();
			}
			break;
		case 'firma':
			if ($('v4_menuLinkFirma') && $('v4_firmaMenu'))
			{
				if ($('v4_menuLinkFirmaHref'))
				{
					$('v4_menuLinkFirmaHref').style.backgroundPosition = 'bottom';
				}
				if ($('v4_menuLinkFirma').cumulativeOffset()[0] + $('v4_firmaMenu').getWidth() > rightOutline)
				{
					$('v4_firmaMenu').style.left = (rightOutline-$('v4_firmaMenu').getWidth())+'px';
				}
				else
				{
					$('v4_firmaMenu').style.left = $('v4_menuLinkFirma').cumulativeOffset()[0]+'px';
				}
				$('v4_firmaMenu').style.top = ($('v4_menuLinkFirma').cumulativeOffset()[1]+$('v4_menuLinkFirma').getHeight()+addTopHeight)+'px';
				$('v4_firmaMenu').show();
			}
			break;
		case 'wawi':
			if ($('v4_menuLinkWawi') && $('v4_wawiMenu'))
			{
				if ($('v4_menuLinkWawiHref'))
				{
					$('v4_menuLinkWawiHref').style.backgroundPosition = 'bottom';
				}
				if ($('v4_menuLinkWawi').cumulativeOffset()[0] + $('v4_wawiMenu').getWidth() > rightOutline)
				{
					$('v4_wawiMenu').style.left = (rightOutline-$('v4_wawiMenu').getWidth())+'px';
				}
				else
				{
					$('v4_wawiMenu').style.left = $('v4_menuLinkWawi').cumulativeOffset()[0]+'px';
				}
				$('v4_wawiMenu').style.top = ($('v4_menuLinkWawi').cumulativeOffset()[1]+$('v4_menuLinkWawi').getHeight()+addTopHeight)+'px';
				$('v4_wawiMenu').show();
			}
			break;
		case 'ticket':
			if ($('v4_menuLinkTicket') && $('v4_ticketMenu'))
			{
				if ($('v4_menuLinkTicketHref'))
				{
					$('v4_menuLinkTicketHref').style.backgroundPosition = 'bottom';
				}
				if ($('v4_menuLinkTicket').cumulativeOffset()[0] + $('v4_ticketMenu').getWidth() > rightOutline)
				{
					$('v4_ticketMenu').style.left = (rightOutline-$('v4_ticketMenu').getWidth())+'px';
				}
				else
				{
					$('v4_ticketMenu').style.left = $('v4_menuLinkTicket').cumulativeOffset()[0]+'px';
				}
				$('v4_ticketMenu').style.top = ($('v4_menuLinkTicket').cumulativeOffset()[1]+$('v4_menuLinkTicket').getHeight()+addTopHeight)+'px';
				$('v4_ticketMenu').show();
			}
			break;
		case 'geraete':
			if ($('v4_menuLinkGeraete') && $('v4_geraeteMenu'))
			{
				if ($('v4_menuLinkGeraeteHref'))
				{
					$('v4_menuLinkGeraeteHref').style.backgroundPosition = 'bottom';
				}
				if ($('v4_menuLinkGeraete').cumulativeOffset()[0] + $('v4_geraeteMenu').getWidth() > rightOutline)
				{
					$('v4_geraeteMenu').style.left = (rightOutline-$('v4_geraeteMenu').getWidth())+'px';
				}
				else
				{
					$('v4_geraeteMenu').style.left = $('v4_menuLinkGeraete').cumulativeOffset()[0]+'px';
				}
				$('v4_geraeteMenu').style.top = ($('v4_menuLinkGeraete').cumulativeOffset()[1]+$('v4_menuLinkGeraete').getHeight()+addTopHeight)+'px';
				$('v4_geraeteMenu').show();
			}
			break;
		case 'support':
			if ($('v4_menuLinkSupport') && $('v4_supportMenu'))
			{
				if ($('v4_menuLinkSupportHref'))
				{
					$('v4_menuLinkSupportHref').style.backgroundPosition = 'bottom';
				}
				if ($('v4_menuLinkSupport').cumulativeOffset()[0] + $('v4_supportMenu').getWidth() > rightOutline)
				{
					$('v4_supportMenu').style.left = (rightOutline-$('v4_supportMenu').getWidth())+'px';
				}
				else
				{
					$('v4_supportMenu').style.left = $('v4_menuLinkSupport').cumulativeOffset()[0]+'px';
				}
				$('v4_supportMenu').style.top = ($('v4_menuLinkSupport').cumulativeOffset()[1]+$('v4_menuLinkSupport').getHeight()+addTopHeight)+'px';
				$('v4_supportMenu').show();
			}
			break;
	}
}

function v4_hideMenu(what)
{
	switch (what)
	{
		case 'info':
			if ($('v4_infoMenu'))
			{
				$('v4_infoMenu').hide();
			}
			if ($('v4_menuLinkInfoHref'))
			{
				$('v4_menuLinkInfoHref').style.backgroundPosition = 'top';
			}
			break;
		case 'firma':
			if ($('v4_firmaMenu'))
			{
				$('v4_firmaMenu').hide();
			}
			if ($('v4_menuLinkFirmaHref') && $('v4_menuLinkFirma') && $('v4_menuLinkFirma').hasClassName('active') == false)
			{
				$('v4_menuLinkFirmaHref').style.backgroundPosition = 'top';
			}
			break;
		case 'wawi':
			if ($('v4_wawiMenu'))
			{
				$('v4_wawiMenu').hide();
			}
			if ($('v4_menuLinkWawiHref') && $('v4_menuLinkWawi') && $('v4_menuLinkWawi').hasClassName('active') == false)
			{
				$('v4_menuLinkWawiHref').style.backgroundPosition = 'top';
			}
			break;
		case 'ticket':
			if ($('v4_ticketMenu'))
			{
				$('v4_ticketMenu').hide();
			}
			if ($('v4_menuLinkTicketHref') && $('v4_menuLinkTicket') && $('v4_menuLinkTicket').hasClassName('active') == false)
			{
				$('v4_menuLinkTicketHref').style.backgroundPosition = 'top';
			}
			break;
		case 'geraete':
			if ($('v4_geraeteMenu'))
			{
				$('v4_geraeteMenu').hide();
			}
			if ($('v4_menuLinkGeraeteHref') && $('v4_menuLinkGeraete') && $('v4_menuLinkGeraete').hasClassName('active') == false)
			{
				$('v4_menuLinkGeraeteHref').style.backgroundPosition = 'top';
			}
			break;
		case 'support':
			if ($('v4_supportMenu'))
			{
				$('v4_supportMenu').hide();
			}
			if ($('v4_menuLinkSupportHref') && $('v4_menuLinkSupport') && $('v4_menuLinkSupport').hasClassName('active') == false)
			{
				$('v4_menuLinkSupportHref').style.backgroundPosition = 'top';
			}
			break;
	}
}

function reCallSession()
{
  if ($('keep_alive_img')) {
    var now = new Date();
    var imgsrc = 'media/hp/keep_alive.png?t='+encodeURIComponent(now.getTime());
    $('keep_alive_img').src = imgsrc;
    window.setTimeout(reCallSession, 60000);
  }
}

function v4_fav()
{
	if ($('favlist'))
	{
		if ($('v4_favIcon'))
		{
			$('favlist').style.left = $('v4_favIcon').cumulativeOffset()[0]+'px';
			$('favlist').style.top = ($('v4_favIcon').cumulativeOffset()[1] + $('v4_menuRowContainer').getHeight()) + 'px';
		}
		if ($('ajaxSucheContainerV4'))
		{
			$('ajaxSucheContainerV4').hide();
		}
		if ($('v4_firmenSucheInfoContainer'))
		{
			$('v4_firmenSucheInfoContainer').hide();
		}
		$('favlist').toggle();
	}
}

function toggleRowsByClass(theClassName, theImageID, mini)
{
	var theDisplay = '';
	if ($$('tr.'+theClassName))
	{
		for (var i = 0; i < $$('tr.'+theClassName).length; i++)
		{
			$$('tr.'+theClassName)[i].toggle();
			theDisplay = $$('tr.'+theClassName)[i].style.display;
		}
	}
	if ($(theImageID))
	{
		if (theDisplay == 'none')
		{
			$(theImageID).src = (mini) ? 'media/katbrowser/tree2_mini.gif' : 'media/katbrowser/tree2.gif';
		}
		else
		{
			$(theImageID).src = (mini) ? 'media/katbrowser/tree1_mini.gif' : 'media/katbrowser/tree1.gif';
		}
	}
}

function toggle2DivsById(divID_1, divID_2)
{
  if ($(divID_1)) $(divID_1).toggle();
  if ($(divID_2)) $(divID_2).toggle();
}

function toggleDivById(theDivID, theImageID, mini)
{
	var theDisplay = '';
	if ($(theDivID))
	{
		$(theDivID).toggle();
		theDisplay = $(theDivID).style.display;
	}
	if ($(theImageID))
	{
		if (theDisplay == 'none')
		{
			$(theImageID).src = (mini) ? 'media/katbrowser/tree2_mini.gif' : 'media/katbrowser/tree2.gif';
		}
		else
		{
			$(theImageID).src = (mini) ? 'media/katbrowser/tree1_mini.gif' : 'media/katbrowser/tree1.gif';
		}
	}
}

function showInfoDivContainer(theText, theClass)
{
	var delay = 2500;
	if ((typeof theClass != 'undefined') && (theClass != '')) {
		$('infoDivContainer').className = theClass;
		if (theClass == 'fehler') {
			delay = 5000;
		}
		if (theClass == 'ajax') {
			delay = 0;
		}
	}
	else {
		$('infoDivContainer').className = 'ok';
	}
	if ($('infoDivContainer'))
	{
		//$('infoDivContainer').style.top = (300 + document.body.scrollTop) + 'px';
		$('infoDivContainer').innerHTML = theText;
		new Effect.Opacity('infoDivContainer', {
				from: 0,
				to: 1,
				duration: 0,
				beforeStart: function (effect) {
					effect.element.show();
				}
			}
		);
		if (typeof infoDivTimeout != 'undefined') {
			window.clearTimeout(infoDivTimeout);
		}
		if (delay > 0) {
			infoDivTimeout = window.setTimeout('hideShowInfoDivContainer()', delay);
		}
	}
}

function hideShowInfoDivContainer()
{
	new Effect.Opacity('infoDivContainer', {
			from: 1,
			to: 0,
			duration: 0.5,
			afterFinish: function (effect) {
				effect.element.hide();
			}
		}
	);
}

function lstAuflistung_removeMatsList()
{
  if ($('lstShowMatsDiv')) $('lstShowMatsDiv').remove();
}

function lstAuflistung_showMats(lstID, idString)
{
  showInfoDivContainer('', 'ajax');
  lstAuflistung_removeMatsList();
  new Ajax.Request('ajax/srv/leistungen_liste_ajax.php?t=lstMats', {
    postBody: 'lstID='+encodeURIComponent(idString),
    onComplete: function (t) {
      var div = new Element('div', {'id': 'lstShowMatsDiv'});
      $('body_element').appendChild(div);
      div.innerHTML = t.responseText;
      hideShowInfoDivContainer();
    }
  });
}

function lstAuflistung_showMatsSave(lstID)
{
	showInfoDivContainer('', 'ajax');
	new Ajax.Request('ajax/srv/leistungen_liste_ajax.php?t=lstMatsSave', {
		parameters: 'lstID=' + lstID + '&' + $('showMatDiv_' + lstID).serialize(),
		onSuccess: function(t) {
			showInfoDivContainer(getLang("all", "edit_successfully"));
      lstAuflistung_removeMatsList();
		}
	});
}

function scrollingInfoDivContainer()
{
	if ($('infoDivContainer')) {
		$('infoDivContainer').onclick = function () {
			if (typeof infoDivTimeout != 'undefined') {
				window.clearTimeout(infoDivTimeout);
				hideShowInfoDivContainer();
			}
		}
	}
}

function show_loadImg()
{
	return '<div class="al_loadImg"><img src="media/hp/ajaxrequest.gif"><br>' + getLang("list", "loadList") + '</div>';
}

function show_load(padding)
{
	return '<div style="padding: '+((padding == true) ? '5px;' : '0')+'"><img src="media/hp/ajaxrequest.gif"></div>';
}

function showTicketStatusPopup(theImgID)
{
	if ($(theImgID) && $('showTicketStatusPopupContainer'))
	{
		$('showTicketStatusPopupContainer').innerHTML = '<div style="padding: 5px;"><img src="media/hp/ajaxrequest.gif"></div>';
		$('showTicketStatusPopupContainer').style.left = ($(theImgID).cumulativeOffset()[0]-$(theImgID).getWidth()-10)+'px';
		$('showTicketStatusPopupContainer').style.top = ($(theImgID).cumulativeOffset()[1]+$(theImgID).getHeight()+5)+'px';
		$('showTicketStatusPopupContainer').show();
		var url = 'ajax/srv/get_ticketStatus.php';
		new Ajax.Request(url,
			{
				method: 'get',
				onComplete: function (transport)
				{
					var response = transport.responseText;
					$('showTicketStatusPopupContainer').innerHTML = response;
					$('showTicketStatusPopupContainer').style.left = ($(theImgID).cumulativeOffset()[0]-$('showTicketStatusPopupContainer').getWidth())+'px';
					$('showTicketStatusPopupContainer').style.top = ($(theImgID).cumulativeOffset()[1]+$(theImgID).getHeight()+5)+'px';
				}
			}
		);
	}
}

function showWVInfosMenu(typ)
{
	if ($('wvMenuContainer') && $('v4_topRowInfoDiv_wv') && $('v4_topRowContainer')) {
		$('wvMenuContainer').style.left = (Prototype.Browser.IE ? -3 : 0) + $('v4_topRowInfoDiv_wv').cumulativeOffset()[0] + 'px';
		$('wvMenuContainer').style.top = $('v4_topRowContainer').getHeight() + 'px';
		$('wvMenuContainer').style.width = $('v4_topRowInfoDiv_wv').getWidth() + 'px';
		$('wvMenuContainer').innerHTML = show_load(true);
		$('wvMenuContainer').show();
		new Ajax.Request('ajax/srv/wv_ajax.php?t=wvMenuContainer&typ=' + typ, {
				onComplete: function (t) {
					$('wvMenuContainer').innerHTML = t.responseText;
				}
		});
	}
}

function hideWVInfosMenu()
{
	if ($('wvMenuContainer'))
	{
		$('wvMenuContainer').hide();
	}
}

function showMenuAnzeigePopup(theImg)
{
	if ($(theImg))
	{
		if (!$('menuAnzeigeInfoPopup'))
		{
			var theDiv = document.createElement('div');
			theDiv.id = 'menuAnzeigeInfoPopup';
			theDiv.style.display = 'none';
			theDiv.style.position = 'absolute';
			theDiv.style.backgroundColor = '#fff';
			theDiv.style.border = '1px solid #000';
			document.body.appendChild(theDiv);
		}
		$('menuAnzeigeInfoPopup').innerHTML = show_load(true);
		$('menuAnzeigeInfoPopup').style.left = ($(theImg).cumulativeOffset()[0] - $('menuAnzeigeInfoPopup').getWidth()) + 'px';
		$('menuAnzeigeInfoPopup').style.top = $(theImg).cumulativeOffset()[1] + $(theImg).getHeight() + 'px';
		$('menuAnzeigeInfoPopup').show();
		if ($('menuAnzeigeInfoPopup'))
		{
			var url = 'ajax/srv/admin_menu.php?t=getInfos';
			new Ajax.Request(url,
				{
					method: 'get',
					onComplete: function (t)
					{
						var res = t.responseText;
						$('menuAnzeigeInfoPopup').innerHTML = res;
						$('menuAnzeigeInfoPopup').style.left = ($(theImg).cumulativeOffset()[0] - $('menuAnzeigeInfoPopup').getWidth()) + 'px';
						$('menuAnzeigeInfoPopup').style.top = $(theImg).cumulativeOffset()[1] + $(theImg).getHeight() + 'px';
					}
				}
			);
		}
	}
}

function toggleWVInfo(wvID)
{
	if ($$('tr.tr_wvInfo_'+wvID).length)
	{
		for (var i = 0; i < $$('tr.tr_wvInfo_'+wvID).length; i++)
		{
			$$('tr.tr_wvInfo_'+wvID)[i].toggle();
		}
		if ($('tr_wvInfo_img_'+wvID))
		{
			$('tr_wvInfo_img_'+wvID).src = ($('tr_wvInfo_img_'+wvID).src.match(/media\/katbrowser\/tree1.gif/)) ? 'media/katbrowser/tree2.gif' : 'media/katbrowser/tree1.gif';
		}
	}
}

function checkAuflistungWidths()
{
	if ($('v4_pageContainer'))
	{
		var maxWidth = 952;
		var al = $$('table.al_table');
		for (var i = 0; i < al.length; i++)
		{
			//al[i].getWidth() > maxWidth ? maxWidth = al[i].getWidth() : true;
			alert(al[i].getWidth());
		}
		//$('v4_pageContainer').style.width = maxWidth + 'px';
	}
}

function printSupportListe(bugID)
{
	var url = 'ajax/srv/auflistung_functions.php?t=countPrintableServices&bugID='+encodeURIComponent(bugID);
	new Ajax.Request(url,
		{
			method: 'get',
			onComplete: function (t)
			{
				var res = t.responseText.evalJSON();
				if (res.anzahl > 0)
				{
					var ufeld = ($('ufeld_bugForm') && ($('ufeld_bugForm').checked == true)) ? 1 : 0;
					var url = 'ajax/srv/auflistung_functions.php?t=generateCachePrintableServices&bugID='+encodeURIComponent(bugID)+'&ufeld='+encodeURIComponent(ufeld);
					new Ajax.Request(url,
						{
							method: 'get',
							onComplete: function (t)
							{
								var json = t.responseText.evalJSON();
								var popup = window.open('ajax/srv/bug_service_list_mail.php?bugID='+bugID+'&md5='+encodeURIComponent(json.md5), '_blank', 'height=200, width=500, top=50, left=50, resiable=yes, statusbar=yes');
							}
						}
					);
				}
				else
				{
					alert(getLang("all", "noEntries"));
				}
			}
		}
	);
}

function selectNewCustomer(fID)
{
	if ($('neueFirma') && $('favoritenwahl'))
	{
		$('neueFirma').value = fID;
		$('favoritenwahl').submit();
	}
}

function s2t_rename(id)
{
  var vorbeleg = '';
  if ($('s2t_name_span_' + id)) {
    vorbeleg = $('s2t_name_span_' + id).innerHTML;
  }
	var name = prompt(getLang("s2t", "s2t_renQuestion"), vorbeleg);
	if (name != '' && name != null) {
		new Ajax.Request('ajax/srv/s2t_ajax.php?t=rename', {
			parameters: 'id=' + id + '&name=' + encodeURIComponent(name),
			onSuccess: function(t) {
				$('s2t_name_span_' + id).innerHTML = name;
			}
		});
	}
}

function isFieldEmpty(fieldname)
{
	if ($(fieldname))
		return $(fieldname).value.blank();
	return true;
}

function toggleAnlFirma()
{
	if ($('fsna_kd_name_tr')) $('fsna_kd_name_tr').toggle();
	if ($('fsna_kd_vorname_tr')) $('fsna_kd_vorname_tr').toggle();
	if ($('fsna_kd_nachname_tr')) $('fsna_kd_nachname_tr').toggle();
	if ($('fsna_kd_privatTel_tr')) $('fsna_kd_privatTel_tr').toggle();
	if ($('fsna_kd_mobilTel_tr')) $('fsna_kd_mobilTel_tr').toggle();
  if ($('fsna_kd_anrede_tr')) $('fsna_kd_anrede_tr').toggle();
  if ($('fsna_kd_titel_tr')) $('fsna_kd_titel_tr').toggle();
}

function fInfo_show(fID, ind, modus) {
  if (modus == 1) {
    window.open('index.php?section=info&sub=fInfo&firmenID=' + fID, '_blank', 'top=50, left=50, height=500, width=400, resizable=yes, scrollbars=yes, status=no');
  } else {
    var id = 'fInfoDiv_' + fID + '_' + ind;
    var imgId = 'fInfoImg_' + fID + '_' + ind;
    if ($(id)) {
      $(id).remove();
    }
    var div = document.createElement("div");
    div.id = id;
    $(div).addClassName("fInfoDiv");
    document.body.appendChild(div);
    div.style.left = $(imgId).cumulativeOffset()[0] - 150 + 'px';
    div.style.top = $(imgId).cumulativeOffset()[1] + 20 + 'px';
    new Ajax.Request('ajax/srv/fInfo_ajax.php?t=show', {
      parameters: 'id=' + fID + '&ind=' + ind,
      onSuccess: function(t) {
        div.innerHTML = t.responseText;
      }
    });
  }
}

var getPLZOrtInfoRequest = null;
function getPLZOrtInfo(sourceField, targetField) {
	if (true) {
		removePLZOrtInfoDiv();
		if (getPLZOrtInfoRequest) getPLZOrtInfoRequest.abort();
		if ($(sourceField) && $(targetField)) {
			var url = 'ajax/srv/ajax.php?t=getPLZOrtInfoRequest&plz='+encodeURIComponent($(sourceField).value) +
																												'&sourceField='+encodeURIComponent(sourceField) + 
																												'&targetField='+encodeURIComponent(targetField);
			getPLZOrtInfoRequest = new Ajax.Request(url, {
				onComplete: function (t) {
					if (t.responseText != '') {
						var theDiv = createPLZOrtInfoDiv();
						theDiv.style.left = $(targetField).cumulativeOffset()[0] + 'px';
						theDiv.style.top = ($(targetField).cumulativeOffset()[1] + $(targetField).getHeight()) + 'px';
						theDiv.innerHTML = t.responseText;
					}
				}
			});
		}
	}
}

function setPLZOrtInfo(theTextFieldID, theText, thePLZFieldID, thePLZ) {
	if ($(theTextFieldID)) $(theTextFieldID).value = theText;
	if ($(thePLZFieldID)) $(thePLZFieldID).value = thePLZ;
	removePLZOrtInfoDiv();
}

function removePLZOrtInfoDiv() {
	if ($('getPLZOrtInfoDiv')) $('getPLZOrtInfoDiv').remove();
}

function createPLZOrtInfoDiv() {
	var theDiv = document.createElement('div');
	theDiv.id = 'getPLZOrtInfoDiv';
	document.body.appendChild(theDiv);
	return theDiv;
}

function confirmNotification(ltID, lID) {
  new Ajax.Request('ajax/srv/notification_ajax.php?t=confirm', {
    parameters: 'ltID=' + ltID + '&lID=' + lID,
    onSuccess: function(t) {
      notificationRemove(ltID, lID);
    }
  });
}
function notificationClose() {
  $('notificationDiv').remove();
  $('notificationClosed').value = "1";
}
function notifDivErstellen() {
  if (!$('notificationDiv')) {
    var divElement = document.createElement('div');
    divElement.id = 'notificationDiv';
    document.body.appendChild(divElement);
  }
}
function notificationShow() {
  new Ajax.Request('ajax/srv/notification_ajax.php?t=check&always=1', {
    onSuccess: function(t) {
      if (t.responseText != '') {
        notifDivErstellen();
        $('notificationDiv').innerHTML = t.responseText;
      }
    }
  });
}
function notificationCheck() {
  var doIt = true;
  if ($('notificationClosed') && $F('notificationClosed') == 1) {
    doIt = false;
  }
  if (doIt) {
    window.setTimeout('notificationCheck()', 120000);
    new Ajax.Request('ajax/srv/notification_ajax.php?t=check', {
      onSuccess: function(t) {
        if (t.responseText == '-') {
          if ($('notifHidImg')) $('notifHidImg').show();
        } else if (t.responseText != '') {
          if ($('notifHidImg')) $('notifHidImg').hide();
          notifDivErstellen();
          $('notificationDiv').innerHTML = t.responseText;
        }
      }
    });
  }
}
function delayNotification(ltID, lID) {
  var zeit = prompt(getLang("notifications", "notify_delayQuestion"), 5);
  if (zeit != null && zeit > 0) {
    new Ajax.Request('ajax/srv/notification_ajax.php?t=delay', {
      parameters: 'ltID=' + ltID + '&lID=' + lID + '&min=' + zeit,
      onSuccess: function(t) {
        notificationRemove(ltID, lID);
      }
    });
  }
}
function notificationRemove(ltID, lID) {
  $('cf1_' + ltID + '_' + lID).hide();
  $('cf2_' + ltID + '_' + lID).hide();
  if ($('notificationCount')) {
    $('notificationCount').value = parseInt($F('notificationCount'), 10)  - 1;
    if ($F('notificationCount') == 0) {
      $('notificationDiv').remove();
    }
  }
}

function menuShowInfo(what, e) {
  var theTrigger = Event.element(e);
  closeMenuShowInfoDiv();
  var theDiv = new Element('div', {'id': 'menuShowInfoDiv'});
  document.body.appendChild(theDiv);
  theDiv.style.left = (theTrigger.cumulativeOffset()[0]-250)+'px';
  theDiv.style.top = (theTrigger.cumulativeOffset()[1]+17)+'px';
  theDiv.innerHTML = show_load(true);
  new Ajax.Request('ajax/srv/admin_menu.php?t=menuInfo&what='+encodeURIComponent(what), {
    onComplete: function (t) {
      theDiv.innerHTML = t.responseText;
    }
  });
}
function closeMenuShowInfoDiv()
{
  if ($('menuShowInfoDiv'))
    $('menuShowInfoDiv').remove();
}

function rr_erledigen(id)
{
	new Ajax.Request('ajax/srv/portal_v4_ajax.php?t=rrSetStatus', {
		parameters: 'id=' + id + '&status=10&info=',
		onSuccess: function (t) {
      notificationRemove(16, id);
			p4_window_inhalt_akt('rueckrufe');
			p4_window_inhalt_akt('rueckrufe_firma');
		}
	});
}

function bez_show(ltID, lID, div, nr) {
  if ($('bezDiv')) {
    $('bezDiv').remove();
  }
  var theDiv = document.createElement('div');
  theDiv.id = 'bezDiv';
  theDiv.className = 'ttDivGen';
  theDiv.style.width = '600px';
  document.body.appendChild(theDiv);
  var img;
  if ($('bezImg_' + ltID + '_' + lID + '_' + nr)) {
    img = $('bezImg_' + ltID + '_' + lID + '_' + nr);
  } else {
    img = $('bezImg_qn');
    $(theDiv).setStyle('z-index: 60000');
  }
  theDiv.style.left = (img.cumulativeOffset()[0]-300)+'px';
  theDiv.style.top = (img.cumulativeOffset()[1]+20)+'px';

  new Ajax.Request('ajax/srv/beziehungen_ajax.php?t=getListe', {
    parameters: 'ltID=' + ltID + '&lID=' + lID,
    onSuccess: function(t) {
      theDiv.innerHTML = t.responseText;
    }
  });
}

function gc_techniker(fID, tID, nr) {
  if ($('geo_t_div')) {
    $('geo_t_div').remove();
  }
  var theDiv = document.createElement('div');
  theDiv.id = 'geo_t_div';
  theDiv.className = 'ttDivGen';
  theDiv.style.width = '500px';
  document.body.appendChild(theDiv);
  var img = $('gc_t_img_' + fID + '_' + tID + '_' + nr);
  theDiv.style.left = (img.cumulativeOffset()[0]-250)+'px';
  theDiv.style.top = (img.cumulativeOffset()[1]+20)+'px';
  new Ajax.Request('ajax/srv/geocode_ajax.php?t=techNaeheDiv', {
    parameters: 'fID=' + fID + '&tID=' + tID,
    onSuccess: function(t) {
      theDiv.innerHTML = t.responseText;
    }
  });
}

function setNewFirma(firmenID) {
  if ($('neueFirma') && $('favoritenwahl')) {
    $('neueFirma').value = firmenID;
    $('favoritenwahl').submit();
  }
}

function copyToClipboard(theText) {
  if ($('copyClipboardFrame')) $('copyClipboardFrame').remove();
  try {
    if (window.clipboardData) {
      window.clipboardData.setData('Text', theText);
    } else {
      var iframeElement = new Element('iframe', {'id': 'copyClipboardFrame', 'height': 1, 'width': 1, 'frameborder': 0, 'scrolling': 'no'});
      document.body.appendChild(iframeElement);
      iframeElement.contentDocument.designMode = "On";
      var iframeBody = iframeElement.contentDocument.getElementsByTagName('body')[0];
      iframeBody.contentEditable = true;
      iframeBody.innerHTML = theText;
      iframeElement.contentDocument.execCommand('selectAll', false, null);
      iframeElement.contentDocument.execCommand('copy', false, null);
    }
  } catch (ex) {}
}

// Unter-Menus an der Seite ausrichten
$(document).observe('dom:loaded', function () {
  if ($('v4_pageContainer')) {
    var pageRightOutline = $('v4_pageContainer').cumulativeOffset()[0] + $('v4_pageContainer').getWidth();
    var menus = $$('ul.mainmenu_sublist');
    for (var i = 0, len = menus.length; i < len; i++) {
      var menuRightOutline = menus[i].cumulativeOffset()[0] + menus[i].getWidth();
      if (menuRightOutline > pageRightOutline) {
        menus[i].setStyle({'right': 0});
      }
    }
  }
});

// DatePicker - Heute-Button "alte" Funktionalität
jQuery.datepicker._gotoToday = function(id) 
{
  var target = jQuery(id);
  var inst = this._getInst(target[0]);
  if (this._get(inst, 'gotoCurrent') && inst.currentDay) {
    inst.selectedDay = inst.currentDay;
    inst.drawMonth = inst.selectedMonth = inst.currentMonth;
    inst.drawYear = inst.selectedYear = inst.currentYear;
  } else {
    var date = new Date();
    inst.selectedDay = date.getDate();
    inst.drawMonth = inst.selectedMonth = date.getMonth();
    inst.drawYear = inst.selectedYear = date.getFullYear();
    this._setDateDatepicker(target, date);
    this._selectDate(id, this._getDateDatepicker(target));
  }
  this._notifyChange(inst);
  this._adjustDate(target);
}

