/************************************
 * Validity Check for Questionnaire *
 *       Function Definations       *
 *                                  *
 *          Built by Sunny          *
 *   (C) 2008-2009 ukchinese.com    *
 ************************************/

function CheckInteger(x)
//To check if "x" is integer or not
{
	for (i = 0; i < x.length; i++)
	{
		ch = x.charAt(i);
		if (ch < '0' || ch > '9')
		{
			return	false;
		}
	}
	return true;
}

function CheckMustLength(x, len)
//To check if the length of "x" is "len"
{
	if (x.length != len)
	{
		return false;
	}
	return true;
}

function CheckEmail(x)
{
  var len = x.length;
	pos1 = x.indexOf("@");
	pos2 = x.indexOf(".");
	pos3 = x.lastIndexOf("@");
	pos4 = x.lastIndexOf(".");
	//check '@' and '.' is not first or last character
	if ((pos1 <= 0)||(pos1 == len-1)||(pos2 <= 0)||(pos2 == len-1))
	{
		return false;
	}
	else
	{
		//check @. or .@
		if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1)
		  || ( pos1 != pos3 )  //find two @
		  || ( pos4 < pos3 ) ) //. should behind the '@'  		
		{
			return false;
		}
	}
	return true;
}