/*** 670 ***/


var scoid=parent.scoid;
var direction = '<FONT color=#333333 size=6 face=Tahoma><STRONG>อ่านเรื่องเที่ยวดอนหอยหลอดแล้วตอบคำถามให้ถูกต้อง</STRONG></FONT> ';
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= 2;
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 color=#333333 size=6 face=Tahoma>การเดินทางไปยังดอนหอยหลอดสามารถเดินทางได้ทางเรือเท่านั้น</FONT>';
question_score[0] = '1';
choice[0] = new Array();

//* Question: 2********************
question[1] = '<FONT color=#333333 size=6 face=Tahoma>บริเวณหาดเลนเป็นที่อยู่อาศัยของหอยหลอด</FONT> ';
question_score[1] = '1';
choice[1] = new Array();
choice[0][0] = new Array();
choice[0][0][0] = 'True';
choice[0][0][1] = '0';

choice[0][1] = new Array();
choice[0][1][0] = 'False';
choice[0][1][1] = '1';

choice[1][0] = new Array();
choice[1][0][0] = 'True';
choice[1][0][1] = '1';

choice[1][1] = new Array();
choice[1][1][0] = 'False';
choice[1][1][1] = '0';




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


function genQuestion(no,a,chkans,ans){
	var txtq = '';

	if(question[a]){
		txtq += '<table width="100%" border="0" cellspacing="0" cellpadding="3">';

		var answer_icon = '';
		var choice_check_true = '';
		var choice_check_false = '';

		if(chkans){
			if(ans==1){
				choice_check_true = 'checked';
				choice_check_false = (chkans)?'disabled':'';
			}
			else
			{
				choice_check_false = 'checked';
				choice_check_true = (chkans)?'disabled':'';
			}

			var choice_ans = (ans==1)?0:1;

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

			answer_icon = '<img src="asset/'+choice[a][choice_ans][1]+'.gif" width="16" height="13">';

		}

		txtq += '  <tr '+(((no%2)==0)?'':'bgcolor=#FBFBFB')+'>';
		txtq += '    <td align="center" width=50 valign=top><input type="radio" name="ch_'+no+'" value=1 '+choice_check_true+'></td>';
		txtq += '    <td align="center" width=50 valign=top><input type="radio" name="ch_'+no+'" value=0 '+choice_check_false+'></td>';
		txtq += '    <td width="25" align="center" valign=top>'+answer_icon+'</td>';
		txtq += '	 <td width="25" align="right" valign=top><font size="6" face="MS Sans Serif, Tahoma, sans-serif">'+cNo[no]+'.</font></td>';
		txtq += '    <td><font size="3" face="MS Sans Serif, Tahoma, sans-serif">'+question[a]+'</font></td>';
		txtq += '  </tr>';

		txtq += '</table>';
	}

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


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

	alert(msg);

	parent.score_suit[parent.score_suit.length] = scr;
	parent.chkSummaryScore();

}
