var TOTAL_INSTALL_MODULE="";

function GetModuleTab(module_name)
{

	//Ūmodule table¡A¬ݸˤF¨º¨ƭodule->¨�dule list,module_total_num

	var url="/goform/Module_Get_Info?";
	var send_value="";
	//module_makeRequest(url,true,2,send_value,module_name);	//return to : Write_Module_Icon();
	module_makeRequest(url,true,2,send_value,module_name);	//return to : Write_Module_Menu();

}

function Write_Module_Menu(http_request,module_name)
{
	if(http_request.readyState == 4)
	{
		if (http_request.status == 200 || http_request.status == 0)
		{
			
			var ModuleMenu_jsonstr=http_request.responseText;
			
			var obj=document.getElementById("topnav_container2");
			
			var json= eval("("+ ModuleMenu_jsonstr + ")");
			
			var Menu_num=json.Menu.length;
			
			var str;
			
			var newcell=obj.insertCell(0);
			str="<IMG src=\"../../web/images/short_modnum.jpg\">" ;
			newcell.innerHTML=str;
						
			var MAX_MODULE_MUN=7;
			var i,k;
			var menu_list = new Array(MAX_MODULE_MUN);
			var menu_url = new Array(MAX_MODULE_MUN);
			k=0;
			
			for(i=0;i<MAX_MODULE_MUN;i++)
			{		
				menu_list[k]="null";
				menu_url[k]="null";
				if(i<Menu_num)
				{
					if(json.Menu[i].ModuleStatus==0 || json.Menu[i].ModuleName=="LANGUAGE" || json.Menu[i].ModuleName=="ADS" || json.Menu[i].URL=="NULL")
					{
						continue;
					}
					menu_list[k]=json.Menu[i].ModuleName;
					menu_url[k]=json.Menu[i].URL;
					k++;
				}
			}
			
			for(i=0;i<5;i++)
			{	
				newcell=obj.insertCell(i+1);
				
				if(module_name==menu_list[i])
					newcell.setAttribute("id","topnavon");
				else
					newcell.setAttribute("id","topnavoff");
				
//				if(menu_list[i]=="null")
//				{
//					continue;
//					//str="";
//				}
//				else
				if(i>k-1)
					str=""
				else
				{
					var dir="";
					if(menu_url[i]=="download_scheduling.asp")
						dir="web/user/";
					else
						dir="imodule/" + menu_list[i] + "/";
					str="<a href=\"/goform/CheckUserTimeout?url=" + dir + menu_url[i] + "\">" + menu_list[i] + "</a>";
				}
				newcell.innerHTML=str;
			}
		}
	}
}
function Write_Module_Icon(http_request)
{
	if(http_request.readyState == 4)
	{
		if (http_request.status == 200 || http_request.status == 0)
		{
			
			var ModuleMenu_jsonstr=http_request.responseText;
						
			var json= eval("("+ ModuleMenu_jsonstr + ")");
			
			var Menu_num=json.Menu.length;

			var obj=document.getElementById("module_list");
	
			var i,j,k,newrow,newcell;
			
			var menu_list = new Array(Menu_num);
			var menu_status = new Array(Menu_num);
			var menu_url = new Array(Menu_num);
			
			for(i=0;i<Menu_num;i++)
			{
				menu_list[i]=json.Menu[i].ModuleName;
				menu_status[i]=json.Menu[i].ModuleStatus;
				menu_url[i]=json.Menu[i].URL;
			}
			
			var total_row=Math.ceil(Menu_num)/3;
			k=0;
			for(i=0;i<total_row;i++)
			{
				newrow = obj.insertRow(obj.rows.length);
				for(j=0;j<3;j++)
				{
					newcell = newrow.insertCell(j);
					newcell.align="center";
					
					if(k<menu_list.length)
					{
						var icon;
						
						if(menu_status[k]==0)
							icon="<img border=\"0\" src=\"../../imodule/" +  menu_list[k] + "_off.png\"><br>" + menu_list[k];
						else
							icon="<a href=\"/goform/CheckUserTimeout?url=../../imodule/" + menu_url[k] +"\"><img border=\"0\" src=\"../../imodule/" +  menu_list[k] + "_on.png\"></a><br>" + menu_list[k];
						newcell.innerHTML=icon;
					}
					else
						newcell.innerHTML="&nbsp;";
						
					k++;
				}
			}
		}
	}		
}
function write_tb()
{
	
}
function module_makeRequest(url,content,return_to,send_value,module_name) 
{	 			
    var http_request = false;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari,IE7...
      
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } 
    else if (window.ActiveXObject)  // IE
    {
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) 
    {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
	
	if (content == true)
    	{ 
		if(return_to==1)
			http_request.onreadystatechange = function(){show_module_info(http_request)};
		else if(return_to==2)
			http_request.onreadystatechange = function(){Write_Module_Menu(http_request,module_name)};
	}
		
	url = url + "&" + Random();    
	http_request.open('Post', url, true);

  	http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	http_request.setRequestHeader('Content-Type','text/html');
	http_request.setRequestHeader('Content-Type','charset=UTF-8');
	http_request.setRequestHeader('Pragma','no-cache');
	http_request.setRequestHeader('Cache-Control', 'no-cache');
	http_request.send(send_value);

}
function Random()
{
	Random_value=Math.floor(Math.random()*1000000000000000);
	return Random_value;
} 
function chg_image(obj_name,file_path)
{
	document.getElementById(obj_name).src=file_path;
}
