/*** 402 ***/


var scoid=parent.scoid;
var direction = '';
var direction_sound = '';
var showanswer = true;
var showanswer_no = 1;
var offline = parent.offline;
var shuffle_question = false;
var score_save = true;
var score = 0;
var testformat= 1;
var thai = parent.thai;
var system_message = parent.system_message;
var random_choice = false;
var random_question = 0;

var tf_label_true = 'True';
var tf_label_false = 'False';

var suspend_data = 0;
if((parent.usescorm) && (showanswer) && (showanswer_no > 0)){
	suspend_data = parent.doLMSGetValue("cmi.suspend_data");

	if(isNaN(suspend_data) || (suspend_data == null) || (suspend_data=='')) suspend_data = 0;
	suspend_data++;

	if(suspend_data){
		/*
		if((!isNaN(suspend_data)) && (suspend_data != null) && (suspend_data != ''))
			showanswer = (showanswer_no <= parseInt(suspend_data))?true:false;
		else
			showanswer = false;
		*/
		showanswer = ((!isNaN(suspend_data)) && (suspend_data != null) && (suspend_data != ''))?((showanswer_no <= parseInt(suspend_data))?true:false):false;
	}
	else
		showanswer = false;
}
else{
	if(showanswer_no > 1) showanswer = false;
}




var question = new Array();
var question_score = new Array();
var choice = new Array();
var question_comment = new Array();


//* Question: 1********************
question[0] = '<FONT face=Tahoma size=6>ข้อใดเป็นพยัญชนะไทย</FONT> ';
question_score[0] = '1';
choice[0] = new Array();

//* Question: 2********************
question[1] = '<FONT face=Tahoma size=6>ข้อใดเป็นหลักการเขียนคำไทย</FONT>';
question_score[1] = '1';
choice[1] = new Array();

//* Question: 3********************
question[2] = '<FONT face=Tahoma size=6>การคัดลายมือทำให้นักเรียนได้ฝึกข้อใด</FONT> ';
question_score[2] = '1';
choice[2] = new Array();

//* Question: 4********************
question[3] = '<FONT size=6 face=Tahoma>การคัดลายมือบ่อยๆ ทำให้ลายมือสวยและยังทำให้เกิดสิ่งใด</FONT> ';
question_score[3] = '1';
choice[3] = new Array();

//* Question: 5********************
question[4] = '<FONT face=Tahoma size=6>ข้อใดเป็นมารยาทในการเขียน</FONT> ';
question_score[4] = '1';
choice[4] = new Array();

//* Question: 6********************
question[5] = '<FONT face=Tahoma size=6>ข้อใด<U>ไม่ใช่</U>วิธีเขียนพยัญชนะ</FONT> ';
question_score[5] = '1';
choice[5] = new Array();

//* Question: 7********************
question[6] = '<FONT face=Tahoma size=6>ข้อใดเป็นวรรณยุกต์ไทย</FONT>';
question_score[6] = '1';
choice[6] = new Array();

//* Question: 8********************
question[7] = '<FONT face=Tahoma size=6>พยัญชนะไทยมีกี่ตัว</FONT> ';
question_score[7] = '1';
choice[7] = new Array();

//* Question: 9********************
question[8] = '<FONT face=Tahoma size=6>ข้อใดไม่ใช่ประโยชน์ของการฝึกคัดลายมือ</FONT>';
question_score[8] = '1';
choice[8] = new Array();

//* Question: 10********************
question[9] = '<FONT face=Tahoma size=6>ข้อใดคือประโยชน์ของการเขียน</FONT> ';
question_score[9] = '1';
choice[9] = new Array();
choice[0][0] = new Array();
choice[0][0][0] = '<FONT face=Tahoma size=6>๑ ๒ ๓ ๔</FONT>';
choice[0][0][1] = '0';

choice[0][1] = new Array();
choice[0][1][0] = '<FONT face=Tahoma size=6>1 2 3 4</FONT>';
choice[0][1][1] = '0';

choice[0][2] = new Array();
choice[0][2][0] = '<FONT face=Tahoma size=6>ก ข ค ง</FONT> ';
choice[0][2][1] = '1';

choice[1][0] = new Array();
choice[1][0][0] = '<FONT face=Tahoma size=6>มีช่องไฟ ไม่มีวรรคตอน</FONT>';
choice[1][0][1] = '0';

choice[1][1] = new Array();
choice[1][1][0] = '<FONT face=Tahoma size=6>เขียนให้อ่านง่าย ไม่มีช่องไฟ</FONT> ';
choice[1][1][1] = '0';

choice[1][2] = new Array();
choice[1][2][0] = '<FONT face=Tahoma size=6>เขียนรูปแบบให้ถูกต้อง</FONT> ';
choice[1][2][1] = '1';

choice[2][0] = new Array();
choice[2][0][0] = '<FONT face=Tahoma size=6>ฝึกการจดจำ</FONT>';
choice[2][0][1] = '0';

choice[2][1] = new Array();
choice[2][1][0] = '<FONT face=Tahoma size=6>ฝึกการสังเกต</FONT> ';
choice[2][1][1] = '1';

choice[2][2] = new Array();
choice[2][2][0] = '<FONT face=Tahoma size=6>มีความรู้</FONT>';
choice[2][2][1] = '0';

