var _quizswf = 'http://www.pbs.org/wgbh/pages/frontline/includes/swf/quiz_frolus.swf';
var _quizpieswf = 'http://www.pbs.org/wgbh/pages/frontline/includes/swf/quizpie.swf';
var activeid = '';
var qcolors = ['0x9778c0', '0x79a6e9', '0xe16765', '0xb3db67', '0x777777'];
var activemode = 0;
var answersec = new Array();
var answercount = new Array();
var answerrange = new Array();
var thisrange = new Object();
var nosections = true;
function shower (target) {
$("#"+target).fadeIn();
}
$(document).ready(function () {
if(document.location.href.indexOf('#t') != -1){
var str = document.location.href.substring(document.location.href.indexOf('#t') + 2, document.location.href.length);
navchange(str);
}
$(".topnav").each(function () {
$(this).click(function () {
navchange($(this).attr('id').substring(1,3));
});
});
$(".thumbsup").each(function () {
$(this).click(function () {
$(this).removeClass('thumbsup');
$(this).removeClass('thumbsupon');
$(this).removeClass('thumbsupoff');
$(this).addClass('thumbsupon');
$("#q" + $(this).attr('q') + "d").removeClass("thumbsdown");
$("#q" + $(this).attr('q') + "d").removeClass("thumbsdownon");
$("#q" + $(this).attr('q') + "d").addClass("thumbsdownoff");
document.getElementById($(this).attr('ic') + 'q' + $(this).attr('q')).value = 1;
});
});
$(".thumbsdown").each(function () {
$(this).click(function () {
$(this).removeClass('thumbsdown');
$(this).removeClass('thumbsdownon');
$(this).removeClass('thumbsdownoff');
$(this).addClass('thumbsdownon');
$("#q" + $(this).attr('q') + "u").removeClass("thumbsup");
$("#q" + $(this).attr('q') + "u").removeClass("thumbsupon");
$("#q" + $(this).attr('q') + "u").addClass("thumbsupoff");
document.getElementById($(this).attr('ic') + 'q' + $(this).attr('q')).value = 0;
});
});
$(".standquiz").each(function () {
$(this).click(function () {
quiz_progressive($(this));
});
});
$(".instantquiz").each(function () {
$(this).click(function () {
var specifics = $(this).attr('id').split('q');
quiz_send(null,4,specifics[0],null,false,false,$(this));
});
});
$(".textquiz").each(function (){
$(this).change(function (){
textquiz($(this).attr('p'));
});
});
});
function navchange (idnum) {
$(".tabs").hide();
$(".topnavon").addClass('topnav');
$(".topnavon").removeClass('topnavon');
$("#tab" + idnum).show();
$("#n" + idnum).removeClass('topnav');
$("#n" + idnum).addClass('topnavon');
}
function textquiz (que) {
$("#" + que).find('.reveal').fadeIn();
}
function quiz_progressive (que) {
var parts = $(que).attr('id').split('r');
var divid = parts[0];
var qid = parseInt(parts[1]);
if($(que).val() == "1"){
$("#" + divid + 'r' + qid).find('.yesno:first').html('Right!');
$("#" + divid + 'r' + qid).find('.yesno:first').css({ 'background-color':'#2a4375' });
} else {
$("#" + divid + 'r' + qid).find('.yesno:first').html('Incorrect');
$("#" + divid + 'r' + qid).find('.yesno:first').css({ 'background-color':'#921612' });
}
$("#" + divid + 'r' + qid).find('.reveal').fadeIn();
$("#" + divid + 'r' + qid + 'a').attr('disabled','disabled');
$("#" + divid + 'r' + qid + 'b').attr('disabled','disabled');
if($(que).attr('to') == "1"){
var passgo = true;
var vals = 0;
$("#"+divid).find('input[name^=r]').each(function () {
if(!($(this).attr('disabled'))){
passgo = false;
}
if($(this).attr('checked')){
if($(this).val() == "1"){
vals++;
}
}
});
if(passgo){
$("#" + divid).find(".answercount:first").html(vals.toString());
$("#" + divid).find("p").each(function () {
if($(this).attr('range_high') != undefined){
if(vals >= parseInt($(this).attr('range_low')) && vals <= parseInt($(this).attr('range_high'))){
$(this).fadeIn();
}
}
});
$("#" + divid).find('.hid').fadeIn();
}
}
}
function quiz_c2process (){
var passgo = true;
var scores = new Array();
scores['a'] = 0;
scores['b'] = 0;
scores['c'] = 0;
scores['d'] = 0;
var hazvalues = new Array();
$("#c2").find(':checked').each(function () {
hazvalues[$(this).attr("name")] =1;
scores[$(this).val()] = scores[$(this).val()] + 1;
});
$("#c2").find('input:radio').each(function () {
if(!hazvalues[$(this).attr('name')]){
passgo = false;
}
});
if(passgo){
$("#c2").find("input:radio").attr('disabled','disabled');
$("#c2").find(".hid").show();
$("#c2sub").hide();
var thisone = 0;
if(scores['b'] > scores['a']){
if(scores['d'] > scores['c']){
thisone = 0;
} else {
thisone = 2;
}
} else {
if(scores['d'] > scores['c']){
thisone = 1;
} else {
thisone = 3;
}
}
$("#c2_" + thisone).addClass('highlight');
} else {
alert("Please make sure you've selected an answer for each question and try again");
}
return false;
}
function quiz_send (frm,newmode,divid,submitbutton,verifyall,inhazgraph,instantid){
var passgo = true;
var str = new String();
if(verifyall){
var hazvalues = new Array();
$("#"+divid).find(':checked').each(function () {
hazvalues[$(this).attr("name")] =1;
});
$("#"+divid).find('input:radio').each(function () {
if(!hazvalues[$(this).attr('name')]){
passgo = false;
}
});
}
if(passgo){
var overlaydiv = document.createElement("div");
overlaydiv.className ="quizoverlay";
overlaydiv.setAttribute("id","_quizover");
document.getElementById(divid).appendChild(overlaydiv);
$("#_quizover").html('
');
$("#_quizover").css( { marginTop: (0 - $('#'+divid).height()) - 9, height: $('#'+divid).height(), width: $('#'+divid).width() });
$("#_quizloadimg").css( { marginTop: ($('#'+divid).height() / 2) - 16 });
$(window).resize( function () {
$("#_quizover").css( { width: $('#'+divid).width() });
});
activeid = divid;
if(submitbutton != undefined){
$("#"+submitbutton).hide();
}
var sdiv = document.createElement("div");
sdiv.setAttribute("id","_quizbridge");
document.body.appendChild(sdiv);
activemode = newmode;
hazgraph = false;
if(inhazgraph){
hazgraph = true;
}
nosections = true;
answersec = [];
answercount = [];
if(activemode == 1){
$("#"+activeid).find('input').each(function () {
if($(this).attr('name').indexOf('s') == 0){
var thissec = new Object();
thissec.code = $(this).attr('name');
thissec.value = $(this).val();
answersec.push(thissec);
answercount[thissec.code] = 0;
nosections = false;
}
});
if(!nosections){
$("#"+activeid).find(':checked').each(function () {
for(var v = 0; v < answersec.length; v++){
if($(this).attr(answersec[v].code) == 1){
answercount[answersec[v].code] = answercount[answersec[v].code] + 1;
if(answercount[answersec[v].code] >= answersec[v].value){
document.getElementById(activeid + 'q' + (v + 1)).value = 1;
$("#" + activeid + "b" + answersec[v].code).show();
} else {
document.getElementById(activeid + 'q' + (v + 1)).value = 0;
}
}
}
});
}
$("#"+activeid).find('input:radio').attr('disabled','disabled');
}
if(activemode == 2){
$("#"+activeid).find('input:checkbox').each(function () {
var thisq = $(this).attr("name").substring(1,3);
if($(this).attr("checked")){
document.getElementById(activeid + 'q' + thisq).value = 1;
} else {
document.getElementById(activeid + 'q' + thisq).value = 0;
}
$(this).attr('disabled','disabled');
});
}
if(activemode == 3){
var cnt = 0;
var max = 0;
var min = 0;
answersec = [];
answerrange = [];
thisrange.rangecode = '';
thisrange.id = 0;
$("#"+activeid).find('input:checked').each(function (){
if($(this).attr('name').substring(0,1) == 'c'){
cnt += parseInt($(this).val());
}
if($(this).attr('name').substring(0,1) == 's'){
answersec.push($(this).attr('age'));
thisrange.id = parseInt($(this).val());
}
});
var extcnt = 1;
$("#"+activeid).find('input[name^=r]').each(function (){
var bounds = $(this).val().split('|');
if(extcnt == 1){
min = parseInt(bounds[0]);
}
var thisans = new Object();
thisans.low = parseInt(bounds[0]);
thisans.high = parseInt(bounds[1]);
thisans.letter = $(this).attr('name').substring(1,2);
answerrange.push(thisans);
max = parseInt(bounds[1]);
if(cnt >= parseInt(bounds[0]) && cnt <= parseInt(bounds[1])){
document.getElementById(activeid + 'q' + extcnt).value = 1;
$("#"+activeid+"s" + $(this).attr('name').substring(1,2)).show();
$("#"+activeid+"cs" + $(this).attr('name').substring(1,2)).animate({ 'opacity':1 },1500);
thisrange.rangecode = extcnt;
}
extcnt++;
});
var pos = (Math.ceil(((cnt - min)/(max - min))*100) - 5);
if(pos < 0){
pos = 0;
}
$("#"+activeid+"score").find(".score").html(cnt);
var siz = ($("#"+activeid).width() - 60) / 100;
$("#"+activeid+'i0').css({ 'margin-left': Math.floor(pos * siz) + 'px' },1500)
}
if(activemode == 4){
answercount = [];
var specifics = $(instantid).attr('id').split('q');
str = 'id='+specifics[0];
str += '&q' + parseInt(specifics[1]) + '=';
if($(instantid).val() == "1"){
str += '1'
answercount.push(1);
} else {
str += '0';
answercount.push(0);
}
}
if(activemode != 4){
str = $("#"+frm).serialize();
}
$("#_quizbridge").html('