
var activeBorder = false;
var activeTagInput = false;

function _playerAdd(anchor) {
    var url = anchor.href;
    var code = '<object type="application/x-shockwave-flash" data="/includes/player/musicplayer_f6.swf?song_url=' + url +'&amp;b_bgcolor=ffffff&amp;b_fgcolor=000000&amp;b_colors=0000ff,0000ff,ff0000,ff0000&buttons=/includes/player/load.swf,/includes/player/play.swf,/includes/player/stop.swf,/includes/player/error.swf" width="14" height="14">';
    var code = code + '<param name="movie" value="/includes/player/musicplayer.swf?song_url=' + url +'&amp;b_bgcolor=ffffff&amp;b_fgcolor=000000&amp;b_colors=0000ff,0000ff,ff0000,ff0000&amp;buttons=/includes/player/load.swf,/includes/player/play.swf,/includes/player/stop.swf,/includes/player/error.swf" />';
    var code = code + '</object>';
    anchor.parentNode.innerHTML = code +' '+ anchor.parentNode.innerHTML;
}

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, '');
};

var deleted = false;
function deleteBookmark(ele, input){
    var confirmDelete = "<span>Sind Sie sicher? <a href=\"#\" onclick=\"deleteConfirmed(this, " + input + ", \'\'); return false;\">Ja</a> - <a href=\"#\" onclick=\"deleteCancelled(this); return false;\">Nein</a></span>";
    ele.style.display = 'none';
    ele.parentNode.innerHTML = ele.parentNode.innerHTML + confirmDelete;
}

function deleteCancelled(ele) {
    var del = previousElement(ele.parentNode);
    del.style.display = 'inline';
    ele.parentNode.parentNode.removeChild(ele.parentNode);
    return false;
}

function deleteConfirmed(ele, input, response) {
    if (deleted == false) {
        deleted = ele.parentNode.parentNode.parentNode;
    }
    var post = deleted;
    post.className = 'xfolkentry deleted';
    if (response != '') {
        post.style.display = 'none';
        deleted = false;
    } else {
        loadXMLDoc('/ajaxDelete?id=' + input);
    }
}


function setClicks(input) {
	var xmlhttp2 = new XMLHttpRequest();
	xmlhttp2.open("GET", "/ajaxSetClicks?id=" + input, false);
	xmlhttp2.send('');

}



function previousElement(ele) {
    ele = ele.previousSibling;
    while (ele.nodeType != 1) {
        ele = ele.previousSibling;
    }
    return ele;
}

function isAvailable(input, response){
    var usernameField = document.getElementById("username");
    var username = usernameField.value;
    username = username.toLowerCase();
    username = username.trim();
    var availability = document.getElementById("availability");
    if (username != '') {
        usernameField.style.backgroundImage = 'url(/loading.gif)';
        if (response != '') {
            usernameField.style.backgroundImage = 'none';
            if (response == 'true') {
                availability.className = 'available';
                availability.innerHTML = 'Gewünschter Mitgliedsname ist verfügbar';
            } else {
                availability.className = 'not-available';
                availability.innerHTML = 'Gewünschter Mitgliedsname ist bereits vergeben';
            }
        } else {
            loadXMLDoc('/ajaxIsAvailable?username=' + username);
        }
    }
}

function useAddress(ele) {
    var address = ele.value;
    if (address != '') {
        if (address.indexOf(':') < 0) {
            address = 'http:\/\/' + address;
        }
        getTitle(address, null);
        ele.value = address;
    }
}

function getTitle(input, response){
    var title = document.getElementById('titleField');
    if (title.value == '') {
        title.style.backgroundImage = 'url(/loading.gif)';
        if (response != null) {
            title.style.backgroundImage = 'none';
            title.value = response;
        } else if (input.indexOf('http') > -1) {
            loadXMLDoc('/ajaxGetTitle?url=' + input);
        } else {
            return false;
        }
    }
}

var xmlhttp;
function loadXMLDoc(url) {
    // Native
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = processStateChange;
        xmlhttp.open("GET", url, true);
        xmlhttp.send(null);
    // ActiveX
    } else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        if (xmlhttp) {
            xmlhttp.onreadystatechange = processStateChange;
            xmlhttp.open("GET", url, true);
            xmlhttp.send();
        }
    }
}

function processStateChange() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        response = xmlhttp.responseXML.documentElement;
        method = response.getElementsByTagName('method')[0].firstChild.data;
        result = response.getElementsByTagName('result')[0].firstChild.data;
	eval(method + '(\'\', result)');
    }
}


function playerLoad() {
    var anchors = document.getElementsByTagName('a');
    var anchors_length = anchors.length;
    for (var i = 0; i < anchors_length; i++) {
        if (anchors[i].className == 'taggedlink' && anchors[i].href.match(/\.mp3$/i)) {
            _playerAdd(anchors[i]);
        }
    }
}

// OJ alltagz addon

