//   -			-			-			-			-			GENERAL VARIABLES

var strModulePath  = 'http://www.zuivelonline.nl/images/module_files/';
var strHomeImages  = strModulePath + 'home/';
var strFillerImage = 'filler.gif';

var kader_path	     ;
var kader_color_dark ;
var kader_color_body ;

var blnOpenCloseDocument = true;

var DOELGROEP_VOLWASSENEN   = 7;
var DOELGROEP_OUDERS		= 6;
var DOELGROEP_KINDEREN		= 9;
var DOELGROEP_ZWANGER		= 8;
var DOELGROEP_LIJNERS		= 10;
var DOELGROEP_DOCENTENLEERL = 11;
var DOELGROEP_PARAMEDISCH	= 12;
var DOELGROEP_INFOPLUS		= 13;
var homepageIntro = true;

//   -          -  MENU's

function sm_a(itemID){
	layer_set_visible("item"+itemID.toString()+"_submenu",true);
	layer_set_visible('submenu_normal',false);
}
function sm_c(itemID){
	layer_set_visible("item"+itemID.toString()+"_submenu",false);
	layer_set_visible('submenu_normal',true);
}

function ssm_c(){
	layer_set_visible("subsub",false);
	layer_set_visible('subsub_normal',true);
}

//   -			-			-			-			-			GENERAL

function max(x,y) {return x>y?x:y;}
function min(x,y) {return x<y?x:y;}

//   -			-			-			-			-			IMAGES

function image_swap(id,bron) {
	if (document.images) document.images[id].src = bron;
}

function image_preload() {
	document.preload = new Array();
	if (document.images) {
		for (var i = 0; i < image_preload.arguments.length; i++) {
			document.preload[i] = new Image();
			document.preload[i].src = image_preload.arguments[i];
		}
	}
}

//   -			-			-			-			-			DISCLAIMER 

function disclaimer(iDoelgroep) {
	kader( '100%', '', '<font class=small>De op deze pagina geboden informatie is bedoeld als indicatie en kan nooit het advies van specialisten vervangen. Voor meer informatie over voedingsmiddelen en gedragspatronen ten aanzien van eetgewoontes verwijzen wij u graag naar de site van <a class=small href=http://www.nvdietist.nl target=_blank>de Nederlandse Vereniging van Diëtisten</a> (NVD).</font>','','');
}  

//   -			-			-			-			-			SCORE 
var score_top=-1;

function ScoreScroll () {
	var max_val, new_val;
	
	if (document.body.scrollTop==0) {
		if (score_top!=-1) document.all.score_table.style.top = score_top;
	} else {
		if (score_top==-1) score_top = document.all.score_table.offsetTop;
		new_val = max(score_top, document.body.scrollTop);
		// make sure score does not get below the bottom of the test-form!
		if (document.all.test) {	
			max_val = score_top + document.all.test.offsetHeight - 
					  document.all.test.offsetTop - document.all.score_table.clientHeight;
			if (new_val > max_val)   new_val = max_val;
			if (new_val < score_top) new_val = score_top;
		}
		document.all.score_table.style.top = new_val;
	}
}

function ScoreWrite (strTitle, strExplain) {
// ' id=score_table ' + (isIE ? 'STYLE="position:absolute"' : '')
	var strBody = '<table cellpadding=0 cellspacing=0><tr><td nowrap>'+strTitle+'&nbsp;:</td><td><font size=2><input type=text name=result size=4 maxlength=4 style=\"BORDER:0px;FONT-SIZE:17px;COLOR:black;BACKGROUND-COLOR:'+kader_color_body+';font-weight:bold\"></font></td><tr>'
	if (strExplain!='') {
		strBody = strBody + '<tr><td colspan=3>'+ strExplain + '</td></tr>';
	} 
	strBody = strBody + '</table>';
	kader ('170px', 'Score' , strBody, 0, 'right', '' )
	
	// NS does not work, Opera scrolls, but below the table errors occur
	if (isIE) t = setInterval("ScoreScroll()",500);
}

