var _CurrentPopupBox = null;
function OpenModal(url, boxId) {
    if (_CurrentPopupBox != null) _CurrentPopupBox.style.display = 'none';

    if (boxId == null) boxId = StandardModal;

    var box = document.getElementById(boxId);
    _CurrentPopupBox = box;
    // Move the box to the center of the screen:
    box.style.display = 'block';
    document.getElementById(boxId + '_Frame').src = url;
    document.getElementById(boxId + '_Cover').style.display = 'block';
}

function SetTextboxClasses() {
    var inputs = document.getElementsByTagName('INPUT');
    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i].type.toLowerCase() == 'text' || inputs[i].type.toLowerCase() == 'password') {
            inputs[i].className += ' textbox';
        }
    }
}

function CloseModal(refreshParent) {
    if (_CurrentPopupBox == null) return;
    document.getElementById(_CurrentPopupBox.id + '_Frame').src = '/Content/PleaseWait.htm';
    document.getElementById(_CurrentPopupBox.id + '_Cover').style.display = '';

    _CurrentPopupBox.style.display = 'none';
    _CurrentPopupBox = null;
    if (refreshParent == true) {
        window.location = window.location;
    }
}

/// This will break the execution for current javascript thread.
function Break() {
    // Return nothing. This method is meant to be used in hyperlink href's
}

function OpenBrowserWindow(url, target) {
    if (target == null) target = '_blank';
    window.open(url, target);
}

function ShowPleaseWait() {
    var image = document.createElement("img");

    image.style.position = "absolute";
    image.style.left = 0;
    image.style.top = 0;
    image.style.margin = '30% 50% 50% 50%';
    image.setAttribute("src", "/Images/PleaseWait.gif");

    document.getElementById('aspnetForm').appendChild(image);
}

function UpdateFileUploadStatus(lstMode, fileUploadControlId) {
    var prefix = lstMode.getAttribute('id').substring(0, lstMode.getAttribute('name').lastIndexOf("$") + 1);
    var file = document.getElementById(prefix + fileUploadControlId);

    if (lstMode.selectedIndex == 1 && file.style.display == 'none')
        file.style.display = '';
    else
        file.style.display = 'none';
}

// Function list, for window.Onload:
var OnLoadFunctions = new Object();
function RunOnLoad(func) {
    var existing = 0;
    for (method in OnLoadFunctions) existing = existing + 1;

    OnLoadFunctions[existing] = func;
}
window.onload = function() {

    for (method in OnLoadFunctions) {
        OnLoadFunctions[method]();
    }
}

RunOnLoad(SetTextboxClasses);