/*/////////////////////////////////////////
Open Sub Window
<a href="image link" onclick="openSubWindow(this, image width[px], image height[px]);"><img src="image"></a>

[sample]
<a href="#" onclick="openSubWindow(this,500,500);" target="slideshow"><img src="/images/test.gif" border="0" width="160" height="50"></a>
/////////////////////////////////////////*/

var openSubWindow_link_obj = null;
function openSubWindow(link_obj, image_width, image_height) {
	try{
		if(link_obj && link_obj.tagName.match(/^a$/i) && link_obj.href){
			
			if(! link_obj.title) link_obj.title = link_obj.href;
			var path = link_obj.href;
			link_obj.href = 'javascript:;';
			
			//window width, height
			var image_width = new Number(image_width);
			var image_height = new Number(image_height);
			try{
				if(statusbar.visible) image_widht += 23;
			}catch(e){}
			
			//window name
			var window_name = "ccs";
			if(link_obj.target && (link_obj.target != "")){
				window_name = link_obj.target;
			}else{
				link_obj.target = window_name;
			}
			
			//
			var subWindow = window.open("", window_name ,"location=no,resizable=yes,width=" + image_width + ",height=" + image_height);
			subWindow.document.open();
			subWindow.document.writeln("<html>");
			subWindow.document.writeln("<head><title>CYBERNET CAE SYSTEMS (Shanghai)</title></head>");
			subWindow.document.writeln("<body bgcolor=\"#ffffff\" leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" onLoad=\"focus();\">");
			subWindow.document.writeln("<img src=\"" + path + "\" border=\"0\">");
			subWindow.document.writeln("<br></body></html>");
			subWindow.document.close();
			subWindow.focus();
			
			openSubWindow_link_obj = link_obj;
			setTimeout("openSubWindow_2()", 1);
		}
	}catch(e){}
}
function openSubWindow_2(){
	try{
		if( openSubWindow_link_obj && openSubWindow_link_obj.href && openSubWindow_link_obj.title){
			openSubWindow_link_obj.href = openSubWindow_link_obj.title;
		}
	}catch(e){}
}



/*/////////////////////////////////////////
A mouse event for menus
/////////////////////////////////////////*/
function globalTAB(target, flag) {
	try{
		if(flag) {
			//mouse over
			var imgDir = "/ccs/images/roof/cur/" + target + ".gif";
		} else {
			//mouse out
			var imgDir = "/ccs/images/roof/ovr/" + target + ".gif";
		}
		document.images[target].src = imgDir;
	}catch(e){}
}



/*/////////////////////////////////////////
The javascript check of the browser
/////////////////////////////////////////*/
function JSorFlashError(){
 var flg = true;
	var browser = navigator.appName;
	var version = navigator.appVersion;
	//Netscapeinot Safarij
	if(browser.indexOf("Netscape") != -1){
		if((version.indexOf("Safari") == -1) && ((version.indexOf("3.") != -1)||(version.indexOf("4.") != -1))){
			flg = false;
		}
	//Internet Explorer
	}else if(browser.indexOf("Explorer") != -1){
		if((version.indexOf("MSIE 5") != -1)||(version.indexOf("MSIE 4") != -1)||(browser.indexOf("MSIE 3") != -1)){
			flg = false;
		}
	}else if(browser.indexOf("Opera") != -1){
		if((version.indexOf("Opera 5") != -1)||(browser.indexOf("Opera 6") != -1)){
			flg = false;
		}
	}
	return(flg);
}



/*/////////////////////////////////////////
event start
/////////////////////////////////////////*/
window.onload = function(){
	if(JSorFlashError()){
		submenuAction();
		setIconStyle();
	}
}


