function doCartAdd(p) {
	success = true;
	outUrl = '';
	
	if (p) {
		outUrl = '/ajax/docartadd.php?p='+p;
	}
	
	if (document.getElementById('addToCart')) {
		qty = document.getElementById('qty').value;
		price = document.getElementById('price').value;
		inFrm = document.forms['addToCart'].elements;
		
		outUrl = '/ajax/docartadd.php?p='+escape(p);
		outUrl += '&qty='+escape(qty);
		outUrl += '&price='+escape(price);
		
		for (i=0; i<inFrm.length; i++) {
			a = inFrm[i].id.substr(0,4);
			if (a=='|op|') {
				if (inFrm[i].value != 0) {
					outUrl += '&'+inFrm[i].id + '=' + inFrm[i].value;
				} else {
					success = false;
					alert('All product options must be filled in.');
				}
			}
		}
	}
	
	if ((outUrl)&&(success)) {
		new Ajax.Request(outUrl,
		{
			method:'get',
			onSuccess: function(transport){
				//var response = transport.responseText || "no response text";
				//alert("Success! \n\n" + response);
				data = transport.responseText;
				if (data == 'true') {
					doCartCountUpdate();
					alert('The item has been added to your cart');
				} else {
					alert(data);
				}
			},
			onFailure: function(){ alert('Ajax failed to add to your cart.') }
	 	});
	}
 }
 
function doCartCountUpdate() {
	if (document.getElementById('cartContentsTitle')) {
		new Ajax.Updater('cartContentsTitle', '/ajax/getcartcount.php', { method: 'get' });
	}
}
 
function doAddNewsletter() {
	email = '';
	unsub = false;
	
	if (document.getElementById('newsPage')) {
		email = document.getElementById('newsPage').value;
		unsub = document.getElementById('unsubscr').checked;
	} else {
		email = document.getElementById('newsTop').value;
	}
	
	outUrl = '/ajax/newsletter.php?e='+email;
	if (unsub) {	outUrl += '&r=1';	}
	
	
	new Ajax.Request(outUrl,
	{
		method:'get',
		onSuccess: function(transport){
			//var response = transport.responseText || "no response text";
			//alert("Success! \n\n" + response);
			data = transport.responseText;
			if (data == 'true') {
				if (unsub) {
					alert('You are now unsubscribed to the newsletter.');
				} else {
					alert('You are now subscribed to the newsletter.');
				}
			} else {
				alert(data);
			}
		},
		onFailure: function(){ alert('Ajax failed subscribe you to the newsletter.') }
	});
	
	if (!document.getElementById('newsPage')) {	document.getElementById('newsTop').value = '';	}
}
 
