//  ALLUC JavaScript Functions 


		var browserName = navigator.appName;
		var browserVer = parseInt(navigator.appVersion);
		var version = "";
		var msie4 = (browserName == "Microsoft Internet Explorer" && browserVer >= 4);
		if ((browserName == "Netscape" && browserVer >= 3) || msie4 || browserName=="Konqueror" || browserName=="Opera") {version = "n3";} else {version = "n2";}
			// Blurring links:
		function blurLink(theObject)	{	//
			if (msie4)	{theObject.blur();}
		}
		

function insert(aTag, eTag) {
  var input = document.getElementById('text');
  input.focus();
  /* für Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfügen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);      
    }
    range.select();
  }
  /* für neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfügen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* für die übrigen Browser */
  else
  {
    /* Abfrage der Einfügeposition */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
  }
}


function wopen(Adresse) {
  MeinFenster = window.open(Adresse);
  MeinFenster.focus();
}

// catsearch \\
function catsearch(to){
	if(document.getElementById('sWord').value.length > 2){
		var tolink = to + '&view=catSearch&sWord=' + document.getElementById('sWord').value;
		location.href = tolink;
	}else{
		alert('Please more then 2 letters!');
		return false;
	}
}

//  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //

function setCookie(name, wert, domain, expires, path)
{
   var cook = name + "=" + unescape(wert);
   cook += (domain) ? "; domain=" + domain : "";
   cook += (expires) ? "; expires=" + expires : "";
   cook += (path) ? "; path=" + path : "";
   document.cookie = cook;
}

function checkCookie()
{ 
	setCookie("CookieTest","en");
    return (getCookie("CookieTest") == "en"); 
}



//  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //
// vote \\

function setStars(rownum, vote)
{
	var imagename = '';
	var idname = '';
	
	// alert("setStarts:"+rownum+"/"+vote);
	
    for (var i=1;i<=5;i++)
	{
		if (i <= vote)
			imagename = "/images/star.gif";
		else
			imagename = "/images/nostar.gif";
		idname = "st"+i+"_"+rownum;
		
		if ((document.getElementById)&&(document.getElementById(idname))
		   )
			document.getElementById(idname).src = imagename;
		else if ((document.all)&&(document.all(idname)))
			document.all(idname).src = imagename;
		else if ((document.layers)&&(document.layers(idname)))
			document.layers(idname).src = imagename;
	}
}

function vote(objectid,rownum,points,page,params)
{
	var cookiecheck = checkCookie();
	if (!cookiecheck)
	{
		alert('You have to enable Cookies before you can vote.');
		return;
	}
	
/*
	var cook = getCookie('alluc_voting20');
	if(cook != null)
	{
		cooki = new Array();
		cooki = cook.split(";");
	
	for (var b=0;b<=cooki.length;b++){
		if (cooki[b] == uid){
			alert('You already voted this link.');
			return;
		}
	}
*/	
	
	var field = document.getElementById('points'+rownum);
	if(field != null)
	{
		field.value = points;
		setStars(rownum,points);
		document.location.href=page+'?mode=vote&linkid='+objectid+'&points='+points+params;
	}
}

function setVote(objectid, rownum)
{
	var field = document.getElementById('score'+rownum);
	if(field != null)
	{
		if(field.value > 0)
		{
			setStars(rownum,field.value);
			return;
		} 
	}
	setStars(rownum, 0); // Sterne löschen
}

//----------------------------------

function getCookie(NameOfCookie){
	if (document.cookie.length > 0)
	{
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1)
		{
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			
			if (end == -1) end = document.cookie.length;
				return unescape(document.cookie.substring(begin, end)); 
		}
	}
	return null;
}


//  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //

function register()
{
	location.href = 'register-now.html?login=false';
}

//  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //


// reportbrokenlink \\
function reportbrokenlink(id, captcha)
{
	//var abfrage = confirm('Do you really want to report this link as broken?');
	if (!captcha)
		document.reportbrokenlinkform.reportedlink.value=id;
	document.getElementById("reportbrokenlinkdiv").style.display = 'block';
	document.getElementById("reportbrokenlinkdiv").style.top = (250 + window.pageYOffset)+'px';
}



