// jQuery functions for Workplace Giving
// by M.Hill, Oct 2009 - Jan 2010, http://www.friskdesign.com
// for Design Culture

//*******************************************************************************************
//
//		GENERAL FUNCTIONS
//
//*******************************************************************************************

jQuery(document).ready(function($) {

// Function to swap two classes
$.fn.swapClass = function(c1, c2){
    return this.each(function(){
        var t = $(this);
        (!t.is('.'+c1)) ? 
            t.addClass(c1).removeClass(c2) : t.addClass(c2).removeClass(c1);
    });
}


// Clear input fields when focussed, return original value if nothing input
 $('input[type=text]').focus(function() {
	 if($(this).val() == $(this).attr('defaultValue')) {
		 $(this).val('');
	}
 })
 .blur(function() {
	 if($(this).val().length == 0) {
		 $(this).val($(this).attr('defaultValue'));
	 }
});


// Fix IE not responding to change events on radio buttons:
// http://norman.walsh.name/2009/03/24/jQueryIE
$(function() {
    if ($.browser.msie) {
        $('input:radio').click(function () {
            this.blur();
            this.focus();
        });
    }
});
	
// New Windows
$('a.newwindow').bind('click',function(){
    window.open(this.href);
    return false;
});

// Close jQuery object
});
 
//*******************************************************************************************
//
//		LIMIT INPUT FIELDS TO SPECIFIC DATA ENTRY
//
//*******************************************************************************************

// Uses "jquery-alphanumeric.js" by Paulo P. Marinas
// http://itgroup.com.ph/alphanumeric/
jQuery(document).ready(function($){
	//	$('#salaryamount').numeric({allow:"."});
	//	$('input.bday').numeric();
	//	$('input.postcode').alphanumeric({allow:" "});
	//	$('#calc-donateamount').numeric({allow:"."});
	//	$('#calc-annualsalary').numeric({allow:"."});		

	$('#phone').numeric({allow:" -"});

 });
 
//*******************************************************************************************
//
//		SCRIPT WRITING COURSE VALIDATION
//
//*******************************************************************************************

jQuery(document).ready(function($){
	$("#script-regform").validate({
		rules: {
			name: "required",
			address: "required",
			email: {
				required: true,
				email: true
			},
			phone: "required",
			paytype: "required"
		},
		messages: {
			name: "Please enter your full name.",
			email: "Please enter a valid email address.",
			address: "Please enter your full address, including Post Code.",
			phone: "Please enter a contact phone number in case we need to confirm anything.",
			paytype: "Will you be paying by Cheque or BACS? Choose one:"			
		}
		/*
		errorElement: "div",
		wrapper: "div",  // a wrapper around the error message
		errorPlacement: function(error, element) {
		    offset = element.offset();
		    error.insertBefore(element)
		    error.addClass('message');  // add a class to the wrapper
		    error.css('position', 'absolute');
		    error.css('left', offset.left + element.outerWidth());
		    error.css('top', offset.top);
		}
		*/
	});
});

