function hide(field)
{
	if (document.getElementById(field))
	{
		document.getElementById(field).style.display = 'none';
		document.getElementById(field).style.visibility = 'hidden';
	}
}

function show(field)
{
	if (document.getElementById(field))
	{
		document.getElementById(field).style.display = 'block';
		document.getElementById(field).style.visibility = 'visible';
	}
}

var editNewstickerActive = false;

function editNewsticker()
{
	var content = '';
	if (document.getElementById('newstickerText') && editNewstickerActive == false)
	{ 
		content = document.getElementById('newstickerText').innerHTML;
		document.getElementById('newstickerText').innerHTML = '<input type="text" name="newsticker" id="newstickerInput" value=""> <input type="button" onclick="saveNewsticker()" value="speichern">';
		document.getElementById('newstickerInput').value = content;
		editNewstickerActive = true;
	}	
}

function saveNewsticker()
{
	var content = '';
	if (document.getElementById('newstickerText') && editNewstickerActive == true)
	{ 
		content = document.getElementById('newstickerInput').value;
		document.getElementById('newstickerText').innerHTML = content;
		editNewstickerActive = false;
		
		var scriptpath = "/updateNewsTicker.php?content=" + content;
		var htmlhead = document.getElementsByTagName("head")[0];
		var script_id = "updateNewsTicker";
	
		if(document.getElementById(script_id)) {
			htmlhead.removeChild(document.getElementById(script_id));
		}
	
		var updatescript = document.createElement("script");
		updatescript.id = script_id;
		updatescript.src = scriptpath;
		htmlhead.appendChild(updatescript);		
	}
}

function getUser(stundenID, cat)
{	
	if (document.getElementById('newuserDiv'))
	{ 
		var scriptpath = "/getUser.php?stundenID=" + stundenID + "&cat=" + cat + "&word=" + document.getElementById('newUser').value;
		var htmlhead = document.getElementsByTagName("head")[0];
		var script_id = "getUser";
	
		if(document.getElementById(script_id)) {
			htmlhead.removeChild(document.getElementById(script_id));
		}
	
		var updatescript = document.createElement("script");
		updatescript.id = script_id;
		updatescript.src = scriptpath;
		htmlhead.appendChild(updatescript);		
	}
}

function setUser(userID, userName)
{
	if (document.getElementById('newUser')) document.getElementById('newUser').value = userName;
	if (document.getElementById('userID')) document.getElementById('userID').value = userID;
}

function deleteContent(method, id)
{
	var scriptpath = "/jsHandling.php?method=" + method + "&id=" + id;
	var htmlhead = document.getElementsByTagName("head")[0];
	var script_id = "deleteContent";

	if(document.getElementById(script_id)) {
		htmlhead.removeChild(document.getElementById(script_id));
	}

	var updatescript = document.createElement("script");
	updatescript.id = script_id;
	updatescript.src = scriptpath;
	htmlhead.appendChild(updatescript);
	return false;
}

var http = null;
var IE = document.all?true:false
var BildX, BildY, moveable = 0, activeFriends = 0, posX = 100, posY = 100, disableSetFriends = 0, friendsVisible = 0;
var imgWidth = 0, imgHeight = 0, userID = 0, imageType = "", album = "", pic_id = "", active = 0, publisherName = '';
LinkedUsers = new Array();
tempUsers = new Array();

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

function sendRequestTextGetAvatar(URL)
{
	if (http == null) http = createRequestObject();
	try{
		http.open('GET', URL);
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = handleResponseTextAvatar;
		http.send(null);
	}
	catch(e){}
	finally{}
}

function sendRequestTextGet(URL)
{
	if (http == null) http = createRequestObject();
	try{
		http.open('GET', URL);
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = handleResponseText;
		http.send(null);
	}
	catch(e){}
	finally{}
}

function sendRequestTextGetlinkedUser(URL)
{
	if (http == null) http = createRequestObject();
	try{
		http.open('GET', URL);
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = handleResponseTextlinkedUser;
		http.send(null);
	}
	catch(e){}
	finally{}
}

function handleResponseTextAvatar() 
{
	if (http == null) http = createRequestObject();
	try{
		if((http.readyState == 4)&& (http.status == 200)){
			var response = http.responseText;
			if (response != '')	document.getElementById("result").innerHTML = response;
		}
	}
	catch(e){}
	finally{}
}

