YAHOO.namespace("configurator.demo");

var cbPrilines;
var cbBrilines;
var cbAnalines;

var result;
var resultIva;
var resultTime;

var lineeDisp;
var lineeDispErr;

var dispAnalogLines = 0;

var hws = new Array(
			{},
			{ id:1, title:'Intel Celeron'		, picture:'hw1.jpg', price: 400, delivery: 1, sel: false,
			  infos:['<b>Intel Celeron 3Ghz</b>',
			  		 '1Gb Ram DDRII','Hard Disk 300Gb' ,
			  		 '24Mb L1 Chache'] },
			{ id:2, title:'Intel Opteron'		, picture:'hw2.jpg', price: 450, delivery: 1, sel: false,
			  infos:['<b>Intel opteron 3Ghz</b>',
			  	     '2Gb Ram DDRII','Hard Disk 500Gb',
			  	     '24Mb L1 Chache'] },
			{ id:3, title:'RAC Intel Celeron'	, picture:'hw3.jpg', price: 600, delivery: 1, sel: false,
			  infos:['<b>RAC Intel opteron 3Ghz</b>',
			  		 '2Gb Ram DDRI','Hard Disk 500Gb', 
			  		 '24Mb L1 Chache'] },
			{ id:4, title:'RAC Intel Opteron'	, picture:'hw4.jpg', price: 700, delivery: 1, sel: false,
			  infos:['<b>RAC Intel pteron 3Ghz</b>' ,
			  		 '2Gb Ram DDRII','Hard Disk 500Gb', 
			  		 '24Mb L1 Chache'] }
		  );

var oss = new Array(
			{},
			{ id:1, title:'Ubuntu', picture:'so1.jpg', visible: true, price: 0, delivery: 0, sel: false,
			  infos:["<b>Ubuntu</b>",
			  		 "e' un sistema operativo libero e gratuito basato su GNU/Linux,", 
			         "che unisce stabilita', sicurezza e facilità di utilizzo.",
			         "E' perfetto per computer portatili, desktop e server e fornisce applicazioni adatte ad ogni esigenza,", 
			         "per l'uso in casa, a scuola o a lavoro."] },
			{ id:2, title:'Debian', picture:'so2.jpg', visible: true, price: 0, delivery: 0, sel: false,
			  infos:["<b>Debian</b>",
			  		 "e' un sistema operativo (OS) libero (free) per il tuo computer.", 
			         "Un sistema operativo e' l’insieme dei programmi di base ed utilità",
			  		 "che fanno funzionare il tuo computer.", 
			  		 "Debian utilizza Linux come kernel (la parte centrale di un sistema operativo),", 
			  		 "ma molti dei programmi di utilità vengono dal GNU project; per questo usiamo il nome GNU/Linux."] },
			{ id:3, title:'Fedora', picture:'so3.jpg', visible: true, price: 0, delivery: 0, sel: false,
			  infos:["<b>Fedora</b>", 
			  		 "e' un sistema operativo basato su Linux che presenta", 
			  		 "gli ultimissimi software liberi ed open source.",
			  		 "L'uso, la modifica e la distribuzione di Fedora è sempre libero per chiunque."] }
		  );

