var validate = {
	isEmpty: function(value) {
  		return (value && value.replace(/^\s\s*/, '').replace(/\s\s*$/, '')) == "" ? true : false;
  	},
  	isAlphaNumeric: function(value) {
  		return (value).match(/^[a-zA-Z0-9]+$/gi);
  	},
  	/**
  	 * @description Validates a zipcode using the site web service.
  	 * @param The zipcode to validate.
  	 * Note: According the second parameter the function validates the value param against a secure web service,
  	 * if the second param is false a non-secure web service is used.
  	 */
  	isValidZipCode: function (value) {
  		var url = linkPrefix+"form/user/getgeographicinfo";
  		if(isSecure()){
  			url = linkPrefix+"my-subaru/data/user/getgeographicinfo";
  		}
		var inputDigits = value.replace(/[^\d]/g, "");
		var digitLength = inputDigits.length;
		var validated = false;
		if(digitLength < 5 || digitLength > 5){
			return false;
		}
		else{
			if(!validate.isDigit(value)){
				return false;
			}else{
				$.ajax({
					type: "post",
					url: url,
					data: "homeZip="+value,
					async: false,
					error: function() {
						validated = false;
					},
					success: function() {
						validated = true;
					}
				});
			}
		}
		return validated;
	},
	isDigit: function(value) {
		return (/^\d+$/.test(value)) ? true : false;
	},
	isValidMileage: function (value) {
		if(!validate.isDigit(value)){
			return false;
		}
		if(value >= 900000) {
			return false;
		}
		else {
			if(value > 0){
				return true;
			}
			return false;
		}
	},
	isDate: function(value) {
		var check = false;
		var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
		if( re.test(value)){
			var adata = value.split('/');
			var mm = parseInt(adata[0],10);
			var gg = parseInt(adata[1],10);
			var aaaa = parseInt(adata[2],10);
			var xdata = new Date(aaaa,mm-1,gg);
			if ( ( xdata.getFullYear() == aaaa ) && ( xdata.getMonth () == mm - 1 ) && ( xdata.getDate() == gg ) )
				check = true;
			else
				check = false;
		} else
			check = false;
		return check;
	},
	isDateISO: function(value) {
			return /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(value);
	},	
	isValidEmail: function(value){
		var valueUpperCase = value.toUpperCase().replace(/^\s\s*/, '').replace(/\s\s*$/, '');
		var regEx = new RegExp("^[A-Z0-9._+-]+@[A-Z0-9.-]+[.]+[A-Z]{2,4}$");
		return (valueUpperCase.match(regEx)) ? true: false;
	},
	isWellFormedPassword: function(value){
		// 6 characters and be only letters, numbers, or ".", "@", "-" or "_" (no other special characters
		var pattern = /^[A-Za-z0-9-@_\-\.]{6,}$/;
		var regex = new RegExp(pattern);
		return value.match(regex) ? true: false;
	}
}
