function validate(frm)
{
	if(Trim(document.getElementById("Name").value)=="")
	{
		alert("The Name cannot be empty. Please fill it in to proceed");
		document.getElementById("Name").focus();
		return false;
	}
	if(Trim(document.getElementById("Email").value)=="")
	{
		alert("The Email field cannot be empty. Please fill it in to proceed");
		document.getElementById("Email").focus();
		return false;
	}
	if(Trim(document.getElementById("Code").value)=="")
	{
		alert("The Code cannot be empty. Please fill it in to proceed");
		document.getElementById("Code").focus();
		return false;
	}
	return true;
}
function validateEmail(fld)
{
	var my=fld.value;
	var attherate=my.indexOf("@");
	var lastattherate = my.lastIndexOf("@")
	var dotpos=my.lastIndexOf(".");
	var posspace = my.indexOf(" ");
	var totallen = my.length;
	
	if (attherate<=0 || dotpos<=0 || attherate > dotpos || (dotpos-attherate)<=1 || (dotpos == totallen-1) || posspace > -1 || attherate!=lastattherate)
		return false;
	else
		return true;
}
function Trim(myval)
{
	var chklen=myval.length; 
	var pos=0;
	mychar = myval.charAt(0);

	while(pos>=0 || lstpos >=0)
	{
		pos=myval.indexOf(" ");
		if (pos==0)
		{
			myval=myval.substring(1,chklen);
			chklen = myval.length;
			mychar = myval.charAt(0);
		}
		lstpos=myval.lastIndexOf(" ");

		if (lstpos==chklen-1)
		{	
			myval=myval.substring(0,chklen-1);
			chklen=myval.length;
			mychar = myval.charAt(chklen-1);
		}
		
		if(mychar!=" ")
			break;

	}
	return myval;			
}