var cards = new Array(
			 {},

			 {id:1, title:'Digium TE122P', visible: true, picture: 'card1.jpg', lines: 30, price: 350, delivery: 1, sel: false,
			  infos: ["<b>Digium TE122P</b>",
			   		  "The Wildcard TE122P is a single span,", 
			   		  "selectable T1 (24-channel), E1 (32-channel) or J1 (24-channel) card.",
			  	      "The card utilizes Digium's VoiceBus™ technology.", 
			  	      "VoiceBus technology allows the TE122P to use an industry standard bus-mastering PCI interface,", 
			  	      "as found in millions of PCs worldwide, to maximize system compatibility and eliminate system conflicts."] },

			 {id:2, title:'Sangoma A101', visible: true, picture: 'card2.jpg', lines: 30, price: 350, delivery: 1, sel: false,
			  infos: ["<b>Sangoma A101</b>",
			   		  "Scheda per un flusso primario PRI T1/E1. Pieno supporto per sistemi Asterisk.",
			   		  "Le schede A101/A102/A104 di Sangoma rappresentano la miglior soluzione",
			   		  "per il supporto di flussi voce e dati su linee T1 ed E1."] },

			 {id:3, title:'A101-X', visible: true, picture: 'card3.jpg', lines: 30, price: 400, delivery: 1, sel: false,
			  infos: ["<b>A101-X</b>",
			   		  "La prima scheda a porta singola T1/E1/J1 proposta dal settore a prezzo conveniente,",
			   		  "compatibile con hardware Telco-grade per la soppressione",
			   		  "dell’eco—pensata come supporto vocale ottimizzato per sistemi più piccoli."] },			   		  

			 {id:4,	title:'Digium TE205P', visible: true, picture: 'card4.jpg', lines: 60, price: 550, delivery: 2,
			  infos: ["<b>Digium TE205P</b>", 
			  		  "La scheda TE205P per 2 flussi primari (2 PRI) puo' essere utilizzata in modalitа E1 o T1", 
			  		  "(selezionabile per ogni card o per singola porta).", 
			  		  "E' possibile quindi gestire entrambi i segnali in una singola scheda."] },

			 {id:5,	title:'TE405P', visible: true, picture: 'card5.jpg', lines: 60, price: 900, delivery: 2, sel: false,
			  infos: ["<b>Sangoma A102D</b>",
			  		  "Scheda per due flussi primari PRI T1/E1. Pieno supporto per sistemi Asterisk.",
			  		  "Le schede A101/A102/A104 di Sangoma rappresentano la miglior soluzione per il supporto di flussi voce e dati su linee T1 ed E1.",
					  "La scheda Sangoma A102: 2 porte T1/E1 e J1 ottimizzate per voce e dati con hardware Telcograde per la soppressione dell’eco."] },

			 {id:6,	title:'Sangoma A102DX', visible: true, picture: 'card6.jpg', lines: 60, price: 1000, delivery: 1, sel: false,
			  infos: ["<b>Sangoma A102DX</b>",
			  		  "Scheda per due flussi primari PRI T1/E1. Pieno supporto per sistemi Asterisk.", 
			  		  "Le schede A101/A102/A104 di Sangoma rappresentano la miglior soluzione per il supporto di flussi voce e dati su linee T1 ed E1.", 
			  		  "La scheda Sangoma A102: 2 porte T1/E1 e J1 ottimizzate per voce e dati con hardware Telcograde per la soppressione dell’eco."] },

			 {id:7,	title:'Digium TE405P', visible: true, picture: 'card7.jpg', lines: 120, price: 1500, delivery: 1, sel: false,
			  infos: ["<b>Digium TE405P</b>",
			  		  "La scheda TE405P puo' essere utilizzata in modalitа E1 o T1", 
			  		  "(selezionabile per ogni card o per singola porta).", 
			  		  "E' possibile quindi gestire entrambi i segnali in una singola scheda."] },
			  		  
			 {id:8,	title:'Sangoma A104DX', visible: true, picture: 'card7.jpg', lines: 120, price: 1600, delivery: 1, sel: false,
			  infos: ["<b>Sangoma A104DX</b>",
			  		  "4 flussi primari (4 PRI) puт essere utilizzata in modalitа E1 o T1 (selezionabile per ogni card o per singola porta).", 
			  		  "E' possibile quindi gestire entrambi i segnali in una singola scheda.",		
			  		  "Inoltre con il nuovo bus ci sono significativi miglioramenti nelle performance rispetto alle schede precedenti."] }
			);
			
var icards = new Array(
			 {},
			 {id:1, title:'Digum TDM410', visible: true, picture: 'icard1.jpg', lines: 4, price: 350, delivery: 1, sel: false,
			  infos: ["<b>Digium TE122P</b>",
			   		  "The Digium® TDM410 is a half-length PCI 2.2-compliant modular gateway card",
			   		  "for connecting analog telephone stations and analog POTS lines through a PC.", 
			   		  "It supports a combination of up to four station or trunk modules for a total of 4 lines."] },

			 {id:2, title:'Digium TDM800P', visible: true, picture: 'icard2.jpg', lines: 8, price: 200, delivery: 1, sel: false,
			  infos: ["<b>Digium TDM800P</b>",
			   		  "Scheda per un flusso primario PRI T1/E1. Pieno supporto per sistemi Asterisk.",
			   		  "Le schede A101/A102/A104 di Sangoma rappresentano la miglior soluzione",
			   		  "per il supporto di flussi voce e dati su linee T1 ed E1."] },

			 {id:3, title:'Digium TDM2400P', visible: true, picture: 'icard3.jpg', lines: 24, price: 300, delivery: 1, sel: false,
			  infos: ["<b>Digium TDM2400P</b>", 
			  		  "fino a 24 fra telefoni analogici e linee urbane ad Asterisk.Usando il software della Digium,", 
			  		  "Asterisk PBX e un PC standard un utente puт creare un SOHO (Small Office Home Office),", 
			  		  "un centralino privato, che include tutte le sofisticate caratteristiche di una piattaforma PBX/Voicemail."] }
			 );
			 