//  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //

function setwatchlist(objectid,add,page,params)
{
	if(add)
	{
		document.location.href=page+'?mode=watchlistadd&linkid='+objectid+params;
	}
	else
	{
		document.location.href=page+'?mode=watchlistremove&linkid='+objectid+params;
	}
}

function setwatchlistcat(catid,add,page,params)
{
	if(add)
	{
		document.location.href=page+'?mode=watchlistaddcat&catid='+catid+params;
	}
	else
	{
		document.location.href=page+'?mode=watchlistremovecat&catid='+catid+params;
	}
}


//  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //

// marklinks \\
function getCookie2(NameOfCookie)
{
	if (document.cookie.length > 0)
	{
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1)
		{
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			
			if (end == -1) end = document.cookie.length;
				return unescape(document.cookie.substring(begin, end)); 
		}
	}
	return '';
}



function showmarkedlinks(){

	var markedlinks = getCookie2("markedlinks");
	
	var ids = markedlinks.split("|");
	var links = "";
	
	var checktime = new Date();
	checktime = checktime.getTime() - 1000*60*60*24*30;
	
	var newclick = new Date();
	newclick = newclick.getTime() - 5000;
	
	var a = new Date();
	a = new Date(a.getTime() +1000*60*60*24*30);
	
	for(i=0; i<ids.length; i++){
		var info = ids[i].split("-");
		if(checktime < info[1] && isNaN(info[0]) == false){
			if(document.getElementById(info[0]) && info[1] < newclick){
				document.getElementById(info[0]).style.background='#66CCFF';
			}
			else if(info[1] > newclick){
				document.getElementById(info[0]).style.background = '#99FFFF';
			}
			links+=ids[i] +  "|";
		}
	}
	
	document.cookie = 'markedlinks=' + links + '; expires='+a.toGMTString()+';domain=alluc.org';
}


function marklink(id){

	var links = "";

	var jetzt = new Date();
	jetzt = jetzt.getTime();	
	links = getCookie2("markedlinks") + id + "-" + jetzt;
	

	document.getElementById(id).style.background = '#99FFFF';
	//alert(links);
	
	var a = new Date();
	a = new Date(a.getTime() +1000*60*60*24*30);
	
	document.cookie = 'markedlinks=' + links + '|; expires='+a.toGMTString()+';domain=alluc.org';
	//alert(links);
}



//  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //  //


// language \\
function getCookie(NameOfCookie)
{
	if (document.cookie.length > 0)
	{
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1)
		{
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			
			if (end == -1) end = document.cookie.length;
				return unescape(document.cookie.substring(begin, end)); 
		}
	}
	return 'en';
}


function decode(lang)
   {
    var url   = window.location.search;
    /* wie gehabt, es wird alles ab dem "?" gelesen */
    if (url != "")  {
      liste = url.split("&");
      /* auch hier splitten am "&" */
      for (i=0;i<=liste.length-1;i++) {
        temp = liste[i].split("=");
        /* auch hier splitten am "=" */
        temp[1]=temp[1].replace(/\+/g," ");
        temp[1]=unescape(temp[1]);
        /* wie gehabt, das Putzen aber jetzt:*/
       if(temp[0] == '?lang' || temp[0] == 'lang'){
		return temp[1];
	   }
       } 
     } 
   } 
   

function language(){

	var shortlang = new Array;
	var langlang = new Array;
	
	shortlang = Array("en","de","es");
	langlang = Array("English","German","Spanish");
	
	var flag = makelang();
	
	var selectbox = '<form action="changelanguage.php" method="POST"><img src="/images/flags/' + flag +'.gif" style="vertical-align:bottom;border-top: 4px solid #FFFFFF;border-left: 2px solid #FFFFFF;border-right: 2px solid #FFFFFF;border-bottom: 4px solid #FFFFFF;margin-bottom: 1px;"><select name="language" onchange="form.submit();">';
	
	for(i=0;i<shortlang.length;i++){
		
		if(shortlang[i] == flag){
			var selected = ' selected';
		}
		else selected = '';
		selectbox+='<option value="' +  shortlang[i] + '" ' + selected + '>' + langlang[i] + '</option>'; 
	}
	
	return selectbox + '</select></form>';
}

