var req;
function newRequest()
{
	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 OpenChat()
{
    window.open('http://www.tropicalhealthfoods.com/supportchat/chat.htm','Help','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,width=500,height=500');
    return;
}
function checkandshow()
{
	setTimeout('checkandshow()', 60000);
	newRequest();
	req.onreadystatechange = pollStateChange;
	req.open("POST", "/supportchat/server.php", true);
	req.setRequestHeader('Content-Type', 
		'application/x-www-form-urlencoded');
	req.send("");
}
function pollStateChange()
{
	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;
					if (is_ad) {
							document.getElementById("citext").innerHTML = "&nbsp;&nbsp;&nbsp;We are <font color=\"#0000ff\"><strong>ONLINE</strong></font> to answer questions (no waiting).&nbsp; <strong><a href=\"javascript:OpenChat();\">Start Live Support Chat</a></strong>";
					}
					else {
						document.getElementById("citext").innerHTML = "&nbsp;&nbsp;&nbsp;Live Support is <font color=\"#0000ff\"><strong>OFFLINE </strong>.</font> (Best time to find Lloyd available is 5:00+ PM CST)";
					}
					return;
				} else {
					alert(req.responseText);
				}
			}
		} catch (e) { }
		req = null;
	}
}
