 var oMsgs = {
 	'newMsg' : 'newMsgs',
 	'inboxRight' : 'inbox',
 	'newRight' : 'newMsgs',
 	'inboxMailbox' : 'inbox',
 	'allMailbox' : 'all',
 	'sentMailbox' : 'sent'
 };
 
 function fnUpdateTotals()
 {
 	
 	var sHost = window.location.host;
 	var sModule = window.location.search;
 	var newDesignSite = 0;
 	if ( typeof(newDesing) != "undefined")
 	{
 	    newDesignSite = 1;
 	}
 	if(window.location.protocol == 'https:') return;
 	
 	if(sModule && sModule.indexOf('mail') > -1 || sModule.indexOf('messages') > -1 || newDesignSite)
 	{
		go(_aSeq[0]);
 	}
 	else
 	{
		var oUpdater = new Net.Loader('/?a=ajax_msg_totals&type=new_inbox',
		{
			method: 'get',
			onSuccess: fnWrite,
			onFailure: fnRetry
		});
	}
 }

 function fnWrite(transport)
 {
 	//
 	var oResponse = transport.responseText;
 	eval(oResponse);
 	
 	if(totals.success == 1) fnRetry();
 	
 	for(each in oMsgs)
 	{
 		if($get(each))
 		{
 			var oPlaceholder = $get(each);
 			switch(each)
 			{
 				case 'newMsg':
 					oPlaceholder.innerHTML = totals[oMsgs[each]] ? '(' + totals[oMsgs[each]] + ') new' : '';
 					break;
 				case 'inboxRight':
 					oPlaceholder.innerHTML = (totals[oMsgs[each]] !== null && totals[oMsgs[each]] !== undefined) ? totals[oMsgs[each]] : '';
 					break;
 				case 'newRight':
 					oPlaceholder.innerHTML = (totals[oMsgs[each]] !== null && totals[oMsgs[each]] !== undefined) ? totals[oMsgs[each]] : '';
 					break;
 				default:
 					oPlaceholder.innerHTML = (totals[oMsgs[each]] !== null && totals[oMsgs[each]] !== undefined) ? '(' + totals[oMsgs[each]] + ')' : '';
 			}
 		}
 	}
 }
 
 function fnRetry()
 {
 	setTimeout('fnUpdateTotals', 1000);
 }
 
 if(window.onload && typeof(window.onload) == 'function')
 {
 	//
 	var fnStrangerListener = window.onload;
 	
 	window.onload = null;
 	
 	EventUtil.addDomLoadListener(fnStrangerListener);
 	EventUtil.addDomLoadListener(fnUpdateTotals);
 	EventUtil.registerOnLoad();
 }
 else
 {
 	EventUtil.addDomLoadListener(fnUpdateTotals);
 	EventUtil.registerOnLoad();
 }
 
 /***********************************************/
 var _aSeq = ['new_inbox', 'all', 'sent'];
 var _sHost = window.location.host;
 
 go = function(type)
 {
	new Net.Loader('/?a=ajax_msg_totals&type=' + type,
	{
		onSuccess: iterations[_aSeq.indexOf(type)]
	});
 };
	
 iterations = [
 function(transport)
 {
 	var oResponse = transport.responseText;
 	eval(oResponse);
 	
	if($get('newMsg')) $get('newMsg').innerHTML = totals['newMsgs'] ? '(' + totals['newMsgs'] + ') new' : '';
	if($get('newRight')) $get('newRight').innerHTML = totals['newMsgs'] !== undefined ? totals['newMsgs'] : '';
	if($get('inboxRight')) $get('inboxRight').innerHTML = totals['inbox'] !== undefined ? totals['inbox'] : '';
 	if($get('inboxMailbox')) $get('inboxMailbox').innerHTML = totals['inbox'] !== undefined ? '(' + totals['inbox'] + ')' : '';
 	
 	if($get('new_left')) $get('new_left').innerHTML = totals['inbox'] !== undefined ?  totals['inbox']  : '';
 	
 	totals = null;
 	setTimeout("go(_aSeq[1])", 300);
 },
 function(transport)
 {
 	var oResponse = transport.responseText;
 	eval(oResponse);
 	
	if($get('allMailbox')) $get('allMailbox').innerHTML = (totals['all'] !== undefined) ? '(' + totals['all'] + ')' : '';
	if($get('all_left')) $get('all_left').innerHTML = (totals['all'] !== undefined) ? totals['all']  : '';

 	totals = null;
 	setTimeout("go(_aSeq[2])", 300);
 },
 function(transport)
 {
 	var oResponse = transport.responseText;
 	eval(oResponse);
 	
	if($get('sentMailbox')) $get('sentMailbox').innerHTML = totals['sent'] !== undefined ? '(' + totals['sent'] + ')' : '';
	if($get('sent_left')) $get('sent_left').innerHTML = totals['sent'] !== undefined ? totals['sent']  : '';
 	totals = null;
 }];