﻿function init_ProductListTabs(sTabId) {
	if (!sTabId)
		sTabId = 'product_list_tabbed';
	var oContainer = jQuery('#' + sTabId + ' .tabs');

	jQuery.each(oContainer.find('ul li'), function () {
		//Click
		var oAnchor = jQuery(this).find('p a');
		var sHref = oAnchor.attr('href');
		if (sHref && sHref.length > 0) {
			jQuery(this).click(function () {
				//alert(oAnchor.attr('href'));
				window.location.href = sHref;
			});
			if (!((browser_IsIE() && jQuery.browser.version <= 6)))
				oAnchor.attr('href', 'javascript://');
		}

		//Hover
		jQuery(this).hover(function () {
			jQuery(this).addClass('hover');
			jQuery.each(jQuery(this).find('img'), function () {
				jQuery(this).attr("src", jQuery(this).attr("src").replace(/(_on)?\.gif$/i, "_on.gif"));
			});
		}, function () {
			jQuery(this).removeClass('hover');
			if (!jQuery(this).hasClass('on')) {
				jQuery.each(jQuery(this).find('img'), function () {
					jQuery(this).attr("src", jQuery(this).attr("src").replace(/_on\.gif$/i, ".gif"));
				});
			}
		});
	});
}

function product_AddToCart(sProdGuid, sCartUrl, sPostUrl, onRefresh) {
	
	jQuery.ajax({
		type: "POST",
		url: sPostUrl,
		data: { request: '<Request><ProductGUID><![CDATA[' + sProdGuid + ']]></ProductGUID></Request>' },
		dataType: "xml",
		error: function (jqXHR, textStatus, errorThrown) {
			alert('ajax returned error');
		},
		success: function (xml) {
			processHandlerReturnXml(xml, function () {
				//Success
				//alert('success');
				if (sCartUrl && sCartUrl.length)
					window.location.href = sCartUrl;
				else {
					if (onRefresh != null)
						onRefresh();
				}
			},
			function (sErrorMessage) {
				//Fail
				alert('fail: ' + sErrorMessage);

			});
		}
	});	
}