var bris  = new Array(
			 {},
			 {id:1,	title:'Sangoma A500BRI', visible: true, picture: 'bri1.jpg', price: 110, lines: 4, delivery: 1, sel: false, sel: false,
			  infos: ["<b>Sangoma A500BRI</b>",
			  		  "Sangoma ha costruito il suo business sulla creazione di hardware che funziona sempre e al primo colpo.",
			  		  "Ci siamo dedicati alla produzione di soluzioni BRI effi cienti.",
					  "La scheda interfaccia Sangoma A500 S/T BRI fornisce una qualità audio superiore e scalabilità.",
					  "Può espandersi da 2 a 24 porte di BRI con opzionale Octasic™ Telco-grade, per la soppressione dell’eco nell’hardware."] },

			 {id:2,	title:'Open Vox B400E', visible: true, picture: 'bri2.jpg', price: 250, lines: 8, delivery: 1, sel: false, sel: false,
			  infos: ["<b>Open Vox B400E</b>",
			  		  "B400E is a PCI Express 1.0 card supporting 4 BRI S/T interfaces.",
			  		  "NT/TE mode can be independently configured on each of the 4 ports.",
			  		  "It can be used to build Asterisk based systems such as ISDN PBX and VOIP gateway. "] },

			 {id:3,	title:'Digium Wildcard B410P', visible: true, picture: 'bri3.jpg', lines: 8, price: 400, delivery: 2, sel: false, sel: false,
			  infos: ["<b>Digium Wildcard B410P</b>",
			  		  "La scheda B410P half-length, full-height universale 3.3V e 5.0V 32-bit PCI 2.2 card, implementa quattro interfaccie BRI S/T.", 
			  		  "Ognuna di queste quattro porte della B410p può essere indipendentemente configurata in modalitа TE o NT,",
			  		  "con l'opzionale modulo PWR400M per fornire alimentazione a telefoni ISDN collegati."] }
			);

var hss  = new Array(
			 {},
			 {id:1,	title:'SupraPlus', visible: true, picture: 'hs1.jpg', price: 110, delivery: 1, sel: false, sel: false,
			  infos: ["<b>SupraPlus</b>",
			  		  "Cuffia biaurale ad archetto con microfono a cancellazione di rumore.",
					  "SupraPlus è disponibile in versione monoauricolare e biauricolare,", 
					  "con possibilità di scelta tra le esclusive tecnologie Plantronics con tubo vocale o con microfono a cancellazione di rumore.", 
					  "Quindi esiste sicuramente un modello adatto a ogni esigenza di comunicazione."] },

			 {id:2,	title:'Sennheiser SH330', visible: true, picture: 'hs2.jpg', price: 80, delivery: 1, sel: false, sel: false,
			  infos: ["<b>Sennheiser SH330</b>",
			  		  "Over the head, monoaural headset supplied with noise cancelling microphone and Activegard protection technology.", 
			  		  "The SH 330 is a lightweight, all purpose monaural headset ideal for longer conversations.", 
			  		  "It is the stylish and highquality solution for users who value great comfort and top speech quality in any professional situation."] },

			 {id:3,	title:'Sennheiser PC131', visible: true, picture: 'hs3.jpg', price: 50, delivery: 2, sel: false, sel: false,
			  infos: ["<b>Sennheiser PC131</b>",
			  		  "La Sennheiser PC131 è una cuffia microfonica stereo multimediale.", 
			  		  "Qualita' e robustezza all'interno di un design classico la rendono uno tra i prodotti più richiesti;", 
			  		  "La cura dei dettagli comprende anche un archetto sdoppiato che garantisce un' assoluta comodità anche in caso di uso prolungato."] }
			);

