//Funktion setzt hiddenfelder zurück
function hiddenfields() {
	document.getElementById('hidden').value = "";
}

// Pop-Up f�r Sedcardanzeige
function popup(url, w, h, scrolling, name) {
	if (!scrolling)
		scrolling = "no";
	scrolling = "yes";
	if (!w)
		w = "800";
	if (!h)
		h = "1024";
	var popup = window;
	var nwl = (screen.width - 700) / 2;
	var nwh = (screen.height - 700) / 2;
	popup
			.open(
					url,
					name,
					'statusbar=no, toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='
							+ scrolling
							+ ',width='
							+ w
							+ ',height='
							+ h
							+ ',resizable=yes,left=' + nwl + ',top=' + nwh + '');
	return false;
}

// ---------------------------------------
// kann h�he und breite verarbeiten
function showlayer(divid, breite, hoehe) {
	var div = document.getElementById(divid); // �bergebenes Element
	LayerTop(div);
	if (breite) {
		div.style.width = breite;
	}
	if (hoehe) {
		div.style.height = hoehe;
	}
	div.style.display = 'block';
}
function showlayerInline(divid, breite, hoehe) {
	var div = document.getElementById(divid); // �bergebenes Element
	LayerTop(div);
	if (breite) {
		div.style.width = breite;
	}
	if (hoehe) {
		div.style.height = hoehe;
	}
	div.style.display = 'inline';
}
function hidelayer(divid) {
	document.getElementById(divid).style.display = 'none';
	return false;
}

function clearlayer(divid, hideLayer) {
	var div = document.getElementById(divid);
	if (div) {
		div.innerHTML = '';
	}
	if (hideLayer) {
		hidelayer(divid);
	}
}

/*
 * Bisher nur f�r die Klasse Centerlayer
 */
function LayerTop(divObj) {
	var divs = document.getElementsByName('popup');
	for ( var x = 0; x < divs.length; x++) {
		var e = divs[x];
		var browser = navigator.appName;
		if (browser == "Microsoft Internet Explorer") {
			var zIndexE = turn2Int(e.currentStyle.zIndex);
			var zIndexDivObj = turn2Int(divObj.currentStyle.zIndex);
		} else {
			var zIndexE = turn2Int(window.getComputedStyle(e, null).zIndex);
			var zIndexDivObj = turn2Int(window.getComputedStyle(divObj, null).zIndex);
		}
		if (zIndexE >= zIndexDivObj)
			divObj.style.zIndex = zIndexE + 1;
	}
	function turn2Int(string) {
		return parseInt(string);
	}
}

// -------------------------------------------------
// zeigen oder verstecken
function showlayer2(divid) {
	document.getElementById(divid).style.visibility = 'visible';
}

function hidelayer2(divid) {
	document.getElementById(divid).style.visibility = 'hidden';

}

// ----------------------------------------------------
// l�scht den Inhalt eines Elements
function clear_element(e) {
	return document.getElementById(e).innerHTML = "";

}

// -------------------------------------------
function style_focus(e, onlyBackGroundColor) {
	e.style.backgroundColor = "#dff2f9";
	if (!onlyBackGroundColor) {
		e.style.borderWidth = "1px";
		e.style.borderColor = "#003f5c";
		e.style.borderStyle = "solid";
	}
}

function style_blur(e, onlyBackGroundColor) {
	e.style.backgroundColor = "white";
	if (!onlyBackGroundColor) {
		e.style.borderWidth = "1px";
		e.style.borderColor = "#003f5c";
		e.style.borderStyle = "solid";
	}
}

function returnCity(divContainer) {
	if (!divContainer)

		divContainer = "divort";
	plz = document.getElementById('plz').value;
	ajaxaction('include/returnCityByZipCode.php?plz=' + plz + '&divContainer='
			+ divContainer);
}

/*
 * wird von der PHP-Funktion PRF_System::liddleHelper($id, $anzeige=false)
 * ausgef�hrt und bewirkt, dass ein Hilfetext in dem Div liddleHelper angezeigt
 * wird dieser wird dann auch eingeblendet, sobald der Text geladen ist
 */
function liddleHelper(textid, divid, admindesk, text) {
	if (admindesk)
		var pfad = "../";
	else
		pfad = "";
	ajaxaction(pfad + 'include/helpinfos.php?textid=' + textid + "&divid="
			+ divid);

	if (mousex + 300 > window.innerWidth) {
		document.getElementById(divid).style.right = "0";
	} else {
		document.getElementById(divid).style.left = "0";
	}

	showlayer(divid);
	return false;
}

function delete_data(url, bezeichnung, altText) {
	var confText;
	if (altText != null) {
		confText = altText;
	} else {
		confText = "Soll " + bezeichnung + " wirklich gelöscht werden?";
	}
	if (confirm(confText) == true) {
		ajaxaction(url);
	}
}

