		//--------------------------------------------------------------------------------
		// Removes the leading and trailing spaces in a strings and returns the trimmed string
		//------------------------------------------------------------------------------------
		function Trim(stringValue)
		{
			// Checks the first occurance of spaces and removes them
			for(i = 0; i < stringValue.length; i++) 
			{
				if(stringValue.charAt(i) != " ") 
				{
					break;
				}
			}
			if(i > 0) 
			{
				stringValue = stringValue.substring(i);
			}
			
			// Checks the last occurance of spaces and removes them
			strLength = stringValue.length - 1;
			for(i = strLength; i >= 0; i--) 
			{
				if(stringValue.charAt(i) != " ") 
				{
					break;
				}
			}
			if(i < strLength) 
			{
				stringValue = stringValue.substring(0, i + 1);
			}
			
			// Returns the string after removing leading and trailing spaces.
			return stringValue;
		}
		
		///----------------------------------------------------------------------------------
		///	TextBox class for HTML Input Box validations
		///----------------------------------------------------------------------------------
		/// Created By :: Author: Prineeth PP. 01-10-2007
		/// Updated By :: 
		function CTextBox (element, isMandatory) 
		{							
			var elmnt = element;
			var vMode = 1;
			var isMan = isMandatory;
			
			//set maximum number of integers
			var count = 5;
			//set maximum number of digits (integer + . + 00)
			var maxlen = count + 3;
			
			//Initial function for all controlls
			this.InitInteger = function() 
			{
				vMode = 1; /* Nemeric ONLY  */
				elmnt.onkeyup	= this.FilterNemeric;
				elmnt.onchange	= this.FilterNemeric;
				if(isMan) elmnt.onblur = this.CheckNotNull;
			} // End of function InitInteger()
			
			///----------------------------------------------------------------------------------
			///	check currency field
			///----------------------------------------------------------------------------------
			/// Created By :: Reeja.S. 05-10-2007
			/// Updated By :: 
			this.InitCurrency = function(integerPartLength) 
			{
				count = integerPartLength;
				maxlen = count + 3;
				
				/* Nemeric  and dot ONLY  */
				elmnt.onkeyup	= this.FilterCurrency;
				elmnt.onchange	= this.FilterCurrency;
				elmnt.onblur	= this.SetCurrency;
			} // End of function InitCurrency()
			
			//--------------------------------------------------------------------
			// Check Email field
			//----------------------------------------------------------------------
			this.InitEmail = function() 
			{
				/* AlphaNemeric , @ and dot ONLY  */
				elmnt.onkeyup	= this.FilterEmail;
				elmnt.onblur	= this.ValidEmail;
			} // End of function InitEmail()
			
			//----------------------------------------------------------------------
			// Check Name field
			//-----------------------------------------------------------------------
			this.InitName = function()
			{	//Alphabets, space and dot ONLY 
				elmnt.onkeyup	= this.FilterName;
				elmnt.onchange	= this.FilterName;
				elmnt.onblur	= this.ValidName;
			} // End of function InitName()
			
			//--------------------------------------------------------------------
			// Function For Name validation
			//-----------------------------------------------------------------------
			this.FilterName = function()
			{
				text="";
				// Allow A to Z , a to z , space and dot only
				for(i=0; i< this.value.length; i++)
				{	
					// first character must be a letter
					if(this.value.length > 1 ) 
					{
						if( (this.value.charAt(i) != this.value.charAt(i-1) ) && 
							(this.value.charAt(i) != '.' || this.value.charAt(i) != ' ' ) )
							{
								if( (this.value.charAt(i) >= 'a' && this.value.charAt(i) <= 'z')  ||
									(this.value.charAt(i) >= 'A' && this.value.charAt(i) <= 'Z')||
									(this.value.charAt(i) == '.' ) ||
									(this.value.charAt(i) == ' ' ) ) text += this.value.substr(i,1);
							} // End of if( (this.value.charAt(i) != this.value.charAt(i-1) ) && (this.value.charAt(i) != '.' || this.value.charAt(i) != ' ' ) )	
					}
					else
					{
						if( (this.value.charAt(i) >= 'a' && this.value.charAt(i) <= 'z') ||
							(this.value.charAt(i) >= 'A' && this.value.charAt(i) <= 'Z') )  text += this.value.substr(i,1);
					}
				} // End of for(i=0; i< this.value.length; i++)
				this.value = text;			
			} // End of function FilterName()
		
			//--------------------------------------------------------------------
			// Check Name is valid
			//--------------------------------------------------------------------
			this.ValidName = function()
			{	
				// Chech length is greater than 0 
				// Chech last character must be a letter 
				if( (this.value.length < 0) || 
					(this.value.length == this.value.lastIndexOf('.') + 1) ) this.focus();
				else if(this.value.charAt(this.value.indexOf('.')+1) == '.')
				{
					alert("Invalid Name");
					this.focus();
				}
			} // End of function ValidName()
			
			//--------------------------------------------------------------------
			//check currency field
			//---------------------------------------------------------------------
			this.FilterCurrency = function() 
			{
				text="";
				i=0;
				for(; i<this.value.length; i++) 
				{
					if( (this.value.charAt(i) >= '0' &&  this.value.charAt(i) <= '9') || (this.value.charAt(i) == '.') ) 
					{
						//check dot is present and length of digit after dot is less than 2
						if( (this.value.indexOf('.') > -1) ) 
						{	
							if(this.value.substr(1,i).split('.').length <= 2)
							 {
								if(text.length < maxlen) 
								{
									text += this.value.substr(i,1);
								} // End of if(text.length < maxlen) 
							} // End of if(this.value.substr(1,i).split('.').length <= 2)
							else if(this.value.substr(i,1) != '.') 
							{
								if(text.length < maxlen) text += this.value.substr(i,1);
							}
						} // End of if( (this.value.indexOf('.') > -1) ) 
						else 
						{
							if(text.length < count) text += this.value.substr(i,1);
						}
					}	// End of if( (this.value.charAt(i) >= '0' &&  this.value.charAt(i) <= '9') || (this.value.charAt(i) == '.') )
				} // End of for(; i<this.value.length; i++) 
				if( (text.length > text.indexOf('.') + 3) && (text.indexOf('.') > 0) ) 
				{
					text = text.substr(0,i-1);
				}
				this.value = text;
			} // End of function FilterCurrency()
			
			//-----------------------------------------------------------------
			//add dot and zeros to the currency field
			//------------------------------------------------------------------- 
			this.SetCurrency = function() {		
				text=this.value;
				
				//if value does not contain dot then add ".00"
				if((this.value.indexOf('.') <=-1 ) && ( this.value.length < maxlen)) 
				{
					this.value=text.concat(".00");
				}
				
				// the number of digit after dot is less than 2 then add 0
				else if((this.value.indexOf('.') > -1 ) && (this.value.length < this.value.indexOf('.') + 3) ) 
				{
					for(i=this.value.length; i <= this.value.indexOf('.') + 2 ; i++) 
					{
						this.value=this.value.concat("0");
					}
				}
				
				// if value is 0 then add 0.00
				else if(this.value.length <= 0) 
				{
					this.value=text.concat("0.00");
				}
			} // End of function SetCurrency()
			
			//-----------------------------------------------------------------------------------
			/*Allow  AlphaNemeric , @ and dot ONLY  */
			//-----------------------------------------------------------------------------------
			this.FilterEmail=function()
			{
				text="";
				var flagAt = false;
				// Allow A to Z , a to z , 0 to 9 , @ and .
				for(i=0; i< this.value.length; i++)
				{
					//First character must be alphabet
					if(this.value.length > 1)
					{
						if( (this.value.charAt(i) >= 'a' && this.value.charAt(i) <= 'z')  ||
							(this.value.charAt(i) == '.' ) ||(this.value.charAt(i) == '_' ) ||
							(this.value.charAt(i) == '@' ) ||
							(this.value.charAt(i) >= 'A' && this.value.charAt(i) <= 'Z') || 
							(this.value.charAt(i) >= '0' && this.value.charAt(i) <= '9') ) 
							{
								// The next character of dot/@ is not dot/@
								if( (this.value.charAt(i) != this.value.charAt(i-1) ) && (this.value.charAt(i) != '.' || this.value.charAt(i) != '@' ) )
								{
									// Allow only one @
									if( (this.value.charAt(i) == '@' && this.value.charAt(i-1) == '.' ) ) 
									{									
										continue;
									}
										// if @ is present then set flagAt
										if(this.value.indexOf('@') > -1)
										{
										 	flagAt = true;
										}
										
										// The next character of @ must be a letter 
										if( (flagAt) && (i > this.value.indexOf('@')) )	
										{
											if( ( i == this.value.indexOf('@') +1 ) && (this.value.charAt(i) == '.') )
											{
												if( (this.value.charAt(i) >= 'a' && this.value.charAt(i) <= 'z')  ||
													(this.value.charAt(i) >= 'A' && this.value.charAt(i) <= 'Z') )
												{
													text += this.value.charAt(i);
												}
											} // End of if( ( i == this.value.indexOf('@') +1 ) && (this.value.charAt(i) == '.') )
											else
											{	
												if( (this.value.charAt(i) >= 'a' && this.value.charAt(i) <= 'z')  ||
													(this.value.charAt(i) == '.' ) ||
													(this.value.charAt(i) >= 'A' && this.value.charAt(i) <= 'Z') ) text += this.value.charAt(i);
											}
										}// End of if( (flag) && (	i > this.value.indexOf('@')) )	
										else text += this.value.charAt(i);
								}// End of if( (this.value.charAt(i) != this.value.charAt(i-1) ) && (this.value.charAt(i) != '.' || this.value.charAt(i) != '@' ) )
								else 
								{	
									if( (this.value.charAt(i) != '.') && (this.value.charAt(i) != '@') ) text += this.value.charAt(i);
								}
							}
						} //if(this.value.length > 1)
						else 
						{	
							if( (this.value.charAt(i) >= 'a' && this.value.charAt(i) <= 'z')||
								(this.value.charAt(i) >= 'A' && this.value.charAt(i) <= 'Z') ) text += this.value.charAt(i);
						}
				}
				this.value=text;
			}  // End of function FilterEmail()
							
			//-----------------------------------------------------------------------------------
			// Check @ and . are present   
			// Check atlest one Character after dot 
			//-----------------------------------------------------------------------------------
			this.ValidEmail=function()
			{	
				// Check @ and Dot is present	
				if( (this.value.indexOf('@') <= -1) ||
					(this.value.indexOf('.') <= -1) ||
					(this.value.length == this.value.lastIndexOf('.') + 1) ) this.focus();
				else if(this.value.charAt(this.value.indexOf('@')+1) == '.')
				{
					alert("Invalid E-mail");
							this.focus();
				}
				else
				{
					for(i=this.value.indexOf('@'); i<this.value.length; i++)
					{
						if( (this.value.charAt(i) >= 'A' && this.value.charAt(i) <= 'Z') )
						{ 
							alert("Invalid E-mail");
							this.focus();
						}
					} // End of for(i=this.value.indexOf('@'); i<this.value.length; i++)
				}
			} // End of function ValidEmail()
			
			//--------------------------------------------------------------------	
			// allow only digits
			//-----------------------------------------------------------------------							
			this.FilterNemeric = function() 
			{
				var filterText = "";
				for(var i=0; i<this.value.length; i++) 
				{
					if( this.value.substr(i, 1) >= '0' && this.value.substr(i, 1) <= '9' ) 
					{
						filterText += this.value.substr(i, 1);
					}
				}
				this.value = filterText;
			} // End of function FilterNemeric()
			///----------------------------------------------------------------------------------
						
			///----------------------------------------------------------------------------------
			///	Checking mandatory Field Validation
			///----------------------------------------------------------------------------------
			/// Created By :: Author: Prineeth PP. 01-10-2007
			/// Updated By :: 
			this.CheckNotNull = function() 
			{
				if(Trim(this.value).length <= 0) 
				{
							this.focus();
					return false;
				}	else 
				{
					return true;
				}
			}
			///----------------------------------------------------------------------------------
			
		};
		
