droplistcount=0;
loading=false;
last_state="new";
last_start=0;
last_order="id DESC";

function feedbackFocus(getsfocus)
{
	if(getsfocus)
	{
		if(document.getElementById("feedbacktextfield").value=='                    Nachricht hier eingeben') document.getElementById("feedbacktextfield").value='';
		setClass("feedbacktextfield","feedbacktext2");
	}
	else
	{
		if(document.getElementById("feedbacktextfield").value=='') document.getElementById("feedbacktextfield").value='                    Nachricht hier eingeben';
		setClass("feedbacktextfield","feedbacktext1");
	}
}

function deleteMyFeed(fid,trc,t)
{
	$.ajax
	({
		type:"POST",
		url:"index.php",
		data:"go=feeds&delete="+fid,
		
		beforeSend:function(data)
		{
			document.getElementById('td_'+trc+'a'+t).innerHTML="<img src='img/icons/wait.gif' border=0 width=11 height=11 alt='Wird gelöscht'>";
			document.getElementById('td_'+trc+'b'+t).innerHTML="Wird gelöscht";
		},
		
		success:function(data)
		{
			document.getElementById('td_'+trc+'a'+t).innerHTML="";
			document.getElementById('td_'+trc+'b'+t).innerHTML="";
			document.getElementById('td_'+trc+'c'+t).innerHTML="";
			document.getElementById('td_'+trc+'d'+t).innerHTML="";
			document.getElementById('td_'+trc+'e'+t).innerHTML="";
			document.getElementById('td_'+trc+'f'+t).innerHTML="";
			document.getElementById('td_'+trc+'g'+t).innerHTML="";
			document.getElementById('td_'+trc+'h'+t).innerHTML="";
		}
	});
}

function spiderWebsiteTitle(url,trc)
{
	$.ajax
	({
		type:"POST",
		url:"index.php",
		data:"go=getwebtitle&url="+url+"&trc="+trc,
		
		beforeSend:function(data)
		{
			document.getElementById('webtitle'+trc).innerHTML="<img src='img/icons/abc.gif' border=0 alt='Searching title'><br>";
		},
		
		success:function(data)
		{
			document.getElementById('webtitle'+trc).innerHTML=data;
		}
	});
}

function switchPrivateState(urlid,p,trc)
{
	$.ajax
	({
		type:"POST",
		url:"index.php",
		data:"go=switchprivate&urlid="+urlid+"&p="+p,
		
		beforeSend:function(data)
		{
			document.getElementById("privateimgwait"+trc).style.display="";
			document.getElementById("privateimg0"+trc).style.display="none";
			document.getElementById("privateimg1"+trc).style.display="none";
		},
		
		success:function(data)
		{
			if(p==1)
			{
				document.getElementById("privateimg0"+trc).style.display="none";
				document.getElementById("privateimg1"+trc).style.display="";
				document.getElementById("privateimgwait"+trc).style.display="none";
			}
			else
			{
				document.getElementById("privateimg0"+trc).style.display="";
				document.getElementById("privateimg1"+trc).style.display="none";
				document.getElementById("privateimgwait"+trc).style.display="none";
			}
		}
	});
}

function waitAndReloadHome()
{
	delay=0;
		
	try
	{
		arr=document.getElementById("droptarget").value.split("\r\n");
		rowcount=arr.length;
		delay=rowcount*500;
	}
	catch(e) { }
	
	setTimeout("reloadWebsite()",2222+delay);
}

function setInnerHTML(id,str)
{
	document.getElementById(id).innerHTML=str;
}

function foo()
{
	// nix
	endLoading();
}

function setClass(id,classname)
{
	document.getElementById(id).className=classname;
}

function reloadWebsite()
{
	location.reload();
}

function setSelectIndex(id,index)
{
	document.getElementById(id).options[index].selected=true; 
}

function showAddUrlOptions()
{
	document.getElementById('ul_more_addoptions').style.display=""; 
}

