var errors = {
	"yahoo.com"   : "^(yahoo\.c0m|yahool\.com|yahooc\.om|yaoo\.com|yahho\.com|ahoo\.com|yahpoo\.ca|yajoo\.com|yhaoo\.com|yajoo\.com|yaho\.com|ahoo\.com|yhaoo\.it|yajoo\.com)$",
	"hotmail.com" : "^(hotmail\.cm|hoatmail\.fr|otmail\.com|hotmaol\.com|hotmai\.com|htmail\.com|homail\.com|hoymail\.com|hotmaiol\.com|hotmaiol\.com)$",
	"gmail.com"   : "^(gmai\.com|gmal\.com)$"
};
function addError( elem, obj, id ) {
	$(elem).closest("tr").after(
		$("<tr></tr>").attr("id", id).append( $("<td></td>") ).append(
				$("<td></td>")
					.attr("colspan", $(elem).closest("tr").find("td").length-1 )
					.css("text-align", "left").css( {"color":"red","font-size":"12px"} )
					.append(obj)
		)
	);
}
$(document).ready(function(){
	$("input[name^='signup[username:'],input[name^='signup[password:']").blur(function(){
		$(this).val( $(this).val().replace( /([^0-9a-zA-Z])/g, "" ) );
	}).blur();
	// Email checking
	$("input[name^='signup[email:']")
		.blur(function() {
			$(this).attr("id","gea4paisai");
			$("#pavu42drap").remove();
			var val = $(this).val().replace( /([^\x21-\x7F])/g, "" );
			if ( val.length>0 ) {
				$(this).parent().append(
					$("<img />")
						.attr("id", "crae56jeat")
						.attr("src","/gnscripts/loader.gif")
				);
				if ( ( res=val.match( /^(.+)@(.+)$/) ) ) {
					for ( var domain in errors) {
						var regex = new RegExp( errors[domain], "i" );
						if ( regex.test( res[2] ) ) {
							var email = res[1]+"@"+domain;
							addError(this,
								$("<em>Did you mean <strong>"+email+"</strong>&nbsp;-&nbsp;</em>").append(
									$("<a>yes</a>")
										.attr("href","#")
										.click( function(){ $("#gea4paisai").val( email ).blur(); return false; } )
								)
								,"pavu42drap"
							);
							break;
						}
					}
				} else {	
					addError( this, "Invalid email address", "pavu42drap" );
				}
			}
			$(this).val( val )
				.parent().find("img").remove();
		}).blur();
});

