function isEmail(email) {
    invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;";
    // 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;
}

function trim(s) {
	while (s.substring(0,1) == ' ') {
	s = s.substring(1,s.length);
  	}
	while (s.substring(s.length-1,s.length) == ' ') {
 	s = s.substring(0,s.length-1);
  	}
	 return s;		
	}

function isPasswordEquals(messageHolderName, pass, passConfirm) {
	var passMsg			= document.getElementById(messageHolderName);
	if(trim(pass) != trim(passConfirm))
		passMsg.innerHTML	= "Passwords do not match";
	else 
		passMsg.innerHTML	= " ";
}
function checkcaptcha(theform) {
	captcha = theform.captcha.value
	captchacheck  = theform.captchacheck.value
	
	if (captcha.toLowerCase() == captchacheck.toLowerCase()) {
		
		return true
	} else {
		
		theform.action = "/userregistration/userregistration/save"
		theform.method = "post"
		theform.submit()
		
		return false;
	}
}