
function isEmail(email) {
    invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;";

    // Check for null
    if (email == "") {
        alert("Va rugam sa introduceti e-mail-ul dumneavoastra.");
		return false;
    }

    // Check for invalid characters as defined above
    for (i=0; i<invalidChars.length; i++) {
        badChar = invalidChars.charAt(i);
        if (email.indexOf(badChar,0) > -1) {
            alert("Adresa de mail trebuie sa contina doar litere, cifre sau _.");
			return false;
        }
    }
    lengthOfEmail = email.length;
    if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == ".")) {
        alert("Adresa de e-mail este incompleta.");
		return false;
    }
    Pos = email.indexOf("@",1);
    if (email.charAt(Pos + 1) == ".") {
        alert("Adresa de e-mail este incompleta(nu contine caracterul @).");
		return false;
    }
    while ((Pos < lengthOfEmail) && ( Pos != -1)) {
        Pos = email.indexOf(".",Pos);
        if (email.charAt(Pos + 1) == ".") {
            alert("Adresa de e-mail este incompleta.");
			return false;
        }
        if (Pos != -1) {
            Pos++;
        }
    }

    // There must be at least one @ symbol
    atPos = email.indexOf("@",1);
    if (atPos == -1) {
        alert("Adresa de e-mail este incompleta.");
		return false;
    }

    // But only ONE @ symbol
    if (email.indexOf("@",atPos+1) != -1) {
        alert("Adresa de e-mail este incorecta.");
		return false;
    }

    // Also check for at least one period after the @ symbol
    periodPos = email.indexOf(".",atPos);
    if (periodPos == -1) {
        alert("Adresa de e-mail este incompleta.");
		return false;
    }
    if (periodPos+3 > email.length) {
        alert("Adresa de e-mail este incorecta.");
		return false;
    }
    return true;
	
}