function setsearchlanguage(){
	if(document.forms['an_search'].elements['tx_ansearchit_form[sword]'].value.length<3){
		alert('Please more then 2 letters!');
		return false;
	}
	
	if(getCookie('language') != 'en'){
		document.getElementById('an_search').action+='&lang=' + getCookie('language');
	}
}

function makelang(){

	var flag = 'en';
	

	if(getCookie('language') == decode('lang')){
	 	flag = decode('lang');
	}
	else if(decode('lang') != getCookie('language') && typeof(decode('lang')) != 'undefined'){
		document.cookie = "language=" + decode('lang') + ";domain=alluc.org";
		flag = decode('lang');
	}
	else
		document.cookie = "language=en" + ";domain=alluc.org";
	
	if(!flag){
		flag="en";
		document.cookie = "language=en" + ";domain=alluc.org";
	}
	
	return flag;

}

function bigflag(){
var flag = makelang();
var resize = 2.5;
var width = (18 * resize);
var height = (12 * resize);

var shortlang = new Array;
var langlang = new Array;

shortlang = Array("en","de","es");
langlang = Array("English","German","Spanish");

for(i=0;i<shortlang.length;i++){
		if(shortlang[i] == flag){
			var flaglong = langlang[i];
		}
}
return '<img alt="Your selected language: ' + flaglong + '" title="Your selected language: ' + flaglong + '" style="border: 2px solid #ffffff;" width="' + width +'" height="' + height + '" src="/images/flags/' + flag +'_big.gif" />';
}

function smallflags(){
var flag = makelang();
var resize = 1.4;
var width = (18 * resize);
var height = (12 * resize);

var shortlang = new Array;
var langlang = new Array;

shortlang = Array("en","de","es");
langlang = Array("English","German","Spanish");

var content = '<form name="langselect" action="changelanguage.php" method="POST"><input type="hidden" name="language" value="en">';

for(i=0;i<shortlang.length;i++){
		if(shortlang[i] != flag){
			var flaglong = langlang[i];
			if(i == 1)
				content += '<a href="javascript:changelang(\'' + shortlang[i] + '\')"><img onclick="changelang(\'' + shortlang[i] + '\');" alt="Select ' + flaglong + '" title="Select ' + flaglong + '" style="vertical-align: bottom; horizontal-align: center; border: 1px solid #9cacbb; margin-bottom: 3px; margin-top: 3px; margin-left: 1px;" width="' + width +'" height="' + height + '" src="/images/flags/' + shortlang[i] +'_big.gif" /></a>&nbsp;&nbsp;';
			else
				content += '<a href="javascript:changelang(\'' + shortlang[i] + '\')"><img onclick="changelang(\'' + shortlang[i] + '\');" alt="Select ' + flaglong + '" title="Select ' + flaglong + '" style="vertical-align: bottom; horizontal-align: center; border: 1px solid #9cacbb; margin-bottom: 3px; margin-top: 3px;" width="' + width +'" height="' + height + '" src="/images/flags/' + shortlang[i] +'_big.gif" /></a>&nbsp;&nbsp;';
		}
}

content += '</form>';

return content;
}

function changelang(shortlang)
{
	document.langselect.language.value=shortlang;
	document.langselect.submit();
}

function changegenre(){
	if(document.getElementById("genreselect").style.display == "none"){
		document.getElementById("genreselect").style.display="inline";
		document.getElementById("newgenre").style.display="none";
		document.getElementById("genreselectlink").style.display="inline";
		document.getElementById("newgenrelink").style.display="none";
		document.setgenre.newgenretext.value = "";
	}
	else{
		document.getElementById("genreselect").style.display="none";
		document.getElementById("newgenre").style.display="inline";
		document.getElementById("genreselectlink").style.display="none";
		document.getElementById("newgenrelink").style.display="inline";
	}
}

