//*******************************************************************
// Do not allow user to left the field blank or fill only with space " "
// this function is internal. i.e it is not called from any page but used by the
// other functions defined here.
function isBlank(obj)
	{
		var s = obj.value;
		var ok = false;
		if (s != ""  )
			{
			for (var i=0;i < s.length; i++)
				{
				if (s.substring(i,i+1) != " ")
					{
					//Ltrim(obj); //Remove Leading space
					return ok;
					}
				}
			}
			alert("No Blank allowed");
//	obj.focus();

	}



//*******************************************************************
// "flg" IN ALL SUB SEQUENT FUNCTION WILL SPECIFY THAT "object" CAN NOT BE EMPTY AT ANY MEANS .
// ie. IT'S CALLED FOR A MENDATORY FIELD

// Allows only alphabets and space

function isText(obj,flg)
	{

	if (flg == "must")
		{
		if (isBlank(obj) == true )
			return;
		}	

		var str = obj.value;  

		for (var i = 0; i < str.length; i++) 
		{
			var ch = str.substring(i, i + 1);
			if (!( (ch >= "a" && ch <= "z" ) || (ch >= "A" && ch <= "Z") || (ch == " ") || (ch == ".") || (ch == "'") || (ch == "-") || (ch == "\\") || (ch == "/") || (ch == "<")|| (ch == ">")  ))
			{
				alert("\nInvalid Character");
				obj.focus();
				return false;
			}
		}/* END OF FOR*/

		Ltrim(obj); //Remove Leading space
	}

//*******************************************************************
// Allows alphabets ,space, dot,numbers,dash,slash,back slash

function isSpecialText(obj,flg)
	{

	if (flg == "must")
		{
		if (isBlank(obj) == true )
			return;
		}	

		var str = obj.value;  

		for (var i = 0; i < str.length; i++) 
		{
			var ch = str.substring(i, i + 1);
			if (!( (ch >= "a" && ch <= "z" ) || (ch >= "A" && ch <= "Z") || (ch == " ") || (ch == ".") || (ch == "'") || (ch == "-") || (ch == "\\") || (ch == "/")  || (ch >= "0" && ch <= "9" ) ))
			{
				alert("\nInvalid Character");
				obj.focus();
				return false;
			}
		}/* END OF FOR*/

		Ltrim(obj); //Remove Leading space
	}

//*******************************************************************
// Allow only numeric values

function isNumeric(obj,flg)
	{

	if (flg == "must")
		{
		if (isBlank(obj) == true )
			return;
		}	

		var str = obj.value;

		for (var i = 0; i < str.length; i++) 
		{
			var ch = str.substring(i, i + 1);
			if (! (ch >= "0" && ch <= "9" )  )
			{
				alert("\nInvalid Number");
				obj.focus();
				return false;
			}
		}

		//if (isNaN(d))
		//	{
		//	alert ("Invlid Number");
		//	obj.focus();
		//	return false;
		//	}

		Ltrim(obj); //Remove Leading space

				
	}


//*******************************************************************
// Check valid email address	

function isEmail(obj,flg)
	{

	if (flg == "must")
		{
		if (isBlank(obj) == true )
			return;
		}	

	var s = obj.value;

	if (s.indexOf("@",0) == -1 || s.indexOf(".",0) == -1 )
		{
		alert(" Enter Valid E-Mail \n");
//		obj.focus();
		return false;
		}
	
	}


//*******************************************************************
// This function allow alphabets,numbers and underscore . no space allowed

function validUserName (obj,flg)
	{

	if (flg == "must")
		{
		if (isBlank(obj) == true )
			return;
		}	

		var str = obj.value;  

		for (var i = 0; i < str.length; i++) 
		{
			var ch = str.substring(i, i + 1);
			if (!( (ch >= "a" && ch <= "z" ) || (ch >= "A" && ch <= "Z") || (ch >= "0" && ch <= "9") || (ch == "_") ) )
				{
				alert("\nPlease enter alphabets(a to z/A to Z),numbers(0 to 9) and underscore ( _ )only");
				obj.focus();
				return false;
				}
		}/* END OF FOR*/

		Ltrim(obj); //Remove Leading space

	}


//*********************************************************************
// This function allow numbers and "[]" , "()" , "-".  space is allowed

function validPhone(obj,flg)
	{

	if (flg == "must")
		{
		if (isBlank(obj) == true )
			return;
		}	

		var str = obj.value;  

		for (var i = 0; i < str.length; i++) 
		{
			var ch = str.substring(i, i + 1);
			if (!( (ch == "]" || ch == "[" ) || (ch == "(" || ch == ")") || (ch >= "0" && ch <= "9") || (ch == "-") || (ch == " ") ) )
				{
				alert("\nPlease enter numbers(0 to 9),braces( () / [] ) or dash(-) and only");
				obj.focus();
				return false;
				}
		}/* END OF FOR*/

		Ltrim(obj); //Remove Leading space

	}


//*********************************************************************
// This function remves leading blanks of any string

function Ltrim(s,flg)
	{
	var t = new String();

	if (flg == "must")
		{
		if (isBlank(s) == true )
			return;
		}	
			
	//t = s.value;
	t=s;

	for (var i=0 ; i < t.length ;i++)
		{
		if (t.charAt(i) == " " ) 
			s.value = t.substr(i+1 ,t.length);
		else
			break;	
		}
	}


//********************************************************************
// This function check weather the obect is empty and if yes it gives mesgbox of its name

	function isEmpty(obj)
		{
		if (obj != null)
			{
			str = obj.name;
			str = str.substring(3,str.length); //removing prefix like "txt" ,"cmb" 

			if (obj.value == "")
				{
				alert ("Please enter " + str);
				obj.focus();
				return false;
				}
			}
		}


//********************************************************************
// This function check maxlength for multiline text box

function chkLength(objText,len)
	{
	mystr = objText.value;
	if (mystr.length > len)
		{
		alert ('Maximum limit is ' + len + ' characters');
		objText.focus (); 
		}
	}


