/* Absurdcoding.org Inventions
 * 
 * Project:		ACTSViewer
 * Author:		Steven Barth
 * Sponsor: 	Germeshausen.de Webhosting - www.germeshausen.de
 * E-Mail: 		actsviewer@absurdcoding.org
 * Homepage:	actsviewer.absurdcoding.org
 * License:		GNU General Public License
 *
 *  ACTSViewer - A multifunctional TeamSpeak-Viewer written in PHP
 *  Copyright (C) 2006 Steven Barth
 *
 *  This program is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 2 of the License,
 *  or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty
 *  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the
 *  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 *  Boston, MA 02110, USA
 * 
 */
//Code
var collall = false;
var intval = false;

function ts_show(layer, img, name, key1, val1, key2, val2, key3, val3, key4, val4, key5, val5) {
	ly = document.getElementById(layer);
	ly.style.display = "block";
	ly.style.backgroundColor = lyBackgroundColor;
	ly.style.color = lyColor;
	ly.style.zIndex = "100";
	ly.style.border = lyBorder;
	ly.style.position = "absolute";
	ly.style.fontSize = lyFontSize;
	ly.innerHTML = '<table style="text-align: left; font-size: '+lyFontSize+'; color: '+lyColor+'" class="ts_info">'+ts_info(img, name, key1, val1, key2, val2, key3, val3, key4, val4, key5, val5)+'</table>';
}

function ts_hide(layer) {
	document.getElementById(layer).style.display = "none";
}

function ts_collapse(id) {
	objid = "collapse_" + id;
	imgid = "colimg_" + id;
	if (document.getElementById(objid).style.display == "none") {
		document.getElementById(objid).style.display = "block";
		document.getElementById(imgid).src = document.getElementById(imgid).src.replace(/tree_(.*?)_plus/, 'tree_$1_minus');
	} else {
		document.getElementById(objid).style.display = "none";
		document.getElementById(imgid).src = document.getElementById(imgid).src.replace(/tree_(.*?)_minus/, 'tree_$1_plus'); 
	}
}

function ts_collapseall() {
	objs = document.getElementsByTagName("div");
	for (i=0; i < objs.length; i++) {
		if (objs[i].id && objs[i].id.substr(0, 9) == "collapse_") {
			objid = objs[i].id;
			imgid = "colimg_" + objid.substring(9);
			if (document.getElementById(objid) && document.getElementById(imgid)) {
				if (collall) {
					document.getElementById(objid).style.display = "block";
					document.getElementById(imgid).src = document.getElementById(imgid).src.replace(/tree_(.*?)_plus/, 'tree_$1_minus');
				} else {
					document.getElementById(objid).style.display = "none";
					document.getElementById(imgid).src = document.getElementById(imgid).src.replace(/tree_(.*?)_minus/, 'tree_$1_plus');
				}
			}
		} 
	}
	collall = !collall;
}

function ts_update() {
	location.reload();
}

function ts_autoupdate(obj) {
	if (!intval) {
		intval = setInterval("ts_update()", tsUpdateInterval);
		obj.firstChild.nodeValue = "[ Disable Autorefresh ]";
	} else {
		clearInterval(intval);
		obj.firstChild.nodeValue = "[ Enable Autorefresh ]";
		intval = false;
	}
}

function ts_join(server, channel, srvpwd, chanpwd) {
	var uri = "teamspeak://" + server + "/?channel=" + channel;
	if (nickname = prompt("Please enter a nickname:")) {
		uri += "?nickname="+nickname;
		if (loginname = prompt("Please enter your loginname or press cancel if you do not want to login:")) {
			uri += "?loginname="+loginname;
		}
		if ((loginname || srvpwd) && (password = prompt("Please enter your account password or the password of the server if you do not have an account:"))) {
			uri += "?password="+password;
		}
		if (chanpwd && (chanpwd = prompt("The channel you are about to join may require a password. Please enter the channel password or press cancel if you do not need it:"))) {
			uri += "?channelpassword="+chanpwd;
		}
		location = uri;
	}
}

function ts_info(img, name, key1, val1, key2, val2, key3, val3, key4, val4, key5, val5) {
	xhtml  = '<tr><td colspan="2"><b><img src="'+tpluri+img+'" alt="Icon" /> '+name+'</b></td></tr>';
	xhtml += '<tr><td><b>'+key1+'</b></td><td>'+val1+'</td></tr><tr><td><b>'+key2+'</b></td><td>'+val2+'</td></tr><tr><td><b>'+key3+'</b></td><td>'+val3+'</td></tr>';
	xhtml += '<tr><td><b>'+key4+'</b></td><td>'+val4+'</td></tr><tr><td><b>'+key5+'</b></td><td>'+val5+'</td></tr>';
	return xhtml;
}

function async_update(layer, uri) {
	async_layer = layer;	
	async_loaduri(uri);
}

function async_loaduri(uri) {
	try {
		xmlobj = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (e) {
		
	}
	xmlobj.onreadystatechange = async_load_trigger;
	xmlobj.open("GET", uri); 
	xmlobj.send(null);
}

function async_update_layer(content) {
	document.getElementById(async_layer).innerHTML = content;
}

function async_load_trigger() {
	if ((xmlobj.readyState == 4) && (xmlobj.status == 200)) {
		 async_update_layer(xmlobj.responseText);
	}
}