﻿function focusControl(id) {
    setTimeout(function() {
        var control = $find(id);
        if (control && control.focus) {
            control.focus();
        } else if (control && control.get_inputDomElement) {
            control.get_inputDomElement().focus();
            if (!control.get_dropDownVisible()) {
                control.showDropDown();
            }
        } else if (control && control.get_dateInput) {
            control.get_dateInput().focus();
        } else {
            control = $get(id);
            if (control && control.focus) {
                control.focus();
            }
        }
    }, 0);
}
function getScrollPosition() {
    var oResult = { x: 0, y: 0 };
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        oResult.x = window.pageXOffset;
        oResult.y = window.pageYOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        oResult.x = document.body.scrollLeft;
        oResult.y = document.body.scrollTop;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        oResult.x = document.documentElement.scrollLeft;
        oResult.y = document.documentElement.scrollTop;
    }
    return oResult;
}
function showAlert(message) {
    alert(decodeURIComponent(message));
}
function clearSelection() {
    try {
        if (window.getSelection && window.getSelection().removeAllRanges) {
            window.getSelection().removeAllRanges();
        } else if (document.selection && document.selection.empty) {
            document.selection.empty();
        }
    } catch (er) {
        var userSelection = {};
        if (window.getSelection) {
            userSelection = window.getSelection();
        } else if (document.selection && document.selection.createRange) {
            userSelection = document.selection.createRange();
        }
        if (userSelection.select) {
            userSelection.select();
        } else if (userSelection.detach) {
            userSelection.detach();
        }
    }
}
function submitDynamicForm(action, params, method, target) {
    params = params || {};
    method = method || "post";
    target = target || "_self"; /* _blank | _parent | _self | _top */

    var form = document.createElement("form");
    form.setAttribute("action", action);
    form.setAttribute("method", method);
    form.setAttribute("target", target);

    for (var key in params) {
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", key);
        hiddenField.setAttribute("value", params[key]);
        form.appendChild(hiddenField);
    }

    document.body.appendChild(form);
    form.submit();
    document.body.removeChild(form);
}

