	/*
	// Allmänna funktioner
	*/
	
	function getCompleteRowHtml(thisRow)
	{
		if (Element.hasClassName(thisRow, 'editableRecepieDescription'))
		{
			var descriptionText = thisRow.getElementsByClassName('descriptionText')[0].value;
			innerHTML = getEditDescriptionHtml(descriptionText, 0);
		}
		else if (Element.hasClassName(thisRow, 'editableRecepieDescriptionSubTitle'))
		{
			var subTitle = thisRow.getElementsByClassName('subTitle')[0].value;
			innerHTML = getEditDescriptionSubTitleHtml(subTitle, 0);
		}
		else if (Element.hasClassName(thisRow, 'editableRecepieContent'))
		{
			var amount = thisRow.getElementsByClassName('amount')[0].value;
			var amountType = thisRow.getElementsByClassName('amountType')[0].value;
			var ingredient = thisRow.getElementsByClassName('ingredient')[0].value;
			innerHTML = getEditContentHtml(amount, amountType, ingredient, thisRow.id);
		}
		else if (Element.hasClassName(thisRow, 'editableRecepieContentSubTitle'))
		{
			var subtitle = thisRow.getElementsByClassName('subTitle')[0].value;
			innerHTML = getEditContentSubRecepieTitleHtml(subtitle, thisRow.id);
		}
		
		return thisRow.inspect()+''+innerHTML+'</'+thisRow.tagName+'>';
	}

	function moveRowUp(descriptionsList, moveLink)
	{
		var thisRow = moveLink.parentNode;
		var prevRow = Element.previous(thisRow);
		
		//Kollar så denna rad inte är den första
		if (prevRow != null && !Element.hasClassName(prevRow, 'helpRow'))
		{
			new Insertion.Before(prevRow, getCompleteRowHtml(thisRow));
			Element.remove(thisRow);
		}
		else
		{
			alert('Du kan inte flytta denna rad högre upp!');
		}
		
		updateTabIndexes($('recepieCore'));
		
		return false;
	}
	
	function moveRowDown(descriptionsList, moveLink)
	{
		var thisRow = moveLink.parentNode;
		var nextRow = Element.next(thisRow);

		//Kollar så denna rad inte är den sista
		if (nextRow != null)
		{			
			new Insertion.After(nextRow, getCompleteRowHtml(thisRow));
			Element.remove(thisRow);
		}
		else
		{
			alert('Du kan inte flytta denna rad längre ner!');
		}
		
		updateTabIndexes($('recepieCore'));
		
		return false;
	}
	
	function removeRow(removeLink)
	{
		var row = removeLink.parentNode;
		Element.remove(row);
		
		updateTabIndexes($('recepieCore'));
		
		return false;
	}
	
	function updateTabIndexes(list)
	{
		var inputs = list.getElementsByClassName('recepieEditableText');
		
		for(i=0; i<inputs.length; i++)
		{
			var input = inputs[i];
			input.tabIndex = i + 1;
		}
	}
	
	function setFirstElementFocusedByClassName(parent, classname)
	{
		var elements = parent.getElementsByClassName(classname);
		
		if (elements.length > 0)
		{
			elements[0].focus();
		}
		else
		{
			return false;
		}
		
		return false;
	}
	
	function setFirstElementFocused(parent, tagName)
	{
		var elements = parent.getElementsByTagName(tagName);
		
		if (elements.length > 0)
		{
			elements[0].focus();
		}
		else
		{
			return false;
		}
		
		return false;
	}
	
	/*
	//	sendRecepie
	*/
	
	function toggleSendRecepieForm()
	{
		var sendRecepie = 'sendRecepie';
		if (Element.visible(sendRecepie))
		{
			Effect.SlideUp(sendRecepie, { duration: 0.5 });
		}
		else
		{
			Effect.SlideDown(sendRecepie, { duration: 0.5 });
		}
		return false;
	}
	
	function previewSendRecepie(form)
	{
		Element.show('sendRecepie_preview');
		
		setTimeout(function()
		{
			var pars = 'ajax=1&senderName='+input2js(form.senderName.value)+'&email='+input2js(form.email.value)+'&recepieId='+form.recepieId.value+'&mess='+input2js(form.mess.value)+'&preview=1';
		
			var myAjax = new Ajax.Updater(
			'sendRecepie_preview', 
			"/actions/send_postcard.php", 
			{
				parameters: pars,
				method: 'post'
			});
		}, 500);

	}
	
	function sendRecepie(form)
	{
		if (form.senderName.value.length == 0)
		{
			alert('Skriv in ditt namn');
			form.senderName.focus();
			return false;
		}
		else if (form.email.value.length == 0)
		{
			alert('Skriv in din väns e-mail');
			form.email.focus();
			return false;
		}
		
		var pars = 'ajax=1&senderName='+input2js(form.senderName.value)+'&email='+input2js(form.email.value)+'&recepieId='+form.recepieId.value+'&mess='+input2js(form.mess.value)+'';
		var url = "/actions/send_postcard.php";
		
		new Ajax.Request(url, {
			method: 'post', 
			parameters: pars,
			onComplete: recepieSent
		});
	
		return false;
	}
	
	function recepieSent(originalRequest)
	{
		if (originalRequest.responseText == "0")
		{
			alert("Något gick snett.. Mailet har INTE skickats!");
			return false;
		}
	
		$('sendRecepie_content').innerHTML = '<p class="padding4 nomargin center"><br /><br />'+originalRequest.responseText+'<br /><a href="/js" onclick="Effect.SlideUp(\'sendRecepie\', { duration: 0.2 }); return false;">Stäng rutan</a><br /><br /><br /></p>';
	}
	
	
	function UploadRecipeImage()
	{
		if(Element.visible('recepieContentsButtons'))
		{
			alert('Spara dina ingrediensändringar innan du laddar upp en bild');
			return false;
		}
		else if (Element.visible('recepieDescriptionsButtons'))
		{
			alert('Spara dina ändringar under Gör så här innnan du laddar upp en bild!');
			return false;
		}
		else if ($('uploadfile').value.length == 0)
		{
			alert('Du måste välja en bild att ladda upp');
			return false;
		};
		Effect.toggle('uploadRecepieImage', 'slide', { duration: 0.4 });
		$('uploadImageloadingImage').innerHTML = '<p><img src="/images/loading.gif" />Laddar upp, ett ögonblick...</p>';
	}
	
	
	
	
	/*
	//	recepieContents
	*/
	var newRowCounter = 0;
	function beginEditContents(contentsList)
	{
		if(Element.visible('recepieContentsButtons'))
		{
			alert('Du är redan i editera-läget för ingredienserna');
			
			//Sätter fokus på första inputen
			setFirstElementFocused(contentsList, 'input');
			
			return false;
		}
	
		// Det finns hard-words descriptions i texten ELLER så har användaren kanske ställt om
		// antalet personer. Vi laddar om ingredienserna här UTAN beskrivning.
		$('recepieNumberOfPersons').innerHTML = recepieInfo['defaultNumberOfPersons'];
		if (recepieInfo['defaultNumberOfPersons'] == 1)
		{
			$('recepieNumberOfPersons_text').innerHTML = 'person';
		}
		else
		{
			$('recepieNumberOfPersons_text').innerHTML = 'personer';
		}
	
		var recepieId = recepieInfo['id'];
		var url = '/actions/get_recepie_contents.php';
		// Reload WITHOUT description for hard words.
		var pars = 'recepieId='+recepieId+'&hardwordsDescriptions=0';
		
		var myAjax = new Ajax.Updater(
			'recepieContents', 
			url, 
			{
				method: 'post', 
				parameters: pars,
				onComplete: function(){

					transformAllContentsToInputs(contentsList);

				}
			});
		
		return false;
	}
	
	function transformAllContentsToInputs(contentsList)
	{
		transformNumberToSelect($('recepieNumberOfPersons').innerHTML);
		
		var contentItems = contentsList.getElementsByTagName("li");
		Element.show('recepieContentsButtons');
		Element.hide('showForNumberOfPersons');
		
		newRowCounter = contentItems.length+1;
		
		for(i=0; i<contentItems.length; i++)
		{
			var contentItem = contentItems[i];

			//Tar reda på vilken typ av rad det är; content eller title
			if (Element.hasClassName(contentItem, 'recepieContent'))
			{
				transformContentToInputs(contentItem, i);
			}
			else if (Element.hasClassName(contentItem, 'recepieContentSubTitle'))
			{
				transformContentSubRecepieTitleToInputs(contentItem, i);
			}
			else if (Element.hasClassName(contentItem, 'tempRow'))
			{
				Element.remove(contentItem);
			}
		}
		
		//Lägger till ett antal tomma rader om det inte finns några alls
		if (contentItems.length == 0)
		{
			for(j=0; j<4; j++)
			{
				addEditContentRow();
			}
		}
		
		//Lägger till en hjälp/info-rad högst upp
		new Insertion.Top(contentsList, '<li class="tempRow helpRow"><span class="ex">Ex:</span><span class="amount">2</span><span class="amountType">dl</span><span class="amountType">mjölk</span></li>');
		
		//Gömmer "Lägg till i inköpslistan"-knappen
		Element.hide('addToShoppingListButton');
		
		//Uppdaterar alla tabIndexes så man kan tabba mellan rutorna
		updateTabIndexes($('recepieCore'));
		
		//Sätter fokus på första inputen
		setFirstElementFocused(contentsList, 'input');
	}
	
	function transformNumberToSelect(numberOfPersons)
	{
		var html = '<select id="numberOfPersons_select">';
		
		for(i=1; i<=50; i++)
		{
			html += '<option value="'+i+'"';
			
			if (i == numberOfPersons)
			{
				html += ' selected="selected"';
			}
			
			html += '>'+i+'</option>';
		}
		
		html += '</select>';
		
		$('recepieNumberOfPersons').innerHTML = html;
	}
	
	function transformSelectToNumber()
	{
		var numberOfPersons = parseInt($('numberOfPersons_select').value)
		
		if (numberOfPersons == 1)
		{
			$('recepieNumberOfPersons_text').innerHTML = "person";
		}
		else
		{
			$('recepieNumberOfPersons_text').innerHTML = "personer";
		}
		
		$('recepieNumberOfPersons').innerHTML = numberOfPersons;
		
		return false;
	}
	
	function transformContentToInputs(content)
	{
		var amount = content.getElementsByClassName('amount')[0].innerHTML;
		var amountType = content.getElementsByClassName('amountType')[0].innerHTML;
		var ingredient = content.getElementsByClassName('ingredient')[0].innerHTML;
		
		Element.removeClassName(content, 'recepieContent');
		Element.addClassName(content, 'editableRecepieContent');
		
		content.innerHTML = getEditContentHtml(amount, amountType, ingredient);
	}
	
	var autosuggest = null;
	function getEditContentHtml(amount, amountType, ingredient)
	{
		if (amount == null) 		{ amount = ""; 	}
		if (amountType == null) 	{ amountType = ""; }
		if (ingredient == null) 	{ ingredient = ""; }

		var output = '';
		output += '	<input name="amount" class="amount recepieEditableText input_text" onfocus="textInputFocus(this);" onblur="textInputBlur(this);" value="'+amount+'" />';
		output += '	<input name="amountType" class="amountType recepieEditableText input_text" onfocus="textInputFocus(this);" onblur="textInputBlur(this);" value="'+amountType+'" />';
		output += '	<input name="ingredient" class="ingredient recepieEditableText input_text" onfocus="textInputFocus(this); autosuggest = new bsn.AutoSuggest(this, ingredientOptions);" onblur="textInputBlur(this); autosuggest.clearSuggestions();" value="'+ingredient+'" />';
		output += '	<a href="/js" onclick="return removeRow(this);");" class="icon delete" title="Ta bort ingrediens"><span>Ta bort ingrediens</span></a>';
		output += '	<a href="/js" onclick="return moveRowUp($(\'recepieContents\'), this);");" class="icon arrow_up" title="Flytta upp"><span>Flytta upp</span></a>';
		output += '	<a href="/js" onclick="return moveRowDown($(\'recepieContents\'), this);");" class="icon arrow_down" title="Flytta ner"><span>Flytta ner</span></a>';
		
		return output;
	}
		
	function transformContentSubRecepieTitleToInputs(titleRow)
	{
		var title = titleRow.getElementsByTagName('h4')[0].innerHTML;
		
		Element.removeClassName(titleRow, 'recepieContentSubTitle');
		Element.addClassName(titleRow, 'editableRecepieContentSubTitle');
		
		titleRow.innerHTML = getEditContentSubRecepieTitleHtml(title, titleRow.id);
	}
	
	function getEditContentSubRecepieTitleHtml(title)
	{
		if (title == null) 		{ title = ""; 	}
	
		var output = '';
		output += '	<input name="subTitle" class="subTitle recepieEditableText input_text" onfocus="textInputFocus(this);" onblur="textInputBlur(this);" value="'+title+'" />';
		output += '	<a href="/js" onclick="return removeRow(this);" class="icon delete" title="Ta bort ingrediens"><span>Ta bort titel</span></a>';
		output += '	<a href="/js" onclick="return moveRowUp($(\'recepieContents\'), this);");" class="icon arrow_up" title="Flytta upp"><span>Flytta upp</span></a>';
		output += '	<a href="/js" onclick="return moveRowDown($(\'recepieContents\'), this);");" class="icon arrow_down" title="Flytta ner"><span>Flytta ner</span></a>';
	
		return output;
	}
	
	function addEditContentRow()
	{
		newRowCounter++;
		var newRowId = 'recepieContentRow'+newRowCounter;
	
		var html = getEditContentHtml('', '', '', newRowId);
		html = '<li class="editableRecepieContent" id="'+newRowId+'">'+html+'</li>';
		addContentRow(html);
	}
	
	function addEditSubTitleRow()
	{
		newRowCounter++;
		var newRowId = 'recepieContentRow'+newRowCounter;
		var html = getEditContentSubRecepieTitleHtml('', newRowId);
		html = '<li class="editableRecepieContentSubTitle" id="'+newRowId+'">'+html+'</li>';
		addContentRow(html);
	}
	
	function addContentRow(html)
	{
		var contentsList = $('recepieContents');
	
		new Insertion.Bottom(contentsList, html);
		updateTabIndexes($('recepieCore'));
	}
	
	
	function isNumeric(value)
	{
		return typeof value != "boolean" && value !== null && !isNaN(+ value);
	}
	
	
	// Check valid amount, returns 0 on failure.
	function parseAmount(value)
	{
		var amount = value;
		amount = amount.replace(/,/g, ".");
		
		if (amount.indexOf("-") != -1)
		{
			return 0;
		}
		
		// Special niceifications can't pass an eval.
		// The space on the end is important because it solves the faulty situation
		// where user types "½1"
		amount = amount.replace(/½/g, "+0.5 ");
		amount = amount.replace(/ 1\/2/g, "+0.5 ");
		amount = amount.replace(/ 1\/3/g, "+0.33 ");
		amount = amount.replace(/ 2\/3/g, "+0.66 ");
		amount = amount.replace(/ 1\/4/g, "+0.25 ");
		amount = amount.replace(/ 3\/4/g, "+0.75 ");

		try
		{
			amount = eval(amount);
		} catch(ba)
		{
			return 0;
		}
		
		if (amount == "" || amount == null)
		{
			return 0;
		}
		return amount;
	}


	function validateInputs(contentsList)
	{
	
		// check all values to be ok. 
		// Warn on 0-rows and leave.
		// in case of ½ replace with +0.5 which js will fix for us.
	
		//Går igenom alla ingrediens-rader
		var contentRows = contentsList.getElementsByTagName("li");
		
		//Skapar en array för att samla all data
		var contentRowsData = new Array();
		
		//Loopar igenom alla ingrediensrader
		for(i=0; i<contentRows.length; i++)
		{
			var contentRow = contentRows[i];
			
			if (Element.hasClassName(contentRow, 'helpRow'))
			{
				continue;
			}
			
			var amountCheck = contentRow.getElementsByClassName('amount');
			if (amountCheck.length > 0)
			{
				var amount = contentRow.getElementsByClassName('amount')[0].value;
				var amountType = contentRow.getElementsByClassName('amountType')[0].value;
				var ingredient = contentRow.getElementsByClassName('ingredient')[0].value;
				
				// Check index 1 and 3 (amount and ingredient)
				// If BOTH are blank, then assume a "delete", just ignore it.
				
				if (amount == "" && ingredient == "")
				{
					continue;
				}
				
				// Check ingredient to have a name at all. 
				if (ingredient == "")
				{
					alert("En av ingredienserna har inte något namn. Vill du ta bort en ingrediens klickar du på röda krysset.");
					contentRow.getElementsByClassName('ingredient')[0].focus();
					return false;
				}
				
				
				amount = parseAmount(amount);
				if (amount == 0)
				{
					alert("Mängden av '" + ingredient + "' måste anges som en siffra, tex 1.5 eller 250");
					contentRow.getElementsByClassName('amount')[0].focus();
					return false;
				}
			}
		}

		return true;
	}
	
	function saveContents()
	{
		var contentsList = $('recepieContents');
		
		if (!validateInputs(contentsList))
		{
			// Just a do-not-reload-false, not failure.
			return false;
		}
		
		var data = getContentsInputData(contentsList);
		data = input2js(data);
		var recepieId = recepieInfo['id'];
		
		Element.hide('recepieContentsButtons');
		Element.show('recepieContentsLoading');
		$('recepieContentsLoading').innerHTML = '<p class="center"><img src="/images/loading_wide.gif" /></p>';
				
		recepieInfo['defaultNumberOfPersons'] = parseInt($('numberOfPersons_select').value);
		saveRecepieChange(recepieInfo, 'defaultNumberOfPersons');
		
		//Sparar alla contents
		var url = '/actions/save_recepie_contents.php';
		var pars = 'ajax=1&recepieId='+recepieId+'&data='+data+'&removedContents=';

		new Ajax.Request(url, {
				method: 'post', 
				parameters: pars,
				onComplete: contentsSaved
			});
		
	}
	
	function contentsSaved(originalRequest)
	{
		$('recepieContents').innerHTML = originalRequest.responseText;
		transformSelectToNumber();
		Element.show('showForNumberOfPersons');
		Element.hide('recepieContentsLoading');
		
		//Visar "Lägg till i inköpslistan"-knappen igen
		Element.show('addToShoppingListButton');
	}
	
	function getContentsInputData(contentsList)
	{
		//Går igenom alla ingrediens-rader
		var contentRows = contentsList.getElementsByTagName("li");
		
		//Skapar en array för att samla all data
		var contentRowsData = new Array();
		
		//Loopar igenom alla ingrediensrader
		for(i=0; i<contentRows.length; i++)
		{
			var contentRow = contentRows[i];
			
			if (Element.hasClassName(contentRow, 'helpRow'))
			{
				continue;
			}
			
			var amount = "";
			var amountType = "";
			var ingredient = "";
			var subtitle = "";
			var isDivider = 0;
			
			var amountCheck = contentRow.getElementsByClassName('amount');
			if (amountCheck.length > 0)
			{
				amount = contentRow.getElementsByClassName('amount')[0].value;
				amountType = contentRow.getElementsByClassName('amountType')[0].value;
				ingredient = contentRow.getElementsByClassName('ingredient')[0].value;
				amount = parseAmount(amount);
			}
			else
			{
				ingredient = contentRow.getElementsByClassName('subTitle')[0].value;
				isDivider = 1;
			}
			
			contentRowsData[i] = {
				amount: ''+amount+'',
				amountType: ''+amountType+'',
				ingredient: ''+ingredient+'',
				isDivider: ''+isDivider+'',
				orderId: 0
			};
		}
		
		var data = contentRowsData.toJSON();
		return data;
	}
	
	function cancelEditContents()
	{
		openYesNoDialogQuestionmark('Är du säker på att du vill avbryta?<br />Ej sparade ingredienser kommer försvinna.', function() {
			$('recepieNumberOfPersons').innerHTML = recepieInfo['defaultNumberOfPersons'];
		
			var recepieId = recepieInfo['id'];
			var url = '/actions/get_recepie_contents.php';
			var pars = 'recepieId='+recepieId+'';
			
			var myAjax = new Ajax.Updater(
				'recepieContents', 
				url, 
				{
					method: 'post', 
					parameters: pars
				});
			
			
			Element.hide('recepieContentsButtons');
			Element.show('showForNumberOfPersons');
			
			//Visar "Lägg till i inköpslistan"-knappen igen
			Element.show('addToShoppingListButton');
			
			newRowCounter = 0;
			
			updateTabIndexes($('recepieCore'));
		});
		
		return false;
	}
	
	
	function changeShowNumberOfPersons(select)
	{
		var numberOfPersons = select.options[select.selectedIndex].value;
		
		// Keep the number checked/unchecked boxes when changing number of persons.
		var contentRows = $('recepieContents').getElementsByTagName("li");
		var contentCheckRowsData = new Array();
		
		for(i=0; i<contentRows.length; i++)
		{
			var contentRow = contentRows[i];
			var inputBoxes = contentRow.getElementsByTagName('input');
			if (inputBoxes.length == 0)
			{
				continue;				
			}
			
			var id = inputBoxes[0].value;
			var checked = inputBoxes[0].checked;
			contentCheckRowsData[id] = checked;
		}
	
		var checkerData = contentCheckRowsData.toJSON();
	
		var recepieId = recepieInfo['id'];
		var url = '/actions/get_recepie_contents.php';
		var pars = 'recepieId='+recepieId+'&showNumberOfPersons='+numberOfPersons+'&checkerInfo='+checkerData;
		
		var myAjax = new Ajax.Updater(
			'recepieContents', 
			url, 
			{
				method: 'post', 
				parameters: pars,
				onComplete: changeShowNumberOfPersonsDone
			});
			
		$('recepieNumberOfPersons').innerHTML = numberOfPersons;
		
		if (numberOfPersons == 1)
		{
			$('recepieNumberOfPersons_text').innerHTML = 'person';
		}
		else
		{
			$('recepieNumberOfPersons_text').innerHTML = 'personer';
		}
	}
	
	
	function changeShowNumberOfPersonsDone()
	{
		 new Effect.Highlight('recepieContents', { duration: 0.5 });
	}


	/*
	//	recepieDescriptions
	*/
	var newDescriptionsRowCounter = 0;
	function beginEditDescriptions(descriptionsList)
	{
		if(Element.visible('recepieDescriptionsButtons'))
		{
			alert('Du är redan i editera-läget för tillagningsstegen');
			
			//Sätter fokus på första elementet med recepieEditableText som klass
			setFirstElementFocusedByClassName(descriptionsList, 'recepieEditableText');
			
			return false;
		}

		Element.show('recepieDescriptionsHelp');

		var recipeId = recepieInfo['id'];
		var url = '/actions/get_recipe_descriptions.php';
		var pars = 'recipeId='+recipeId+'&markWords=0';
		
		var myAjax = new Ajax.Updater(
			'recepieDescriptions', 
			url, 
			{
				method: 'post', 
				parameters: pars,
				onComplete: function(originalRequest) {
				transformAllDescriptionsToInputs(descriptionsList);

				updateTabIndexes($('recepieCore'));
				
				//Sätter fokus på första elementet med recepieEditableText som klass
				setFirstElementFocusedByClassName(descriptionsList, 'recepieEditableText');
				
				}
			});

		return false;
	}
	
	function transformAllDescriptionsToInputs(descriptionsList)
	{
		var descriptionItems = descriptionsList.getElementsByTagName("li");
		Element.show('recepieDescriptionsButtons');
		
		newDescriptionsRowCounter = descriptionItems.length+1;
		
		for(i=0; i<descriptionItems.length; i++)
		{
			var descriptionItem = descriptionItems[i];

			//Tar reda på vilken typ av rad det är; description eller descriptionSubTitle
			if (Element.hasClassName(descriptionItem, 'recepieDescription'))
			{
				transformDescriptionToTextarea(descriptionItem, i);
			}
			else if (Element.hasClassName(descriptionItem, 'recepieDescriptionSubTitle'))
			{
				transformDescriptionSubRecepieTitleToInput(descriptionItem, i);
			}
			else if (Element.hasClassName(descriptionItem, 'tempRow'))
			{
				Element.remove(descriptionItem);
			}
		}
		
		//Lägger till ett antal tomma rader om det inte finns några alls
		if (descriptionItems.length == 0)
		{
			for(j=0; j<4; j++)
			{
				addEditDescriptionRow();
			}
		}
	}
	
	function transformDescriptionToTextarea(description, count)
	{
		var descriptionText = description.getElementsByClassName('description')[0].innerHTML;
		
		Element.removeClassName(description, 'recepieDescription');
		Element.addClassName(description, 'editableRecepieDescription');
		
		// Replace <br />, <BR> or <br> with line end. 
		descriptionText = descriptionText.replace(/<br>/g, "\n");
		descriptionText = descriptionText.replace(/<br \/>/g, "\n");
		descriptionText = descriptionText.replace(/<BR>/g, "\n");
		descriptionText = descriptionText.replace(/<BR \/>/g, "\n");
		// Replace all duplicates of line endings with ONE
		descriptionText = descriptionText.replace(/\n\n/g, "\n");
		descriptionText = descriptionText.replace(/\r\n/g, "\n");
		descriptionText = descriptionText.replace(/\r\r/g, "\n");

		description.innerHTML = getEditDescriptionHtml(descriptionText, count);
	}
	
	function transformDescriptionSubRecepieTitleToInput(title, count)
	{
		var subTitle = title.getElementsByTagName('h4')[0].innerHTML;
		
		Element.removeClassName(title, 'recepieDescriptionSubTitle');
		Element.addClassName(title, 'editableRecepieDescriptionSubTitle');
		
		title.innerHTML = getEditDescriptionSubTitleHtml(subTitle, count);
	}

	function getEditDescriptionHtml(descriptionText, count)
	{
		if (descriptionText == null) 		{ descriptionText = ""; 	}
	
		var tabindex = count*2;
		
		var output = '';
		output += '	<textarea tabindex="'+(tabindex+1)+'" name="descriptionText" class="descriptionText recepieEditableText input_text" onfocus="textInputFocus(this);" onblur="textInputBlur(this);">'+descriptionText+'</textarea>';
		output += '	<a href="/js" onclick="return removeRow(this);" class="icon delete" title="Ta bort tillagningssteg"><span>Ta bort tillagningssteg</span></a>';
		output += '	<a href="/js" onclick="return moveRowUp($(\'recepieDescriptions\'), this);" class="icon arrow_up" title="Flytta upp"><span>Flytta upp</span></a>';
		output += '	<a href="/js" onclick="return moveRowDown($(\'recepieDescriptions\'), this);" class="icon arrow_down" title="Flytta ner"><span>Flytta ner</span></a>';
		
		return output;
	}
	
	function getEditDescriptionSubTitleHtml(subTitle, count)
	{
		if (subTitle == null) 		{ subTitle = ""; 	}
	
		var tabindex = count*2;
		
		var output = '';
		output += '	<input tabindex="'+(tabindex+1)+'" name="subTitle" class="subTitle recepieEditableText input_text" onfocus="textInputFocus(this);" onblur="textInputBlur(this);" value="'+subTitle+'" />';
		output += '	<a href="/js" onclick="return removeRow(this);" class="icon delete" title="Ta bort tillagningssteg"><span>Ta bort tillagningssteg</span></a>';
		output += '	<a href="/js" onclick="return moveRowUp($(\'recepieDescriptions\'), this);" class="icon arrow_up" title="Flytta upp"><span>Flytta upp</span></a>';
		output += '	<a href="/js" onclick="return moveRowDown($(\'recepieDescriptions\'), this);" class="icon arrow_down" title="Flytta ner"><span>Flytta ner</span></a>';
		
		return output;
	}

	function addEditDescriptionRow()
	{
		newDescriptionsRowCounter++;	
		var html = getEditDescriptionHtml('', newDescriptionsRowCounter);
		html = '<li class="editableRecepieDescription">'+html+'</li>';
		addDescriptionRow(html);
	}
	
	function addEditDescriptionSubTitleRow()
	{
		newDescriptionsRowCounter++;
		var newRowId = 'recepieContentRow'+newRowCounter;
		var html = getEditContentSubRecepieTitleHtml('', newRowId);
		html = '<li class="editableRecepieDescriptionSubTitle" id="'+newRowId+'">'+html+'</li>';
		addDescriptionRow(html);
	}
	
	function addDescriptionRow(html)
	{
		new Insertion.Bottom($('recepieDescriptions'), html);
		
		updateTabIndexes($('recepieCore'));
	}
	
	function cancelEditDescriptions()
	{
		openYesNoDialogQuestionmark('Är du säker på att du vill avbryta?<br />Ej sparade tillagningssteg kommer att försvinna.', function() {
			var recipeId = recepieInfo['id'];
			var url = '/actions/get_recipe_descriptions.php';
			var pars = 'recipeId='+recipeId+'';
			
			var myAjax = new Ajax.Updater(
				'recepieDescriptions', 
				url, 
				{
					method: 'post', 
					parameters: pars
				});
			
			
			Element.hide('recepieDescriptionsButtons');
			Element.hide('recepieDescriptionsHelp');
			newDescriptionsRowCounter = 0;
			
			updateTabIndexes($('recepieCore'));
		});
		
		return false;
	}
	
	function saveDescriptions()
	{
	
		var descriptionsList = $('recepieDescriptions');
		var data = getDescriptionsInputData(descriptionsList);
		data = input2js(data);
		
		var recepieId = recepieInfo['id'];
		
		Element.hide('recepieDescriptionsButtons');
		Element.show('recepieDescriptionsLoading');
		$('recepieDescriptionsLoading').innerHTML = '<p class="center"><img src="/images/loading_wide.gif" /></p>';
		
		//Sparar alla descriptions
		var url = '/actions/save_recepie_descriptions.php';
		var pars = 'ajax=1&recepieId='+recepieId+'&data='+data;

		new Ajax.Request(url, {
				method: 'post', 
				parameters: pars,
				onComplete: descriptionsSaved
			});
		
	}
	
	function descriptionsSaved(originalRequest)
	{
		Element.hide('recepieDescriptionsLoading');
		Element.hide('recepieDescriptionsHelp');
		$('recepieDescriptions').innerHTML = originalRequest.responseText;
	}

	function getDescriptionsInputData(descriptionsList)
	{
		//Går igenom alla tillagningssteg
		var descriptionRows = descriptionsList.getElementsByTagName("li");
		
		//Skapar en array för att samla all data
		var descriptionRowsData = new Array();
		
		//Loopar igenom alla ingrediensrader
		for(i=0; i<descriptionRows.length; i++)
		{
			var descriptionRow = descriptionRows[i];
			
			var stepText = "";
			var isDivider = 0;
			
			var amountCheck = Element.select(descriptionRow, '.descriptionText');
			if (amountCheck.length > 0)
			{
				stepText = Element.select(descriptionRow, '.descriptionText')[0].value;
			}
			else
			{
				stepText = Element.select(descriptionRow, '.subTitle')[0].value;
				isDivider = 1;
			}
			
			descriptionRowsData[i] = {
				stepText: ''+stepText+'',
				isDivider: ''+isDivider+''
			};
		}
		
		var data = Object.toJSON(descriptionRowsData);
		return data;
	}
	
	/*
	//	recepieImages
	*/
	function changeMainImage(imageId, imageWidth, link)
	{
		deselectAllThumbs();
		Element.addClassName(link, 'active');
		
		var mainImage = $('recepieImage');
		mainImage.src = '/bilder/recept/'+imageId+'.jpg';
		
		var imageLink = $('recepieImageLink');
		imageLink.href = '/bilder/recept/'+imageId+'-stor.jpg';
		
		if (imageWidth > 580)
		{
			Element.addClassName(mainImage, 'recepieImageMaxWidth');
		}
		else
		{
			Element.removeClassName(mainImage, 'recepieImageMaxWidth');
		}
		
		$('recepieImageCredits').innerHTML = '<p class="center"><img src="/images/loading_wide.gif" /></p>';
		
		//Lägger in en timeout så folk fattar att ratingen laddas om
		setTimeout(function()
		{
			var pars = 'imageId='+imageId;
			new Ajax.Updater(
				'recepieImageCredits', 
				"/actions/get_image_credits.php", 
				{
					parameters: pars,
					method: 'post'
				});
		}, 100);

		return false;
	}
	
	function deselectAllThumbs()
	{
		var thumbList = $('recepieThumbImages');
		var thumbs = thumbList.getElementsByTagName('li');
		
		for(i=0; i<thumbs.length; i++)
		{
			var thumb = thumbs[i];
			var link = thumb.getElementsByTagName('a')[0];
			Element.removeClassName(link, 'active');
		}
	}
	
	/*
	//	recepieDifficulty
	*/
	
	function beginEditDifficulty()
	{	
		if ($('recepieDifficultyEdit').innerHTML.length == 0)
		{
			var output = '<span class="float_left padding4" style="margin-left: 5px;">Ändra till:</span>';
			output += '<select class="float_left margin2" id="difficulty_select" onchange="changeCurrentDisplayDifficulty(this.options[this.selectedIndex].value);" style="width: 200px;">';
			
			for(i=1; i<=5; i++)
			{
				output += '<option value="'+i+'"';
				
				if (i == recepieInfo['difficulty'])
					output += ' selected';
				
				output += '>'+i+' - '+js2html(difficultyTexts[i])+'</option>';
			}
						
			output += '</select>';

			output += '<a href="/js" onclick="return saveDifficulty();" style="margin-top: 2px;" class="save float_left" alt="Spara svårighetsgrad" title="Spara svårighetsgrad"><span>Spara svårighetsgrad</span></a>'; 
			output += '<a href="/js" onclick="return cancelDifficultyEdit()"; class="cancel float_left margin2" alt="Avbryt" title="Avbryt"><span>Avbryt</span></a>';
			
			$('recepieDifficultyEdit').innerHTML = output;
			
			recepieEditModes['difficulty'] = true;
		}
		else
		{
			alert('Du är redan i editera-läget!');
		}
		
		return false;
	}
	
	function changeCurrentDisplayDifficulty(difficulty)
	{
		if ($('recepieDifficultyEdit').innerHTML.length > 0)
		{
			changeCurrentDifficultyText(difficulty);
			setSelectedOptionByValue($('difficulty_select'), difficulty);
		
			var imageOutput = "";
			for(i=1; i<=5; i++)
			{
				var filename = "";
				if (i <= difficulty)
				{
					filename = "diff_"+i+".gif";
				}
				else if(i == 5)
				{
					filename = "diff_empty_last.gif";
				}
				else
				{
					filename = "diff_empty.gif";
				}
			
				imageOutput += '<img src="/images/difficulty/'+filename+'" onclick="changeCurrentDisplayDifficulty('+i+');" alt="Svårighetsgrad" />';
			}
			
			$('recepieDifficultyBarImage').innerHTML = imageOutput;
		}
		
		return false;
	}
	
	function changeCurrentDifficultyText(difficulty)
	{
		$('recepieDifficultyText').innerHTML = difficultyTexts[difficulty];
		return false;
	}
	
	function saveDifficulty()
	{
		recepieInfo['difficulty'] = $('difficulty_select').value;
		
		$('recepieDifficultyEdit').innerHTML = '<img src="/images/loading_wide.gif" /><br />Sparar...';
		
		setTimeout(function()
		{
			saveRecepieChange(recepieInfo, 'difficulty', 'difficultySaved');
		}, 600);
		
		return false;
	}
	
	function difficultySaved(originalRequest)
	{
		restoreDifficulty();
	}
	
	function cancelDifficultyEdit()
	{
		if ($('recepieDifficultyEdit').innerHTML.length > 0)
		{
			openYesNoDialogQuestionmark('Är du säker på att du vill avbryta?', function() {
				restoreDifficulty();
			});
		}
		
		return false;
	}
	
	function restoreDifficulty()
	{
		$('recepieDifficultyEdit').innerHTML = "";
		changeCurrentDisplayDifficulty(recepieInfo['difficulty']);
		recepieEditModes['difficulty'] = false;
	}
	
	/*
	//	recipeTags
	*/
	
	function beginEditTags()
	{
		if (!recepieEditModes['tags'])
		{
			var width = $('tags_edit').getWidth() + 50;
			
			if (width < 100)
			{
				width = 100;
			}
			else if (width > 175)
			{
				width = 175;
			}
		
			 var output = '<input id="tags_edit_input" value="'+js2input(recepieInfo['tags'])+'" class="float_left input_text" onfocus="textInputFocus(this);" onblur="textInputBlur(this);" style="width: 220px;" />';
			 output += '<a href="/js" onclick="return saveNewTags()" class="icon save"><span>Save</span></a>';
			 output += '<a href="/js" onclick="return cancelTagsEdit()" class="icon cancel"><span>Avbryt</span></a><br /><br /><br /><em>Separera med komma-tecken</em>';
			 $('tags_edit').innerHTML = output;
			recepieEditModes['tags'] = true;
		}
		else
		{
			alert('Du håller redan på och ändrar nyckelorden');
		}
		
		//Sätter fokus på första inputen
		setFirstElementFocused($('tags_edit'), 'input');
			
		return false;
	}

	function cancelTagsEdit()
	{
		if (recepieEditModes['tags'])
		{
			openYesNoDialogQuestionmark('Är du säker på att du vill avbryta?', function() {
				restoreTags();
			});

		}
		
		return false;
	}
	
	function restoreTags()
	{
		var tags = decodeURIComponent(recepieInfo['tags']);
		$('tags_edit').innerHTML = tagsStringToLinkString(tags);
		recepieEditModes['tags'] = false;
	}
	
	function saveNewTags()
	{
		if (recepieEditModes['tags'])
		{
			var tags_string = $('tags_edit_input').value;
			var return_tags_string = tagsStringToLinkString(tags_string);
			
			$('tags_edit').innerHTML = '<img src="/images/loading_wide.gif" /><br />Sparar...';
			
			var url = '/actions/set_recepie_categories.php';
			var pars = 'recepieId='+recepieInfo['id']+'&categories='+tags_string+'&ajax=1';
			
			setTimeout(function()
			{
				new Ajax.Request(url, {
						method: 'post', 
						parameters: pars,
						onComplete: tagsSaved
					});
			}, 600);

			recepieInfo['tags'] = input2js(tags_string);
		}
		
		return false;
	}
	
	function tagsSaved(originalRequest)
	{
		var response = originalRequest.responseText;
		if (response == "0")
		{
			alert('Du är inte inloggad!');
		}
		restoreTags();
	}

	function tagsStringToLinkString(tags_string)
	{
		var pieces = splitAndTrim(tags_string);
		var return_tags_string = "";
	
		for(i=0; i<pieces.length; i++)
		{
			piece = pieces[i];
			return_tags_string += '<a href="/search/?keywords='+piece+'" class="tag">'+js2html(piece)+'</a>';
			
			if (i != pieces.length-1)
			{
				return_tags_string += ', ';
			}
		}
		
		return return_tags_string;
	}
	
	
	
	
	function getTextareaSaveCancel(value, onsave, oncancel, textareaWidth)
	{
		if (textareaWidth == null)
		{
			textareaWidth = 280;
		}
	
		var html = '';
		html += '<textarea style="width: '+textareaWidth+'px; height: 80px; float: left;" class="input_text" onfocus="textInputFocus(this);" onblur="textInputBlur(this);">'+value+'</textarea>';
		html += '<a href="/js" class="icon save" onclick="'+onsave+'" title="Spara"><span>Spara</span></a>';
		html += '<a href="/js" class="icon cancel" onclick="'+oncancel+'" title="Avbryt"><span>Avbryt</span></a>';
		return html;
	}
	
	function getInputSaveCancel(value, onsave, oncancel, inputWidth)
	{
		if (inputWidth == null)
		{
			inputWidth = 280;
		}
	
		var html = '';
		html += '<input style="width: '+inputWidth+'px; float: left;" value="'+value+'" class="input_text" onfocus="textInputFocus(this);" onblur="textInputBlur(this);" />';
		html += '<a href="/js" class="icon save" onclick="'+onsave+'" title="Spara"><span>Spara</span></a>';
		html += '<a href="/js" class="icon cancel" onclick="'+oncancel+'" title="Avbryt"><span>Avbryt</span></a>';
		return html;
	}
	
	
	/*
	//	chefsComment
	*/
	function beginEditChefsComment(chefsCommentContainer)
	{
		var textarea = chefsCommentContainer.getElementsByTagName('textarea');

		Element.removeClassName(chefsCommentContainer, 'yellow_bg');

		//Om man inte redan är i editeraläget kör vi..
		if (textarea.length == 0)
		{
			var chefsComment = recepieInfo['outroText'];
			
			var html = getTextareaSaveCancel(js2textarea(chefsComment), "return saveEditChefsComment($('chefsComment'));", "return cancelEditChefsComment($('chefsComment'));");
			chefsCommentContainer.innerHTML = html;
		}
		else
		{
			alert('Du håller redan på och ändrar kockens kommentar');
		}
		
		//Sätter fokus på första inputen
		setFirstElementFocused(chefsCommentContainer, 'textarea');
		
		return false;
	}
	
	function saveEditChefsComment(chefsCommentContainer)
	{
		var textarea = chefsCommentContainer.getElementsByTagName('textarea')[0].value;
		chefsCommentContainer.innerHTML = '<img src="/images/loading_wide.gif" />';

		recepieInfo['outroText'] = input2js(textarea);

		setTimeout(function()
		{
			saveRecepieChange(recepieInfo, 'outroText', 'chefsCommentSaved');
		}, 600);

		return false;
	}
	
	function chefsCommentSaved(originalRequest)
	{
		if (originalRequest.responseText == "0")
		{
			alert('Du är inte inloggad!');
			return false;
		}
		
		$('chefsComment').innerHTML = originalRequest.responseText;
	}
	
	function cancelEditChefsComment(chefsCommentContainer)
	{
		openYesNoDialogQuestionmark('Är du säker på att du vill avbryta?', function() {
			chefsCommentContainer.innerHTML = js2html(recepieInfo['outroText']);
		});
		return false;
	}
	
	
	/*
	//	introText
	*/
	function beginEditIntroText(introTextContainer)
	{
		var editLink = $('introTextContainer').getElementsByClassName('edit')[0];
		Element.hide(editLink);
		
		Element.removeClassName($('theIntroText'), 'yellow_bg');
		
		var textarea = introTextContainer.getElementsByTagName('textarea');

		//Om man inte redan är i editeraläget kör vi..
		if (textarea.length == 0)
		{
			var introText = recepieInfo['introText'];
			var html = getTextareaSaveCancel(js2textarea(introText), "return saveEditIntroText($('theIntroText'));", "return cancelEditIntroText($('theIntroText'));", 350);
			introTextContainer.innerHTML = html;
			
			setFirstElementFocused(introTextContainer, 'textarea');
		}
		
		return false;
	}

	function saveEditIntroText(introTextContainer)
	{
		var textarea = introTextContainer.getElementsByTagName('textarea')[0].value;
		introTextContainer.innerHTML = '<img src="/images/loading_wide.gif" />';

		recepieInfo['introText'] = input2js(textarea);

		setTimeout(function()
		{
			saveRecepieChange(recepieInfo, 'introText', 'introTextSaved');
		}, 600);

		return false;
	}
	
	function introTextSaved(originalRequest)
	{
		var editLink = $('introTextContainer').getElementsByClassName('edit')[0];
		Element.show(editLink);
		
		if (originalRequest.responseText == "0")
		{
			alert('Du är inte inloggad!');
			return false;
		}
		
		$('theIntroText').innerHTML = originalRequest.responseText;//js2html(recepieInfo['introText']);
	}
	
	function cancelEditIntroText(introTextContainer)
	{
		openYesNoDialogQuestionmark('Är du säker på att du vill avbryta?', function() {
			var editLink = $('introTextContainer').getElementsByClassName('edit')[0];
			Element.show(editLink);
			
			introTextContainer.innerHTML = js2html(recepieInfo['introText']);
		});
	
		return false;
	}
	
	
	/*
	//	title
	*/
	function beginEditTitle(titleContainer)
	{
		var editLink = $('recepieTitle').getElementsByClassName('edit')[0];
		Element.hide(editLink);

		var input = titleContainer.getElementsByTagName('input');

		//Om man inte redan är i editeraläget kör vi..
		if (input.length == 0)
		{
			var title = recepieInfo['title'];
			var html = getInputSaveCancel(js2textarea(title), "return saveEditTitle($('theRecepieTitle'));", "return cancelEditTitle($('theRecepieTitle'));", 390);
			titleContainer.innerHTML = html;
			
			setFirstElementFocused(titleContainer, 'input');
		}
		
		return false;
	}

	function saveEditTitle(titleContainer)
	{
		var input = titleContainer.getElementsByTagName('input')[0].value;
		titleContainer.innerHTML = '<img src="/images/loading_wide.gif" />';

		recepieInfo['title'] = input2js(input);

		setTimeout(function()
		{
			saveRecepieChange(recepieInfo, 'title', 'titleSaved');
		}, 600);

		return false;
	}
	
	function titleSaved(originalRequest)
	{
		var editLink = $('recepieTitle').getElementsByClassName('edit')[0];
		Element.show(editLink);
		
		if (originalRequest.responseText == "0")
		{
			alert('Du är inte inloggad. Ändringen har INTE sparats!');
			return false;
		}
		
		$('theRecepieTitle').innerHTML = js2html(recepieInfo['title']);
	}
	
	function cancelEditTitle(titleContainer)
	{
		openYesNoDialogQuestionmark('Är du säker på att du vill avbryta?', function() {
			var editLink = $('recepieTitle').getElementsByClassName('edit')[0];
			Element.show(editLink);
			
			titleContainer.innerHTML = js2html(recepieInfo['title']);
		});

		return false;
	}
	
	function recepieParser()
	{
		var body = document.getElementsByTagName('body');
		body = body[0];
		
		var html = '<div id="recepieParser" style="position: absolute; border: 1px #CCCCCC; background: #F1F1F1; padding: 10px; right: 10px; top: 700px;">';

		html += 'Steps<br />';
		html += '<textarea style="width: 300px; height: 150px;" id="recepieParser_contents"></textarea><br /><br />';
		html += '<input type="button" value="Parse" onclick="return recepieContentsParse();" /><br /><br />';
		
		html += 'Descriptions<br />';
		html += '<textarea style="width: 300px; height: 150px;" id="recepieParser_descriptions"></textarea><br />';
		html += '<input type="button" value="Parse" onclick="return recepieDescriptionsParse();" />';

		html += '</div>'
		
		var insertion = new Insertion.Top(body, html);
		
		Element.scrollTo($('recepieParser'));
	}
	
	function recepieContentsParse()
	{
		var contents = $('recepieParser_contents').value;
		
		if (contents.length > 0)
		{
			if(Element.visible('recepieContentsButtons'))
			{
				var regex = null;
				var tl = new RegExp(/([\d,\.]+) ([\w\dåäöÅÄÖ%\/\(\), ]+)[\s]+([\w\dåäöÅÄÖ%\/\(\), ]+)\n?/g);
				
				if (contents.match(tl)) { regex = tl; }
				else { alert('Contents matchade ingenting!'); return false; }
				
				var myArray;
				while ((myArray = regex.exec(contents)) != null)
				{
					var html = getEditContentHtml(myArray[1], myArray[2], myArray[3]);
					html = '<li class="editableRecepieContent">'+html+'</li>';
					addContentRow(html);
				}
				
				$('recepieParser_contents').value = "";
			}
			else
			{
				alert('Du måste starta edit-läget för contents');
			}
		}
		else
		{
			alert('Tom contents-ruta?');
		}
	}
	
	function recepieDescriptionsParse()
	{
		var descriptions = $('recepieParser_descriptions').value;

		if (descriptions.length > 0)
		{
			if(Element.visible('recepieDescriptionsButtons'))
			{
				var regex = null;
				var ki = new RegExp(/\s+\d+\.\s+(.+)\n?/g);
				var tl = new RegExp(/\d\.\s+(.+)\n?/g);
				
				if (descriptions.match(ki)) { regex = ki; }
				if (descriptions.match(tl)) { regex = tl; }
				else { alert('Descriptions matchade ingenting!'); return false; }
				
				var myArray;
				while ((myArray = regex.exec(descriptions)) != null)
				{
					var msg = myArray[1];
					var html = getEditDescriptionHtml(msg);
					html = '<li class="editableRecepieDescription">'+html+'</li>';
					addDescriptionRow(html);
				}
				
				$('recepieParser_descriptions').value = "";
			}
			else
			{
				alert('Du måste starta edit-läget för descriptions');
			}
		}
		else
		{
			alert('Tom descriptions-ruta?');
		}

	}
	
	/*
	//	myRecipes
	*/	

	function doAddToMyRecipeCollection()
	{
		if ($('useExistingCollection_radio').getValue() == "useExisting" && $('addRecipeToCollection_form').collection.value == 0)
		{
			openAlertDialog('Du har inga samlingar i din receptbok än.<br /><strong>Du måste skapa en ny.</strong>');
			return false;	
		}
		
		if ($('createNewCollection_radio').getValue() == "createNew" && $('createNewCollection_input').getValue() == "")
		{
			openAlertDialog('Du måste skriva in ett namn för samlingen!');
			return false;		
		}
		addRecipeToCollection($('addRecipeToCollection_form'));
	} 
	

	function openAddToMyRecipesWindow(link, recipeId)
	{
		
		var html = '';
		
//		html += '<h3>Spara receptet i din receptbok</h3>';
		html += '<p class="padding4 center">Välj vilken samling du vill spara receptet till:</p>';
		
		html += '<form action="/actions/add_recipe_to_recipe_collection.php" method="post" id="addRecipeToCollection_form">';
		html += '<input name="recipeId" type="hidden" value="' + recipeId + '" />';
		html += '<fieldset>';
		
		html += '<div class="useExistingCollection">';
		html += '<input name="action" id="useExistingCollection_radio" value="useExisting" type="radio" class="radio" checked="checked" onfocus="$(\'useExistingCollection_select\').focus(); if($(\'createNewCollection_input\').value == \'\') { $(\'createNewCollection_input\').value = \'Skapa ny samling\'}" />';
		html += '<select name="collection" id="useExistingCollection_select" onfocus="$(\'useExistingCollection_radio\').checked = true; textInputFocus(this); if($(\'createNewCollection_input\').value == \'\') { $(\'createNewCollection_input\').value = \'Skapa ny samling\'}" onblur="textInputBlur(this);">';
		html += '	<option value="">Laddar...</option>';
		html += '</select>';
		html += '</div><br /><br />';
		html += 'eller..';
		html += '<div class="createNewCollection">';
		html += '<input name="action" id="createNewCollection_radio" value="createNew" type="radio" class="radio" onclick="$(\'createNewCollection_input\').focus();" />';
		html += '<input name="newCollectionName" id="createNewCollection_input" value="Skapa ny samling" type="text" class="text" onfocus="$(\'createNewCollection_radio\').checked = true; this.value = \'\'; textInputFocus(this);" onblur="textInputBlur(this);" />';
		html += '</div>';
		
		html += '</fieldset>';
		html += '</form>';
		
		html += '<p class="center"><input type="button" value="Spara" onclick="doAddToMyRecipeCollection();" /> <input type="button" value="Avbryt" onclick="CloseDialogBox();" /></p>';

		ShowDialogBox(html,{title: 'Spara receptet i din receptbok'});


		setTimeout(function()
		{
			var url = '/actions/get_user_recipe_collections.php';
			var pars = 'ajax=1';
			
			new Ajax.Request(url, {
					method: 'post', 
					parameters: pars,
					onComplete: function(request){
						collections = request.responseText.evalJSON(true);
						$('useExistingCollection_select').innerHTML = "";
						collections.each(function(collectionName){
							new Insertion.Bottom('useExistingCollection_select', '<option value="'+collectionName.tabId+'">'+collectionName.tabText+'</option>');
			            });
					}
				});
		}, 1000);
	
		return false;
	}
	
	function addRecipeToCollection(form)
	{
		form.request({
			onComplete: function(request){
				$('recipeCommunityInfo').innerHTML = '<img src="/images/recipeSavedInMyRecipes.gif" class="noborder" title="Receptet finns sparat i din receptbok" />';
				openAlertDialog('<img src="/images/icons/addressBook.gif" height="120" /><br /><p>Receptet är nu sparat i din <strong>receptbok</strong>!<br />Hela receptboken hittar du under "Mitt kök" i menyn.<br />Där kan du även lägga till externa recept från andra sidor.<br /><br /></p>');
				return false;
			}
		});
		
		return false;
	}

