function checkEmail(email)
{
elen = email.length;
efirstch=email.substring(0,1);
elastch=email.substring(elen-1,elen);

atPos=email.indexOf("@",1)

if (atPos==-1)
{
return 0;
}

if (email.indexOf("@",atPos+1)!= -1)
{
return 0;
}

periodPos=email.indexOf(".",atPos)

if(periodPos == -1)
{
return 0;
}
if (periodPos+3 > elen)
{
return 0;
}
if (email.indexOf("..",1) != -1)
{
return 0;
}
if (email.indexOf("@.",1)!=-1)
{
return 0;
}

if (email.indexOf(".@",1)!=-1)
{
return 0;
}

if (email.indexOf("-@",1)!=-1)
{
return 0;
}

if (email.indexOf("@-",1)!=-1)
{
return 0;
}

if (email.indexOf("-.",1)!=-1)
{
return 0;
}
if (email.indexOf(".-",1)!=-1)
{
return 0;
}

if (email.indexOf("--",1)!=-1)
{
return 0;
}

for (var i = 1; i<elen; ++i)
{
var ch=email.substring(i,i+1);
if  ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch < "0" || "9" < ch) && (ch != "@") && (ch != "_") && (ch != ".") && (ch != "-"))
{
return 0;
}
}
return true;
}