var phones = new Array(
			 {},
			 {id:1,	title:'Siemens optiPoint 410', visible: true, picture: 'phone1.jpg', price: 180, delivery: 1, sel: false,
			  infos: ["<b>Siemens optiPoint 41</b>",
			  		  "The optiPoint 410 economy plus model offers even more flexibility.", 
			  		  "It has a 10/100 Base-T mini-switch and a headset connection,", 
			  		  "it is perfectly equipped for particularly individual use."] },

			 {id:2,	title:'Siemens optiPoint 420 Entry', visible: true, picture: 'phone2.jpg', price: 80, delivery: 2, sel: false,
			  infos: ["<b>Siemens optiPoint 420 Entry</b>",
			  		  "The move into VoIP is especially cost effective with optiPoint 410 entry.", 
			  		  "The perfect piece of equipment for all back office areas, for example, and wherever only the basic functions are required,", 
			  		  "such as in storerooms, workshops, hospitals or reception areas."] },
			  		  

			 {id:3,	title:'Siemens optiPoint 420 Advanced', visible: true, picture: 'phone3.jpg', price: 320, delivery: 1, sel: false,
			  infos: ["<b>Siemens optiPoint 420 Advanced</b>",
			  		  "The Siemens optiPoint 420 advance is a modular multi line IP speakerphone that provides", 
			  		  "high fidelity voice quality via the integrated G.722 wideband codec.", 
			  		  "It comes with a backlit alphanumeric 4x24 display and with optiGuide for additional softkey functionality.", 
			  		  "Select the right cord for the telephone system from the compatible products below."] },

			 {id:4,	title:'Telefono SPA921', visible: true, picture: 'phone4.jpg', price: 65, delivery: 1, sel: false,
			  infos: ["<b>Telefono SPA921</b>",
			  		  "Stylish and functional in design, the SPA921 VoIP Phone is ideal for a residence or business", 
			  		  "using a hosted IP telephony service, an IP PBX, or a large scale IP Centrex deployment.",
			  		  "The SPA921 leverages industry leading VoIP technology from Linksys to deliver an upgradeable", 
			  		  "high quality IP Phone that is unparalleled in features, value, and support."] }
			);

var sips = new Array(
			 {},
			 {id:1,	title:'SNOM 320', visible: true, picture: 'sip1.jpg', price: 150, delivery: 1, sel: false,
			  infos: ["<b>SNOM 320</b>",
			  		  "Ideale per l'uso in ufficio. lo snom 320 e' un apparecchio SIP con un ottimo rapporto qualitа/prezzo.",
					  "Tra le principali caratteristiche: speakerphone full-duplex.", 
					  "3 way call. display LCD semi-grafico 2x24.",
					  "interfaccia utente a menщ e 12 tasti programmabili."] },

			 {id:2,	title:'SNOM  370', visible: true, picture: 'sip2.jpg', price: 220, delivery: 1, sel: false,
			  infos: ["<b>SNOM  370</b>",
			  		  "High audio quality, ease of use, security and interoperability make the snom 370", 
			  		  "highly suitable for SMEs, home offices, private users or ISP applications.", 
			  		  "The snom 370 is the VoIP phone for the business user who needs immediate access to all of their important information."] },

			 {id:3,	title:'SNOM 360', visible: true, picture: 'sip3.jpg', price: 180, delivery: 1, sel: false,
			  infos: ["<b>SNOM 360</b>",
			  		  "Lo Snom 360 definisce un nuovo standard riguardante la flessibilitiа e la interoperabilitiа.", 
			  		  "E' infatti compatibile con ogni Gateway o Gatekeeper VoIp basati sullo standard SIP che lo rende", 
			  		  "facilmente integrabile in qualsiasi struttura LAN/WAN."] }
			);


var services = new Array(
			 {},
			 {id:1,	title:'Installazione Asterisk', visible: true, picture: 'service1.jpg', price: 100, delivery: 2, sel: false,
			  infos: ["<b>Installazione Asterisk</b>",
			  		  "Installazione e configurazione del software PBX Asterisk con le predispozioni scelte dall'utente"], selected: null },			

			 {id:2,	title:'Garanzia per 3 anni', visible: true, picture: 'service2.jpg', price: 1000, delivery: 1, sel: false,
			  infos: ["<b>Garanzia per 3 anni</b>",
			  		  "Garanzia per 3 anni che compre disfunzioni sull'hardware dell'impianto fornito."] }

			);


for (i=1; i<services.length; i++) {

	services[i].selected = function() {
		this.sel = !this.sel;
		YAHOO.util.Dom.get('serviceCb'+this.id).checked = this.sel;
		this.save();
	}

	services[i].showInfo = function() {
		showInfoDialog(this.infos, this.picture);
	}

	services[i].save = function() {
		makeResults();
	}
	
	services[i].title = '';
	
}

