// JavaScript Document
function contentHeight() {
  $(".left-column, .pn-content").css("min-height", "").css("min-height", $(".sticky-footer").offset().top);
}
function scrollToAnchor(id) {
  var elem = $('#_' + id);
  if (elem.length > 0) {
    var targetOffset = elem.offset().top;
    $('html,body').animate({ scrollTop: targetOffset }, 1000);
  }

}
var complete = true;
var DFV = new Array("Last Name", "Access Code");
function LoadMarqueeJS() {
  $('#marquee').cycle({ fx: 'fade', speed: "slow", timeout: 7000, pager: '#nav', pauseOnPagerHover: true, sync: true });
  $("#marquee-pause").click(function () { $(this).toggleClass("marquee-paused"); $('#marquee').cycle("toggle"); });
}

function popupMessage() {
  if ($(".Popup").length > 0) {//if element is found on page.
    if (!$.cookie('popup')) {//if no cookie is set show popup otherwise popup is not shown.
      $(".Popup").css({left:0, top:0}).css({ left: 220, top: $(".login-box").offset().top - 135 }).show(); 
    }
  }
}
var SS = false;
var FC = false;
var OVI = false;
$(document).ready(function () {

  popupMessage(); //If no cookie is set show popup message.
  $(".Popup .close-popup").click(function () {//close is clicked set cookie and hide popup.
    $(".Popup").hide();
    $.cookie('popup', 'closed', { expires: 365 });
  });
  //If someone tries to frame us stop em
  if (self != top) { top.location.href = self.location.href; }
  //EnrollTransaction
  //RPG-56 if ($(".ccv").length > 0) {
  //RPG-56  $(".ccv").tooltip({ tip: '#ccvDisplay', effect: 'fade', offset: [0, -($(".ccv").offset().left - 295)]/*position: "top center"*/, events: { input: 'mouseover, mouseout'} });
  //RPG-56 }
  //Demo.aspx functionality
  if ($("#Demo").length > 0) {
    $('#Demo').flash({ swf: '../Demo/Demo_2011.swf', wmode: 'transparent', bgcolor: '#FFFFFF', width: 639, height: 360, hasVersion: 10, expressInstaller: '../Demo/expressInstall.swf' });
  }
  //EnrollAddress.aspx Functionality
  $("input[type='radio']").click(function () {
    if ($("#ctl00_Content_rblReferredBy_9").length > 0 && $("input[type='radio']:checked").val() == 10 && $(this).attr("id") == "ctl00_Content_rblReferredBy_9") { $("#other").slideDown("fast", function () { contentHeight(); }); }
    else { $("#other").slideUp("fast", function () { contentHeight(); }); }
  });
  //EnrollFeature Functionality
  $("#ctl00_Content_cbxSS").live("click", function () {
    if ($(this).attr('checked') == true && SS == false) { SS = true; $(this).attr('checked', true); }
    else { $(this).attr('checked', false); SS = false; }
  });
  $("#ctl00_Content_ctl00").live("click", function () {
    if ($(this).attr('checked') == true && FC == false) { FC = true; $(this).attr('checked', true); }
    else { $(this).attr('checked', false); FC = false; }
  });
  $("#ctl00_Content_ctl03").live("click", function () {
    if ($(this).attr('checked') == true && OVI == false) { OVI = true; $(this).attr('checked', true); }
    else { $(this).attr('checked', false); OVI = false; }
  });
  if ($("#ctl00_Content_cbxSS").length > 0 && $("#ctl00_Content_cbxSS").is(':checked') == true) { alert(""); }
  $(window).resize(function () {
    popupMessage();
    contentHeight();
  });
  $(".more-icon").each(function () { $(this).css({ "height": $(this).parent().height() + "px" }); });
  $(".more-icon, .flyout-icon").mouseenter(function () {
    $(this).prev("a").addClass("temp-active");
  });
  $(".more-icon, .flyout-icon").mouseleave(function () {
    $(this).prev("a").removeClass("temp-active");
  });
  $(".more-icon").click(function () {
    var self = this;
    var open = false;
    $("span.fo-active").each(function () {
      $(this).removeClass("fo-active").siblings("div").hide("fast").parent().removeClass("li-active");
    });
    $("span.mi-active").each(function () {
      if (this == self) { open = true; return; }
      else { $(this).removeClass("mi-active").siblings("ul").slideUp(); }
    });
    if (open == true) { $(this).removeClass("mi-active").siblings("ul").slideUp("normal", function () { contentHeight(); }); }
    else { $(this).addClass("mi-active").siblings("ul").slideDown("normal", function () { contentHeight(); }); }
  });
  $(".flyout-icon").click(function () {
    var self = this;
    var li = $(this).parent();
    var open = false;
    var offset = $(this).parent("li").offset();
    $("span.fo-active").each(function () {
      if (this == self) { open = true; return; }
      else { $(this).removeClass("fo-active").siblings("div").hide("fast").parent().removeClass("li-active"); }
    });
    if (open == true) { $(this).removeClass("fo-active").siblings("div").hide("fast").parent().removeClass("li-active"); }
    else { $(this).addClass("fo-active").siblings("div").toggle("fast").css({ "top": (offset.top - 1) + "px", "left": (li.width() + 40) + "px" }).parent().addClass("li-active"); }
  });
  $('input[type="text"]').blur(function () {
    focusSet = false;
    $(this).css({ backgroundColor: "#EAEAEA" });
    if (this.value == "") { this.value = this.defaultValue; }
  });
  $('input[type="text"]').live("focus", function () {
    //$('input[type="text"]').focus(function () {
    //$("#aaa").append("focus<br/>");
    $(".error-message, .searchAlert, .stateAlert").hide();
    contentHeight();
    focusSet = true;
    if (this.value == this.defaultValue) { this.value = ''; $(this).css({ backgroundColor: "#e6e5e5" }); $(this).select(); return false; }
    if (this.value != this.defaultValue) { $(this).select(); }
    if (this.value == "") { this.value = this.defaultValue; }
  });
  $(".sign-in").click(function () {
    var errors = false;
    $('.error_message').empty();
    $('.error-message').empty().hide();
    $('input[signin="true"]').each(function (i) {
      if ($(this).val() == DFV[i] || $(this).val() == "") {
        $('.error-message').append("<p>*Please supply your " + $(this)[0].defaultValue + ".</p>");
        errors = true;
      }
    });
    if (errors == true) {
      $('.error-message').slideDown("fast");
      return false;
    }
  });
  $(".subscribe").click(function () {
    var errors = false;
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    $('.subscribe-message').empty().hide();
    $('input[subscribe="true"]').each(function () {
      if ($(this).val() == $(this)[0].defaultValue || $(this).val() == "") {
        $('.subscribe-message').append("<p>*Please supply your " + $(this)[0].defaultValue + ".</p>");
        errors = true;
      }
      else if (!emailReg.test($(this).val())) {
        $('.subscribe-message').append("<p>*Please supply a valid " + $(this)[0].defaultValue + ".</p>");
        errors = true;
      }
    });
    if (errors == true) {
      $('.subscribe-message').slideDown("fast");
      return false;
    }
  });
  $(".state-btn").click(function (e) {
    $('input[state="true"]').each(function () {
      if ($(this).val() == $(this)[0].defaultValue || $(this).val() == "" || $(this).val().length < 3) {
        $(".stateAlert").slideDown("slow", function () { contentHeight(); });
        e.preventDefault();
        return false;
      }



      if ($(this).val().length > 3) {
        window.location.href = "Utility/StateRules.aspx#" + $(this).val().split(' ').join('_');
      }
    });
  });

  $(".pn-navigation a").each(function (i) {
    if (i == $.url.param("id") && $.url.param("id") != "") {
      if ($(this).parent("li").parent("ul").hasClass("pn-navigation")) { $(this).next("span.more-icon").triggerHandler("click"); }
      else if ($(this).parent("div").hasClass("flyout-content")) {
        $(this).parent("div.flyout-content").parent("div.flyout").siblings("a").addClass("active").parent("li").parent("ul").parent("li").children("span.more-icon").triggerHandler("click");
      }
      else { $(this).parent("li").parent("ul").parent("li").children("span.more-icon").triggerHandler("click"); }
      $(this).addClass("active");
    }
    var href = $(this).attr("href");
    $(this).attr("href", (href + "?id=" + i));
  });
  if (window.location.hash && window.location.hash.length > 1) {
    setTimeout("scrollToAnchor(window.location.hash.replace('#', ''))", 1000);
  }
  $("a").click(function () { if (this.hash.slice(1)) { scrollToAnchor(this.hash.slice(1)); } });
  $("#CourseContainer div").click(function () {
    var self = this;
    var moveRight = false;
    var left = 0;
    $("#CourseContainer").children("div").children("span").css({ "display": "none" });
    $("#CourseContainer div").each(function (i) {
      var _id = $(this).attr("id");
      if (_id.length < 4) { $(this).attr("id", _id + "_sm"); }
      if (moveRight) { if (i != 0) { $(this).stop().animate({ left: (570 + (left += 35)) + "px" }, 1000); } }
      else if (!moveRight) { if (i != 0) { $(this).stop().animate({ left: (left += 35) + "px" }, 1000); } }
      if (this == self) { moveRight = true; $(this).children("span").css({ "display": "block" }); }
    });
  });
  contentHeight();
  $(function () {
    var availableTags = [

"Alabama",
"Alaska",
"Arizona",
"Arkansas",
"California",
"Colorado",
"Connecticut",
"Delaware",
"District of Columbia",
"Florida",
"Georgia",
"Hawaii",
"Idaho",
"Illinois",
"Indiana",
"Iowa",
"Kansas",
"Kentucky",
"Louisiana",
"Maine",
"Montana",
"Nebraska",
"Nevada",
"New Hampshire",
"New Jersey",
"New Mexico",
"New York",
"North Carolina",
"North Dakota",
"Ohio",
"Oklahoma",
"Oregon",
"Maryland",
"Massachusetts",
"Michigan",
"Minnesota",
"Mississippi",
"Missouri",
"Pennsylvania",
"Rhode Island",
"South Carolina",
"South Dakota",
"Tennessee",
"Texas",
"Utah",
"Vermont",
"Virginia",
"Washington",
"West Virginia",
"Wisconsin",
"Wyoming"
		];
    if ($("#stateSearch").length > 0) {
      $("#stateSearch").autocomplete({
        source: availableTags
      });
    }
  });
});
