// JavaScript Document
function validateForm(form, rules) {
  //clear out any old errors
  $("#messages").html("");
  $("#messages").slideUp();
  $(".error-message").hide();

  //loop through the validation rules and check for errors
  $.each(rules, function(field) {

    var val = $.trim($("#" + field).val());

    $.each(this, function() {
      //console.log(this['rule']);

      //check if the input exists
      if ($("#" + field).attr("id") != undefined) {
        var valid = true;

        if (this['allowEmpty'] && val == '') {
          //do nothing
        } else if (this['rule'].match(/^range/)) {

          var range = this['rule'].split('|');
          if (val < parseInt(range[1])) {
            valid = false;
          }
          if (val > parseInt(range[2])) {
            valid = false;
          }
        } else if (this['negate']) {
          if (val.match(eval(this['rule']))) {
            valid = false;
          }
        } else if (!val.match(eval(this['rule']))) {
          valid = false;
        }
		//alert(field+":"+this['rule']+":"+valid+":"+$("#messages"));
        if (!valid) {
          //add the error message
          $("#messages").append("<p>" + this['message'] + "</p>");
			//alert($("#messages").attr("id"));
          //highlight the label
          //$("label[for='" + field + "']").addClass("error");
          $("#" + field).parent().addClass("error");
        }
      }
    });
  });
	//alert($("#messages").html());
  if($("#messages").html() != "") {
    $("#messages").wrapInner("<div class='errors'></div>");
    $("#messages").slideDown();
    return false;
  }

  return true;
}

 $(function(){
 	$("#checkAll").click(function(){
 		if($("#checkAll").attr('checked')== true){
 			var checked = true;
 		}else{
 			var checked = false;
 		}
		$("input:checkbox").each(function(){
			//alert('hi');
			$(this).attr('checked',checked);
		})
 	})
})

$(function() {
    $('#nav').droppy();
  });


jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}