function checkMail(email)
{
	var filter  = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) return true;
}

// This function will check the format of the date string (Month dd, YYYY) and also check the day of the month to ensure it is valid. it will work correctly for years up to 2029
function checkDate(date) {

	errors = 0;
  regex = new RegExp('(January|February|March|April|May|June|July|August|September|October|November|December) ([0-9]{1,2}), (20[0-2][0-9])');
  parts = regex.exec(date);
	// console.log("parts: "+parts);
	if(parts == null){errors++}
	else {
	  month = parts[1];
	  day = parts[2];
	  year = parts[3];

	  switch(month.toString()) {
	    case "February":
	      days = 28;
	      var isLeap = new Date(year, 1, 29).getDate();
	      if (isLeap == 29) {days = 29}
	      break;
    
	    case "January":
	    case "March":
	    case "May":
	    case "July":
	    case "August":
	    case "October":
	    case "December":
				days = 31;
	      break;
  
	    case "April":
	    case "June":
	    case "September":
	    case "November":
				days = 30;
	      break;
	  }
		if (day > days) {errors++}

		if (errors == 0){return true};
	}
}

$(document).ready(function() {
	
	$("form.validate").submit(function() {
    errors = 0;
    $(":input.required").each(function(index) {
      if ($(this).val() == '') {
        errors++;
        $(".error#e_"+$(this).attr('id')).fadeIn('slow');
      } else {
        $(".error#e_"+$(this).attr('id')).fadeOut('fast');
      };
    });
    if (errors != 0) {return false};
  });
  
	$("ul#qAndA li > p > a").click(function(){
		$("ul#qAndA li span.a:visible").hide();
		$(this).parent().next("span.a").fadeIn("fast");
		return false;
	})
	
	$('a[rel=external]').click(function() {
    window.open($(this).attr('href'));
    return false;
	});
	
});

$(document).ready(function() {
  $("select#agency").bind("change", function() {
	  if (this.value == 0) { 
	    $("#new_agency_div").fadeIn("slow");
	  } else {
	    $("#new_agency_div").fadeOut("slow");
	    $("input#agency_name").val("");
	  }
	});
});

$(document).ready(function() {
  $("li#activities").hover(
    function() {
      $("ul#drop_down_"+this.id).removeClass("hide-drop-down");
      $("ul#drop_down_"+this.id).addClass("drop-down");
    },
    function() {
      $("ul#drop_down_"+this.id).removeClass("drop-down");
      $("ul#drop_down_"+this.id).addClass("hide-drop-down");
    }
  );
  $("ul#drop_down_activities").hover(
    function() { $("li#activities").css("background", "#b3d528"); },
    function() { $("li#activities").css("background", "url('/images/nav-bg.png') repeat-x"); }
    )
});

// $(document).ready(function(){
//  $("#nav li").hover(
//    function(){ $("ul", this).fadeIn("fast"); }, 
//    function() { } 
//  );
//  if (document.all) {
//    $("#nav li").hoverClass ("sfHover");
//  }
// });
// 
// $.fn.hoverClass = function(c) {
//  return this.each(function(){
//    $(this).hover( 
//      function() { $(this).addClass(c);  },
//      function() { $(this).removeClass(c); }
//    );
//  });
// };