function validate_spamFilter(digit1, digit2) {
	var digitSum = parseInt(digit1) + parseInt(digit2);
	jQuery.validator.addMethod(
	  "spamFilter",
	  //this is the class that we assign to the element 
	  function(value, element) {
		if (element.value != digitSum)
		{
		return false;
		}
		else 
		{
		return true;
		}
	  },
	  "Please enter the correct sum of the two numbers."
	);	
}

function spamFilter(d1, d2, fId) {

	validate_spamFilter(d1, d2);
	
	var dSum = parseInt(d1) + parseInt(d2);
	var formId = fId;
	var subButton = formId.find("input[type='submit']");
	var spamFilterElem = formId.find(".spamFilter");
	
	$(formId).keyup(function(){
		if ($(spamFilterElem).val() != dSum) {
			 $(subButton).attr("disabled", "disabled");
		} else {
			$(subButton).removeAttr("disabled");
		}
	});	
		
}


	



$(function(){

	$("form.validateMe").validate();
	//spam filter set in html form, created dynamically with 2 numbers
	
	// set up fck editors and get the id of each one
	//$(".fck").createFckEditors();
	
	// set value of select options to create jump menu		   
	$(".jumpMenu").change(function(){
		var val = $(this).val();
        if (val != '') {
            location.href=val;
        }
	});
	
	$(".datepicker").datepicker({ defaultDate: 0, dateFormat: 'dd/mm/yy', changeMonth: true, changeYear: true });
	
	// .m to display any server side validation messages - after showing them we remove the element from view
	$(".m").delay(4000).fadeOut(4000);
	
	
	// warning for delete links, give users a chance to change their mind
	$("a.delete").click(function(){
		return confirm('Are you sure to delete this item? \n\nThis action cannot be undone!');					   
	});
	
	
	// a function to toggle slide on element, by clicking another
    $(".slider").click(function () {
		var $this = $(this);
		var divID = $this.attr("id").replace("slider_", "slid_");
      $('#'+divID).slideToggle();
	  return false;
    });	
	
	//  shows hides the admin panel on hover. we need to make this better really.... 
	$("#adminContainer").hover(
	  function () {
		$("#adminPanel").slideDown();
		
	  },
	  function () {
		$("#adminPanel").slideUp();
	  }
	);
	

	$(".jHtml").htmlarea({
		// Override/Specify the Toolbar buttons to show
		toolbar: [
			["bold", "italic", "underline", "|", "forecolor"],
			["p", "h1", "h2", "h3", "h4"],
			["link", "unlink", "|", "image", "html"],                    
			[{
				// This is how to add a completely custom Toolbar Button
				css: "custom_disk_button",
				text: "Save",
				action: function(btn) {
					// 'this' = jHtmlArea object
					// 'btn' = jQuery object that represents the <A> "anchor" tag for the Toolbar Button
					alert('SAVE!\n\n' + this.toHtmlString());
				}
			}]
		],

		// Override any of the toolbarText values - these are the Alt Text / Tooltips shown
		// when the user hovers the mouse over the Toolbar Buttons
		// Here are a couple translated to German, thanks to Google Translate.
		toolbarText: $.extend({}, jHtmlArea.defaultOptions.toolbarText, {
				"bold": "fett",
				"italic": "kursiv",
				"underline": "unterstreichen"
			}),

		// Specify a specific CSS file to use for the Editor
		css: "style//jHtmlArea.Editor.css",

		// Do something once the editor has finished loading
		loaded: function() {
			//// 'this' is equal to the jHtmlArea object
			//alert("jHtmlArea has loaded!");
			//this.showHTMLView(); // show the HTML view once the editor has finished loading
		}
	});	


		
});