choice[3][0] = new Array();
choice[3][0][0] = '<FONT face=Tahoma size=6>ภูมิใจในความเป็นไทย</FONT> ';
choice[3][0][1] = '1';

choice[3][1] = new Array();
choice[3][1][0] = '<FONT face=Tahoma size=6>รักภาษาไทย</FONT> ';
choice[3][1][1] = '0';

choice[3][2] = new Array();
choice[3][2][0] = '<FONT face=Tahoma size=6>เกิดเป็นคนไทย</FONT>';
choice[3][2][1] = '0';

choice[4][0] = new Array();
choice[4][0][0] = '<FONT face=Tahoma size=6>ถูกต้อง รวดเร็ว</FONT>';
choice[4][0][1] = '0';

choice[4][1] = new Array();
choice[4][1][0] = '<FONT face=Tahoma size=6>ถูกต้อง มีระเบียบ</FONT>';
choice[4][1][1] = '1';

choice[4][2] = new Array();
choice[4][2][0] = '<FONT face=Tahoma size=6>ถูกต้อง ชัดเจน</FONT> ';
choice[4][2][1] = '0';

choice[5][0] = new Array();
choice[5][0][0] = '<center><img src=\"asset/8_57.jpg\" border=0 name=\"img0\"></center>';
choice[5][0][1] = '0';

choice[5][1] = new Array();
choice[5][1][0] = '<center><img src=\"asset/8_58.jpg\" border=0 name=\"img0\"></center>';
choice[5][1][1] = '0';

choice[5][2] = new Array();
choice[5][2][0] = '<center><img src=\"asset/8_59.jpg\" border=0 name=\"img0\"></center>';
choice[5][2][1] = '1';

choice[6][0] = new Array();
choice[6][0][0] = '<FONT face=Tahoma size=6>พ ฟ ฒ ม</FONT>';
choice[6][0][1] = '0';

choice[6][1] = new Array();
choice[6][1][0] = '<FONT face=Tahoma size=6>ไม้เอก ไม้โท ไม้ตรี ไม้จัตวา</FONT> ';
choice[6][1][1] = '1';

choice[6][2] = new Array();
choice[6][2][0] = '<FONT face=Tahoma size=6>สระอะ สระอา สระอิ สระอี</FONT> ';
choice[6][2][1] = '0';

choice[7][0] = new Array();
choice[7][0][0] = '<FONT size=6 face=Tahoma>๔๔ ตัว</FONT> ';
choice[7][0][1] = '1';

choice[7][1] = new Array();
choice[7][1][0] = '<FONT size=6 face=Tahoma>๔๕ ตัว</FONT> ';
choice[7][1][1] = '0';

choice[7][2] = new Array();
choice[7][2][0] = '<FONT size=6 face=Tahoma>๔๖ ตัว</FONT> ';
choice[7][2][1] = '0';

choice[8][0] = new Array();
choice[8][0][0] = '<FONT face=Tahoma size=6>สร้างนิสัยความเป็นระเบียบ</FONT>';
choice[8][0][1] = '0';

choice[8][1] = new Array();
choice[8][1][0] = '<FONT face=Tahoma size=6>เพื่อใช้สำหรับการประกวดคัดลายมือ</FONT> ';
choice[8][1][1] = '1';

choice[8][2] = new Array();
choice[8][2][0] = '<FONT face=Tahoma size=6>เป็นการฝึกสมาธิ</FONT>';
choice[8][2][1] = '0';

choice[9][0] = new Array();
choice[9][0][0] = '<FONT face=Tahoma size=6>สื่อสารให้ผู้อื่นเข้าใจว่าเราเขียนสวย</FONT>';
choice[9][0][1] = '1';

choice[9][1] = new Array();
choice[9][1][0] = '<FONT face=Tahoma size=6>เพื่อแสดงให้ผู้อื่นเห็นว่าเราเขียนสวย</FONT>';
choice[9][1][1] = '0';

choice[9][2] = new Array();
choice[9][2][0] = '<FONT face=Tahoma size=6>เพื่อต้องการบอกผู้อื่นว่าเรามีความรู้</FONT>';
choice[9][2][1] = '0';




var fb_range = [];


var outChoice = "";
var outAns = "";
var cChoice = "กขคงจฉช";
//var cNo=new Array("0","1","2","3","4","5","6","7","8","9","10");
var cNo=new Array("๐","๑","๒","๓","๔","๕","๖","๗","๘","๙","๑๐");
var qid = 1;


