﻿// xtreeView JScript File

var ie5 = document.all&&document.getElementById;
var ns6 = document.getElementById&&!document.all;
//var menuobj = null;
//alert(ie5);
if (ie5||ns6)
{
   var menuobj = null;
}


function showmenuie5(e, NodeName, NodeLevel, NodeId, NodeType, ChildNodeCountLocation, parentid, 
                     ChildNodeCountCinema, Role, RoleID, CompanyID)
{
       //alert(NodeId);
       hidemenuie5(e);
       switch(NodeType)
            {
                case "Root":
                    if(Role == "Super Admin")
                    {
                        menuobj = document.getElementById("PanelRootMenuLocation");
                    }
                    else
                    {
                        menuobj = document.getElementById("PanelMsg");
                    }
                    break;
                    
                case "Location":
                    if(Role == "Super Admin")
                    {
                        if(ChildNodeCountLocation == 0 && ChildNodeCountCinema == 0 
                           && NodeLevel == "Parent" && NodeType != "" && NodeType == "Location")
                        {
                            menuobj = document.getElementById("PanelParentMenuLocation_1");
                        }
                        else if(ChildNodeCountLocation != 0 && ChildNodeCountCinema == 0 
                           && NodeLevel == "Parent" && NodeType != "" && NodeType == "Location")
                        {
                            menuobj = document.getElementById("PanelParentMenuLocation_2");
                        }                        
                        else if(ChildNodeCountLocation == 0 && ChildNodeCountCinema == 0 
                           && NodeLevel == "Child" && NodeType != "" && NodeType == "Location")
                        {
                            menuobj = document.getElementById("PanelParentMenuLocation_3");
                        }
                        else if(ChildNodeCountLocation == 0 && ChildNodeCountCinema != 0 
                           && NodeLevel == "Child" && NodeType != "" && NodeType == "Location")
                        {
                            menuobj = document.getElementById("PanelParentMenuLocation_4");
                        }
                    }
                   else if(Role == "Company Admin" && ChildNodeCountLocation == 0 
                       && NodeLevel == "Child" && NodeType == "Location")
                     {
                         menuobj = document.getElementById("PanelParentMenuLocation_5");
                     }
                   else
                    {
                        menuobj = document.getElementById("PanelMsg");
                    }  
                    break;
                        
                case "Cinema":
                    if(Role == "Super Admin" && NodeLevel == "CinemaParent" && NodeType != "" 
                        && NodeType == "Cinema")
                     {
                         menuobj = document.getElementById("PanelRootMenuCinema_1");
                     }
                     else if(Role == "Company Admin" && NodeLevel == "CinemaParent" && NodeType != "" 
                             && NodeType == "Cinema")
                     {
                        menuobj = document.getElementById("PanelRootMenuCinema_1");
                     }
                     else
                     {
                        menuobj = document.getElementById("PanelRootMenuCinema_2");
                     }
                    break;
            }
    
    if(menuobj)
    {
        var ALlDiv = menuobj.getElementsByTagName('a');
        var EventMode = '';
        for(var i = 0; i < ALlDiv.length; i++)
        {
            EventMode = ALlDiv[i].getAttribute('EventMode');
            if(EventMode)
            {
                //alert(EventMode);
                switch(EventMode)
                {
                    case "AddLocation":
                        //ALlDiv[i].href="/Limata/Location/Location.aspx?Action=AddLocation&LocationId="+ NodeId +"&Parentid="+ parentid +"&Role="+ Role +"&RoleID="+ RoleID +"&CompanyID="+ CompanyID +"";
                        ALlDiv[i].href="../Location/Location.aspx?Action=AddLocation&LocationId="+ NodeId +"&Parentid="+ parentid +"&Role="+ Role +"&RoleID="+ RoleID +"&CompanyID="+ CompanyID +"";
                        break;                        
                    case "AddSubLocation":
                        //ALlDiv[i].href="/Limata/Location/Location.aspx?Action=AddSubLocation&LocationId="+ NodeId +"&Parentid="+ parentid +"&LocationName="+ NodeName +"&Role="+ Role +"&RoleID="+ RoleID +"&CompanyID="+ CompanyID +"";
                        ALlDiv[i].href="../Location/Location.aspx?Action=AddSubLocation&LocationId="+ NodeId +"&Parentid="+ parentid +"&LocationName="+ NodeName +"&Role="+ Role +"&RoleID="+ RoleID +"&CompanyID="+ CompanyID +"";
                        break;
                    case "EditLocation":
                        //ALlDiv[i].href="/Limata/Location/Location.aspx?Action=EditLocation&LocationId="+ NodeId +"&Parentid="+ parentid +"&LocationName="+ NodeName +"&Role="+ Role +"&RoleID="+ RoleID +"&CompanyID="+ CompanyID +"";
                        ALlDiv[i].href="../Location/Location.aspx?Action=EditLocation&LocationId="+ NodeId +"&Parentid="+ parentid +"&LocationName="+ NodeName +"&Role="+ Role +"&RoleID="+ RoleID +"&CompanyID="+ CompanyID +"";
                        break;
                    case "DeleteLocation":
                        //ALlDiv[i].href="/Limata/Location/Location.aspx?Action=DeleteLocation&LocationId="+ NodeId +"&Parentid="+ parentid +"&LocationName="+ NodeName +"&Role="+ Role +"&RoleID="+ RoleID +"&CompanyID="+ CompanyID +"";
                        ALlDiv[i].href="../Location/Location.aspx?Action=DeleteLocation&LocationId="+ NodeId +"&Parentid="+ parentid +"&LocationName="+ NodeName +"&Role="+ Role +"&RoleID="+ RoleID +"&CompanyID="+ CompanyID +"";
                        break;
                        
                    case "AddCinema":
                         //ALlDiv[i].href="/Limata/Cinema/Cinema.aspx?Action=AddCinema&LocationId="+ NodeId +"&Parentid="+ parentid +"&LocationName="+ NodeName +"&Role="+ Role +"&RoleID="+ RoleID +"&CompanyID="+ CompanyID +"";
                         ALlDiv[i].href="../Cinema/Cinema.aspx?Action=AddCinema&LocationId="+ NodeId +"&Parentid="+ parentid +"&LocationName="+ NodeName +"&Role="+ Role +"&RoleID="+ RoleID +"&CompanyID="+ CompanyID +"";
                        break;                                                                                            
                    case "EditCinema":
                         //ALlDiv[i].href="/Limata/Cinema/Cinema.aspx?Action=EditCinema&CinemaId="+ NodeId +"&Locationid="+ parentid +"&CinemaName="+ NodeName +"&Role="+ Role +"&RoleID="+ RoleID +"&CompanyID="+ CompanyID +"";
                         ALlDiv[i].href="../Cinema/Cinema.aspx?Action=EditCinema&CinemaId="+ NodeId +"&Locationid="+ parentid +"&CinemaName="+ NodeName +"&Role="+ Role +"&RoleID="+ RoleID +"&CompanyID="+ CompanyID +"";
                        break;
                                                    
                    case "CreateShows":
                         //ALlDiv[i].href="/Limata/Cinema/ShowDetails.aspx?Action=CreateShows&CinemaId="+ NodeId +"&Locationid="+ parentid +"&CinemaName="+ NodeName +"&Role="+ Role +"&RoleID="+ RoleID +"&CompanyID="+ CompanyID +"";
                         ALlDiv[i].href="../Cinema/ShowDetails.aspx?Action=CreateShows&CinemaId="+ NodeId +"&Locationid="+ parentid +"&CinemaName="+ NodeName +"&Role="+ Role +"&RoleID="+ RoleID +"&CompanyID="+ CompanyID +"";
                        break;
                    
                    case "CreateScreen":
                         //ALlDiv[i].href="/Limata/Cinema/Auditorium.aspx";
                         ALlDiv[i].href="../Cinema/Auditorium.aspx?cid="+ NodeId +"";
                        break;
                                                
                    default:
                        alert("Didn't fall in any Node Type");
                        break;
                }
            }
        }
    }
    
    //Find out how close the mouse is to the corner of the window
    var rightedge  = ie5? document.body.clientWidth-event.clientX : window.innerWidth-e.clientX;
    var bottomedge = ie5? document.body.clientHeight-event.clientY : window.innerHeight-e.clientY;
    
    //alert("rightedge : "+ rightedge +"     bottomedge : "+ bottomedge +"");

    //if the horizontal distance isn't enough to accomodate the width of the context menu
    if (rightedge<menuobj.offsetWidth)
    {
        //move the horizontal position of the menu to the left by it's width
        menuobj.style.left=ie5? document.body.scrollLeft+event.clientX-menuobj.offsetWidth : window.pageXOffset+e.clientX-menuobj.offsetWidth;
    }    
    else
    {
        //position the horizontal position of the menu where the mouse was clicked
        menuobj.style.left=ie5? document.body.scrollLeft+event.clientX - 100 : window.pageXOffset+e.clientX
    }

    //same concept with the vertical position
    if (bottomedge<menuobj.offsetHeight)
    {
        menuobj.style.top=ie5? document.body.scrollTop+event.clientY-menuobj.offsetHeight : window.pageYOffset+e.clientY-menuobj.offsetHeight;
    }    
    else
    {
        menuobj.style.top=ie5? document.body.scrollTop+event.clientY - 130 : window.pageYOffset+e.clientY;
    }

    if(ie5)
    {
        window.event.cancelBubble = true;
    }
    else if(ns6)
    {
        e.stopPropagation();
    }
    menuobj.style.visibility = "visible";
    return false;
}

