
function CloseWindow(refresh)
{
    if(refresh)
    { 
        ReloadParent();
    }
    window.close();
}

function ReloadParent()
{
    var parent = window.opener;
    if (parent != null)
    {
        var btnRefresh = parent.document.getElementById("btnRefresh");

        if (btnRefresh != null)
        {
            btnRefresh.click();
        }
    }
}

//function GridViewExtenderMouseOver1(row)
//{
//    row.cells[0].style.borderColor = "red";
//}

//function GridViewExtenderMouseOut1(row)
//{
//    alert("Out");
//}

function CollapseMenu(rowIndex, link)
{
    if (link.firstChild.src != null)
    {
        link.firstChild.src = "./images/pointer_close.gif";
    }
    
    var tblMenu = document.getElementById("tblMenu");
    
    link.onclick = function anonymous(){return ExpandMenu(rowIndex, link)};    
    
    var customRowIndex = rowIndex + 1;

    while (customRowIndex < tblMenu.rows.length)
    {
        if (tblMenu.rows[customRowIndex].cells[0].className != "menu_subelement")
        {
            break;
        }
        tblMenu.rows[customRowIndex].style.display = "none";
        customRowIndex++;
    }
}

function ExpandMenu(rowIndex, link)
{
    if (link.firstChild.src != null)
    {
        link.firstChild.src = "./images/pointer_open.gif";
    }
    
    var tblMenu = document.getElementById("tblMenu");
    
    link.onclick = function anonymous(){return CollapseMenu(rowIndex, link)};    
    
    var customRowIndex = rowIndex + 1;
    
    while (customRowIndex < tblMenu.rows.length)
    {
        if (tblMenu.rows[customRowIndex].cells[0].className != "menu_subelement")
        {
            break;
        }
        tblMenu.rows[customRowIndex].style.display = "";
        customRowIndex++;
    }
}

function popupWindow(url, width, height) 
{
    var top, left;

    if (navigator.appName.indexOf("Microsoft")!=-1)
    {
        top = window.screenTop;
        left = window.screenLeft;
             
//        alert("top = " + top);                   
//        alert("left = " + left);                   
//        alert("document.documentElement.offsetHeight = " + document.documentElement.offsetHeight);                   
//        alert("document.documentElement.offsetWidth = " + document.documentElement.offsetWidth);                   
        if (document.documentElement.offsetHeight > height)
        {
            top = top + (document.documentElement.offsetHeight - height) / 2;
        }
                
        if (document.documentElement.offsetWidth > width)
        {
            left = left + (document.documentElement.offsetWidth - width) / 2;
        }        
    }
    else
    {        
        top = window.screenY;
        left = window.screenX; 
        
        if (window.innerHeight > height)
        {
            top = top + (window.innerHeight - height) / 2;
        }
                
        if (window.innerWidth > width)
        {
            left = left + (window.innerWidth - width) / 2;
        }        
    }
            
    // adds for margin
    width = width + 10;
    height = height + 10;
    
    window.open(url,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=' + width + ',height=' + height + ',screenX=' + left + ',screenY=' + top + ',top=' + top + ',left='+ left + '');
}

function HandleFileButtonClick(fileUploaderId, txtFileNameId)
{
    var fileUploader = document.getElementById(fileUploaderId);
    var txtFileName = document.getElementById(txtFileNameId);
    
    txtFileName.value = fileUploader.value;
    
    return false;
}

function ToggleAlertDiv(visString)
{
    if ((disabledScreenElem != null) && (alertDivElem != null))
    {
        $get(disabledScreenElem).style.visibility = visString;
        $get(alertDivElem).style.visibility = visString;
    }
}

function ClearErrorState() 
{
    if (messageElem != null)
    {
        $get(messageElem).innerHTML = '';
    }
    ToggleAlertDiv('hidden');         
}
function ManageProgress(isVisible)
{
    if (progeressDivElem != null)
    {
        if (isVisible == true)
            $get(progeressDivElem).style.display = '';
        else 
            $get(progeressDivElem).style.display = 'none';
    }
    return true;
}

function BeginRequestHandlerWrapper(sender, args)
{
    ManageProgress(true);
} 
function EndRequestHandlerWrapper(sender, args)
{
    ManageProgress(false);

    if (args.get_error() != undefined)
    {
        var errorMessage;
        if (args.get_response().get_statusCode() == '200')
        {
           errorMessage = args.get_error().message;
        }
        else
        {
           // Error occurred somewhere other than the server page.
           errorMessage = 'An unspecified error occurred. ';
        }
        args.set_errorHandled(true);
        if (progeressDivElem != null)
        {
            ToggleAlertDiv('visible');
            $get(messageElem).innerHTML = errorMessage;
        }
    }
}