$(document).ready(function() { 
	    var options = { 
	        success:  subscribeResponse,
	        dataType:  'json'
	    }; 
	    $('#subscribeForm').ajaxForm(options); 
	}); 
    
function subscribeResponse(responseText, statusText)  { 

	if (responseText.successStatus) {

		$('#subscribeText').show('slow').html(responseText.message).css('color', '#007700').css('font-size', '14px');
		$('#subscribeError').hide();
		$('#subscribeFormBlock').hide();

	} else {

		$('#subscribeError').show('slow').html(responseText.message);

	}
} 
	
function searchProduct() {

	document.location.href='/search.php?category=' + $('#category').val() + '&q='+$('#q').val();
}

function addToCart(p_sku_id) { 
	
	if (document.cartForm) { 
		document.getElementById('CART_SKU_ID').value = p_sku_id;
		document.cartForm.submit();
	}
}

function showView(p_view) {
	
	if (p_view == 'list') {
		$('#product-gallery').hide();
		$('#product-list').show('slow');
	
	} else {
		$('#product-list').hide();
		$('#product-gallery').show('slow');
	}
	
	$.post("/ajax/controller.php", { actiontype: "changeview", view: p_view, action: "postmsg"});

}

function saveFavorite(p_product_id) {

	$.post("/ajax/controller.php", { actiontype: "saveproduct", product_id: p_product_id, action: "postmsg"}, function(){ $('#save'+p_product_id).text('saved!')});
}

function emptyCart(p_product_id) {

	if (confirm('Are you sure you want to empty your cart?')) { 
		$.post("/ajax/controller.php", { actiontype: "emptycart", action: "postmsg"}, function(){ $('#emptycartlink').text('emptied!'); $('#cartitemcount').text('0'); });
	}
}

function closePromo() {
	$('#promobox').hide('slow');
	$.post("/ajax/controller.php", { actiontype: "closepromo", action: "postmsg"});
}