function genQuestion(no,a,chkans,ans){
	
	if(chkans){
		var txtq = '<div id=q'+no+' name=q'+no+'  style="position:absolute; left:0cm; top:0.9cm; display :none; width:680">';
	}else{
		var txtq = '<div id=q'+no+' name=q'+no+' style="position:absolute; left:0cm; top:0.9cm; display :none; width:680" >';
//		var txtq = '<div id=q'+no+' name=q'+no+' style="position:absolute; left:2.5cm; top:2.5cm; visibility:visible">';
	}

//	txtq += '<div style="font-size: 20; text-align: center; vertical-align: bottom; color: #9900CC">&nbsp';
//	txtq +='<A HREF="javascript:if('+no+'>1) showhide('+(no-1)+')"><IMG SRC="asset/prev.gif" BORDER="0" ALT="กลับ"></A>&nbsp;&nbsp;&nbsp;';
//	txtq += '&nbsp;&nbsp;&nbsp; <span onclick="showhide(1)" style="cursor: pointer">1</span>&nbsp;&nbsp;&nbsp; <span onclick="showhide(2)" style="cursor: pointer">2</span>&nbsp;&nbsp;&nbsp; <span onclick="showhide(3)" style="cursor: pointer">3</span>&nbsp;&nbsp;&nbsp; <span onclick="showhide(4)" style="cursor: pointer">4</span>&nbsp;&nbsp;&nbsp; <span onclick="showhide(5)" style="cursor: pointer">5</span>&nbsp;&nbsp;&nbsp; <span onclick="showhide(6)" style="cursor: pointer">6</span>&nbsp;&nbsp;&nbsp; <span onclick="showhide(7)" style="cursor: pointer">7</span>&nbsp;&nbsp;&nbsp; <span onclick="showhide(8)" style="cursor: pointer">8</span>&nbsp;&nbsp;&nbsp; <span onclick="showhide(9)" style="cursor: pointer">9</span> &nbsp;&nbsp;&nbsp;<span onclick="showhide(10)" style="cursor: pointer">10</span> &nbsp;&nbsp;&nbsp;';
//	txtq += '&nbsp;&nbsp;&nbsp; <span onclick="showhide(1)" style="cursor: pointer">๑</span>&nbsp;&nbsp;&nbsp; <span onclick="showhide(2)" style="cursor: pointer">๒</span>&nbsp;&nbsp;&nbsp; <span onclick="showhide(3)" style="cursor: pointer">๓</span>&nbsp;&nbsp;&nbsp; <span onclick="showhide(4)" style="cursor: pointer">๔</span>&nbsp;&nbsp;&nbsp; <span onclick="showhide(5)" style="cursor: pointer">๕</span>&nbsp;&nbsp;&nbsp; <span onclick="showhide(6)" style="cursor: pointer">๖</span>&nbsp;&nbsp;&nbsp; <span onclick="showhide(7)" style="cursor: pointer">๗</span>&nbsp;&nbsp;&nbsp; <span onclick="showhide(8)" style="cursor: pointer">๘</span>&nbsp;&nbsp;&nbsp; <span onclick="showhide(9)" style="cursor: pointer">๙</span> &nbsp;&nbsp;&nbsp;<span onclick="showhide(10)" style="cursor: pointer">๑๐</span> &nbsp;&nbsp;&nbsp;';

//	txtq +='&nbsp;&nbsp;&nbsp;<A HREF="javascript:if('+no+'<10) showhide('+(no+1)+')"><IMG SRC="asset/next.gif" BORDER="0" ALT="ต่อไป"></A>';
//	txtq += '</div>';
	
		txtq += '<table width="680" border="0" cellspacing="0" cellpadding="4">';
	if(question[a]){
		
		txtq += '<tr bgcolor="#F5F5F5"> ';
		txtq += '<td width="25" align="right" valign=top>';
		txtq += '<IMG SRC="asset/speaker.png" WIDTH="30" HEIGHT="30" BORDER="0" ALT="ฟังเสียง"  style="cursor: pointer" onclick="qPlayer(\''+no+'\')">';
//		txtq += '<strong><font size="6" face="Tahoma">'+cNo[no]+'.</font></strong></td>';
//	if(no==1) txtq += '<td valign="bottom"><font size="6" face="THSarabunPSKBold">';
		txtq += '<td valign="top"><font size="6" face="THSarabunPSKBold">';
		txtq += ' '+cNo[no]+'. ';
		txtq += question[a];
		txtq += '</font></td>';
		txtq += '</tr>';

		bgc = "#F5F5F5";
		if (no%2) bgc = "#CCFFCC";

		if(chkans){
			outChoice +=  '<tr id="tq'+no+'" bgcolor="'+bgc+'" onclick="showhide('+no+');showbg('+no+')" ><td width="25" align="center"><div id="cho_'+no+'" style="color: #000000;font-family:THSarabunPSKBold; font-size: 22">'+cNo[no]+'.</div></td>';
		}else{
			outChoice +=  '<tr id="tq'+no+'" bgcolor="'+bgc+'" onclick="showhide('+no+');" ><td width="25" align="center"><div id="cho_'+no+'" style="color: #000000;font-family:THSarabunPSKBold; font-size: 22">'+cNo[no]+'.</div></td>';
		}

		var correct = false;
		var txtch = '<table width="100%" border="0" cellspacing="5" cellpadding="5">';
		for(c=0;c<choice[a].length;c++)
		{
			var ch_radio = '<font size="6" face="THSarabunPSKBold">'+cChoice.charAt(c)+'.</font>';
			if(chkans){
//				outChoice +=  '<td align="center"><input type="radio" name="ch_'+no+'" value="'+c+'" class="bigButton"  ';
				outChoice +=  '<td align="center"><span id="tch_'+no+'_'+c+'" name="tch_'+no+'_'+c+'" > ';
				txtch += '<tr valign="middle"> ';
			}else{
//				outChoice +=  '<td align="center"><input type="radio" name="ch_'+no+'" value="'+c+'" onClick="setAns('+no+','+c+')"   class="bigButton" ';
				outChoice +=  '<td align="center" onClick="setAns('+no+','+c+')"><input type="radio" name="ch_'+no+'" value="'+c+'" style="position:absolute; display :none"><span id="tch_'+no+'_'+c+'" name="tch_'+no+'_'+c+'" style="cursor: pointer;"><img src=asset/c.gif>';
				txtch += '<tr valign="middle"   > ';
			}
			
//			var ch_radio = '<input type="radio" name="ch_'+no+'" value="'+c+'"';

			if(chkans){
				if(ans==c){
//					outChoice +=' checked';
					outChoice +='<img src=asset/m.gif>';
					outAns += 'document.getElementById(\'ch_'+no+'_'+c+'\').style.backgroundImage = "url(asset/ans.gif)"; ';


					if(choice[a][c][1] == 1){
						score+=parseInt(question_score[a]);
						correct = true;
					}
				txtch += '<td width=17 align="center" valign="top">&nbsp;<img src=asset/';
				txtch += (correct)?'1':'0';
				txtch += '.gif></td>';

				}
				else
				{
//					outChoice += ' disabled';
					outChoice +='<img width=21 src=asset/spacer.gif>';
					txtch += '<td width=17 align="center" valign="top">&nbsp;';
					if(showanswer){
						if(choice[a][c][1] == 1){
							txtch += '<img src=asset/1.gif>';
							//ch_radio = '<img src=asset/arrow.gif>';
							choice[a][c][0] = '<font color=GREEN>'+choice[a][c][0]+'</font>';
						}
					}
					txtch += '</td>';
				}
			}

			outChoice += '</span></td>';
			
			var answer_icon = '';
			if(chkans){
				answer_icon = '<img src=asset/';
				answer_icon += (correct)?'1':'0';
				answer_icon += '.gif>';
			}
		
			txtch += '<td width="30" valign="top"><IMG SRC="asset/speaker.png" WIDTH="30" HEIGHT="30" BORDER="0" ALT="ฟังเสียง"  style="cursor: pointer" onclick="chPlayer(\''+no+'-'+(parseInt(c)+1)+'\')"></td>';
			txtch += '<td width="25" align="center"  valign="top" class="bgimage" name="ch_'+no+'_'+c+'" id="ch_'+no+'_'+c+'" onClick="setAns('+no+','+c+')" style="cursor: pointer">';

			txtch += ch_radio;
			txtch += '</td>';
			txtch += '<td valign="top">';
			txtch += choice[a][c][0];
			txtch += '</td>';
			txtch += '</tr>';
		}
		txtch += '</table>';

//		txtq += '<tr><td align="center">'+answer_icon+'</td>';
		txtq += '<tr><td align="center">&nbsp;</td>';
		txtq += '<td valign="top">';
		txtq += txtch;
		txtq += '</td></tr>';
		if (chkans) {
			outChoice += '<td align="center">'+answer_icon+'</td></tr>';

		}else{
			outChoice += '</td></tr>';
		}
	
	}

	txtq += '</table><br>';
	txtq += '</div>';
//alert(txtq);
//alert(outChoice);
	return txtq;
}

		function checkAnswer(frm){
			var chr = checkRadio(frm);
			if(chr=="0")
			{

				var el = frm.elements; 
				var sel = '';
				var sel2 = new Array();
				var s = 0;
				for(var i = 0 ; i < el.length ; ++i) { 
					if(el[i].type == "radio") {   
						var radiogroup = el[el[i].name];   
						sel2[s] = el[i].name;
						var itemchecked = false;  
						for(var j = 0 ; j < radiogroup.length ; ++j) {    
							if(radiogroup[j].checked) {	 

								if(s > 0)
								{
									if(sel2[(s-1)] != el[i].name)
									{						
										if(sel == '') sel = radiogroup[j].value; else sel += ':'+radiogroup[j].value;
									}
								}
								else
								{
									if(sel == '') sel = radiogroup[j].value; else sel += ':'+radiogroup[j].value;
								}
								s++;
							}   
						}   
					} 
				} 


				if(sel == '')
				{
					alert(system_message['mustdoquiz']);
				}
				else
				{
					var sel3 = sel.split(':');
					var text_ans = '';
					var e = 1;
					var txt_show = '';
					var divtst = document.getElementById("divTest");
					divtst.innerHTML = "";

//					document.write('<style type="text/css">.bgimage { background-image: url(asset/spacer.gif); background-repeat: no-repeat; background-position: top; font-family:"THSarabunPSKBold"; font-size: 28 } .choice {cursor: pointer}</style>');
txt_show += ('<style type="text/css">.bgimage { background-image: url(asset/spacer.gif); background-repeat: no-repeat; background-position: top; font-family:THSarabunPSKBold; font-size: 30 } .choice {cursor: pointer} @font-face {    font-family: \'THSarabunPSKBold\';    src: url(\'thsarabun_bold-webfont.eot\');    src: url(\'thsarabun_bold-webfont.eot?#iefix\') format(\'embedded-opentype\'),         url(\'thsarabun_bold-webfont.woff\') format(\'woff\'),         url(\'thsarabun_bold-webfont.ttf\') format(\'truetype\'),         url(\'thsarabun_bold-webfont.svg#THSarabunPSKBold\') format(\'svg\');    font-weight: normal;    font-style: normal;}font{	font-family: \'THSarabunPSKBold\';	font-size: 30;}.bigButton{	width: 28px; height: 28px;cursor: pointer;}</style>');

					if(showanswer)
//						document.write('<font size=4 face="Tahoma" color=#FF0000> ( '+system_message['remark']+' ) </font><br>&nbsp;');

//-----1----???????????????????
						outChoice = "";
						txt_show += ('<div id="divTest2" style="position:absolute;left:0.0cm; top:0.0cm; width:100% " >');
						txt_show += ('<table width="100%" border="0" cellspacing="0" cellpadding="2">');
						txt_show += ('  <tr bgcolor=#FBFBFB> ');
						txt_show += ('    <td width="700"><span style="width:700px;height:450px;overflow:auto;">');
//					document.write('<div style="position:absolute; left:0cm; top:0cm;  width:680" ><center><strong><font size=4 face="Tahoma"><U>'+system_message['chkanswer']+'</U>&nbsp;&nbsp; </font></strong></center><p>');
						txt_show += ('<div style="position:absolute; left:0cm; top:0cm;  width:680" >&nbsp;&nbsp;&nbsp;<font size=5 face="THSarabunPSKBold" color=#0033FF><span style="font-size: 28">คลิกเลือกข้อแบบทดสอบ เพื่อดูคำตอบที่ถูกต้อง</span></font></div>');
//	document.write('<div style="position:absolute; left:0cm; top:0cm;  width:680" ><span style="font-size: 28">&nbsp;&nbsp;&nbsp;'+direction+' </span></div>');
//-----1----

						for(e=0;e<random_question;e++){
							txt_show += (genQuestion((e+1),e,true,sel3[e]));	
						}

//-----2----???????????????????
						txt_show += ('</span>    </td >');
						txt_show += ('    <td valign=top>');
						txt_show += ('      <table id="tq" width="100%" border="1" cellspacing="0" cellpadding="2" bgcolor=#D8D6D7>');
						txt_show += ('		<tr><td rowspan="2" align="center">ข้อ</td ><td colspan="'+(choice[1].length+1)+'" align="center">ตัวเลือก</td >');
						txt_show += ('		<tr>');
						for(c=0;c<choice[1].length;c++)
						{
							txt_show += ('			<td align="center">'+cChoice.charAt(c)+'</td >');
						}
							txt_show += ('			<td align="center">&nbsp;</td >');
							txt_show += ('		</tr>');
							txt_show += (outChoice);
							txt_show += ('        </table>');
							txt_show += ('    </td >');
							txt_show += ('  </tr></table>');
							txt_show += ('  </div>');
		//-----2----


							displayMsg(score,sel3.length);
					}
					txt_show += ('<SCRIPT LANGUAGE="JavaScript">qid = 1;var agt=navigator.userAgent.toLowerCase();var browser_ie  = (agt.indexOf("msie") != -1);var browser_ns  = (navigator.appName.indexOf("Netscape") != -1); function showhide(id){ if(id == 66) id = qid>1?qid-1:qid;if(id == 99) id = qid<10?qid+1:qid;if(qid != id ) qid = id;for(i=0;i<'+random_question+';i++){document.getElementById(\'q\'+(i+1)).style.display = \'none\';document.getElementById(\'cho_\'+(i+1)).style.color = \'#000000\';document.getElementById(\'cho_\'+(i+1)).style.fontSize = 22;parent.document.getElementById(\'numq_\'+(i+1)).style.color = "#3366FF";}document.getElementById(\'q\'+id).style.display = \'block\';document.getElementById(\'cho_\'+id).style.color = \'#FF00CC\';document.getElementById(\'cho_\'+id).style.fontSize = 22;parent.document.getElementById(\'numq_\'+id).style.color = "#FF0099";startPlayer(id);showbg(id);} function moAns(tr,n){	tr.bgColor="#FFCCCC";} function muAns(tr,n){	if (n%2) bgc = "#CCFFCC";	else bgc = "#F5F5F5";	tr.bgColor=bgc;} function startPlayer(id) { if(qid != id ) {qid = id;src =  "./sound/"+id+".mp3";var wmObject = document.getElementById(\'wmp_p\');if(browser_ie) wmObject.fileName = src;else{ wmObject.src = src; wmObject.play();}}    }function qPlayer(id) { if(window.android){ window.android.playSound(id+".mp3"); } else{ var wmObject = document.getElementById(\'wmp_p\');src =  "./sound/"+id+".mp3";if(browser_ie) wmObject.fileName = src;else{ wmObject.src = src; wmObject.play();} }    }function chPlayer(chid) { if(window.android){ window.android.playSound(chid+".mp3"); } else{ var wmObject = document.getElementById(\'wmp_p\');src =  "./sound/"+chid+".mp3";if(browser_ie) wmObject.fileName = src;else{ wmObject.src = src; wmObject.play();} }   }function showbg(n){for (i=1; i<=10 ; i++ ){ var tq = "tq"+i; if (i%2) bgc = "#CCFFCC"; else bgc = "#F5F5F5"; document.getElementById(tq).bgColor = bgc;} document.getElementById("tq"+n).bgColor = "#FFCCCC";}function showtBox(n) { document.getElementById(\'tBox_\'+n).style.display = \'block\'; } function hiddentBox(n) { document.getElementById(\'tBox_\'+n).style.display = \'none\'; }'+outAns+'</SCRIPT>');

					if(browser_ie) txt_show += (wmp_ie());
					else txt_show += (wmp_ns());
					
					//showhide('1');
					document.write(txt_show+"<script>showhide('1');</script>");			}else{
				alert(system_message['mustdoquiz'] +" (ข้อ "+chr.substring(3)+") ");
			}
		}
						
		function checkRadio(frm) { 
			var el = frm.elements; 
			for(var i = 0 ; i < el.length ; ++i) {  
				if(el[i].type == "radio") {   
					var radiogroup = el[el[i].name];   
					var itemchecked = false;   
					for(var j = 0 ; j < radiogroup.length ; ++j) {    
						if(radiogroup[j].checked) {	 
							itemchecked = true;	 
							break;	
						}   
					}   
					if(!itemchecked) { 
						return el[i].name;   
					}  
				} 
			} 
			return "0";
		} 


