setCNETAssetBaseHref('/inc/img/assets');
function createHome(){
	new Accordion($$('div.accorder2'), $$('div.accorded2'),{alwaysHide: false,fixedHeight: 380,display: 0});
	/*getPdtHL(0,'newHL',1);
	getPdtHL(1,'rilievoHL',1);
	getPdtHL(2,'offerteHL');
	getBrAcc(0);*/
	
	var myTabSwapper = new TabSwapper({
		tabSelector: "#myTabs li",
		clickSelector: "#myTabs li a",
		sectionSelector: "#myContent div[rel=content]",
		name: "myTabSwapper",
		smooth: true
   });

	new Accordion($$('div.vetrina_c'), $$('div.vetrina_o'),{ //ACCORDION VETRINA
		alwaysHide: false,
		fixedHeight: '210px',
		opacity: false,
		onActive: function(toggler, element){
			toggler.removeClass('dp_vetrina_box_clsb');
			toggler.addClass('dp_vetrina_box_cls');
		},
		onBackground: function(toggler, element){
			toggler.removeClass('dp_vetrina_box_cls');
			toggler.addClass('dp_vetrina_box_clsb');
		}
	});
	$$('#dp_cnt_top span').each(function(sp){
		if(sp) sp.remove();
	});
}

function getPdtHL(pid,div){ //Prodotti d'impulso
	var mode = arguments.length>2 ? arguments[2] : 0;
	var url = '../inc/ecomm.content.php?s=6&p='+pid+'&mode='+mode;
	var jsonCart = new Ajax(url,{
		method : 'get',
		evalScripts: true,
		update : $(div)
	}).request();
}

function getContent(caso,p,tipo,p2,prof){
	var indice = 0;
	var uss = [];
	uss[indice] = caso;
	indice++;
	if(!p | p == 'undefined'){
	} else {
		uss[indice] = p;
		indice++;
	}
	if(!tipo | tipo == 'undefined'){
		uss[indice] = 0;
		indice++;
	} else {
		uss[indice] = tipo;
		indice++;
	}
	if(!p2 | p2 == 'undefined') {
		p2 = '';
	} else {
		p2 = p2;
		uss[indice] = p2;
		indice++;
	}
	if(!prof | prof == 'undefined') {
		prof = 1;
		uss[indice] = 0;
		indice++;
	} else {
		prof = prof
		uss[indice] = prof;
		indice++;
	}
	var his = '';
	var a = 0;
	uss.each(function(un){
		his = his+''+un;
		if(a!=(indice-1))
			his = his+'-';
		a++
	});
	if(caso == 12){
		createHome();
	}
	var url = "../inc/ecomm.content.php?"+Object.toQueryString({'s' : caso, 'p' : p, 'tipo' : tipo, 'p2' : p2, 'prof' : prof});	
	if(caso == 10){
		var coun = 0;
		if($('vettore')){
			var vett = $('vettore').getProperty('value');
			coun++;
		}
		if($('pagamento')){
			var paga = $('pagamento').getProperty('value');
			coun++;
		}
		if(coun==2){
			url = url + '&vett='+vett+'&paga='+paga;
		} else {
			url = "../inc/ecomm.content.php?s=9";	
		}
	}
	
	if($('dp_vetrina')) $('dp_vetrina').remove();
	if($('dp_vn')){
		$('dp_vn').remove();
		$('dp_offerta').remove();
	}
	new Ajax(url,{
		autoCancel: true,
		method: 'get',
		evalScripts: true,
		update: $('dp_gbl'),
		onRequest: function(){
			goTop();
			if($('dp_gbl')){
				$('dp_gbl').setHTML('loading...');
			}
		}
	}).request();
}

