
function loadmenu(index)
{
    
    var myarrmenuitem = new Array();
    var resIndex = getListCategoryByIndex(index);
    if(resIndex.value != null && typeof(resIndex.value) == 'object' && typeof(resIndex.value.Tables) == 'object' && resIndex.value.Tables[0].Rows.length > 0)
    {	
	    for(var iItem = 0 ; iItem < resIndex.value.Tables[0].Rows.length; iItem ++)
	    {			    
		    var linkUrl = Trim(resIndex.value.Tables[0].Rows[iItem]['cateLinkUrl'].toString());
    		
		    myarrmenuitem.push(new menuitem(parseInt(resIndex.value.Tables[0].Rows[iItem]['cateID']),
		            resIndex.value.Tables[0].Rows[iItem]['cateIsImage'],
				    Trim(resIndex.value.Tables[0].Rows[iItem]['cateName'].toString()),
				    Trim(resIndex.value.Tables[0].Rows[iItem]['cateNameEng'].toString()),
				    linkUrl,
				    parseInt(resIndex.value.Tables[0].Rows[iItem]['cateChilfdOf'])));
	    }
    			
	    if(myarrmenuitem != null && myarrmenuitem.length > 0)
	    {	
	   	    var objmenu = new menu(myarrmenuitem);
		    objmenu.initmenu();																	
	    }
	 }
}

function menuitem(id,isimg,namevi,nameeng,url,childOf)
{	
    this.id = id;
	this.namevi=namevi;
	this.nameeng=nameeng;
	this.url=url;
	this.childOf=childOf;
		
}

function menu(arrmenuitem)
{
   	this.arrmenuitem=arrmenuitem;
}


menu.prototype.getarritem = function(parentID)
{
	var arritems = new Array();
	
	for(var mItem=0; mItem < this.arrmenuitem.length ; mItem++)
	{
		if(this.arrmenuitem[mItem].childOf == parentID)
		{
		   	arritems.push(this.arrmenuitem[mItem]);	
					
		}
	}
	return arritems;
}

