﻿function Product(IDnode, IDlanguage)
{
	this.pageUrl = 'GetProduct.aspx';
	this.IDnode = IDnode;
	this.IDlanguage = IDlanguage;
	if(this.conn != null)
		this.conn.req.abort();

	this.conn = new net.XMLHTTPRequestWrapper(this.onLoad, this.onLoadError, this);
	this.conn.loadData(this.pageUrl +
		'?IDnode=' + this.IDnode +
		'&IDlanguage=' + this.IDlanguage);
		
	var obj = document.getElementById('productCard');
	if(obj != null)
		obj.innerHTML = (this.IDlanguage == 1)?"caricamento in corso":"loading, please wait";	
};

Product.prototype.onLoad = function()
{
	//alert(this.conn.req.responseText);
	var obj = document.getElementById('productCard');
	if(obj != null)
		obj.innerHTML = this.conn.req.responseText;
	this.conn = null;
};

Product.prototype.onLoadError = function()
{
	//alert(this.conn.req.responseXML.documentElement.nodeName);
	alert('Error loading product info.\nPlease try again later.');
	this.conn = null;
};

//
function ShowSubsection(IDnode)
{
	//
	var categories = document.getElementById('categories');
	var divs = categories.getElementsByTagName('DIV');
	//
	for(var i = 0; i < divs.length; i++)
	{
		var id = divs[i].id;
		divs[i].style.display = (id == ('IDnode_' + IDnode))?'':'none';
	}
}


/* CART */
function ModificaNumero(IDnode)
{
	// get value
	var tf = document.forms[0]['tf_' + IDnode.toString()];
	if(tf != null)
	{
		var number = parseInt(tf.value);
		if(!isNaN(number))
		{
			document.location = 'Cart.aspx?action=update&ID=' + IDnode.toString() + '&value=' + number;
		}
	}
};
