﻿var genericShowModalDialog = window.showModalDialog;

window.showModalDialog = function(uri, arguments, options)
{
    if (options == undefined)
    {
        options = 'dialogHeight:600px;dialogWidth:1000px;';
    }

    var result = genericShowModalDialog(uri, arguments, options);

    return result;
};

window.showModalDialogAndEval = function(uri, arguments, options)
{
    var result = showModalDialog(uri, arguments, options);
    return eval(result);
};

window.blockForm = function(duration)
{
    var div = document.createElement('div');
    div.setAttribute('id', 'blockingDiv');
    div.setAttribute('class', 'blockingDiv');
    document.body.appendChild(div);

    if (duration)
    {
        setTimeout('unblockForm();', duration);
    }
}

window.unblockForm = function()
{
    var div = document.getElementById('blockingDiv');

    if (div)
    {
        div.parentNode.removeChild(div);
    }
}

Array.prototype.last = function() {
    if (this.length > 0) {
        return this[this.length - 1];
    }
    else {
        return null;
    }
   }

//Pobiera ze zdarzenia wspolrzedne i tlumaczy je na absolutne wzgledem dokumentu
function getAbsoluteCoordinates(e) {
    var posx = 0;
    var posy = 0;

    if (!e) {
        var e = window.event;
    }

    if (e.pageX || e.pageY) {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
        posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
        posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }

    return { x: posx, y: posy };
}   
   

   function newGuid() {
    var result = '';

    for (var j = 0; j < 32; j++) {
        if (j == 8 || j == 12 || j == 16 || j == 20) {
            result = result + '-';
        }

        result = result + Math.floor(Math.random() * 16).toString(16).toUpperCase();
    }

    return result;
   }

function genericPrintReport(content) {
    var headstr = "<html><head><title>Print Preview</title></head><body>";
    var footstr = "</body></html>"
    var WinPrint = window.open('', '', 'left=150,top=150,width=700,height=500,menubar=1,toolbar=0,scrollbars=0,status=0');
    WinPrint.document.write(headstr + content + footstr);
    WinPrint.document.close();
    WinPrint.focus();
    WinPrint.print();
}
