function xhr(method, url, querystring, callback, parameters) {
	var handler = null;
	method = method.toUpperCase();

	try {
		if (window.XMLHttpRequest) {
			// firefox and so on
			handler = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			// iexplore
			handler = new ActiveXObject("Microsoft.XMLHTTP");
		}

		switch (method) {
			case "GET":
				handler.open("GET", url+querystring, true);
				break;
			case "POST":
				handler.open("POST", url, true);
				handler.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				break;
		}

		handler.onreadystatechange = function() {
			switch (handler.readyState) {
				case 1:
				case 2:
				case 3:
					break;
				case 4:
					callback(handler, parameters);
					break;
			}
		}

		handler.send(querystring);
		return true;
	} catch (e) {
		return false;
	}
}

function bbCheck(input, output) {
	xhr(
		'POST'
		, '/Admin/XHR/bb.php'
		, 'code=' + escape(document.getElementById(input).value)
		, simpleCallback
		, output
	);
}
function treeview(user, output, id, anchor) {
	icon = anchor.getElementsByTagName('img')[0]
	if (document.getElementById(output).style.display != 'block') {
		document.getElementById(output).style.display = 'block';
		icon.src = '/Images/Icons/loading.gif'
		args = new Array()
		args.push(icon)
		args.push(output)
		xhr(
			'GET'
			, '/XHR/tree.php'
			, '?user=' + user + '&id=' + id
			, treeCallback
			, args
		);
	} else {
		document.getElementById(output).style.display = 'none';
	}
	
}
function simpleCallback(handler, element) {
	document.getElementById(element).innerHTML = handler.responseText;
}
function treeCallback(handler, args) {
	args[0].src = '/Images/Icons/tree.png';
	document.getElementById(args[1]).innerHTML = handler.responseText;
}
function tree_action(element, id, owner) {
	element.getElementsByTagName('img')[0].src = '/Images/Icons/loading.gif';
	class = element.getAttribute('class').split(' ')[1]
	switch (class) {
		case 'ta_collapse':
			document.getElementById('n_' + id).removeChild(document.getElementById('n_' + id).getElementsByTagName('ul')[0])
			element.getElementsByTagName('img')[0].src = '/Images/Icons/plus.png';
			element.setAttribute('class', "tree_action ta_expand")
			delete(target)
		break;
		case 'ta_expand':
			target = document.getElementById('n_' + id)
			tree_expand(id, target, owner, element)
			element.setAttribute('class', "tree_action ta_collapse")
		break;
	}
	
}
function tree_expand(id, target, owner, element) {
	xhr('GET'
		, '/XHR/tree_expand.php'
		, '?user='+owner+'&id=' + id
		, tree_expand_cb
		, target)
	element.src = '/Images/Icons/minus.png';
}
function tree_expand_cb(handler, target) {
	target.innerHTML = handler.responseText
}
function tree_pre_show_cb(handler, target) {
	target.innerHTML += handler.responseText
}
function tree_pre_show(id, target, owner) {
}
function tree_pre(id, target, owner) {
	try {
		id
	} catch (e) {
		alert('foo')
	}
}
function tree_pre_hide(output, id, element) {
	try {
		document.getElementById('pre_'+id).style.display = 'none'
	} catch (e) {
	}
}


//intersicom get stuff
function intersicom_get_xhr(output) {
	xhr('POST'
		, '/XHR/Intersicom/get.php'
		, ''
		, intersicom_get_xhr_callback
		, output)
}
function intersicom_get_xhr_callback(handler, output) {
	document.getElementById(output).innerHTML = handler.responseText + document.getElementById(output).innerHTML
}



// intersicom send stuff
function intersicom_keyDown(e, input, output_str) {
	if(window.event) { // IE
		keynum = e.keyCode
	}
	else if(e.which) { // Netscape/Firefox/Opera
		keynum = e.which
	}
	if (keynum == 13) {
		intersicom_send_xhr(input, output_str);
		input.value = ''
	}
}
function intersicom_send_xhr(input, output_str) {
	value = input.value
	xhr('POST'
		, '/XHR/Intersicom/send.php'
		, 'text=' + value
		, intersicom_send_xhr_callback
		, output_str)
}
function intersicom_send_xhr_callback(handler, output_str) {
	output = document.getElementById(output_str)
	output.innerHTML = output.innerHTML + handler.responseText
}
