// Finds the clicked row in a RadGrid, which is then used to display a RadMenu
//function CustomRowContextMenu(sender, eventArgs, radmenu, hidden_input)
//{
//    var menu = $find(radmenu);
//    var evt = eventArgs.get_domEvent();                  
//    
//    var index = eventArgs.get_itemIndexHierarchical();
//    document.getElementById(hidden_input).value = index;
//    
//    sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);
//    
//    menu.show(evt);
//    
//    evt.cancelBubble = true;
//    evt.returnValue = false;

//    if (evt.stopPropagation)
//    {
//       evt.stopPropagation();
//       evt.preventDefault();
//    }
//}

function Invoke_Parent_Close_ModalPopupExtender(action) {
    parent.Close_ModalPopupExtender(action);
}

//finds the Y position of the passed object
function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent)
        while (1) {
        curtop += obj.offsetTop;
        if (!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}

//sets the height and position of the Edit Panel
function adjustEditPanelHeight_helper(newheight, editpanelid, iframeid) {
    var editpanel = window.document.getElementById(editpanelid);
    var iframe = document.getElementById(iframeid);
    editpanel.style.height = newheight;
    iframe.style.height = newheight;
    //alert(document.height + ' ' + document.body.offsetHeight);
    //var docHeight = (document.height !== undefined) ? document.height : document.body.offsetHeight;
    //var docHeight = window.innerHeight;
    var docHeight = document.documentElement.clientHeight;    
    var temp = (docHeight / 2) - (parseInt(newheight) / 2) + 'px';
    editpanel.style.top = temp;
}

// Returns the number of selected rows of a RadGrid
function RadGridSelectedRowCount(RadGrid) {
    var grid = $find(RadGrid);
    var MasterTable = grid.get_masterTableView();
    var selectedRows = MasterTable.get_selectedItems();
    return selectedRows.length;
}

// Stops the RadComboBox from opening when there are no items in it
function RadComboBox_OnClientDropDownOpening(sender, eventArgs) {
    items = sender.get_items();
    if (items.get_count() == 0)
        eventArgs.set_cancel(true);
}

function randomString(string_length) {
    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";    
    var randomstring = '';
    for (var i = 0; i < string_length; i++) {
        var rnum = Math.floor(Math.random() * chars.length);
        randomstring += chars.substring(rnum, rnum + 1);
    }
    return randomstring;
}

function disableBackButton() {
    var back_btn = document.getElementById('history_back');
    if (!back_btn) return;
    back_btn.setAttribute('class', 'backbutton_disabled');
    back_btn.onclick = function() { return false; };    
}

function enableBackButton() {
    var back_btn = document.getElementById('history_back');
    if (!back_btn) return;
    if (back_btn.href != '#') {
            back_btn.setAttribute('class', 'backbutton');
            back_btn.onclick = null;
        }
}
