
//for Quiz
function checkAnswer() {
	if (checkCompletedRadio()) {
		var theLayer = document.getElementById("feedbackLayer");
		theLayer.style.visibility="visible";
		var theText = document.getElementById("feedbackText");
		var theForm = document.getElementById("quiz");
		if (theForm.elements[correctAnswer].checked) { 
			//parent.bottom.tally++;
			theText.innerHTML=txtCorrect;
		}
		else { 
			theText.innerHTML=txtIncorrect;
		}
		//alert(parent.bottom.tally);
		//clearForm();
	}
}

//break out of frames
if (top.location != self.location) top.location = self.location

//window.onload = function() { setOnClick(); }

function setOnClick() {
  if(!document.getElementsByTagName) {
    return;
  }
  var anchors = document.getElementsByTagName("a");
  for (var i=anchors.length; i !=0; i--) {
    var a=anchors[i-1];
    if (a.rel.indexOf("external") != -1) {
	  a.title += " [external site] ";
      //a.onclick = function(){newWin(this.href,'popup1',795,580,'yes','yes','yes','yes','yes');return false;}
    }
    if (a.rel=="coupon") {
      a.title += " [opens in new window] ";
	  a.onclick = function(){newWin(this.href,'coupon',625,500,'yes','no','no','yes','yes');return false;}
    }
    if (a.rel=="quiz") {
      a.title += " [opens in new window] ";
	  a.onclick = function(){newWin(this.href,'quiz',625,575,'yes','no','no','yes','yes');return false;}
    }
    if (a.rel=="newsletter") {
      a.title += " [opens in new window] ";
	  a.onclick = function(){newWin(this.href,'newsletter',700,575,'yes','no','no','yes','yes');return false;}
    }
}
}

function newWin(url,winName,w,h,menubar,toolbar,location,scrollbar,resizable) {
  var winvars = "width=" + w + ",height=" + h + ",menubar=" + menubar + ",toolbar=" + toolbar + ",location=" + location + ",scrollbars=" + scrollbar + ",resizable=" + resizable + ",left=0,top=0";
  var wina = window.open(url, winName, winvars);
}


function makeButtons() {
	document.write("<p>&nbsp;</p>");
	makePrintButton();
	makeCloseButton();
}
function makePrintButton(){document.write(" <input type='button' value='Print' onclick='javascript:window.print()'>");}
function makeCloseButton(){document.write(" <input type='button' value='Close' onclick='parent.window.close()'>");}


//HYGIENE QUIZ
//function to check that a selection has been made for radio button questions
function checkCompletedRadio() {
	var z = 0;
	var theForm = document.getElementById("quiz");
	for (var i = 0; i < theForm.elements.length; i++) {
		if (theForm.elements[i].checked) { 
			z=1;
			userAnswer=i;
		}
	}
	if (z==0) {
		alert("Please select an answer.");
		return false
	}
	else {
		return true
	}
}
function clearForm() {
	var theForm = document.getElementById("quiz");
	for (var i = 0; i < theForm.elements.length; i++) {
		theForm.elements[i].checked=false;
	}
}


function validEmail(email) {
	invalidChars = " /:,;"
	if (email == "") {
		return false
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) != -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) != -1) {
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {
		return false
	}
	if (periodPos+3 > email.length)	{
		return false
	}
	return true
}

//the awesome addLoad Event function by Simon Willison
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}


