var ShoppingId = false;
var ShoppingInit = false;
var ShoppingModo  
var ShoppingPagina
var ShoppingLoaded = false;
var ShoppingStyle = false;
var ShoppingServerPage = "/webiris/Modules/Shopping/AjaxServer/index.aspx";

function Shopping_init(ajaxIndex)
{
	var response = ajaxObjects[ajaxIndex].responseXML;

	// inizializza il modulo
	try
	{
	  	var moduleStyle=response.getElementsByTagName("style")[0].childNodes[0].nodeValue;
		if (ShoppingStyle == false) {
			ShoppingStyle = true;
			//addStyle(ajaxObjects[ajaxIndex].response); 
			addStyle(moduleStyle); 
		}
	} catch (err) {
	}

	if (modulename != "Shopping" && ShoppingInit==false) {
		modulename = "Shopping"

  		if (!ShoppingId)
		   ShoppingId=response.getElementsByTagName("contenitore")[0].childNodes[0].nodeValue;

		// moduli contenuti nel "modulo"
		var x = response.getElementsByTagName("struttura")
	  	for (var i=0;i<x.length;i++) {
			var nome=XmlGet(x,0,"nome");
			var contenitore=XmlGet(x,0,"contenitore");
			eval(nome + "Id='" + contenitore + "'")
			eval(nome + "Init=true")
			eval(nome+"_initAjax()")
		}
	}
	clearAjaxSession(ajaxIndex);
	Shopping_listAjax();
}

function Shopping_showForm(ajaxIndex)
{
	replace_html(ShoppingId, ajaxIndex)
}
    
function Shopping_showList(ajaxIndex)
{
	replace_html(ShoppingId, ajaxIndex)
}
function Shopping_CheckOut()
{
	// gid(ShoppingId).style.display = 'none';
	CheckOut_initAjax();
}

function Shopping_AddToCart(cat, prod)
{
	var ajaxIndex = ajaxObjects.length;
	ajaxObjects[ajaxIndex] = newAjaxSession(ajaxIndex, ShoppingId, 'addcart')
	ajaxObjects[ajaxIndex].requestFile = ShoppingServerPage;
	ajaxObjects[ajaxIndex].isBookmark = false;
	ajaxObjects[ajaxIndex].setVar('addcart','*');
	ajaxObjects[ajaxIndex].setVar('catalogo',cat);
	ajaxObjects[ajaxIndex].setVar('prodotto',prod);
	ajaxObjects[ajaxIndex].onCompletion = function(){ Shopping_showList(ajaxIndex); };	// Specify function that will be executed after file has been found
	ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function		

}

function Shopping_AddToCart(cat, prod, qta, divisa, lordo, netto)
{
	var ajaxIndex = ajaxObjects.length;
	ajaxObjects[ajaxIndex] = newAjaxSession(ajaxIndex, ShoppingId, 'addcart')
	ajaxObjects[ajaxIndex].requestFile = ShoppingServerPage;
	ajaxObjects[ajaxIndex].isBookmark = false;
	ajaxObjects[ajaxIndex].setVar('addcart','*');
	ajaxObjects[ajaxIndex].setVar('catalogo',cat);
	ajaxObjects[ajaxIndex].setVar('prodotto',prod);
	ajaxObjects[ajaxIndex].setVar('qta',qta);
	ajaxObjects[ajaxIndex].setVar('divisa',divisa);
	ajaxObjects[ajaxIndex].setVar('lordo',parseFloat(lordo));
	ajaxObjects[ajaxIndex].setVar('netto',parseFloat(netto));
	ajaxObjects[ajaxIndex].onCompletion = function(){ Shopping_showList(ajaxIndex); };	// Specify function that will be executed after file has been found
	ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function		

}

function Shopping_RemoveFromCart(prod)
{
	var ajaxIndex = ajaxObjects.length;
	ajaxObjects[ajaxIndex] = newAjaxSession(ajaxIndex, ShoppingId, 'removecart')
	ajaxObjects[ajaxIndex].requestFile = ShoppingServerPage;
	ajaxObjects[ajaxIndex].isBookmark = false;
	ajaxObjects[ajaxIndex].setVar('removecart','*');
	ajaxObjects[ajaxIndex].setVar('prodotto',prod);
	ajaxObjects[ajaxIndex].onCompletion = function(){ Shopping_showList(ajaxIndex); };	// Specify function that will be executed after file has been found
	ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function		

}
function Shopping_initAjax(modo, pagina)
{
 	//LoadStyle("Modules/Shopping/Ajax/style.css","Shopping");
	if (ShoppingLoaded) {
		Shopping_listAjax();
		return;
	}

    if (modo == "null" || typeof(modo) == "undefined") modo = "list";
    if (pagina == "null" || typeof(pagina) == "undefined") pagina  = "1";


    ShoppingModo = modo;  
    ShoppingPagina = pagina; 

	var ajaxIndex = ajaxObjects.length;
	ajaxObjects[ajaxIndex] = newAjaxSession(ajaxIndex, ShoppingId, 'init')
	ajaxObjects[ajaxIndex].requestFile = ShoppingServerPage;
	ajaxObjects[ajaxIndex].isBookmark = false;
	ajaxObjects[ajaxIndex].setVar('init',' ');
	ajaxObjects[ajaxIndex].onCompletion = function(){ Shopping_init(ajaxIndex); };	// Specify function that will be executed after file has been found
	ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function		
}

function Shopping_formAjax(id)
{
	var ajaxIndex = ajaxObjects.length;
	ajaxObjects[ajaxIndex] = newAjaxSession(ajaxIndex, ShoppingId, 'form')
	ajaxObjects[ajaxIndex].requestFile = ShoppingServerPage;
	ajaxObjects[ajaxIndex].isBookmark = false;
	ajaxObjects[ajaxIndex].setVar('form', id);
	ajaxObjects[ajaxIndex].onCompletion = function(){ Shopping_showForm(ajaxIndex); };	// Specify function that will be executed after file has been found
	ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function		
}


function Shopping_listAjax()
{
	var ajaxIndex = ajaxObjects.length;
	ajaxObjects[ajaxIndex] = newAjaxSession(ajaxIndex, ShoppingId, 'list')
	ajaxObjects[ajaxIndex].requestFile = ShoppingServerPage;
	ajaxObjects[ajaxIndex].isBookmark = false;
	ajaxObjects[ajaxIndex].setVar('list',ShoppingModo);
	ajaxObjects[ajaxIndex].setVar('pagina',ShoppingPagina);
	ajaxObjects[ajaxIndex].onCompletion = function(){ Shopping_showList(ajaxIndex); };	// Specify function that will be executed after file has been found
	ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function		
}

function Shopping_ExecuteScript(div)
{
	// execute script
   	var x = div.getElementsByTagName("script");    
   	for( var i=0; i < x.length; i++) {   
      	eval(x[i].text);   
	}   

}