function showNhide(layer, checkbox, otherWayRound, inline) {
	if (!otherWayRound)
		otherWayRound = false;
	else
		otherWayRound = true;

	if (document.getElementById(checkbox).checked == otherWayRound) {
		// alert(inline);
		if (!inline) {
			showlayer(layer);
		} else {
			showlayerInline(layer);
		}

	} else {
		hidelayer(layer);
	}
}

function hideLayersByName(name) {
	var elements = getElementsByClass(name);
	for ( var i = 0; i < elements.length; i++) {
		elements[i].style.display = 'none';
	}
}

/**
 * Liefert alle Objekte zur�ck, die einer Klasse angeh�ren.
 * 
 * @param {string}
 *            className
 */
function getElementsByClass(className, node) {
	if (node) {
		var allElements = node.getElementsByTagName('*');
	} else {
		var allElements = document.getElementsByTagName('*');
	}

	var elements = new Array();
	for ( var i = 0; i < allElements.length; i++) {
		var thisElement = allElements[i];
		if (thisElement.className) {
			if (thisElement.className.match(className) != null) {
				var thisElementArray = new Array(thisElement);
				elements = elements.concat(thisElementArray);
			}
		}
	}
	return elements;
}

function showLoadInfo(divid) {

}

/**
 * �ndert die Klasse des angegeben Tabs auf die des aktivierten Tabs
 * 
 * @param {string}
 *            tabid
 */
function activateTab(parentId, contentId, tabId) {
	var parent = document.getElementById(parentId);
	if (parent) {

		// alle Content-Divs des Parents ausblenden
		var contents = getElementsByClass('tabContentJS', parent);
		if (contents) {
			for ( var i = 0; i < contents.length; i++) {
				contents[i].style.display = 'none';
			};
		}

		// den gew�nschten einblenden
		var content = document.getElementById(contentId);
		if (content) {
			content.style.display = 'block';
		}

		// alle Tabs zur�cksetzen
		var tabs = getElementsByClass('tabJS', parent);
		if (tabs) {
			for ( var i = 0; i < tabs.length; i++) {
				tabs[i].className = 'tabJS';
			};
		}

		// den aktuellen Tabs aktivieren
		var tab = document.getElementById(tabId);
		if (tab) {
			tab.className = 'tabJS tabJS_active';
		}

	}
	return true;

	var tabs = getElementsByClass('tabJS');
	for ( var i = 0; i < tabs.length; i++) {
		var tab = tabs[i];
		if (tab.id != tabid) {
			tab.className = 'tabJS';
		} else {
			tab.className = 'tabJS tabJS_active';
		}
	}
}
var mousex;
var mousey;
// Das Objekt, das gerade bewegt wird.
var dragobjekt = null;
// Position, an der das Objekt angeklickt wurde.
var dragx = 0;
var dragy = 0;
var elementzIndex = 100;
if (window.event) {
	if (document.captureEvents) {
		document.captureEvents(Event.MOUSEMOVE);
	} else {
		window.captureEvents(Event.MOUSEMOVE);
	}
}
// Ermittlung der Maus-Position
function mousePosition(e) {
	if (!e)
		e = window.event;
	var body = (window.document.compatMode && window.document.compatMode == "CSS1Compat")
			? window.document.documentElement
			: window.document.body || null;

	mousey = e.pageY ? e.pageY : e.clientY + body.scrollTop;
	mousex = e.pageX ? e.pageX : e.clientX + body.scrollLeft;
	if (dragobjekt != null) {
		if (mousex - dragx >= 0)
			dragobjekt.style.left = (mousex - dragx) + "px";
		if (mousey - dragy >= 0)
			dragobjekt.style.top = (mousey - dragy) + "px";
	}
}
document.onmousemove = mousePosition;
document.onmouseup = dragstop;
function dragstart(element) {
	var e = document.getElementById(element);
	LayerTop(e);
	// Wird aufgerufen, wenn ein Objekt bewegt werden soll.
	dragobjekt = e;
	dragx = mousex - dragobjekt.offsetLeft;
	dragy = mousey - dragobjekt.offsetTop;
}
function dragstop() {
	// Wird aufgerufen, wenn ein Objekt nicht mehr bewegt werden soll.
	dragobjekt = null;
}

function PosLayerByMouse(layerid, offsetX, offsetY) {
	layer = document.getElementById(layerid);
	if (!offsetX)
		offsetX = 15;
	if (!offsetY)
		offsetY = 10;
	layer.style.left = mousex + offsetX + "px";
	layer.style.top = mousey + offsetY + "px";
}

