
function appendComment(bid, url, name, comment){
		var ret = "";
		
		ret += "<div class=\"comment\" name=\"" + name +  "\" style=\"border:1px solid #009900; background-color:#EEFFEE; color:#006600;\">\n";
		ret += "<h4><img src=\"/bilder/plus.gif\" /><div style=\"float:left;\">Dein Kommentar :</div><div style=\"clear:right; text-align:right;\"><a href=\"#" + name + "\">Heute</a></div></h4>\n";
		ret += "<p>\n";
		ret += comment;
		ret += "\n</p></div>\n";

	$("#comments").before(ret);
}

function submitComment(bid){
	$.post("/new_comment.php", {
		bid			: bid,
		url			: $('#url').attr("value"),
		name		: $('#name').attr("value"),
		comment	: $('#message').attr("value")
	},
	  function(data){
			$('#TB_ajaxContent').html(data);
	  });
}

function windowSize(val) {
  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;
  }
	if(val == 'height'){
		return myHeight;
	}
	else{
		return myWidth;
	}
}

function getHeight(){
	// 	var height = Math.floor((screen.availHeight / 100) * 70);
	height = (windowSize('height') / 100) * 80;
	return height;
}

function getWidth(){
	// 	var width = Math.floor((screen.availWidth / 100) * 90);
	width = (windowSize('width') / 100) * 80;
	return width;
}

function spamReport(title, description, address){
	$.get("/spam-melden.php", { title:title, description:description, address:address, update:'true' },
  function(data){
		alert(data);
  });
}

function linkMelden(category, message, bId){
	$.get("/link-melden.php", { bId:bId, category:category, message:message, job:'send' },
  function(data){
		tb_remove();
		alert(data);
  });
}

// var imgOver = new Image();
// imgOver.src = '/reviewstar.gif';
// var imgOut = new Image();
// imgOut.src = '/reviewemptystar.gif';
function voteFX(state, id){
	var i			= 1;
	var val			= id.substr(-1, 1);
	var bId			= id.substr(3, (id.length - 4)); 
	var imgOver		= '/reviewstar.gif';
	var imgOut		= '/reviewemptystar.gif';
	var imgActive	= '/reviewstar_active.gif';
	
	if(state == 'over'){
		for(i=1; i<=val; i++){
			document.getElementById('img' + String(bId) + String(i)).src = imgActive;
			switch(val){
				case '1':
					document.getElementById('vote' + String(bId)).innerHTML = 'sehr schlecht';
					break;
				case '2':
					document.getElementById('vote' + String(bId)).innerHTML = 'schlecht';
					break;
				case '3':
					document.getElementById('vote' + String(bId)).innerHTML = 'mittelmäßig';
					break;
				case '4':
					document.getElementById('vote' + String(bId)).innerHTML = 'gut';
					break;
				case '5':
					document.getElementById('vote' + String(bId)).innerHTML = 'sehr gut';
					break;
			}
		}
	}
	else{
		var initRating = document.getElementById('init' + String(bId)).value;
		for(var i=1; i<=val; i++){
			// ursprünglichen wert wieder anzeigen
 			if(i <= initRating){
 				document.getElementById('img' + String(bId) + String(i)).src = imgOver;
 			}
 			else{
 				document.getElementById('img' + String(bId) + String(i)).src = imgOut;
 			}
		}
		document.getElementById('vote' + String(bId)).innerHTML = 'Link bewerten &rarr; ';
	}
}

function idle(){
// 	nothing
}

function vote(id, val){
	var i = 1;
	for(i=1; i<=5; i++){
		document.getElementById('img' + String(id) + String(i)).style.cursor = 'default';
		document.getElementById('img' + String(id) + String(i)).onmouseover = new Function("idle()");
		document.getElementById('img' + String(id) + String(i)).onmouseout = new Function("idle()");
		document.getElementById('img' + String(id) + String(i)).onclick = new Function("idle()");
	}
	// Vote the Link
	$.get("/vote.php", { bId: id, val: val },
  function(data){
    document.getElementById('vote' + String(id)).innerHTML = data;
  });
}

function _playerAdd(anchor) {
    var url = anchor.href;
    var code = '<object type="application/x-shockwave-flash" data="http://bookmark-one.com/includes/player/musicplayer_f6.swf?song_url=' + url +'&amp;b_bgcolor=ffffff&amp;b_fgcolor=000000&amp;b_colors=0000ff,0000ff,ff0000,ff0000&buttons=http://bookmark-one.com/includes/player/load.swf,http://bookmark-one.com/includes/player/play.swf,http://bookmark-one.com/includes/player/stop.swf,http://bookmark-one.com/includes/player/error.swf" width="14" height="14">';
    var code = code + '<param name="movie" value="http://bookmark-one.com/includes/player/musicplayer.swf?song_url=' + url +'&amp;b_bgcolor=ffffff&amp;b_fgcolor=000000&amp;b_colors=0000ff,0000ff,ff0000,ff0000&amp;buttons=http://bookmark-one.com/includes/player/load.swf,http://bookmark-one.com/includes/player/play.swf,http://bookmark-one.com/includes/player/stop.swf,http://bookmark-one.com/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>Bist Du 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 {
		    document.getElementById("pic" + input + "_1").parentNode.style.display = 'none';
		    document.getElementById("pic" + input + "_1").style.display = 'none';
		    document.getElementById("pic" + input + "_2").style.display = 'none';
		    
// 		    $("pic" + input + "_1").fadeOut("slow");
// 		    $("pic" + input + "_2").fadeOut("slow");
// 		    $("pic" + input + "_1:parent").fadeOut("slow");
		    
				var newval = document.getElementById('linkcount').innerHTML - 1;
				document.getElementById('linkcount').innerHTML = newval;
        loadXMLDoc('http://bookmark-one.com/ajaxDelete.php?id=' + input);
    }
}

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(http://bookmark-one.com/loading.gif)';
        if (response != '') {
            usernameField.style.backgroundImage = 'none';
            if (response == 'true') {
                availability.className = 'available';
                availability.innerHTML = 'Nicht Vorhanden ';
            } else {
                availability.className = 'not-available';
                availability.innerHTML = 'Vorhanden';
            }
        } else {
            loadXMLDoc('http://bookmark-one.com/ajaxIsAvailable.php?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(http://bookmark-one.com/loading.gif)';
        if (response != null) {
            title.style.backgroundImage = 'none';
            title.value = response;
        } else if (input.indexOf('http') > -1) {
            loadXMLDoc('http://bookmark-one.com/ajaxGetTitle.php?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]);
        }
    }
}

$(document).ready(function(){
//	$('#abg').attr('style', 'color:#999;');
});

$(window).unload(function(){
// 	GUnload();
});