// Does not work under NS4, reason unknown! 
function ScoreUpdate( number ) {
	window.document.forms.test["result"].value=number.toString();
}  

//   -			-			-			-			-			QUIZ
var intQuestions;
var arrAllQuestions;
var intMaxQuestions = 5;
var arrQuestions;
var quiz_score = 0;
var quiz_finished = false;

function quiz_init( ){
	arrQuestions = new Array();
	arrAllQuestions = new Array();
	intQuestions = 0;
	image_preload(strModulePath + 'quiz/k_goed.gif', strModulePath + 'quiz/k_fout.gif');
}

function quiz_question( question, answer, explain, option1, option2, option3, option4) {
	var temp = new Object();
	
	temp.question    = question; 
	temp.answer      = answer;
	temp.explain     = explain;
	temp.answered    = false;
	temp.last_answer = 0;
	temp.selected 	 = false; // for the randomizer

	// HARD CODED change later! 
	temp.num_options = (option4=="") ? 3 : 4;
	temp.options = new Array();
	temp.options[1] = option1;
	temp.options[2] = option2;
	temp.options[3] = option3;
	temp.options[4] = option4;
	
	intQuestions++;
	arrAllQuestions[intQuestions] = temp;
}

function quiz_write() {
	var x, y
	var sfil3 = '<TD width=3 bgcolor=#000000><img src='+strModulePath+'filler.gif width=3 height=1></TD>';
	var sfil1 = '<TD width=1 bgcolor=#000000><img src='+strModulePath+'filler.gif width=1 height=1></TD>';
	var colors = Array;
	var selected_count;
	var rnd_id;
	
	colors[1] = "91ccf4";
	colors[2] = "c38db7";
	colors[3] = "EED507";
	colors[4] = "A6D6CA";
	colors[5] = "FEA192";

	// randomize quiz questions 
	selected_count = 0;
	while (selected_count<intMaxQuestions){
		// randomize number
		rnd_id=-1;
		while (rnd_id<1||rnd_id>intQuestions)
			rnd_id=Math.round(Math.random()* intQuestions);
		// if it's not yet selected, add
		if (!arrAllQuestions[rnd_id].selected) {
			selected_count++;
			arrAllQuestions[rnd_id].selected = true;
			arrQuestions[selected_count] = arrAllQuestions[rnd_id];
		}
	}
	
	if (blnOpenCloseDocument) document.open();
	document.write( '<FORM name=test STYLE=MARGIN:0PX><TABLE cellSpacing=0 cellPadding=0><TR vAlign=top><TD width=98%>');
	ScoreWrite('Vragen goed ','&nbsp;');
	for (x=1; x<=intMaxQuestions; x++ ){
		curr = arrQuestions[x];
		
		document.write( (x==1?'':'<BR><BR>')+'<TABLE cellSpacing=0 cellPadding=0 width=521>');		
		document.write('<TR valign=bottom>');
		document.write('<TD width=81><img src='+strModulePath+'quiz/k_lb.gif width=81 height=19></TD>');
		document.write('<TD width=340><img src='+strModulePath+'quiz/k_boven.gif width=440 height=56></TD></TR></TABLE>');
		
		document.write('<TABLE cellSpacing=0 cellPadding=0>');
		document.write('<TR>'+ sfil3);
		document.write('<TD bgcolor=#EA9C1E width=77><img src='+strModulePath+'quiz/k_vraag.gif ID=quiz_vr'+x.toString()+' NAME=quiz_vr'+x.toString()+' width=77 height=90></TD>');
		document.write(sfil1);
		
		document.write('<TD bgcolor=#' + colors[x]+' valign=top><TABLE cellSpacing=0 cellPadding=1 border=0 width=437>'); 
		document.write('<TR Valign=top><TD>&nbsp;&nbsp;' + x.toString() + '.&nbsp;</TD><TD><B>' + curr.question + '</B></TD></TR>');
		for (y=1; y<=curr.num_options; y++) {
		  document.write('<TR vAlign=top><TD width=1%><INPUT onclick=\"return quiz_recalc('+x.toString()+')\" type=radio value=' + ( y==curr.answer ? '1' : '0') + ' name=rad' + x.toString() + '></TD>');
		  document.write('<TD valign=middle width=99%>' + curr.options[y] + '</TD></TR>');
		}
		document.write('</TABLE></TD>');
		document.write( sfil3 + '</TABLE>');
		
		document.write('<TABLE cellSpacing=0 cellPadding=0>');
		document.write('<TR valign=top><TD><img src='+strModulePath+'quiz/k_lo.gif width=81 height=23></TD>');
		document.write('<TD colspan=3><img src='+strModulePath+'quiz/k_onder.gif width=440 height=55></TD></TR></TABLE>');
	}
	document.write( '</TD></TR></TABLE></FORM>');
	if (blnOpenCloseDocument) document.close();
}

