
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("p1i1",[6,1,"#d6dde8","",-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,"#415eb8",0,"#20467c",0,"","",3,3,0,0,"#27ADB0","#E3B73D","#FFFFFF","#e7eaee","bold 8pt tahoma","bold 8pt tahoma"]);
	   }
	   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,"#415eb8",0,"#20467c",0,"","",3,3,0,0,"#27ADB0","#E3B73D","#FFFFFF","#e7eaee","bold 8pt tahoma","bold 8pt tahoma"]);
	        
	   }
	}
	else
	{		 
	    // menu cha  
	    
	/*  if(menuisimg == true) // Hinh Anh
		{
	
	        if (lang == 'vi-VN')
           {
         
                
                stm_ai("p0i" + index,[2,"","img/button/vn/butt_0"+arritemroot[index].id+".jpg","img/button/vn/butt_0"+arritemroot[index].id+"a.jpg",-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_aix("p0i1","p1i1",[6,1,"#e7eaee"]);
		    
		    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,"#415eb8",0,"#415eb8",0,"","",3,3,0,0,"#E3B73D","#E3B73D","#FFFFFF","#b6c8e3","bold 8pt 'Arial','Verdana'","bold 8pt 'Arial','Verdana'",0,0]);
            }
            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,"#415eb8",0,"#415eb8",0,"","",3,3,0,0,"#E3B73D","#E3B73D","#FFFFFF","#b6c8e3","bold 8pt 'Arial','Verdana'","bold 8pt 'Arial','Verdana'",0,0]);
                
            }
//            
//           
//			
//		}
		
	}	
	
	var arritem = this.getarritem(arritemroot[index].id);
	if(arritem.length > 0)
	{		
		//thay doi hieu ung cua menu
		stm_bp("p1",[1,4,0,0,0,5,0,0,100,"progid:DXImageTransform.Microsoft.Wipe(GradientSize=1.0,wipeStyle=1,motion=forward,enabled=0,Duration=0.70)",5,"progid:DXImageTransform.Microsoft.Wipe(GradientSize=1.0,wipeStyle=1,motion=reverse,enabled=0,Duration=0.70)",4,40,0,0,"#000000","#415eb8","",3,1,1,"#415EB8 #D6DDE8 #D6DDE8"]);
        
		
		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(["yfatchr",430,"","_pgtres/blank.gif",0,"","",0,0,0,0,20,1,1,1,"","",67108865],this);
            stm_bp("p0",[0,4,0,0,0,3,0,0,100,"",-2,"",-2,90,0,0,"#000000","#d6dde8","",3,0,0,"#E3B73D"]);
            //-------------------------------------------------
			
			this.initmenuitem(arritemsRoot);
			stm_em();
			
		}
	}
}





