﻿// JScript File

// JScript File


function loadmenu(index)
{   
    var myarrmenuitem = new Array();
    //var resIndex = getListCategoryByIndex(index);
    var resIndex = processinfo.readmenuxml();
    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']),
				    Trim(resIndex.value.Tables[0].Rows[iItem]['orient'].toString()),parseInt(resIndex.value.Tables[0].Rows[iItem]['cateTotalChild']),resIndex.value.Tables[0].Rows[iItem]['cateShowOnIndex']));
	    }
    			
	    if(myarrmenuitem != null && myarrmenuitem.length > 0)
	    {	
	   	    var objmenu = new menu(myarrmenuitem);
		    objmenu.initmenu();																	
	    }
	 }
}

function menuitem(id,isimg,namevi,nameeng,url,childOf,orient,totalchild,show)
{	
    this.id = id;
    this.isimg = isimg;
	this.namevi=namevi;
	this.nameeng=nameeng;
	this.url=url;
	this.childOf=childOf;
	this.totalchild = totalchild;
	this.show = show;
	switch(orient.toLowerCase())
	{
		case 'left':{this.orient=1;break;}
		case 'right':{this.orient=2;break;}
		case 'top':{this.orient=3;break;}
		case 'bottom':{this.orient=4;break;}
		default :{this.orient = 2;}
	}
		
}

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)
{
    menuisimg=arritemroot[index].isimg;
    var xsart=0;
    if(arritemroot[index].childOf != 0 && (arritemroot[index].childOf == 100 || arritemroot[index].childOf == 101||arritemroot[index].childOf == 103||arritemroot[index].childOf == 104||arritemroot[index].childOf == 105||arritemroot[index].childOf == 200||arritemroot[index].childOf == 214||arritemroot[index].childOf == 218))
	{
	  /************************************************************/
	     //stm_ai("p1i1"+ index,[6,0,"#333333","",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,arritemroot[index].target,"","","","",0,0,0,"","",0,0,0,0,1,"#027dc3",0,"#00adef",0,"","",3,3,0,0,"#fffff7","#ffffff","#ffffff","#f6ffa6","bold 12px Arial","bold 12px Arial"]);
    
	   }
	   else
	   {
	        //thay doi "","",-1,-1,......
	        stm_ai("p0i" + index,[0," "+arritemroot[index].nameeng+" ","","",-1,-1,0,arritemroot[index].url,arritemroot[index].target,"","","","",0,0,0,"","",0,0,0,0,1,"#027dc3",0,"#00adef",0,"","",3,3,0,0,"#fffff7","#ffffff","#ffffff","#f6ffa6","bold 12px Arial","bold 12px Arial"]);
	   }
	}
	else
	{	
	    if(arritemroot[index].childOf != 0)	 
	        {
	            if (lang == 'vi-VN')
           {
	            //thay doi từ "","",-1,-1,......
	            stm_ai("p0i" + index,[0," "+arritemroot[index].namevi+" ","","",-1,-1,0,arritemroot[index].url,arritemroot[index].target,"","","","",0,0,0,"","",0,0,0,0,1,"#014a73",0,"#005395",0,"","",3,3,0,0,"#fffff7","#ffffff","#ffffff","#f6ffa6","bold 12px Arial","bold 12px Arial"]);
        
	       }
	       else
	       {
	            //thay doi "","",-1,-1,......
	            stm_ai("p0i" + index,[0," "+arritemroot[index].nameeng+" ","","",-1,-1,0,arritemroot[index].url,arritemroot[index].target,"","","","",0,0,0,"","",0,0,0,0,1,"#014a73",0,"#005395",0,"","",3,3,0,0,"#fffff7","#ffffff","#ffffff","#f6ffa6","bold 12px Arial","bold 12px Arial"]);
	       }
	    
	    }  
	    else
	    {
	   //if(menuisimg == true)//là root
		//{
		    //stm_ai("p0i"+ index,[2,"","img/vn/layout/top_06.gif","img/vn/layout/top_06.gif",12,21,0,"","_self","","","","",0,0,0,"","",0,0,0,0,1,"#ffffff",1,"#ffffff",1,"","",3,3,0,0,"#fffff7","#000000","#000000","#000000","11px Arial","11px Arial",0,0]);
		    if(arritemroot[index].show == 1)
            {
		        if (lang == 'vi-VN')
                {
		            stm_ai("p0i" + index,[2,"","img/button/button_0"+(index+1)+".jpg","img/button/button_0"+(index+1)+"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","#498923","#184002","bold 12px Arial","bold 12px Arial",0,0]);
		        }
		        else
		        {
		            stm_ai("p0i" + index,[2,"","img/en/button_0"+(index+1)+".jpg","img/en/button_0"+(index+1)+"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","#498923","#184002","bold 12px Arial","bold 12px Arial",0,0]);
		        }
	        }
        }
	}
	var arritem = this.getarritem(arritemroot[index].id);
	if(arritem.length > 0)
	{	
	   	//thay doi
		//[0,4,-90,0,0,0,0,0,100,"progid:DXImageTransform.Microsoft.Fade(overlap=.5,enabled=0,Duration=0.60)",-2,"progid:DXImageTransform.Microsoft.Fade(overlap=.5,enabled=0,Duration=0.60)",-2,50,0,0,"#799BD8","#EEEEEE","060417line1.gif"]
		//stm_bpx("p1","p0",[1,arritemroot[index].orient,0,-1,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","transparent","",3,1,1,"#0099ff"]);
		stm_bpx("p1","p0",[1,arritemroot[index].orient,0,0,0,3,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","transparent","",3,0,0,"#f67a00"]);
        //stm_bp("p1",[1,arritemroot[index].orient,0,0,0,3,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","transparent","",3,0,0,"#f67a00"]);

	     

		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","transparent","",3,0,0,"#000000"]);


            //-------------------------------------------------
			
			this.initmenuitem(arritemsRoot);
			
			stm_em();
			
		}
	}
}









