function checkForAt(str)
{
	var l = str.length;
	var hasat = false;
	for (var i = 0; i < l; i++)
	{
		if (str.charAt(i) == '@')
		{
			hasat = true;
		}
	}
	return hasat;
}
function quicklink(str)
{
	var l = str.length;
	var begin = false;
	var output = "";
	var compare = "";
	var bcompare = false;
	for (var i = 0; i < l; i++)
	{
		if (begin)
		{
			if (str.charAt(i) == '.')
			{
				bcompare = false;
			}
			output += str.charAt(i);
			if (bcompare)
			{
				compare += str.charAt(i);
			}
		}
		if (str.charAt(i) == '@')
		{
			begin = true;
			bcompare = true;
		}
	}
	if (compare == 'gmail')
	{
		return "http://www."+output;
	}
	if (compare == 'yahoo')
	{
		return "http://www."+output;
	}
	if (compare == 'live')
	{
		return "http://www."+output;
	}
	if (compare == 'hotmail')
	{
		return "http://www."+output;
	}
	if (compare == 'msn')
	{
		return "http://www."+output;
	}
	return '';
}

window.addEvent('domready', function()
{
	$('myform').addEvent('submit', function(e){
		e.preventDefault();
		if ($('email').get('value') == 'enter your email address...')
		{
			$('comment').innerHTML = 'Please enter an email address';
		}
		else
		{
			if (checkForAt($('email').value))
			{
				var request = new Request({url:'processNewUser.php', onSuccess: function(response){
						if (response == '1')
						{
							var q = quicklink($('email').value);
							if (q != '')
							{
								$('comment').innerHTML = "Welcome to notes for later!  An email has been sent to you with a link to claim your bookmarklet.  IMPORTANT: Make sure the email wasn\'t sent to spam!<br /><br />Proceed to <a href='"+q+"'>"+q+"</a>";
							}
							else
							{
								$('comment').innerHTML = 'Welcome to notes for later!  An email has been sent to you with a link to claim your bookmarklet.  IMPORTANT: Make sure the email wasn\'t sent to spam!';
							}
						}
						else
						{
							$('comment').innerHTML = 'Please enter an email address';
						}
					}
				}).get({'e' : $('email').value});
			}
			else
			{
				$('comment').innerHTML = 'Please enter an email address';
			}
		}
	});
	$('email').addEvent('focus', function(){
		if ($('email').get('value') == 'enter your email address...')
		{
			$('email').set('value', '');
		}
	});
	$('email').set('value', 'enter your email address...');
});
