﻿addOnloadEvent(resizeBody);
addOnResizeEvent(resizeBody);

function resizeBody() {
    var iHeight = document.documentElement.clientHeight;
    if ($obj('tbl') != null)
        $obj('tbl').style.height = iHeight + "px";
}

function $obj(obj) {
    return document.getElementById(obj);
}

function addOnloadEvent(fnc) {
    if (typeof window.addEventListener != "undefined")
        window.addEventListener("load", fnc, false);
    else if (typeof window.attachEvent != "undefined") {
        window.attachEvent("onload", fnc);
    }
    else {
        if (window.onload != null) {
            var oldOnload = window.onload;
            window.onload = function (e) {
                oldOnload(e);
                window[fnc]();
            };
        }
        else
            window.onload = fnc;
    }
}

function addOnResizeEvent(fnc) {
    if (typeof window.addEventListener != "undefined")
        window.addEventListener("resize", fnc, false);
    else if (typeof window.attachEvent != "undefined") {
        window.attachEvent("onresize", fnc);
    }
    else {
        if (window.onload != null) {
            var oldOnResize = window.onresize;
            window.onresize = function (e) {
                oldOnResize(e);
                window[fnc]();
            };
        }
        else
            window.onresize = fnc;
    }
}

function popup(url) {
    params = 'width=' + window.screen.availWidth;
    params += ', height=' + window.screen.availHeight;
    params += ', top=0, left=0'
    params += ', directories=yes';
    params += ', location=yes';
    params += ', menubar=yes';
    params += ', resizable=yes';
    params += ', scrollbars=yes';
    params += ', status=yes';
    params += ', toolbar=yes';

    newwin = window.open(url, 'menke', params);
    if (window.focus) { newwin.focus() }
    return false;
}

function getClientHeight() {

    var myHeight = 0;
    if (typeof (window.innerHeight) == 'number') {
        myHeight = window.innerHeight - 20;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && document.body.clientHeight) {
        myHeight = document.body.clientHeight;
    }
    return myHeight
}

function getClientWidth() {

    var myWidth = 0;
    if (typeof (window.innerWidth) == 'number') {
        myWidth = window.innerWidth
    } else if (document.documentElement && document.documentElement.clientWidth) {
        myWidth = document.documentElement.clientWidth;
    } else if (document.body && document.body.clientWidth) {
        myWidth = document.body.clientWidth;
    }
    return myWidth
}

function resizeGrid(offsetHeight, gridName) {

    var iHeight = getClientHeight();

    if (gridName == null) return;

    var grid = igtbl_getGridById(gridName);

    iHeight = iHeight - offsetHeight;

    if (iHeight <= 50)
        iHeight = 50;

    grid.MainGrid.style.height = iHeight + "px";

    document.getElementById(grid.Id + "_mr").style.height = iHeight + "px";
    document.getElementById(grid.Id + "_mc").style.height = iHeight + "px";
}


function resizeWebDataGrid(gridName, offset) {
    addOnloadEvent(function () { if (getClientHeight() - offset > 10) document.getElementById(gridName).style.height = getClientHeight() - offset + "px"; });
    addOnResizeEvent(function () { if (getClientHeight() - offset > 10) document.getElementById(gridName).style.height = getClientHeight() - offset + "px"; });
}


function getWidth() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return myWidth;
}
var val;
function itemclicked(sender, args) {
    val = args.getExplorerBarItem().get_value();
    if (val == "") return;
    PageMethods.SetSession(val, onReqComplete);
}
function onReqComplete(ret) {
    document.getElementById('winFrame_tmpl_iDowload').src = "blank.aspx";
    document.getElementById('winFrame_tmpl_iDowload').src = ret;
    var oWebDialogWindow1 = $find('winFrame');
    oWebDialogWindow1.set_windowState($IG.DialogWindowState.Normal);
    if (val == 0)
        setWebDiaglog(oWebDialogWindow1, 500, 600, 'Send Client Email');
    else if (val == 1)
        setWebDiaglog(oWebDialogWindow1, 500, 800, 'Send Client File');
    else if (val == 2)
        setWebDiaglog(oWebDialogWindow1, 500, 800, 'Participant Users');
    else if (val == 3)
        setWebDiaglog(oWebDialogWindow1, 500, 800, 'Client Users');
    else if (val == 4)
        setWebDiaglog(oWebDialogWindow1, 550, 900, 'Process Distribution');
    else if (val == 7)
        setWebDiaglog(oWebDialogWindow1, 600, 900, 'Load Distribution File');
    else if (val == 11)
        setWebDiaglog(oWebDialogWindow1, 500, 600, 'M Units Sell');
    else if (val == 12)
        setWebDiaglog(oWebDialogWindow1, 500, 900, 'M Units Buy');
    else if (val == 14)
        setWebDiaglog(oWebDialogWindow1, 550, 940, 'Company Masterfile');
    else if (val == 16)
        setWebDiaglog(oWebDialogWindow1, 500, 900, 'Distribution Policy');
    else if (val == 17)
        setWebDiaglog(oWebDialogWindow1, 550, 900, 'Import 1099');
    else if (val == 5)
        setWebDiaglog(oWebDialogWindow1, 600, 950, 'Review Distribution');
    else {
        oWebDialogWindow1.setSize('95%', '95%');
        oWebDialogWindow1.set_top('2%');
        oWebDialogWindow1.set_left('2%');
    }
}


