// checkmail.js
// Checks server for new mail every 30 seconds

var _mailTimer = null;

function pollMailServer(skip_timer) {
	
	var post_data = "a=checkmail";
	
	$.ajax({
			type: "POST",
			url: "/assets/ajax/checkmail.php",
			async: true,
			data: post_data,
			success: function(xml){
				
				//alert("OK so far");
				NotificationListener(xml);
				
				var new_messages = $(xml).find('new_messages').text();
				
				//alert(new_messages);
				
				//$(".newMsgNotification").html("("+new_messages+" new)");
				if (Number(new_messages) > 0) {
					// update mail notification div here via jQuery with # of new messages
					$(".newMsgNotification").html("("+new_messages+" new)");
				}
				else {
					$(".newMsgNotification").html("");
				}
			}
			
	});
	
	if (skip_timer === undefined) { _mailTimer = setTimeout("pollMailServer()", 30000); }
}

$(document).ready(function() { 
	pollMailServer();
});
