function ChkForm(objForm,bgColor,errorColor)
{
	FieldStr='';
	flag=true;
	tmpflag=true;
	
	for(i=0;i<objForm.length;++i)
	{
		if (objForm[i].Check=='true')
		{
			objForm[i].style.background=bgColor;
			switch(objForm[i].FType)
			{
				case 'EMAIL':
					if (!CheckEmail(objForm[i].value))
					{
						objForm[i].style.background=errorColor;
						FieldStr+='  -' + objForm[i].CName + String.fromCharCode(13);
						flag=false;
					}
					break;
				case 'NUM':
					if (!CheckNum(objForm[i].value))
					{
						objForm[i].style.background=errorColor;
						FieldStr+='  -' + objForm[i].CName + String.fromCharCode(13);
						flag=false;
					}
					break;
				case 'CHAR':
					if (!CheckChr(objForm[i].value))
					{
						objForm[i].style.background=errorColor;
						FieldStr+='  -' + objForm[i].CName + String.fromCharCode(13);
						flag=false;
					}
					break;
				default:
					if (!CheckStr(objForm[i].value))
					{
						objForm[i].style.background=errorColor;
						FieldStr+='  -' + objForm[i].CName + String.fromCharCode(13);
						flag=false;
					}
					break;
			}
		}
	}
	if (!flag)
		alert('Please check the following field(s) are filled in correctly.' + String.fromCharCode(13) + FieldStr);
	return flag;
}

function CheckStr(objVal)
{
	//tar=document.getElementById(objStr);
	if ( objVal=="" || objVal== null)
		return false;
	else
		return true;
}	

function CheckChr(objVal)
{
	for(i=0;i<objVal.length;++i)
	{
		tmp=objVal.toUpperCase();
		if (!(tmp.charCodeAt(i)>64 && tmp.charCodeAt(i)<91))
		{
				if (!(tmp.charCodeAt(i)>47 && tmp.charCodeAt(i)<58))
					return false;
		}
	}
	return true;
}

function CheckNum(objVal)
{
	//tar=document.getElementById(objStr);
	if ( objVal=="" || objVal== null)
	{
		return false;
	}

	tmp=objVal+"";

	if(isNaN(parseInt(tmp/1)) ||parseInt(tmp)<0)
	{
			return false;
	}
	return true;
}

function CheckCB(obj,LstStr)
{
	LstArr=LstStr.split(';');
	for(i=0;i<LstArr.length;++i)
	{
		for(j=0;j<obj.length;++j)
		{
			if(obj[j].value==LstArr[i])
				obj[j].checked=true;
		}
	}
}

function CheckEmail (emailStr)
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(emailStr))
		return true
	else{
		return false
	}

}

function CheckEmail1 (emailStr)
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)

	if (matchArray==null)
	{
		//alert("Email address seems incorrect")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null)
	{
	   // alert("The email address seems incorrect")
	    return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null)
	{
		for (var i=1;i<=4;i++) 
		{
		    if (IPArray[i]>255) 
		    {
		      //  alert("Email address is incorrect")
				return false
		    }
	    }
	    return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null)
	{
		alert("The email address is incorrect")
	    return false
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
	{
	 //  alert("Email Address is incorrect")
	   return false
	}

	if (len<2)
	{
		var errStr="The Email Address is incorrect"
		//alert(errStr)
		return false
	}
	
	return true;
}