// This function will be called every time the server pushes a new event.
function push(event) {
	// For this example, we simply show the excuse on the page.
	document.getElementById('excuse').innerHTML = event;
}

// This function will be called when/if the stream closes.
function disconnected() {
	// For this example we'll just show a nice message.
	document.getElementById('excuse').innerHTML = '<img src="img/arrow.png" alt="" title="" />'+
		' Click to see MORE reasons why this souldn\'t work!';
	document.getElementById('control').value = 'start';
}

// This function is executed when the button is clicked.
function toggle() {
	// First we check if the stream is open.
	if (!comet.active) {
		// Lets start streaming!
		comet.open('excuses.php', push, disconnected);
		document.getElementById('control').value = 'stop';
	} else {
		// Streaming is active, means the user wants to stop it.
		comet.close();
	}
}