function hideAddUrlOptions()
{
	document.getElementById('ul_more_addoptions').style.display="none"; 
}

function showMoreAddOptions()
{
	document.getElementById('show_more_addoptions').style.display="none"; 
	document.getElementById('ul_more_addoptions').style.display=""; 
}

function setRssGenres()
{
	document.getElementById('form_setgenre').submit();
}

function setHomeFormActions(action)
{
	for(i=1;i<=3;i++) setFormAction("homeform"+i,action);
}

function setFormAction(formname,action)
{
	try
	{
		document.getElementById(formname).action="?"+action;
	}
	catch(e){};
}

function parseFeed(feedid)
{
	startLoading();
	x_parseFeed(feedid,feedParsed);
}

function feedParsed(result)
{
	if(confirm(result+" Links hinzugefügt. Möchten Sie diese Links jetzt sehen?"))
	{
		location.href="?new";
	}
	
	endLoading();
}

function setActiveLi(i)
{
	try
	{
		for(x=1;x<=4;x++) document.getElementById('homeli'+x).className=document.getElementById('homeli'+x).title;
		document.getElementById('homeli'+i).className="activeli";
	}
	catch(e){};
}

function putLinkIntoTextfield(url)
{
	try
	{
		document.getElementById('droptarget').value=url;
	}
	catch(e){};
}

function showMovingArrows()
{
	try
	{
		document.getElementById('img_movingarrorw').style.display=""; 
	}
	catch(e){};
}

function hideMovingArrows()
{
	try
	{
		document.getElementById('img_movingarrorw').style.display="none";
	}
	catch(e){};
}

function hideNotSupportedLinkWarning()
{
	try
	{
		document.getElementById('dropped_link_not_suppported').style.display="none";
	}
	catch(e){};
}

function showLoadingIconForIWantIt(i)
{
	try
	{
		document.getElementById('img_iwantit_loading'+i).style.display="";
		document.getElementById('img_iwantit_add'+i).style.display="none";
	}
	catch(e){};
}

function showCheckIconForIWantIt(i)
{
	try
	{
		document.getElementById('img_iwantit_add'+i).style.display="none";
		document.getElementById('img_iwantit_loading'+i).style.display="none";
		document.getElementById('img_iwantit_check'+i).style.display="";
		
		endLoading();
	}
	catch(e){};
}

function transferFinishedUrlToMyAccount(trid,url,from_uid)
{
	if(!loading)
	{
		showLoadingIconForIWantIt(trid);
		putLinkIntoTextfield(url);
		addLinkToLinkList();
		addUrl('from_'+from_uid,'',"no_redirect");
		
		setTimeout("showCheckIconForIWantIt("+trid+")",500);
		//setTimeout("clearTrs("+trid+")",800);
	}
}

function transferFeedToMyAccount(trid,url,uid)
{
	if(!loading)
	{
		startLoading();
		showLoadingIconForIWantIt(trid);
		x_addFeed(url,uid,trid,feedAdded);
	}
}

function feedAdded(result)
{
	trid=result;
	
	setTimeout("showCheckIconForIWantIt("+trid+")",500);
	endLoading();
}

function clearDroppedUrls()
{
	document.getElementById('btn_addlinks').value="No links so far";
	document.getElementById('droppedlinks').value="";
	droplistcount=0;
	
	hideNotSupportedLinkWarning();
}

function switchButton_SaveToSaving()
{
	setValue('btn_save','Saving..');
	setBgColor('btn_save','#DCACA3');
	disableObject("btn_save");
}

function switchButton_SavingToSaved()
{
	setValue('btn_save','Saved!');
	setBgColor('btn_save','#CADBA8');
	setTimeout("switchButton_SavingToSave()",500);
}

function switchButton_SavingToSave()
{
	setValue('btn_save','Save');
	setBgColor('btn_save','');
	enableObject("btn_save");
}

