function sendRequest(url,callback,postData) {
	var req = createXMLHTTPObject();
	if (!req) return;
	var method = (postData) ? "POST" : "GET";
	req.open(method,url,true);
	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (postData)
		req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	req.onreadystatechange = function () {
		if (req.readyState != 4) return;
		if (req.status != 200 && req.status != 304) {
//			alert('HTTP error ' + req.status);
			return;
		}
		callback(req);
	}
	if (req.readyState == 4) return;
	req.send(postData);
}

var XMLHttpFactories = [
	function () {return new XMLHttpRequest()},
	function () {return new ActiveXObject("Msxml2.XMLHTTP")},
	function () {return new ActiveXObject("Msxml3.XMLHTTP")},
	function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];

function createXMLHTTPObject() {
	var xmlhttp = false;
	for (var i=0;i<XMLHttpFactories.length;i++) {
		try {
			xmlhttp = XMLHttpFactories[i]();
		}
		catch (e) {
			continue;
		}
		break;
	}
	return xmlhttp;
}

var liveChatStatusButtonBaseUrl = '';
var liveChatStatusButtonCounter = 0;

function initLiveChatStatusButton(baseUrl, link)
{
	if (typeof baseUrl != 'undefined') 
	{
		liveChatStatusButtonBaseUrl = baseUrl;
	}
	if (typeof link == 'undefined') link = true;
	document.write('<span id="livechat-statusbutton">');
	document.write('<map name="livechat-button-map">');
	document.write('<area href="javascript:startLiveChat()"" title="Start Live Chat" shape="rect" coords="3,2,153,38" />');
	//document.write('<area href="http://www.adobe.com/go/getflashplayer" target="_blank" title="Get Flashplayer" shape="rect" coords="9,48,91,60" />');
	//document.write('<area href="javascript:showLiveChatHelp()" title="Gebruiksaanwijzing" shape="rect" coords="9,72,103,85" />');
	document.write('</map>');
	document.write('<img id="livechat-statusbutton-img" src="'+baseUrl+'statusbutton.php" alt="status" width="155" height="45" border="0" usemap="#livechat-button-map"/>');
	//document.write('<a href="http://www.adobe.com/go/getflashplayer" title="Get Flashplayer" style="left: 9px; top: 48px; width: 82px; height: 22px; position:absolute;" target="_blank"><span style="display:none">Get Flashplayer</span></a>');
	//document.write('<a href="javascript:showLiveChatHelp()" title="Gebruiksaanwijzing" style="left: 9px; top: 72px; width: 94px; height: 13px; position:absolute;" ><span style="display:none">Show Live Chat Help</span></a>');
	document.write('</span>');
	updateLiveChatStatusButton();
}

function startLiveChat()
{
	window.open(liveChatStatusButtonBaseUrl + 'index.php', 'LiveChat', 'width=900,height=500,resizable=yes');
}
function showLiveChatHelp()
{
	window.open(liveChatStatusButtonBaseUrl + 'help.php', 'LiveChatHelp', 'width=550,height=500,resizable=yes,scrollbars=yes');
}

function handleRequest(req)
{
	var img = document.getElementById('livechat-statusbutton-img');
	img.src = liveChatStatusButtonBaseUrl + 'images/button_'+req.responseText+'.png';
	img.alt = 'Chat: ' + req.responseText;
	window.setTimeout('updateLiveChatStatusButton()', 3000);
}

function updateLiveChatStatusButton()
{
	//sendRequest(liveChatStatusButtonBaseUrl+'status.php', handleRequest);
	liveChatStatusButtonCounter++;
	var img = document.getElementById('livechat-statusbutton-img');
	img.src = liveChatStatusButtonBaseUrl + 'statusbutton.php?seq='+liveChatStatusButtonCounter;
	
	window.setTimeout('updateLiveChatStatusButton()', 3000);
}