function invert(that,todo,type){
	if(type == "top"){
		if(todo == 'in'){
			that.style.backgroundImage = 'url(/images/background/topbuttonselected.gif)';
		}
		else{
			that.style.backgroundImage = 'url(/images/background/topbutton.gif)';
		}
	}
	else if (type == "new"){
		if(todo == 'in'){
			that.style.backgroundImage = 'url(/images/background/leftbuttonselected.gif)';
		}
		else{
			that.style.backgroundImage = 'url(/images/background/leftbutton_new.gif)';
		}
	}
	else{
		if(todo == 'in'){
			that.style.backgroundImage = 'url(/images/background/leftbuttonselected.gif)';
		}
		else{
			that.style.backgroundImage = 'url(/images/background/leftbutton.gif)';
		}
	}
}


// Watchlist funktionen
function getwatchlist(uid){
	var watchlist = getCookie2("watchlist");
	
	var watchids = watchlist.split("|");
	
	for(i=0; i<watchids.length; i++){
		if(watchids[i] == uid)
			return '<img src="fileadmin/templates/remove.gif" alt="Remove from watchlist" title="Remove from watchlist">';
	}
	return '<img src="fileadmin/templates/watchlist.png" alt="Add link to watchlist" title="Add link to watchlist">';
	
}

function getwatchlistseason(uid){
	var watchlist = getCookie2("watchseasons");
	
	var watchids = watchlist.split("|");
	
	for(i=0; i<watchids.length; i++){
		if(watchids[i] == uid)
			return '<img src="fileadmin/templates/remove.gif" alt="Remove all links from watchlist" title="Remove from watchlist">';
	}
	return '<img src="fileadmin/templates/watchlist.png" alt="Add all links to watchlist" title="Add link to watchlist">';
}


/*function charCounter(charInputSrcName, maxCharCount) {  
  
   // Zugriffsvariablen festlegen  
   var charInputSrc = document.getElementById(charInputSrcName);  
  
   if (charInputSrc != null) {  
      // Länge des Feldinhaltes prüfen  
      if (charInputSrc.value.length <= maxCharCount) {  
         // Anzahl Restzeichen berechnen und Zeichenanzeige aktualisieren  
         charsToGo = maxCharCount - charInputSrc.value.length;  
      }  
      else  
         // Eingegebenes Zeichen wieder abschneiden  
         charInputSrc.value = charInputSrc.value.substring(0, maxCharCount);  
         charsToGo = maxCharCount - charInputSrc.value.length;  
      }  
}  */