function quiz_recalc( clicked ) {
	var x, fld, ret=true;
	var strExplain

	if (!arrQuestions[clicked].answered) {
		quiz_score = 0;
		for (x=1;x<=intMaxQuestions;x++) {
			fld=window.document.forms.test['rad'+x.toString()];
			for (sel=0;sel<fld.length;sel++) 
				if (fld[sel].checked) {
					if (fld[sel].checked) quiz_score += parseInt(fld[sel].value);
					if (x==clicked) {
						arrQuestions[x].answered = true;
						arrQuestions[x].last_answer = sel;
						strExplain = arrQuestions[x].explain;
						if (strExplain=='') strExplain = "Het antwoord op de vraag <BR>'"+arrQuestions[x].question+"' is <BR>'"+arrQuestions[x].options[arrQuestions[x].answer]+"'.";						
						quiz_result ((parseInt(fld[sel].value)>0), strExplain );
						image_swap("quiz_vr"+x.toString(), strModulePath + 'quiz/k_' + (parseInt(fld[sel].value)>0 ? 'goed' : 'fout') + '.gif');
					}
				}
		}
		ScoreUpdate( quiz_score );	
	} else {
		ret = false;
		window.document.forms.test['rad'+clicked.toString()][arrQuestions[clicked].last_answer].checked = true;
	}
	return ret;
}

function quiz_ready_test() {
	var x, intAnswered = 0;
	
	for (x=1; x<=intMaxQuestions; x++) 
		intAnswered += (arrQuestions[x].answered ? 1 : 0);
	
	if (intAnswered == intMaxQuestions && !quiz_finished) 
		quiz_final (quiz_score);
}

function quiz_result( blnGoed, txtExplain ){
	var strContent
	
	strContent = "<HTML><HEAD><TITLE>Resultaat</TITLE><SCRIPT language=javascript>function wclose(){"+(isIE?"":"window.opener.quiz_ready_test();")+"window.close();} function cd(){var x=setTimeout(\'wclose()\',10000);}</"+"SCRIPT></HEAD>" +
				 "<BODY bgcolor=#f0f0f0 onload=javascript:cd() onkeydown=javascript:wclose() onclick=javascript:wclose()>" + 
				 "<CENTER><BR><B><FONT FACE=VERDANA SIZE=4 COLOR= " +
				 (blnGoed ? "GREEN>Inderdaad, dat klopt!" : "RED>Helaas, je hebt het fout!") + "</FONT></B><BR>" +
				 "<BR><FONT FACE=VERDANA SIZE=2> " + txtExplain + "</FONT><BR><BR>" +
 				 "<FONT FACE=VERDANA SIZE=2>" + 
 					(isNS4 || isOpera ? "<a href=javascript:wclose()>&nbsp;&nbsp;OK&nbsp;&nbsp;</a>" : "<INPUT TYPE=SUBMIT VALUE=\"  Ok  \" onclick=wclose()>") + 
				 "</CENTER></BODY></HTML>";
	
 	quiz_window ("quizresult", strContent);
 	if (isIE) quiz_ready_test();
}


