var languages_num =0;
 var EN="English"; languages_num++; 

function gen_frames(topnav,sidenav,m17n_lang,model_name,hw_version,version){
	if(get_by_id("header_container")) gen_header(model_name,hw_version,version);
	if(get_by_id("copyright")) gen_copyright();
	if(get_by_id("m17n_div") && languages_num>1) m17n_lang_select(m17n_lang);
	if(get_by_id("topnav")) gen_topnav(topnav);
	if(get_by_id("sidenav")) gen_sidenav(topnav,sidenav);	
}

/* header_container generater**/
function gen_header(modelname,hw_ver,sw_ver){
	var header_container = get_by_id("header_container");
	var tmp_tbody = document.createElement("tbody");
	var tmp_tr = document.createElement("tr");
	var tmp_td;
	var tmp_text;
	
	for(var i=0;i<4;i++){
		tmp_td=document.createElement('td');		
		switch (i)	{
			case 0:
				tmp_text=document.createElement("div");
				tmp="\u00a0\u00a0"+TA2+":"+"\u00a0<a href=\"http://support.dlink.com.tw/\" onclick=\"return jump_if();\">"+modelname+"</a>";				
				tmp_text.innerHTML=tmp;
				tmp_td.setAttribute("width","100%");
				break;
			case 1:				
				tmp_text=document.createTextNode(TA3+":\u00a0"+hw_ver+"\u00a0\u00a0");
				tmp_td.setAttribute("align","right");
				//tmp_td.setAttribute("nowrap",'true');
				tmp_td.style.whiteSpace='nowrap';	//for IE compatibility
				break;
			case 2:
				tmp_text=document.createTextNode(sd__FWV+": "+sw_ver);
				tmp_td.setAttribute("align","right");
				tmp_td.style.whiteSpace='nowrap';				
				break;
			case 3:	
				tmp_text=document.createTextNode(" ");
				break;			
		}
		tmp_td.appendChild(tmp_text);
		tmp_tr.appendChild(tmp_td);		
	}
	tmp_tbody.appendChild(tmp_tr);
	header_container.appendChild(tmp_tbody);	
}	

/* topnav_container generater*/
function gen_topnav(highlight){
	if(!highlight) return false;
	if(!get_by_id("topnav")) return false;
	var topnav = get_by_id("topnav");	
	var tmp_td = new Array();
	var topnav_modelname;
	var topnav_text = new Array(__setup,__advanced,__tools,__status,__support);
	var topnav_href = new Array("index.html","adv_virtual.html","tools_admin.html","st_device.html","support_men.html");
	
	tmp_td[0]= document.createElement("td");
	topnav_modelname = document.createElement("img");
	topnav_modelname.setAttribute("src","short_modnum.gif");
	topnav_modelname.setAttribute("width","125");
	topnav_modelname.setAttribute("height","25");
	tmp_td[0].setAttribute("width","125");
	tmp_td[0].setAttribute("height","29");		

	tmp_td[0].appendChild(topnav_modelname);
	topnav.appendChild(tmp_td[0]);

	for (i=1; i<=topnav_text.length;i++){
		tmp_td[i]= document.createElement("td");
		if(highlight==i)
			tmp_td[i].setAttribute("id", "topnavon"); 
		else
			tmp_td[i].setAttribute("id", "topnavoff"); 
		tmp_td[i].setAttribute("height",29);
		tmp_td[i].innerHTML="<a href=\""+topnav_href[i-1]+"\" onclick=\"return jump_if();\">"+topnav_text[i-1]+"</a>";
		topnav.appendChild(tmp_td[i]);
	}

}