function getContentWindow(iframe) {
    return iframe.contentWindow || x.contentDocument;
}

function showWin2Info(src, width, height, caption) {
    var oWebDialogWindow1 = $find('winFrame2');
    oWebDialogWindow1.set_windowState($IG.DialogWindowState.Normal);
    iframe = document.getElementById('iDownload2');
    if (getContentWindow(iframe) != null) {
        getContentWindow(iframe).location = src;
    }
    else {
        document.getElementById('iDownload2').src = '';
        document.getElementById('iDownload2').src = src;
    }
    setWebDiaglog(oWebDialogWindow1, height, width, caption);
}

function showWin2(src, tag) {
    var oWebDialogWindow1 = $find('winFrame2');
    oWebDialogWindow1.set_windowState($IG.DialogWindowState.Normal);
    document.getElementById('iDownload2').src = '';
    document.getElementById('iDownload2').src = src;
    if (tag == null) return;
    if (tag == 1) {
        oWebDialogWindow1.setSize('500px', '560px');
        oWebDialogWindow1.set_top((getClientHeight() - 560) / 2);
        oWebDialogWindow1.set_left(((getWidth() - 500) / 2) + 'px');
    }
    else if (tag == 2) {
        oWebDialogWindow1.setSize('530px', '300px');
        oWebDialogWindow1.set_top((getClientHeight() - 300) / 2);
        oWebDialogWindow1.set_left(((getWidth() - 530) / 2) + 'px');
    }
    else if (tag == 3 || tag == 4) {
        oWebDialogWindow1.setSize('700px', '300px');
        oWebDialogWindow1.set_top((getClientHeight() - 300) / 2);
        oWebDialogWindow1.set_left(((getWidth() - 700) / 2) + 'px');
        if (tag == 4)
            oWebDialogWindow1.get_header().setCaptionText('Modify Bid');
        else
            oWebDialogWindow1.get_header().setCaptionText('Add New Bid');
    }
    else if (tag == 5) {
        setWebDiaglog(oWebDialogWindow1, 600, 950, 'Edit Client Information');
    }
    else if (tag == 6) {
        setWebDiaglog(oWebDialogWindow1, getClientHeight(), getClientWidth(), 'Edit Distribution');
    }
    else if (tag == 7) {
        setWebDiaglog(oWebDialogWindow1, getClientHeight(), getClientWidth(), 'Enter/Edit Election');
        oWebDialogWindow1.set_top(0);
        oWebDialogWindow1.set_left(0);
    }
    else if (tag == 8) {
        setWebDiaglog(oWebDialogWindow1, 350, 500, 'Selling M Units');
        var hideIMG = oWebDialogWindow1._elements.Close;
        if (hideIMG)
            hideIMG.style.display = 'none';
    }
    else if (tag == 9) {
        setWebDiaglog(oWebDialogWindow1, 550, 900, 'Enter/Edit Election');        
    }
}


function showWin4Info(src, width, height, caption) {
    var oWebDialogWindow1 = $find('winFrame4');
    oWebDialogWindow1.set_windowState($IG.DialogWindowState.Normal);
    iframe = document.getElementById('iDownload4');
    if (getContentWindow(iframe) != null) {
        getContentWindow(iframe).location = src;
    }
    else {
        document.getElementById('iDownload2').src = '';
        document.getElementById('iDownload2').src = src;
    }
    setWebDiaglog(oWebDialogWindow1, height, width, caption);
}

function showWin4InfoPCT(src, width, height, caption) {
    var oWebDialogWindow1 = $find('winFrame4');
    oWebDialogWindow1.set_windowState($IG.DialogWindowState.Normal);
    iframe = document.getElementById('iDownload4');
    if (getContentWindow(iframe) != null) {
        getContentWindow(iframe).location = src;
    }
    else {
        document.getElementById('iDownload2').src = '';
        document.getElementById('iDownload2').src = src;
    }
    setWebDiaglogPCT(oWebDialogWindow1, height, width, caption);
}

