	/**
	 * 
	 * Javascript Validators used staticly.
	 * 
	 * @name Validator
	 * @author Vincent Cantin Bellemre
	 * @since 2007-11-11
	 * @version 1.0.0
	 * @package cbwebdevframework
	 * 
	 */
	 
	function Validator()
	{
		this.is_email = function (email)
		{			
			var reg_email = /^[\.a-zA-Z0-9_-]+@[\.a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,3}$/
			return (reg_email.exec(email) != null)
		}

		this.is_filled = function (text_value,nb_chars)
		{
			if(nb_chars == null)
			{
				nb_chars = 0;
			}
			else
			{
				nb_chars--;
			}
		
			if(typeof(text_value) == 'number' || typeof(text_value) == 'string' || typeof(text_value) == 'boolean')
			{
				return (text_value.length > nb_chars);
			}
			return false;
		}
		
		this.is_postal_code = function (postal_code)
		{
			postal_code = postal_code.toUpperCase()
			var reg = /^([A-Z]){1}([0-9]){1}([A-Z]){1}([\.\ \-]){0,1}([0-9]){1}([A-Z]){1}([0-9]){1}$/;
			return reg.test(postal_code);	
		}
		
		this.is_positive_int = function (int_value)
		{	
			if(isNaN(int_value))
			{
				return false;			
			}
	
			if(int_value > 0)
			{
				return true;
			}
		
			return false;
		}
		
		this.is_phone = function (phone)
		{
			if(phone.length < 3)
			{
				return false;				 
			}

			 if(phone.match(/[\<\>\,\;\:\\\"\[\]]/) || phone.match(/[a-zA-Z]/))
			 {
				return false;				 
			 }
			 
			return true;				
		}
		
		this.is_price_format = function (price)
		{
			var reg = /^\d+[.]{1}\d{2}$/;
			return reg.test(price);

		}
		
		this.is_time_format = function(time_format)
		{	
			var reg = /^(\d{1}|\d{2})[:]{1}\d{2}$/;
			return reg.test(time_format);
		}
	
		this.is_date_format = function (date_format)
		{
			var reg = /^\d{4}[-]{1}\d{2}[-]{1}\d{2}$/;
			return reg.test(date_format);
		}
		
		this.is_year = function(year)
		{
			if(theYear > 1968 && theYear < 2500 )
			{
				return true
			}
		
			return false;
		}
	
		this.parse_price_format = function (num)
		{
			num = num.toString().replace(/\$|\,/g,'');
	
			if(isNaN(num))
			{
				num = "0";		
			}
		
			sign = (num == (num = Math.abs(num)));
			num = Math.floor(num*100+0.50000000001);
			cents = num%100;
			num = Math.floor(num/100).toString();
		
			if(cents < 10)
			{
				cents = "0" + cents;			
			}
	
			for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			{
				num = num.substring(0,num.length-(4*i+3))+','+
				num.substring(num.length-(4*i+3));		
			}
	
			return (((sign)?'':'-') + '' + num + '.' + cents + ' $');
		}
		
		this.is_credit_card = function (type, ccnum) 
		{
			if(typeof(type) == 'undefined' || type == null)
			{
				return false;
			}
		   
		   if (type == "Visa") 
		   {
			  // Visa: length 16, prefix 4, dashes optional.
			  var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
		   } 
		   else if (type == "MC") 
		   {
			  // Mastercard: length 16, prefix 51-55, dashes optional.
			  var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;
		   } 
		   else if (type == "Disc") 
		   {
			  // Discover: length 16, prefix 6011, dashes optional.
			  var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;
		   } 
		   else if (type == "AmEx") 
		   {
			  // American Express: length 15, prefix 34 or 37.
			  var re = /^3[4,7]\d{13}$/;
		   } 
		   else if (type == "Diners") 
		   {
			  // Diners: length 14, prefix 30, 36, or 38.
			  var re = /^3[0,6,8]\d{12}$/;
		   }
		   
		   if (!re.test(ccnum)) 
		   {
			   return false;
		   }
		   // Remove all dashes for the checksum checks to eliminate negative numbers
		   ccnum = ccnum.split("-").join("");
		   // Checksum ("Mod 10")
		   // Add even digits in even length strings or odd digits in odd length strings.
		   var checksum = 0;
		   
		   for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) 
		   {
			  checksum += parseInt(ccnum.charAt(i-1));
		   }
		   
		   // Analyze odd digits in even length strings or even digits in odd length strings.
		   for (var i=(ccnum.length % 2) + 1; i<ccnum.length; i+=2) 
		   {
			  var digit = parseInt(ccnum.charAt(i-1)) * 2;
			  
			  if (digit < 10) 
			  { 
				checksum += digit; 
			  } 
			  else 
			  { 
				checksum += (digit-9); 
			  }
		   }
		   
		   if ((checksum % 10) == 0) return true; else return false;
		}
		
		this.is_required = function(string_text)
		{
			return (string_text.length > 0);
		}
	}
	
	Validator = new Validator();