///////////////////////////////////////////
//small window generate
///////////////////////////////////////////
/*/////////////////////////////////////////

/////////////////////////////////////////*/

function openSubWindow() {
	//hikisuu flag
	var flg = false;
	
	//hikisuu 4
	if(arguments.length == 4){
		flg = true;
		var uri = arguments[0];
		var name = arguments[1];
		var w = arguments[2];
		var h = arguments[3];
	}
	//hikisuu 3
	else if(arguments.length == 3){
		flg = true;
		var uri = arguments[0].href;
		var name = arguments[0].target;
		var w = arguments[1];
		var h = arguments[2];
	}
	
	//window name
	if((name == null) || (name == undefined) || (name == "")){
		arguments[0].target = "blank";
		name = "blank";
	}
	
	if(flg){
		w += 21;
		h += 21;
		/* case image */
		if(uri.match(/\.gif$|\.jpg$|\.jpeg$/i)){
			
			var subWindow = window.open("",name,"location=no,directories=no,scrollbars=1,resizable=1,width="+w+",height="+h+",left=5,top=5");
			subWindow.document.open();
			subWindow.document.writeln("<html>");
			subWindow.document.writeln("<head><title>WAON(daionkyou kaiseki puroguramu):cybernet system</title></head>");
			subWindow.document.writeln("<body bgcolor=\"#ffffff\" leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" onLoad=\"focus();\">");
			subWindow.document.writeln("<img src=\""+uri+"\" border=\"0\">");
			subWindow.document.writeln("<br></body></html>");
			subWindow.document.close();
			subWindow.focus();
		}
		/* case not image */
		else{
			var subWindow=window.open(uri,name,"location=no,directories=no,scrollbars=1,resizable=1,width="+w+",height="+h+",left=5,top=5");
			subWindow.focus();
		}
	}
	
	return true;
}


///////////////////////////////////////////
//global menu image change according to mouse move
///////////////////////////////////////////
/*/////////////////////////////////////////
hikisuu target : change image name value
hikisuu flag : mouse over or out inform int
(1:over,0:out)
siyoukasho is <div id="ROOF">ikano global navi part
/////////////////////////////////////////*/

function globalTAB(target,flag) {
	if(flag) {
		//case is over replace white letter image
		var imgDir = "/waon/english/images/roof/ovr/" + target + ".jpg";
	} else {
		//case is out replace yellow letter image
		var imgDir = "/waon/english/images/roof/cur/" + target + ".jpg";
	}
	document.images[target].src = imgDir;
}


///////////////////////////////////////////
//left menu current setting(4th layer)
///////////////////////////////////////////

/* --------------------------- */
/* check           */
/* --------------------------- */
//JavaSctipt Flash check(old blowser dont action left menu)
function JSorFlashError(){
 var flg = true;
	var browser = navigator.appName;
	var version = navigator.appVersion;
	//Netscape(Safari is jogai)
	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);
}
var ScriptError = JSorFlashError();


//left menu current open page, change button style
//change left menu background color to relation of current open page
window.onload = function(){
	if(ScriptError){
		setIconStyle();
	}
}



/*----------------------------------*/
/* change icon style         */
/*----------------------------------*/
/* <a class="icon" href="#"></a>change to style  */
function setIconStyle(){
	//target ID
	var idname = 'CONTENTS';
	
	try{
		//A tag
		var a_list = document.getElementById(idname).getElementsByTagName("a");
		for(i=0; i<a_list.length; i++){
			
			//icon class
			if((a_list[i].className != "") && (a_list[i].className.indexOf("icon") != -1)){
				
				//change style
				setIconStyleUpdate(a_list[i]);
				
			}
		}
		
		
		//P tag icon
		var p_list = document.getElementById(idname).getElementsByTagName("p");
		for(i=0; i<p_list.length; i++){
			
			//icon class
			if((p_list[i].className != "") && (p_list[i].className.indexOf("icon") != -1)){
				
				//P tag class=icon
				a_list = p_list[i].getElementsByTagName("a");
				//
				for(j=0; j<a_list.length; j++){
					setIconStyleUpdate(a_list[j]);
				}
			}
		}
	
		//memory reflesh
		p_list = null;
		
		
		//P tag
		var div_list = document.getElementById(idname).getElementsByTagName("div");
		for(i=0; i<div_list.length; i++){
			
			//icon class
			if((div_list[i].className != "") && (div_list[i].className.indexOf("icon") != -1)){
				
				//div tag class=icon
				a_list = div_list[i].getElementsByTagName("a");
				//
				for(j=0; j<a_list.length; j++){
					setIconStyleUpdate(a_list[j]);
				}
			}
		}
	
		//memory reflesh
		div_list = null;
		
	}
	//reigai shori
	catch(e){
		alert("yosouguy");
	}
	
	//icon auto check
	function setIconStyleUpdate(o){
		if(o.tagName.match(/a/i) && o.getAttribute('href')){
			
			//case protocol is mail
			if(o.href.indexOf("mailto:") == 0){
				if(o.className == ""){
					o.className = "mail";
				}else{
					o.className = o.className.replace("icon", "mail");
				}
			}
			
			//case target is new window
			else if((o.target != "") && (o.href.indexOf("_top") == -1) && (o.href.indexOf("_self") == -1) && (o.href.indexOf("_parent") == -1) && !o.href.match(/\.pdf/i) && !((o.href.indexOf("https:") == 0) && (o.href.indexOf("cybernet.co.jp") != -1))){
				if(o.className == ""){
					o.className = "window";
				}else{
					o.className = o.className.replace("icon", "window");
				}
			}
			
			//case protocol is http
			else if(o.href.indexOf("http") == 0){
				
				//case extension is pdf
				if(o.href.match(/\.pdf/i)){
					if(o.className == ""){
						o.className = "pdf";
					}else{
						o.className = o.className.replace("icon", "pdf");
					}
					if(! o.href.match(/\.php\?/)){
						o.target = "_blank";
					}
				}
				
				//case extension is text
				if(o.href.match(/\.txt/i)){
					if(o.className == ""){
						o.className = "file";
					}else{
						o.className = o.className.replace("icon", "file");
					}
					if(! o.href.match(/\.php\?/)){
						o.target = "_blank";
					}
				}
				
				//case host is not cybernet
				else if(o.href.indexOf(".cybernet.co.jp/") == -1){
					if(o.className == ""){
						o.className = "window";
					}else{
						o.className = o.className.replace("icon", "window");
					}
					o.target = "_blank";
				}
				
				//case SSL
				else if(o.href.indexOf("https:") == 0){
					if(o.className == ""){
						o.className = "form";
					}else{
						o.className = o.className.replace("icon", "form");
					}
					o.target = "_blank";
				}
				
				//case atesaki to download server
				else if((o.href.indexOf("://dl") != -1) || (o.href.indexOf(".jp/common/DLlink") != -1) || o.href.match(/\.zip/)){
					if(o.className == ""){
						o.className = "download";
					}else{
						o.className = o.className.replace("icon", "download");
					}
				}
				
				//case else
				else{
					if(o.className == ""){
						o.className = "arrow";
					}else{
						o.className = o.className.replace("icon", "arrow");
					}
				}
			}
			
			//case protocol is unknown
			else{
				if(o.className == ""){
					o.className = "arrow";
				}else{
					o.className = o.className.replace("icon", "arrow");
				}
			}
			
		}
	}
	
}