function addLinkToLinkList()
{
	url=document.getElementById('droptarget').value;
	
	if(url!="")
	{
		hideNotSupportedLinkWarning();
		switchButton_SaveToSaving();
		
		document.getElementById('droppedlinks').value=document.getElementById('droppedlinks').value+url+"\n";
		
		/*if(url.substr(0,4)=="www.")
		{
			url="http://"+url;
			document.getElementById('droptarget').value=url;
		}
		
		if(url.substr(0,4)=="http")
		{
			document.getElementById('droppedlinks').value=document.getElementById('droppedlinks').value+url+"\n";
			document.getElementById('droptarget').value="";
			
			droplistcount++;
		}
		else
		{
			document.getElementById('dropped_link_not_suppported').style.display="";
		}*/
		
		setTimeout("switchButton_SavingToSaved()",1400);
	}
		
	switch(droplistcount)
	{
		case 0: 
			document.getElementById('btn_addlinks').value="No links so far";
			break;
			
		case 1: 
			document.getElementById('btn_addlinks').value="OK, add link";
			break;
			
		default: 
			document.getElementById('btn_addlinks').value="OK, add links ("+droplistcount+")";
			break;
	}
}

function hideYeahSmiley()
{
	try
	{
		document.getElementById('img_yeahsmiley').style.display="none";
	}
	catch(e){};
}

function markAllCheckboxes()
{
	try
	{
		itemcount=document.getElementById('itemcount').value;
			
		for(i=1;i<=itemcount;i++)
		{
			document.getElementById('cb'+i).checked=true;
		}
	}
	catch(e){};
	
	document.getElementById('img_mark').style.display="none";
	document.getElementById('img_unmark').style.display="";
}

function unmarkAllCheckboxes()
{
	try
	{
		itemcount=document.getElementById('itemcount').value;
		
		for(i=1;i<=itemcount;i++)
		{
			document.getElementById('cb'+i).checked=false;
		}
	}
	catch(e){};
	
	document.getElementById('img_mark').style.display="";
	document.getElementById('img_unmark').style.display="none";
}

function addBrowserCss()
{
	addIeCss();
	addFfCss();
}

function addIeCss()
{
	if (navigator.userAgent.indexOf("MSIE")!==-1)
	{
		document.write("<style>"+
		".minimize{"+
		"margin-right:2px;"+
		"height:10px;"+
		"min-height:10px;"+
		"max-height:10px;"+
		"top:-3px;"+
		"}"+
		".downloadsoftware{"+
		"position:relative;"+
		"left:684px;"+
		"top:-50px;"+
		"}"+
		"</style>");
	}
}

function addFfCss()
{
	if (navigator.userAgent.indexOf("Mozilla")!==-1)
	{
		document.write("<style>.minimize{margin-top:-16px;}</style>");
	}
}

function showHtmlCode(area)
{
	document.getElementById("static_code").style.display="none";
	document.getElementById("floating_code").style.display="none";
	
	document.getElementById(area+"_code").style.display="";
}

function switchDisplay(id)
{
	if(document.getElementById(id).style.display=="none")
		document.getElementById(id).style.display=""; else
		document.getElementById(id).style.display="none";
}

function setBgColor(id,color)
{
	try
	{
		document.getElementById(id).style.backgroundColor=color;
	}
	catch(e){}
}

function setValue(id,str)
{
	try
	{
		document.getElementById(id).value=str;
	}
	catch(e){}
}

function disableObject(id)
{
	try
	{
		document.getElementById(id).disabled=true;
	}
	catch(e){}
}

function enableObject(id)
{
	try
	{
		document.getElementById(id).disabled=false;
	}
	catch(e){}
}

function hideCategorizeDiv()
{
	try
	{
		document.getElementById("div_categorize").style.display="none";
	}
	catch(e){}
}