for (i=1; i<oss.length; i++) {

	oss[i].hide = function() {
		if (this.visible) {
			var li = YAHOO.util.Dom.get('osli'+this.id);
			YAHOO.util.Dom.removeClass	(li, 'contentList_li');
			YAHOO.util.Dom.removeClass	(li, 'contentListRight_li');
			YAHOO.util.Dom.addClass		(li, 'contentListDisabledRight');

			this.visible = !this.visible;
			YAHOO.util.Dom.get	('osCb'+this.id).disabled = true;
		}
	}

	oss[i].show = function() {
		if (!this.visible) {
			var li = YAHOO.util.Dom.get('osli'+this.id);
			YAHOO.util.Dom.addClass		(li, 'contentList_li');
			YAHOO.util.Dom.addClass		(li, 'contentListRight_li');
			YAHOO.util.Dom.removeClass	(li, 'contentListDisabledRight');

			this.visible = !this.visible;
			YAHOO.util.Dom.get	('osCb'+this.id).disabled = false;
		}
	}

	oss[i].selected = function() {
		if (this.visible) {
			var cb 		= YAHOO.util.Dom.get('osCb'+this.id);
			this.sel 	= !this.sel;

			for (i=0; i<oss.length; i++)
				if (oss[i].id != this.id)
					oss[i].sel = false;

			this.save();
		}
	}

	oss[i].showInfo = function() {
		showInfoDialog(this.infos, this.picture);		
	}
	
	oss[i].save = function() {
		makeResults();
	}	
	
}


for (i=1; i<hws.length; i++) {

	hws[i].selected = function() {
		var cb 		= YAHOO.util.Dom.get('hwCb'+this.id);
		this.sel 	= !this.sel;

		for (i=0; i<hws.length; i++)
			if (hws[i].id != this.id)
				hws[i].sel = false;

		this.save();
	}

	hws[i].showInfo = function() {
		showInfoDialog(this.infos, this.picture);
	}

	hws[i].save = function() {
		makeResults();
	}
	
}

for (i=1; i<hss.length; i++) {
	hss[i].selected = function() {

		this.sel = !this.sel;
		YAHOO.util.Dom.get('hsCb'+this.id).checked = this.sel;

		if (this.sel) {
			YAHOO.util.Dom.setStyle	('hsSpan'+this.id, 'display', 'block');
			YAHOO.util.Dom.get		('hsAmount'+this.id).focus();
		} else {
			YAHOO.util.Dom.setStyle	('hsSpan'+this.id, 'display', 'none');
		}		
		this.save();

	}
	
	hss[i].showInfo = function() {
		showInfoDialog	(this.infos, this.picture);
	}
	
	hss[i].getAmount = function() {
		return YAHOO.util.Dom.get('hsAmount'+this.id).value;
	}
	
	hss[i].setAmount = function(value) {
		YAHOO.util.Dom.get('hsAmount'+this.id).value = value;
	}
	
	hss[i].save = function() {
		var am = YAHOO.util.Dom.get('hsAmount'+this.id)	
		am.value = getIntValue(am);
		makeResults();
	}	
}

for (i=1; i<phones.length; i++) {
	phones[i].selected = function() {

		this.sel = !this.sel;
		YAHOO.util.Dom.get('phoneCb'+this.id).checked = this.sel;

		if (this.sel) {
			YAHOO.util.Dom.setStyle	('phoneSpan'+this.id, 'display', 'block');
			YAHOO.util.Dom.get		('phoneAmount'+this.id).focus();
		} else {
			YAHOO.util.Dom.setStyle	('phoneSpan'+this.id, 'display', 'none');
		}		
		
		this.save();
	}
	
	phones[i].showInfo = function() {
		showInfoDialog	(this.infos, this.picture);
	}
	
	phones[i].getAmount = function() {
		return YAHOO.util.Dom.get('phoneAmount'+this.id).value;
	}
	
	phones[i].setAmount = function(value) {
		YAHOO.util.Dom.get('phoneAmount'+this.id).value = value;
	}
	
	phones[i].save = function() {
		var am = YAHOO.util.Dom.get('phoneAmount'+this.id)	
		am.value = getIntValue(am);
		makeResults();
	}
		
}

