/**
 * In The Name of Allah, The Most Gracious, The Most Merciful
 */
 // ? = Zero or One Time
 // + = One or More Times
 // * = Zero or More Times
var RegExpPatterns = {
	"STRING" : /./,
	"SQL_STRING" : /./,
	"En_STRING" : /\w+/,
	"Fa_STRING" : /./,
	"NAME" : /./,
	"USERNAME" : /^[0-9a-zA-Z-_&#^!~]{5,15}$/,
	"PASSWORD" : /^[0-9a-zA-Z-_&#^!~]{5,15}$/,
	"PASSWORD_CRUDE_STING" : /^[0-9a-zA-Z-_&#^!~]{5,15}$/,
	"EMAIL" : /^[\w-\.]+\@([a-zA-Z0-9\x60-\x69-_]+\.)+[a-zA-Z0-9\x60-\x69-_]{2,}$/,
//	"EMAIL" : /^((?>[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+\x20*|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*"\x20*)*(?<angle><))?((?!\.)(?>\.?[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+)+|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*")@(((?!-)[a-zA-Z\d\-]+(?<!-)\.)+[a-zA-Z]{2,}|\[(((?(?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4}|[a-zA-Z\d\-]*[a-zA-Z\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+)\])(?(angle)>)$/,
	"URL" : /./,
	"FILE_PATH" : /./,
	"PATH" : /./,
	"NUMBER" : /^[-+]?[0-9\x60-\x69]+(\.[0-9\x60-\x69]*)?$/,
	"NONZERONUMBER" : /^[-+]?(([0\x60]*[1-9\x61-\x69]{1}[0-9\x60-\x69]*[\.]?[0\x60]+)|([0\x60]+[\.]?[0\x60]*[1-9\x61-\x69]{1}[0-9\x60-\x69]*)|([0\x60]*[1-9\x61-\x69]{1}[0-9\x60-\x69]*[\.]?[0\x60]*[1-9\x61-\x69]{1}[0-9\x60-\x69]*))$/,
	"NONNUMERIC" : /[^0-9\x60-\x69]+/,
	"PHONE_NUMBER" : /^[0-9\x60-\x69]+$/,
	"NATIONAL_CODE" : /./,
	"NUMERIC_NATIONAL_CODE" : /^[0-9\x60-\x69]{10}$/,
	"POSTAL_CODE" : /./,
	"HEXADECIMAL_RGB_COLOR_CODE" : /./,
	"ISBN" : /^[0-9\x60-\x69-]{4,}$/,
	"AGE" : /./,
	"DATE" : /^[0-9]{4}\/(([0]{1}[1-9]{1})|([1]{1}[0-2]{1}))\/(([0-2]{1}[0-9]{1})|([3]{1}[0-1]{1}))$/,
	"YEAR" : /./,
	"MONTH" : /./,
	"DAY" : /./,
	"TIME" : /^[0-9\x60-\x69]{1,}:[0-5\x60-\x65]{1}[0-9\x60-\x69]{1}$/,
	"CLOCK" : /^(2[0-3\x60-\x63]{1}|[0-1\x60-\x61]{1}[0-9\x60-\x69]{1}):[0-5\x60-\x65]{1}[0-9\x60-\x69]{1}$/,
	"HOUR" : /./,
	"MINUTE" : /./,
	"SECOND" : /./,
	"PERCENT" : /^[%]?(100|[0-9\x60-\x69]{1,2}(\.[0-9\x60-\x69]*)?|[0\x60]+)$/,
	"NUMERICPERCENT" : /^(100|[0-9\x60-\x69]{1,2}(\.[0-9\x60-\x69]*)?|[0\x60]+)$/,
	"GUID" : /./,
	"COLOR" : /^#[0-9a-f]{1,6}$/i,
	"DOMAIN" : /^[-a-zA-Z0-9\.]+$/
};

if (typeof trim == 'undefined')
function trim(str) {
	if (typeof(str) == "string")
		return str.replace(/^\s*|\s*$/,"");
}

function Validate(Value, Type, Force) {
	Force = ((typeof Force == 'string') && (trim(Force).toLowerCase != 'false')) || ((typeof Force != 'string') && Force !== false) ? true : false;
	Value = trim(Value);
//	$Value .= '';
	if (typeof RegExpPatterns[Type] != 'undefined')
	{
		if (RegExpPatterns[Type].test(Value)) {
			return true;
		} else if (Force && !Value)	{
			return -2; // Forced But Value Not Set
		} else if (Value) {
			return -1;// Not Forced But Value is Not Regular!
		} else if (!Value) {
			return 0; // Is Not Forced And Value is Not Set
		}
	}
	else
	{
		return false;
//		return true; // temporary for Compatibility return true!
	}
}
