/* File Created: May 15, 2014 */
// asynchronous refreshes of the urgent message indicator



var tidUrgent; // = setTimeout(asyncUserAgent, 2000);
var tiUrgentMsg;            // 70054890 Time Interval for Urgent Messages
function asyncUrgentMsg() {
	$.ajax({
		url: '/Home/UrgentMessageCount',
		type: 'POST',
		dataType: 'json',
		cache: false,
		success: ShowHideUrgentMsg
	});
    clearTimeout(tidUrgent);
    tidUrgent = setTimeout(function() { asyncUrgentMsg(); }, tiUrgentMsg);
}

// 70054890 Async function to be called only once (not setTimeOut)
function asyncUrgentMsgOnlyOnce() {
    $.ajax({
        url: '/Home/UrgentMessageCount',
        type: 'POST',
        dataType: 'json',
        success: ShowHideUrgentMsg
    });
}


// 70054890 Function called in _Laout.cshtml. Use this function instead of direct use of asyncUnreadMsg() because paramenter timeInterval is lost after setTimeout() is trigger
function setAsyncUrgentMsg(timeInterval) {
    if (timeInterval > 0) {
        tiUrgentMsg = (timeInterval * 60000) + 3000;                // 70054890 Set Time interval in Milliseconds from Minutes, AX-506 Add 3 seconds to avoid be the same as AutoLogout
        asyncUrgentMsg();                                           // 70054890 Call async Urgent message
    } else {
        asyncUrgentMsgOnlyOnce();                                   // 70054890 Just get UrgerntMessage once.
    }
}

function ShowHideUrgentMsg(result) {
	if (result == 0) {
		$("#urgentMsg").hide();
	} else {
		$("#urgentMsg").css("display", "inline");
	}

}
//$(document).ready(asyncUnreadMsg);        // 70054890 Set in _Layout.cshtml file
