/**
 * This file contains Vtypes - used for validations
 *
 * @author Interface
 * @created 12-18-2009
 * @version 1.0
 * 
 */
 
/*
 * This is to apply validation for numeric field.
 */
Ext.apply(Ext.form.VTypes, {
	'numeric': function(){
		var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
		return function(strValue){   //check for numeric characters
			return objRegExp.test(strValue);
		}
	}(),
	'numericText': 'Only numbers are allowed'
});

/*
 * This is to apply validation for username.
 */

Ext.apply(Ext.form.VTypes, {
	'username': function() {
		var objRegExp  =  /^[a-zA-Z][-_.a-zA-Z0-9]/;
		return function(strValue){   //check for numeric characters
			var array = strValue.split('@');
			if(typeof(array[1]) == 'undefined') {
				objRegExp  =  /^[a-zA-Z0-9][-_.a-zA-Z0-9]/;
			}else {
				objRegExp  =  /^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6}$/;
			}
			return objRegExp.test(strValue);
		}
	}()
	,'usernameText':  'Invalid username (allowed types : "ronuser", "ron_user" or "user@ron.com)"'
	,'usernameMask':  /[-_.@]/
});

/*
 * This is to apply validation for username.
 */

Ext.apply(Ext.form.VTypes, {
	'loginusername': function() {
		var objRegExp  =  /^[a-zA-Z][-_.a-zA-Z0-9]/;
		return function(strValue){   //check for numeric characters
			var array = strValue.split('@');
			if(typeof(array[1]) == 'undefined') {
				objRegExp  =  /^[a-zA-Z0-9][-_.a-zA-Z0-9]/;
			}else {
				objRegExp  =  /^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6}$/;
			}
			return objRegExp.test(strValue);
		}
	}(),
	'loginusernameText':  'Invalid username',
	'loginusernameMask':  /[-_.@]/
});


/*
 * This is to apply validation for name field value must start with letter.
 */
Ext.form.VTypes["nameVal"]  = /^([a-zA-Z0-9]{1})+/;
Ext.form.VTypes["nameText"] = 'Only special charactes not allowed';
Ext.form.VTypes["name"] 	= function(v){
	return Ext.form.VTypes["nameVal"].test(v);
};

/*
 * This is to apply validation for phone number field.
 */
Ext.form.VTypes["phoneNumberVal"]  = /^(?:\([2-9]\d{2}\)\ ?|[2-9]\d{2}(?:\-?|\ ?))[2-9]\d{2}[- ]?\d{4}$/;
Ext.form.VTypes["phoneNumberText"] = 'Not a valid phone number.  Must be in the format 123-4567, 123-456-7890 or (123)-456-7890(dashes optional).';
Ext.form.VTypes["phoneNumber"] 	= function(v){
	return Ext.form.VTypes["phoneNumberVal"].test(v);
};

/*
 * This is to apply validation for link url field, value must start with http:// or https://.
 */
Ext.form.VTypes["urlVal"]  = /^(http:\/\/|https:\/\/{1})+/;
Ext.form.VTypes["urlText"] = 'Must starts with http:// or https://';
Ext.form.VTypes["url"] 	= function(v){
	return Ext.form.VTypes["urlVal"].test(v);
};

/*
 * This is to apply validation for password.
 */
Ext.form.VTypes["passwordcheckerVal"] = /^.{6,31}$/;
Ext.form.VTypes["passwordcheckerText"] = "Password length must be 6 to 31 characters long";
Ext.form.VTypes["passwordcheckerMask"] = /./;
Ext.form.VTypes["passwordchecker"] = function(v){
  return Ext.form.VTypes["passwordcheckerVal"].test(v);
};

// Add the additional 'advanced' VTypes
Ext.apply(Ext.form.VTypes, {  
  password : function(val, field) {  		
        if (field.initialPassField) {
            var pwd = Ext.getCmp(field.initialPassField);
            return (val == pwd.getValue());
        }
        return true;
  }
});

/*
 * This is to apply validation for file name.
 */
Ext.form.VTypes["fileVal"]  = /^[^\\\/:*?"<>|.]+(.[^\\\/:*?"<>|.]+)+$/;
Ext.form.VTypes["fileText"] = '\ / : * ? < > | characters not allow in name field ';
Ext.form.VTypes["file"] 	= function(v){
	return Ext.form.VTypes["fileVal"].test(v);
};
//Ext.form.VTypes["fileMask"] = /[a-zA-Z0-9]/;

/*
 * This is to apply validation for valid phone number.
 */
Ext.form.VTypes["phoneVal"] = /^(\D?(\d{3})\D?\D?(\d{3})\D?(\d{4}))$/;
Ext.form.VTypes["phoneMask"] = /[\d-()]/;
Ext.form.VTypes["phoneText"] = 'Not a valid phone number.  Must be in the format 123-4567, 123-456-7890 or (123)-456-7890(dashes optional)'; 
Ext.form.VTypes["phone"] 	= function(v){
	return Ext.form.VTypes["phoneVal"].test(v);
};

