/* NOTES

	Params object is never extended. We keep this original
	in order to preserve behaviour, like setting specific 
	default names for vtypes when no message has been set
	(instead of overriding default message). 
	
	thisOpts object is the extended version of options and params. 
	This is used in the event there are globals in the options that 
	need to override parameters.
	
	params and thisOpts are used interchangeably depending on their 
	importance to the multi-levelled process of configuration.

*/

(function($){
	
	/* Function for validating a form */
	$.fn.validate = function(options){
		
		/* Extend and overwrite defaults with object specific options */
		var opts = $.extend({}, $.fn.validate.defaults, options);
		
		/* Iteration var for each form we find */
		var f=0;
		
		/* Loop through matching forms */
		return this.each(function(){
			
			/* Cache form in object */
			var $form = $(this);
			
			/* Bind options of each form for later retrieval (on refresh etc.) */
			$form.data("options", options);
			
			/* Cache the parent element id */
			var parentID = $form.attr("id");
			
			/* If there is no ID, assign a default "id" 
			   for adding useful elements */
			if(parentID == "") parentID = "form" + f;
			
			/* Increment the iterator var */
			f++;
			
			/* Iteration var for each element within the form  */
			var i = 0;
			
			/* Match specific elements within the resulting forms */
			$form.find("input[type!='radio'], textarea, .radioGroup, .select").each(function(){
				
				/* Matched element (input, or textarea) */
				var $el = $(this);
				
				/* Element specific parameters (passed by rel attr) */
				var params = $.fn.validate.evalRel($el.attr("rel"));
				
				/* Check if we should proceed with validating this form element */
				if($el.attr('disabled') == true || $el.css('display') == 'none')
					return true;
					
				/* Check if it has class select and is a select, otherwise don't proceed */
				if( $el.hasClass('select') && $el.get(0).nodeName != 'SELECT' ){
					return true;
				}
				
				/* If it has a class called ignoreValidation */
				if( $el.hasClass('ignoreValidation') ){
					return true;	
				}
				
				/* Proceed only if validation parameters object was returned */
				if(params || opts){
				
					/* Assign position of element in the form to data object */
					$el.data("i", i);
					
					/* Overwrite the options with parameters if needed */
					var thisOpts = $.extend({}, opts, params);
					
					/* Add a div after each element for absolute positioning */
					/* Exceptions are radio buttons and submit */
					if($el.attr('type') != 'submit' && $el.attr('type') != 'radio'){
						if(opts.inputTips){
							$('<div class="validation-tip-wrapper"></div>').insertAfter($el);
						}
					}
					
					/* Attached tips IDs */
					if(!thisOpts.customID){
					 var tipID = parentID + "-tip-" + $el.data("i");
					} else var tipID = thisOpts.customID;
					
					/* Check if the tip needs to be created */
					if(thisOpts.inputTips){
						if($("#" + tipID).length == 0){
	
							var elWidth = ($el.css("width"));
							
							var widthLen = elWidth.length - 2;
							
							var elPos = parseInt(elWidth.substr(0, widthLen)) + 6;
							
							var html = '<div id="' + tipID + '" class="' + thisOpts.inputTipCls + '" style="width:'+elWidth+';">' + thisOpts.msg + '</div>';
	
							/* Append the tip to the div which follows the element (added onload) */
							$el.next("div").append(html);
						}
					}
					
					// BLUR
					/* Only invalidate on blur, 
					   and only if validation on blur is true */
					if(thisOpts.validateOnBlur !== false){
						$el.blur(function(){
											
							/* Change the class based on state */
							var returnState = globalValidate(thisOpts, $el, params, parentID);
							
							/* The element did validate */
							if(returnState == 1){
								
								/* Function to execute when validated */
								if(params.onValidate){
									window[params.onValidate](true, el);
								}
								
								/* If the tip exists, hide it now */
								if($("#" + tipID).length > 0){
									$("#" + tipID).hide();
								}
							
							/* The element did not validate */
							} else if(returnState == 0){
								
								/* Function to execute when invalidated */
								if(params.onInvalidate){
									window[params.onInvalidate](false, el);
								}
								
								/* Display the tip */
								if(thisOpts.inputTips)
								$("#" + tipID).show();
							}
						});	
					}
					
					/* Validate on change */
					if(thisOpts.validateOnChange !== false){
						$el.change(function(){
											
							/* Change the class based on state */
							var returnState = globalValidate(thisOpts, $el, params, parentID);
							
							/* The element did validate */
							if(returnState == 1){
								
								/* Function to execute when validated */
								if(params.onValidate){
									window[params.onValidate](true, el);
								}
								
								/* If the tip exists, hide it now */
								if($("#" + tipID).length > 0){
									$("#" + tipID).hide();
								}
							
							/* The element did not validate */
							} else if(returnState == 0){
								
								/* Function to execute when invalidated */
								if(params.onInvalidate){
									window[params.onInvalidate](false, el);
								}
								
								/* Display the tip */
								if(thisOpts.inputTips)
								$("#" + tipID).show();
							}
						});	
					}
					
					// KEY PRESS
					/* But re-validate on key presses */
					if(thisOpts.revalidateOnKey !== false){
						$el.keypress(function(){
							/* Only validate if state is on */
							if($el.data("state") == 0){
								var returnState = globalValidate(thisOpts, $el, params, parentID);
								
								if(returnState == 1){
									if($("#" + tipID).length > 0){
										$("#" + tipID).hide();	
									}
								}
							}
						});
					}
					
					// FILE SELECTION
					if($el.attr('type') == 'file')
					$el.change(function(){
						var returnState = globalValidate(thisOpts, $el, params, parentID);
					});
					
					// FOCUS
					/* Input tip displayed */
					if(thisOpts.inputTips){
						
						$el.focus(function(){
											 
							if($el.data("state") == 0){
								/* Display the tip */
								$("#" + tipID).show();
							}
							
						});
						
						/* Checkbox behaviour is different */
						if($el.attr("type") == "checkbox" && thisOpts.checked){
							$el.hover(function(){
								
								var html = '<div id="' + tipID + '" class="' + thisOpts.inputTipCls + '">' + thisOpts.msg + '</div>';
								$(this).next("div").append(html);
								
								if($(this).data("state") == 0 || !$(this).data("state")){
									$("#" + tipID).show();
								}
								
							});
							
							$el.mouseout(function(){
								$(this).next("div").html("");
							});
						}
					}
				
				}
				
				
				
				/* For radio group */
				if($el.hasClass('radioGroup')){
					var $radioGroup = $el;
					/* For changing class of group container to valid */
					$radioGroup.find('input').change(function(){
						/* Change the class immediately to success */
						$radioGroup.removeClass(thisOpts.failureCls);
						$radioGroup.removeClass(thisOpts.successCls).addClass(thisOpts.successCls);
						
						/* Hide the validation tip */
						$('#' + tipID).hide();
						$el.data("state", 1);
					});
				}
				
				/* Increment the iterator var */
				
				i++;
				
			});
			
			/* Remove enter key submission from input elements */
			$form.find("input").each(function(){
				$(this).keypress(kH);
			});
			
			/* Assign total number of elements being validated to data object in parent element */
			$(this).data("count", i);
			
			/* CLICK (submit) */
			
			$(this).submit(function(){
				//$(this).unbind();
				var i=0; var x=0;
				$form.find("input[type!='submit'], textarea, .radioGroup, .select").each(function(){
					
					/* Matched element */
					var $el = $(this);
					
					/* Parameters (passed by rel attr) */
					var params = $.fn.validate.evalRel($el.attr("rel"));
					
					/* Overwrite the options with parameters if needed */
         			var thisOpts = $.extend({}, opts, params);
					
					var cont = true;
					
					/* If it has a class called ignoreValidation */
					if( $el.hasClass('ignoreValidation') ){
						cont = false;	
					}
					
					/* Check if we should proceed with validating this form element */
					if($el.attr('disabled') == true){
						cont = false;

					}
					$el.parents().each(function(){
						if($(this).css('display') == 'none'){
							cont = false;
							return false;	
						}
					});
				  
				  /* Check if it has class select and is a select, otherwise don't proceed */
				  if( $el.hasClass('select') && $el.get(0).nodeName != 'SELECT' ){
					 return true;
				  }
				  
				  /* Check if we should proceed with validating this form element */
				  if($el.attr('disabled') == true || $el.css('display') == 'none'){
					cont = false;
				  }
						  
				  /* Check if it's a hidden input and don't continue */
				  if( $el.attr('type') == 'hidden' ){
				    cont = false;
				  } 
				  
					/* Check if an object was parsed via the rel tag */
					if((params || thisOpts) && cont){
						
						/* Validate element */
						returnState = null;
						if($el.data("validateOnSubmit") !== false)
						returnState = globalValidate(thisOpts, $el, params, parentID);
						
						/* If element does not validate, increment iterator var */
						returnState == 0 ? i++ : '';
					}
					
					/* Make a label for the parameter if html label exists */
					if(!params.label && $el.prev("label")){
						params.label = $el.prev("label").text();
					}
					
					/* SUMMARY */
					
					/* Check a summary element has been configured */
					if(opts.summaryEl){
						
						/* Add the individual message if it doesn't exist in the DOM yet */
						var messageEl = parentID + "-summary-" + x;
						
						if(returnState == 0){
							if(!document.getElementById(messageEl)){
								var summaryEl = "#" + opts.summaryEl;
								var html = $(summaryEl).html();
								var tip = '<div class="' + opts.summaryMsgCls + '" id="' + messageEl + '"><span>' + params.label + ': </span>' + $el.data("msg") + '</div>';
								$(summaryEl).append(tip);
							}
						} else if(document.getElementById(messageEl)){
							$("#" + messageEl).remove();
						}
					}
					
					
					
					/* Attached tips IDs */
					if(thisOpts.inputTips){
						  if(!thisOpts.customID){
						   var tipID = parentID + "-tip-" + $el.data("i");
						  } else var tipID = thisOpts.customID;
					
						if($("#" + tipID).length == 0 && $el.data("state") == 0 && thisOpts.inputTips){
								
							var elWidth = ($el.css("width"));
							
							var widthLen = elWidth.length - 2;
							
							var elPos = parseInt(elWidth.substr(0, widthLen)) + 6;
							
							var html = '<div id="' + tipID + '" class="' + thisOpts.inputTipCls + '" style="width:'+elWidth+';">' + $el.data("msg") + '</div>';
							
							/* Append the tip to the div which follows the element (added onload) */
							$el.next("div").append(html);
							
							/* Display the tip */
							if(thisOpts.inputTips)
							$("#" + tipID).show();
							
						} else {
							if($el.data("state") == 0){
								/* Display the tip */
								if(thisOpts.inputTips)
								$("#" + tipID).show();
							}
						}
					}
					
					/* Increment the iterator var */
					x++;
					
				});
				
				
				
				/* SUBMIT FORM */
				/* Reset the valid data object */
				$form.data('valid', false);
				/* Try and submit the form */
				var submitForm = false;
				if(i == 0 && !options.preventSubmit){
					submitForm = true;
				}
				
				if(i == 0 && options.onSubmitSuccess){
					options.onSubmitSuccess($form);
					if(options.preventSubmit){
						submitForm = false;
					} else submitForm = true;
				}
				
				if(i > 0) {
				  
					if(options.onSubmitFailed){
						
						/* Function to return on submission failure */
						options.onSubmitFailed($form);
						
						/* Show the summary of validation failures */
						$("#" + opts.summaryEl).show();
					}
					
					/* Form should not submit */
					submitForm = false;
				} else if(i == 0){
				  $form.data('valid', true);
				}
				
				if(submitForm) return true;
				else return false;
				
			});
			
		});
		
		function globalValidate(opts, $el, params, parentID){

			/* Intialise some objects and vars */
			var st = new Array(); 
			var i = $el.data("i");
			var val = $el.val();
			var pattern;
			
			switch(opts.vtype){
					
			/* Check if value is a valid email address. */
			case "email" :
				pattern = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+$/;
				if(validate(val, pattern, false) == false){
					/* State will be needed to determine key up validation */
					st.push(0);
				}
				
				/* Default message */
				!params.msg ? opts.msg = opts.messages.email:'';
				
				
			break;
			
			case "phone" : 
				pattern = /^(\d+$)|^(\+\d+$)|^(\(\d{2,3}\)\d+$)/;
				if(validate(val, pattern, true) == false){
					st.push(0);
				}
				
				/* Default message */
				!params.msg ? opts.msg = opts.messages.phone:'';
				
				
				
			break;
			
			case "password" : 
				pattern = /^[a-zA-Z\d]+/;
				if(validate(val, pattern, false) == false){
					st.push(0);
				}
				
				/* Default message */
				!params.msg ? opts.msg = opts.messages.password:'';
				
			break;
			
			case "date" :
				
				pattern = /^\d{1,2}([\-|\/|\.|\\])\d{1,2}([\-|\/|\.|\\])\d{4}$/;
				
				if(validate(val, pattern, false) == true){
					
					/* Get the length of the date string */
					var dateParts;
					if(val.indexOf("/") !== -1){
						dateParts = val.split("/");
					} else if (val.indexOf("\\") !== -1){
						dateParts = val.split("\\");
					} else if (val.indexOf("-") !== -1){
						dateParts = val.split("-");
					} else if (val.indexOf(".") !== -1){
						dateParts = val.split(".");
					}
					
					var d = new Array();
					
					d[0] = parseInt(dateParts[0]);
					d[1] = parseInt(dateParts[1]);
					d[2] = parseInt(dateParts[2]);
					
					switch(opts.dateFormat){
						
						case "mm/dd/yyyy" : 
						
						if(parseDate(d[1], d[0], d[2]) == false){
							st.push(0);
						}
						
						break;
						
						case "dd/mm/yyyy" :
						
						if(parseDate(d[0], d[1], d[2]) == false){
							st.push(0);
							
						}
						
						break;
					}
				} else {
					st.push(0);	
				}
				
				/* Default message */
				!params.msg ? opts.msg = opts.messages.date:'';
				
			break;
			
			case 'RSAID' :
				
				/* ************************ CODE FROM IGNITION DEVELOPERS **************************** */
				
				if(val.length != 13)//added check to see if id number is 13 digits long
				{
					st.push(0);
				} else {
					
					var mm = val.substring(2,2);
					var dd = val.substring(4,2);
					
					if((mm>12)||(dd>31))
					{
						st.push(0);
						break;
					}
					
					if(val.indexOf('000000') != -1)
					{
						st.push(0);
						break;		
					}
					
					var ID = val.split('');
					var val1 = parseInt(ID[0]) + parseInt(ID[2]) + parseInt(ID[4]) + parseInt(ID[6]) + parseInt(ID[8]) + parseInt(ID[10]);
					
					var val2 = eval(ID[1]+ID[3]+ID[5]+ID[7]+ID[9]+ID[11]) * 2;
					val2 += "";
					var arr = val2.split('');
					
					var val3 = 0;
					for (var k = 0; k < arr.length; k++) {
						val3 += parseInt(arr[k]);
					}
					
					var val4 = val1 + val3;
					val4 += "";
					arr = val4.split('');
					
					var val5 = 10 - arr[1];
					
					if (val5 == 10)
						val5 = 0;
						
					if (val1==0 || val2==0)
					{
						st.push(0);
						break;
					}
						
					if (val5 != ID[12]){
						st.push(0);
					}
				}
				
			break;
				
			}
			
			/* Check for hint value */
			if(opts.hintValue){
				if(val == opts.hintValue){
				  st.push(0);
				}
			  }
			
			/* Check for min length / max length parameters */
			if(opts.maxLength){
				if(val.length > params.maxLength){
					st.push(0);
				}
				
				/* Default message */
				!params.msg ? opts.msg = opts.messages.maxLength.replace("{x}", opts.maxLength):'';
				
			}
			
			if(opts.minLength){
				if(val.length < params.minLength){
					st.push(0);
				}
				
				/* Default message */
				!params.msg ? opts.msg = opts.messages.minLength.replace("{x}", opts.minLength):'';
			}
			
			if(opts.setLength){
				if(val.length != params.setLength){
					st.push(0);
				}
				
				/* Default message */
				!params.msg ? opts.msg = opts.messages.minLength.replace("{x}", opts.minLength):'';
			}
			
			/* Check for data type */
			if(opts.dataType){
				switch(opts.dataType){
					
					/* Only whitespace and alphabetic characters */
					case "alpha" : 
						if(!validate(val, /^[a-zA-Z]+$/, true)){
							st.push(0);
						}
						
						/* Default message */
						!params.msg ? opts.msg = opts.messages.alpha:'';
						
					break;
					
					/* Only whitespace and integers */
					case "int" :
						if(!validate(val, /^[\d]+$/, true)){
							st.push(0);
						}
						
						/* Default message */
						!params.msg ? opts.msg = opts.messages.int:'';
						
					break;
					
					/* Only whitespace, integers, and alphabetic characters */
					case "alphanum" :
						if(!validate(val, /^[a-zA-Z0-9]+$/, true)){
							st.push(0);
						} 
						
						/* Default message */
						!params.msg ? opts.msg = opts.messages.alphanum:'';
						
					break;
					
					/* Single word, can be hyphenated */
					case "oneword" : 
						if(!validate(val, /^[a-zA-Z]+$|^[a-zA-Z]+\-?[a-zA-Z]+$/, false)){
							st.push(0);
						} 
						
						/* Default message */
						!params.msg ? opts.msg = opts.messages.oneword:'';
						
					break;
					
				}
			}
			
			/* Custom regular expression */
			if(opts.regExp){
				pattern = new RegExp(params.regExp);
				if(!validate(val, pattern, true)){
					st[i] = 0;
				} else st[i] = 1;
			}
			
			/* Check extensions */
			if(opts.extensions && val > ""){
				var arr = params.extensions.split(" ");
				var cont = false;
				for(x in arr){
					var pattern = new RegExp(arr[x] + "$");
					
					if(pattern.test(val)){
						cont = true;
						break;
					}
				}
				
				if(cont == false) st[i] = 0;
				
				/* Default message */
				!params.msg ? opts.msg = opts.messages.extensions:'';
			}
			
			/* Check if allowing input to be blank */
			if(opts.allowBlank !== null){
				if(opts.allowBlank == true && val == ""){
					/* Unset the array */
					st = new Array();
				} else if(opts.allowBlank == false && val == ""){
					st.push(0);
				}
			}
			
			/* Exceptional Cases */
			/* Checkbox */
			if(opts.checked !== null){
				if(opts.checked == true){
					if($el.attr("checked") == false){
						st.push(0);
					}
				}
			}
			
			/* Intialize return state to true */
			if(!opts.preserveState){
				var returnState = 1;
				$el.data("state", returnState);
			} else {
				var returnState = $el.data("state");
			}
			
			/* Loop through states */
			for(var x in st){
				if(st[x] == 0){
					returnState = 0;
					$el.data("state", returnState);
					break;
				}
			}
			
			/* Set form message and slidedown tip elements */
			var messageEl = parentID + "-summary-" + i;
			
			/* Check where to place the message */
			var summaryEl = opts.summaryEl;
			
			/* OVERRIDES (radio group) */
			/* For radio group */
			if($el.hasClass('radioGroup')){
				var $radioGroup = $el;
				/* For changing class of group container to valid */
				var checkInputs = [];
				$radioGroup.find('input').each(function(){
					if($(this).attr('checked')){
						checkInputs.push(1);
					}
				});
				
				/* If a selection has not been made in the radio group */
				if(checkInputs.length == 0){
					returnState = 0;
				} else returnState = 1;
				
				$el.data("state", returnState);	
				
			}
			
			/* Change the class based on state */
			if(returnState == 0){
				
				if(opts.useParent){
					$el.parent().removeClass(opts.successCls).addClass(opts.failureCls);	
				} else {
					$el.removeClass(opts.successCls).addClass(opts.failureCls);
				}
				
				/* Store the message that's been set for later retrieval */
				$el.data("msg", opts.msg);
			
			} else if(returnState == 1){

				if(opts.useParent){
					$el.parent().removeClass(opts.failureCls).addClass(opts.successCls);	
				} else {
					$el.removeClass(opts.failureCls).addClass(opts.successCls);
				}
				
			}
			return returnState;
		}
		
		/* Private functions */
		function validate(str, pattern, strip){
			/* If strip is true, ignore whitespace and hyphen */
			var str = strip ? str.replace(/\s|\-/g, '') : str;
			if(!pattern.test(str)) return false;
			else return true;
		}
		
		function parseDate(d, m, y){
			if(m == 0 || m > 12){
				return false;
			}
			
			if(m == 4 || m == 6 || m == 9 || m == 11){
				/* For April, June, September, November */
				if(d > 30 || d < 1){
					return false;
				}
				/* For February */
			} else if(m == 2){
				
				/* Check if it's a leap year */
				if(d > 28 || d < 1){
					if(d == 29){
						if(y%4 !==0){
							return false;
						} else if(y%100 == 0 && y%400 !== 0){
							return false;
						}
					} else return false;
				}
				
			/* All other days have 31 */
			} else {
				if(d > 31 || d < 1){
					return false;
				}
			}
		}
		
	};
	
	/* Remove the validation option from the matching elements */
	$.fn.validate.clear = function(options){
		
		/* Object specific defaults */
		var opts = $.extend({}, $.fn.validate.clear.defaults, options);
		
		/* Loop through matched elements of the parent form */
		$(opts.matchParent).find(opts.matchChildren).each(function(){
			
			/* Unbind event handlers */
			$(this).unbind();
			
			/* Restore default class to item */
			$(this).parent().removeClass(opts.successCls).removeClass(opts.failureCls).addClass(opts.nullCls);
			
			/* Change validateOnSubmit */
			$(this).data("validateOnSubmit", false);
			
		});
		
	}
	
	$.fn.validate.refresh = function($el){
		
		var thisOptions = $el.data("options");
		
		/* Loop through matched elements of the parent form */
		$el.find("input, textarea, .select, .radioGroup").each(function(){
			
			/* Enable validation on submit */
			$(this).data("validateOnSubmit", true);
			
			/* Unbind event handlers */
			$(this).unbind();
			
			/* Remove state data */
			$(this).data('state', null);
			
			/* Remove validation tips */
			$(this).next('.validation-tip-wrapper').remove();
			
			/* Remove the classes that were added to inputs */
			$(this).removeClass(thisOptions.successCls + ' ' + thisOptions.failureCls);
			$(this).parent().removeClass(thisOptions.successCls + ' ' + thisOptions.failureCls);
		});
		
		/* Unbind events associated with form submission */
		$el.unbind();
		
		/* Get the stored options that were originally passed to the validate function
		   on the loading of the page. */
		$el.validate(thisOptions);
	}
	
	$.fn.validate.find = function(options){
		
		/* Object specific defaults */
		var opts = $.extend({}, $.fn.validate.find.defaults, options);
		
		/* Loop through matched elements of the parent form */
		
	};
	
	/* Function for failing an item in a form */
	$.fn.validate.failThis = function($this, showMsg){
		
		var opts = $.fn.validate.evalRel($this.attr('rel'));
		
		/* An item will fail with a state of 0 */
		$this.data('state', 0);
		
		/* Add the fail class */
		$this.parent().removeClass(opts.successCls + ' ' + opts.failureCls).addClass(opts.failureCls);
		
		/* Show the tip */
		$this.next().children().show();
	}
	
	/* Function for passing an item in a form */
	$.fn.validate.passThis = function($this){
		var opts = $.fn.validate.evalRel($this.attr('rel'));
		
		/* An item will pass with a state of 1 */
		$this.data('state', 1);
		
		/* Add the success class */
		$this.parent().removeClass(opts.successCls + ' ' + opts.failureCls).addClass(opts.successCls);

		/* Hide the validation tip */
		$this.next().children().hide();
	}
	
	/* Force the state */
	$.fn.validate.makeState = function($this, state){
		$this.data('state', state);
	}
	
	$.fn.validate.evalRel = function(rel){
		
		if(rel > ""){
			
			/* Check if it's a JSON string */
			if(rel.indexOf("{") !== -1){
				var obj = $.parseJSON(rel);
				
				/* Check if it's a complex JSON string */
				if(obj.validation){
					return obj.validation;	
				} else return obj;
			
			/* Check if it's a simple string */
			} else {
				/*
				var obj = rel.split(":");
				
				/* For boolean 
				if(obj[1] !== 'false' && obj[1] !== 'true'){
					obj[1] == '"' + obj[1] + '"';
				} 
				
				return $.parseJSON('{"' + obj[0] + '":' + obj[1] + '}');
				*/
				return false;
			}
		} else return false;
	}
	
	/* Set defaults for validate function */
	$.fn.validate.defaults = {
		successCls:'successValid',
		failureCls:'failValid',
		nullCls:'nullValid',
		msgCls:'failValid',
		validateOnBlur:true,
		validateOnChange:true,
		revalidateOnKey:true,
		msg:'Field must not be blank.',
		allowBlank:false,
		onSubmitFailed: function(){},
		inputTips:true
	};
	
	$.fn.validate.defaults.messages = {
		email:'Please input a valid email address.',
		phone:'Please input a valid phone number.',
		date:'Please input a valid date.',
		password:'Please input a password consisting of a mix of characters and integers.',
		extensions:'Please input only valid extensions {x}.',
		alpha:'Please input only alphabetical characters.',
		alphanum:'Please input only alphabetical or numeric characters.',
		oneword:'Please input only a single word (can be hyphenated).',
		minLength:'Please input a minimum of {x} characters.',
		maxLength:'Please input a maximum of {x} characters.'
	};
	
	$.fn.validate.clear.defaults = {
		parent:'matchParent'
	};
	
	/* MISC */
	/* Disable enter key */
	function kH(e) {
		var pK = e ? e.which : window.event.keyCode;
		return pK != 13;
	}

})(jQuery);
