Validate = {
	
	// whitespace characters
	whitespace: " \t\n\r",

	
	// Validate.me(aItems ARRAY of items to validate)
	// aItems is an array of arrays. 
	// top level array contains element for each item to validate
	// second level array contains pointer to element to set pass/fail class to in [0]
	// second level array contains validation(s) to test against in [1]
	me: function(aItems) {
		
		var ii;
		
		if (aItems.length) {
			for (ii=0;ii < aItems.length;ii++) {
				if (!aItems[ii][1]) {
				// item is not valid
					jQuery(aItems[ii][0]).addClass("isValidatedFail");	
					jQuery(aItems[ii][0]).removeClass("isValidatedPass");	
				} else {
				// item is valid
					jQuery(aItems[ii][0]).addClass("isValidatedPass");	
					jQuery(aItems[ii][0]).removeClass("isValidatedFail");	
				}
			}
		}
		
	},
	
	
	isNotNull: function(str) {
		if (this.trim(str) == "") return false;
		return true;		
	},
	
	
	// does str1 equal str2 i.e. type password and confirm it
	isConfirmed: function(str1,str2) {
		if (str1==str2) return true;
		return false;		
	},

	
	isCreditCard: function(s) {
		// remove non-numerics
		var v = "0123456789";
		var w = "";
		for (i=0; i < s.length; i++) {
		x = s.charAt(i);
		if (v.indexOf(x,0) != -1)
		w += x;
		}
		// validate number
		j = w.length / 2;
		if (j < 6.5 || j > 8 || j == 7) return false;
		k = Math.floor(j);
		m = Math.ceil(j) - k;
		c = 0;
		for (i=0; i<k; i++) {
			a = w.charAt(i*2+m) * 2;
			c += a > 9 ? Math.floor(a/10 + a%10) : a;
		}
		for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
		return (c%10 == 0);
	},
	

	isGoodExpireDate: function(month,year) {
	    var ccExpYear = year;
	    var ccExpMonth = month;
	    var expDate=new Date();
		
	    expDate.setFullYear(ccExpYear, ccExpMonth, 1);
	    var today = new Date();
	    if (expDate<today)
	    {
	        // Credit Card is expire
	        return false;
	    }
	    else
	    {
	        // Credit is valid
	        return true;
	    }
	},
	
	// for checking if string length is in range
	// i.e. password must be > 5 and < 20 characters long
	isLengthBetween: function(s,l,h) {
		if (s.length >= l && s.length <= h) return true;
		return false;
	},
	
	// is string a valid email address format
	isEmail: function(s) {
	    // does s have whitespace?
	    if (this.hasWhitespace(s)) return false;
	    
	    // there must be >= 1 character before @, so we
	    // start looking at character position 1 
	    // (i.e. second character)
	    var i = 1;
	    var sLength = s.length;
	
	    // look for @
	    while ((i < sLength) && (s.charAt(i) != "@"))
	    { i++
	    }
	
	    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	    else i += 2;
	
	    // look for .
	    while ((i < sLength) && (s.charAt(i) != "."))
	    { i++
	    }
	
	    // there must be at least one character after the .
	    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	    else return true;
	},
	
	
	trim: function(str) {
		return str.replace(/^\s+|\s+$/g,"");
	},
	
	
	isEmpty: function(s) {
		return ((s == null) || (this.trim(s).length == 0));
	},
	
	// is checkbox chbx checked?
	isChecked: function(chbx) {
		return chbx.checked;
	},
	
	hasWhitespace: function(s) {
		var i;

		// trim the string first we only care about embedded whitespace
		s = this.trim(s);

	    // Is s empty?
	    if (this.isEmpty(s)) return true;
	
	    // Search through string's characters one by one
	    // until we find a whitespace character.
	    // When we do, return true; if we don't, return false.
	    for (i = 0; i < s.length; i++) {   
			// Check that current character isn't whitespace.
			var c = s.charAt(i);
			if (this.whitespace.indexOf(c) != -1) return true;
	    }
	
	    // No characters are whitespace.
	    return false;
	}
	
	
}