function createPath2(content,titolo,prof){
	if(prof == 1){
		$$('#dp_cnt_top span').each(function(sp){
			sp.remove();
		});
	}

	$$('#dp_cnt_top span').each(function(sp){
		if(sp){
			var numero = sp.getProperty('id');
			numero = numero.substr(14).toInt();
			if(numero > prof ){
				sp.remove();
			}
		}
	});

	if($('menu_temp_path'+prof)) $('menu_temp_path'+prof).remove();
	var menu = $('menu_path').innerHTML;
	if($(titolo)) var testo = $(titolo).getText(); else  var testo = titolo;
	var arr_hash = content.split(',');
	var str_hash = '';
	arr_hash.each(function(hashin){
		str_hash = str_hash + hashin+'-';
	});
	var le = str_hash.length.toInt()-1;
	var hash2 = str_hash.substring(0,le)
	$('menu_path').empty().setHTML(menu+'<span id="menu_temp_path'+prof+'"><a href="#'+hash2+'" onclick="window.hash(\''+hash2+'\');createPath2(\''+content+'\',\''+testo+'\','+prof+');getContent('+content+');"> &#8250; '+testo+'</a></span>');
}


var find_timer = 0;
function findThis(val){
	find_timer = find_timer+1;
	setTimeout('findThisGo('+find_timer+',"'+val+'")',500);
}

function findThisGo(temp_timer,val){
	if(temp_timer == find_timer){
		find_timer = 0;
		if(val.length > 2){
			getContent('find',val,'find');
		}/* else if(val.length == 0){
			getContent('13','','1');
		}*/
	}
}

function selThis(id){
	if($(id)){
		if(id.substr(0,3)=='all'){
			$$('a.unsel').each(function(menu){
				menu.setStyles({
					'font-weight':'',
					'color' : '',
					'background':''
				});
			});
			return;
		}
		$$('a.unsel').each(function(menu){
			menu.setStyles({
				'font-weight':'',
				'color' : '',
				'background':''
			});
		});

		$(id).setStyles({
			'color': '#FFF',
			'font-weight':'bold',
			'background':'transparent url(../inc/img/menus/dpz_sx_catsel.jpg) no-repeat top center'
		});

	}
}

function getActions(action,sex,eta,price_min,price_max,prof){
	if(!sex) sex = 9;
	if(!eta) eta = 1000;
	if(!price_min) price_min = 0;
	if(!price_max) price_max = 0;
	if(!prof) prof = 1;
	var url_param = Object.toQueryString({'s' : action, 'sex' : sex, 'eta' : eta, 'price_min' : price_min, 'price_max' : price_max, 'prof' : prof});
	var url = '../inc/ecomm.content.php?'+url_param;
	if($('dp_vetrina')) $('dp_vetrina').remove();
	if($('dp_vn')) $('dp_vn').remove();
	if($('dp_offerta')) $('dp_offerta').remove();
	if(!$('dp_gbl')){
		new Element('div').setProperties({'id': 'dp_gbl'}).injectAfter('main_path');
	}
	new Ajax(url,{
		method : 'post',
		evalScripts: true,
		autoCancel : true,
		update: $('dp_gbl')
	}).request();
}

function goTop(){
	new Fx.Scroll(window).toTop();
}

function addCart(v,qty){
	window.location = '../www-dpz/index.php?action=buy&s=3&p='+v+'&qty='+qty+'&m=1';
}

function chkButt(id,ele){ //elimina il bottone acquista se si esauriscono le scorte durante la navigazione
	var url_param = Object.toQueryString({'s' : 25,'v': id});
	var url = '../inc/ecomm.content.php?'+url_param;
	$$('.loader_gif_ajax').each(function(loa){
		loa.remove();
	});
	var loader;
	var jsonCart = new Ajax(url,{
		method : 'get',
		autoCancel : true,
		onRequest: function(){
			var loaderImg = '<img src="../inc/img/ajax-loader.gif" class="loader_gif_ajax" />';
			loader = new StickyWin({
				content: loaderImg,
				relativeTo: $(ele),
				position: 'center'
			});
		},
		onComplete: function(res){
			loader.hide();
			if(res == 'true'){
				if($(ele)) $(ele).remove();
			} else if(res == 'false'){
				stop();
			}
		}
	}).request();
}


