﻿function clearDefault(el) {
    if (el.defaultValue == el.value) el.value = ""
}

function setProgressPanelPosition() {
    var verticalCenter = mdlInt(mdlGetClientHeight() / 2);
    var horizontalCenter = mdlInt(mdlGetClientWidth() / 2);

    var _progresspanel = mdlGet("LoginProgressPanel");
    if (_progresspanel != null) {
        if (verticalCenter > 40) {
            _progresspanel.style.top = mdlInt(verticalCenter - 40) + "px";
        }
        else {
            _progresspanel.style.top = "0px";
        }
        if (horizontalCenter > 100) {
            _progresspanel.style.left = mdlInt(horizontalCenter - 100) + "px";
        }
        else {
            _progresspanel.style.left = "0px";
        }
    }

    var _progresspanel = mdlGet("DefaultPageProgressPanel");
    if (_progresspanel != null) {
        if (verticalCenter > 40) {
            _progresspanel.style.top = mdlInt(verticalCenter - 40) + "px";
        }
        else {
            _progresspanel.style.top = "0px";
        }
        if (horizontalCenter > 100) {
            _progresspanel.style.left = mdlInt(horizontalCenter - 100) + "px";
        }
        else {
            _progresspanel.style.left = "0px";
        }
    }

    var _progresspanel = mdlGet("ContentProgressPanel");
    if (_progresspanel != null) {
        if (verticalCenter > 40) {
            _progresspanel.style.top = mdlInt(verticalCenter - 40) + "px";
        }
        else {
            _progresspanel.style.top = "0px";
        }
        if (horizontalCenter > 100) {
            _progresspanel.style.left = mdlInt(horizontalCenter - 100) + "px";
        }
        else {
            _progresspanel.style.left = "0px";
        }
    }
}

function popup(url) {
    var width = 810;
    var height = 676;
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
    var params = 'width=' + width + ', height=' + height;
    params += ', top=' + top + ', left=' + left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=no';
    params += ', scrollbars=no';
    params += ', status=no';
    params += ', toolbar=no';
    newwin = window.open(url, 'windowname1', params);
    if (window.focus) { newwin.focus() }
    return false;
}

function mdlGetClientHeight() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myHeight = document.body.clientHeight;
    }
    return myHeight;
}

function mdlGetClientWidth() {
    var myWidth = 0, myHeight = 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 mdlGet(object) {
    if (document.all) {
        return (document.all[object])
    } else if (document.layers) {
        return (document.layers[object])
    } else {
        return (document.getElementById(object))
    }
}

function mdlInt(d_x, d_y) {
    return isNaN(d_y = parseInt(d_x)) ? 0 : d_y;
}

function keyPressed(object) {
    var keyID = (window.event) ? event.keyCode : e.keyCode;

    if (keyID == 13) {
        mdlGet(object).click();
        return false;
    }
    else
        return true;
}