function handleResponseText() 
{
	if (http == null) http = createRequestObject();
	try{
		if((http.readyState == 4)&& (http.status == 200)){
			var response = http.responseText;
			if (response != '')	document.getElementById("friends").innerHTML = response;
		}
	}
	catch(e){}
	finally{}
}

function handleResponseTextlinkedUser() 
{
	if (http == null) http = createRequestObject();
	try{
		if((http.readyState == 4)&& (http.status == 200)){
			var response = http.responseText;
			document.getElementById("linkUsers").innerHTML = response;
		}
	}
	catch(e){}
	finally{}
}

function startSetLinks()
{
	active = 1;
	showMarker();
	moveMarker();
	showAllFriends();
	//document.getElementById('actionLink').href = 'javascript:stopSetLinks()';
	//document.getElementById('actionLink').innerHTML = '<img border="0" src="/images/userlink-no.png" title="Verlinkung beenden" alt="Verlinkung beenden">&nbsp;Verlinkungsvorgang abschließen';
}

function stopSetLinks()
{
	active = 0;
	hideMarker();
	//document.getElementById('actionLink').href = 'javascript:startSetLinks()';
	//document.getElementById('actionLink').innerHTML = '<img src="/web/images/link_add.png" alt="Verlinke deine Freunde" title="Verlinke deine Freunde">&nbsp;Personenlink hinzufügen';
}

function showMarker()
{
	moveable = 1;
	if (document.getElementById)
	{
		document.getElementById("infool").style.visibility = 'visible';
		document.getElementById("infool").style.display = 'block';
		document.getElementById("infoor").style.visibility = 'visible';
		document.getElementById("infoor").style.display = 'block';
		document.getElementById("infoul").style.visibility = 'visible';
		document.getElementById("infoul").style.display = 'block';
		document.getElementById("infour").style.visibility = 'visible';
		document.getElementById("infour").style.display = 'block';
	}
	else if (document.all)
	{
		document.all.infool.style.visibility = 'visible';
		document.all.infool.style.display = 'block';
		document.all.infoor.style.visibility = 'visible';
		document.all.infoor.style.display = 'block';
		document.all.infoul.style.visibility = 'visible';
		document.all.infoul.style.display = 'block';
		document.all.infour.style.visibility = 'visible';
		document.all.infour.style.display = 'block';
	}
}

function moveMarker()
{
	if (document.getElementById)
	{
		if (MouseX) document.getElementById("infool").style.left  = (MouseX - 20) + 'px';
		if (MouseY) document.getElementById("infool").style.top = (MouseY - 20) + 'px';
		if (MouseX) document.getElementById("infoor").style.left  = (MouseX + 10) + 'px';
		if (MouseY) document.getElementById("infoor").style.top = (MouseY - 20) + 'px';
		if (MouseX) document.getElementById("infoul").style.left  = (MouseX - 20) + 'px';
		if (MouseY) document.getElementById("infoul").style.top = (MouseY + 10) + 'px';
		if (MouseX) document.getElementById("infour").style.left  = (MouseX + 10) + 'px';
		if (MouseY) document.getElementById("infour").style.top = (MouseY + 10) + 'px';
	}
	else if (document.all)
	{
		if (MouseX) document.all.infool.style.left  = (MouseX - 20) + 'px';
		if (MouseY) document.all.infool.style.top = (MouseY - 20) + 'px';
		if (MouseX) document.all.infoor.style.left  = (MouseX + 10) + 'px';
		if (MouseY) document.all.infoor.style.top = (MouseY - 20) + 'px';
		if (MouseX) document.all.infoul.style.left  = (MouseX - 20) + 'px';
		if (MouseY) document.all.infoul.style.top = (MouseY + 10) + 'px';
		if (MouseX) document.all.infour.style.left  = (MouseX + 10) + 'px';
		if (MouseY) document.all.infour.style.top = (MouseY + 10) + 'px';
	}
}

