<!-- javascript -->

// Scripts for The Youth Centre parenting learning module. 
// Last modified on August 4, 2005

// global variable
// set array variable to hold the answers for the refreshers
var adValues = new Array();

function SymError()
{
  return true;
}

window.onerror = SymError;

var SymRealWinOpen = window.open;

function SymWinOpen(url, name, attributes)
{
  return (new Object());
}

window.open = SymWinOpen;

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// What's your parenting style?

function radioValue(r) {
	 for (var i = 0; i < r.length; i++) {  
		if (r[i].checked) 
			return r[i].value;
    }
	return null;
}

//////////////////////////////////////////////////////////////////////////////////////////////////

// This function is called by the results display page for the 
// What's Your Parenting Style questionnaire.
// This script is restricted to either three or four questions.
// Change the code if there the number of questions varies.

function checkParentingStyle(prevPage)
{

// assign default null values to the parameters in case values are not passed
// i.e., the page was loaded without the query string
// this also resets the values from other refreshers (note that we are hardcoding
// four array values. If the number of values vary, change the code.)

adValues['q1'] = null;
adValues['q2'] = null;
adValues['q3'] = null;
adValues['q4'] = null;

getValues();

var output = "";

var counta = 0;
  var countb = 0;
  var countc = 0;    

	if (adValues['q1'] && adValues['q2'] && adValues['q3'] && adValues['q4']) {

  // check for the most letters selected
  // this is hardcoded, specific to the number of questions and options
  // for the What's your parenting style? questionnaire
  
// Q1
if (adValues['q1'] == "1") {
      counta++;	  
    }
 else if (adValues['q1'] == "2") {
      countb++;
    }
 else if (adValues['q1'] == "3") {
      countc++;
    }
 
  // Q2
if (adValues['q2'] == "1") {
      counta++;
    }
 else if (adValues['q2'] == "2") {
      countb++;
    }
 else if (adValues['q2'] == "3") {
      countc++;
    }

 // Q3
 if (adValues['q3'] == "1") {
      counta++;
    }
 else if (adValues['q3'] == "2") {
      countb++;
    }
 else if (adValues['q3'] == "3"){
      countc++;
    }
	
 // Q4
 if (adValues['q4'] == "1") {
      counta++;
    }
 else if (adValues['q4'] == "2") {
      countb++;
    }
 else if (adValues['q4'] == "3"){
      countc++;
    }

// compare numbers and generate the results page
		  
// permissive		  
 if (counta == "3" || counta == "4") {
    	output = "<p class='pink'>You answered mostly <strong>A</strong>s.</p><p class='pink'>Your parenting style is most similar to <em>permissive parenting</em>.</p><p> The <strong>permissive parenting</strong> style shows no recognizable structure, rules or guidelines. Permissive parents may feel that they will lose their teen's love if they don't give in on most issues so they allow their teen to seize control. <p>People who answer mostly <strong>B</strong>s have a parenting style most similar to <strong>autocratic parenting</strong>. The autocratic parenting style has a very rigid structure of hierarchy and control. Autocratic parents believe they know what is good for everybody else and therefore teach teens what to think, rather than how to think. <p>People who answer mostly <strong>C</strong>s have a parenting style most similar to <strong>effective, balanced parenting</strong>. This style has a firm but flexible structure. Effective parents are active leaders who discipline with respect.";

	document.write(output);
			
}

// permissive		  
 if (counta == "2" && countb == "1" && countc == "1") {
    	output = "<p class='pink'>You answered mostly <strong>A</strong>s.</p><p class='pink'>Your parenting style is most similar to <em>permissive parenting</em>.</p><p> The <strong>permissive parenting</strong> style shows no recognizable structure, rules or guidelines. Permissive parents may feel that they will lose their teen's love if they don't give in on most issues so they allow their teen to seize control. <p>People who answer mostly <strong>B</strong>s have a parenting style most similar to <strong>autocratic parenting</strong>. The autocratic parenting style has a very rigid structure of hierarchy and control. Autocratic parents believe they know what is good for everybody else and therefore teach teens what to think, rather than how to think. <p>People who answer mostly <strong>C</strong>s have a parenting style most similar to <strong>effective, balanced parenting</strong>. This style has a firm but flexible structure. Effective parents are active leaders who discipline with respect.";

	document.write(output);
			
}

// autocratic
else if (countb == "3" || countb == "4") {
   		output = "<p class='pink'>You answered mostly <strong>B'</strong>s.</p><p class='pink'>Your parenting style is most similar to <em>autocratic parenting</em>.</p><p>The <strong>autocratic parenting</strong> style has a very rigid structure of hierarchy and control. Autocratic parents believe they know what is good for everybody else and therefore teach teens what to think, rather than how to think. <p>People who answer mostly <strong>A</strong>s have a parenting style most similar to <strong>permissive parenting</strong>. The permissive parenting style shows no recognizable structure, rules or guidelines. Permissive parents may feel that they will lose their teen's love if they don't give in on most issues so they allow their teen to seize control. <p>People who answer mostly <strong>C</strong>s have a parenting style most similar to <strong>effective, balanced parenting</strong>. This style has a firm but flexible structure. Effective parents are active leaders who discipline with respect.";

	document.write(output);
}

// autocratic
else if (countb == "2" && counta == "1" && countc == "1") {
   		output = "<p class='pink'>You answered mostly <strong>B'</strong>s.</p><p class='pink'>Your parenting style is most similar to <em>autocratic parenting</em>.</p><p>The <strong>autocratic parenting</strong> style has a very rigid structure of hierarchy and control. Autocratic parents believe they know what is good for everybody else and therefore teach teens what to think, rather than how to think. <p>People who answer mostly <strong>A</strong>s have a parenting style most similar to <strong>permissive parenting</strong>. The permissive parenting style shows no recognizable structure, rules or guidelines. Permissive parents may feel that they will lose their teen's love if they don't give in on most issues so they allow their teen to seize control. <p>People who answer mostly <strong>C</strong>s have a parenting style most similar to <strong>effective, balanced parenting</strong>. This style has a firm but flexible structure. Effective parents are active leaders who discipline with respect.";

	document.write(output);
}

// effective
else if (countc == "3" || countc == "4") {

   		output = "<p class='pink'>You answered mostly <strong>C'</strong>s.</p><p class='pink'>Your parenting style is most similar to <em><strong>effective, balanced</strong> parenting</em>.</p><p>The <strong>effective, balanced style</strong> has a firm but flexible structure. Effective parents are active leaders who discipline with respect. <p>People who answer mostly <strong>A</strong>s have a parenting style most similar to <strong>permissive parenting</strong>. The permissive parenting style shows no recognizable structure, rules or guidelines. Permissive parents may feel that they will lose their teen's love if they don't give in on most issues so they allow their teen to seize control. <p>People who answer mostly <strong>B</strong>s have a parenting style most similar to <strong>autocratic parenting</strong>. The autocratic parenting style has a very rigid structure of hierarchy and control. Autocratic parents believe they know what is good for everybody else and therefore teach teens what to think, rather than how to think.";

	document.write(output);              
}

else if (countc == "2" && counta == "1" && countb == "1") {

   		output = "<p class='pink'>You answered mostly <strong>C'</strong>s.</p><p class='pink'>Your parenting style is most similar to <em><strong>effective, balanced</strong> parenting</em>.</p><p>The <strong>effective, balanced style</strong> has a firm but flexible structure. Effective parents are active leaders who discipline with respect. <p>People who answer mostly <strong>A</strong>s have a parenting style most similar to <strong>permissive parenting</strong>. The permissive parenting style shows no recognizable structure, rules or guidelines. Permissive parents may feel that they will lose their teen's love if they don't give in on most issues so they allow their teen to seize control. <p>People who answer mostly <strong>B</strong>s have a parenting style most similar to <strong>autocratic parenting</strong>. The autocratic parenting style has a very rigid structure of hierarchy and control. Autocratic parents believe they know what is good for everybody else and therefore teach teens what to think, rather than how to think.";

	document.write(output);              
}

// permauto
else if (counta == "2" && countb == "2") {
output = "<p class='pink'>You answered mostly <strong>A</strong>s and Bs.</p><p class='pink'>Your parenting style is similar to both <em>permissive parenting </em>and<em> autocratic parenting</em>.</p><p> People who answer mostly <strong>A</strong>s have a parenting style most similar to <strong>permissive parenting</strong>. The permissive parenting style shows no recognizable structure, rules or guidelines. Permissive parents may feel that they will lose their teen's love if they don't give in on most issues so they allow their teen to seize control. <p>People who answer mostly <strong>B</strong>s have a parenting style most similar to <strong>autocratic parenting</strong>. The autocratic parenting style has a very rigid structure of hierarchy and control. Autocratic parents believe they know what is good for everybody else and therefore teach teens what to think, rather than how to think. <p>People who answer mostly <strong>C</strong>s have a parenting style most similar to <strong>effective, balanced parenting</strong>.  This style has a firm but flexible structure. Effective parents are active leaders who discipline with respect.";

	document.write(output);               
				
}
 
else if (counta == "2" && countc == "2") {
   output = "<p class='pink'>You answered mostly <strong>A</strong>s and Cs.</p><p class='pink'>Your parenting style is similar to both <em>permissive parenting </em>and<em> <strong>effective, balanced</strong> parenting</em>.</p><p> People who answer mostly <strong>A</strong>s have a parenting style most similar to <strong>permissive parenting</strong>. The permissive parenting style shows no recognizable structure, rules or guidelines. Permissive parents may feel that they will lose their teen's love if they don't give in on most issues so they allow their teen to seize control. <p>People who answer mostly <strong>C</strong>s have a parenting style most similar to <strong>effective, balanced parenting</strong>. This style has a firm but flexible structure. Effective parents are active leaders who discipline with respect.<p>People who answer mostly <strong>B</strong>s have a parenting style most similar to <strong>autocratic parenting</strong>. The autocratic parenting style has a very rigid structure of hierarchy and control. Autocratic parents believe they know what is good for everybody else and therefore teach teens what to think, rather than how to think.";		
		
		document.write(output);  
}

// autoeff
else if (countb == "2" && countc == "2") {

	output = "<p class='pink'>You answered mostly <strong>B</strong>s and Cs.</p><p class='pink'>Your parenting style is similar to both <em>autocratic parenting </em>and<em> <strong>effective, balanced</strong> parenting</em>.</p><p> People who answer mostly <strong>B</strong>s have a parenting style most similar to <strong>autocratic parenting</strong>. The autocratic parenting style has a very rigid structure of hierarchy and control. Autocratic parents believe they know what is good for everybody else and therefore teach teens what to think, rather than how to think. <p>People who answer mostly <strong>C</strong>s have a parenting style most similar to <strong>effective, balanced parenting</strong>. This style has a firm but flexible structure. Effective parents are active leaders who discipline with respect.<p>People who answer mostly <strong>A</strong>s have a parenting style most similar to <strong>permissive parenting</strong>. The permissive parenting style shows no recognizable structure, rules or guidelines. Permissive parents may feel that they will lose their teen's love if they don't give in on most issues so they allow their teen to seize control.";
 document.write(output);  
}	

	} // end if
	
	// if there is no query string, tell user to take the quiz for answers
	
	else { 
	
	document.write('<br><br><p align="center">To find out what parenting style you have,<br><br><a class="body" href=' + prevPage + '>click here to take the questionnaire</a>.</p>');
	
	}		
		
}

