var labelDone = 'Hai prenotato questo premio.';
var labelGet = 'Può essere tuo';
var labelPay = 'Può essere tuo con xx euro.';
//var labelPay1 = 'Saldo punti insufficiente';
var labelPts = 'Ti mancano ancora xx punti.';
var labelPdv = 'Prendilo nel tuo punto vendita preferito.';
var labelNd = 'Premio non prenotabile via web';

var myPoint = 0;

function addGift(id){
    $.getJSON("/AjaxRpc/wishlistManager.addGift?premioId=" + id, null, function(data, textstatus){
        if (!data.result) {
            //alert('Errore premio non inserito.');
            window.location.href = '/richieste/richiesta-registrazione.html';
        }
        else {
            window.location.href = '/my-carrefour/wishlist.html';
        }
    });
    
}

function removeGift(id){

	code = id;

    $.getJSON("/AjaxRpc/wishlistManager.removeGift?premioId=" + id
		, null
		, function(data, textstatus){
        	if (!data.result) {
	            alert('Errore nella eliminazione del premio.');
    	    }
        	else {
	            if ('all' == code) {
    	            //rimuovo tutti
        	        $("#wishlistpremi").empty();
            	}
	            else {
    	            $("#removePremi_" + id).parent().remove();
        	    }
        	}
    });
}

function checkStatus(ptGratis, ptContributo, contributo, available){

        var labels = new Array();
        var classLabel = '';
        var textLabel = '';
        var hide = false;
        var active = 'N';
        var avaCat = String(available).split('_');
        for(var i=0;i<avaCat.length;i++){
        	if(parseInt(avaCat[i]) == parseInt(catalogId) || parseInt(catalogId) < 0){
        		active = 'S';
        	}
        }
        if (myPoint >= ptGratis) {
            // punti premio gratis
            textLabel = labelGet;
            classLabel = 'wish_status wish_get';
        }

		else if (myPoint < ptGratis && ptContributo == 0) {
			var tmpLable = labelPts.split('xx');
			textLabel = tmpLable[0] + (ptGratis - myPoint) + tmpLable[1];
			classLabel = 'wish_status wish_pay';
			active = 'S';
		}
        else if (myPoint >= ptContributo && ptContributo > 0) {
			// punti premio con pagamento
			var tmpLable = labelPay.split('xx');
			textLabel = tmpLable[0] +contributo + tmpLable[1];
			classLabel = 'wish_status wish_get';
		}
		else if (myPoint >= ptContributo && ptContributo == 0) {
			//punti premio senza possibilità di pagamento
			var tmpLable = labelPts.split('xx');
			textLabel = tmpLable[0] + (ptGratis - myPoint) + tmpLable[1];
			classLabel = 'wish_status wish_pts';
			active = 'S';			
		}
		else {
			var tmpLable = labelPts.split('xx');
			textLabel = tmpLable[0] + (ptContributo - myPoint) + tmpLable[1];
			classLabel = 'wish_status wish_pay';
			active = 'S';
		}
        

		if (active == 'N') {
			//premio non dispodibile
			textLabel = labelNd;
			classLabel = 'wish_status wish_nav';
		}
	labels[0] = classLabel;
	labels[1] = textLabel;
	labels[2] = active;
	return labels;
}

function getUrlParameter( name ){
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
 		var regexS = "[\\?&]"+name+"=([^&#]*)";
  		var regex = new RegExp( regexS );
		var results = regex.exec( window.location.href );
		if( results == null )
    		return "";
 		else
   			return decodeURIComponent(results[1]);
}