function getSize() {
	var myWidth = 0, myHeight = 0;

	if (typeof (window.innerWidth) == 'number') {
		// Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if (document.documentElement
			&& (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		// IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if (document.body
			&& (document.body.clientWidth || document.body.clientHeight)) {
		// IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [myWidth, myHeight];
}

function ModalScreen(url) {
	clear_element('modal_lockscreen_content');
	showlayer('modal_lockscreen');
	ajaxaction(url);
	return false;
}
function expandView(layer, imgID, imgSRCplus, imgSRCminus) {
	var img = document.getElementById(imgID);
	var src = img.src;
	if (imgSRCplus == "") {
		imgSRCplus = "daten/plus.png";
		imgSRCminus = "daten/minus.png";
	}
	if (src.indexOf(imgSRCplus) == -1) {
		reduceView(layer, imgID, imgSRCplus);
	} else {
		img.src = imgSRCminus;
		showlayer(layer);
	}
}

function reduceView(layer, imgID, imgSRCplus) {
	var img = document.getElementById(imgID);
	img.src = imgSRCplus;
	hidelayer(layer);
}

function PersonalInfoWindow(uid) {
	clear_element('piw');
	ajaxaction('/clientpages/sedcard/start.php?ID=' + uid);
	PosLayerByMouse('piw');
	showlayer('piw');
}

function userImageWindow(id) {
	clear_element("userImageWindow");
	ajaxaction('sedcard/images/showLargeImage.php?imageId=' + id);
	PosLayerByMouse("userImageWindow");
	showlayer("userImageWindow");
}

/**
 * 
 * @param e
 *            Bsp. Button
 * @return
 */
function disable(e) {
	return document.getElementById(e).disabled = true;
}
function enable(e) {
	return document.getElementById(e).disabled = false;
}

function toggle(elementId) {
	element = document.getElementById(elementId);
	if (!element)
		return true;
	if (element.style.display == "block")
		hidelayer(elementId);
	else
		showlayer(elementId);
}

function calcMainWindowPositionAndSetSize(width, height) {
	if (navigator.appName == 'Microsoft Internet Explorer') {
		document.getElementById('mainWindow').style.left = (document.body.clientWidth / 2)
				- (width / 2) + 'px';
		document.getElementById('mainWindow').style.top = (document.body.clientHeight / 2)
				- (height / 2) + 'px';

	} else {
		document.getElementById('mainWindow').style.left = (window.innerWidth / 2)
				- (width / 2) + 'px';
		document.getElementById('mainWindow').style.top = (window.innerHeight / 2)
				- (height / 2) + 'px';
	}
	document.getElementById('mainWindow').style.width = width + 'px';
	document.getElementById('mainWindow').style.height = height + 'px';

}

// number formatting function
// copyright Stephen Chapman 24th March 2006, 10th February 2007
// permission to use this function is granted provided
// that this copyright notice is retained intact
function formatNumber(num, dec, thou, pnt, curr1, curr2, n1, n2) {
	var x = Math.round(num * Math.pow(10, dec));
	if (x >= 0)
		n1 = n2 = '';

	var y = ('' + Math.abs(x)).split('');
	var z = y.length - dec;

	if (z < 0)
		z--;

	for ( var i = z; i < 0; i++)
		y.unshift('0');

	y.splice(z, 0, pnt);
	if (y[0] == pnt)
		y.unshift('0');

	while (z > 3) {
		z -= 3;
		y.splice(z, 0, thou);
	}

	var r = curr1 + n1 + y.join('') + n2 + curr2;
	return r;
}
function parseInputToDate(fieldId) {
	// Datumsfeld
	field = document.getElementById(fieldId);
	if (field) {
		var strDatum = field.value;
		var aStrDatum = strDatum.split(".");
		if (aStrDatum.length != 3) {
			var datum = new Date();
		} else {
			var datum = new Date(aStrDatum[2], aStrDatum[1] - 1, aStrDatum[0]);
		}
	} else
		datum = new Date();
	return datum;
}

/*******************************************************************************
 * 
 * Suckerfish - NavigationHack
 * 
 ******************************************************************************/
/*
 * sfHover = function() { var sfEls = document.getElementById("navigation")
 * .getElementsByTagName("LI"); for ( var i = 0; i < sfEls.length; i++) {
 * sfEls[i].onmouseover = function() { this.className += " sfhover"; };
 * sfEls[i].onmouseout = function() { this.className =
 * this.className.replace(new RegExp(" sfhover\\b"), ""); }; } }; if
 * (window.attachEvent) window.attachEvent("onload", sfHover);
 * 
 * sfHover = function() { var sfEls =
 * document.getElementById("tabs").getElementsByTagName("LI"); for ( var i = 0;
 * i < sfEls.length; i++) { sfEls[i].onmouseover = function() { this.className += "
 * sfhover"; }; sfEls[i].onmouseout = function() { this.className =
 * this.className.replace(new RegExp(" sfhover\\b"), ""); }; } }; if
 * (window.attachEvent) window.attachEvent("onload", sfHover);
 */