// Function to pass the selected answer in an Effective Communication refresher to the next page
// Change the code if there the number of questions or the output varies.

function passEcURL(ecForm, nextPage)
{

  var choice = "?";

  // go through the "current choices"
  // to find the selected choice.
  // radio boxes pointing to choices
  // must be named "cc"
  // change if necessary
  //
  var i = 0;
  for(;i<ecForm.elements.length;i++)
  {
    if(("cc" ==
        ecForm.elements[i].name) &&
       (ecForm.elements[i].checked))
    {
      choice = ecForm.elements[i].value;
    }
  }

  // no choice was selected
  //
  if("?" == choice)
  {
    alert("Please select an answer.");
    return false;
  }
	
	 var nextURL = nextPage + "?q1=" + choice;
	  	
	document.location.href = nextURL;
	
  // return "false" to indicate not to
  // submit the form.
  // change this to "true" if the form
  // "action" is valid,
  // i.e. points to a valid CGI script
  
	return false;
}

// This function is called by the results display page for the Effective Communication refreshers.
// This script is restricted to either two or three answer options.
// Change the code if there the number of questions varies.

function setEcResults(correctLetter, wrongLetter1, wrongLetter2, correct, wrong1, wrong2, prevPage)
{

// assign default null values to the parameters in case values are not passed
// i.e., the page was loaded without the query string
// this also resets the values from other refreshers (note that we are hardcoding
// four array values. If the number of values vary, change the code.)

adValues['q1'] = null;
adValues['q2'] = null;
adValues['q3'] = null;
adValues['q4'] = null;

getValues();			
				
var question1 = "";
var question2  = "";
var question3  = "";
var question4  = "";

var correctAnswer = "";
var wrongAnswer = "";

// Effective Communication refreshers only contain one question each,
// so we only need to check the first array value (we've reset the other three
// values to null).

	if (adValues['q1']) {
					
		if (adValues['q1'] == correctLetter) {
			correctAnswer = "<p align='center'><b><img src='../images/correct.gif' width='40' height='35' align='absmiddle'>That's a good choice!</b></p>";
			document.write(correctAnswer + correct + wrong1 + wrong2);
		}

		else {
		
			// there is no third option, so the respondent selected the one wrong answer
			if (wrongLetter2 == "") {
						wrongAnswer = "<p align='center'><strong>" + adValues['q1'] + " is not the best choice!</strong></p>";
			document.write(wrongAnswer + wrong1 + wrong2 + correct);
			}
			
			// both wrong answers have the same reasons
			else if (wrongLetter2 == "samereason") {
						wrongAnswer = "<p align='center'><strong>" + adValues['q1'] + " is not the best choice!</strong></p>";
			document.write(wrongAnswer + wrong1 + correct);
			}
			
			else {
				
			wrongAnswer = "<p align='center'><strong>" + adValues['q1'] + " is not the best choice!</strong></p>";
			
			// respondent selected wrong1
					if (adValues['q1'] == wrongLetter1) {
			document.write(wrongAnswer + wrong1 + wrong2 + correct);			
					}	

			// respondent selected wrong2
					else {
			document.write(wrongAnswer + wrong2 + wrong1 + correct);
					}
			
			}	
		}	// end else

		
	
	} // end if q1
	
	// if there is no query string, tell user to take the quiz for answers
	
	else { 
	
	document.write('<br><br><p align="center">To find out the refresher answers,<br><br><a class="body" href=' + prevPage + '>click here to take the quiz</a>.</p>');
	
	}		
		
}