function hidemenuie5(e)
{
    if(menuobj)
        menuobj.style.visibility="hidden";
}

function highlightie5(e)
{
    var firingobj=ie5? event.srcElement : e.target
    if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems")
    {
        if (ns6&&firingobj.parentNode.className=="menuitems")
        { 
            firingobj=firingobj.parentNode; //up one node
        }    

        firingobj.style.backgroundColor="white";//highlight
    }
}

function lowlightie5(e)
{
    var firingobj=ie5? event.srcElement : e.target
    if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems")
    {
        if (ns6&&firingobj.parentNode.className=="menuitems") 
        {
            firingobj=firingobj.parentNode; //up one node
        }    

        firingobj.style.backgroundColor="";
        window.status='';
    }
}

function jumptoie5(e)
{
    //alert("hi...");   
    var firingobj = ie5? event.srcElement : e.target
    if (firingobj.className == "menuitems"||ns6&&firingobj.parentNode.className == "menuitems")
    {
        if (ns6&&firingobj.parentNode.className == "menuitems") 
        {
            var firingobj2 = firingobj.parentNode;
            // the click can be controlled by firingobj
            // if the click was generated by the div tag enclosing the link buttons
            //then the value of firingobj=htmlDivElement el
            // else if the click was generated by the linkbutton
            // then the value of firingobj will be href of the link button and the value of firingobj2 will be htmlDivElement
            // the code for controlling the clciks goes here
        }
    }
}

if (ie5||ns6)
{
    //menuobj.style.display = ''
    document.onclick = hidemenuie5;
    //document.onmouseout = hidemenuie5
}