function charCounter(charInputSrcName, maxCharCount) {  
  
   // Zugriffsvariablen festlegen  
  var charInputSrc = document.getElementById(charInputSrcName);  
  
  if (charInputSrc != null) {  
  	 //alert(charInputSrc.selectionStart);
  	 CharCountString = charInputSrc.value;
  	 CharCountString = CharCountString.replace('[b]', '');
  	 CharCountString = CharCountString.replace('[/b]', '');
  	 CharCountString = CharCountString.replace('[i]', '');
  	 CharCountString = CharCountString.replace('[/i]', '');
  	 CharCountString = CharCountString.replace('[u]', '');
  	 CharCountString = CharCountString.replace('[/u]', '');
  	 CharCountString = CharCountString.replace('[list]', '');
  	 CharCountString = CharCountString.replace('[/list]', '');
  	 CharCountString = CharCountString.replace('[*]', '');
  	 CharCountString = CharCountString.replace('[/*]', '');
  	
  	if( document.selection )
  	{
  		CharCountString = CharCountString.replace(/\r/g, '');
  		
  	}
  	
  	 if (CharCountString.length <= maxCharCount) {  
         // Anzahl Restzeichen berechnen und Zeichenanzeige aktualisieren  
         charsToGo = maxCharCount - CharCountString.length;  
       
      }  
      else
      {
      
      	if( navigator.appVersion.indexOf("MSIE") != -1 ){
      		
			// The current selection
			var range = document.selection.createRange();
			// We'll use this as a 'dummy'
			var stored_range = range.duplicate();
			
			// Select all text
			stored_range.moveToElementText( charInputSrc );
			
			// Now move 'dummy' end point to end point of original range
			stored_range.setEndPoint( 'EndToEnd', range );
			// Now we can calculate start and end points
			charInputSrc.selectionStart = stored_range.text.length - range.text.length;
			charInputSrc.selectionEnd = charInputSrc.selectionStart + range.text.length;
			
		}
      	
      	
        var cursorPosition = charInputSrc.selectionStart;
        
      	var scrollPosition = charInputSrc.scrollTop;
      	temptext = charInputSrc.value.substring(0,cursorPosition-(CharCountString.length-maxCharCount));
      	var results = temptext.match(/\n/g);
      	
      	temptext += charInputSrc.value.substring(cursorPosition, charInputSrc.value.length);
      	charInputSrc.value = temptext;
      	charInputSrc.focus();
      	
      	if (navigator.appVersion.indexOf("MSIE") == -1)
			charInputSrc.setSelectionRange(cursorPosition-(CharCountString.length-maxCharCount),cursorPosition-(CharCountString.length-maxCharCount));
		else
		{
			
			var range = charInputSrc.createTextRange();
			range.collapse(true);
				
			if (results != null)
			{
				range.moveEnd('character', cursorPosition-(CharCountString.length-maxCharCount)-results.length);
				
				range.moveStart('character', cursorPosition-(CharCountString.length-maxCharCount)-results.length);
			}
			else
			{
				range.moveEnd('character', cursorPosition-(CharCountString.length-maxCharCount));
				
				range.moveStart('character', cursorPosition-(CharCountString.length-maxCharCount));
			}
			range.select();
		}
		
		cursorPosition = charInputSrc.selectionStart;
		temptext = charInputSrc.value.substring(0,cursorPosition);
		var results = temptext.match(/\n/g);
		
		charInputSrc.scrollTop = scrollPosition;
		var charsToGo = maxCharCount - CharCountString.length;
		
		
      }
      if (charsToGo<0)
      	charsToGo = 0;
       return charsToGo; 
  }
  
}  


function showMore()
{
	var shorttext = document.getElementById('shorttext');
	var longtext = document.getElementById('text');
	
	if(shorttext.style.display == 'none')
	{
		longtext.style.display = 'none';
		shorttext.style.display = 'block';
		
		if(document.getElementById('shbox').offsetHeight > 560)
			document.getElementById('admincontent').style.height = document.getElementById('shbox').offsetHeight+'px';
		else
			document.getElementById('admincontent').style.height = '560px';
		
		defHeight = 560;
	}
	else
	{
		
		var results = longtext.innerHTML.match(/<br>|<BR>/g);
		
		if (results)
			document.getElementById('admincontent').style.height = 560+(13*results.length)+'px';
			
		shorttext.style.display = 'none';
		longtext.style.display = 'block';
		
		defHeight = document.getElementById('admincontent').style.height.replace('px','');
	}
}

function setValueForPageBlatt(value)
{
	 var obj = document.getElementsByName('page');
	 
	 for(var c = 0; c < obj.length; c++)
	 	document.getElementsByName('page')[c].value = value;
}

/* Hifefunktionen für ältere Browser (Letter-Blätter-Funktion) */
if(window.navigator.systemLanguage && !window.navigator.language) 
{
	function hoverIE() 
	{
		var LI = document.getElementById("Navigation").firstChild;
		do 
		{
			if (sucheUL(LI.firstChild)) 
			{
				LI.onmouseover=einblenden; 
				LI.onmouseout=ausblenden;
			}
			LI = LI.nextSibling;
		}
		while(LI);
	}
	function sucheUL(UL) 
	{
		do
		{
			if(UL) UL = UL.nextSibling;
			if(UL && UL.nodeName == "UL") 
				return UL;
		}
		while(UL);
		return false;
	}
	function einblenden() 
	{
		var UL = sucheUL(this.firstChild);
		UL.style.display = "block"; UL.style.backgroundColor = "silver";
	}
	function ausblenden() 
	{
		sucheUL(this.firstChild).style.display = "none";
	}
	window.onload=hoverIE;
}