////////////////////////////////////////////////////////////////////////////////////////////////

// Refreshers for Adolescent Development and Staying Connected
// Also for the What's Your Parenting Style questionnaire
// This script is restricted to a maximum of four questions.

// Change the code if there the number of questions varies.

function passURL(mcForm, nextPage)
{
	var errors=0;
	var alertString = "Please select answers for\n";

	  	// if question1 exists
	if (mcForm.question1) {
		
	  if (radioValue(mcForm.question1) == null) {
		alertString += "Question 1\n";
		errors++;
		}

	// check for other questions, if they exist
			
	  	// if question2 exists		
	if (mcForm.question2) {		
	if (radioValue(mcForm.question2) == null) {
		alertString += "Question 2\n";
		errors++;
		}
		}

	  	// if question3 exists
	if (mcForm.question3) {		
	  if (radioValue(mcForm.question3) == null) {
		alertString += "Question 3\n";
		errors++;
		}
		}

	  	// if question4 exists		
	if (mcForm.question4) {
	  if (radioValue(mcForm.question4) == null) {
		alertString += "Question 4\n";
		errors++;
		}
		}				
	
	} // end if 
	
	  // missing answers
  //
  
  	if (errors > 0) {
		alert(alertString);
		return false;
	} else {
	
		// if question1 exists
	  	if (mcForm.question1) {	
		  var nextURL = nextPage + "?q1=" + radioValue(mcForm.question1);
		
		// add on other question values, if they exist
		
			// if question2 exists
	  		if (mcForm.question2) {
				nextURL = nextURL + "&q2=" + radioValue(mcForm.question2);
			}	 
			
			// if question3 exists
	  		if (mcForm.question3) {
				nextURL = nextURL + "&q3=" + radioValue(mcForm.question3);
			}	   
	  
	  		// if question4 exists
	  		if (mcForm.question4) {
				nextURL = nextURL + "&q4=" + radioValue(mcForm.question4);
			}
		
		} // end questions
		
	document.location.href = nextURL;
	

  // return "false" to indicate not to
  // submit the form.
  // change this to "true" if the form
  // "action" is valid,
  // i.e. points to a valid CGI script
  //
	return false;
	}
}

// This function is called by the results display page.
// The script is restricted to a maximum of four questions. 
// The quiz must have at least one question.
// Change the code if there are more than four questions.