function delCart(v){
	var url = '../inc/ecomm.content.php?s=4&p='+v;
	$$('.loader_gif_ajax').each(function(loa){
		loa.remove();
	});
	var loader;
	var jsonCart = new Ajax(url,{
		method : 'get',
		evalScripts: true,
		autoCancel : true,
		onRequest: function(){
			var loaderImg = '<img src="../inc/img/ajax-loader.gif" class="loader_gif_ajax" />';
			loader = new StickyWin({
				content: loaderImg,
				relativeTo: $('cart'),
				position: 'center'
			});
		},
		onComplete: function(){
			loader.hide();
			goToCart(7);
		},
		update : $('cart')
	}).request();
}

function viewCart(){
	var url = '../inc/ecomm.content.php?s=5';
	$$('.loader_gif_ajax').each(function(loa){
		if(loa){
			loa.remove();
		}
	});
	var loader;
	var jsonCart = new Ajax(url,{
		method : 'get',
		autoCancel : true,
		evalScripts: true,
		onRequest: function(){
			var loaderImg = '<img src="../inc/img/ajax-loader.gif" class="loader_gif_ajax" />';
			loader = new StickyWin({
				content: loaderImg,
				relativeTo: $('cart'),
				position: 'center'
			});
		},
		onComplete: function(){
			loader.hide();
		},
		update : $('cart')
	}).request();
}

function bancRis(a,b,c){
	var url = '../inc/ecomm.content.php?s=22&a='+a+'&b='+b+'&c='+c;
	$$('.loader_gif_ajax').each(function(loa){
		if(loa){
			loa.remove();
		}
	});
	if($('dp_vetrina')){
		$('dp_vetrina').remove();
	}
	if($('dp_vn')){
		$('dp_vn').remove();
	}
	if($('dp_offerta')){
		$('dp_offerta').remove();
	}
	if($('dp_gbl')){
		var target =  $('dp_gbl');
	}else {
		var target = new Element('div').setProperties({'id':'dp_gbl'}).injectInside('contents');
	}
	var jsonCart = new Ajax(url,{
		method : 'get',
		evalScripts: true,
		autoCancel : true,
		onRequest: function(){
			var loaderImg = '<img id="temp_loader" src="../inc/img/ajax-loader.gif" class="loader_gif_ajax" />';
			loader = new StickyWin({
				content: loaderImg,
				relativeTo: target,
				position: 'center'
			});
		},
		onComplete: function(){
			if($('temp_loader')){
				$('temp_loader').hide();
			}
		},
		update : target
	}).request();
}

function goToCart(num){
	var id = (num == '' | num == null | num.length == 0) ? 7: num;
	var url = '../inc/ecomm.content.php?s='+id;
	$$('.loader_gif_ajax').each(function(loa){
		if(loa){
			loa.remove();
		}
	});
	if($('dp_vetrina')){
		$('dp_vetrina').remove();
	}
	if($('dp_vn')){
		$('dp_vn').remove();
	}
	if($('dp_offerta')){
		$('dp_offerta').remove();
	}
	if($('dp_gbl')){
		var target =  $('dp_gbl');
	}else {
		var target = new Element('div').setProperties({'id':'dp_gbl'}).injectInside('contents');
	}
	var jsonCart = new Ajax(url,{
		method : 'get',
		evalScripts: true,
		autoCancel : true,
		onRequest: function(){
			var loaderImg = '<img id="temp_loader" src="../inc/img/ajax-loader.gif" class="loader_gif_ajax" />';
			loader = new StickyWin({
				content: loaderImg,
				relativeTo: target,
				position: 'center'
			});
		},
		onComplete: function(){
			if($('temp_loader')){
				$('temp_loader').hide();
			}
		},
		update : target
	});
	jsonCart.cancel();
	jsonCart.request();
}

function getVectors(){
	var url = '../inc/ecomm.content.php?s=8';
	var jsonCart = new Ajax(url,{
		method : 'get',
		evalScripts: true,
		autoCancel : true,
		onRequest: function(){
			$('dp_gbl').setHTML('loading...');
		},
		update : $('dp_gbl')
	}).request();
}

