// Funzione che apre un div e chiude tutti gli altri //

function THISonTHAToff(code) {

    ff = document.getElementsByTagName("div");
    for (i = 0; i < ff.length; i++) {
        if (ff[i].id.substr(0,5)=="onOff") {
            ff[i].style.display = "none";
        }
    }   
    for (i = 0; i < ff.length; i++) {
        if (ff[i].id == code) {
            if (ff[i].style.display == "none") {
                ff[i].style.display = "";
            }
        }
    }
}

// Funzione che apre e chiude un div cliccando sul link //
function THISonTHISoff(code) {
    ff = document.getElementById(code);
		if (ff.style.display == "") {
			ff.style.display = "none";
		} else
		if (ff.style.display == "none") {
			ff.style.display = "";
		}
}

// Funzione che apre la popup //
function Popup(url, stile) {
	window.open(url, "", stile);
	}
	
//Funzioni per la votazione delle ricette (richiede JQuery)	
/*
function rateRecipe(StarsNumber, CurrentAverageVote, RecipeId)
{
	this.starsHtmlString="";
	this.starsNumber=StarsNumber;
	this.averageVote=CurrentAverageVote;
	this.recipeId=RecipeId;
	
	//Check valori
	if (CurrentAverageVote > StarsNumber)
		this.averageVote=StarsNumber;
	else if (CurrentAverageVote<=0)
		this.averageVote=-1;
		
	if (this.starsNumber!=0)
	{
		for (s=0; s<this.starsNumber; s++)
			this.starsHtmlString+="<a href=\"#\" onclick=\"rateRecipeControl.setRating("+(s+1)+");\" onmouseover=\"rateRecipeControl.showStar("+s+")\" onmouseout=\"rateRecipeControl.clearAll()\"><img src=\"./gfx/ico_stellina_vuota.png\" width=\"14\" height=\"12\" alt=\"\" id=\"rating_"+s+"\" title=\"Voto "+(s+1)+"\" border=\"0\"></a>";
 		$("#voteControlContainer").html(this.starsHtmlString);
		if (this.averageVote!=0 || this.averageVote!=null)
		{
			var vote=this.averageVote;
			for (s=0; s<vote; s++)
				$('#rating_'+s).attr({ src: "./gfx/ico_stellina_piena.png", alt: vote });
			$("#rateControlVote").width(value2width(vote));
			$("#rateControlVote").show();
			$("#rateControlContainer").mouseover( function() { $("#rateControlVote").hide();$("#rateControlContainer").hide();$("#voteControlContainer").show(); } );
			$("#rateControlContainer").show();	
			$("#voteControlContainer").hide();	
		}		
	}	

	this.showStar = function(vote)
	{
		if (vote<=this.starsNumber)
		{
			for (s=0; s<this.starsNumber; s++) 
				$('#rating_'+s).attr({ src: "./gfx/ico_stellina_vuota.png", alt: "" });		
			for (s=0; s<=vote; s++)
				$('#rating_'+s).attr({ src: "./gfx/ico_stellina_piena.png", alt: vote });
		}
	}

	this.setRating = function(vote)
	{
		if (vote<=this.starsNumber)
		{
			$.post("vote.aspx?recipeId="+this.recipeId+"&vote="+vote, {queryString: vote}, function(data) {
			    if(data.length > 0)
					$("#rateControlVote").width(value2width(data));			
				$("#rateControlVote").show();
				$("#rateControlContainer").show();	
				$("#voteControlContainer").hide();												
			});
		}
	}	

	this.clearAll = function()
	{
		if (this.averageVote==0 || this.averageVote=="")
		{
			for (s=0; s<this.starsNumber; s++) 
				$('#rating_'+s).attr({ src: "./gfx/ico_stellina_vuota.png", alt: "" });			
		}
		else
		{
			var stars=this.starsNumber;
			var vote=this.averageVote;		
			this.showRating(vote);
			$("#rateControlVote").width(value2width(this.averageVote));			
			$("#rateControlVote").show();
			$("#rateControlContainer").show();	
			$("#voteControlContainer").hide();	
		}
	}
	
	this.showRating = function(vote)
	{
		var stars=this.starsNumber;
		for (s=0; s<stars; s++) 
			$('#rating_'+s).attr({ src: "./gfx/ico_stellina_vuota.png", alt: "" });		
		for (s=0; s<vote; s++) 
			$('#rating_'+s).attr({ src: "./gfx/ico_stellina_piena.png", alt: "" });			
	}
}


function value2width(vote)
{	
	var valueReturned;
	// PARTE INTERA: 5 Stelline = 100% = 70px = 5 vote | 1 stellina = 20% = 14px = 1 vote
	// PARTE DECIMALE: 1 stellina= 100% = 14px;
	
	if (vote>=5)
		return 70;
	else if (vote<=0)
		return 0;
	else
	{
		vote=""+vote;
		var parti = vote.split(".");
		return((parti[0] * 14) + parseInt(parti[1]));
	}
}
*/
function doStuff(event, yourchoice, recipeId)
{
	$.post("vote.aspx?recipeId="+recipeId+"&vote="+yourchoice, {queryString: yourchoice}, function(data) { 
	    if(data.length > 0) 
	        v.lock(); 
	        });
}

function jVote(parent, settings)
{
	this.locked = false;
	this.images = [];
	this.settings = settings;
	this.parent = parent;
	this.init();
}

jVote.prototype.init = function()
{
	var that = this;	
	for(var i = 0, e = this.settings.max; i < e; i++)
	{
	
		var image = document.createElement('img');
		this.images[i] = image;
		image.value = this.settings.labels[i];
		image.alt = this.settings.labels[i];
		image.style.cursor = 'pointer';
		image.recipeId=this.settings.recipeid;		
		image.onmouseover = function()
		{
			if(that.locked)
			{
				return;
			}
			that.set(this);
		};
		image.onclick = function(evnt)
		{
			if(that.locked)
			{
				return;
			}
			var eEvent = evnt || window.event;
			if (that.settings.click)
			{
				that.settings.click(eEvent, this.value, this.recipeId);
			}
		};				
		document.getElementById(this.parent).appendChild(image);				
	}
	this.set(this.images[this.settings.min-1]);	
};

jVote.prototype.set = function(domImage)
{

	domImage.src = './gfx/ico_stellina_piena.png';
	var next = domImage.nextSibling;
	while(next)
	{
		next.off = true;
		next.src = './gfx/ico_stellina_vuota.png';
		next = next.nextSibling;
	}
	var prev = domImage.previousSibling;
	while(prev)
	{
		prev.off = false;
		prev.src = './gfx/ico_stellina_piena.png';
		prev = prev.previousSibling;
	}
};

jVote.prototype.reset = function(num)
{
	if(this.locked)
	{
		return;
	}
	var index = (num) ? num : this.settings.min;
	this.set(this.images[index-1]);
};

jVote.prototype.lock = function()
{
	this.locked = true;
};

jVote.prototype.unLock = function()
{
	this.locked = false;
};