if(random_question <= 0) random_question = question.length;

function RandomQuestion(){
	var Len = random_question;
	var j = question.length;
	var num = new Array();
	
	for (i=0; i<Len; i++){
		n = Math.floor(j  *  Math.random());
		if(num[n]) 
			i--;
		else
			num[n] = 1;
	}

	var q = new Array();
	var ch = new Array();
	var i = 0;
	for(var id in num){
		q[i] = question[id];
		ch[i] = choice[id];
		i++;
	}

	question = q;
	choice = ch;
}

function RandomSuit(suit){		
	Temp = new Array();		
	TempCh = new Array();		
	var Len = suit.length;		
	var j = Len;		
	
	for (var i=0; i<Len; i++)
	{				
		Temp[i] = suit[i];			
	}			
	
	for (i=0; i<Len; i++)
	{				
		Num = Math.floor(j  *  Math.random());				
		suit[i] = Temp[Num];					
		for (var k=Num; k < j; k++) 
		{						
			Temp[k] = Temp[k+1];						
		}				
		
		j--;				
	}		

	return suit;
}


//if(direction == '') direction = '????????????????';
//if(direction == '') direction = system_message['direction'];
direction = system_message['direction'];

document.write('<style type="text/css">.bgimage { background-image: url(asset/spacer.gif); background-repeat: no-repeat; background-position: top; font-family:THSarabunPSKBold; font-size: 30 } .choice {cursor: pointer} @font-face {    font-family: \'THSarabunPSKBold\';    src: url(\'thsarabun_bold-webfont.eot\');    src: url(\'thsarabun_bold-webfont.eot?#iefix\') format(\'embedded-opentype\'),         url(\'thsarabun_bold-webfont.woff\') format(\'woff\'),         url(\'thsarabun_bold-webfont.ttf\') format(\'truetype\'),         url(\'thsarabun_bold-webfont.svg#THSarabunPSKBold\') format(\'svg\');    font-weight: normal;    font-style: normal;}font{	font-family: \'THSarabunPSKBold\';	font-size: 30;}</style>');
document.write('<a name="top"></a>');
document.write('<form name="frmexam" method="post">');				
document.write('<div id="divTest" style="position:absolute;left:0.0cm; top:0.0cm; z-index:1;width:100% " >');