function hideMarker() 
{
	moveable = 0;
	if (document.getElementById) {
		document.getElementById("infool").style.visibility = 'hidden';
		document.getElementById("infool").style.display = 'none';
		document.getElementById("infoor").style.visibility = 'hidden';
		document.getElementById("infoor").style.display = 'none';
		document.getElementById("infoul").style.visibility = 'hidden';
		document.getElementById("infoul").style.display = 'none';
		document.getElementById("infour").style.visibility = 'hidden';
		document.getElementById("infour").style.display = 'none';
	}
	else if (document.all)
	{
		document.all.infoul.style.visibility = 'hidden';
		document.all.infoul.style.display = 'none';
		document.all.infour.style.visibility = 'hidden';
		document.all.infour.style.display = 'none';
		document.all.infool.style.visibility = 'hidden';
		document.all.infool.style.display = 'none';
		document.all.infoor.style.visibility = 'hidden';
		document.all.infoor.style.display = 'none';
	}
}

function doAction()
{
	if (active == 1)
	{
		showFriends();
	}
	else
	{
		if (nextLink != '') window.location.href = nextLink;
	}
}

function filterFriends(search)
{
	sendRequestTextGet('linkUserOnPicsHandle.inc.php?method=list&imageType='+ imageType + "&album=" + album + "&pic_id=" + pic_id + "&search=" + search);
}

function showFriends()
{
	if (active == 1)
	{
		if (disableSetFriends == 0)
		{
			activeFriends = 1;
			sendRequestTextGet('linkUserOnPicsHandle.inc.php?method=list&imageType='+ imageType + "&album=" + album + "&pic_id=" + pic_id);
			if (document.getElementById)
			{
				document.getElementById("friendsBox").style.visibility = 'visible';
				document.getElementById("friendsBox").style.display = 'block';
				document.getElementById("friendsBox").style.left  = (MouseX + 40) + 'px';
				document.getElementById("friendsBox").style.top = MouseY + 'px';
			}
			else if (document.all)
			{
				document.all.friends.style.visibility = 'visible';
				document.all.friends.style.display = 'block';
				document.all.friends.style.left  = (MouseX + 40) + 'px';
				document.all.friends.style.top = MouseY + 'px';
			}
		}
	}
}

function hideFriends()
{
	activeFriends = 0;
	friendsVisible = 0;
	if (document.getElementById)
	{
		document.getElementById("friendsBox").style.visibility = 'hidden';
		document.getElementById("friendsBox").style.display = 'none';
		document.getElementById("friendsBox").style.left  = '1 px';
		document.getElementById("friendsBox").style.top = '1 px';
	}
	else if (document.all)
	{
		document.all.friends.style.visibility = 'hidden';
		document.all.friends.style.display = 'none';
		document.all.friends.style.left  = '1 px';
		document.all.friends.style.top = '1 px';
	}
	stopSetLinks();
}

function addFriend(id)
{	
	sendRequestTextGetlinkedUser('linkUserOnPicsHandle.inc.php?method=add&imageType='+ imageType + "&album=" + album + "&pic_id=" + pic_id + "&addID=" + id + "&posX=" + posX  + "&posY=" + posY);
	LinkedUsers[id] = new Array(id, posX, posY);
	//sendRequestTextGetlinkedUser('linkUserOnPicsHandle.inc.php?method=linkedUser&imageType="+ imageType + "&album=" + album + "&pic_id=" + pic_id);
	showAllFriends();
	hideFriends();
	moveMarker();
}

function deleteUser(id)
{
	Check = confirm("Willst du diesen Link wirklich entfernen?");
	if (Check == true)
	{
		sendRequestTextGetlinkedUser('linkUserOnPicsHandle.inc.php?method=delete&imageType='+ imageType + "&album=" + album + "&pic_id=" + pic_id + "&delID=" + id);
		for (var uid in LinkedUsers)
		{			
			if (uid.toString().search(/^-?[0-9]+$/) == 0)
			{				
				if (uid != id) tempUsers[uid] = LinkedUsers[uid];
			}
		}
		LinkedUsers = tempUsers;
		//sendRequestTextGetlinkedUser('linkUserOnPicsHandle.inc.php?method=linkedUser&imageType="+ imageType + "&album=" + album + "&pic_id=" + pic_id);
		showAllFriends();
		hideFriends();
	}
}

function setAllVisible()
{
	showAllFriends();
}