function getPayments(){
	var ok = 0;
	var arr = $$('input[name=shipping]').getProperty('checked');
	arr.each(function(val){
		if(val == true){
			ok = 1;
		}
	});
	if(ok == 1){
		var url = '../inc/ecomm.content.php?s=9';
		var jsonCart = new Ajax(url,{
			method : 'get',
			evalScripts: true,
			autoCancel : true,
			onRequest: function(){
				if($('dp_gbl')){
					$('dp_gbl').setHTML('loading...');
				}
			},
			update: $('dp_gbl')
		}).request();
	} else {
		if(!$('errorMsg')){
			var err = new Element('p',{'id': 'errorMsg'}).setHTML('Devi scegliere un valore prima di continuare').injectAfter($('dp_gbl'));
		}
	}
}

function saveVector(valore){
	$('vettore').setProperty('value',valore);
}

function savePayment(valore){
	$('pagamento').setProperty('value',valore);
}

function getBrAcc(m){ //costruisce gli accordion per i brand e i prodotti correlati, se m = 1 stampa prodotti correlati
	var url_param = Object.toQueryString({'s': 11, 'msch' : m});
	var url = '../inc/ecomm.content.php?'+url_param;
	var jsonCart = new Ajax(url,{
		method : 'get',
		evalScripts: true,
		autoCancel : true,
		update : $('dp_dx_box1')
	}).request();
}

function tC(id,id2){ //Swappa le classi per i prodotti novità/in offerta
	$(id).setProperties({
		'onclick' : 'return false;'
	});
	$(id2).setProperties({
		'onclick' : 'tC(\''+id2+'\',\''+id+'\');return false;'
	});
	$('pn').toggleClass('dp_vnhead_sx');
	$('pr').toggleClass('dp_vnhead_dx');
	$('pn').toggleClass('dp_vnhead_sxsel');
	$('pr').toggleClass('dp_vnhead_dxsel');
}

/*********************/
/*Rating delle schede*/
/*********************/
var NUMBER_OF_STARS = 5;
function init_rating(vid){
	if(arguments.length>1){
		var s = arguments[1][1];
		var r = new Array();
	} else {
		var s = 'dp_star_{TIPO}1.png';
		var r = $$('div.schd_star');
	}
	r.include($('star'+vid));
	//var ratings = $('star'+vid);
	r.each(function(ratings){
		if(ratings && ratings.getElements('img').length==0){
			var rating = ratings.getText().toInt();
			ratings.empty();
			for (var j = 0; j < NUMBER_OF_STARS; j++){
				var star = document.createElement('img');
				if (rating >= 1){
					//star.setAttribute('src', '/inc/img/rating/dp_star_on.jpg');
					star.setAttribute('src', '/inc/img/rating/'+s.replace('{TIPO}','on'));
					star.className = 'on';
					rating--;
				} else if(rating == 0.5) {
					star.setAttribute('src', '/inc/img/rating/'+s.replace('{TIPO}','half'));
					star.className = 'half';
					rating = 0;
				} else {
					//star.setAttribute('src', '/inc/img/rating/dp_star_off.jpg');
					star.setAttribute('src', '/inc/img/rating/'+s.replace('{TIPO}','off'));
					star.className = 'off';
				}
				star.setAttribute('id', 'star_'+vid+'_'+j);
				ratings.appendChild(star);
			}
		}
	});
}

function displayHover(ratingId, vid,star){
	for (var i = 0; i <= star; i++){
		//$('star_'+ratingId+vid+'_'+i).setAttribute('src', '/inc/img/rating/dp_star_over.jpg');
		$('star_'+ratingId+vid+'_'+i).setAttribute('src', '/inc/img/rating/dp_star_on2.png');
	}
}

function displayNormal(ratingId,vid, star){
	for (var i = 0; i <= star; i++){
		var status = $('star_'+ratingId+vid+'_'+i).className;
		//$('star_'+ratingId+vid+'_'+i).setAttribute('src', '/inc/img/rating/dp_star_'+status+'.jpg');
		$('star_'+ratingId+vid+'_'+i).setAttribute('src', '/inc/img/rating/dp_star_'+status+'2.png');
	}
}

function displayClick(ratingId,vid,star){
	for(i=0;i<=star;i++){
		$('star_'+ratingId+vid+'_'+i).className = 'on';
	}
	for(i=star+1;i<NUMBER_OF_STARS;i++){
		$('star_'+ratingId+vid+'_'+i).className = 'off';
	}
	displayNormal(ratingId,vid,NUMBER_OF_STARS-1);
}