function setResults(correct1, correct2, correct3, correct4, answer1, answer2, answer3, answer4, prevPage, currentSection, nextSection)
{

// assign default null values to the parameters in case values are not passed
// i.e., the page was loaded without the query string
// this also resets the values from other refreshers (note that we are hardcoding
// four array values. If the number of values vary, change the code.)

adValues['q1'] = null;
adValues['q2'] = null;
adValues['q3'] = null;
adValues['q4'] = null;

getValues();

var question1 = "";
var question2  = "";
var question3  = "";
var question4  = "";

	if (adValues['q1']) {
	
		if (adValues['q1'] == correct1) {
			question1 = "<b>You selected " + adValues['q1'] + ". That's a good choice! <img src='../images/correct.gif' width='40' height='35' align='absmiddle'></b>";
		}
		else {
			question1 = "<b>You selected " + adValues['q1'] + ". Not the best choice!<br></b>";
		}
		
	document.write('<p><ol>');
	document.write('<li>' + question1 + '<br>' + answer1 + '<br><br></li>');

	// check if there is a q2
		if (adValues['q2']) {
	
			if (adValues['q2'] == correct2) {
			question2 = "<b>You selected " + adValues['q2'] + ". That's a good choice! <img src='../images/correct.gif' width='40' height='35' align='absmiddle'></b>";
		}
		else {
			question2 = "<b>You selected " + adValues['q2'] + ". Not the best choice!<br></b>";
		}

	document.write('<li>' + question2 + '<br>' + answer2 + '<br><br></li>');
			
		} // end q2
		
	// check if there is a q3
		if (adValues['q3']) {
	
			if (adValues['q3'] == correct3) {
			question3 = "<b>You selected " + adValues['q3'] + ". That's a good choice! <img src='../images/correct.gif' width='40' height='35' align='absmiddle'></b>";
		}
		else {
			question3 = "<b>You selected " + adValues['q3'] + ". Not the best choice!<br></b>";
		}

	document.write('<li>' + question3 + '<br>' + answer3 + '<br><br></li>');
			
		} // end q3
		
	// check if there is a q4
		if (adValues['q4']) {
	
			if (adValues['q4'] == correct4) {
			question4 = "<b>You selected " + adValues['q4'] + ". That's a good choice! <img src='../images/correct.gif' width='40' height='35' align='absmiddle'></b>";
		}
		else {
			question4 = "<b>You selected " + adValues['q4'] + ". Not the best choice!<br></b>";
		}

	document.write('<li>' + question4 + '<br>' + answer4 + '<br><br></li>');
			
		} // end q4

	document.write('</ol></p>');
	
	if (currentSection != "") {
	document.write('<TABLE BORDER="1" bgcolor="#cccccc" bordercolordark="#666666" CELLPADDING="10" CELLSPACING="0" WIDTH="450" align="center"><TR><td class="padded" valign="top" align="center"><p>Congratulations. You have completed the ' + currentSection + ' section. The next section is ' + nextSection +'.</p></TD></TR></TABLE>');
		
	}
	
	} // end q1, q2
	
	// if there is no query string, tell user to take the quiz for answers
	
	else { 
	
	document.write('<br><br><p align="center">To find out the refresher answers,<br><br><a class="body" href=' + prevPage + '>click here to take the quiz</a>.</p>');
	
	}		
		
}

// General function to get the query string from a URL

function getValues() {

var query = window.location.search.substring(1);

var values = query.split('&');

for (var i=0; i<values.length; i++) {
   var pos = values[i].indexOf('=');
   if (pos > 0) {
      var key = values[i].substring(0,pos);
      var val = values[i].substring(pos+1);
      adValues[key] = val;  
      }
   }
   
}

//  Function to pass the refresher values to the next page

function valuesForNextButton(nextURL, coords) {

// Retrieve the the query portion of the URL at location 1, i.e., after the "?"
var answerQuery = window.location.search.substring(1);

var nextPage = ""; 

if (answerQuery == null || answerQuery.length == 0)
{	
	nextPage = "<area shape='rect' coords='" + coords + "' href='" + nextURL + "' alt='next page'>";
	document.write(nextPage);	
}

else {
	
	var values = answerQuery.split('?');
	nextPage = "<area shape='rect' coords='" + coords + "' href='" + nextURL + "?" + values + "' alt='next page'>";
	document.write(nextPage);

}
}

// Pass the refresher values to the previous page

function valuesForPrevButton(prevURL, coords) {

// Retrive the the query portion of the URL at location 1, i.e., after the "?"
var answerQuery = window.location.search.substring(1);

var prevPage = ""; 

if (answerQuery == null || answerQuery.length == 0)
{	
	prevPage = "<area shape='rect' coords='" + coords + "' href='" + prevURL + "' alt='previous page'>";
	document.write(prevPage);
}

else {
	
	var values = answerQuery.split('?');
	prevPage = "<area shape='rect' coords='" + coords + "' href='" + prevURL + "?" + values + "' alt='previous page'>";
	document.write(prevPage);

}
}

 function validate(form){
for(var i=0; i< form.elements.length; i++){
	var el = form.elements[i];
		
		if(el.type.toLowerCase() == 'radio'){
			var group = el.form[el.name];
			var checked = false;
			
			for(var j=0; j<group.length; j++)
			
			if(checked = group[j].checked){ break };
				if(!checked){
					alert('Please check a radio button in group '+el.name.toUpperCase());
					el.focus();
					return false;
				}
			}
		} 
		
		return true;
} 

// Radio Button Validation
// copyright Stephen Chapman, 15th Nov 2004
// you may copy this function but please keep the copyright notice with it

function valButton(btn) {
	var cnt = -1;
	for (var i=0; i < btn.length; i++) {
	
	   if (btn[i].checked) {
	   	cnt = i; 
		i = btn.length;
		}
	 }
	 
	if (cnt > -1)
	{
	 return btn[cnt].value;
	}
	else {
		return null;
	}
}


// Summary quiz
// code taken from http://www.faqts.com/knowledge_base/view.phtml/aid/1756/fid/129
// and modified 