//-----1----..........................
	document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
	document.write('  <tr bgcolor=#FBFBFB> ');
	document.write('    <td width="700"><span style="width:700px;height:450px;overflow:auto;">');
	document.write('<div style="position:absolute; left:0cm; top:0cm;  width:680" ><font size=5 face="THSarabunPSKBold" color=#0033FF><span style="font-size: 28">&nbsp;&nbsp;&nbsp;'+direction+' </span> </font></div>');
//-----1----

if(testformat==2){
	document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
	document.write('  <tr bgcolor=#FBFBFB> ');
	document.write('    <td  width=50 align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">'+tf_label_true+'</font></td>');
	document.write('    <td  width=50 align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">'+tf_label_false+'</font></td>');
	document.write('    <td  align="center">&nbsp;</td>');
	document.write('  </tr>');
}

if(shuffle_question) RandomQuestion();

for(i=0;i<random_question;i++){
	if(random_choice) choice[i] = RandomSuit(choice[i]);
	document.write(genQuestion((i+1),i,false,0));
}

//-----2----..........................
	document.write('</span>    </td >');
	document.write('    <td valign=top>');
//	document.write('<CENTER><BR><input type="button" name="Submit" value="ส่งตรวจ" onclick="checkAnswer(document.frmexam)"></CENTER>');
	document.write('<IMG SRC="asset/spacer.gif" WIDTH="1" HEIGHT="5"><table id="tq" width="100%" border="1" cellspacing="0" cellpadding="2" bgcolor=#D8D6D7>');
	document.write('		<tr><td rowspan="2"  align="center">ข้อ</td ><td colspan="'+choice[1].length+'" align="center">ตัวเลือก</td >');
	document.write('		<tr>');
		for(c=0;c<choice[1].length;c++)
		{
			document.write('			<td align="center">'+cChoice.charAt(c)+'</td >');
		}
	document.write('		</tr>');
	document.write(outChoice);
	document.write('        </table>');
	document.write('<CENTER><IMG SRC="asset/spacer.gif" WIDTH="1" HEIGHT="5"><BR><input type="button" name="Submit" value="&nbsp;&nbsp;&nbsp;ส่งตรวจ&nbsp;&nbsp;&nbsp;" onclick="checkAnswer(document.frmexam)" style="font-size: 18"></CENTER>');
	document.write('    </td >');
	document.write('  </tr></table>');