function startLoading()
{
	try
	{
		document.getElementById('loadinggif').style.display="block";
		loading=true;
	}
	catch(e){}
}

function endLoading()
{
	try
	{
		document.getElementById('loadinggif').style.display="none";
		loading=false;
	}
	catch(e){}
}

function sleep(ms)
{ 
	var zeit=(new Date()).getTime(); 
	var stoppZeit=zeit+ms; 
	
	while((new Date()).getTime()<stoppZeit)
	{
		//
	} 
}

function hideMessageBox(boxid)
{
	try
	{
		document.getElementById(boxid).style.display="none";
	}
	catch(e){}
}

function clearDropTarget()
{
	try
	{
		document.getElementById("droptarget").value="";
	}
	catch(e){}
}

function replaceStandardText()
{
	oldstr=document.getElementById("droptarget").value;
	
	if(oldstr!="Url hier eintragen")
	{
		newstr=oldstr.replace("Url hier eintragen","");
		
		document.getElementById("droptarget").value=newstr;
	}
}

function hideSpeechBubble()
{
	try
	{
		document.getElementById("speechbubble_drophere").style.display="none";
		clearDropTarget();
	}
	catch(e){}
}

function showOptionTds(trid)
{
	/*document.getElementById("td_"+trid+"3").style.display="";
	document.getElementById("td_"+trid+"4").style.display="";
	document.getElementById("td_"+trid+"5").style.display="";*/
}

function hideOptionTds(trid)
{
	/*document.getElementById("td_"+trid+"3").style.display="none";
	document.getElementById("td_"+trid+"4").style.display="none";
	document.getElementById("td_"+trid+"5").style.display="none";*/
}

function hideCategorizeBox(trid)
{
	try
	{
		document.getElementById("span_categorize"+trid).innerHTML="";
	}
	catch(e){}
}

//-------------------------------------------------------
// Kategoriesierungsoptionen setzen

function showCategorizeOptions(id,trid,state)
{
	startLoading();
	
	x_showCategorizeOptions(id,trid,state,setCategorizeOptions);
}

function setCategorizeOptions(result)
{
	var id=result[0];
	var trid=result[1];
	var html=result[2];
		
	document.getElementById("div_categorize").style.display="";
	document.getElementById("div_categorize").innerHTML="<div class='main' style='margin:0px;'><div class='title'>Set new state</div>"+html+"</div>";
	
	endLoading();
}

function loadSessionStates()
{
	x_loadSessionStates(0,setSessionStates);
}

function setSessionStates(result)
{
	last_state=result[0];
	last_start=result[1];
	last_order=result[2];
}

//-------------------------------------------------------
// Linllisten ausgeben

function statesSaved(result)
{
	//alert(result);
}

function setLinks(result)
{
	if(result=="NO_NEW_LINKS")
	{
		document.getElementById("linklist").innerHTML="There are no links which match your query.";
	}
	else
	{
		document.getElementById("linklist").innerHTML="<table class='urltable' border='0' cellpadding='2' cellspacing='0' width='100%'><tr width=10><th></th><th align=right><b>User</b></th><th width=13></th><th onclick='orderLinks(\"url\")'><b>Url</b></th><th></th><th><b>Errors</b></th><th align=right><b>Downloads</b></th><th align=right><b>Comments</b></th><th><b>Last update</b></th><th><b>Genre</b></th><th colspan=3 align=center><b>Prioity</b></th><th width=20>Size</th></tr>"+result+"</table>";
	}
	
	setTimeout("hideYeahSmiley()",3100);
	endLoading();
}

