﻿// JScript File
function HideAllSubMenus()
{
   var allDivs = document.getElementById('UserMenu1_hdnAllSubMenus').value.split('|');
   var tempControl;
   for (var i = 0; i < allDivs.length - 1; i++)
   {
        document.getElementById(allDivs[i]).style.visibility = "hidden";
   }
}
function OpenWindow(url)
{
    //alert('Found : ' + url);
    window.open(url, '_self');
}

function OpenSubMenu(control,menuId)
{
    //alert('Found');
   //alert(menuId);
   var allDivs = document.getElementById('UserMenu1_hdnAllSubMenus').value.split('|');
   var tempControl;
   for (var i = 0; i < allDivs.length - 1; i++)
   {
        document.getElementById(allDivs[i]).style.visibility = "hidden";
   }
    
    var strId='';
    var preId;
    var addWidth, addHeigth;
    var displaySubMenu = menuId.split('_');
    ////alert(menuId);
    for (var i = 0; i < displaySubMenu.length; i++)
    {                
        preId =  strId;
        if(i==0)       
            strId = displaySubMenu[i];
        else
            strId = strId + '_' + displaySubMenu[i];
        //alert(strId);                
////////                alert(1);
        //document.getElementById(strId).style.display = "";
        if(i==0)
        {
            //alert(2);
            
            tempControl = document.getElementById('Main_' + strId);
            //addHeigth = document.getElementById(strId).offsetHeight;
            addHeigth = 18;
            if(document.getElementById(strId) != null)
            {
                //salert(strId);
                var tempControl2 = document.getElementById('Main_' + strId);
                if( parseInt(tempControl2.offsetWidth) > parseInt(document.getElementById(strId).offsetWidth))
                    document.getElementById(strId).style.width = tempControl2.offsetWidth + 'px';
                //alert(tempControl.offsetWidth);
                document.getElementById(strId).style.visibility = 'visible';
                document.getElementById(strId).style.top = parseInt(getY(tempControl)) + parseInt(addHeigth) + 'px';
                if(window.screen.availWidth <= 1024)
                    document.getElementById(strId).style.left = getX(tempControl) - 35 + 'px';
                else
                    document.getElementById(strId).style.left = getX(tempControl) - 160 + 'px';
                //alert(window.screen.availWidth);
            }
        }
        else
        {   
            //alert(2);
            if(document.getElementById(strId) != null)
            {
                //alert(3);
                tempControl = document.getElementById('parent_' + strId);
                //alert('Id : ' + strId);
                addWidth = document.getElementById(preId).offsetWidth;
                //alert(document.getElementById(preId).offsetWidth);
                document.getElementById(strId).style.visibility = 'visible';
                document.getElementById(strId).style.top = parseInt(getY(tempControl)) - 9 + 'px';                        
                //if(parseInt((getX(tempControl)) + 2*parseInt(addWidth)) > parseInt(screen.availWidth) )
                //    addWidth = -181;
                document.getElementById(strId).style.left = parseInt(getX(tempControl)) - 42 + parseInt(addWidth) - 5 + 'px';
            }
        }

    }
    ////alert('Done');
}

function getX(obj)
{
   return( obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft+getX(obj.offsetParent) );
}

function getY(obj)
{
   return( obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+getY(obj.offsetParent) );
}