function showWin3Info(src, width, height, caption) {
    var oWebDialogWindow1 = $find('winFrame3');
    oWebDialogWindow1.set_windowState($IG.DialogWindowState.Normal);
    iframe = document.getElementById('iDownload3');
    if (getContentWindow(iframe) != null) {
        getContentWindow(iframe).location = src;
    }
    else {
        document.getElementById('iDownload3').src = '';
        document.getElementById('iDownload3').src = src;
    }
    setWebDiaglog(oWebDialogWindow1, height, width, caption);
}

function hideWin3(src) {
    oWebDialogWindow1 = $find('winFrame3');
    oWebDialogWindow1.set_windowState($IG.DialogWindowState.Hidden);
    if (src == null) return;
    document.getElementById('iDownload3').src = '';
    document.getElementById('iDownload3').src = src;
}

function showWin3(src, tag) {
    var oWebDialogWindow1 = $find('winFrame3');
    oWebDialogWindow1.set_windowState($IG.DialogWindowState.Normal);
    document.getElementById('iDownload3').src = '';
    document.getElementById('iDownload3').src = src;
    if (tag == null) return;
}

function showWin4(src, tag) {
    var oWebDialogWindow1 = $find('winFrame4');
    oWebDialogWindow1.set_windowState($IG.DialogWindowState.Normal);
    document.getElementById('iDownload4').src = '';
    document.getElementById('iDownload4').src = src;
    if (tag == null) return;
    if (tag == 1) {
        setWebDiaglog(oWebDialogWindow1, 400, 500, "Add Client User");
    }
    else if (tag == 2) {
        setWebDiaglog(oWebDialogWindow1, 400, 500, "Add Client Admin User");
    }
    else if (tag == 3) {
        setWebDiaglog(oWebDialogWindow1, getClientHeight(), getClientWidth(), 'Print Election');
        oWebDialogWindow1.set_top(0);
        oWebDialogWindow1.set_left(0);
    }
    else if (tag == 4) {
        setWebDiaglog(oWebDialogWindow1, getClientHeight(), getClientWidth(), 'Enter/Edit Beneficiary');
        oWebDialogWindow1.set_top(0);
        oWebDialogWindow1.set_left(0);
    }
    else if (tag == 5) {
        setWebDiaglog(oWebDialogWindow1, 350, 500, 'Buying M Units');
        var hideIMG = oWebDialogWindow1._elements.Close;
        if (hideIMG)
            hideIMG.style.display = 'none';
    }
}
function submitLot() {
    oWebDialogWindow1 = $find('winFrame4');
    oWebDialogWindow1.set_windowState($IG.DialogWindowState.Hidden);
    var myIFrame = document.getElementById('iDownload2');
    var content = getContentWindow(myIFrame).document.forms[0].cmdSubmitDetail.click();
}

function setWebDiaglog(oWebDialogWindow1, iHeight, iWidth, sCaption) {
    oWebDialogWindow1.setSize(iWidth + 'px', iHeight + 'px');
    oWebDialogWindow1.set_top((getClientHeight() - iHeight) / 2);
    oWebDialogWindow1.set_left(((getWidth() - iWidth) / 2));
    oWebDialogWindow1.get_header().setCaptionText(sCaption);
}

function setWebDiaglogPCT(oWebDialogWindow1, iHeight, iWidth, sCaption) {
    oWebDialogWindow1.setSize(iWidth + '%', iHeight + '%');
    oWebDialogWindow1.set_top('2%');
    oWebDialogWindow1.set_left('2%');
    oWebDialogWindow1.get_header().setCaptionText(sCaption);
}

function hideWin1() {
    oWebDialogWindow1 = $find('winFrame');
    oWebDialogWindow1.set_windowState($IG.DialogWindowState.Hidden);
    document.getElementById('winFrame_tmpl_iDowload').src = '';
}

function hideWin2(src) {
    oWebDialogWindow1 = $find('winFrame2');
    oWebDialogWindow1.set_windowState($IG.DialogWindowState.Hidden);
    document.getElementById('iDownload2').src = '';
    if (src == null) return;
    document.getElementById('winFrame_tmpl_iDowload').src = '';
    document.getElementById('winFrame_tmpl_iDowload').src = src;
}

function hideWin4(src) {
    oWebDialogWindow1 = $find('winFrame4');
    oWebDialogWindow1.set_windowState($IG.DialogWindowState.Hidden);
    if (src == null) return;
    document.getElementById('iDownload4').src = '';
    document.getElementById('iDownload4').src = src;
}

function resize() {
    var iHeight = getClientHeight() - 160;
    if (iHeight <= 200)
        iHeight = 200;
    document.getElementById("content").style.height = iHeight + "px";
}
