// If server.php is not in the same folder with this page,
// make sure you fix this URL! For instance: /supportmelive/server.php

var server = "http://www.spokesbmx.at/chat/server.php";

var req;

function chatEntryNewRequest()
{
	req = false;
	// For Safari, Firefox, and other non-MS browsers
	if (window.XMLHttpRequest) {
		try {
			req = new XMLHttpRequest();
		} catch (e) {
			req = false;
		} 
	} else if (window.ActiveXObject) {
		// For Internet Explorer on Windows
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				req = false;
			}
		}
	}
}

function chatEntryOpenChat()
{
    window.open('http://www.spokesbmx.at/chat/index.html','Spokes Live Support','toolbar=no,status=no,scrollbars=no,location=no,menubar=no,directories=no,width=500,height=500');
    return;
}

function chatEntryCheckAndShow()
{
	setTimeout('chatEntryCheckAndShow()', 60000);
	chatEntryNewRequest();
	req.onreadystatechange = chatEntryPollStateChange;
	req.open("POST", server, true);
	req.setRequestHeader('Content-Type', 
		'application/x-www-form-urlencoded');
	req.send("");
}

function chatEntryPollStateChange()
{
	if (req.readyState == 4) {
		try {
			if (req.status == 200) {
				var xml = req.responseXML;
				if (xml) {
					var is_ad = xml.getElementsByTagName("ad")[0].attributes.getNamedItem("isad").value;
					var el = document.getElementById('chatinvite');
					if (is_ad) {
							document.getElementById("chatinvite").innerHTML = "<a href=\"javascript:chatEntryOpenChat();\"><img src=\"../images/p_chat-on.gif\" border=\"0\" class=\"commercials\"/></a>";
					}
					else {
							document.getElementById("chatinvite").innerHTML = "<a href=\"javascript:chatEntryOpenChat();\"><img src=\"../images/p_chat-off.gif\" border=\"0\" class=\"commercials\"/></a>";
					}
					return;
				} else {
					alert(req.responseText);
				}
			}
		} catch (e) { }
		req = null;
	}
}
