function bulkdelete(messageDiv){
	if(confirm('Are you sure you want to delete all the checked messages?')){
		var postVal = "idlist=";
		field = document.msgform.list
		if(field.length==undefined){
		//only 1 checked
			postVal += field.value;
		}else{
			for (i = 0; i < field.length; i++){
				if(field[i].checked){
					postVal += field[i].value + ",";
				}
			}
		}
		postVal += "&bulkdelete=true";
		
		
		
	new Ajax.Updater(messageDiv,'blank.php?module=message&action=deleteMany', {
	 	evalScripts: true,
	 	method:'post',
		parameters:postVal,	
	  	onComplete: function(){doPollInbox()}
	});
		/*
		
		makePOSTRequest('blank.php?module=message&action=deleteMany',postVal);
	  	http_request.onreadystatechange = function() {//Call a function when the state changes.
			if(http_request.readyState == 4 && http_request.status == 200) {
				document.getElementById(messageDiv).innerHTML = http_request.;
				doPollInbox();
			}
		}*/
	}
}

function bulkdeletesent(){
	if(confirm('Are you sure you want to delete all the checked messages?')){
		var postVal = "idlist=";
		field = document.msgform.list
		if(field.length==undefined){
		//only 1 checked
			postVal += field.value;
		}else{
			for (i = 0; i < field.length; i++){
				if(field[i].checked){
					postVal += field[i].value + ",";
				}
			}
		}
		postVal += "&bulkdelete=true";
		new Ajax.Updater(messageDiv,'blank.php?module=message&action=deleteSent', {
	 		evalScripts: true,
	 		method:'post',
			parameters:postVal,	
	  		onComplete: function(){doPollInbox()}
		});
		/*makePOSTRequest('blank.php?module=message&action=deleteSent',postVal);
	  	http_request.onreadystatechange = function() {//Call a function when the state changes.
			if(http_request.readyState == 4 && http_request.status == 200) {
				document.getElementById(messageDiv).innerHTML = http_request.responseText;
				doPollInbox();
			}
		}*/
	}
}

function bulkread(messageDiv){
	
	var postVal = "idlist=";
	field = document.msgform.list;
	if(field.length==undefined){
	//only 1 checked
		postVal += field.value;
	}else{
		for (i = 0; i < field.length; i++){
			if(field[i].checked){
				postVal += field[i].value + ",";
			}
		}
	}
	
	postVal += "&bulk=true";
	new Ajax.Updater(messageDiv,'blank.php?module=message&action=markread', {
		evalScripts: true,
		method:'post',
		parameters:postVal,	
		onComplete: function(){doPollInbox()}
	})
	/*makePOSTRequest('blank.php?module=message&action=markread',postVal);
  	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			document.getElementById(messageDiv).innerHTML = http_request.responseText;
			doPollInbox();
		}
	}*/
}

function bulkunread(messageDiv){

		var postVal = "idlist=";
		field = document.msgform.list
		if(field.length==undefined){
		//only 1 checked
			postVal += field.value;
		}else{
			for (i = 0; i < field.length; i++){
				if(field[i].checked){
					postVal += field[i].value + ",";
				}
			}
		}
		postVal += "&bulk=true";
		new Ajax.Updater(messageDiv,'blank.php?module=message&action=markunread', {
	 		evalScripts: true,
	 		method:'post',
			parameters:postVal,	
	  		onComplete: function(){doPollInbox()}	  
		})
		
		/*
		makePOSTRequest('blank.php?module=message&action=markunread',postVal);
	  	http_request.onreadystatechange = function() {//Call a function when the state changes.
			if(http_request.readyState == 4 && http_request.status == 200) {
				document.getElementById(messageDiv).innerHTML = http_request.responseText;
				doPollInbox();
			}
	}*/
}


function doPollInbox() {
	new Ajax.Request("/blank.php?do=message_displayCount", {
	method:'post',
	evalScripts: true,
	onComplete: function(transport){
			try{
				$('msgcnt1').update(transport.responseText);
			}catch (e){}
			try{
				$('msgcnt2').update(transport.responseText);	
			}catch(e){}
		}
	})
}