function quiz_final( score ){
	var perc_score;
	var txt_explain;
	var strContent;
		
	strContent = "<HTML><HEAD><TITLE>Je eindscore</TITLE><SCRIPT language=javascript>function wclose(){window.close()} function cd(){var x=setTimeout(\'wclose()\',10000);}</"+"SCRIPT></HEAD>" +
				 "<BODY bgcolor=#f0f0f0 onload=javascript:cd() onkeydown=javascript:wclose() onclick=javascript:wclose()>";
	
	perc_score = (score*100) / intMaxQuestions;

	if (perc_score > 80) 
		strContent += "<EMBED SRC="+strModulePath+"quiz/eeee.wav HEIGHT=0 WIDTH=0 AUTOSTART=TRUE LOOP=FALSE HIDDEN=TRUE></EMBED>"
	if (perc_score < 50)  
		txt_explain = "Je hebt nog een hoop te leren over zuivel, kijk snel verder op deze site of speel de quiz met andere vragen om meer te leren." 
	else if (perc_score < 70) 
		txt_explain = "Je hebt het redelijk gedaan, maar er is nog meer te leren. Kijk dan snel verder op deze site of speel de quiz met andere vragen."
	else if (score==intMaxQuestions) 
			txt_explain = "Wow, je hebt alles goed! Wil je nog meer leren? Kijk dan snel verder op deze site of speel de quiz met andere vragen."
		 else
			txt_explain = "Goed gedaan, maar er is nog veel meer te leren. Kijk snel verder op deze site of speel de quiz met andere vragen om meer te leren."
	
	strContent += "<TABLE><TR valign=top><TD>" +
				  "<IMG SRC=" + strModulePath + "quiz/finish.gif width=84 height=100></TD><TD><FONT FACE=VERDANA SIZE=3>" +
				  "Je hebt <b>" + score + "</b> van de <b>" + intMaxQuestions+ "</b> vragen goed</FONT><BR>" +
				  "<BR><FONT FACE=VERDANA SIZE=2> " + txt_explain + "</FONT></TD></TR>" +
 				  "<TR><TD COLSPAN=2>" +
 					"<CENTER><FONT FACE=VERDANA SIZE=2>" + 
 					(isNS4 || isOpera ? "<a href=javascript:wclose()>&nbsp;&nbsp;OK&nbsp;&nbsp;</a>" : "<INPUT TYPE=SUBMIT VALUE=\"  Ok  \" onclick=wclose()>") + 
 					"</CENTER></TD></TR>" +
				  "</TABLE>" +
				  "</BODY></HTML>" ;
				 
	quiz_window("quizfinish", strContent);
	quiz_finished = true; 
}

function quiz_window( strName, strWindowContent) {
	var result_width = 370;
	var result_height = ( (isMac&&isIE) ? 70 : 190);
	var w, x
	
	var Xpos = (screen.width  - result_width ) / 2;
	var Ypos = (screen.height - result_height) / 2;

 	if (window.showModalDialog) {
 		w = window.showModalDialog(strModulePath+"quiz/result_ie.htm",strWindowContent,'dialogWidth:'+result_width+'px;dialogHeight:'+result_height+'px;dialogTop:'+Ypos+'px;dialogLeft:'+Xpos+'px;status:no;help:no;scroll:no');
 	} else {
		w = window.open("", strName, "width="+result_width.toString()+",height="+result_height.toString()+",status=no,titlebar=no,resizable=no,top="+Ypos.toString()+",left="+Xpos.toString());
		while(w.document == null){x++}; 
		w.opener = window;
		with (w.document) {
			open();
			write( strWindowContent );
			close();
		}
		if (w.focus) w.focus(); 
	}
}

//   -			-			-			-			-			KADERS
function kader_init( path, color_dark, color_body) {
	kader_path	     = path;
	kader_color_dark = color_dark;
	kader_color_body = color_body;
}

