var sentences = "<h5><b>Your results are represented by the water in each bucket.</b></h5>";


// function to display the question set
function DisplayQuestions(subject)
{
	var diplayCategory= 0;
	var counter = 0;
	document.write("<table width='100%' border='1' cellspacing='0' cellpadding='0'>\n");
	document.write("<tr><td width='40%'>Nature of the " + subject + "</td>\n");
	if (subject == "modern society")
	{
		document.write("<td width='40%'>Qualities of a Preferred Graduate in the modern society</td>\n");
	}
	else
	{
		document.write("<td width='40%'>Qualities of a Preferred Graduate in the discipline</td>\n");
	}
	document.write("<td colspan='5' width = 20%>How far am I from being a Preferred Graduate?</td></tr>\n");
	document.write("<tr><td width='40%'></td>\n");
	document.write("<td width='40%'></td>\n");
	document.write("<td colspan='5' width = 20%>'How much water would there be in your bucket?'</td></tr>\n");
	document.write("<tr><td width='40%'></td><td width='40%'></td>\n");
	document.write("<td width = 4%><image name='img1' src='../../../images/bucket05.gif'><br>A</td>\n");
	document.write("<td width = 4%><image name='img2' src='../../../images/bucket04.gif'><br>B</td>\n");
	document.write("<td width = 4%><image name='img3' src='../../../images/bucket03.gif'><br>C</td>\n");
	document.write("<td width = 4%><image name='img4' src='../../../images/bucket02.gif'><br>D</td>\n");
	document.write("<td width = 4%><image name='img5' src='../../../images/bucket01.gif'><br>E</td></tr>\n");
	for (i=0; i<Category.length; i++)
	{
		
		displayCategory = 1;
		
		for (j=0; j<QuestionCategory[i]; j++)
		{	document.write("<tr>");
			if (displayCategory == 1)
			{
				document.write("<td bgcolor='#CC99FF' rowspan='" + QuestionCategory[i] + "' valign='top'>" + Category[i] + "</td>\n");
			}
			displayCategory = 0;
			
			document.write("<td valign='top'>" + Question[counter] + "</td>\n");
			for (k=TotalNoOfOptions; k>=1; k--)
			{
				document.write("<td valign='top'><input type='radio' name='" + department + "_Q" + (counter) +"' value='" + k + "' onClick=\"checkselected(this, '" + department + "_Q" + (counter) +"' , " + k +"); cookieVal('" + department + "_Q" + (counter) +"'); Result();\" >" + "</td>\n");
			}
			document.write("</tr>\n");
			counter++;
		}
	}
	document.write("<tr><td colspan='7'>");
	document.write("<input type='button' name='submit' value='Submit' onClick=\" return checkfillin();\">\n");		
		document.write("<input type='button' name='print' value='Print' onClick='javascript:window.print()'>\n");
		document.write("<input type='reset' name='reset' value='Reset' onClick=\"resetResult()\"></td></tr>\n");
	document.write("</table>\n");
}
	

	function displayParticularResult(j)
	{
	//	parent.content.document.close();
		parent.content.document.open();
	//	parent.content.document.clear();
		parent.content.document.writeln("<html><head><title>result</title>\n");
		parent.content.document.writeln("<link rel=\"stylesheet\" href=\"../../css/ex2.css\" type=\"text/css\">\n");
		parent.content.document.writeln("</head><body bgcolor=\"#FFFFFF\" text=\"#000000\" onLoad=\"MM_preloadImages('images/home_f2.gif','../images/home_f2.gif')\" background=\"../../images/bg_01_futpro.gif\">\n");
		var good = true;
		var number = 0;

		for (i=0; i<TotalNoOfQuestions; i++) 
			{
				var whichQuestion= department + "_Q"+(i);

				if (getCookie(whichQuestion) == j) 
				{
						number++;
						good = false;
				}
			}

		if (number>0)
			{
				 parent.content.document.write("You give yourself <image  src='../../../images/bucket0" + j +".gif'> in the following qualities:\n");
				 parent.content.document.write("<form name=\"thisform\" method=\"post\" action=\"\">\n");
				 parent.content.document.write("<table width='100%' border='1' cellspacing='0' cellpadding='0'>");
				for (i=0; i<TotalNoOfQuestions; i++) 
				{
					var whichQuestion= department + "_Q"+(i);
			
					if (getCookie(whichQuestion) == j) 
					{
						 parent.content.document.write("<tr><td  valign='top'>"+ Question[i] + ".</td><p>\n");
						 parent.content.document.write("</tr>\n");
					}
				}
				
				 parent.content.document.write("</table><br>\n");
				 parent.content.document.write("<br><input type=\"button\" name=\"print\" value=\"Print\" onClick=\"javascript:window.print()\"></form>\n");
				 parent.content.document.writeln("</body></html>\n");
				 parent.content.document.close();
			}
		else 
		{
			 parent.content.document.write("You didn't chooose this option.<br>\n");
			 parent.content.document.close(); 
		}

	}


	function displayResult()
	{
		var good = true;
		var number = 0;
		
		for (j=3; j>=1; j--)
		{
			number = 0;
			
			for (i=0; i<TotalNoOfQuestions; i++) 
			{
				var whichQuestion= department + "_Q"+(i);

				if (getCookie(whichQuestion) == j) 
				{
						number++;
						good = false;
				}
			}
		
			if (number>0)
			{
				document.write("You give yourself <image  src='../../../images/bucket0" + j +".gif'> in the following qualities:\n");
				document.write("<table width='100%' border='1' cellspacing='0' cellpadding='0'>");
				for (i=0; i<TotalNoOfQuestions; i++) 
				{
					var whichQuestion= department + "_Q"+(i);
			
					if (getCookie(whichQuestion) == j) 
					{
						document.write("<tr><td  valign='top'>"+ Question[i] + ".</td><p>\n");
						document.write("</tr>\n");
					}
				}
				document.write("</table><br>\n");
			}
		}
		if (good == false) {
		document.write("<p>Don't worry! ... 'The PolyU programme is specially designed to help you.'");
		}
		else
		{
		document.write("<p>Congratulations! ... You are not too far from being a preferred graduate. You might be interested in the PolyU programme which is specially designed for you.");
		}

	}





	function Result()
	{
		for (i=0; i<TotalNoOfQuestions; i++) 
		{
			for (j=0; j<TotalNoOfOptions; j++)
			{
				obj =eval("document.forms[0]." + department + "_Q" +(i)+ "[j]");
				if (obj.checked == true)
				{
					result[i] = obj.value;
					break;
				}
			}
		}
	}
	



function checkselected(which, quename, queval) {
		document.cookie = quename+"="+queval
}




function checkfillin()
{
	
	var pass = true;
	
	for (i=0; i<result.length; i++)
	{
		if (result[i] == "" || result[i]==null)
		{	
			pass = false;
			alert("Please fill in all the questions first!");
			break;
		}
		
	}
	
	if (pass == true)
	{
		openResultWin();
	}
	
	return pass
}


function openResultWin() { //v2.0
  //var width = 640, height = 480;
  var winFeatures = 'scrollbars=yes,resizable=yes,width=640,height=480';
  var winName="Result";
  var URL="result.htm";
  //can't use the following style to decalre the winFeatures, coz it doesn't work in Netscape
  //var winFeatures = '\''+ 'scrollbars=yes, width =' + width + ', height =' + height + '\'';
   //var LeftUpperCornerX = screen.availWidth - 640- HorizontalOffset;
   //var LeftUpperCornerY = screen.availHeight - 480 - statusbarHeight;
   var win = window.open(URL,winName,winFeatures)
   //win.moveTo(LeftUpperCornerX, LeftUpperCornerY);
 }
//--> 

function resetResult()
{
	for (i=0; i<result.length; i++)
	{
		result[i]="";
	}
}
