﻿var TextHandler = 
{
	IsCharWhitespace : function(ch) 
	{
		return/^\s$/.test(ch);
	},
	
	IsCharPunctuation : function(ch) 
	{
		return/[`~!@#$%^&\*()\'-+={}\[\]|\\:;\"<>,\.\?\/]/.test(ch);
	},

	IsWordCharacter : function(ch) 
	{
		if(ch == null || (typeof ch != "string" || ch.length != 1)) 
		{
			return false;
		}
		var code = ch.charCodeAt(0);
		return code >= 48 && code <= 57 || (code >= 65 && code <= 90 || (code >= 97 && code <= 122 || (code >= 138 && code <= 142 || (code >= 154 && code <= 159 || code >= 192 && code <= 255))))
	},

	BeginsWith : function(str, pref) 
	{
		return str.substring(0, pref.length).toUpperCase() == pref.toUpperCase();
	},
	
	EndsWith : function(str, pref)
	{
		var iIndex = str.length - pref.length;
		return str.substring(iIndex).toLowerCase() == pref.toLowerCase();
	},
	
	TotalTrim : function(str)
	{
		str = str.replace(/\s/g,'');
		return str;
	},
	
	TrimToOne : function(str) 
	{
		 // Return empty if nothing was passed in
		if (!str) return "";
	    
		// Efficiently replace any leading or trailing whitespace
		str = str.replace(/^\s+/, '');
		str = str.replace(/\s+$/, '');
	    
		// Replace any multiple whitespace characters with a single space
		str = str.replace(/\s+/g, ' ');
	    
		// Return the altered string
		return str;
	},
	
	IsValidEMail : function(strEMail)
	{
		return 	/^([0-9a-zA-Z]([-.\w_])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/.test(strEMail);
	},
	
	ConvertToHTMLSpaces : function(strText)
	{
		strText = strText.replace(/\s/g,'&nbsp;');
		return strText;
	}
}



function IsValidImageFile(strFilePath)
{
	var arrValidImage = ['.jpg','.gif'];
	
	for(var i=0;i<arrValidImage.length;i++)
	{
		if(TextHandler.EndsWith(strFilePath,arrValidImage[i]))
		{
			return true;
		}
	}
	
	return false;
}

function IsValidStringName(str)
{
	for(var i=0;i<str.length;i++)
	{
		if(TextHandler.IsCharPunctuation(str.charAt(i)))
		{
			return false;
		}
	}
	
	return true;
}