/* sidenav_container generater*/
function gen_sidenav(which_topnav,which_sidenav){
	if(!which_topnav || !which_sidenav) return false;	
	var sidenav = get_by_id("sidenav");
	var tmp_ul = document.createElement("ul");		
	sidenav.appendChild(tmp_ul);
	
	var tmp_li;
	var tmp_div = new Array();
	
	side_nav = {
		sideclass: function(value){
				switch (value){
					case 1:
						tmp_div_text = new Array(sa__Internet,__wirelesst,bln__title__NetSt);
						tmp_div_href = new Array("index","wizard_wireless","lan");
						break;
					case 2:
						tmp_div_text = new Array(__virtserv,__pf,__specappsr
				,YM48
						,__netfilt,ACCESS_CONTROL,__websfilter,INBOUND_FILTER,__firewalls
					,__routing
						,__adwwls
						,__advnetwork
				,"IPv6"
						);
						tmp_div_href = new Array("adv_virtual","adv_portforward","adv_appl"
				,"adv_qos"
						,"adv_filters_mac","adv_access_control","adv_filters_url","Inbound_Filter","adv_dmz"
					,"adv_routing"
						,"adv_wlan_perform"
						,"adv_network"
				,"adv_ipv6_sel_wan"
						);
						break;
					case 3:
						tmp_div_text = new Array(__admin,__time,__syslog,te__EmSt,__system,__firmware,__dyndns,__syscheck,__scheds);
						tmp_div_href = new Array("tools_admin","tools_time","tools_syslog","tools_email","tools_system","tools_firmw","tools_ddns","tools_vct","tools_schedules");
						break;
					case 4:
						tmp_div_text = new Array(__devinfo,__logs,__stats,YM157,sr__RTable,__wireless
				,"IPv6"
						);
						tmp_div_href = new Array("st_device","st_log","st_stats","internet_sessions","st_routing","st_wireless"
				,"st_ipv6"
						);
						break;
					case 5:
						tmp_div_text = new Array(ish__menu,__setup,__advanced,__tools,__status);
						tmp_div_href = new Array("support_men","support_internet","support_adv","support_tools","support_status");						
						break;
				}	
			}
	}
	
	side_nav.sideclass(which_topnav);	
	
	for (i=0; i<tmp_div_text.length;i++){
		tmp_li= document.createElement("li");
		tmp_div[i] = document.createElement("div");				
		
		if(which_sidenav==tmp_div_href[i]){			
			tmp_div[i].setAttribute("id", "sidenavoff"); 
			tmp_div[i].innerHTML = tmp_div_text[i];
		}else
			tmp_div[i].innerHTML="<a href=\""+tmp_div_href[i]+".html\" onclick=\"return jump_if();\">"+tmp_div_text[i]+"</a>";
		
		
		tmp_li.appendChild(tmp_div[i]);
		tmp_ul.appendChild(tmp_li);		
	}		
}	

function gen_copyright(){
	get_by_id("copyright").innerHTML = __copyright;
}

/* Multiple-lingual language form*/

function m17n_lang_select(selected_value){
	if(!selected_value)	selected_value="EN";
			
	var m17n_div = get_by_id("m17n_div");
	var m17n_p1 = document.createElement("p");	
	
	var m17n_form = document.createElement("form");
	m17n_form.setAttribute("id", "form_lingual"); 
	m17n_form.setAttribute("name", "form_lingual");  
	m17n_form.setAttribute("method","post");
	m17n_form.setAttribute("action","apply.cgi");	
	
	var m17n_response_page = document.createElement("input"); 
	m17n_response_page.setAttribute("type", "hidden"); 
	m17n_response_page.setAttribute("id", "html_response_page"); 
	m17n_response_page.setAttribute("name", "html_response_page"); 
	m17n_response_page.setAttribute("value", get_current_pagename()); 	
	
	var m17n_select = document.createElement("select");
	m17n_select.setAttribute("id", "lingual"); 
	m17n_select.setAttribute("name", "lingual");
	m17n_select.onchange = send_lingual;	
	
	m17n_form.appendChild(m17n_response_page);
	m17n_form.appendChild(m17n_select);
	m17n_p1.appendChild(m17n_form);
	m17n_div.appendChild(m17n_p1);	
	
  AddOption(m17n_select,EN,"EN");
	set_selectIndex (selected_value,m17n_select);
} 

function send_lingual(e){
	document.getElementById("form_lingual").submit();
}