/*/////////////////////////////////////////
Sub menu control
/////////////////////////////////////////*/
function submenuAction() {
	//try{
		
		//set
		var contentpath = document.getElementById('CONTENTPATH');
		var _contentpath = "";
		var h1_text =  document.getElementsByTagName('h1')[0];
		var a_list = document.getElementById('SIDEBAR').getElementsByTagName('a');
		var li_list = document.getElementById('SIDEBAR').getElementsByTagName('li');
		var ul_list = document.getElementById('SIDEBAR').getElementsByTagName('ul')[0].getElementsByTagName('ul');
		var category_title = document.getElementById('SIDEBAR').getElementsByTagName('img')[0].getAttributeNode('alt').value;
		var category_url = document.getElementById('SIDEBAR').getElementsByTagName('img')[0].parentNode.href;
		var url = document.URL.replace(/index\..+$/, '');
		var flg_is_url = false;
		var flg_is_url2 = false; 
		//alert(contentpath +"\n"+ h1_text +"\n"+ category_title +"\n"+ category_url +"\n"+ url);
		
		//
		if(contentpath && h1_text && category_title && category_url && url){
			
			//revision
			for(i=0; i<a_list.length; i++){
				if(a_list[i].href && (a_list[i].href != "")) a_list[i].href = a_list[i].href.replace(/index\.html$/, '');
			}
			
			//close other
			for(i=0; i<ul_list.length; i++){
				ul_list[i].style.display = 'none';
			}
			
			//is'nt URL in a
			for(i=0; i<a_list.length; i++){
				if(a_list[i].href && (a_list[i].href.indexOf(url) != -1)){
					flg_is_url = true;
					break;
				}
			}
			if(!flg_is_url){
				if(url.match(/\/$/)){
					url = url.replace(/[^\/]+\/$/, '');
					flg_is_url2 = true;	//is'nt URL in a
				}else{
					url = url.replace(/[^\/]+$/, '');
					flg_is_url2 = true;	//is'nt URL in a
				}
			}
			
			//
			for(i=0; i<li_list.length; i++){
				if(li_list[i].getElementsByTagName('a')[0] && li_list[i].getElementsByTagName('a')[0].href && (li_list[i].getElementsByTagName('a')[0].href == url)){
					
					//contentpath
					if( !flg_is_url && flg_is_url2){
						_contentpath = '<a href="' + li_list[i].getElementsByTagName('a')[0].href + '">' + li_list[i].getElementsByTagName('a')[0].innerHTML + '</a>' + h1_text.innerHTML;	//is'nt URL in a
					}else{
						_contentpath = li_list[i].getElementsByTagName('a')[0].innerHTML;
					}
					
					//mark
					li_list[i].className = 'mark';	//class
					
					//open ul
					if(li_list[i].getElementsByTagName('ul')[0]){
						li_list[i].getElementsByTagName('ul')[0].style.display = 'block';
					}
					var item = li_list[i].parentNode;
					while(item && item.tagName && item.tagName.match(/ul|li/i)){
						
						//open ul
						if(item.tagName.match(/ul/i)){
							item.style.display = 'block';
						}
						
						//
						else if(item.tagName.match(/li/i) && item.getElementsByTagName('a')){
							
							//contentpath
							_contentpath = '<a href="' + item.getElementsByTagName('a')[0].href + '">' + item.getElementsByTagName('a')[0].innerHTML + '</a>' + _contentpath;
							//mark
							item.className = 'mark2';	//class
						}
						
						item = item.parentNode;
					}
					
					break;
				}
			}
			
			//contentpath
			if(category_url == url){
				contentpath.innerHTML += category_title;
			}else{
				contentpath.innerHTML += '<a href="' + category_url + '">' + category_title + '</a>' + _contentpath;
			}
			
		}
		
	//}catch(e){ alert(e); }
}



/*/////////////////////////////////////////
set pdf icon
Link ahead changes class arrow into a PDF icon in the case of PDF.
/////////////////////////////////////////*/
function setIconStyle(){
	try{
		//a tag
		var doc = document.getElementById('CONTENTS');
		var a_list = doc.getElementsByTagName('a');
		for(i=0; i<a_list.length; i++){
			if(a_list[i].className && a_list[i].className.match(/arrow/i)){
				if(a_list[i].href && a_list[i].href.match(/\.pdf$/i)){
					if(a_list[i].className){
						a_list[i].className += ' pdf';
					}else{
						a_list[i].className = 'pdf';
					}
				}
			}
		}
		
		//
		function setPDFicon(list){
			for(i=0; i<list.length; i++){
				if(list[i].className && list[i].className.match(/arrow/i)){
					if(list[i].getElementsByTagName('a').length > 0){
						for(j=0; j<list[i].getElementsByTagName('a').length; j++){
							if(list[i].getElementsByTagName('a')[j].href && list[i].getElementsByTagName('a')[j].href.match(/\.pdf$/i)){
								if(list[i].getElementsByTagName('a')[j].className){
									list[i].getElementsByTagName('a')[j].className += ' pdf';
								}else{
									list[i].getElementsByTagName('a')[j].className = 'pdf';
								}
							}
						}
					}
				}
			}
		}
		setPDFicon(doc.getElementsByTagName('p'));
		setPDFicon(doc.getElementsByTagName('li'));
		setPDFicon(doc.getElementsByTagName('ol'));
		setPDFicon(doc.getElementsByTagName('ul'));
		setPDFicon(doc.getElementsByTagName('dd'));
		setPDFicon(doc.getElementsByTagName('dt'));
		
	}catch(e){ alert(e); }
}

mailid = new Array();
uid=0;
function mail(ad,expre){
	uid += 1;
	ad=ad.replace(/\@/g,"\.");
	ad=ad.replace(/\%/,"\@");
	if(expre==""){
		expre=ad;
	}
	if (expre=="nolink") {
		document.write(ad);
	} else {
		mailid[uid] = ad;
		document.write("<a href=\"javascript:mailto('" + uid + "');\">" + expre + "</a>");
	}
}
function mailto(i){
	location.href="mailto:" + mailid[i];
}
