//--------------------------------------
//ならびかえクイズ スクリプト V.07C5
//		Copyright エルゼアール 2007/12/1
//		HomePage:http://tanosii.net/
//--------------------------------------
var Dat;
var Qlen;
var Mno;
var Dcnt;
var Qstr;
var Astr;
var Span;
var TimerID=0;
var Seikai=new Array(3);
var OnPlay=false;
//----------------------------
function Narabikae()
{
	var str='<TABLE border="0"><TBODY><TR><TD nowrap><A href="http://elze.tanosii.net/" style="TEXT-DECORATION: none ;" title=" Official Site 「エルゼの森」へ ">ならびかえて！</A>&nbsp;&nbsp;&nbsp;&nbsp;<span id="No">No.</span>&nbsp;&nbsp;&nbsp;<span id="Tm">0秒</span>&nbsp;&nbsp;&nbsp;<button onclick="Kaisi()" style="border-style:solid; border-width:1px; background:white; " title="スタートボタン　クリック！">スタート</button> <font size="-2"><A href="http://elze.tanosii.net/nq/nqmenu.htm" title="ヘルプ 「ならびかえクイズ」のページへ">[Help]</A></font></TD></TR><TR><TD id="Q" style="font-size : '+FontSize+'px;font-family:monospace;" nowrap></TD></TR><TR><TD nowrap><span id="Ti" onclick="Info()" Title="クリック 制作者表示">タイトル</span><span id="Hi"> </span></TD></TR></TBODY></TABLE>';
	document.write(str);

	Dat=MondaiDat.split(",");
	Dcnt=Dat.length;
	var i;
	for( i=0; i<Dcnt*9; i++)
	{
		a=Math.floor(Math.random() * Dcnt);
		b=Math.floor(Math.random() * Dcnt);
		if( a!=b)
		{
			tmp=Dat[a]; Dat[a]=Dat[b]; Dat[b]=tmp;
		}
	}
	Span = document.getElementsByTagName("span");

	Span.namedItem("Ti").firstChild.nodeValue=Title;
	if( Max<1 )Max=100;

	Waku=(Waku==1 )? "border-width : 1px 1px 1px 1px;border-style : solid solid solid solid;": "";
	Tate=( Tate==1 )? "<br>":"";
	Mno=0;
	Shutudai(-1);
}
//----------------------------
function Kaisi()
{
	Mno=0; Shutudai(0);
}
//----------------------------
function Shutudai(mode)
{
	var i, a, b, tmp;
	Qstr=new Array();
	Astr=new Array();
	Span.namedItem("No").firstChild.nodeValue="No."+(Mno+1);

	Seikai=Dat[Mno].split("=");
	if( Seikai[1]==null || Seikai[1]=="") Seikai[1]="正解！";
	if( Seikai[2]==null ) Seikai[2]="";

	if( Seikai[2]!="" ) document.getElementById("Hi").innerHTML = '　<button onclick="DispHint()" style="border-style:solid; border-width:1px; background:white; " title="ヒントボタン　クリック！">ヒント</button>';

	if( Seikai[0].indexOf("~")<0 )
	{
		Qstr=Seikai[0].split('');
		Qlen=Qstr.length;
	}
	else
	{
		Qstr=Seikai[0].split("~");
		Qlen=Qstr.length;
		for( i=0; i<Qlen; i++)Qstr[i]+=" ";
		Seikai[0]=Qstr.join("");
	}
	for( i=0; i<Qlen*11; i++)
	{
		a=Math.floor(Math.random() * Qlen);
		b=Math.floor(Math.random() * Qlen);
		if( a!=b)
		{
			tmp=Qstr[a]; Qstr[a]=Qstr[b]; Qstr[b]=tmp;
		}
	}
	Disp();
	if( mode>-1) DispTime(0);
}
//----------------------------
function DispHint()
{
	document.getElementById("Hi").innerHTML = "：　"+Seikai[2];
}
//----------------------------
function Info()
{
	alert("ならびかえクイズ\n「"+Title+"」\n\n"+"問題制作： "+Author+"\n\n問題総数： "+Dcnt);
}
//----------------------------
function Clk(no)
{
	if( !OnPlay ){ alert("「スタート」ボタンを押して開始！");return;}
	Astr.push(Qstr[no]);
	Qstr.splice(no,1);
	Disp();
	if( Seikai[0]==Astr.join(""))
	{
		DispTime(2);
		if( Seikai[1]!="" )
		{
			var str='<A href="javascript:void(0);" style="color : blue;TEXT-DECORATION: none ;">'+Seikai[1]+'</A>';
			document.getElementById("Q").innerHTML = str;
		}
		Mno++;
		if( Mno<Dcnt && Mno<Max) setTimeout('Shutudai(0)',1000 );
		else
		{
			alert("おめでとう！！\n\nよくできました\n\n問題終了です。");
		}
	}
}
//----------------------------
function Del(no)
{
	if( !OnPlay ) return;
	var ar=Astr.slice(no);
	Astr.splice(no, Astr.length-no+1);
	Qstr=Qstr.concat(ar);
	Disp();
}
//----------------------------
function Disp()
{
	var str="", i;
	for( i=0; i<Astr.length; i++)
		str+='<A href="javascript:void(0);" onclick="Del('+i+')" onmouseover="Ms(this,2)" onmouseout="Ms(this,0)" style="color : blue;TEXT-DECORATION: none ;">'+Astr[i]+'</A>'+Tate;

	for( i=0; i<Qstr.length; i++)
		str+='<A href="javascript:void(0);" onclick="Clk('+i+')" onmouseover="Ms(this,1)" onmouseout="Ms(this,0)" style="color : black;TEXT-DECORATION: none ;'+Waku+'">'+Qstr[i]+'</A>'+Tate;

	document.getElementById("Q").innerHTML = str;
}
//----------------------------
function Ms( e, cno )
{
	if( !OnPlay ) return;
	var col = new Array("", "Lime", "Aqua");
	e.style.backgroundColor=col[cno];
}
//----------------------------
function DispTime(mode)
{
	if( mode==0 )
	{
		if( TimerID!=0 )clearInterval(TimerID);
		TStart=new Date(); 
		TimerID=setInterval( "DispTime(1)", 1000);
		Span.namedItem("Tm").firstChild.nodeValue=TimeLimit+"秒";
		OnPlay=true;
	}
	else if( mode==1 )
	{
		TNow=new Date();
		Nokori = TimeLimit-Math.floor( (TNow.getTime() - TStart.getTime() )/1000 );
		Span.namedItem("Tm").firstChild.nodeValue=Nokori+"秒";
		if( Nokori<=0 ){DispTime(2);alert("残念！！\n\n時間切れです。\n\n正解は、"+Seikai[0]+"  でした。");}
	}
	else
	{
		clearInterval(TimerID);TimerID=0;OnPlay=false;
	}
}
//----------------------------

