jQuery(document).ready(function(){

	//Ajax submit
	jQuery("#ctc_form").validate({
   		submitHandler: function(form) {
   			jQuery("#ctc_form").ajaxSubmit(function(data){
   				jQuery("#ctc_form").clearForm();
   				jQuery("#formfeedback").remove();
   				jQuery("#ctc_form").after('<div id="formfeedback">'+data+'</div>');
   			});
   		}
	});		
	
	//Tooltips
	$("#ctc_social ul li a").jdmtip({
		tiptarget 	: "#ctc_social",
		itemwidth	: 38,
		itempad		: 0,
		margintop	: 30
	});	
});


jQuery.fn.clearForm = function() {
  return this.each(function() {
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form')
   return jQuery(':input',this).clearForm();
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = '';
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 else if (tag == 'select')
   this.selectedIndex = -1;
  });
};