function mooInit(vid){
	if(arguments.length>1){
		init_rating(vid,arguments);
	} else {
		init_rating(vid);
	}
}

function getRatingVar(vid){
	var n = Object.toQueryString({'m':0, 'vid': vid});
	var url = '/inc/rating.php?'+n;
	var star = 'star'+vid;
	if($(star)){
		var request = new Ajax(url, {
			method : 'get',
			evalScripts: true,
			update : $(star),
			onComplete: function() {
				mooInit(vid);
			}
		}).request();
	}
}

function viewOrder(){
	var url = '../inc/ecomm.content.php?s=23';
	var jsonCart = new Ajax(url,{
		method : 'post',
		evalScripts: true,
		autoCancel : true,
		update : $('dp_gbl')
	}).request();
}

/*function useAgreement(code){ //USA CODICE CONVENZIONE
	useDiscount(code);
}

function useDiscount(code){ //USA CODICE SCONTO
	var url = '../inc/ecomm.content.php?s=discount&c='+ code;
	var disc = new Ajax(url,{
		method : 'get',
		evalScripts: true,
		autoCancel : true,
		onComplete: function(ret){
			if(ret != 0){
				$('discount').setHTML(ret);
				viewCart();
				goToCart(10);
			} else if(ret == 0){
				alert('codice errato!');
				$('discount').setProperty('value','');
			}
		}
	}).request();
}*/

function remPromo(){ //RIMUOVI CODICE PROMOZIONE
	var url = '../inc/ecomm.content.php?s=remPromo';
	var disc = new Ajax(url,{
		method : 'get',
		autoCancel : true,
		onComplete : function(){
			viewCart();
			goToCart(10);
		}
	}).request()
}

function tryStep2(email,giorno,mese,anno){ //primo step reset password: invia la mail e va sul secondo form
	var url_param = Object.toQueryString({'s': 'reset_pwd2', 'email' : email, 'giorno' : giorno, 'mese': mese, 'anno' : anno});	
	var url = '../inc/ecomm.content.php?'+url_param;
	var disc = new Ajax(url,{
		method : 'POST',
		autoCancel : true,
		evalScripts: true,
		update : $('dp_login')
	}).request()
}

function tryStep3(pwd,uid,code){ //secondo step reset password: invia i valori delle nuove password per il controllo
	var url_param = Object.toQueryString({'s': 'reset_pwd4', 'pwd' : pwd, 'uid' : uid, 'code' : code});	
	var url = '../inc/ecomm.content.php?'+url_param;
	var disc = new Ajax(url,{
		method : 'POST',
		autoCancel : true,
		evalScripts: true,
		onComplete: function(res){
			if(res == 1){
				$('reset_pwd_2').setHTML('<p class="przgreen3" style="text-align:center !important;">PASSWORD CORRETTAMENTE RESETTATA!</p>');
			} else {
				$('reset_pwd_2').setHTML('<p class="przred3" style="text-align:center !important;">SI E\' VERIFICATO UN ERRORE.</p>');
			}
		}
	}).request()
}

function openTicket(){ //SERVIZIO CLIENTI
	var url_param = Object.toQueryString({'s': 'support'});
	var url = '../inc/ecomm.content.php?'+url_param;
	var ticket = new Ajax(url,{
		method : 'POST',
		autoCancel : true,
		evalScripts: true,
		update : $('dp_gbl')
	}).request($('servizio_clienti'))
}

/*function newRegister(){ //NUOVA REGISTRAZIONE
	var url_param = Object.toQueryString({'s': 'register'});
	var url = '../inc/ecomm.content.php?'+url_param;
	new Ajax(url,{
		method : 'post',
		autoCancel : true,
		data : $('form_maggiore'),
		evalScripts: true,
		update : $('dp_gbl')
	}).request()
}*/

