var VMenuPrefix = 'AirIndiaVMenu1_';
var VSubMenuIDCookie='';
//onload=function()
//    {
//        setVmenuState();
//    }
//img object for changing image of expand collapse
//tblid is the id of table to set visible true false, 
//action is either 'show' or 'hide'

function expandCollapseTbl(imgname, tblID, action )
{
    var tbl = window.document.getElementById( VMenuPrefix + tblID ); 
    var img = window.document.getElementById(imgname);
    
    var setVSubMenuID = VSubMenuIDCookie ; //read cookie
    //var setVSubMenuID = getCookie('selectedVMenuMID') ; //read cookie
    
    var vmenuIds = setVSubMenuID.split(",");
    var incv;
    
//    alert( img.offsetParent.className );
   // if( img.alt == 'click here to collapse' )
   if( img.src == "images/collapse.jpg" )
    {
        alert( img.offsetParent.className );
        img.offsetParent.offsetParent.style.color="#000000";
        img.offsetParent.className = "leafMenuNodeNormal";
        
        img.src = "images/expand.jpg";
        img.alt='click here to expand';
        tbl.style.display='none';
        
        var index= setVSubMenuID.indexOf(tblID.substring(8));
        var tempStr;
        
        if( setVSubMenuID != null && index >=0 ) //it means avaialbel in cookie so remove it
        {
            tempStr= setVSubMenuID.substring(0,index-1);
            setVSubMenuID = tempStr+ setVSubMenuID.substring(index+tblID.substring(8).length,setVSubMenuID.length );
            setVSubMenuID = setVSubMenuID.replace(",,",","); 
            //VSubMenuIDCookie = setVSubMenuID;
        }
    }
    else
    {
        img.src = "images/collapse.jpg";
        img.alt='click here to collapse';
        tbl.style.display='block';
        img.offsetParent.childNodes[0].style.color="#cc0000";
        img.offsetParent.className = "leafMenuNodeSelected";
        //img.offsetParent.childNodes[0].className="vmenuLinkSelected";
        //img.offsetParent.className="vmenuLinkSelected";
        
        if( setVSubMenuID != null && setVSubMenuID.indexOf(tblID.substring(8))<0 ) //it means not in cookie
        {
            setVSubMenuID = setVSubMenuID + ","+ tblID.substring(8) ;
            //VSubMenuIDCookie = setVSubMenuID;
        }
    }
    /*for each expanded VMenuID see is there any VmenuID based on the offset.offsetparent.className then 
    collapse it */
        
    for( incv=1 ; incv < vmenuIds.length ; incv++)
    {
        //alert( img.offsetParent.offsetParent.className );
        var imgtemp = window.document.getElementById("imgVSubMenu"+vmenuIds[incv]);
        if( imgtemp && imgtemp.offsetParent.offsetParent.className==img.offsetParent.offsetParent.className )
        {
            //then collapse tblvmenuIds[incv];
            var temptbl = window.document.getElementById(VMenuPrefix +"VSubMenu" + vmenuIds[incv]); 
            imgtemp.src = "images/expand.jpg";
            imgtemp.alt='click here to expand';
            imgtemp.offsetParent.childNodes[0].style.color="black";
            temptbl.style.display='none';
            
            var index= setVSubMenuID.indexOf(vmenuIds[incv]);
            var tempStr;
            
            if( setVSubMenuID != null && index >=0 ) //it means avaialbel in cookie so remove it
            {
                tempStr= setVSubMenuID.substring(0,index-1);
                setVSubMenuID = tempStr+ setVSubMenuID.substring(index+tblID.substring(8).length,setVSubMenuID.length );
                setVSubMenuID = setVSubMenuID.replace(",,",","); 
             //   setCookie('selectedVMenuMID', setVSubMenuID ,null);
            }
        }
    }
    VSubMenuIDCookie = setVSubMenuID;
   
    
    //window.status=setVSubMenuID;
}

function setVmenuState()
{
/*    var setVSubMenuID = VSubMenuIDCookie.split(",") ;
    var inc,img;
    
    if( setVSubMenuID.length == 0 )
        return;
    
    for( inc=0 ; inc < setVSubMenuID.length ; inc ++ )
    {
        img= window.document.getElementById( "imgVSubMenu" +setVSubMenuID[inc]); 
        if( img ==null)
            continue;
        img.click();    
    }
    */
}

