﻿var MsgDiv = "<div id='InfoMsg' class='MsgBox'><table style='width:98%;' cellpadding='0' cellspacing='0'><tr><td id='InfoMsgIcon' align='center' width='100px'>&nbsp;</td><td id='InfoMsgText'>&nbsp;</td><td align='right' height='48px' width='100px'><a href='javascript:void(0)' onclick='closeMsgWindow()'><img alt='' style='border-width:0px;' src='../App_Images/closebtn.png' /></a></td></tr></table></div>";
var timer;

function displayMessage(MsgTitle, MsgText, DisCloseBtn, AutoHide) {
    document.getElementById("InfoMsgContainer").innerHTML = MsgDiv;
    document.getElementById("InfoMsgIcon").innerHTML = "<img src='../App_Images/" + getImageIcon(MsgTitle) + "'/>";
    var Msg = "<span class='MsgTitle'>" + MsgTitle + ": </span><span>" + MsgText + "&nbsp;</span>";
    document.getElementById("InfoMsgText").innerHTML = Msg;

    topFixed();
    
    if (AutoHide) {
        timer = setTimeout(closeMsgWindow, 8000);
    }
}

function getImageIcon(MsgTitle) {
    switch (MsgTitle) {
        case 'Confirmation':
            return "info.png";
        case 'Alert':
            return "alert.png";
        case 'Error':
            return "error.png";
        case 'Processing':
            return "Loader.gif";
    }
}

function closeMsgWindow() {
    document.getElementById("InfoMsgContainer").innerHTML = "";
    clearTimeout(timer);
}

function topFixed() {
    var ele = document.getElementById("InfoMsg");
    var dist = 0;

    ele.style.top = dist + 'px';
    var ieMatch = navigator.appVersion.match(/MSIE (\d+)\./);
    if (!ieMatch || +ieMatch[1] >= 7) {
        ele.style.position = 'fixed';
    }
    else {
        ele.style.position = 'absolute';
        setInterval(function (ele) {
            ele.style.display = 'none'; // turn visibility off...
            ele.style.top = dist + 'px'; // change the offset...
            ele.style.display = 'block';
        }, 10, ele);
    }
}


