$(document).ready(function() {
  $("#thankyou-poll .questions a").click(function() {
    $(this).parent().addClass("selected").siblings().removeClass("selected");
    $(this).next().click();
  });
});

function KCANewsLetterSignup() {
  var e = false;
  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

  var iname   = $("#thankyou-form input[name='yourname']");
  var iemail  = $("#thankyou-form input[name='youremail']");
  var iparent = $("#thankyou-form input[name='parentsemail']");

  $("#thankyou-form .section").removeClass("error");
  
  if ( iname.val().length == 0 ) { iname.parent().addClass("error"); e=true; }
  if ( !reg.test(iemail.val()) ) { iemail.parent().addClass("error"); e=true; }
  if ( !reg.test(iparent.val()) ) { iparent.parent().addClass("error"); e=true; }

  if ( e == false ) {
    $("#thankyou-form").fadeOut("slow", function() {
      $("#thankyou-subscribed").fadeIn("slow");
    });
    $.post("/common/layout07/data_files/newsletterSignup.jhtml", {name: iname.val(), email: iemail.val(), parents: iparent.val()});
  }
}

function KCAPollSubmit() {
  var id = $("#thankyou-poll .questions .selected input").attr("id");

  if ( !id ) { return false; }
  
  var li = $("#thankyou-poll .questions li");

  $("#thankyou-poll").addClass("complete");
  $("#thankyou-poll .submit").remove();
  $("#thankyou-poll .question").html("Poll Results:");

  $.get("/common/poll/castVote.jhtml",
    {
      "pollName": "kca_2009_sponsored_poll",
      "ballotNum": 0,
      "vote": id,
      "showResults": "true"
    },
    function(data) {
      $(data).find('lineItem').each(function(i) {
        var cli = li.eq(i);
        cli.html('<div class="progressbar"><div class="size" style="width:' + 
                  parseInt($(this).attr("percent")) + 
                  '%"></div></div><span class="percent">' + 
                  parseInt($(this).attr("percent")) + 
                  '%</span><span class="option">' +
                  $(this).attr("name") +
                  '</span>');
      });
    },
    "xml");
}