var validation = {
	phone: {
		/* Phone validation - the bool below is overidden by the codebehind if validation is enabled in web config */
		checkFormat: false,
		minDigitsInIPhoneNumber: 10,
		maxDigitsInIPhoneNumber: 13,

		trim: function(s) {
			return s.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
		},

		// validates international phone format when validation turned on globally
		isPhoneNum: function(strPhone, mandatory){
			var isBlank = this.trim(strPhone).length == 0;
			if (!this.checkFormat) {
				if (mandatory) return !isBlank;
				return true;
			}
			if (!mandatory && isBlank) {
				return true;
			}

			var re = /[^0-9\+\-\(\)\s]+/g;	// find invalid chars
			if (strPhone.match(re)) return false;

			re = /[^0-9]+/g;
			s = strPhone.replace(re, "");
			if (isNaN(parseFloat(s))) return false;
			return (s.length >= this.minDigitsInIPhoneNumber && s.length <= this.maxDigitsInIPhoneNumber);
		}
	}
};

