function ValidateEmail(EmailStr)
{
	var tempstr;
	var countofid;

		tempstr = EmailStr;
			
		while(tempstr.length != 0)
		{
			if(tempstr.indexOf("@") != -1)
			{
				countofid++;
				tempstr = tempstr.substr(tempstr.indexOf("@") + 1);
			}
			else
			{
				tempstr = "";
				break;
			}
		}
			
		if((countofid > 1))
		{
			alert("Please make sure that Id is correct.");
			return (false);
		}
			
		tempstr = EmailStr;
		if ((tempstr.indexOf("@",1) == -1)||(tempstr.indexOf("@") == 0))
		{
			alert("Please enter a valid Email address")
			return (false);
		}
			
		if (tempstr.indexOf(".") == 0)
		{
			alert("Please enter a valid E-Mail address");
			return (false);
		}
		
	var checkstr = "";
	var checkstrflag = false;
		
	checkstr = tempstr.substring(0,(tempstr.indexOf("@")));
	if(checkstr.length == 0)
	{
		alert("Please enter a valid E-Mail address");
		return(false);
	}
	else
	{
		//this is for checking character in the string and for validation of string.
		for(i=0;i <= (checkstr.length - 1);i++)
		{
			if((checkstr.charCodeAt(i) >= 48) && (checkstr.charCodeAt(i) <= 57))
				checkstrflag = false;
			else if((checkstr.charCodeAt(i) >= 65) && (checkstr.charCodeAt(i) <= 90))
				checkstrflag = false;
			else if((checkstr.charCodeAt(i) >= 97) && (checkstr.charCodeAt(i) <= 122))
				checkstrflag = false;
			else if(checkstr.charCodeAt(i) == 45)
				checkstrflag = false;
			else if(checkstr.charCodeAt(i) == 46)
				checkstrflag = false;
			else if(checkstr.charCodeAt(i) == 95)
				checkstrflag = false;
			else
			{
				checkstrflag = true;
				break;
			}
		}
	}
		
	if(checkstrflag)
	{
		alert("Please make sure that Id is correct.");
		return (false);
	}
		
	var findstr = "";
	if(checkstr.indexOf(".") != -1)
	{
		findstr = tempstr.substr(checkstr.indexOf(".") + 1);
	}
	else
	{
		findstr = tempstr;
	}
		
	checkstr = findstr.substring((findstr.indexOf("@") + 1),findstr.indexOf("."));
	if(checkstr.length == 0)
	{
		alert("Please enter a valid E-Mail address");
		return (false);
	}
	else
	{
		for(i=0;i <= (checkstr.length - 1);i++)
		{
			if((checkstr.charCodeAt(i) >= 48) && (checkstr.charCodeAt(i) <= 57))
				checkstrflag = false;
			else if((checkstr.charCodeAt(i) >= 65) && (checkstr.charCodeAt(i) <= 90))
				checkstrflag = false;
			else if((checkstr.charCodeAt(i) >= 97) && (checkstr.charCodeAt(i) <= 122))
				checkstrflag = false;
			else if((checkstr.charCodeAt(i) >= 45) && (checkstr.charCodeAt(i) <= 46))
				checkstrflag = false;
			else if(checkstr.charCodeAt(i) == 95)
				checkstrflag = false;
			else
			{
				checkstrflag = true;
				break;
			}
		}
	}
	if(checkstrflag)
	{
		alert("Please make sure that Id is correct.");
		return (false);
	}
	
	return (true);
}

function checkFields()
{
	//e-mail check
	if(ValidateEmail(document.alignorForm.email.value) == false)
	{
		document.alignorForm.email.select();
		document.alignorForm.email.focus();
		return false;
	}
		
	// question check
	if (document.alignorForm.txtQuestion.value == "")
	{	
		alert("Question field cannot be left blank.");
		document.alignorForm.txtQuestion.select();
		document.alignorForm.txtQuestion.focus();
		return false;
	}
		
	return true;
}