function tellVariant(f){
	$(f).send({
		onComplete: function(res){
			res = Json.evaluate(res);
			if(res[0] ==1){
				$('tellform').setStyle('display','none');
			}
			new StickyWin({
				relativeTo: $('img_centrale'),
				content: stickyWinHTML('',res[1], {
					width: '400px',
					buttons: [{
						text: 'ok', 
						onClick: function(){javascript:void(0);}
					}]
				})
			});
		}
	});
}

function sendVoteVariant(f){
	$(f).send({
		onComplete: function(res){
			res = Json.evaluate(res);
			if(res.ok==1){
				$('commentform').setStyle('display','none');
			}
			new StickyWin({
				relativeTo: $('img_centrale'),
				content: stickyWinHTML('',res.msg, {
					width: '400px',
					buttons: [{
						text: 'ok', 
						onClick: function(){javascript:void(0);}
					}]
				})
			});
		}
	});
}

function sendVoteSurvey(c,val,pos){
	new Json.Remote('/inc/ecomm.content.php?s=votevariant', {
		onRequest: function(){
			new Confirmer({
				msg: 'Attendere... Salvataggio in corso...',
				positionOptions: {
					relativeTo: pos,
					position: "bottomLeft",
					offset: {x: 0, y: 0}
			  	}
			}).prompt();
		},
		onComplete: function(res){
			var err = '';
			if(!$chk(res)){
				err = 'Errore!';
			} else if(res.ok==1){
				new Confirmer({
					msg: 'Salvato!',
					positionOptions: {
						relativeTo: pos,
						position: "bottomLeft",
						offset: {x: 0, y: 0}
				  	}
				}).prompt();
				pos.setProperty('disabled','disabled').setStyle('cursor','default');
				pos.getParent().getParent().getElements('input[type=image]').each(function(inp){
					inp.setProperty('disabled','disabled').setStyle('cursor','default');
				});
			} else {
				err = res.msg;
			}
			if(err!=''){
				new StickyWin({
					relativeTo: pos,
					content: stickyWinHTML('',err, {
						width: '400px',
						buttons: [{
							text: 'ok', 
							onClick: function(){javascript:void(0);}
						}]
					})
				});
			}
		}
	}).send('j=0&voteSurvey='+c+'&val='+val+'&j1=0');
}

function changePageComments(vid,from,num){
	new Ajax('/inc/ecomm.content.php?s=votevariant',{
		method : 'post',
		evalScripts: true,
		update : $('variantCommentsContainer')
	}).request('viewComments='+vid+'&from='+from+'&num='+num);
}

function liveSaver(what,where){ //salva in automatico i campi dello step due del carello
	var url = '../inc/ecomm.content.php?s=8';
	var ticket = new Ajax(url,{
		method : 'POST',
		onRequest: function(){
			new Confirmer({
				msg: 'Attendere.... Salvataggio in corso...',
				positionOptions: {
					relativeTo: $(where),
					position: "bottomLeft",
					offset: {x: 0, y: 0}
			  	}
			}).prompt();
		},
		onComplete: function(){
			new Confirmer({
				msg: 'Salvato!',
				positionOptions: {
					relativeTo: $(where),
					position: "bottomLeft",
					offset: {x: 0, y: 0}
			  	}
			}).prompt();			
		}
	}).request($('controllo_dati'));
}

/********** INVITA UN AMICO ************/

function inviteFriend(val){
	var total = 0;
	if($('total')){
		total = $('total').getValue();
	}
	$('divtot').empty();
	if(val.length > 4){
		url = "invitefriend.php?email="+val;
		new Ajax(url,{
			method: 'get',
			evalScripts: true,
			autoCancel: true,
			update: $('divtot'),
			onRequest: function(){
				$('btnadd').setProperty('disabled','disabled');
				$('btnadd').setHTML('Caricamento...');
			},
			onComplete: function(){
				$('btnadd').removeProperty('disabled');
				$('btnadd').setHTML('Aggiungi nominativo');
				$('email').setProperty('value','');
				var t2 = $('total').getValue();
				if(t2 > total){
					new Element('div',{'id':'nmailnew'+t2}).setHTML(val).injectInside($('lstMail'));
					$('nmailnew'+t2).effect('background-color', {
						duration: 1500, 
						transition: Fx.Transitions.Quart.easeInOut
					}).start('#0099ff','#FFFFFF');
					if(t2 == 3){
						$('btnadd').remove();
						new Element('button',{'id':'btnadd'}).setHTML('Richiedi il tuo codice sconto').injectAfter($('total'));
						$('countdown').empty();
						location.href = 'invitefriend.php?s=discount';
					} else {
						$('countdown').setHTML('Mancano '+ (3 - t2) +' email per ricevere lo sconto!');
					}
					$('error').setHTML('');
				} else {
					$('error').setHTML('<span style="color:#FFFFFF; font-size:14px;">Mail inserita non valida o gi&agrave; presente!</span>');
					exampleFx = new Fx.Style($('error'), 'background-color', {
						duration: 1500, 
						transition: Fx.Transitions.Quart.easeInOut
					});
					exampleFx.start('#FFFFFF','#CC0000');					
				}
			} 
		}).request($('total'));
	}
}

