//var path = window.location.pathname;
var path = window.location.href;
var lev_no = -1
var lev_div = "";
var tar_level = 0;
var lay_lev = 1;
var layer_no = 1;
var data_lev1 = new Array();
var data_lev2 = new Array();
var data_lev3 = new Array();

var isV5 = false;
var isIE = false;
var navmenuout = true
var navmenutimeoutID = 1
var mouseout_menuarticle = true
var menutimeoutID = 1
var pollanswer = false

//base function

var isNS4 = (document.layers) ? true : false;
var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
                parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
var isMinIE4 = (document.all) ? 1 : 0;
var isMinIE5 = (isMinIE4 && navigator.appVersion.indexOf("5.") >= 0) ? 1 : 0;


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function MM_showHideLayers() {
if(parseInt(navigator.appVersion) == 5){
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  if(document.getElementById){
   for (i=0; i<(args.length-2); i+=3){
   obj=document.getElementById(args[i]);v=args[i+2];
v=(v=='show')?'visible':(v='hide')?'hidden':v;
   if(obj)obj.style.visibility=v;
   }
  }

  else{
  for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
 }
 }

else{
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("##")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function MM_swapImage() { //v3.0C
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function MM_swapImgRestore() { //v3.0C
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//end


if(path.indexOf('\\') != -1){
	div = "\\";
}else{
	div = "/";	
}

lev = path.split(div);

for(i=0; i<level.length; i++){	
	if(path.indexOf(div + level[i] + div) != -1){		
		fol = i;		
		for (j=0; j<lev.length; j++){
			if(lev[j] == level[i]){
				lev_no = j;
				break;
			}
		}
	}
}
//alert(level.length)

for (i=0 ;i<(lev.length - lev_no)-1 ;i++){		
		lev_div += "../";
	
}

if(lev_div == ""){
	lev_div = "english/";	
}


menu();

function add_data(data_link, data_alt, data_color, data_target, data_layer, data_level, data_folder){
	if (data_level == 1){		
		data_lev1[tar_level] = {link:data_link, alt:data_alt, color:data_color, target:data_target, layer:data_layer, folder:data_folder};
		data_lev2[tar_level] = new Array();
		data_lev3[tar_level] = new Array();
		tar_level++;
		tar_level2 = 0;
	}else if(data_level == 2){
		data_lev2[(tar_level-1)][tar_level2] = {link:data_link, alt:data_alt, color:data_color, target:data_target, layer:data_layer, folder:data_folder};
		data_lev3[(tar_level-1)][tar_level2] = new Array();
		tar_level2++;
		tar_level3 = 0;
	}else if(data_level == 3){
		data_lev3[(tar_level-1)][(tar_level2-1)][tar_level3] = {link:data_link, alt:data_alt, color:data_color, target:data_target, layer:data_layer, folder:data_folder};
		tar_level3++;
	}	
}


function genhd(){
	for(i=0; i<data_lev1.length;i++){
		if(level[fol] == data_lev1[i]['folder']){
			document.write('<td background="'+lev_div+'images/'+level[fol]+'/ctrpic.jpg" width="100%" align="right" style="background-repeat: repeat-x; background-position: 0% 0%" class="title">'+data_lev1[i]['alt']+'</td>');
			break;
		}
	}
}

function gensubhd(){
if ( document.location.href.search("/ma_")!=-1)
{
		document.write("Management ");
		return false;
}

if ( document.location.href.search("/job_apply.asp")!=-1)
{
		document.write("Job Application ");
		return false;
}
 var subhd = "";
	for(i=0; i<data_lev1.length;i++){		
		if(data_lev2[i].length > 0){			
			for(j=0;j<data_lev2[i].length;j++){	
				if(path.indexOf(div + data_lev2[i][j]['folder']) != -1){					
					subhd = data_lev2[i][j]['alt'];					
					break;
				}
			}
		}
	}
	
	if(subhd != ""){
		document.write(subhd);
	}else{
		for(i=0; i<data_lev1.length;i++){
			if(level[fol] == data_lev1[i]['folder']){
				document.write(data_lev1[i]['alt']);
			}
		}
	}
}

function genmenu(){	
	for(i=0; i<data_lev1.length;i++){		
		if(level[fol] == data_lev1[i]['folder']){
			for(j=0;j<data_lev2[i].length;j++){
				genlv1table(data_lev2[i][j]['link'],data_lev2[i][j]['alt'],data_lev2[i][j]['color'],data_lev2[i][j]['target'],data_lev2[i][j]['layer'],j,layer_no);
			}
			break;
		}
	}
}


function gennav(){
	for(i=0; i<data_lev1.length;i++){
		if(level[fol] == data_lev1[i]['folder']){			
			document.write('<a href="'+data_lev1[i]['link']+'" class="nav_link">' + data_lev1[i]['alt'] + '</a> <img src="'+lev_div + 'images/general/nav_arrow.gif" hspace="5">');
			for (j=0;j<data_lev2[i].length ;j++ ){				
				if(path.indexOf(div + data_lev2[i][j]['folder']) != -1){
					document.write(' <span class="nav_selected">' + data_lev2[i][j]['alt'] +'</span>');					
					//document.write(' <a href="'+data_lev2[i][j]['link']+'">' + data_lev2[i][j]['alt'] + '</a> <img src="'+lev_div + 'images/general/nav_arrow.gif" hspace="5"> ');
					break;
				}				
			}
			break;			
		}
	}
}


// gen table

function genlv1table(link, alt, color, target, layer, no, layerno){	

	document.write('<tr onMouseOver="bgColor=\''+color+'\'" onMouseOut="bgColor=\'#E20D11\'" bgcolor="#E20D11">'+
		'<td class="sidebtn_arrow" width="5" valign="top"><img name="sidearrow'+no+'" border="0" src="'+lev_div+'images/general/side_arrow.gif"></td>'+
		'<td class="sidebtn"><a href="'+link+'" class="sidebtn_link" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'sidearrow'+no+'\',\'\',\''+lev_div+'/images/general/side_arrow_over.gif\',1)" target="'+target+'">'+alt+'</a></td>'+
     '</tr>');

}


function chglang(lang){
	if(lang == "en"){
		tempPath = path.replace(div + "tc_chi" + div, div + "english" + div);
		tempPath = tempPath.replace(div + "sc_chi" + div, div + "english" + div);		

        if (tempPath.search("/cgi-bin/search.pl") != -1 )
        {
                tempPath = tempPath.replace("/cgi-bin/search.pl","/english/search/search.html");
        }
	
	}else if(lang == "tc"){
		tempPath = path.replace(div + "english" + div, div + "tc_chi" + div);
		tempPath = tempPath.replace(div + "sc_chi" + div, div + "tc_chi" + div);

        if (tempPath.search("/cgi-bin/search.pl") != -1 )
        {
                tempPath = tempPath.replace("/cgi-bin/search.pl","/tc_chi/search/search.html");
        }
	
	}else if(lang == "sc"){
		tempPath = path.replace(div + "english" + div, div + "sc_chi" + div);
		tempPath = tempPath.replace(div + "tc_chi" + div, div + "sc_chi" + div);
	

	if (tempPath.search("/cgi-bin/search.pl") != -1 )
	{
		tempPath = tempPath.replace("/cgi-bin/search.pl","/sc_chi/search/search.html");
	}
}
	window.location.href = tempPath;
}

//auto resize
function isIE4()
{
	if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion)>=4) {
		return true;
	} else {
		return false;
	}
}

function isN4()
{
	if (navigator.appName == "Netscape" && parseInt(navigator.appVersion)>=4) {
		return true;
	} else {
		return false;
	}
}
function resizeWin()
{
	
	var caption = '';

	if (!document.largephoto)
	{
		return false;
	}

	if((document.largephoto.width==0)&&(document.largephoto.height==0))
	{
		window.setTimeout('resizeWin()', 800);
		
	}
	else
	{
		
		photowidth=document.largephoto.width;
		photoheight=document.largephoto.height;
				

		if (isIE4())
		{
			
			photowidth=photowidth + 60;
			photoheight=photoheight + 110;
			//document.body.scroll="no";


		}
		
		
		if (caption.length > 0)
			//photoheight=photoheight + 25 + caption.length ;
		{
			if (isIE4())
				photoheight=document.body.scrollHeight + 32;
			else if (isN4())
				photoheight=document.height;
			else
				photoheight=photoheight + 25 + caption.length ;
		}
		
		if (photowidth > window.screen.width - 30)
		{
			photowidth = window.screen.width - 30;
			if (isIE4())
			{
				document.body.scroll="yes";
			}
		}
		if (photoheight > window.screen.height - 20)
		{
			photoheight = window.screen.height - 20;
			if (isIE4())
			{
				photowidth=photowidth + 13;
				document.body.scroll="yes";
			}
		}
		photowidth = photowidth + 10;
		photoheight=document.body.scrollHeight + 55;
		
		window.resizeTo(photowidth,photoheight);
		window.focus();
		
	}
}


function popwin_print()
{
	var ms;
	Today = new Date(); 
	ms = Today.getMilliseconds();
	print_path = window.location.href;
	print_path = print_path.replace("#","");
	if (print_path.search("/english/") !=-1)
	{
			print_path= print_path.replace("/english/","/print/english/");
	} else if ( print_path.search("/tc_chi/") !=-1)
	{
			print_path= print_path.replace("/tc_chi/","/print/tc_chi/");
	}else if ( print_path.search("/sc_chi/") !=-1)
	{
			print_path= print_path.replace("/sc_chi/","/print/sc_chi/");
	}
			window.open(print_path,'english'+ms,'resizable=yes,toolbar=yes,menubar=yes,scrollbars=yes,width=618,height=600,top=1,left=1');
}