onloads.push( initPage );
				
function initPage() 
{
	productUpdater = new ProductUpdater();
	ajaxEngine.registerRequest( 'update', '/product_updater.php' );
	ajaxEngine.registerAjaxObject( 'productUpdater', productUpdater);
}

var available_inventory = new Array();

function updateProduct(n, productId)
{
	if (productId == null)
	{
		var features = new Array();
		var i = 0;

		itemId = document.getElementById('item_id' + n);

		for (a = 0; a < 10; a++)
		{
			selectId = "feature" + n + "_" + a;
			select =  document.getElementById(selectId);
			if (select != null)
			{
				features[i++] = select.value;
			}
		}

		ajaxEngine.sendRequest('update', "item_id=" + itemId.value, "features=" + features, "n=" + n);
	}
	else
	{
		ajaxEngine.sendRequest('update', "product_id=" + productId, "n=" + n);
	}
}

function moredetails (n)
{
	document.getElementById('shopping_cart'+n).action = '/products.html';
	document.getElementById('shopping_cart'+n).submit();
}

function addtocart (n)
{
	document.getElementById('shopping_cart'+n).action = '/shopping_cart.html?action=addtocart';
}

function checkout (n)
{
	document.getElementById('shopping_cart'+n).action='/shopping_cart.html?action=checkout';
}

function stockNotification (n)
{
	productId = document.getElementById('product_id'+n);

	day = new Date();
	id = day.getTime();
	
	eval("page" + id + " = window.open ('/stock_notification.html?product_id=" + productId.value + "', '" + id + "', 'toolbar=0, scrollbars=0, location=0, statusbar=0, menubar=0, resizable=0, width=600, height=450, left = 212, top = 284');");
}

function multiInternationalization (n)
{
	for (i = 0; i < n; i++)
	{
		stateReqLabel = document.getElementById('state_req_label_' + i);
		stateLabel = document.getElementById('state_label_' + i);
		stateSelect = document.getElementById('state_select_' + i);
		stateText = document.getElementById('state_text_' + i);
		country = document.getElementById('country_' + i);

		if (country.value == "245")
		{
			stateReqLabel.style.display = "inline";
			stateLabel.style.display = "none";
			stateSelect.style.display = "inline";
			stateText.style.display = "none";
		}
		else
		{
			stateReqLabel.style.display = "none";
			stateLabel.style.display = "inline";
			stateSelect.style.display = "none";
			stateText.style.display = "inline";
		}
	}
}
