﻿var PageFullyLoaded;
function _LoadBegin() {
    PageFullyLoaded = false;
}
function _LoadComplete() {
    PageFullyLoaded = true;
    _SetFullScreen('fullScreenDiv');
}
function $PEC(id) {
    return document.getElementById(id);
}
function _SetFullScreen(elementId) {
    var obj = $PEC(elementId);
    if (obj != null) {
        var viewportwidth;var viewportheight;
        // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
        if (typeof window.innerWidth != 'undefined') {
            viewportwidth = window.innerWidth;
            viewportheight = window.innerHeight;
        }
        // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
        else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
            viewportwidth = document.documentElement.clientWidth;
            viewportheight = document.documentElement.clientHeight;
        }
        // older versions of IE
        else {
            viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
            viewportheight = document.getElementsByTagName('body')[0].clientHeight;
        }
        obj.style.height = viewportheight + 'px';
    }
    _ensureModalDragHandle();
}
String.prototype.endsWith = function(s, isCaseSensitive) {
    if (isCaseSensitive == false) {
        return this.length >= s.length && this.substr(this.length - s.length).toLowerCase() == s.toLowerCase();
    }
    return this.length >= s.length && this.substr(this.length - s.length) == s;
}
String.prototype.replaceAll = function(s, r) {
    var re = new RegExp(s,"g"); 
    var c = this.replace(re, r);
    return c;
}
function encodeHtml(toEncode) {
    return toEncode.replaceAll('&','&amp;').replaceAll('"', '&quot;').replaceAll('<', '&lt;').replaceAll('>', '&gt;');
}
function doLimitBeforePaste(control) {
    maxLength = control.attributes["maxLength"].value;
    if (maxLength) {
        event.returnValue = false;
    }
}
function doLimitPaste(control) {
    maxLength = control.attributes["maxLength"].value;
    value = control.value;
    if (maxLength) {
        event.returnValue = false;
        maxLength = parseInt(maxLength);
        var oTR = control.document.selection.createRange();
        var iInsertLength = maxLength - value.length + oTR.text.length;
        var sData = window.clipboardData.getData("Text").substr(0, iInsertLength);
        oTR.text = sData;
    }
}
function doLimitInput(control) {
    if (control.value.length > control.attributes["maxLength"].value) {
        control.value = control.value.substring(0, control.attributes["maxLength"].value);
    }
}
function doLimitReport(control, targetId, checkClass) {
    var obj = $PEC(targetId);
    if (obj != null) {
        if (checkClass) {
            if (control.className != checkClass) {
                maxLength = control.attributes["maxLength"].value;
                if (maxLength) {
                    obj.innerHTML = maxLength;
                }
                return;
            }
        }
        maxLength = control.attributes["maxLength"].value;
        if (maxLength) {
            maxLength = parseInt(maxLength);
            obj.innerHTML = (maxLength - control.value.length);
        }
    }
}                         
function GetWindowWidth() {
    var width =
		document.documentElement && document.documentElement.clientWidth ||
		document.body && document.body.clientWidth ||
		document.body && document.body.parentNode && document.body.parentNode.clientWidth ||
		0;

    return width;
}
function GetWindowHeight() {
    var height =
		document.documentElement && document.documentElement.clientHeight ||
		document.body && document.body.clientHeight ||
  		document.body && document.body.parentNode && document.body.parentNode.clientHeight ||
  		0;

    return height;
}
function _SetDivScrollPosition() {
    var strCook = document.cookie;
    if (strCook.length > 0) {
        var cookies = strCook.split(";");
        for (var i = 0; i < cookies.length; i++) {
            var mySplit = cookies[i].split("=");
            try {
                if (mySplit[1] > $PEC(mySplit[0].replace(" ", "")).offsetHeight) {
                    var fn = function() {
                        return _SetDivScrollPosition();
                    }
                    setTimeout(fn, 500);
                }
                $PEC(mySplit[0].replace(" ", "")).scrollTop = mySplit[1];
            }
            catch (e) {
            }
        }
    }
}
function FilterInput(newValue, acceptableChars) {
    var str = newValue;
    var x;
    for (x = 0; x < acceptableChars.length; x++) {
        str = str.split(acceptableChars.substring(x, x + 1));
        str = str.join("");
    }
    var unacceptableChars = str;
    str = newValue;
    for (x = 0; x < unacceptableChars.length; x++) {
        str = str.split(unacceptableChars.substring(x, x + 1));
        str = str.join("");
    }
    return str;
}
function FilterTextBoxInput(target) {
    target.value = FilterInput(target.value, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-");
}
function FilterUserNameTextBoxInput(target) {
    target.value = FilterInput(target.value, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-.");
}
function CobbleUserName(targetId, firstnameId, lastnameId) {
    var target = $PEC(targetId);
    if (target != null) {
        var username = "";
        var firstName = $PEC(firstnameId);
        if (firstName != null) {
            username = FilterInput(firstName.value, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-");
            username = username + '.';
        }
        var lastName = $PEC(lastnameId);
        if (lastName != null) {
            if (username == "") username = username + '.';
            username = username + FilterInput(lastName.value, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-");
        }
        target.innerHTML = username.toLowerCase();
    }
}
function popupShown(sender, e) {
    if (sender._dragBehavior != null) {
        sender._dragBehavior.popupParent = sender;
        sender._dragBehavior.add_move(savePanelPosition);
    }
}
function savePanelPosition(sender, e)
{
    var elem = sender.get_element();
    var loc = $common.getLocation(elem);
    if ((typeof sender.popupParent != 'undefined') && (sender.popupParent != null)) {
        sender.popupParent.set_X(loc.x);
        sender.popupParent.set_Y(loc.y);
    }
}
function SetModalPopup(popupExtenderId) {
    var popupExtender = $find(popupExtenderId);
    if (popupExtender != null)
    {
        popupExtender.set_X(-1);
        popupExtender.set_Y(-1);
        popupExtender.add_shown(popupShown);
        
        if (popupExtender._dragBehavior != null) {
            popupExtender._dragBehavior.popupParent = popupExtender;
            popupExtender._dragBehavior.add_move(savePanelPosition);
        }
    }
    else
    {
        var fn = function() {
            SetModalPopup(popupExtenderId);
        }
        window.setTimeout(fn, 100);
    }
}
function SetWidgetPopup(popupExtender, wbinding, wstate, wviewroles, weditroles, winheritroles, werrormsg) {
    try {
        if (popupExtender != null)
        {
            popupExtender.w_errorMsgId = werrormsg;
            popupExtender.w_bindingId = wbinding;
            popupExtender.w_stateId = wstate;
            popupExtender.w_viewRolesId = wviewroles;
            popupExtender.w_editRolesId = weditroles;
            popupExtender.w_inheritRolesId = winheritroles;

            popupExtender.w_binding = $PEC(popupExtender.w_bindingId).value;
            popupExtender.w_state = $PEC(popupExtender.w_stateId).value;
            _loadWidgetPopupAsyncRoleTab(popupExtender);
        }
    }
    catch (e) {
        ;
    }
}
function _loadWidgetPopupAsyncRoleTab(popupExtender) {
    try {
        if (popupExtender != null)
        {
            popupExtender.w_viewRoles = new Array();
            var obj = $PEC(popupExtender.w_viewRolesId);
            if (obj != null) {
                var inputRefArray = obj.getElementsByTagName('input');
                for (var i = 0; i < inputRefArray.length; i++) {
                    var inputRef = inputRefArray[i];
                    if (inputRef.type.substr(0, 8) == 'checkbox') {
                        popupExtender.w_viewRoles.push(inputRef.checked);
                    }
                }
            }
            popupExtender.w_editRoles = new Array();
            obj = $PEC(popupExtender.w_editRolesId);
            if (obj != null) {
                var inputRefArray = obj.getElementsByTagName('input');
                for (var i = 0; i < inputRefArray.length; i++) {
                    var inputRef = inputRefArray[i];
                    if (inputRef.type.substr(0, 8) == 'checkbox') {
                        popupExtender.w_editRoles.push(inputRef.checked);
                    }
                }
            }
            obj = $PEC(popupExtender.w_inheritRolesId);
            if (obj != null) {
                popupExtender.w_inheritRoles = obj.checked;
            }
        }
    }
    catch (e) {
        ;
    }
}
function ResetWidgetPopup(popupExtender) {
    try {
        if (popupExtender != null) {       
            var errorMsg = $PEC(popupExtender.w_errorMsgId);
            if (errorMsg != null) {
                errorMsg.className = errorMsg.className.substring(0, errorMsg.className.indexOf('_')) + '_Empty';
            }
            var bindingInput = $PEC(popupExtender.w_bindingId);
            if (bindingInput != null) {
                bindingInput.value = popupExtender.w_binding;
                bindingInput.style.backgroundColor = 'white';
            }
            var stateInput = $PEC(popupExtender.w_stateId);
            if (stateInput != null) {
                stateInput.value = popupExtender.w_state;
                stateInput.style.backgroundColor = 'white';
            }
            var obj = $PEC(popupExtender.w_viewRolesId);
            if (obj != null) {
                var inputRefArray = obj.getElementsByTagName('input');
                for (var i = 0; i < inputRefArray.length; i++) {
                    var inputRef = inputRefArray[i];
                    if (inputRef.type.substr(0, 8) == 'checkbox') {
                        inputRef.checked = popupExtender.w_viewRoles[i];
                    }
                }
            }
            obj = $PEC(popupExtender.w_editRolesId);
            if (obj != null) {
                var inputRefArray = obj.getElementsByTagName('input');
                for (var i = 0; i < inputRefArray.length; i++) {
                    var inputRef = inputRefArray[i];
                    if (inputRef.type.substr(0, 8) == 'checkbox') {
                        inputRef.checked = popupExtender.w_editRoles[i];
                    }
                }
            }
            obj = $PEC(popupExtender.w_inheritRolesId);
            if (obj != null) {
                obj.checked = popupExtender.w_inheritRoles;
            }
        }
    }
    catch (e) {
        ;
    }
}
function SetPagePopup(popupExtender, pbinding, pstate, pviewroles, peditroles, perrormsg) {
    try {
        if (popupExtender != null)
        {
            popupExtender.p_errorMsgId = perrormsg;
            popupExtender.p_bindingId = pbinding;
            popupExtender.p_stateId = pstate;
            popupExtender.p_viewRolesId = pviewroles;
            popupExtender.p_editRolesId = peditroles;

            popupExtender.p_binding = $PEC(popupExtender.p_bindingId).value;
            popupExtender.p_state = $PEC(popupExtender.p_stateId).value;
            _loadPagePopupAsyncRoleTab(popupExtender);
        }
    }
    catch (e) {
        ;
    }
}
function _loadPagePopupAsyncRoleTab(popupExtender) {
    try {
        if (popupExtender != null) 
        {
            popupExtender.p_viewRoles = new Array();
            var obj = $PEC(popupExtender.p_viewRolesId);
            if (obj != null) {
                var inputRefArray = obj.getElementsByTagName('input');
                for (var i = 0; i < inputRefArray.length; i++) {
                    var inputRef = inputRefArray[i];
                    if (inputRef.type.substr(0, 8) == 'checkbox') {
                        popupExtender.p_viewRoles.push(inputRef.checked);
                    }
                }
            }
            popupExtender.p_editRoles = new Array();
            obj = $PEC(popupExtender.p_editRolesId);
            if (obj != null) {
                var inputRefArray = obj.getElementsByTagName('input');
                for (var i = 0; i < inputRefArray.length; i++) {
                    var inputRef = inputRefArray[i];
                    if (inputRef.type.substr(0, 8) == 'checkbox') {
                        popupExtender.p_editRoles.push(inputRef.checked);
                    }
                }
            }
        }
    }
    catch (e) {
        ;
    }
}
function ResetPagePopup(popupExtender) {
    try {
        if (popupExtender != null) {
            var errorMsg = $PEC(popupExtender.p_errorMsgId);
            if (errorMsg != null) {
                errorMsg.className = errorMsg.className.substring(0, errorMsg.className.indexOf('_')) + '_Empty';
            }
            var bindingInput = $PEC(popupExtender.p_bindingId);
            if (bindingInput != null) {
                bindingInput.value = popupExtender.p_binding;
                bindingInput.style.backgroundColor = 'white';
            }
            var stateInput = $PEC(popupExtender.p_stateId);
            if (stateInput != null) {
                stateInput.value = popupExtender.p_state;
                stateInput.style.backgroundColor = 'white';
            }
            var obj = $PEC(popupExtender.p_viewRolesId);
            if (obj != null) {
                var inputRefArray = obj.getElementsByTagName('input');
                for (var i = 0; i < inputRefArray.length; i++) {
                    var inputRef = inputRefArray[i];
                    if (inputRef.type.substr(0, 8) == 'checkbox') {
                        inputRef.checked = popupExtender.p_viewRoles[i];
                    }
                }
            }
            obj = $PEC(popupExtender.p_editRolesId);
            if (obj != null) {
                var inputRefArray = obj.getElementsByTagName('input');
                for (var i = 0; i < inputRefArray.length; i++) {
                    var inputRef = inputRefArray[i];
                    if (inputRef.type.substr(0, 8) == 'checkbox') {
                        inputRef.checked = popupExtender.p_editRoles[i];
                    }
                }
            }
        }
    }
    catch (e) {
        ;
    }
}
function IsIE8Browser() {
    var rv = -1;
    var ua = navigator.userAgent;
    var re = new RegExp("Trident\/([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null) {
        rv = parseFloat(RegExp.$1);
    }
    return (rv == 4); 
}
function resetNewFolderPopup(popupExtenderId, nameTextBoxId, descTextBoxId, errorMsgId) {
    var obj = $PEC(nameTextBoxId);
    if (obj != null) {
        obj.value = '';
        obj.style.backgroundColor = 'white';
    }
    obj = $PEC(descTextBoxId);
    if (obj != null) {
        obj.value = '';
    }
    obj = $PEC(errorMsgId);
    if (obj != null) {
        obj.className = obj.className.substring(0, obj.className.indexOf('_')) + '_Empty';
    }
    SetModalPopup(popupExtenderId);
}
function _onPositionContainerFrame(dragExtender, resizeExtender, panelId, frameId, elementId, posx, posy, posw, posh) {
    if ((posx != -1) && (posy != -1)) {
        var e = dragExtender.get_element();
        if (e != null) {
            $common.setLocation(e, new Sys.UI.Point(posx, posy));
        }
    }
    if ((posw != -1) && (posh != -1)) {
        var size = resizeExtender.get_Size();
        resizeExtender.set_Size({ width: size.width, height: size.height });
        resizeExtender.set_Size({ width: posw, height: posh });

        resizeExtender._handle.style.left = (posw + resizeExtender._HandleOffsetX - 10) + 'px';
        resizeExtender._handle.style.top = (posh + resizeExtender._HandleOffsetY - 10) + 'px';
        resizeExtender._MinimumHeight = 0;
        resizeExtender._MinimumWidth = 0;
        
        var e = $PEC(panelId);
        if (e != null) {
            e.style.width = posw + 'px';
            e.style.height = posh + 'px';
        }
        var obj = $PEC(frameId);
        if (obj != null) {
            var topArea = $PEC(elementId);
            if (topArea != null) {
                obj.width = posw - 4;
                obj.height = posh - topArea.offsetHeight - 4;
            }
            else {
                obj.width = posw - 2;
                obj.height = posh - 2;
            }
        }
    }
}
function _onResizeContainerFrame(sender, eventArgs, frameId, elementId, poswId, poshId) {
    var e = sender.get_element();
    if ((sender._MinimumHeight != 0) && (sender._MinimumWidth != 0)) {
        if (e.parentNode.style.display != 'none') {
            sender._handle.style.left = (sender._MinimumWidth + sender._HandleOffsetX - 10) + 'px';
            sender._handle.style.top = (sender._MinimumHeight + sender._HandleOffsetY - 10) + 'px';
            sender._MinimumHeight = 0;
            sender._MinimumWidth = 0;
        }
    }
    var obj = $PEC(frameId);
    if (obj != null) {
        var topArea = $PEC(elementId);
        if (topArea != null) {
            obj.width = e.offsetWidth - 4;
            obj.height = e.offsetHeight - topArea.offsetHeight - 4;
        }
        else {
            obj.width = e.offsetWidth - 2;
            obj.height = e.offsetHeight - 2;
        }
        var posW = $PEC(poswId);
        if (posW != null) posW.value = e.offsetWidth;
        var posH = $PEC(poshId);
        if (posH != null) posH.value = e.offsetHeight;
    }
}
function _onMoveContainerFrame(sender,eventArgs,posxId,posyId) {
    var elem = sender.get_element();
    var loc = $common.getLocation(elem);

    var posX = $PEC(posxId);
    if (posX != null) {
        posX.value = loc.x;
    }
    var posY = $PEC(posyId);
    if (posY != null) {
        posY.value = loc.y;
    }
}
function tcActiveTabChanged(sender, e) {
    var btns = sender._tabs[sender.get_activeTabIndex()]._element.getElementsByTagName('input');
    if (btns.length > 0) {
        if (btns[0].className == '__lazyloader') {
            __doPostBack(btns[0].name, '');
        }
    }
}
function _gvDelWhatPrompt(what) {
    if (confirm('Are you sure you want to delete this ' + what + '?') == false) return false;
}
function _gvDenyWhatPrompt(what) {
    alert('You can not remove ' + what + '!');
    return false;
}
function gvDenyPrompt() {
    return _gvDenyWhatPrompt('this item');
}
function gvDelPrompt() {
    return _gvDelWhatPrompt('item');
}
function FilterSubmit(tbid, hfid, lbid, pid) {
    var tb = $PEC(tbid);
    var hf = $PEC(hfid);
    var lb = $PEC(lbid);
    var p = $PEC(pid);

    tb.value = "";
    for (i = 0; i < lb.length; i++) {
        if (lb.options[i].selected == true) {
            if (tb.value == "") {
                tb.value = lb.options[i].text;
                if (hf != null) {
                    hf.value = lb.options[i].value;
                }
            }
            else {
                tb.value = tb.value + ", " + lb.options[i].text;
                if (hf != null) {
                    hf.value = hf.value + ";" + lb.options[i].value;
                }
            }
        }
    }
    p.style.display = 'none';
    return false;
}
function doDynamicResize(tb) {
    if (tb.style.height != (tb.scrollHeight + 15) + 'px') {
        tb.style.height = (tb.scrollHeight + 15) + 'px';
    }
}
function tbClassStartTimeValueChanged(startId, endId, delta) {
    var startTime = new String($PEC(startId).value)
    if ((startTime.length == 5) && (delta > 0)) {
        var _subHour = startTime.substr(0, 2);

        if (_subHour[0] == '0') {
            _subHour = _subHour.substr(1, 1);
        }

        var hour = parseInt(_subHour);

        if ((hour + delta) >= 24) {
            hour = hour - (24 - delta);
        }
        else {
            hour = hour + delta;
        }
        $PEC(endId).innerText = hour.toString() + ':' + startTime.substr(3, 2);
    }
    else {
        $PEC(endId).innerText = '';
    }
}
function tbClassLengthValue(lengthId) {
    try {
        var classLength = parseInt($PEC(lengthId).value);
        return classLength;
    }
    catch (e) {
        return 0;
    }
}
/* These functions deal with IE's retardedness in not allowing divs to 
* cover select elements by replacing the select elements with spans. */
function RemoveSelectSpans() {
    var selects = document.getElementsByTagName('select');

    for (var i = 0; i < selects.length; i++) {
        var select = selects[i];

        if (select.clientWidth == 0 || select.clientHeight == 0 ||
			select.nextSibling == null || select.nextSibling.className != 'selectReplacement') {
            continue;
        }

        select.parentNode.removeChild(select.nextSibling);
        select.style.display = select.cachedDisplay;
    }
}
function ReplaceSelectsWithSpans() {
    var selects = document.getElementsByTagName('select');

    for (var i = 0; i < selects.length; i++) {
        var select = selects[i];

        if (select.clientWidth == 0 || select.clientHeight == 0 ||
			select.nextSibling == null || select.nextSibling.className == 'selectReplacement') {
            continue;
        }

        var span = document.createElement('span');

        // this would be "- 3", but for that appears to shift the block that contains the span 
        //   one pixel down; instead we tolerate the span being 1px shorter than the select
        span.style.height = (select.clientHeight - 4) + 'px';
        span.style.width = (select.clientWidth - 6) + 'px';
        span.style.display = 'inline-block';
        span.style.border = '1px solid rgb(200, 210, 230)';
        span.style.padding = '1px 0 0 4px';
        span.style.fontFamily = 'Arial';
        span.style.fontSize = 'smaller';
        span.style.position = 'relative';
        span.style.top = '1px';
        span.className = 'selectReplacement';

        span.innerHTML = select.options[select.selectedIndex].innerHTML +
			'<img src="custom_drop.gif" alt="drop down" style="position: absolute; right: 1px; top: 1px;" />';

        select.cachedDisplay = select.style.display;
        select.style.display = 'none';
        select.parentNode.insertBefore(span, select.nextSibling);
    }
}
var _currentModalPopup = null;
function _onWindowCenter() {
    // we only need to move the dialog based on scroll position if
    //   we're using a browser that doesn't support position: fixed, like < IE 7
    var left = window.XMLHttpRequest == null ? document.documentElement.scrollLeft : 0;
    var top = window.XMLHttpRequest == null ? document.documentElement.scrollTop : 0;
    if (_currentModalPopup != null) {
        _currentModalPopup.style.left = Math.max((left + (GetWindowWidth() - _currentModalPopup.offsetWidth) / 2), 0) + 'px';
        _currentModalPopup.style.top = Math.max((top + (GetWindowHeight() - _currentModalPopup.offsetHeight) / 2), 0) + 'px';

        _currentModalPopup.scrollOffset = { x: document.documentElement.scrollLeft, y: document.documentElement.scrollTop };
        _currentModalPopup.isPinned = false;
    }
}
function _onWindowResize() {
    if (_currentModalPopup != null) {
        var left = document.documentElement.scrollLeft;
        var top = document.documentElement.scrollTop;
        if (!_currentModalPopup.isPinned) {
            var pos = getPosition(_currentModalPopup);

            _currentModalPopup.style.left = pos.x + (_currentModalPopup.scrollOffset.x - left) + 'px';
            _currentModalPopup.style.top = pos.y + (_currentModalPopup.scrollOffset.y - top) + 'px';
        }
        _currentModalPopup.scrollOffset.x = left;
        _currentModalPopup.scrollOffset.y = top;
    }
}
var dragObject = null;
function mouseCoords(ev) {
    if (ev.pageX || ev.pageY) {
        return { x: ev.pageX, y: ev.pageY };
    }
    return {
        x: ev.clientX + document.body.scrollLeft - document.body.clientLeft,
        y: ev.clientY + document.body.scrollTop - document.body.clientTop
    };
}
function getMouseOffset(target, ev) {
    ev = ev || window.event;

    var docPos = getPosition(target);
    var mousePos = mouseCoords(ev);
    return { x: mousePos.x - docPos.x, y: mousePos.y - docPos.y };
}
function getPosition(e) {
    var left = 0;
    var top = 0;

    while (e.offsetParent) {
        left += e.offsetLeft;
        top += e.offsetTop;
        e = e.offsetParent;
    }

    left += e.offsetLeft;
    top += e.offsetTop;

    return { x: left, y: top };
}
function mouseMove(ev) {
    if (dragObject) {
        ev = ev || window.event;
        var mousePos = mouseCoords(ev);
        
        dragObject.style.position = 'fixed';
        dragObject.style.top = mousePos.y - dragObject.mouseOffset.y;
        dragObject.style.left = mousePos.x - dragObject.mouseOffset.x;

        return false;
    }
}
function mouseUp() {
    dragObject = null;
    document.onmousemove = null;
    document.onmouseup = null;
}
function modalPopupKeyDown() {
    if ((_currentModalPopup != null) && (event.keyCode == 27)) {
        _hideModalPopup(_currentModalPopup);
    }
}
function _ensureModalDragHandle() {
    if (_currentModalPopup != null) {
        makeDraggable($PEC(_currentModalPopup.DragHandleID));
    }
}
function makeDraggable(dragHandle) {
    if (!dragHandle) return;
    dragHandle.onmousedown = function (ev) {
        dragObject = _currentModalPopup;
        if (dragObject != null) {
            document.onmousemove = mouseMove;
            document.onmouseup = mouseUp;

            // !: Positioning metrics
            dragObject.mouseOffset = getMouseOffset(dragObject, ev);
        }
        return false;
    }
}
function ShowModalPopup(popupCtrlId, dragHandleId, backgroundCtrlId) {
    if (_currentModalPopup == null) {
        // Try to show it as soon as possible
        _showModalPopup($PEC(popupCtrlId), $PEC(dragHandleId), $PEC(backgroundCtrlId));
        if ((_currentModalPopup == null) && (PageFullyLoaded != true)) {
            var fn = function() {
                ShowModalPopup(popupCtrlId, dragHandleId, backgroundCtrlId);
            }
            window.setTimeout(fn, 100);
        }
    }
    else if (_currentModalPopup != $PEC(popupCtrlId)) {
        // Wait for the current popup to close
        _stackModalPopup(_currentModalPopup);
        var fn = function() {
            ShowModalPopup(popupCtrlId, dragHandleId, backgroundCtrlId);
        }
        window.setTimeout(fn, 100);        
    }
}
function _showModalPopup(popupCtrl, dragHandleCtrl, backgroundCtrl) {
    _currentModalPopup = popupCtrl;
    if ((popupCtrl != null) && (backgroundCtrl != null)) {
        popupCtrl.style.display = backgroundCtrl.style.display = 'block';
        if (PageFullyLoaded == true) makeDraggable(dragHandleCtrl);
        popupCtrl.DragHandleID = (dragHandleCtrl) ? dragHandleCtrl.id : '';
        popupCtrl.modalBackground = backgroundCtrl;
        
        // special < IE7 -only processing for windowed elements, like select	
        if (window.XMLHttpRequest == null) {
            ReplaceSelectsWithSpans();
        }
        // call once to center everything
        _onWindowCenter();

        if (window.attachEvent)
            window.attachEvent('onresize', _onWindowResize);
        else if (window.addEventListener)
            window.addEventListener('resize', _onWindowResize, false);
        else
            window.onresize = _onWindowResize;

        // we won't bother with using javascript in CSS to take care
        //   keeping the window centered
        if (document.all) {
            //if (document.documentElement.attachEvent)
            //    document.documentElement.attachEvent('onscroll', _onWindowResize);
            //else if (document.documentElement.addEventListener)
            //    document.documentElement.addEventListener('scroll', _onWindowResize, false); 
            //else
                document.documentElement.onscroll = _onWindowResize;
        }
        if (document.body) {
            if (document.body.attachEvent)
                document.body.attachEvent('onkeydown', modalPopupKeyDown);
            else if (document.body.addEventListener)
                document.body.addEventListener('keydown', modalPopupKeyDown, false);
            else
                document.body.onkeydown = modalPopupKeyDown;
        }
        return;
    }
    _currentModalPopup = null;
}
function ModalPopupPinToggleClick(sender, pinned, unpinned) {
    if (_currentModalPopup != null) {
        if (_currentModalPopup.isPinned) {
            sender.src = unpinned;
            _currentModalPopup.isPinned = false;
        }
        else {
            sender.src = pinned;
            _currentModalPopup.isPinned = true;
        }
    }
}
function HideModalPopup(popupCtrlId) {
    if (PageFullyLoaded == true) {
        _hideModalPopup($PEC(popupCtrlId));
    }
    else {
        var fn = function() {
            HideModalPopup(popupCtrlId);
        }
        window.setTimeout(fn, 100);
        return;
    }
}
function _detachModalPopup(popupCtrl) {
    if (popupCtrl != null) {
        popupCtrl.style.display = popupCtrl.modalBackground.style.display = 'none';
        if (popupCtrl == _currentModalPopup) {
            // special IE-only processing for windowed elements, like select	
            if (document.all) {
                RemoveSelectSpans();
            }
            if (window.detachEvent)
                window.detachEvent('onresize', _onWindowResize);
            else if (window.removeEventListener)
                window.removeEventListener('resize', _onWindowResize, false);
            else
                window.onresize = null;

            if (document.all) {
                //if (document.documentElement.detachEvent)
                //    document.documentElement.detachEvent('onscroll', _onWindowResize);
                //else if (document.documentElement.removeEventListener)
                //    document.documentElement.removeEventListener('scroll', _onWindowResize, false);
                //else
                document.documentElement.onscroll = null;
            }
            if (document.body) {
                if (document.body.detachEvent)
                    document.body.detachEvent('onkeydown', modalPopupKeyDown);
                else if (document.body.removeEventListener)
                    document.body.removeEventListener('keydown', modalPopupKeyDown, false);
                else
                    document.body.onkeydown = null;
            }
        }
    }
}
function _hideModalPopup(popupCtrl) {
    // Disconnect the popup from the page handlers
    _detachModalPopup(popupCtrl);
    // ShowPopup takes precedence, so we could have already set this to the new active popup...
    if (_currentModalPopup == popupCtrl) {
        _currentModalPopup = null;
    }
    // Do we have a nested popup that is not the popup we just closed?
    if (_popupStack.length > 0) {
        var popPopup = _popupStack.pop();
        if (popPopup != popupCtrl) {
            ShowModalPopup(popPopup.id, popPopup.DragHandleID, popPopup.modalBackground.id);
        }
    }
}
var _popupStack = new Array();
function _stackModalPopup(popupCtrl) {
    // Disconnect the popup from the page handlers
    _detachModalPopup(popupCtrl);
    // ShowPopup takes precedence, so we could have already set this to the new active popup...
    if (_currentModalPopup == popupCtrl) {
        _popupStack.push(popupCtrl);
        _currentModalPopup = null;
    }
}
function setSendEmailPopup(errorMsgId, sendToCtrlId, emailAddress, subjectCtrlId, messageCtrlId) {
    var errMsg = $PEC(errorMsgId);
    if (errMsg != null) {
        errMsg.className = errMsg.className.substring(0, errMsg.className.indexOf('_')) + '_Empty';
    }
    var sendToCtrl = $PEC(sendToCtrlId);
    if (sendToCtrl != null) {
        sendToCtrl.value = emailAddress;
    }
    var subjectCtrl = $PEC(subjectCtrlId);
    if (subjectCtrl != null) {
        subjectCtrl.value = '';
        subjectCtrl.style.backgroundColor = 'white';
    }
    var messageCtrl = $PEC(messageCtrlId);
    if (messageCtrl != null) {
        messageCtrl.value = '';
        messageCtrl.style.backgroundColor = 'white';
    }
}
function _clearAsyncUploader(aul) {
    if (aul != null) {
        var orig = aul.get_inputFile();
        if (orig != null) {
            var clone = orig.cloneNode(false);
            if (clone != null) {
                clone.style.backgroundColor = "white";
                aul.set_inputFile(clone);
            }
            orig.parentNode.replaceChild(clone, orig);
            orig = null;
        }
    }  
}
function asyncUploadStarted(sender, args) {
}
function asyncUploadCompleted(sender, args) {
    if (_currentModalPopup != null) {
        _hideModalPopup(_currentModalPopup);
    }
    _clearAsyncUploader(sender);
    alert('File uploaded successfully!');
}
function asyncUploadError(sender, args) {
    if (_currentModalPopup != null) {
        _hideModalPopup(_currentModalPopup);
    }
    _clearAsyncUploader(sender);
    alert(args.get_errorMessage());
}
function checkCapsLock(sender, e) {
    var keyCode = 0;
    var shiftKey = false;
    // Internet Explorer 4+
    if (document.all) {
        keyCode = e.keyCode;
        shiftKey = e.shiftKey;
        // Netscape 4
    } else if (document.layers) {
        keyCode = e.which;
        shiftKey = (keyCode == 16) ? true : false;
        // Netscape 6
    } else if (document.getElementById) {
        keyCode = e.which;
        shiftKey = e.shiftKey ? e.shiftKey : ((keyCode == 16) ? true : false); // Makes it work in firefox
    }
    // Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
    if ((keyCode >= 65 && keyCode <= 90) && !shiftKey) {
        return true;

        // Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
    } else if ((keyCode >= 97 && keyCode <= 122) && shiftKey) {
        return true;
    }
        // Upper case letters are seen while depressing the Shift key, therefore Caps Lock is off
    else if ((keyCode >= 65 && keyCode <= 90) && !shiftKey) {
        return false;

        // Lower case letters are seen while not depressing the Shift key, therefore Caps Lock is off
    } else if ((keyCode >= 97 && keyCode <= 122) && !shiftKey) {
        return false;
    }
    if (typeof sender.capsLocked == 'undefined') return false;
    return sender.capsLocked;
}
function _toggleHeader(collapserId) {
    var collPanel = $find(collapserId);
    if (collPanel != null) {
        if (collPanel.get_Collapsed())
            collPanel.set_Collapsed(false);
        else
            collPanel.set_Collapsed(true);
    }
    return false;
}
// Move an element directly on top of another element (and optionally
// make it the same size)
function Cover(bottom, top, ignoreSize) {
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}
// !: Cascading DropDownList Support for the Class Log
function ResetCascadingDropDown(extender, value) {
    if (extender != null) {
        extender._selectedValue = value;
    }
}
function PopulateObservationText(classDDL, participantDDL, subCategoryDDL, observationTB) {
    if (classDDL != null) {
        var classId = parseInt(classDDL._selectedValue);
        if (participantDDL != null) {
            var participantName = participantDDL._selectedValue;
            var obj = $PEC(subCategoryDDL);
            if (obj != null) {
                var subCategoryText = obj.options[obj.selectedIndex].text;
                Webservices.Dashboards.Logger.Service.PopulateObservation(classId, participantName, subCategoryText, observationTB, poCallbackHandler, poErrorHandler, poTimeoutHandler);
            }
        }
    }
}
function poCallbackHandler(strResponse) {
    var targetObj = $PEC(strResponse[0]);
    if (targetObj != null) {
        if (targetObj.value != "") {
            targetObj.value += "\r";
        }
        targetObj.value += strResponse[1];
    }
}
function poErrorHandler() {
}
function poTimeoutHandler() {
}
try {
    if (typeof Sys == 'undefined') {
        ;
    }
    else {
        if (Sys && Sys.Application) {
            Sys.Application.notifyScriptLoaded();
        }
    }
}
catch (e) {
    ;
}
