function checkMaxLen(txt,maxLen)
{
    try
    {
        if(txt.value.length > (maxLen-1))
        {
            var cont = txt.value;
            txt.value = cont.substring(0,(maxLen -1));
            return false;
        }
    }
    catch(e)
    {
    }
}

function newWindow(a) {
    a.target = "_blank";
}

function popup(url, name, w, h) {
    var details = "toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,status=no,width=" + w + ",height= " + h + " ";
    window.open(url, name, details);
}

function HideContent(d) {
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
    if (d.length < 1) { return; }
    var dd = document.getElementById(d);
    dd.style.display = "inline";
}
function ReverseContentDisplay(d) {
    if (d.length < 1) { return; }
    var dd = document.getElementById(d);
    if (dd.style.display == "none") { dd.style.display = "inline"; }
    else { dd.style.display = "none"; }
}
var CheckForChangesFunction = new function() {
    // Internal reference to the class to avoid the "this" pointer issue
    // when dealing with events.
    var _this = this;

    //you can declare this if you want, but I don't see the point.
    //this.globalChange = undefined;

    // Determines whether or not a form is being saved.
    this.saving;

    // Message to display.
    this.navigateAwayMessage = "You have made some changes which will be lost if you leave this page. Do you want to leave this page?";

    // Verify if any changes were made. If there have been changes and the form is not being saved,
    // alert the user that they are about to leave a page where they have made edits.
    this.checkForChanges = function() {
        if (!_this.saving && typeof (_this.globalChange) != "undefined" && _this.globalChange) {
            if (document.all && event)
                event.returnValue = _this.navigateAwayMessage;
            else
                return _this.navigateAwayMessage;
        }
    }
}

// Register the event.
window.onbeforeunload = function() { return CheckForChangesFunction.checkForChanges(); }

function PrintPreview() {
    var OLECMDID = 7;
    /* OLECMDID values:
    * 6 - print
    * 7 - print preview
    * 1 - open window
    * 4 - Save As
    */
    var PROMPT = 1; // 2 DONTPROMPTUSER 
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
    document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
    WebBrowser1.ExecWB(OLECMDID, PROMPT);
    WebBrowser1.outerHTML = "";
}

function getWindowWidth(e) 
{
    var myWidth = 0
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
    }
    return myWidth;
}

function getWindowHeight(e) {
    var myHeight = 0
    if (typeof (window.innerHeight) == 'number') {
        //Non-IE
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientHeight || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientHeight || document.body.clientHeight)) {
        //IE 4 compatible
        myHeight = document.body.clientHeight;
    }
    return myHeight;
}

function getScrollWidth(e) 
{
    var posX = 0;
    if (window.event)
    {
        var IEEvent = window.event;
        if (IEEvent.clientX)
        {
            posX = IEEvent.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
        }        
    }
    else
    {
        if (e.pageX) 
        {
            posX = e.pageX;
        }
    }
    return posX;
}

function getScrollHeight(e) 
{
    var posY = 0;
    if (window.event)
    {
        var IEEvent = window.event;
        if (IEEvent.clientY) 
        {
            posY = IEEvent.clientY + document.body.scrollTop + document.documentElement.scrollTop;
        }
    }
    else 
    {
        if (e.pageY) 
        {
            posY = e.pageY;
        }
    }
    return posY;
}

function Left(str, n) {
    if (n <= 0 || str == "" || str == "undefined")
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0, n);
}

function Right(str, n) {
    if (n <= 0 || str == "" || str == "undefined")
        return "";
    else if (n > String(str).length)
        return str;
    else {
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
    }
}