//-----2----

document.write('</div>');
document.write('</form>');
//alert(outChoice);

function showhide(id){ //alert(qid);
	if(id == 66) id = qid>1?qid-1:qid;
	if(id == 99) id = qid<10?qid+1:qid;
	if(qid != id ) qid = id;

	for(i=0;i<random_question;i++){
		document.getElementById('q'+(i+1)).style.display  = 'none';
		document.getElementById('cho_'+(i+1)).style.color  = '#000000';
		document.getElementById('cho_'+(i+1)).style.fontSize     = 22;
		parent.document.getElementById('numq_'+(i+1)).style.color = "#3366FF";
	}
	document.getElementById('q'+id).style.display  = 'block';
	document.getElementById('cho_'+id).style.color  = '#FF00CC';
	document.getElementById('cho_'+id).style.fontSize   = 22;
	parent.document.getElementById('numq_'+id).style.color = "#FF0099";

	startPlayer(id);
	showbg(id);
} 

function showbg(n){

	for (i=1; i<=10 ; i++ )
	{
		var tq = "tq"+i;
		if (i%2) bgc = "#CCFFCC";
		else bgc = "#F5F5F5";

		document.getElementById(tq).bgColor = bgc;
	}
	document.getElementById("tq"+n).bgColor = "#FFCCCC";
}

