//clear text box on click
function clearField(a,b) {
	if (a.value==b) {
		a.value="";
	}
    //a.select();
}

function checkRegForm(theForm) {
    //theForm.email.value=Trim(theForm.email.value);
    
    if (theForm.email.value=="") {
        alert("Please enter your email address.");
        theForm.email.select();
    } else if (!isEmail(theForm.email.value)) {
        alert("Your email address appears to be invalid.  Please check your typing and try again.");
        theForm.email.select();
    } else if (theForm.UserName.value=="") {
        alert("Please enter your Name.");
        theForm.UserName.select();
    } else {
        theForm.submit();
    }
}

function RTrim(strMyString) {
    return(strMyString.replace(/^\s*/,""));
}
 
function LTrim(strMyString) {
    return(strMyString.replace(/\s*$/, ""));
}
 
function Trim(strMyString) {
    return(RTrim(LTrim(strMyString)));
}

// check for valid email
function isEmail(email) {
    invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;";

    // Check for null
    if (email == "") {
        return true;
    }

    // Check for invalid characters as defined above
    for (i=0; i<invalidChars.length; i++) {
        badChar = invalidChars.charAt(i);
        if (email.indexOf(badChar,0) > -1) {
            return false;
        }
    }
    lengthOfEmail = email.length;
    if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == ".")) {
        return false;
    }
    Pos = email.indexOf("@",1);
    if (email.charAt(Pos + 1) == ".") {
        return false;
    }
    while ((Pos < lengthOfEmail) && ( Pos != -1)) {
        Pos = email.indexOf(".",Pos);
        if (email.charAt(Pos + 1) == ".") {
            return false;
        }
        if (Pos != -1) {
            Pos++;
        }
    }

    // There must be at least one @ symbol
    atPos = email.indexOf("@",1);
    if (atPos == -1) {
        return false;
    }

    // But only ONE @ symbol
    if (email.indexOf("@",atPos+1) != -1) {
        return false;
    }

    // Also check for at least one period after the @ symbol
    periodPos = email.indexOf(".",atPos);
    if (periodPos == -1) {
        return false;
    }
    if (periodPos+3 > email.length) {
        return false;
    }
    return true;
}