// JavaScript Document

function checkMail(txtEmail,errMsg)
{
    var strEmail,tempStr,countI,countJ;
	strEmail="";
	tempStr=txtEmail.value;
	
	for(countI=0;countI<tempStr.length;countI++)
	{
		if(tempStr.charAt(countI)==' ') 
			continue;
		else
			break
	}
	
	for(countJ=tempStr.length-1;countJ>=0;countJ--)
	{
		if(tempStr.charAt(countJ)==' ') 
			continue;
		else
			break;
	}
	strEmail=tempStr.substring(countI,countJ+1);
	
	var SPLCHARS;
	SPLCHARS="'~!#$%^&*()`:\"<>?,/|\\"
	if (checkChars(txtEmail.value,SPLCHARS) == true || countChar(txtEmail.value,"@") >1)
	{
		alert(errMsg);
		txtEmail.focus();
		return false;
	}
	

	if(strEmail.indexOf("@") == -1 || strEmail.indexOf(".") == -1 || strEmail.indexOf(" ") != -1 || strEmail.indexOf("@") > strEmail.lastIndexOf(".") || strEmail.lastIndexOf(".")==strEmail.length-1) 
	{
		alert(errMsg);
		txtEmail.focus();
		return false;
	}
	return true;
}

function checkChars(str,chrs)
{
	var count;
	for(count=0;count<chrs.length;count++)
	{
		if(str.indexOf(chrs.charAt(count)) != -1)
			return true;
	}
	return false;
}
	
function countChar(str,chr)
{
	var pos,cnt;
	cnt=0;
	while((pos=str.indexOf(chr)) != -1)
	{
		cnt++;
		str=str.substring(pos+1);
	}
	return cnt;
}