function substituteImageUrl( name ){
	var imageUrl = "&lt;a href=\"javascript:x=document;a=encodeURIComponent(x.location.href);t=encodeURIComponent(x.title);d=encodeURIComponent(window.getSelection());open('http://www.alltagz.de/bookmarks/?action=add&popup=1&address='+a+'&title='+t+'&description='+d,'alltagz','modal=1,status=0,scrollbars=1,toolbar=0,resizable=1,width=730,height=465,left='+(screen.width-730)/2+',top='+(screen.height-425)/2);void 0;\"&gt;&lt;img src=\"http://www.alltagz.de/add2alltagz/"+name+".png\" border=0 /&gt;&lt;/a&gt;";
	document.getElementById( 'postButton' ).innerHTML = imageUrl;
}

function getTags(input, response){
    var tags = document.getElementById('recommend');
    if (tags.innerHTML == '') {
        if (response != null) {
	    data = response.split("|||");
	    tagcloud = data[0].split(" ");
	    count = data[1].split(" ");
	    if (data != 'undefined') {
	    	for(i = 0; i < tagcloud.length; i++) {
               		tags.innerHTML += "<a id='recommendedtags' style='font-size: "+count[i]+";' class='recommendedtags' href='javascript:{}' onclick='addTag(this)'>"+tagcloud[i]+"</a> ";
	    	}
	    }
        } else if (input.indexOf('http') > -1) {
            loadXMLDocTags('/ajaxGetTags?url=' + input);
        } else {
            return false;
        }
    }
}

function useAddressTag(ele) {
    var address = ele.value;
    if (address != '') {
        if (address.indexOf(':') < 0) {
            address = 'http:\/\/' + address;
        }
        getTags(address, null);
        ele.value = address;
    }
}

function loadXMLDocTags(url) {
    // Native
    if (window.XMLHttpRequest) {
        xmlhttptag = new XMLHttpRequest();
        xmlhttptag.onreadystatechange = processStateChangeTags;
        xmlhttptag.open("GET", url, true);
        xmlhttptag.send(null);
    // ActiveX
    } else if (window.ActiveXObject) {
        xmlhttptag = new ActiveXObject("Microsoft.XMLHTTP");
        if (xmlhttptag) {
            xmlhttptag.onreadystatechange = processStateChangeTags;
            xmlhttptag.open("GET", url, true);
            xmlhttptag.send();
        }
    }
}

function processStateChangeTags() {
    if (xmlhttptag.readyState == 4 && xmlhttptag.status == 200) {
        response = xmlhttptag.responseXML.documentElement;
        method = response.getElementsByTagName('method')[0].firstChild.data;
        result = response.getElementsByTagName('result')[0].firstChild.data;
        content = response.getElementsByTagName('content')[0].firstChild.data;
	eval(method + '(\'\', result+\'|||\'+content)');
    }
}

function selectAll(form) {
			for (var x = 0; x< form.elements.length; x++) {
				var y = form.elements[x];
				if (y.name != 'checkall_upper') {
					y.checked = form.checkall_upper.checked;
				}
			}
}

function checkAllTop(form) {
			for (var x = 0; x< form.elements.length; x++) {
				var y = form.elements[x];
				y.checked = form.checkall_top.checked;
			}
}

function checkAllBottom(form) {
			for (var x = 0; x< form.elements.length; x++) {
				var y = form.elements[x];
				y.checked = form.checkall_bottom.checked;
			}
}
		
function showTableMail(bId) {
	if (bId) { 
		if(document.getElementById('mailSubject')) {
			document.getElementById('mailSubject').value = "Toller Favorit bei alltagz";
		}
		if(document.getElementById('mailBody')) {
			document.getElementById('mailBody').innerHTML = "Schau Dir das mal an:<br><a href='"+document.getElementById(bId).href+"'>"+document.getElementById(bId).innerHTML+"</a>";
		}
	} else {
		if(document.getElementById('mailSubject')) {
			document.getElementById('mailSubject').value = "Gerade entdeckt: Favoriten sinnvoll nutzen!";
		}
		if(document.getElementById('mailBody')) {
			document.getElementById('mailBody').innerHTML = "Freunden schickt man schliesslich nur Gutes! Ein Klick der sich lohnt...schau doch dort mal vorbei!";
		}
	}


	document.getElementById('table-mail').style.visibility = "visible";
	document.getElementById('table-mail').style.left = window.innerWidth/4 + "px";
	document.getElementById('table-mail').style.top = window.innerHeight/4 + "px";
} 

function hideTableMail() {
	document.getElementById('table-mail').style.visibility = "hidden";
}

function showConfirmation() {
	document.getElementById('confirmation').style.visibility = "visible";
	document.getElementById('confirmation').style.left = window.innerWidth/4 + "px";
	document.getElementById('confirmation').style.top = window.innerHeight/4 + "px";
	window.setTimeout("closeConfirmation()", 4000);
}

function closeConfirmation() {
	document.getElementById('confirmation').style.visibility = "hidden";
}

function setActiveBorder(bId) {
	if (activeBorder) { activeBorder.style.background = "none"; }
	activeBorder = document.getElementById(bId);
	activeTagInput = document.getElementById(bId+'_tag');
	document.getElementById(bId).style.background = "#e3e3e3";
}


function popUp1(wintype)
{
  var nwl = (screen.width-800)/2;
  var nwh = (screen.height-500)/2;
  popUp=window.open(wintype, 'alltagz - Hilfetour', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=800,height=500,left='+nwl+',top='+nwh+''); 
  popUp.window.focus(); 
}

function popUp(URL) {
<!--
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=yes,width=800,height=530');");
-->
}