function setNaviArrows(state,start,order,genre,url,group)
{
	p=(start-100);
	n=(start-(-100));
	
	if(p<0) p=0;
	if(n<0) n=0;
	
	try
	{
		document.getElementById("navi_arrow_left1").innerHTML="<div class='navi_arrow_left' onclick=\"location.href='?go=home&state="+state+"&filter_genre="+genre+"&filter_url="+url+"&start="+p+"&order="+order+"&group="+group+"'\"></div>";
		document.getElementById("navi_arrow_left2").innerHTML="<div class='navi_arrow_left' onclick=\"location.href='?go=home&state="+state+"&filter_genre="+genre+"&filter_url="+url+"&start="+p+"&order="+order+"&group="+group+"'\"></div>";
		document.getElementById("navi_arrow_right1").innerHTML="<div class='navi_arrow_right' onclick=\"location.href='?go=home&state="+state+"&filter_genre="+genre+"&filter_url="+url+"&start="+n+"&order="+order+"&group="+group+"'\"></div>";
		document.getElementById("navi_arrow_right2").innerHTML="<div class='navi_arrow_right' onclick=\"location.href='?go=home&state="+state+"&filter_genre="+genre+"&filter_url="+url+"&start="+n+"&order="+order+"&group="+group+"'\"></div>";
	}
	catch(e){}
}

//-------------------------------------------------------
// Url löschen

function deleteUrl(id,trid)
{
	hideCategorizeDiv();
	startLoading();
	
	if(id>0 && trid>0)
	{
		x_deleteUrl(id,trid,clearTrs)
	}
}

function clearTrs(result)
{
	if(result>0)
	{
		for(i=1;i<=13;i++)
		{
			try
			{
				document.getElementById("td_"+result+i).innerHTML="";
				document.getElementById("td_"+result+i).style.height="0px";
			}
			catch(e){}
		}
	}
	
	endLoading();
}

//-------------------------------------------------------
// Url verschieben

function moveUrlUp(id,uid,state)
{
	hideCategorizeDiv();
	startLoading();
	x_moveUrlUp(id,uid,state,reloadCurrentList);
}

function moveUrlDown(id,uid,state)
{
	hideCategorizeDiv();
	startLoading();
	x_moveUrlDown(id,uid,state,reloadCurrentList);
}

function reloadCurrentList(result)
{
	//location.reload();
}

function ReTryToDownloadErrorLinks()
{
	startLoading();
	x_ReTryToDownloadErrorLinks(x,true,reloadWebsite);
}

function ReTryToDownloadLinks(state,uid)
{
	startLoading();
	x_ReTryToDownloadLinks(state,uid,reloadWebsite);
}

//-------------------------------------------------------
// Url hinzufügen

function addUrl(mode,filter,redirect)
{
	droped_by=0;

	if(mode=="" || mode==undefined || mode=="undefined")
	{
		mode="get_new_links";
	}
	else
	{
		if(mode.substr(0,5)=="from_")
		{
			droped_by=mode.substr(5);
			mode="no_action";
		}
	}
	
	urls=document.getElementById("droppedlinks").value;
	genre=document.getElementById("droppedgenre").value;
	
	if(urls!="" && urls!="Url hier eintragen")
	{
		startLoading();
		hideCategorizeDiv();
		replaceStandardText();
		showMovingArrows();
		x_addUrl(urls,genre,mode,filter,0,droped_by,0,reloadCurrentList);
	}
}