function checkSummaryURL(form, nextPage) {

  var errors=0;
  var alertString = "Please select answers for\n";
  var nextURL = nextPage;

// hardcoded to 12 questions
// change code if number of questions varies
// should be a for loop that checks each group of radio questions

// q1
var btn = valButton(form.question1);

if (btn == null) {
	alertString += "Question1\n";
	errors++;
}
else {
	nextURL = nextURL + "?q1=" + btn;
}

// q2
btn = valButton(form.question2);

if (btn == null) {
	alertString += "Question2\n";
	errors++;	
}
else {
	nextURL = nextURL + "&q2=" + btn;
}

// q3
btn = valButton(form.question3);

if (btn == null) {
	alertString += "Question3\n";
	errors++;
}
else {
	nextURL = nextURL + "&q3=" + btn;	
}

// q4
btn = valButton(form.question4);

if (btn == null) {
	alertString += "Question4\n";
	errors++;
}
else {
	nextURL = nextURL + "&q4=" + btn;
}

// q5
btn = valButton(form.question5);

if (btn == null) {
	alertString += "Question5\n";
	errors++;
}
else {
	nextURL = nextURL + "&q5=" + btn;
}

// q6
btn = valButton(form.question6);

if (btn == null) {
	alertString += "Question6\n";
	errors++;
}
else {
	nextURL = nextURL + "&q6=" + btn;
}

// q7
btn = valButton(form.question7);

if (btn == null) {
	alertString += "Question7\n";
	errors++;
}
else {
	nextURL = nextURL + "&q7=" + btn;
}

// q8
btn = valButton(form.question8);

if (btn == null) {
	alertString += "Question8\n";
	errors++;
}
else {
	nextURL = nextURL + "&q8=" + btn;
}

// q9
btn = valButton(form.question9);

if (btn == null) {
	alertString += "Question9\n";
	errors++;
}
else {
	nextURL = nextURL + "&q9=" + btn;
}

 // q10
btn = valButton(form.question10);

if (btn == null) {
	alertString += "Question10\n";
	errors++;
}
else {
	nextURL = nextURL + "&q10=" + btn;
}

// q11
btn = valButton(form.question11);

if (btn == null) {
	alertString += "Question11\n";
	errors++;
}
else {
	nextURL = nextURL + "&q11=" + btn;
}

// q12
btn = valButton(form.question12);

if (btn == null) {
	alertString += "Question12\n";
	errors++;
}
else {
	nextURL = nextURL + "&q12=" + btn;
}
 
// if there are errors, pop up a message
		
if (errors > 0) {

		alert(alertString);
		return false;
	} 
	
// set the query string in the URL

else {
	  document.location.href = nextURL;
		
  // return "false" to indicate not to
  // submit the form.
  // change this to "true" if the form
  // "action" is valid,
  // i.e. points to a valid CGI script
  //
	return false;

}  // end else
  
} // end checkSummaryQuiz

// This function is called by the Summary Quiz page.
// Everything is hardcoded here.

