function trim(str)
{
// To trim the leading and trailing spaces in a string
	var len=str.length
	var retstr=""
	var i = 0
	if(len > 0)
	{
		for(i = 0; i < len; i++)
		{
			if(str.charAt(i)==" ")
			{
				retstr=str.substring(i+1)
			}
			else
				break;
		}
		if(i!=0)
			str=retstr
		len = str.length
		for(i=len-1; i >=0; i--)
		{
			if(str.charAt(i)==" ")
			{
				retstr=str.substring(0,i)
			}
			else
				break;
		}
		if(i!=(len-1))
			str=retstr
	}
	return str
}

function checkempty(obj)
{
// To check whether the contents of a HTML object is empty.
	if(trim(obj.value)=="")
	{
		obj.value=""
		return true
	}
	else
		return false
}

function msgempty(msg, obj)
{
// To display the message 
	alert(msg + " cannot be empty")
	obj.focus()
}

function checklength(obj, len)
{
// To check whether a HTML Textbox contain the necessary length of characters.
	if(trim((obj.value)).length < len)
	{
		obj.value=trim(obj.value)
		return true
	}
	else
		return false
}

function msglength(msg, len, obj)
{
// To display the message 
	alert(msg + " should contain a minimum of " + len + " characters.")
	obj.focus()
}
function trimmail(str)
{
// To trim the leading, trailing, middle spaces in a string
	var len=str.length
	var str1=""
	var str2=""
	var retstr = ""
	var i = 0
	if(len > 0)
	{
		for(i = 0; i < len; i++)
		{
			if(str.charAt(i)==" ")
			{
				str2 = str.substring(i+1)
				if(str1!="")
				{
					retstr = retstr + str1
					str1 = ""
				}
			}
			else
			{
				str1 = str1 + str.substring(i,i+1)
			}
		}
		if(str1!="")
		{
			retstr = retstr + str1
			str1 = ""
		}
	if(retstr!="")
		str = retstr
	}
	return str
}

function checkcontent(obj,len)
{
// To check the Content for being not empty and with a minimum no. of characters
	if(checkempty(obj))
	{
		msgempty(obj.name,obj)
		return false
	}
	if(checklength(obj, len))
	{
		msglength(obj.name, len, obj)
		return false
	}
	return true
}

function checkmail(obj)
{
// To check the e-mail for correctness
		if(!checkempty(obj))
		{
		obj.value = trimmail(obj.value)
		var strmail
		strmail = obj.value
		var pos1 = strmail.indexOf("@")
		if((pos1== -1) || (pos1 < 3))
		{
			alert("E-mail should contain a @ Symbol and it should occur at or after the 4th Position")
			obj.focus()
			return false
		}
		var pos2 = strmail.indexOf(".")
		if((pos2== -1) || (pos2 < 6) || (pos2 < pos1+3))
		{
			alert("E-mail should contain a . Symbol and it should occur at or after the 6th Position and after the @ Symbol")
			obj.focus()
			return false
		}
		if(strmail.length <= strmail.indexOf(".")+2)
		{
			alert("Email should contain a minimum of 2 characters after the . Symbol")
			obj.focus()
			return false
		}
		return true
		}
		return true
}