function urlAdded(result)
{
	phpreturn=result[0];
	uid=result[1];
	showalert=result[2];
	getnewlinks=result[3];
	alerts="";

	if(typeof phpreturn!="object") // einzelne url wurde hinzugefügt
	{
		if(phpreturn=="OK")
		{
			if(showalert) alerts="Ihre übergebenen URLs wurden erfolgreich gespeichert.";
		}
		else
		{
			alerts="Die übergebenen URLs konnten nicht gespeichert werden.";
			/*
			if(phpreturn=="USER_NOT_FOUND")
			{
				alerts="Sorry, the Url could not be saved. Are you logged in? ;-)";
			}
			else
			{
				alerts="Sorry, this the could not be saved. Please try again later. :-(";
			}
			*/
		}
		
		if(showalert) alert(alerts);
	}
	else
	{
		for(i=0;i<500;i++)
		{
			if(phpreturn[i]=="" || phpreturn[i]=="undefined" || phpreturn[i]==undefined) break;
			
			if(phpreturn[i]=="OK")
			{
				alerts=alerts+"URL #"+(i+1)+": gespeichert\n";
			}
			else
			{
				if(phpreturn[i]=="USER_NOT_FOUND")
				{
					alerts=alerts+"URL #"+(i+1)+": User nicht gefunden\n";
				}
				else
				{
					if(phpreturn[i]=="NOT_ALLOWED")
					{
						alerts=alerts+"URL #"+(i+1)+": Nicht erlaubt\n";
					}
					else
					{
						alerts=alerts+"URL #"+(i+1)+": Nicht gespeichert\n";
					}
				}
			}
		}
		
		if(showalert) alert(alerts);
	}
	
	if(getnewlinks) getLinks("new",0,uid,true,"id DESC");
	
	document.getElementById('btn_addlinks').value="No links so far";
	droplistcount=0;
	
	clearDropTarget();
	hideMovingArrows();
	clearDroppedUrls();
	endLoading();
}

function subscribeToUsersUrl(droped_by,trid)
{
	startLoading();
	
	get_old_links=confirm("Sie haben alle Links von diesem Benutzer in Ihre eigene Liste übertragen.\n\nMöchten Sie auch alle zukünftigen links von diesem Benutzer erhalten?\nWenn ja, dann klicken Sie bitte auf 'OK'.");
	
	document.getElementById('img_subscribe'+trid).style.display="none";
	document.getElementById('img_subscribe_loading'+trid).style.display="";
	
	x_subscribeToUsersUrl(droped_by,trid,get_old_links,setSubscribeToUsersUrl)
}

function setSubscribeToUsersUrl(result)
{
	trid=result[0];
	text=result[1];
	
	if(text=="NO_VALID_USER")
	{
		alert("User ist nicht gültig.");
	}
	else
	{
		if(text=="ALREADY_SUBSRIBED")
		{
			alert("URLs von diesem User haben Sie bereits abonniert.");
		}
		else
		{
			document.getElementById('img_subscribe_loading'+trid).style.display="none";
			document.getElementById('img_subscribe_check'+trid).style.display="";
		}
	}
	
	endLoading();
}

function showSetTitle(trid,urlid)
{
	document.getElementById('img_settitle'+trid).style.display="none";
	document.getElementById('titlediv'+trid).style.display="";
}

function saveTitle(urlid,trid)
{
	startLoading();
	
	document.getElementById('img_savetitle_loading'+trid).style.display="";
	document.getElementById('savetitlebuitton'+trid).style.display="none";
	txt=document.getElementById('titletext'+trid).value;

	x_saveTitle(urlid,trid,txt,setSavedTitle);
}

function setSavedTitle(result)
{
	res=result[0];
	trid=result[1];
	url=result[2];
	txt=result[3];
	
	document.getElementById('img_savetitle_loading'+trid).style.display="none";
	document.getElementById('titlediv'+trid).style.display="none";
	
	if(res=="OK")
	{
		document.getElementById('img_settitle_check'+trid).style.display="";
		document.getElementById('urltext'+trid).innerHTML="<a href='"+url+"'>"+txt+"</a>";
	}
	else
	{
		alert("Dieser Titel konnte ncht gespeichert werden.");
	}
	
	endLoading();
}

function cancelTitle(urlid,trid)
{
	document.getElementById('titlediv'+trid).style.display="none";
	document.getElementById('img_settitle'+trid).style.display="";
}

//--------------------------------------------------------
// Freunde

function deleteFriend(fid)
{
	startLoading();
	
	x_deleteFriend(fid,clearFriendRow);
}

function clearFriendRow(result)
{
	if(result>0) document.getElementById("div_friend"+result).innerHTML="";
	
	endLoading();
}