/*** 1575 ***/


var scoid=parent.scoid;
var direction = '<P><FONT size=5 face=Tahoma>จงเลือกคำตอบที่ถูกต้อง</FONT></P>';
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 size=5 face=Tahoma>นพ.บุญส่ง เลขะกุล เป็นบิดาแห่งอะไร</FONT>  <P>&nbsp;</P>';
question_score[0] = '1';
choice[0] = new Array();

//* Question: 2********************
question[1] = '<FONT size=5 face=Tahoma>นพ.บุญส่ง เลขะกุล และสมาชิกนิยมไพรสมาคม ได้ก่อตั้งมูลนิธิอะไร</FONT>';
question_score[1] = '1';
choice[1] = new Array();

//* Question: 3********************
question[2] = '<FONT size=5 face=Tahoma>นพ.บุญส่ง เลขะกุล ได้รับรางวัลอะไร</FONT>';
question_score[2] = '1';
choice[2] = new Array();
choice[0][0] = new Array();
choice[0][0][0] = '<FONT size=5 face=Tahoma>บิดาแห่งการแพทย์ไทย</FONT>';
choice[0][0][1] = '0';

choice[0][1] = new Array();
choice[0][1][0] = '<FONT size=5 face=Tahoma>บิดาแห่งวงการวิทยาศาสตร์ไทย</FONT>';
choice[0][1][1] = '0';

choice[0][2] = new Array();
choice[0][2][0] = '<FONT size=5 face=Tahoma>บิดาแห่งการอนุรักษ์นกและธรรมชาติไทย</FONT>';
choice[0][2][1] = '1';

choice[1][0] = new Array();
choice[1][0][0] = '<FONT size=5 face=Tahoma>มูลนิธิสืบ นาคะเสถียร</FONT>';
choice[1][0][1] = '0';

choice[1][1] = new Array();
choice[1][1][0] = '<FONT size=5 face=Tahoma>มูลนิธิสร้างสรรค์เด็ก</FONT>';
choice[1][1][1] = '0';

choice[1][2] = new Array();
choice[1][2][0] = '<FONT size=5 face=Tahoma>มูลนิธิคุ้มครองสัตว์ป่าและพรรณพืชแห่งประเทศไทย</FONT>';
choice[1][2][1] = '1';

choice[2][0] = new Array();
choice[2][0][0] = '<FONT size=5 face=Tahoma>รางวัลโนเบล</FONT>';
choice[2][0][1] = '0';

choice[2][1] = new Array();
choice[2][1][0] = '<FONT size=5 face=Tahoma>รางวัลแมกไซไซ</FONT>';
choice[2][1][1] = '1';

choice[2][2] = new Array();
choice[2][2][0] = '<FONT size=5 face=Tahoma>รางวัลนักอนุรักษ์</FONT>';
choice[2][2][1] = '0';




var fb_range = [];
var cNo=new Array("๐","๑","๒","๓","๔","๕","๖","๗","๘","๙","๑๐");






function genQuestion(no,a,chkans,ans){
	var txtq = '<table width="100%" border="0" cellspacing="0" cellpadding="4">';
	if(question[a]){
		
		txtq += '<tr bgcolor="#F5F5F5"> ';
		txtq += '<td width="25" align="right" valign=top><strong>';
		txtq += '<font size="6" face="MS Sans Serif, Tahoma, sans-serif">'+cNo[no]+'.</font></strong></td>';

		txtq += '<td valign="top"><strong><font size="3" face="MS Sans Serif, Tahoma, sans-serif">';
		txtq += question[a];
		txtq += '</font></strong></td>';
		txtq += '</tr>';

		var correct = false;
		var txtch = '<table width="100%" border="0" cellspacing="0" cellpadding="2">';
		for(c=0;c<choice[a].length;c++)
		{
			txtch += '<tr> ';
			txtch += '<td width="25" align="center" valign="top">';
			
			var ch_radio = '<input type="radio" name="ch_'+no+'" value="'+c+'"';
			if(chkans){
				if(ans==c){
					ch_radio +=' checked';

					if(choice[a][c][1] == 1){
						score+=parseInt(question_score[a]);
						correct = true;
					}

				}
				else
				{
					ch_radio += ' disabled';
					if(showanswer){
						if(choice[a][c][1] == 1){
							ch_radio = '<img src=asset/arrow.gif';
							choice[a][c][0] = '<font color=#FF0000>'+choice[a][c][0]+'</font>';
						}
					}
				}
			}

			ch_radio += '>';
			
			var answer_icon = '';
			if(chkans){
				answer_icon = '<img src=asset/';
				answer_icon += (correct)?'1':'0';
				answer_icon += '.gif>';
			}
		
			txtch += ch_radio;
			txtch += '</td>';
			txtch += '<td><font size="3" face="MS Sans Serif, Tahoma, sans-serif">';
			txtch += choice[a][c][0];
			txtch += '</font></td>';
			txtch += '</tr>';
		}
		txtch += '</table>';

		txtq += '<tr><td align="center">'+answer_icon+'</td>';
		txtq += '<td valign="top">';
		txtq += txtch;
		txtq += '</td></tr>';
	}

	txtq += '</table><br>';

	return txtq;
}





						function checkAnswer(frm){
							if(checkRadio(frm))
							{

								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('<center><strong><font size=3 face="MS Sans Serif, Tahoma, sans-serif"><U>'+system_message['chkanswer']+'</U>&nbsp;&nbsp; </font></strong></center><p>');

									if(showanswer)
										document.write('<font size=1 face="MS Sans Serif, Tahoma, sans-serif" color=#FF0000>'+system_message['remark']+'</font><br>&nbsp;');

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

									displayMsg(score,sel3.length);

								}
							}
							else
							{
								alert(system_message['mustdoquiz']);
							}
						}
						
				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 false;   }  } } return true;} 


				


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

//function RandomQuestion(){		Temp = new Array();		TempCh = new Array();		var Len = random_question;		var j = Len;		for (var i=0; i<Len; i++){				Temp[i] = question[i];			TempCh[i] = choice[i];		}			for (i=0; i<Len; i++){				Num = Math.floor(j  *  Math.random());				question[i] = Temp[Num];					choice[i] = TempCh[Num];				for (var k=Num; k < j; k++) {						Temp[k] = Temp[k+1];						TempCh[k] = TempCh[k+1];				}				j--;				}		}

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'];


document.write('<a name="top"></a>');
document.write('<form name="frmexam" method="post">');				
document.write('<div id="divTest" style="position:absolute;z-index:1; ">');
document.write('<p>'+direction+'</p>');

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

document.write('<p align=center><input type="button" name="Submit" value="Check Answer" onclick="checkAnswer(document.frmexam)"></p>&nbsp;<p>&nbsp;');
document.write('</div>');
document.write('</form>');


/*
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??????t '+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);


}
