$(function(){
	$.iCounter = 1;
  $("#frmListItem").validate({
    errorContainer: "#frmListItem_Error",
    errorLabelContainer: "#frmListItem_Error",
    wrapper: "p",
    messages: {
      Species_Species_txt_t: {required:"The field Species is required."},
      Species2_Species_txt_f: {required:"The field Species is required."},
      Gender_Gender_int_t: {required:"The field Gender is required."},
      Description_Description_txt_f: {maxlength:"The field Description can only be 1000 characters long."},
      Price_Price_int_f: {digits:"Please use whole numbers only, no decimals."},
      DateOfBirth_DateOfBirth_date_f: {dateITA:"The field Date of Birth is not a valid date"}
    },
    rules: {
      Species_Species_txt_t: {required: function() {
				if ($("#Species").val() == '' && $("#Species2").val() ==''){
					return true;
				}
				else {
					return false;
				}
			}},
      Species2_Species_txt_f: {required: function() {
        if ($("#Species").val() == '' && $("#Species2").val() == '') {
          return true;
		    }
		    else {
          return false;
		    }
      }},
      Gender_Gender_int_t: {required:true},
      Description_Description_txt_f: {maxlength:1000},
      Price_Price_int_f: {digits:true},
      DateOfBirth_DateOfBirth_date_f: {dateITA:true}
    }
	});
  $("#DateOfBirth").datepicker({showOn: "button",buttonImage: "/images/calendar.gif",buttonImageOnly: true});
  $("#frmListItem #Species").change(function() {
    var iSpeciesID = $(this).val();
    var MethodVal = 'fnRetrieveSpeciesXML';
    if (iSpeciesID == '') {
      $("#frmListItem select#Breed").html('');
      $("#frmListItem select#Breed").append('<option value="">Select a Breed</option>');
      return false;
    }
    $.ajax({
      type: "GET",
      url: "/components/MasterLists.cfc",
      dataType: "xml",
      data: "method="+MethodVal+"&SpeciesID="+iSpeciesID,
      success: function(xml){
        $("#frmListItem select#Breed").html('');
        $("#frmListItem select#Breed").append('<option value="">Select a Breed</option>');
        $(xml).find('breed').each(function(){
          $("#frmListItem select#Breed").append('<option value="' + $(this).text() + '">' + $(this).text() + '</option>');
        });
      }
    });   
  });
});

$(function(){
    $("#Species").change(function (){
    	$("#newBreed").css({'display' : 'none'});
		$("#Breed").attr('disabled','');
	});
});

$(function(){
    $("#btnNewSpecies").click(function (){
    	$("#newSpecies").css({'display' : 'block'});
		$("#Species").attr('disabled','disabled');
	});
});

$(function(){
    $("#newSpeciesCancel").click(function (){
    	$("#newSpecies").css({'display' : 'none'});
		$("#Species").attr('disabled','');
	});
});

$(function(){
    $("#btnNewBreed").click(function (){
    	$("#newBreed").css({'display' : 'block'});
		$("#Breed").attr('disabled','disabled');
	});
});

$(function(){
    $("#newBreedCancel").click(function (){
    	$("#newBreed").css({'display' : 'none'});
		$("#Breed").attr('disabled','');
	});
});