function getSummaryResults()
{

// assign default null values to the parameters in case values are not passed
// i.e., the page was loaded without the query string
// this also resets the values from other refreshers (note that we are hardcoding
// four array values. If the number of values vary, change the code.)

adValues['q1'] = null;
adValues['q2'] = null;
adValues['q3'] = null;
adValues['q4'] = null;
adValues['q5'] = null;
adValues['q6'] = null;
adValues['q7'] = null;
adValues['q8'] = null;
adValues['q9'] = null;
adValues['q10'] = null;
adValues['q11'] = null;
adValues['q12'] = null;

getValues();

var question1 = "";
var question2  = "";
var question3  = "";
var question4  = "";
var question5 = "";
var question6  = "";
var question7  = "";
var question8  = "";
var question9 = "";
var question10  = "";
var question11  = "";
var question12  = "";

var prevPage = "summary01.htm";

var correct = 0;
var wrong = 0;

var answer1 = "The best answer is B:<br><br>During adolescence, teens examine previously unquestioned attitudes, behaviours, and values.";
var answer2  = "The best answer is B:<br><br>As your teen experiences the Separation/Individualization task of adolescent development, he or she is likely to take oppositional stances in order to define him/herself. This can be displayed through choice of hairstyles and clothing.";
var answer3  = "The best answer is B:<br><br>Research has indicated that when talking about sexuality issues with your teen, the more open and honest you are with him or her, the more he or she will trust you and communicate with you about his or her own dating and sexuality.";
var answer4  = "The best answer is C:<br><br>Autocratic parents believe they know best for their teens and, therefore, focus on teaching them what to think rather than how to think.";
var answer5 = "The best answer is FALSE:<br><br>Be authoritative not authoritarian. Your parenting style should be firm, yet respectful. Set reasonable standards and have reasonable expectations instead of using authority for strict discipline.";
var answer6  = "The best answer is B:<br><br>Effective, balanced parenting teaches responsibility and allows teens to make more and more of their own decisions. By learning from their own experiences and being empowered by their parents, teens will gain self-esteem.";
var answer7  = "The best answer is FALSE:<br><br>You-messages accuse, blame, and criticize. They destroy communication, reinforce goals of misbehaviour, and can trigger your teen to become defensive and avoid responsibility. Rather than using You-messages, use I-messages.";
var answer8  = "The best answer is D:<br><br>Look for what you agree on with your teen. Agreeing helps you and your teen   to begin negotiating.";
var answer9 = "The best answer is FALSE:<br><br>Although reflective listening allows you to reflect your teen's feelings in order to understand, this may not always identify the real problem. To help, use the five step approach to explore alternatives.";
var answer10  = "The best answer is B:<br><br>Stay connected by encouraging your teen to participate in activities.";
var answer11  = "The best answer is A:<br><br>Connect with one another by sharing feelings of appreciation at the start of each meeting.";
var answer12  = "The best answer is D:<br><br>All of the above. Having family meals brings togetherness among family members, improves nutrition by eating more nutrious meals, and teaches some basic cooking and meal-preparation skills.";

	if (adValues['q1']) {
	
		if (adValues['q1'] == "B") {
			question1 = "<b>You selected " + adValues['q1'] + ". That's the best choice! <img src='../images/correct.gif' width='40' height='35' align='absmiddle'></b>";
			correct++;
		}
		else {
			question1 = "<b>You selected " + adValues['q1'] + ". Not the best choice!<br></b>";
			wrong++;
		}
		
	// check if there is a q2, but this is redundant
	// this function is hardcoded for the Summary Quiz and there is already a form validator
		if (adValues['q2']) {
	
			if (adValues['q2'] == "B") {
			question2 = "<b>You selected " + adValues['q2'] + ". That's the best choice! <img src='../images/correct.gif' width='40' height='35' align='absmiddle'></b>";
			correct++;			
		}
		else {
			question2 = "<b>You selected " + adValues['q2'] + ". Not the best choice!<br></b>";
			wrong++;			
		}
	
		} // end q2
		
	// q3
		if (adValues['q3']) {
	
			if (adValues['q3'] == "B") {
			question3 = "<b>You selected " + adValues['q3'] + ". That's the best choice! <img src='../images/correct.gif' width='40' height='35' align='absmiddle'></b>";
			correct++;			
		}
		else {
			question3 = "<b>You selected " + adValues['q3'] + ". Not the best choice!<br></b>";
			wrong++;			
		}
			
		} // end q3
		
	// q4
		if (adValues['q4']) {
	
			if (adValues['q4'] == "C") {
			question4 = "<b>You selected " + adValues['q4'] + ". That's the best choice! <img src='../images/correct.gif' width='40' height='35' align='absmiddle'></b>";
			correct++;			
		}
		else {
			question4 = "<b>You selected " + adValues['q4'] + ". Not the best choice!<br></b>";
			wrong++;			
		}
		
		} // end q4

	// q5
		if (adValues['q5']) {
	
			if (adValues['q5'] == "FALSE") {
			question5 = "<b>You selected " + adValues['q5'] + ". That's the best choice! <img src='../images/correct.gif' width='40' height='35' align='absmiddle'></b>";
			correct++;			
		}
		else {
			question5 = "<b>You selected " + adValues['q5'] + ". Not the best choice!<br></b>";
			wrong++;			
		}
		
		} // end q5		

	// q6
		if (adValues['q6']) {
	
			if (adValues['q6'] == "B") {
			question6 = "<b>You selected " + adValues['q6'] + ". That's the best choice! <img src='../images/correct.gif' width='40' height='35' align='absmiddle'></b>";
			correct++;			
		}
		else {
			question6 = "<b>You selected " + adValues['q6'] + ". Not the best choice!<br></b>";
			wrong++;			
		}
			
		} // end q6

	// q7
		if (adValues['q7']) {
	
			if (adValues['q7'] == "FALSE") {
			question7 = "<b>You selected " + adValues['q7'] + ". That's the best choice! <img src='../images/correct.gif' width='40' height='35' align='absmiddle'></b>";
			correct++;			
		}
		else {
			question7 = "<b>You selected " + adValues['q7'] + ". Not the best choice!<br></b>";
			wrong++;			
		}
		
		} // end q7		

	// q8
		if (adValues['q8']) {
	
			if (adValues['q8'] == "D") {
			question8 = "<b>You selected " + adValues['q8'] + ". That's the best choice! <img src='../images/correct.gif' width='40' height='35' align='absmiddle'></b>";
			correct++;			
		}
		else {
			question8 = "<b>You selected " + adValues['q8'] + ". Not the best choice!<br></b>";
			wrong++;			
		}
			
		} // end q8
		
	// q9
		if (adValues['q9']) {
	
			if (adValues['q9'] == "FALSE") {
			question9 = "<b>You selected " + adValues['q9'] + ". That's the best choice! <img src='../images/correct.gif' width='40' height='35' align='absmiddle'></b>";
			correct++;			
		}
		else {
			question9 = "<b>You selected " + adValues['q9'] + ". Not the best choice!<br></b>";
			wrong++;			
		}
			
		} // end q9		

	// q10
		if (adValues['q10']) {
	
			if (adValues['q10'] == "B") {
			question10 = "<b>You selected " + adValues['q10'] + ". That's the best choice! <img src='../images/correct.gif' width='40' height='35' align='absmiddle'></b>";
			correct++;			
		}
		else {
			question10 = "<b>You selected " + adValues['q10'] + ". Not the best choice!<br></b>";
			wrong++;			
		}
			
		} // end q10
		
	// q11
		if (adValues['q11']) {
	
			if (adValues['q11'] == "A") {
			question11 = "<b>You selected " + adValues['q11'] + ". That's the best choice! <img src='../images/correct.gif' width='40' height='35' align='absmiddle'></b>";
			correct++;			
		}
		else {
			question11 = "<b>You selected " + adValues['q11'] + ". Not the best choice!<br></b>";
			wrong++;			
		}			
		} // end q11		

	// q12
		if (adValues['q12']) {
	
			if (adValues['q12'] == "D") {
			question12 = "<b>You selected " + adValues['q12'] + ". That's the best choice! <img src='../images/correct.gif' width='40' height='35' align='absmiddle'></b>";
			correct++;			
		}
		else {
			question12 = "<b>You selected " + adValues['q12'] + ". Not the best choice!<br></b>";
			wrong++;			
		}
			
		} // end q12

	document.write('<p align="center" class="pink"><br><b>YOUR SCORE: '+ correct + ' out of 12</b></p>');
	document.write('<p><ol>');
	document.write('<li>' + question1 + '<br>' + answer1 + '<br><br></li>');
	document.write('<li>' + question2 + '<br>' + answer2 + '<br><br></li>');		
	document.write('<li>' + question3 + '<br>' + answer3 + '<br><br></li>');
	document.write('<li>' + question4 + '<br>' + answer4 + '<br><br></li>');
	document.write('<li>' + question5 + '<br>' + answer5 + '<br><br></li>');
	document.write('<li>' + question6 + '<br>' + answer6 + '<br><br></li>');
	document.write('<li>' + question7 + '<br>' + answer7 + '<br><br></li>');
	document.write('<li>' + question8 + '<br>' + answer8 + '<br><br></li>');
	document.write('<li>' + question9 + '<br>' + answer9 + '<br><br></li>');
	document.write('<li>' + question10 + '<br>' + answer10 + '<br><br></li>');
	document.write('<li>' + question11 + '<br>' + answer11 + '<br><br></li>');
	document.write('<li>' + question12 + '<br>' + answer12 + '<br><br></li>');
	document.write('</ol></p>');
		
	} // end questions
	
	// if there is no query string, tell user to take the quiz for answers
	
	else { 
	
	document.write('<br><br><p align="center">To find out the Summary Quiz answers,<br><br><a class="body" href=' + prevPage + '>click here to take the quiz</a>.</p>');
	
	}		
		
}