for (i=1; i<sips.length; i++) {
	sips[i].selected = function() {

		this.sel = !this.sel;
		YAHOO.util.Dom.get('sipCb'+this.id).checked = this.sel;

		if (this.sel) {
			YAHOO.util.Dom.setStyle	('sipSpan'+this.id, 'display', 'block');
			YAHOO.util.Dom.get		('sipAmount'+this.id).focus();
		} else {
			YAHOO.util.Dom.setStyle	('sipSpan'+this.id, 'display', 'none');
		}
		
		this.save();		
	}
	
	sips[i].showInfo = function() {
		showInfoDialog(this.infos, this.picture);
	}
	
	sips[i].getAmount = function() {
		return YAHOO.util.Dom.get('sipAmount'+this.id).value;
	}
	
	sips[i].setAmount = function(value) {
		YAHOO.util.Dom.get('sipAmount'+this.id).value = value;
	}
	
	sips[i].save = function() {
		var am = YAHOO.util.Dom.get('sipAmount'+this.id)	
		am.value = getIntValue(am);
		makeResults();
	}
		
}

for (i=1; i<bris.length; i++) {

	bris[i]._selected = function(focus) {
		this.sel = !this.sel;
		YAHOO.util.Dom.get('briCb'+this.id).checked = this.sel;

		if (this.sel) {
			YAHOO.util.Dom.setStyle	('briSpan'+this.id, 'display', 'block');
			if (focus)
				YAHOO.util.Dom.get('briAmount'+this.id).focus();
		} else {
			YAHOO.util.Dom.setStyle	('briSpan'+this.id, 'display', 'none');
		}
		
		this.save();
	}
	
	bris[i].selected = function() {
		this._selected(true);
	}

	bris[i].selectedWithoutFocus = function() {
		this._selected(false);
	}
	
	bris[i].deSelected = function() {
		this.sel = false;
		YAHOO.util.Dom.get('briCb'+this.id).checked = false;
		YAHOO.util.Dom.setStyle	('briSpan'+this.id, 'display', 'none');
	}
	
	bris[i].showInfo = function() {
		showInfoDialog(this.infos, this.picture);
	}
	
	bris[i].hide = function() {
		if (this.visible) {
			var li = YAHOO.util.Dom.get('brili'+this.id);
					
			if (this.id < 5) {
				YAHOO.util.Dom.removeClass	(li, 'contentList_li');
				YAHOO.util.Dom.removeClass	(li, 'contentListLeft_li');
				YAHOO.util.Dom.addClass		(li, 'contentListDisabledLeft');			
			} else {
				YAHOO.util.Dom.removeClass 	(li, 'contentList_li');
				YAHOO.util.Dom.removeClass 	(li, 'contentListRight_li');
				YAHOO.util.Dom.addClass	   	(li, 'contentListDisabledRight');
			}		
		

			var cb = YAHOO.util.Dom.get('briCb'+this.id);
			cb.checked	= false;
			cb.disabled = true;	
			this.visible = !this.visible;
			this.deSelected();
		}
	}
	
	bris[i].show = function() {
		if (!this.visible) {
			var li = YAHOO.util.Dom.get('brili'+this.id);
			
			if (this.id < 5) {
				YAHOO.util.Dom.addClass		(li, 'contentList_li');
				YAHOO.util.Dom.addClass		(li, 'contentListLeft_li');
				YAHOO.util.Dom.removeClass	(li, 'contentListDisabledLeft');			
			} else {
				YAHOO.util.Dom.addClass		(li, 'contentList_li');
				YAHOO.util.Dom.addClass		(li, 'contentListRight_li');
				YAHOO.util.Dom.removeClass	(li, 'contentListDisabledRight');			
			}

			YAHOO.util.Dom.get('briCb'+this.id).disabled = false;
			this.visible = !this.visible;
		}
	}

	bris[i].getAmount = function() {
		return YAHOO.util.Dom.get('briAmount'+this.id).value;
	}
	
	bris[i].setAmount = function(value) {
		YAHOO.util.Dom.get('briAmount'+this.id).value = value;
	}
	
	bris[i].save = function() {
		var am = YAHOO.util.Dom.get('briAmount'+this.id)	
		am.value = getIntValue(am);
		makeResults();
	}	
		
}

