/*******************************
このファイルをインクルードする前に、
以下のように変数を初期化しておく。

<SCRIPT LANGUAGE="JavaScript">
<!--
ChartPath = "../../../Pics/Stock/";
ct = 1;
cd = "00101";
ttl = "株式チャート";
ttlSubD = "(日足)";
ttlSubW = "(週足)";
ttlSubM = "(月足)";
ttlSubG = "(業績)";
ttlColor = "Black";
//-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="ChartK.js">
</SCRIPT>
********************************/

//var ct = 1;

function ShowStatus(s){
	window.status = s;
}

function getInnerWidth(){
	if(document.layers){
		return window.innerWidth;		//NN用
	} else if(document.all){
		return document.body.clientWidth;	//IE用
	} else {
		return document.documentElement.clientWidth;
	}
}

function getInnerHeight(){
	if(document.layers)	return window.innerHeight;		//NN用
	if(document.all)	return document.body.clientHeight;	//IE用
	return 0;
}

function Centering(){
	CenteringX(0);
}

function CenteringX(dx){
	var w = getInnerWidth();
	var x = parseInt(dx);
	if(document.layers){	// for NN4.0
		if(w > x + 620){
//			alert("hoge");
			document.layers['title1'].pageX = (w + x) / 2 - 300;
			document.layers['img0'].pageX = (w + x) / 2 - 300;
			document.layers['btn0'].pageX = (w + x) / 2 - 300;
		}else{
			document.layers['title1'].pageX = x + 10;
			document.layers['img0'].pageX = x + 10;
			document.layers['btn0'].pageX = x + 10;
		}
		document.layers['title1'].width = 600;
		document.layers['img0'].width = 600;
		document.layers['btn0'].width= 600;
	} else if(document.all){	// for IE4.0
		if(w > x + 620){
			document.all('title1').style.pixelLeft = (w + x) / 2 - 300;
			document.all('img0').style.pixelLeft = (w + x) / 2 - 300;
			document.all('btn0').style.pixelLeft = (w + x) / 2 - 300;
		}else{
			document.all('title1').style.pixelLeft = x + 10;
			document.all('img0').style.pixelLeft = x + 10;
			document.all('btn0').style.pixelLeft = x + 10;
		}
	} else {
		if(w > x + 620){
			document.getElementById('title1').style.left = (w + x) / 2 - 300 + "px";
			document.getElementById('img0').style.left = (w + x) / 2 - 300 + "px";
			document.getElementById('btn0').style.left = (w + x) / 2 - 300 + "px";
		}else{
			document.getElementById('title1').style.left = x + 10 + "px";
			document.getElementById('img0').style.left = x + 10 + "px";
			document.getElementById('btn0').style.left = x + 10 + "px";
		}
	}
}

function OnLoad(){
	var s;
	if ( location.hash.length == 6 ){	//URLでコード／足種別が指定されたとき
		s = location.hash;
		s = "00000" + s.substring(1 ,s.length);
		cd = s.substring(s.length - 5, s.length);
		ct = cd.substring(cd.length - 1, cd.length);
		cd = "0" + cd.substring(0, cd.length - 1);
	} else if ( location.hash.length > 0 ){	//URLでコードが指定されたとき
		s = location.hash;
		s = "00000" + s.substring(1 ,s.length);
		cd = s.substring(s.length - 5, s.length);
	}
	Show(cd,ttl);
}

function Show(c,t){
	var s;
	s = "00000" + c;
	cd = s.substring(s.length - 5, s.length);
	ttl = t;
	Click(ct);
}

function Click(btn){
	var s, p, obj0;
	btn = parseInt(btn);
	switch(btn){
		case 1:
			s = ttlSubD;
			p = ChartPath + "Day/K";
			ct = 1;
			break;
		case 2:
			s = ttlSubW;
			p = ChartPath + "Wek/K";
			ct = 2;
			break;
		case 3:
			s = ttlSubM;
			p = ChartPath + "Mon/K";
			ct = 3;
			break;
		case 4:
			if (cd > "01300"){
				s = ttlSubG;
				p = ChartPath + "Etc/K";
				ct = 4;
			} else {
				s = ttlSubD;
				p = ChartPath + "Day/K";
				ct = 1;
			}
			break;
		default:
			s = ttlSubD;
			p = ChartPath + "Day/K";
			ct = 1;
			break;
	}

	if(document.layers){	// for NN4.0
		document.layers['title1'].document.open();
		document.layers['title1'].document.write( "<CENTER><B><FONT SIZE=\'+1\' COLOR=\'" + ttlColor + "\'>" + ttl + s + "</FONT></B></CENTER>" );
		document.layers['title1'].document.close();
//		document.layers['img0'].background.src = p + cd + ct + ".GIF";
		document.layers['img0'].document.open();
		document.layers['img0'].document.write( "<IMG OnClick=\"Toggle()\" CLASS=\"mch\" SRC=\'" + p + cd + ct + ".GIF\'>" );
		document.layers['img0'].document.close();
	} else if(document.all){	// for IE4.0
//		img0.innerHTML = "<IMG BORDER=0 WIDTH=600 HEIGHT=400 SRC=\"" + p + cd + ct + ".GIF\">";
		document.all('img0').style.backgroundImage = "url(" + p + cd + ct + ".GIF)";
		document.all('title1').innerHTML = "<CENTER><B><FONT SIZE=\'+1\' COLOR=\'" + ttlColor + "\'>" + ttl + s + "</FONT></B><CENTER>";
	} else {
		document.getElementById("img0").style.backgroundImage =  "url(" + p + cd + ct + ".GIF)";
		document.getElementById('title1').innerHTML = "<CENTER><B><FONT SIZE=\'+1\' COLOR=\'" + ttlColor + "\'>" + ttl + s + "</FONT></B><CENTER>";
	}
}

function Toggle(){
	switch(ct){
		case 1:		Click(2);	break;
		case 2:		Click(3);	break;
		case 3:		if ( cd < "01300" ) Click(1); else Click(4);	break;
		case 4:		Click(1);	break;
		default:	Click(1);	break;
	}
}