// Email Validation Javascript
// copyright 23rd March 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function validateEmail(addr,man,db) {
if (addr == '' && man) {
   if (db) alert('email address is mandatory');
   return false;
}
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      if (db) alert('email address contains invalid characters');
      return false;
   }
}
for (i=0; i<addr.length; i++) {
   if (addr.charCodeAt(i)>127) {
      if (db) alert("email address contains non ascii characters.");
      return false;
   }
}

var atPos = addr.indexOf('@',0);
if (atPos == -1) {
   if (db) alert('email address must contain an @');
   return false;
}
if (atPos == 0) {
   if (db) alert('email address must not start with @');
   return false;
}
if (addr.indexOf('@', atPos + 1) > - 1) {
   if (db) alert('email address must contain only one @');
   return false;
}
if (addr.indexOf('.', atPos) == -1) {
   if (db) alert('email address must contain a period in the domain name');
   return false;
}
if (addr.indexOf('@.',0) != -1) {
   if (db) alert('period must not immediately follow @ in email address');
   return false;
}
if (addr.indexOf('.@',0) != -1){
   if (db) alert('period must not immediately precede @ in email address');
   return false;
}
if (addr.indexOf('..',0) != -1) {
   if (db) alert('two periods must not be adjacent in email address');
   return false;
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   if (db) alert('invalid primary domain in email address');
   return false;
}
return true;
}

// Send email and call certificate page

function sendEmailCert(form) {

if (form.fullname.value == "") {
	alert('Please enter your full name.');
	return false;
}

if (!validateEmail(form.email.value,1,0)) {
  alert('Email address is invalid or was not entered.');
  return false;
  } 

if (form.notify.checked) {

		document.location.href = "mailto:jimcl@theyouthcentre.ca?subject=" + form.fullname.value + " has completed the Raising a Healthy Teenager course&cc=" + form.email.value + "&body=This email confirms that " + form.fullname.value + " has completed the Raising a Healthy Teenager course and is now qualified to enroll in the next parenting course. Jim Clendinning from The Youth Centre will contact " + form.fullname.value + " shortly to make arrangements.";
		document.location.href = "../certificate/certificate.htm?fullname=" + form.fullname.value + "&email=" + form.email.value + ";";
//setTimeout("document.location = ../links/links.htm?name=" + form.fullname.value + "&email=" + form.email.value + ";",300);
	}
	else {
		document.location.href = "../certificate/certificate.htm?fullname=" + form.fullname.value + "&email=" + form.email.value + ";";
	}

}

/////////////////////////////////
// Generate completion form page
// for user to fill in name and email address

