        var nameRegex=/^[^!@#$%<>]+$/i;
        var numRegExp  = /(^-?\d\d*$)/;
      //Button on and off effects
      $(".registerOff").hover(
        function(){
          $(this).removeClass('registerOff').addClass('registerOn');
        },
        function(){
          $(this).removeClass('registerOn').addClass('registerOff')
        }
      );
      //calender init
      var init = function(){
        $.datePicker.setDateFormat('mdy','/');
        $('input#startDate').datePicker({endDate:'01/01/2500'});
        $('input#endDate').datePicker({endDate:'01/01/2500'});
        //$('input#paymentDueDate').datePicker();
      }
      //dropdown hint text
      $(".hintDropdown").bind("focus",function(){
        $(this).removeClass("hintTxt");
      });
      $(".hintDropdown").bind("blur",function(){
        if($(this).val()==""){
          $(this).addClass("hintTxt");
        }else {
          $(this).removeClass("hintTxt");
        }
      });
      $("#birthYear,#year").change(function() {
        var year=$("#year").val();
        var birthYear=$("#birthYear").val();
        if((birthYear!="") && (year!="") && (numRegExp.test(birthYear))){
          $("#year").valid();
          $("#birthYear").valid();
        }
      });
      function checkValidSchool(){
          if($("#tmpSchool").val()!=$("#query").val()){
            return false;
          }   else {
          	return true;
          }   	
      }
      var appendClasses = function () {
        var selectedItems = [];
        $('#classList_select option:selected').each(function(i, selected){
          selectedItems[i] = $(selected).attr("value");
          $(selected).remove();
        });
        var appendOptString = "";
        for(i=0;i<selectedItems.length;i++) {
          appendOptString += "<option value=\"" + selectedItems[i] + "\">" + "Class of " + selectedItems[i].split("|")[2] + "</option>";
        }
        $('#selectedClassList_select').append(appendOptString);
        sortSelectYears("selectedClassList_select");
        updateOtherCommunityKeys();
      };
      var removeClasses = function (selectedClassList_select, classList_select) {
        var selectedItems = [];
        $('#selectedClassList_select option:selected').each(function(i, selected){
          selectedItems[i] = $(selected).attr("value");
          $(selected).remove();
        });
        var appendOptString = "";
        for(i=0;i<selectedItems.length;i++) {
         appendOptString += "<option value=\"" + selectedItems[i] + "\">" + "Class of " + selectedItems[i].split("|")[2] + "</option>";
        }
        $('#classList_select').append(appendOptString);
        sortSelectYears("classList_select");
        updateOtherCommunityKeys();
      };
      var sortSelectYears = function(selectEleId) {
        var newArrayYears = [];
        var newArrayObjects = {};
        $("#" + selectEleId + " option").each(function() {
          var optVal = $(this).val();
          var optYear = parseInt(optVal.split("|")[2]);
          newArrayObjects[optYear] = optVal;
          newArrayYears.push(optYear);
        });
        $("#" + selectEleId).html("");
        newArrayYears.sort();
        var appendOptString = "";
        for(var i=newArrayYears.length-1; i>=0; i--) {
          appendOptString += "<option value=\"" + newArrayObjects[newArrayYears[i]] + "\">" + "Class of " + newArrayYears[i] + "</option>";
        }
        $("#" + selectEleId).html(appendOptString);
        $("#" + selectEleId)[0].selectedIndex = -1;
      };
      var toggleOtherClasses = function(visible) {
        if(visible) {
          $("#selectedClassList_select,#classList_select").show();
          $("#inviteOtherClassDiv").show();
          $("#otherClassesAddEnabled").hide();
          $("#otherClassesAddDisabled").show();
          //anchorNearClassYear($("#communityKey").val());
        } else {
          $("#selectedClassList_select,#classList_select").hide();
          $("#inviteOtherClassDiv").hide();
          $("#otherClassesAddDisabled").hide();
          $("#otherClassesAddEnabled").show();
          $("#enabledOtherClassesLink").hide();
        }
        if((checkValidSchool()) && ($("#year").val() > 0)) {
          //$("#disabledOtherClassesLink").hide();
          //$("#enabledOtherClassesLink").show();
        }
      };
      var getClassEventCreationInfo = function() {
        $.ajax({
          type: "GET",
          url: "/registration/services/getAffiliations",
          data: "communityId=" + $("#communityId").val(),
          dataType: "json",
          success: function(resp) {
            var classYears=resp.classYears.split(";");
            if(classYears.length>0) {
              $("#allClassCommunityKeys").val("");
              $("#invitedClassCommunityKeys").val("");
              $("#nonInvitedClassCommunityKeys").val("");
              $("#allClassCommunityKeys").val(classYears.join(","));
              var appendOptString = "";
              var otherClassLen=classYears.length;
              for(var i=classYears.length-2; i>-1; i--) {
                if(classYears[i].split("|")[2]!=$("#year").val()){
                  appendOptString += "<option value=\"" + classYears[i] + "\">" + "Class of " + classYears[i].split("|")[2] + "</option>";
                }
              }
              $('#classList_select').html(appendOptString);
              $('#classList_select')[0].selectedIndex=-1;
              if($('#classList_select option').size()>0) {
                //$("#disabledOtherClassesLink").hide();
                $("#enabledOtherClassesLink").show();
                //toggleOtherClasses(true);
              } else {
                $("#enabledOtherClassesLink").hide();
                //$("#disabledOtherClassesLink").show();
                toggleOtherClasses(false);
              }
              //toggleOtherClasses(true);
            } else {
              $("#enabledOtherClassesLink").hide();
              //$("#disabledOtherClassesLink").show();
              //$("#communityId").val("");
            }
          },
          error: function() {
            alert("error");
          }
        });
      }
      var restoreClasses = function () {
        $("#classList_select").append($('#selectedClassList_select').html());
        $('#selectedClassList_select').html("");
        sortSelectYears("classList_select");
        toggleOtherClasses(false);
      };
      var updateOtherCommunityKeys = function() {
        var icyString = "";
        $('#selectedClassList_select option').each(function(i, selected){
          icyString += $(selected).attr("value") + ((i<$('#selectedClassList_select option').size()-1)?",":"");
        });
        $("#invitedClassCommunityKeys").val(icyString);
        icyString="";
        $('#classList_select option').each(function(i, selected){
          icyString += $(this).attr("value")+",";
        });
        $("#nonInvitedClassCommunityKeys").val(icyString);
      };
      function submitForm(){
        updateOtherCommunityKeys();
        if($("#school_info").valid()){
          if($("#currentLastName").val()==$("#currentLastName").attr("hint")){
            $("#currentLastName").val(" ");
          }
          if($("#eventDetailsTextarea").val()==$("#eventDetailsTextarea").attr("hint")){
            $("#eventDetailsTextarea").val(" ");
          }
        }
      }
      var checkIClass=$("#invitedClassCommunityKeys").val();
      if((checkIClass=='undefined') || (checkIClass=="")){
        toggleOtherClasses(false);
      } else {
        toggleOtherClasses(true);
      }
      $(document).ready(function(){
        $(".hintTxt").each(function(){
          if(($(this).val()!="") && ($(this).val()!=$(this).attr("hint"))){
            $(this).removeClass("hintTxt");
          }
        });
        init();
        function toggleOtherClasseVlaues(){
          if(($("#year").val()!="") && (checkValidSchool())) {
            $('#selectedClassList_select, #classList_select').html('');
            getClassEventCreationInfo();
          } else {
              $("#enabledOtherClassesLink").hide();
              //$("#disabledOtherClassesLink").show();
              toggleOtherClasses(false);
          }
        }
        $("#query").blur(toggleOtherClasseVlaues);
        $("#query").change(function(){
          //$("#communityId").val("");
          toggleOtherClasses(false);
        });
        $("#year").change(toggleOtherClasseVlaues);
        var onAutocompleteSelect = function(value, data) {
          //$('#selection').html('<img src="\/global\/flags\/small\/' + data + '.png" alt="" \/> ' + value);
          $("#communityId").val(data.split(",")[0]);
          $("#communityType").val(data.split(",")[1]);
          $("#tmpSchool").val(value);
          $("#query").focus();            
          if(($("#query").valid()) && ($("#year").val()>0)){
            getClassEventCreationInfo();
          }
        }
        function fnFormatResult(value, data, currentValue) {
          alert(1);
        }
        $(".date-picker").bind("change",function(){
          $(this).removeClass("hintTxt");
          $(this).focus().blur();
        });
        $('#query').autocomplete({
          serviceUrl: '/registration/services/predictiveSearch/edu',
          minChars:2, 
          width: 467,          
          delimiter: /(;)\s*/,
          onSelect: onAutocompleteSelect,
          deferRequestBy: 100
        });


        $.validator.addMethod("validateString", function(value, element) {
          if(!nameRegex.test(value)) { return false; }
          return true;
        }, "Please enter a valid name");
        $.validator.addMethod("validateNumber", function(value, element) {
          if(!numRegExp.test(value)) { return false; }
          return true;
        }, "Please enter a valid year");
        $.validator.addMethod("checkEmpty", function(value, element) {
          var id=element.id;
          if((value==$("#"+id).attr("hint")) || value==""){
            return false;
          }
          return true;
        }, "Please enter a valid date.");
        $.validator.addMethod("validDate", function(value, element) {
          return /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/.test(value);
        }, "Please enter a valid date.");
        $.validator.addMethod("dateRange", function(value, element) {
            var sdate = new Date();
            var edate = new Date();
            var eventSDate=$("#startDate").val().split("/");
            var eventEDate=value.split("/");
            var eventSTime=$("#startTime").val();
            var eventETime=$("#endTime").val();
            if((eventEDate.length==3) && (eventSDate.length==3)){
              //Set date
              sdate.setFullYear(eventSDate[2],eventSDate[1],eventSDate[0]);
              edate.setFullYear(eventEDate[2],eventEDate[1],eventEDate[0]);
              //get event start time hours and minutes
              var eventSHours,eventSSecs,eventEHours,eventESecs;
              if((eventSTime!="") && (eventETime!="")){
                eventSTime=eventSTime.split(" ");
                eventSHours=eventSTime[0];
                if(eventSTime[1]=="PM"){
                  var eventSTime=eventSHours.split(":");
                  eventSHours=parseInt(eventSTime[0])+12;
                  eventSSecs=eventSTime[1];
                  sdate.setHours(eventSHours,eventSSecs);
                }
                eventETime=eventETime.split(" ");
                eventEHours=eventETime[0];
                if(eventETime[1]=="PM"){
                  var eventSTime=eventEHours.split(":");
                  eventEHours=parseInt(eventETime[0])+12;
                  eventESecs=eventETime[1];
                  edate.setHours(eventEHours,eventESecs);
                }
              }
              if(sdate>edate){
                return false;
              }
            }
            return true;
        }, "End date and time cannot be before current date and time");
        $.validator.addMethod("validYearComb", function(value, element) {
          var year=$("#year").val();
          var birthYear=$("#birthYear").val();
          if((birthYear!="") && (year!="") && (numRegExp.test(birthYear))){
            return year>birthYear;
          }
          return true;
        }, "Please enter a valid date.");
        $.validator.addMethod("validSchool", function(value, element) {
          return checkValidSchool()
        }, "Please enter a valid date.");
        var validator = $("#school_info").validate({
          rules: {
            query: { validSchool: true},
            year: {required: true, validYearComb: true},
            name: {checkEmpty: true},
            startTime: {required: true},
            startDate: {checkEmpty: true, validDate: true},
            endTime: {required: true},
            endDate: {checkEmpty: true, validDate: true, dateRange: true},
            currentFirstName: {required: true, validateString:true},
            affiliationLastName: {required: true, validateString:true},
            currentLastName: { validateString:true},
            email: {required: true, email: true},
            birthYear: {checkEmpty: true, validateNumber: true, validYearComb: true}
          },
          messages: {
            query: {validSchool: "Please enter a valid school name."},
            year: {required: "Please choose a graduation year.", validYearComb: "Please select a valid year of birth and graduation year combination."},
            name: {checkEmpty: "* Required"},
            startTime: {required: "* Required"},
            startDate: {checkEmpty: "<br /><br />* Required", validDate: "Please enter a valid date."},
            endTime: {required: "* Required"},
            endDate: {checkEmpty: "<br /><br />* Required", validDate: "Please enter a valid date.", dateRange: "End date and time cannot be before current date and time."},
            currentFirstName: {required: "Please enter a current first name.", validateString: "Please enter a valid current last name."},
            affiliationLastName: {required: "Please enter a last name at graduation.", validateString: "Please enter a valid last name at graduation"},
            currentLastName: { validateString: "Please enter a valid current last name."},
            email: {required: "Please enter an email address.", email: "Please enter a valid email."},
            birthYear: {checkEmpty: "Please enter your year of birth.", validateNumber: "Please enter a valid graduation year.", validYearComb: "Please select a valid year of birth and graduation year combination."}
         },
         onkeydown: false,
         onkeyup: false
        });
      });
