var ignore = false;
jQuery(document).ready(function() {
	// Check for unanswered chats every five seconds
	if (location.href.indexOf('/chat.asp') == -1) {
		setInterval(CheckForChat, 5000);
		CheckForChat();
	}
});
function CheckForChat() {
	jQuery.get('/chatfunctions.asp?action=unanswered&r=' + Math.random(), function(xml) {
		// If there are no chats anymore, close any open prompts
		if (jQuery(xml).find('Chat').length == 0) {
			if (jQuery('#jqibox').length > 0)
				jQuery.prompt.close();
		} else {
			// If there isn't already a prompt open, open one
			if (jQuery('#jqibox').length == 0 && !ignore)
				jQuery.prompt('<p>There is an unanswered chat session.</p><p>Answer the session?</p>', { buttons: { Yes: true, No: false }, focus: 1, submit: AnswerChat } );
		}
	});
}
function AnswerChat(v, m, f) {
	if (v) {
		location.href = '/chat.asp';
	} else
		ignore = true;
}
