var Alphabets = 1;
var Names = 2;
var Numbers = 3;
var NumbersSpaceCommaHyphen = 4;
var AlphaNumerics = 5;
var NumbersDotsHyphen = 6;
var Email = 7;
var Web = 8;
function AllowOnly(code, theCtl, sCaption, bReq)
{
	var retVal = true;
	strVal = theCtl.value;
	if(strVal=='' && bReq)
		return showMessage(theCtl, sCaption + " field should not be empty");
	if(strVal=='')
		return true;
	var prvChr = ' ';
	var countAt = 0;
	var countP = 0;
	var countC = 0;
	for(var i=0;i<strVal.length;i++)
	{
		var chr = strVal.substring(i,i+1);
		if(i>0)
			prvChr = strVal.substring(i-1,i);
		if(i==0 && chr==' ')
			retVal = showMessage(theCtl, sCaption + " cannot start with spaces");
		if(code==Alphabets && !((chr>='A' && chr<='Z')||(chr>='a' && chr<='z')))
			retVal = showMessage(theCtl, sCaption + " allows only alphabets");
		if(code==Names && !((chr>='A' && chr<='Z')||(chr>='a' && chr<='z')||chr=='.'||chr==' '))
			retVal = showMessage(theCtl, sCaption + " allows only alphabets space and period");
		if(code==Numbers && !(chr>='0' && chr<='9'))
			retVal = showMessage(theCtl, sCaption + " allows only numbers");
		if(code==NumbersSpaceCommaHyphen && !((chr>='0' && chr<='9')||chr==' '||chr==','||chr=='-'))
			retVal = showMessage(theCtl, sCaption + " allows only numbers space comma and hypen");
		if(code==AlphaNumerics && !((chr>='A' && chr<='Z')||(chr>='a' && chr<='z')||(chr>='0' && chr<='9')||chr==' '))
			retVal = showMessage(theCtl, sCaption + " allows only alphabets numbers and blank spaces");
		if(code==NumbersDotsHyphen && !((chr>='0' && chr<='9')||chr=='.'||chr=='-'))
			retVal = showMessage(theCtl, sCaption + " allows only numbers with decimal and comma");
		if(code==Email)
		{
			if(!((chr>='A' && chr<='Z')||(chr>='a' && chr<='z')||(chr>='0' && chr<='9')||(chr=='@' && prvChr!='@')||(chr=='.' && prvChr!='.')||chr=='-'||chr=='_'))
				retVal = false;
			if(chr=='@') countAt++;
			if(chr=='.') countP++;
		}
		if(code==Web)
		{
			if(!((chr>='A' && chr<='Z')||(chr>='a' && chr<='z')||(chr>='0' && chr<='9')||(chr=='.' && prvChr!='.')||(chr=='/' && prvChr==':')||chr=='-'||prvChr=='_'||chr==':'))
				retVal = false;
			if(chr==':') countC++;
			if(chr=='.') countP++;
		}
		if(!retVal)
			break;
	}
	if(code==Email)
		if(!retVal)
			retVal = showMessage(theCtl, "Invalid Email id");
		else
		{
			if(countAt==0 && retVal)
				retVal = showMessage(theCtl, "Email id should contains @ symbol");
			if(countP==0 && retVal)
				retVal = showMessage(theCtl, "Email is should contains atleast one . symbol");
			if(countAt>1 && retVal)
				retVal = showMessage(theCtl, sCaption + "Email should not allows more than one @ symbol");
		}
	if(code==Web)
		if(!retVal)
			retVal = showMessage(theCtl, "Invalid Web Address");
		else
		{
			if(countC>0 && countC!=2  && retVal)
				retVal = showMessage(theCtl, "Web address should allowed only two : symbol");
			if(countP==0  && retVal)
				retVal = showMessage(theCtl, "Web address should contains atleast one . symbol");
		}
	return retVal;
}

function showMessage(theCtl,msg)
{
	alert(msg);
	theCtl.focus();
	return false;
}