var agt=navigator.userAgent.toLowerCase();
var browser_ie  = (agt.indexOf("msie") != -1);
var browser_ns  = (navigator.appName.indexOf("Netscape") != -1);

//alert(browser_ie);
//alert(browser_ns);
if(browser_ie) document.write(wmp_ie());
else document.write(wmp_ns());

	function startPlayer(id) { //alert(qid+":"+id);
		if(qid != id ) {
			qid = id;
			src =  "./sound/"+id+".mp3";

			var wmObject = document.getElementById('wmp_p');
			if(browser_ie) wmObject.fileName = src;
			else{ wmObject.src = src; wmObject.play();}
		}
    }

	function qPlayer(id) { 
		if(window.android){
				window.android.playSound(id+".mp3");
		}
		else{
			var wmObject = document.getElementById('wmp_p');
			src =  "./sound/"+id+".mp3";
			if(browser_ie) wmObject.fileName = src;
			else{ wmObject.src = src; wmObject.play();}
		}
    }
	function chPlayer(chid) { 
		if(window.android){
				window.android.playSound(chid+".mp3");
		}
		else{
			var wmObject = document.getElementById('wmp_p');
			src =  "./sound/"+chid+".mp3";
			if(browser_ie) wmObject.fileName = src;
			else{ wmObject.src = src; wmObject.play();}
		}
    }
		function wmp_ns() {
	s = '<audio id="wmp_p" width="0" height="0" src="">';
	s += '</audio>';
	return s;
    }

	function wmp_ie() {
	var fb_sound = "";
	
	var s = '';
	s += '<OBJECT ID="wmp_p" name="wmp_p" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" ';
	s += 'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ';
	s += 'standby="Loading Microsoft? Windows? Media Player components..." ';
	s += 'type="application/x-oleobject" width="1" height="1">';
	s += '<PARAM NAME="FileName" value="'+fb_sound+'">';
	s += '<param name="ShowControls" value="1">';
	s += '<param name="ShowPositionControls" value="0">';
	s += '<param name="ShowAudioControls" value="1">';
	s += '<param name="ShowTracker" value="0">';
	s += '<param name="ShowDisplay" value="0">';
	s += '<param name="ShowStatusBar" value="1">';
	s += '<param name="AutoSize" value="0">';
	s += '<param name="ShowGotoBar" value="0">';
	s += '<param name="ShowCaptioning" value="0">';
	s += '<param name="AutoStart" value="1">';
	s += '<param name="AnimationAtStart" value="0">';
	s += '<param name="TransparentAtStart" value="0">';
	s += '<param name="AllowScan" value="1">';
	s += '<param name="EnableContextMenu" value="1">';
	s +='<param name="Volume" value="80">';
	s += '<param name="ClickToPlay" value="0">';
	s += '<EMBED type="application/x-mplayer2" ';
	s += 'pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" ';
	s += 'src="'+fb_sound+'"	';
	s += 'name="wmp_p"	';
	s += 'id="wmp_p"	';
	s += 'width=1	';
	s += 'height=1	';
	s += 'autostart=0 ';
	s +='Volume=80 ';
	s += 'showcontrols=1	showpositioncontrols=0	showstatusbar=0	showcaptioning=0>';
	s += '</EMBED>';
	s += '</OBJECT>';
//alert(s);
	return s;
}


