
// Redirect to page
function goChapter(filename) {
	if(filename!="") {
		window.location=filename;
	}
	return false;
}

function getWindow(url,name) {
	window.open(url,name,'resizable=yes,scrollbars=yes,width=798,height=550')
}

function getPrintPreview(url,name) {
	window.open(url,name,'toolbar=yes,resizable=yes,scrollbars=yes,status=yes,width=798,height=550')
}

function showExample(id) {
	var whichEl = eval("document.all.E" + id);
	whichEl.style.display = "inline";

	var next_id = id + 1;
	var prev_id = id - 1;

	if(id < ExampleNum) {
		document.all.ENext.innerHTML = "<a href='javascript: showExample(" + next_id + ")' onMouseOver=\"MM_swapImage('imgNextQ','','images/05-11.1.gif',1)\" onMouseOut=\"MM_swapImgRestore();\"><img name=\"imgNextQ\" src=\"images/05-11.gif\" border=0 alt=\"下一題\"></a>";
	} else {
		document.all.ENext.innerHTML = "";
	}

	if(id > 1) {
		document.all.EPrev.innerHTML = "<a href='javascript: showExample(" + prev_id + ")' onMouseOver=\"MM_swapImage('imgPrevQ','','images/05-12.1.gif',1)\" onMouseOut=\"MM_swapImgRestore();\"><img name=\"imgPrevQ\" src=\"images/05-12.gif\" border=0 alt=\"上一題\"></a>";
	} else {
		document.all.EPrev.innerHTML ="";
	}

	for(var i=1; i <= ExampleNum; i++) {
		if(i!=id) {
			whichEl = eval("document.all.E" + i);
			whichEl.style.display = "none";
		}
	}
}

function showQes(id) {

	var whichEl = eval("document.all.Q" + id);
	whichEl.style.display = "inline";

	document.all.Summary.style.display = "none";

	var next_id = id + 1;
	var prev_id = id - 1;

	if(id < QesNum) {
		document.all.QNext.innerHTML = "<a href='javascript: showQes(" + next_id + ")' onMouseOver=\"MM_swapImage('imgNextQ','','images/05-11.1.gif',1)\" onMouseOut=\"MM_swapImgRestore();\"><img name=\"imgNextQ\" src=\"images/05-11.gif\" border=0 alt=\"下一題\"></a>";
	} else if(id == QesNum && CType==0) {
		document.all.QNext.innerHTML ="<a href='javascript: showSummary()'>" + QType + "總結</a>";
	} else {
		document.all.QNext.innerHTML = "";
	}

	if(id > 1) {
		document.all.QPrev.innerHTML = "<a href='javascript: showQes(" + prev_id + ")' onMouseOver=\"MM_swapImage('imgPrevQ','','images/05-12.1.gif',1)\" onMouseOut=\"MM_swapImgRestore();\"><img name=\"imgPrevQ\" src=\"images/05-12.gif\" border=0 alt=\"上一題\"></a>";
	} else {
		document.all.QPrev.innerHTML ="";
	}

	for(var i=1; i <= QesNum; i++) {
		if(i!=id) {
			whichEl = eval("document.all.Q" + i);
			whichEl.style.display = "none";
		}
	}
}

function showSummary() {

	var string = "<table border=1 bordercolor=#000000 bgcolor=white cellpadding=5 width=100%><tr><td>";
	string += "<table border=0 cellspacing=5 cellpadding=0 width=100%>";
	string += "<tr>";
	string += "	<td nowrap><font style='font-size: 16pt; font-weight: bold'>" + curBook + "</font>&nbsp;&nbsp;&nbsp;<font style='font-size: 14pt; font-weight: bold'>" + curChapter + "</font><BR><font style='font-size: 12pt; font-weight: bold'>" + QType + "總結</font></td>";
	// string += "	<td nowrap><b>班別：</b> <input type=text></td>";
	// string += "	<td nowrap><b>姓名：</b> <input type=text></td>";
	//string += "	<td nowrap align=right><a onClick=\"getPrintPreview('preview.html'); return false;\" href=\"\" onMouseOver=\"MM_swapImage('ImgPrint','','images/05-8.gif',1)\" onMouseOut=\"MM_swapImgRestore()\"><img name=ImgPrint src=\"images/05-8.1.gif\" border=0></a></td>";	
	string += "	<td nowrap align=right>&nbsp;</td>";
	string += "</tr></table>";
	string += "<hr noshade width=98% size=1>";

	var whichEl = eval("document.contentForm.step" + 1); //Dummy

	for (var i=1; i<= QesNum; i++) {
		string += "<font style=\"font-size: 11pt\"><b>題目：</b></font><BR>";

		whichEl = eval("document.all.Ask" + i);
		string += whichEl.innerHTML + "<BR>";
		
		// string += "<font style=\"font-size: 11pt\"><b>算式：</b></font><BR><pre>";

		// whichEl = eval("document.contentForm.step" + i);
		// string += whichEl.value + "</pre><BR>";

		// string += "<font style=\"font-size: 11pt\"><b>作答：</b></font>";

		// whichEl = eval("document.contentForm.answer" + i);
		// string += whichEl.value + "<P>";

		string += "<font style=\"font-size: 11pt\"><b>答案：</b></font><BR>";

		whichEl = eval("document.all.A" + i);
		string += whichEl.innerHTML;


		if(i != QesNum )
		string += "<hr noshade size=1 width=98%><P>";
	}

	string += "</td></tr></table>";

	document.all.Summary.innerHTML = string;
	document.all.QNext.innerHTML = "";
	document.all.QPrev.innerHTML = "";

	for(var i=1; i <= QesNum; i++) {
		whichEl = eval("document.all.Q" + i);
		whichEl.style.display = "none";
	}

	document.all.Summary.style.display = "inline";
}

function startQuiz() {

	document.all.Introduction.style.display = "none";
	
	document.all.QLink.style.display = "inline";
	document.all.PageLinks.style.display = "inline";
	document.all.printLayer.style.display = "inline";
	document.all.SubmitButton.style.display = "inline";

	showQes(1);
	
}

function submitQuiz() {

	document.all.QLink.style.display = "none";
	document.all.PageLinks.style.display = "none";
	document.all.SubmitButton.style.display = "none";
	
	showSummary();

}

// Generate Print Content
function printContent() {

        var parentFrame = window.opener;

	if(parentFrame.Summary && parentFrame.Summary.style.display=="inline") {
			var string = parentFrame.Summary.innerHTML;
	} else {
	        for(var i=1; i <= parentFrame.QesNum; i++) {
                        	whichEl = eval("parentFrame.document.all.Q" + i);
	                        if (whichEl.style.display != "none" ) {
                                	var thisItem = i;
	                                break;
                        	}
        	}

	        whichEl = eval("parentFrame.document.all.Ask" + thisItem);
        	var string =  whichEl.innerHTML;
	
         	string += "<p><font style=\"font-size: 11pt\"><b>作答：</b></font><br>";
	
        
	        whichEl = eval("parentFrame.document.all.A" + thisItem);
        	if(whichEl.style.display == "inline" ) {
        		string += whichEl.innerHTML;
		}

	}
         document.write( string);

}

function showHide(layerID) {

	var whichEL = eval("document.all." + layerID);
	whichEL.style.display = (whichEL.style.display == "none")? "inline" : "none";
}

function showContent () {
	var re = new RegExp("#");
	if(! re.test(self.location.href))
		self.location.href=self.location.href+"#contentPart";
}

function MM_swapImgRestore() { //v3.0
  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_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_findObj(n, d) { //v4.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);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  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];}
}