function setAllHidden()
{
	document.getElementById('bildkoord').innerHTML = '';
	//document.getElementById('actionLinkVisibility').href = 'javascript:showAllFriends()';
	//document.getElementById('actionLinkVisibility').innerHTML = '<img src="/web/images/picture_link.png" alt="Verlinkungen anzeigen" title="Verlinkungen anzeigen">&nbsp;Verlinkungen anzeigen';
	document.getElementById('actionLinkVisibility').style.display = 'none';
	document.getElementById('actionLinkVisibility').style.visibility = 'hidden';
	friendsVisible = 0;
}

function showAllFriends()
{
	friendsVisible = 1;		
	var text = '<div id="infoText" class="userLinksInfobox" style="postion: absolute; visibility: hidden; display: none;"></div>';
	if (LinkedUsers.length > 0)
	{		
		for (var i in LinkedUsers)
		{				
			if (i.toString().search(/^-?[0-9]+$/) == 0)
			{				
				if (active == 0) text += "<a href='userdetail,id," + LinkedUsers[i][0] + ".html' style='position: absolute; left: " + (LinkedUsers[i][1] - 20) + "px; top: " + (LinkedUsers[i][2] - 20) + "px;z-index: 99;'><img src='/web/images/userIconbg.gif' onmouseout='hideDetails(" + LinkedUsers[i][0] + ")' onMouseOver='showDetails(" + LinkedUsers[i][0] + ")' style='border: 0px'></a>";
				else text += "<img src='/web/images/userIconbg.gif' onmouseout='hideDetails(" + LinkedUsers[i][0] + ")' onMouseOver='showDetails(" + LinkedUsers[i][0] + ")' style='position: absolute; left: " + (LinkedUsers[i][1] - 20) + "px; top: " + (LinkedUsers[i][2] - 20) + "px;z-index: 99;border: 0px'>";
					text += "<img src='/web/images/userIconol.gif' id='" + LinkedUsers[i][0] + "_ol' style='position: absolute; left: " + (LinkedUsers[i][1] - 15) + "px; top: " + (LinkedUsers[i][2] - 15) + "px;'>";
					text += "<img src='/web/images/userIconor.gif' id='" + LinkedUsers[i][0] + "_or' style='position: absolute; left: " + (LinkedUsers[i][1] + 5) + "px; top: " + (LinkedUsers[i][2] - 15) + "px;'>";
					text += "<img src='/web/images/userIconul.gif' id='" + LinkedUsers[i][0] + "_ul' style='position: absolute; left: " + (LinkedUsers[i][1] - 15) + "px; top: " + (LinkedUsers[i][2] + 5) + "px;'>";
					text += "<img src='/web/images/userIconur.gif' id='" + LinkedUsers[i][0] + "_ur' style='position: absolute; left: " + (LinkedUsers[i][1] + 5) + "px; top: " + (LinkedUsers[i][2] + 5) + "px;'>";
			}
		}	
	}		
	if (document.getElementById('bildkoord')) document.getElementById('bildkoord').innerHTML = text;	
	if (LinkedUsers.length > 0)
	{
		document.getElementById('actionLinkVisibility').style.display = 'block';
		document.getElementById('actionLinkVisibility').style.visibility = 'visible';
	}	
	//document.getElementById('actionLinkVisibility').href = 'javascript:setAllHidden()';
	//document.getElementById('actionLinkVisibility').innerHTML = '<img src="/web/images/picture.png" alt="Verlinkungen ausblenden" title="Verlinkungen ausblenden">&nbsp;Verlinkungen ausblenden';	
}

function showDetails(id)
{
	if (friendsVisible == 0)
	{
		showAllFriends();
	}
	if (typeof LinkedUsers[id] != "undefined" && LinkedUsers[id][0] > 0)
	{
		disableSetFriends = 1;
		document.getElementById(id + "_ol").style.left = LinkedUsers[id][1] - 20 + "px";
		document.getElementById(id + "_ol").style.top = LinkedUsers[id][2] - 20 + "px";
		document.getElementById(id + "_or").style.left = LinkedUsers[id][1] + 10 + "px";
		document.getElementById(id + "_or").style.top = LinkedUsers[id][2] - 20 + "px";
		document.getElementById(id + "_ul").style.left = LinkedUsers[id][1] - 20 + "px";
		document.getElementById(id + "_ul").style.top = LinkedUsers[id][2] + 10 + "px";
		document.getElementById(id + "_ur").style.left = LinkedUsers[id][1] + 10 + "px";
		document.getElementById(id + "_ur").style.top = LinkedUsers[id][2] + 10 + "px";
		document.getElementById('infoText').style.visibility = 'visible';
		document.getElementById('infoText').style.display = 'block';
		document.getElementById('infoText').style.left = LinkedUsers[id][1] + 30 + "px";
		document.getElementById('infoText').style.top = LinkedUsers[id][2] + -10 + "px";
		document.getElementById('infoText').style.position = 'absolute';
		document.getElementById('infoText').innerHTML = document.getElementById('details_' + id).innerHTML;
	}
}