menu.prototype.recursion = function(arritemroot,index)
{
    // duong phan cach ngang giua cac item con cai nao khong co thi hide di
    //if(index>0)
    //{
    //stm_ai("p0i1",[6,1,"#ffffff","",-1,-1,0]);
    //}
    
    menuisimg=arritemroot[index].isimg;
    
    if(arritemroot[index].childOf != 0)
	{
	// menu con 
	  
	  if (lang == 'vi-VN')
       {
            //thay doi từ "","",-1,-1,......
	        
	        stm_ai("p0i" + index,[0,arritemroot[index].namevi,"","",-1,-1,0,arritemroot[index].url,"_self","","","","",0,0,0,"","",0,0,0,0,1,"#ca2525",0,"#a51e1e",0,"","",3,3,0,0,"#fffff7","#ffffff","#ffffff","#ffffff","11px Arial","11px Arial"]);
	   }
	   else
	   {
	        //thay doi "","",-1,-1,......
	        stm_ai("p0i" + index,[0,arritemroot[index].nameeng,"","",-1,-1,0,arritemroot[index].url,"_self","","","","",0,0,0,"","",0,0,0,0,1,"#ca2525",0,"#a51e1e",0,"","",3,3,0,0,"#fffff7","#ffffff","#ffffff","#ffffff","11px Arial","11px Arial"]);
	        
	   }
	}
	else
	{		 
	    // menu cha  
	    
	//  if(menuisimg == true)
	//	{
	
	        if (lang == 'vi-VN')
           {
         
                
                stm_ai("p0i" + index,[2,"","img/button/vn/main_button_0"+arritemroot[index].id+".gif","img/button/vn/main_button_0"+arritemroot[index].id+"a.gif",-1,-1,0,arritemroot[index].url,"_self","","","","",0,0,0,"","",0,0,0,0,1,"#ffffff",1,"#ffffff",1,"","",3,3,0,0,"#fffff7","#000000","#ffffff","#feffb8","bold 11px arial","bold 11px Arial",0,0]);
	       }
	       else
	       {
	     
	            stm_ai("p0i" + index,[2,"","img/button/en/main_button_0"+arritemroot[index].id+".gif","img/button/en/main_button_0"+arritemroot[index].id+"a.gif",-1,-1,0,arritemroot[index].url,"_self","","","","",0,0,0,"","",0,0,0,0,1,"#ffffff",1,"#ffffff",1,"","",3,3,0,0,"#fffff7","#000000","#ffffff","#feffb8","bold 11px arial","bold 11px Arial",0,0]);
	       }
		    
//		}
//		else
//		{
//		    if(index!=0)
//		        // duong phan cach doc giua cac item cha
//		       // stm_ai("p1",[6,"  |  ","#ffffff","",-1,-1,0,"","","","","","",0,0,0,"","",0,0,0,0,1,"#ffffff",1,"#ffffff",1,"","",3,3,0,0,"#fffff7","#000000","#ffffff","#004a8f","11px Arial","11px Arial",0,1]);
//		        stm_ai("p1",[6,"  |  ","#ffffff","",-1,-1,0]);
//		       

//		    if (lang == 'vi-VN')
//            {
//                //thay doi từ "","",-1,-1,......
//                stm_ai("p0i" + index,[0,"  "+arritemroot[index].namevi+"  ","","",-1,-1,0,arritemroot[index].url,"_self","","","","",0,0,0,"","",0,0,0,0,1,"#0083c6",0,"#ff6633",0,"","",3,3,0,0,"#0099cc","#000000","#ffffff","#ffffff","bold 9pt 'Arial','Verdana'","bold 9pt Arial"]);
//                
//                
//        
//            }
//            else
//            {
//                //thay doi "","",-1,-1,......
//                stm_ai("p0i" + index,[0,"  "+arritemroot[index].nameeng+"  ","","",-1,-1,0,arritemroot[index].url,"_self","","","","",0,0,0,"","",0,0,0,0,1,"#0083c6",0,"#ff6633",0,"","",3,3,0,0,"#0099cc","#000000","#ffffff","#ffffff","bold 9pt 'Arial','Verdana'","bold 9pt Arial"]);
//                
//            }
//            
//           
//			
//		}
		
	}	
	
	var arritem = this.getarritem(arritemroot[index].id);
	if(arritem.length > 0)
	{		
		//thay doi hieu ung cua menu
		stm_bpx("p1","p0",[1,4,0,0,1,2,0,0,100,"progid:DXImageTransform.Microsoft.Wipe(GradientSize=1.0,wipeStyle=1,motion=forward,enabled=0,Duration=0.60)",5,"progid:DXImageTransform.Microsoft.Wipe(GradientSize=1.0,wipeStyle=1,motion=reverse,enabled=0,Duration=0.60)",4,50,0,0,"#3399ff","#cccccc"]);
        
		
		for (var j=0; j< arritem.length; j++)
		{
			this.recursion(arritem, j);
		}
		
		stm_ep();
	}
	else
	{
		return;
	}
}	

menu.prototype.initmenuitem = function(arrrootitem)
{
	if(arrrootitem.length > 0)
	{
			
		for(var i=0;i< arrrootitem.length;i++)
		{
			this.recursion(arrrootitem,i);
			
		}
	}
}

menu.prototype.initmenu = function()
{	
	if(this.arrmenuitem.length > 0)
	{
		var arritemsRoot = this.getarritem(0);
		
		if(arritemsRoot.length > 0)
		{	   
			
			//phai doi khi tao menu moi ----------------------------------------
            stm_bm(["menu63b0",430,"","blank.gif",0,"","",0,0,250,0,1000,1,0,0,"","",0],this);
            stm_bp("p0",[0,4,0,0,0,0,0,0,100,"",-2,"",-2,50,0,0,"#fffff7","#da251c","",3,0,0,"#000000"]);
            
            
            
            
            //-------------------------------------------------
			
			this.initmenuitem(arritemsRoot);
			stm_em();
			
		}
	}
}