function kader_open ( strText ) {
	if (blnOpenCloseDocument) document.open();
	document.write ("<TABLE cellpadding=0 cellspacing=0 width=100% style=\"border:1px solid #"+kader_color_dark+"\">");
	document.write ("<tr><td style=padding:5px bgcolor=#"+kader_color_body+" style=\"border-bottom:1px solid #"+kader_color_dark+"\"><font color=#000000><b>" + strText + "</b></td></tr>");
	document.write ("<tr><td style=padding:5px>");
	if (blnOpenCloseDocument) document.close();
}

function kader_close() {
	if (blnOpenCloseDocument) document.open();
	document.write ("</td></tr></table><br>&nbsp;");		
	if (blnOpenCloseDocument) document.close();
}

function kader( strWidth, strKopje, strContent, strAlign, strAdditional ) { 
	if (blnOpenCloseDocument) document.open();
	document.write ("<table cellpadding=0 cellspacing=0 width=" + strWidth + (strAlign=='' ? '' : ' align='+strAlign) + " "+ strAdditional + ">");
	if (strKopje!='') {
		document.write ("<tr><td colspan=3>");
		document.write ("<object classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width=156 height=20 id=kaderkop align=middle>")
		document.write ("<param name=allowScriptAccess value=sameDomain />")
		document.write ("<param name=movie value=\'kaderkop.swf?kleur="+kader_color_dark+"&kopje="+ strKopje + "\' />")
		document.write ("<param name=quality value=best />")
		document.write ("<param name=bgcolor value=#ffffff />")
		document.write ("<embed src=\"kaderkop.swf?kleur="+kader_color_dark+"&kopje="+ strKopje + "\" quality=best bgcolor=#ffffff width=156 height=20 name=kaderkop align=middle allowScriptAccess=sameDomain type=application/x-shockwave-flash pluginspage=http://www.macromedia.com/go/getflashplayer /></object>")
		document.write ("</td></tr>")
	}
	document.write ("<tr><td><img src="+kader_path+"/kader_lt.gif width=10 height=10></td>")
	document.write ("<td valign=top background="+kader_path+"/kader_filler_top.gif></td>")
	document.write ("<td><img src="+kader_path+"/kader_rt.gif width=7 height=10></td></tr>")
	document.write ("<tr><td width=1% background="+kader_path+"/kader_filler_left.gif>&nbsp;</td><td bgcolor="+kader_color_body+" width=98%>"+strContent+"</td><td width=1% background="+kader_path+"/kader_filler_right.gif>&nbsp;</td></tr>")
	document.write ("<tr><td><img src="+kader_path+"/kader_lb.gif width=10 height=10></td><td background="+kader_path+"/kader_filler_bot.gif></td><td><img src="+kader_path+"/kader_rb.gif width=7 height=10></td></tr>")
	document.write ("</table>") 
	if (blnOpenCloseDocument) document.close();
}

//   -			-			-			-			-			MEMOBLOKJE
function memoblok( sTekst ) {
	kader ( '170px', '', sTekst, 'right', '');
}

//   -			-			-			-			-			TEST UZELF  

function testuzelf( sTekst, iModule, legacy) {
	if (!legacy!='undefined') {
		iModule=legacy;
	}
	var link = "<a href=index.asp?PageID="+iModule+">";
	kader ( '170px', 'Test uzelf', link+sTekst+'</a>', 'right', '');
}

//   -			-			-			-			-			TEST UZELF  
var intOldFaqID = 9999;

function faq(id) {
	document.getElementById("antwoord"+intOldFaqID.toString()).style.display='none';
	document.getElementById("antwoord"+id.toString()).style.display='block';
	if (p = document.getElementById("pijl"+intOldFaqID.toString())) p.style.display='none';
	document.getElementById("pijl"+id.toString()).style.display='block';
	intOldFaqID = id;
}