function hideDetails(id)
{
	if (typeof LinkedUsers[id] != "undefined" && LinkedUsers[id][0] > 0)
	{
		disableSetFriends = 0;
		document.getElementById(id + "_ol").style.left = LinkedUsers[id][1] - 15 + "px";
		document.getElementById(id + "_ol").style.top = LinkedUsers[id][2] - 15 + "px";
		document.getElementById(id + "_or").style.left = LinkedUsers[id][1] + 5 + "px";
		document.getElementById(id + "_or").style.top = LinkedUsers[id][2] - 15 + "px";
		document.getElementById(id + "_ul").style.left = LinkedUsers[id][1] - 15 + "px";
		document.getElementById(id + "_ul").style.top = LinkedUsers[id][2] + 5 + "px";
		document.getElementById(id + "_ur").style.left = LinkedUsers[id][1] + 5 + "px";
		document.getElementById(id + "_ur").style.top = LinkedUsers[id][2] + 5 + "px";
		document.getElementById('infoText').style.visibility = 'hidden';
		document.getElementById('infoText').style.display = 'none';
		document.getElementById('infoText').innerHTML = '';
	}
}

function getMouseX(evt) 
{
	if (evt && evt.offsetY) 
	{
		return evt.offsetX;
	} 
	else 
	{
		var obj = getEventObject( evt );
		if ( !obj.pageLeft )
		setPageTopLeft( obj );
		scrollPos = 0;
		if (typeof window.pageXOffset != 'undefined') {
		   scrollPos = window.pageXOffset;
		}
		else if (typeof document.compatMode != 'undefined' &&
		     document.compatMode != 'BackCompat') {
		   scrollPos = document.documentElement.scrollLeft;
		}
		else if (typeof document.body != 'undefined') {
		   scrollPos = document.body.scrollLeft;
		}
		return (evt.clientX - obj.pageLeft + scrollPos);
	}
}

function getMouseY(evt) 
{
	if (evt && evt.offsetY) 
	{
		return evt.offsetY;
	} 
	else 
	{
		var obj = getEventObject( evt );
		if ( !obj.pageTop )
		setPageTopLeft( obj );	
		scrollPos = 0;	
		if (typeof window.pageYOffset != 'undefined') {
		   scrollPos = window.pageYOffset;
		}
		else if (typeof document.compatMode != 'undefined' &&
		     document.compatMode != 'BackCompat') {
		   scrollPos = document.documentElement.scrollTop;
		}
		else if (typeof document.body != 'undefined') {
		   scrollPos = document.body.scrollTop;
		}
		return (evt.clientY - obj.pageTop + scrollPos);
	}
}

function setPageTopLeft( o )
{
	var top = 0,
	left = 0,
	obj = (typeof o == "string") ? document.getElementById(o) : o,
	body = document.getElementsByTagName('body')[0];

	while ( o.offsetParent && o != body)
	{
		left += o.offsetLeft ;
		top += o.offsetTop ;
		o = o.offsetParent ;
	};

	obj.pageTop = top;
	obj.pageLeft = left;
}

function getEventObject( e )
{
	return e.target || e.srcElement;
}

function mouseX(evt)
{
	if (evt.pageX) return evt.pageX;
	else if (evt.clientX)
	return evt.clientX + (document.documentElement.scrollLeft ?
	document.documentElement.scrollLeft :
	document.body.scrollLeft);
	else return null;
}

function mouseY(evt)
{	
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY)	return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop :	document.body.scrollTop);
	else return null;
}

function getPosition(evt)
{
	if (!evt)
	evt = window.event;
	MouseX = mouseX(evt);
	MouseY = mouseY(evt);	
}