for (i=1; i<icards.length; i++) {

	icards[i]._selected = function(focus) {
		this.sel = !this.sel;
		YAHOO.util.Dom.get('icardCb'+this.id).checked = this.sel;

		if (this.sel) {
			YAHOO.util.Dom.setStyle	('icardSpan'+this.id, 'display', 'block');
			if (focus)
				YAHOO.util.Dom.get		('icardAmount'+this.id).focus();
		} else {
			YAHOO.util.Dom.setStyle	('icardSpan'+this.id, 'display', 'none');
		}
		this.save();
	}

	icards[i].selectedWithoutFocus = function() {
		this._selected(false);
	}
	
	icards[i].selected = function() {
		this._selected(true);
	}

	icards[i].deSelected = function() {
		this.sel = false;
		YAHOO.util.Dom.get('icardCb'+this.id).checked = false;
		YAHOO.util.Dom.setStyle	('icardSpan'+this.id, 'display', 'none');
	}

	icards[i].showInfo = function() {
		showInfoDialog(this.infos, this.picture);
	}
	
	icards[i].hide = function() {
		if (this.visible) {
			var li = YAHOO.util.Dom.get('icardli'+this.id);
					
			if (this.id < 5) {
				YAHOO.util.Dom.removeClass	(li, 'contentList_li');
				YAHOO.util.Dom.removeClass	(li, 'contentListLeft_li');
				YAHOO.util.Dom.addClass		(li, 'contentListDisabledLeft');			
			} else {
				YAHOO.util.Dom.removeClass 	(li, 'contentList_li');
				YAHOO.util.Dom.removeClass 	(li, 'contentListRight_li');
				YAHOO.util.Dom.addClass	   	(li, 'contentListDisabledRight');
			}		
		

			var cb = YAHOO.util.Dom.get('icardCb'+this.id);
			cb.checked	= false;
			cb.disabled = true;
			this.visible = !this.visible;
			this.deSelected();
		}
	}
	
	icards[i].show = function() {
		if (!this.visible) {
			var li = YAHOO.util.Dom.get('icardli'+this.id);
			
			if (this.id < 5) {
				YAHOO.util.Dom.addClass		(li, 'contentList_li');
				YAHOO.util.Dom.addClass		(li, 'contentListLeft_li');
				YAHOO.util.Dom.removeClass	(li, 'contentListDisabledLeft');			
			} else {
				YAHOO.util.Dom.addClass		(li, 'contentList_li');
				YAHOO.util.Dom.addClass		(li, 'contentListRight_li');
				YAHOO.util.Dom.removeClass	(li, 'contentListDisabledRight');			
			}

			YAHOO.util.Dom.get('icardCb'+this.id).disabled = false;

			this.visible = !this.visible;
		}
	}	
	
	icards[i].getAmount = function() {
		return YAHOO.util.Dom.get('icardAmount'+this.id).value;
	}
	
	icards[i].setAmount = function(value) {
		YAHOO.util.Dom.get('icardAmount'+this.id).value = value;
		this.save();
	}
	
	icards[i].save = function() {
		var am = YAHOO.util.Dom.get('icardAmount'+this.id)	
		am.value = getIntValue(am);	
		makeResults();
	}

}

for (i=1; i<cards.length; i++) {

	cards[i].hide = function() {
		if (this.visible) {
			var li = YAHOO.util.Dom.get('cardli'+this.id);
					
			if (this.id < 5) {
				YAHOO.util.Dom.removeClass	(li, 'contentList_li');
				YAHOO.util.Dom.removeClass	(li, 'contentListLeft_li');
				YAHOO.util.Dom.addClass		(li, 'contentListDisabledLeft');			
			} else {
				YAHOO.util.Dom.removeClass 	(li, 'contentList_li');
				YAHOO.util.Dom.removeClass 	(li, 'contentListRight_li');
				YAHOO.util.Dom.addClass	   	(li, 'contentListDisabledRight');
			}		
		
			var cb = YAHOO.util.Dom.get('cardCb'+this.id);
			cb.checked	= false;
			cb.disabled = true;	
			this.visible = !this.visible;
			this.deSelected();
		}
	}
	
	cards[i].show = function() {
		if (!this.visible) {
			var li = YAHOO.util.Dom.get('cardli'+this.id);
			
			if (this.id < 5) {
				YAHOO.util.Dom.addClass		(li, 'contentList_li');
				YAHOO.util.Dom.addClass		(li, 'contentListLeft_li');
				YAHOO.util.Dom.removeClass	(li, 'contentListDisabledLeft');			
			} else {
				YAHOO.util.Dom.addClass		(li, 'contentList_li');
				YAHOO.util.Dom.addClass		(li, 'contentListRight_li');
				YAHOO.util.Dom.removeClass	(li, 'contentListDisabledRight');			
			}

			YAHOO.util.Dom.get('cardCb'+this.id).disabled = false;

			this.visible = !this.visible;
		}
	}

	cards[i].selected = function() {
		this._selected(true);
	}

	cards[i].selectedWithoutFocus = function() {
		this._selected(false);
	}

	cards[i]._selected = function(focus) {
		if (this.visible) {	
			this.sel = !this.sel;
			YAHOO.util.Dom.get('cardCb'+this.id).checked = this.sel;
	
			if (this.sel) {
				YAHOO.util.Dom.setStyle	('cardSpan'+this.id, 'display', 'block');
				if (focus)
					YAHOO.util.Dom.get('cardAmount'+this.id).focus();
			} else {
				YAHOO.util.Dom.setStyle	('cardSpan'+this.id, 'display', 'none');
			}
			this.save();			
		}
	}

	cards[i].deSelected = function() {
		this.sel = false;
		YAHOO.util.Dom.get('cardCb'+this.id).checked = false;
		YAHOO.util.Dom.setStyle	('cardSpan'+this.id, 'display', 'none');
		this.save();
	}
	
	cards[i].getAmount = function() {
		return YAHOO.util.Dom.get('cardAmount'+this.id).value;
	}
	
	cards[i].setAmount = function(value) {
		YAHOO.util.Dom.get('cardAmount'+this.id).value = value;
		this.save();
	}
	
	cards[i].showInfo = function() {
		showInfoDialog(this.infos, this.picture);		
	}
	
	cards[i].save = function() {
		var am = YAHOO.util.Dom.get('cardAmount'+this.id)	
		am.value = getIntValue(am);	
		makeResults();
	}
	
}

