var smInitNewFriendOnline = false; //this is because soundmanager initilizes slowly

function callbackFriendlist(aFriends) {
	if (aFriends.length == 0) {
		msgNoFriends();
	} else {
		arFriends = new Array(aFriends.length);
		for(i = 0; i < aFriends.length; i++)	{
			arFriends[i] = new Array(5);
			arFriends[i]["id"] = aFriends[i].childNodes[0].firstChild.data; //id
			arFriends[i]["un"] = aFriends[i].childNodes[1].firstChild.nodeValue //un
			arFriends[i]["st"] = aFriends[i].childNodes[2].firstChild.data //st
			arFriends[i]["al"] = aFriends[i].childNodes[3].firstChild.data //al
			arFriends[i]["ge"] = aFriends[i].childNodes[4].firstChild.data //ge
		}
		buildFriendList(arFriends);
	}
}

function msgNoFriends() {
	msg = "Sekarang ini tidak ada anggota di daftar teman anda. Untuk menambahkan anggota-anggota ke daftar teman anda, jelajahi profil mereka dan klik pada 'Tambahkan ke daftar teman'.";
	FriendList = document.getElementById('friendList');
	removeChildren(FriendList);
	oFriendDiv = document.createElement("DIV");
	oFriendDiv.className = "message";
	oFriendDiv.appendChild(document.createTextNode(msg));
	FriendList.appendChild(oFriendDiv);
}

function buildFriendList(aFriends) {
	FriendList = document.getElementById('friendList');
	removeChildren(FriendList);	
	friendAlert = false;
	//var oFriendLink = new Array();
	for(i = 0; i < aFriends.length; i++)	{
		oFriendDiv = document.createElement("DIV");
		oFriendDiv.className = "friendContainer";
		oFriendLink = document.createElement("A");
		oFriendLink.className = aFriends[i]["st"] + aFriends[i]["ge"] + "Friend"; //st, ge
		oFriendLink.href = "profile.php?profielID="+aFriends[i]["id"];
		oFriendLink.title = "Perlihatkan profil "+aFriends[i]["un"];
		oFriendLink.id = "ofl"+aFriends[i]["id"];
		oFriendLink.appendChild(document.createTextNode(aFriends[i]["un"])); //un
		oFriendDiv.appendChild(oFriendLink);
		//doBlink(aFriends[i]["id"]);
		if (aFriends[i]["al"] == "t") {
			friendAlert = true;
			doBlink(aFriends[i]["id"]);
		}
		if (aFriends[i]["st"] == "t" && cpm != "f") {
			oFriendChatLink = document.createElement("A");
			oFriendChatLink.className = "friendChat";
			oFriendChatLink.title = "Chat sekarang dengan "+aFriends[i]["un"] + " menggunakan JK Messenger";
			oFriendChatLink.href = "javascript:newIMsession("+aFriends[i]["id"]+");";
			oFriendDiv.appendChild(oFriendChatLink);
		}
		FriendList.appendChild(oFriendDiv);
	}
	if (friendAlert == true && sound_friendonline == "t") {
		soundManager.play('online');
		smInitNewFriendOnline = true;
	}
}

function doBlink(i) {
	var secs2blink = 5;
	for(bi = 0; bi < secs2blink; bi++)	{
		setTimeout("document.getElementById('ofl"+i+"').style.fontWeight = 'bold'", ((bi*1000)+500));
		setTimeout("document.getElementById('ofl"+i+"').style.fontWeight = 'normal'", ((bi*1000)+1000));
	}
}

function handle_error() {

}

function server_slow() {

}

function server_ok() {
	
}

function IMsystemMsg(msg1, msg2, msg3) {

}