//----- ......................
function moAns(tr,n){
	tr.bgColor='#FFCCCC';
}
function muAns(tr,n){
	if (n%2) bgc = "#CCFFCC";
	else bgc = "#F5F5F5";
	tr.bgColor=bgc;
}
function setAns(n,c){
	var Ans = "url(asset/ans.gif)";
	var cAns = "url(asset/spacer.gif)";
	for(var i=0; i<choice[1].length; i++) {
		document.getElementById('ch_'+n+'_'+i).style.backgroundImage = cAns;
		document.getElementById('tch_'+n+'_'+i).innerHTML = "<img src=asset/c.gif>";
	}
	elm = eval("document.frmexam.ch_"+n);
	elm[c].checked = true;
	document.getElementById('ch_'+n+'_'+c).style.backgroundImage = Ans;
	document.getElementById('tch_'+n+'_'+c).innerHTML = "<img src=asset/m.gif>";
//	alert(n+":"+c);
}
function AtoT(data){
	var cNo=new Array("๐","๑","๒","๓","๔","๕","๖","๗","๘","๙","๑๐");
	var outdata = "";
	data += '';

	for(i=0;i<data.length;i++){
		outdata += cNo[data.substr(i,1)];
	}
	return outdata;
}

   function showtBox(n) { document.getElementById('tBox_'+n).style.display = 'block'; }
   function hiddentBox(n) { document.getElementById('tBox_'+n).style.display = 'none'; }

showhide('1');
//-------------------


/*
var fb_range = new Array();
fb_range[0] = new Array();
fb_range[0][0] = 0;
fb_range[0][1] = 100;
fb_range[0][2] = 'aaaaa';
fb_range[0][3] = 'asset/';
fb_range[0][4] = 'aaaaaa.wma';

document.write(codeMediaFeedback('55'));
*/




function Feedback(score){
	var show = '';
	var scr = Math.floor(score);
	if(!isNaN(scr)){
		if(typeof(fb_range) != 'undefined'){

			for(var i=0;i<fb_range.length;i++){
				if((fb_range[i][0] == scr) || (fb_range[i][1] == 1) || ((fb_range[i][0] <= scr) && (fb_range[i][1] >= scr))){

					if(fb_range[i][4] != ''){
						var fb_sound = fb_range[i][3]+fb_range[i][4];
						var fb_sound_holder = sound(fb_sound);
						var fb_layer = drawLayer(fb_sound_holder,'ContentHolderFB',0, 0, 0, 0, 2, 0);
						document.body.innerHTML += fb_layer;
					}

					if(fb_range[i][2] != ''){ 
//						alert(fb_range[i][2]);
						show = fb_range[i][2];
					}

					break;
				}
			}
		}
	}

//	return (show)?true:false;
	return show;
}


function codeMediaFeedback(v){
	var fb_sound = fb_range[v][3]+fb_range[v][4];
	
	var s = '';
	s += '<OBJECT ID="MediaPlayerFB'+v+'" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" ';
	s += 'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ';
	s += 'standby="Loading Microsoft? Windows? Media Player components..." ';
	s += 'type="application/x-oleobject" width="1" height="1">';
	s += '<PARAM NAME="FileName" value="'+fb_sound+'">';
	s += '<param name="ShowControls" value="1">';
	s += '<param name="ShowPositionControls" value="0">';
	s += '<param name="ShowAudioControls" value="1">';
	s += '<param name="ShowTracker" value="0">';
	s += '<param name="ShowDisplay" value="0">';
	s += '<param name="ShowStatusBar" value="1">';
	s += '<param name="AutoSize" value="0">';
	s += '<param name="ShowGotoBar" value="0">';
	s += '<param name="ShowCaptioning" value="0">';
	s += '<param name="AutoStart" value="0">';
	s += '<param name="AnimationAtStart" value="0">';
	s += '<param name="TransparentAtStart" value="0">';
	s += '<param name="AllowScan" value="1">';
	s += '<param name="EnableContextMenu" value="1">';
	s +='<param name="Volume" value="100">';
	s += '<param name="ClickToPlay" value="0">';
	s += '<EMBED type="application/x-mplayer2" ';
	s += 'pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" ';
	s += 'src="'+fb_sound+'"	';
	s += 'name="MediaPlayerFB'+v+'"	';
	s += 'width=1	';
	s += 'height=1	';
	s += 'autostart=0 ';
	s +='Volume=100 ';
	s += 'showcontrols=1	showpositioncontrols=0	showstatusbar=0	showcaptioning=0>';
	s += '</EMBED>';
	s += '</OBJECT>';

	return s;
}



function displayMsg(score,total){
	var test_result = "failed";
	var scr = Math.floor((score/total)*100);

	/*
	var msg = '?????????? '+score+' ???\n???????? '+total+' ???';
	msg+='\n???? '+scr+'%';

	if(!thai) msg = 'Your mark is '+scr+' %';
	*/
	
	var msg = system_message['score'];
	msg = parent.replaceAll(msg, '{score}', score);
	msg = parent.replaceAll(msg, '{total_score}', total);
	msg = parent.replaceAll(msg, '{pc_score}', scr);

	if(parent.usescorm){
		if(score_save){
			parent.doLMSSetValue("cmi.core.score.raw",scr);
			parent.doLMSSetValue("cmi.suspend_data",suspend_data);
			parent.doLMSCommit();
		}
	}

	var fb_msg = Feedback(scr);
	if(fb_msg != '') msg = fb_msg + '\n\n'+msg;

	alert(msg);


}