function getIntValue(elem) {
	if (IsNumeric(elem.value)) {
		return elem.value;
	} else {
		return 0;
	}
}

function IsNumeric(sText) {
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) {
         IsNumber = false;
         }
      }
   return IsNumber;
}


function makeResults() {
	var tot 	= 0;
	var deliv 	= 0;
	
	for (i=0; i<hws.length; i++) {
		if (hws[i].sel) {
			tot += hws[i].price;
			if (hws[i].delivery > deliv) 
				deliv = hws[i].delivery;
		}
	}
	
	for (i=0; i<cards.length; i++) {
		if (cards[i].sel) {
			tot += (cards[i].price * cards[i].getAmount());
			if (cards[i].delivery > deliv)
				deliv = cards[i].delivery;
		}
	}
	
	for (i=0; i<icards.length; i++) {
		if (icards[i].sel) {
			tot += (icards[i].price * icards[i].getAmount());
			if (icards[i].delivery > deliv)
				deliv = icards[i].delivery;
		}
	}		

	for (i=0; i<bris.length; i++) {
		if (bris[i].sel) {
			tot += (bris[i].price * bris[i].getAmount());
			if (bris[i].delivery > deliv)
				deliv = bris[i].delivery;
		}
	}		

	for (i=0; i<hss.length; i++) {
		if (hss[i].sel) {
			tot += (hss[i].price * hss[i].getAmount());
			if (hss[i].delivery > deliv)
				deliv = hss[i].delivery;
		}
	}		

	for (i=0; i<phones.length; i++) {
		if (phones[i].sel) {
			tot += (phones[i].price * phones[i].getAmount());
			if (phones[i].delivery > deliv)
				deliv = phones[i].delivery;
		}
	}		

	for (i=0; i<sips.length; i++) {
		if (sips[i].sel) {
			tot += (sips[i].price * sips[i].getAmount());
			if (sips[i].delivery > deliv)
				deliv = sips[i].delivery;
		}
	}

	for (i=0; i<services.length; i++) {
		if (services[i].sel) {
			tot += services[i].price;
			if (services[i].delivery > deliv)
				deliv = services[i].delivery;
		}
	}

	if (tot != 0) {
		result.innerHTML 	= tot + '€';
		var iva = (tot / 100) * 20;				
		resultIva.innerHTML	= (tot+iva) + '€';
	} else {
		result.innerHTML 	= '';
		resultIva.innerHTML	= '';	
	}
	
	if (deliv == 0) {
		resultTime.innerHTML = '';		
	} else if (deliv>1) {
		resultTime.innerHTML = deliv + ' settimane';
	} else {
		resultTime.innerHTML = deliv + ' settimana';
	}

}

YAHOO.configurator.demo.hws = hws;
YAHOO.configurator.demo.oss = oss;
YAHOO.configurator.demo.cards = cards;
YAHOO.configurator.demo.icards = icards;
YAHOO.configurator.demo.bris = bris;
YAHOO.configurator.demo.hss = hss;
YAHOO.configurator.demo.phones = phones;
YAHOO.configurator.demo.sips = sips;
YAHOO.configurator.demo.services = services;


