var close_panel = true ;

function check_answers (input) {
   var ans3 = input.question3.value.toUpperCase() ;
   return (input.question1[1].checked && input.question2[2].checked && (ans3.indexOf('ROBERT BOURASSA') != -1 || ans3.indexOf('ROBERT-BOURASSA') != -1)) ;
}

function write_date ( ) {
   var d = new Date ( ) ;
   document.quizForm.DateStamp.value = "" + d ;
}

function check_input (input) {
   var okay = false ;
   if (input.question1[0].checked || input.question1[1].checked || input.question1[2].checked &&
      input.question2[0].checked || input.question2[1].checked || input.question2[2].checked &&
      input.question3.value.length != 0) {
      okay = true ;
   }
   else {
      alert ("Sorry! One or more questions were not answered.\nPlease give it another try!\n\n") ;
      okay = false ;
      close_panel = false ;
   }
   if (okay) {
      var msg = "Sorry! One or more fields were not completed.\n" ;
      msg += "Please give it another try!\n\n" ;
      var initial_size = msg.length ;
      msg += input.firstname.value.length == 0 ? "First Name:\n" : "" ;
      msg += input.lastname.value.length == 0 ? "Last Name:\n" : "" ;
      msg += input.email.value.length == 0 ? "E-Mail Address:\n" : "" ;
      if (msg.length == initial_size) {
         if (check_answers(document.quizForm)) {
            alert ('Congratulations! By correctly answering the CDA\'s Educational Quiz your name has been entered\n into a draw for a prize at the 2010 Annual Conference in Niagara Falls, Ontario.\nWatch for updated quiz questions every six months (every March and September) on the CDA website at\n www.cda.ca. Come and take the quiz again!') ;
         close_panel = true ;
         okay = true ;
         }
         else {
            alert ('Sorry! One or more answers are not correct.\nPlease give it another try!\n\n') ;
            close_panel = false ;
            okay = false ;
         }
      }
      else {
         alert (msg) ;
         close_panel = false ;
         okay = false ;
      }
   }
   if (okay)
      write_date() ;
   return okay ;
}

function closePanel() {
   $('div.panel').animate({height: '535px', width: '520px'}, 'slow').animate({height: '0px', width: '520px', top:'0px'}, 'fast', 'linear', function(){$(this).hide();}) ;
}

function quiz_buttons ( ) {
   $('#close_panel').click(function() {
      $('div.panel-contents').show(closePanel()) ;
      close_panel = false ;
      return false ;
   });

   $('.open').click(function(){
      $('div.panel').css({'height':'500px'}) ;
      $('div.panel').slideDown(1000) ;
      $('div.panel-contents').show() ;
      return false ;
   });
}