function createCompletionForm() {

getValues();

if (adValues['q12']) {

document.write('<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="740" HEIGHT="330"><TR><TD colspan="3" WIDTH="740" HEIGHT="93" valign="top"><IMG SRC="../images/topbordercomplete.gif" WIDTH="740" HEIGHT="93" BORDER="0"></TD></TR><TR><TD WIDTH="25" height="206" background="../images/leftside.gif" valign="top">&nbsp;</TD><TD WIDTH="695" HEIGHT="206" valign="top"><p><br>If you would like to receive a certificate for completion of the course, enter your full name and email address.</p><p>To notify The Youth Centre that you have completed the course, select the "Send notification to The Youth Centre" checkbox.</p><p>Your refreshers and Summary Quiz results are not recorded and will not be sent to any other parties.</p><div align="center"><FORM name="eForm"><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="550"><tr><td class="padded" valign="top" width="150" align="right"><p><strong>Full name:</strong></p></td><td class="padded" valign="top"><input type="text" name="fullname" value="" size="40"></td></tr><tr><td class="padded" valign="top" colspan="2">&nbsp; </td></tr><tr><td class="padded" valign="top" width="150" align="right"><p><strong>Email address:</strong></p></td><td class="padded" valign="top"><input type="text" name="email" size="40" maxlength="40"></td></tr><tr><td class="padded" valign="top" colspan="2"><p>&nbsp;</p></td></tr><tr><td class="padded" valign="top" colspan="2"><p><strong>Your name and email address will only be sent to The Youth Centre if you select the checkbox below. </strong></p></td></tr><tr><td class="padded" valign="top" colspan="2">&nbsp; </td></tr><tr><td class="padded" valign="top" width="150" align="right"><input type="checkbox" name="notify" value="notify"></td><td class="padded" valign="top"><p>Yes, I would like to notify The Youth Centre about my completion of the Raising a "Healthy&quot; Teenager course.</p><p>(Note: Your email application will launch. Add any comments and send the message.)</p></td></tr><tr><td class="padded" valign="top" colspan="2"><p>&nbsp;</p></td></tr><tr><td class="padded" valign="top" colspan="2" align="center"><INPUT TYPE="reset" VALUE="Clear all">&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE="button" VALUE="Submit information" onclick="sendEmailCert(eForm);"></td></tr></TABLE></FORM></div></TD><TD WIDTH="25" height="206" background="../images/rightside.gif" valign="top">&nbsp;</TD></TR><TR><TD colspan="3" WIDTH="740" HEIGHT="93" valign="top"><img src="../images/bottomborder_740.gif" width="740" height="93" border="0" usemap="#Map"><map name="Map"><script language="JavaScript" type="text/javascript"><!-- var prevURL = "../summary/summary02.htm";var coords = "567,22,602,54"; valuesForPrevButton(prevURL, coords); //--></script><area shape="rect" coords="619,22,653,53" href="../links/links.htm" alt="next page"></map></TD></TR><TR><td colspan="3" width="740" valign="top" align="center"><p>&nbsp;</p></td></TR></TABLE>');

} // end if

else { 
	
		document.write('<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="740"><TR><TD colspan="3" HEIGHT="93" valign="top"><IMG SRC="../images/topborderquiz.gif" WIDTH="740" HEIGHT="93" BORDER="0"></TD></TR><TR><TD WIDTH="25" height="80" valign="top" background="../images/leftside.gif">&nbsp;</TD><TD WIDTH="690" valign="top"><p>&nbsp;</p><p>&nbsp;</p><p class="pink">You must take the Summary Quiz before you can<br><br>obtain a Certificate of Completion or<br><br> notify The Youth Centre about your completion for the<br><br><b>Parenting: Raising a Healthy Teenager</b> course.<br><br><a class="body" href="../summary/summary01.htm">Click here to take the Summary Quiz</a></TD><TD WIDTH="25" valign="top" background="../images/rightside.gif">&nbsp;</TD></TR><TR><TD height="80" valign="top" background="../images/leftside.gif">&nbsp;</TD><TD>&nbsp;</TD><TD valign="top" background="../images/rightside.gif">&nbsp;</TD></TR><TR><TD height="19" valign="top" background="../images/leftside.gif">&nbsp;</TD> <TD valign="top">&nbsp;</TD><TD valign="top" background="../images/rightside.gif">&nbsp;</TD></TR><TR><TD colspan="3" HEIGHT="93" valign="top"><img src="../images/bottomborder_740.gif" width="740" height="93" border="0" usemap="#Map"><map name="Map"><area shape="rect" coords="619,22,653,53" href="../links/links.htm" alt="next page"><area shape="rect" coords="563,22,598,54" href="../summary/summary01.htm" alt="previous page"></map> </TD></TR><TR><td colspan="3" valign="top" align="center"><p>&nbsp;</p></td></TR></TABLE>');
	
} // end else

}

/////////////////////////////
// Generate certificate page

function createCertificate() {

getValues();

// date code made by: Nicolas - http://www.javascript-page.com

var today = new Date();
var month = today.getMonth() + 1;
var day = today.getDate();
var year = today.getFullYear();
var s = "/"
var currentdate = month + s + day + s + year;

if (adValues['fullname'] && adValues['email']) {

var name = adValues['fullname'].replace(/%20/g," ");
var capsname = name.toUpperCase();

document.write('<table border="0" cellpadding="0" cellspacing="0" width="740"><tr><td colspan="3" height="55" valign="top"><img src="../images/cert_border_top.gif" width="740" height="55"></td></tr><tr><td width="53" rowspan="2" valign="top" bgcolor="#DFD9B7"> <p align="center"><img src="../images/cert_border_left.gif" width="53" height="389"></p></td><td width="634" height="228" valign="top" bgcolor="#FFFFFF"><div style="padding-left: 10; padding-right: 5; padding-top: 10; padding-bottom: 0"><div align="center"><span class="style8"><img src="../images/cert.gif" width="370" height="50"></span></div><p align="center" class="style6">This is to certify that </p><p align="center" class="style6">' + capsname + '</p><p align="center" class="style14">has completed the course in<br><br><span class="style14"><u>Parenting: Raising a Healthy Teenager</u></span><br></p></div></td><td WIDTH="53" rowspan="2" valign="top" bgcolor="#DFD9B7"><img src="../images/cert_border_right.gif" width="53" height="389"></td></tr><tr><td width="634" height="119" valign="top" bgcolor="#FFFFFF"> <div style="padding-left: 10; padding-right: 10; padding-top: 10; padding-bottom: 10"><p><img src="../images/logo-color.gif" width="170" height="109" align="right"></p><p class="style27">Completion Date:&nbsp;&nbsp;&nbsp;' + currentdate + '</p></div></td></tr><tr><td colspan="3" height="93" valign="top"><img src="../images/cert_border_bottom.gif" width="740" height="55"></td></tr><tr><td colspan="3" height="50" valign="top" align="center"><p align="center"><p align="center"><img src="../images/bottomborderprint.gif" border="0" usemap="#Map2"></p></td></tr></table><map name="Map2"><area shape="rect" coords="73,4,199,36" href="javascript:print();"><area shape="rect" coords="615,4,651,37" href="../links/links.htm" alt="next page"></map>');

} // end if

else { 
	
	document.write('<table border="0" cellpadding="0" cellspacing="0" width="740" height="400"><tr><td colspan="3" height="350" valign="top"><p>&nbsp;</p><p class="pink">You must take the Summary Quiz before<br><br>you can obtain a Certificate of Completion for the<br><br><b>Parenting: Raising a Healthy Teenager</b> course.<br><br><a class="body" href="../summary/summary01.htm">Click here to take the Summary Quiz</a></p></td></tr><tr><td colspan="3" height="50" valign="top" align="center"><p align="center"><p align="center"><img src="../images/bottomborderecertificate.gif" border="0" usemap="#Map2"></p></td></tr></table><map name="Map2"><area shape="rect" coords="615,4,651,37" href="../links/links.htm" alt="next page"></map>');
	
} // end else

}