function getProvince(ids,what,selOpt){
	if(ids=='dis') {	$('comune'+what).setProperty('disabled','disabled'); return;}
	$('comune'+what).empty();
	new Element('option').setHTML('-').injectInside('comune'+what);
	var n = Object.toQueryString({'id': ids, 'mode' : 1});
	var myAjax = new Json.Remote('/inc/location.php?'+n, {
		onComplete: function(json){
			(json.city).each(function(citta){
				var o = new Element('option').setProperty('value',citta.id).setHTML(citta.city.capitalize());
				if($chk(selOpt) && selOpt==citta.id){
					o.setProperty('selected','selected');
				}
				o.injectInside('comune'+what);
			});
			$('comune'+what).setProperty('disabled','');
		}
	}).send();
}

function changeWishlistVariant(wid,vid,t,val,price){
	new Json.Remote('/inc/ecomm.content.php?action=user_panel&s=user_panel&changevalues=1', {
		onRequest: function(){
			new Confirmer({
				msg: 'Attendere.... Salvataggio in corso...',
				positionOptions: {
					relativeTo: $('pricevid'+vid),
					position: "bottomLeft",
					offset: {x: 0, y: 0}
			  	}
			}).prompt();
		},
		onComplete: function(res){
			if(!res){
				new Confirmer({
					msg: 'Errore!',
					positionOptions: {
						relativeTo: $('pricevid'+vid),
						position: "bottomLeft",
						offset: {x: 0, y: 0}
				  	}
				}).prompt();
			} else if(res.ok==1){
				if(t=='qty'){
					var tot = (val*price*100).round().toString();
					$('pricevid'+vid).setHTML(tot.substr(0,tot.length-2)+','+tot.substr(tot.length-2));
				}
				new Confirmer({
					msg: 'Salvato!',
					positionOptions: {
						relativeTo: $('pricevid'+vid),
						position: "bottomLeft",
						offset: {x: 0, y: 0}
				  	}
				}).prompt();
			} else {
				new Confirmer({
					msg: res.msg,
					positionOptions: {
						relativeTo: $('pricevid'+vid),
						position: "bottomLeft",
						offset: {x: 0, y: 0}
				  	}
				}).prompt();
			}
		}
	}).send('json=1&wid='+wid+'&vid='+vid+'&type='+t+'&value='+val+'&json2=1');
}

function deleteAddressUserPanel(aid){
	if(!confirm('Sei sicuro di voler cancellare questo indirizzo?')) return;
	new Json.Remote('/inc/ecomm.content.php?action=user_panel&s=user_panel&deleteAddress='+aid, {
		onComplete: function(res){
			if(!res){
				new Confirmer({
					msg: 'Errore!',
					positionOptions: {
						relativeTo: $('deleteAddress'+aid),
						position: "bottomLeft",
						offset: {x: 0, y: 0}
				  	}
				}).prompt();
			} else if(res.ok==1){
				$$('tr[rel=address'+aid+']').each(function(tr){
					tr.remove();
				});
			} else {
				new Confirmer({
					msg: res.msg,
					positionOptions: {
						relativeTo: $('deleteAddress'+aid),
						position: "bottomLeft",
						offset: {x: 0, y: 0}
				  	}
				}).prompt();
			}
		}
	}).send();
}