function clearProdField()
{
	$('prodURL').value = '';
}

function submitProdEnter(e)
{
	if (e.type == "keypress") // the user entered a character
		var whichCode = e.keyCode;
	if ( whichCode == "13" ) 
	{
		submitProduct();
   	}
}

function submitProduct()
{
	var personID = $F('personID');
	var prodURL = $F('prodURL');
	var regURL = /http:/i.exec(prodURL);
	if (personID == 'NULL')
	{
		personID = '';
	}
	if (prodURL == 'Enter a product URL to add it to your list' || prodURL == '')
	{
		alert('Please enter the URL of the product you want to save.')
	}
	else if (!regURL)
	{
		alert('It looks like you entered the name of the product instead of the URL. Please copy the URL from your browser\'s address bar. It should start with http://');
	}
	else
	{
		var requestURL = 'http://www.savvycircle.com/web/input/controller/inputController.php';
		var requestParams = "a=url&pid="+personID+'&at=3&u='+encodeURIComponent(prodURL);	
		var myAjax = new Ajax.Request(requestURL,
			{method:'get', parameters: requestParams, onSuccess: submitProductResponse}
			);	
	}
}

function saveSavedProduct(prodURL)
{	
	var personID = $F('personID');
	var requestURL = 'http://www.savvycircle.com/web/input/controller/inputController.php';
	var requestParams = "a=url&pid="+personID+'&at=1&u='+encodeURIComponent(prodURL);	
	var myAjax = new Ajax.Request(requestURL,
		{method:'get', parameters: requestParams, onSuccess: submitSaveSavedProductResponse}
		);
}

function submitProductResponse(req)
{
	if (req.responseText == "This item has been added to your shopping list!")
	{
		var answer = confirm(req.responseText+'\n\nDo you want to reload your shopping list?');
		if (answer)
		{
			location.href = 'http://www.savvycircle.com/page.php?page=shoppinglist';
		}
	}
	
	//alert(req.responseText);
}

function submitSaveSavedProductResponse(req)
{
	location.href = 'http://www.savvycircle.com';
}
