// functions for recipe.php
function showRating(rating){
	for (i=1; i<=5; i++)
				{
					if (i<=rating) {
						document.getElementById(i + "forks").setAttribute("src", "http://www.grouprecipes.com/images/ratings/fork_on.gif");
					}
					else
						document.getElementById(i + "forks").setAttribute("src", "http://www.grouprecipes.com/images/ratings/fork_off.gif");
				}
	if (rating == 1){
		$('rating_desc').innerHTML='<span class="line_highlight">Didn\'t like it</span>';
	}else if(rating == 2){
		$('rating_desc').innerHTML='<span class="line_highlight">Mediocre</span>';
	}else if(rating == 3){
		$('rating_desc').innerHTML='<span class="line_highlight">Pretty good. Might make it again.</span>';
	}else if(rating ==4){
		$('rating_desc').innerHTML='<span class="line_highlight">Very good. Will make it again.</span>';
	}else{
		$('rating_desc').innerHTML='<span class="line_highlight">Simply PERFECT!</span>';
	}
}

// rate the recipe
function addRating(rating, recipeID){
	document.getElementById('rating_cell').style.display='block';
	document.getElementById('ratings_container').innerHTML = '<img src="http://www.grouprecipes.com/images/spinner.gif" alt="" />';
	// hold heigth
	$('ratings_container').style.minHeight='60px';
	new Ajax.Updater('ratings_container', 'http://www.grouprecipes.com/add_rating.php', {
		method: 'get',
		parameters: 'rating=' + rating + '&recipeID=' + recipeID,
		onComplete: function() {
			Element.setOpacity('ratings_container', 0.0); 
			Effect.Appear('ratings_container', { duration: 1.0 });
		}
	});
}

// edit comment
function editComment(commentID, userID, username, timestamp){
	comment = $('edit_comment_field_' + commentID).value;
	new Ajax.Updater('comment_' + commentID, 'http://www.grouprecipes.com/recipe_edit_comment.php', {
	method: 'get',
	parameters: 'commentID=' + commentID + '&userID=' + userID + '&comment=' + encodeURIComponent(comment) + '&username=' + username + '&date=' + timestamp,
	onComplete: editAdded
 });
	
	function editAdded(){
		new Effect.Highlight('comment_' + commentID, {startcolor:'#ffff99', endcolor:'#ffffff', duration:2.0});	
		$('wall_form_' + commentID).style.display='none';
	}
}

// get user's other recipes
function getUserRecipes(userID, recipeID, start, username){
	new Ajax.Updater('user_other_recipes', 'http://www.grouprecipes.com/profile_get_users_other_recipes.php', {
	method: 'get',
	parameters: 'userID=' + userID + '&recipeID=' + recipeID + '&start=' + start + '&username=' + username,
	onComplete: bringDown
	});
	function bringDown(){
		new Effect.SlideDown('user_other_recipes', {duration:0.5});
	}
}

// add a personal recipe note
function AddNote(recipeID) {
	document.getElementById('note-div').style.display='inline';
	document.getElementById('note-div').innerHTML = '<span class="loading-small">Submitting</span> <img src="http://www.grouprecipes.com/images/dot.gif" alt="" />';
    var note = document.getElementById('noteField').value;
	
	// validate
	  if (note == "") {
	document.getElementById("noteError").style.display = "inline";
	document.getElementById("noteField").select();
	document.getElementById("noteField").focus();
	  return;
	  } 
	  
	new Ajax.Request('http://www.grouprecipes.com/add_note.php', {
	method: 'get',
	parameters: 'recipeID=' + recipeID + '&note=' + encodeURIComponent(note),
	onComplete: noteFinished
 });
	
	function noteFinished(){
	$('note-div').innerHTML = '<img src="http://www.grouprecipes.com/images/tick.gif" style="vertical-align:text-bottom" alt="" /> <span class="green" style="font-weight:bold; padding-top:2px;">Note Added!</span>';    
	$('noteField').value = '';
	$('note').style.display='none';
	}
}

// add recipe to user group
function addGroup(recipeID) {
	document.getElementById('groups').style.display='block';
	document.getElementById('groups').innerHTML = '<img src="http://www.grouprecipes.com/images/fork_loading.gif" alt="" /> <span class="loading">Submitting</span>';
	var groupID = document.getElementById('groupID').value;
	new Ajax.Updater('groups', 'http://www.grouprecipes.com/add_group.php', {
	method: 'get',
	parameters: 'recipeID=' + recipeID + '&groupID=' + groupID
 });
}

// add flavor tags
function addFlavorTag(recipeID) {
	document.getElementById('flavortags').style.display='block';
	document.getElementById('flavortags').innerHTML = '<img src="http://www.grouprecipes.com/images/fork_loading.gif" alt="" /> <span class="loading">Submitting</span>';
	tags = document.getElementById("tagField").value;

	// validate
	if (tags == "") {
	document.getElementById("tagsError").style.display = "inline";
	document.getElementById("tagField").select();
	document.getElementById("tagField").focus();
	return;
	} 
	document.getElementById("tagsError").style.display = "none";
	new Ajax.Updater('flavortags', 'http://www.grouprecipes.com/add_flavor_tag.php', {
	method: 'get',
	parameters: 'tag=' + encodeURIComponent(tags) + '&recipeID=' + recipeID,
	onComplete: flavorTagAdded
	 });

	function flavorTagAdded(){
		tags = document.getElementById("tagField").value='';
		document.getElementById("addflavors").style.display='none';		
	}

}

// add recipe bookmark
function AddBookmark(recipeID) {
	document.getElementById('bookmark').style.display='inline';
	document.getElementById('bookmark').innerHTML = '<span class="loading-small">Submitting</span> <img src="http://www.grouprecipes.com/images/dot.gif" alt="" />';
	new Ajax.Updater('bookmark', 'http://www.grouprecipes.com/add_bookmark.php', {
	method: 'get',
	parameters: 'recipeID=' + recipeID
 });
}

// add recipe comment
function addComment(recipeID, owner_name, owner_userID, recipe_title) {
	$('comment_status').style.display='inline';
	$('comment_status').innerHTML = '<img src="http://www.grouprecipes.com/images/fork_loading.gif" alt="" /> <span class="loading">Submitting</span>';
    var comment = document.getElementById('commentField').value;

	// validate
	if (comment == "") {
		$("commentsError").style.display = "inline";
		$("commentField").select();
		$("commentField").focus();
		$('comment_status').innerHTML='';
		return;
	}
	$("commentsError").style.display = "none";

	new Ajax.Request('http://www.grouprecipes.com/recipe_post_comment.php', {
	method: 'get',
	parameters: 'recipeID=' + recipeID + '&owner_name=' + owner_name + '&comment=' + encodeURIComponent(comment) + '&recipe_title=' + encodeURIComponent(recipe_title),
	onComplete: function(response) {
		$('commentField').value ='';
		$('comment_status').innerHTML = '<img src="http://www.grouprecipes.com/images/tick.gif" alt="" /> <span class="green" style="font-weight:bold;">Comment Added!</span>';
		new Insertion.Bottom('comments', response.responseText);
		new Effect.Highlight('comment_status', {startcolor:'#ffff99', endcolor:'#ffffff'});				
		new Effect.Highlight('last_comment', {startcolor:'#ffff99', endcolor:'#ffffff', duration:2.0});
	}
 });
}

// add recipe alteration
function addAlterations(recipeID, owner_name, owner_userID, recipe_title) {
	$('alteration_status').style.display='inline';
	$('alteration_status').innerHTML = '<img src="http://www.grouprecipes.com/images/fork_loading.gif" alt="" /> <span class="loading">Submitting</span>';
    var alterations = $('alterationsField').value;

	// validate
	if (alterations == "") {
		document.getElementById("alterationsError").style.display = "inline";
		document.getElementById("alterationsField").select();
		document.getElementById("alterationsField").focus();
		$('alteration_status').innerHTML = '';
		return;
	}
	$("alterationsError").style.display = "none";

	new Ajax.Request('http://www.grouprecipes.com/recipe_post_alterations.php', {
	method: 'get',
	parameters: 'recipeID=' + recipeID + '&owner_name=' + owner_name + '&alterations=' + encodeURIComponent(alterations) + '&recipe_title=' + encodeURIComponent(recipe_title),
	onComplete: function(response) {
		$('alterationsField').value ='';
		$('alteration_status').innerHTML = '<img src="http://www.grouprecipes.com/images/tick.gif" alt="" /> <span class="green" style="font-weight:bold;">Alteration Added!</span>';
		new Insertion.Bottom('alterations', response.responseText);
		new Effect.Highlight('alteration_status', {startcolor:'#ffff99', endcolor:'#ffffff', duration:2.0});
		new Effect.Highlight('last_alteration', {startcolor:'#ffff99', endcolor:'#ffffff', duration:2.0});
	}
 });
}

// turn off stumbler
function killStumble(){
	new Ajax.Request('http://www.grouprecipes.com/clear_stumble.php', {
	method: 'get'
 });
}

// send recipe to friend on GroupRecipes
function toFriend(recipeID, recipe_title){
	document.getElementById('tofriend-div').innerHTML = '<span class="loading-small">Submitting</span> <img src="http://www.grouprecipes.com/images/dot.gif" alt="" />';
	to_friend = $('select_friend').value;
	message = $('tomessage').value;
	new Ajax.Updater('tofriend-div', 'http://www.grouprecipes.com/recipe_to_friend.php', {
	method: 'get',
	parameters: 'recipeID=' + recipeID + '&recipe_title=' + recipe_title + '&to_friend=' + to_friend + '&message=' + message,
	onComplete: document.getElementById('tofriend').style.display='none'
 });
}

// get form to forward recipe
function getForwardForm(userID, recipeID, recipe_title){
	document.getElementById('tofriend').style.display='block';
	new Ajax.Updater('tofriend', 'http://www.grouprecipes.com/recipe_forward_get_form.php', {
	method: 'get',
	parameters: 'userID=' + userID + '&recipeID=' + recipeID + '&recipe_title=' + recipe_title
 });
}

// stumbler index
function decreaseCount(current, url){
	new Ajax.Request('http://www.grouprecipes.com/stumbler_subtract.php', {
	method: 'get',
	parameters: 'current=' + current,
	onComplete: goTo(url)
  });
}

// stumbler index
function increaseCount(current, url){
	new Ajax.Request('http://www.grouprecipes.com/stumbler_add.php', {
	method: 'get',
	parameters: 'current=' + current,
	onComplete: goTo(url)
  });
}

function goTo(url){
	window.open('http://www.grouprecipes.com/' + url, '_self');
}

// subscribe to user who posted this recipe
function addSubscription(subscribe_to){
	document.getElementById('subscription').style.display='inline';
	document.getElementById('subscription').innerHTML = '<span class="loading-small">Submitting</span> <img src="http://www.grouprecipes.com/images/dot.gif" alt="" />';
	new Ajax.Updater('subscription', 'http://www.grouprecipes.com/add_subscription.php', {
	method: 'get',
	parameters: 'subscribe_to=' + subscribe_to
 });
}

// flag recipe as unique
function flag(recipeID){
	document.getElementById('flag').style.display='inline';
	document.getElementById('flag').innerHTML = '<span class="loading-small">Submitting</span> <img src="http://www.grouprecipes.com/images/dot.gif" alt="" />';
	new Ajax.Updater('flag', 'http://www.grouprecipes.com/flag.php', {
	method: 'get',
	parameters: 'recipeID=' + recipeID
 });
}

// who liked this recipe
function who(recipeID){
	document.getElementById('who-liked').style.display='block';
	document.getElementById('who-liked').innerHTML = '<img src="http://www.grouprecipes.com/images/fork_loading.gif" alt="" /> <span class="loading">Loading</span>';
	new Ajax.Updater('who-liked', 'http://www.grouprecipes.com/who_liked.php', {
	method: 'get',
	parameters: 'recipeID=' + recipeID,
	onComplete: document.getElementById('who-liked').style.display='block'
 });
}

// get recipe honors (pulled from cron job output)
function honors(recipeID, average, course, cuisine){
	document.getElementById('honors').style.display='block';
	document.getElementById('honors').innerHTML = '<img src="http://www.grouprecipes.com/images/fork_loading.gif" alt="" /> <span class="loading">Loading</span>';
	new Ajax.Updater('honors', 'http://www.grouprecipes.com/honors.php', {
	method: 'get',
	parameters: 'recipeID=' + recipeID + '&average=' + average + '&course=' + course + '&cuisine=' + cuisine,
	onComplete: document.getElementById('honors').style.display='block'
 });
}

// add to recipe comparison queue
function compare1(recipeID, compare1_title){
	$('compare_queue').style.display = 'block';
	$('compare_queue').innerHTML = '<img src="http://www.grouprecipes.com/images/fork_loading.gif" alt="" /> <span class="loading">Submitting</span>';
	new Ajax.Updater('compare_queue', 'http://www.grouprecipes.com/add_compare.php', {
	method: 'get',
	parameters: 'recipeID=' + recipeID + '&which=1&compare1_title=' + compare1_title,
	onComplete: $('add_queue').style.display='none'
 });
}

function clearCompare(){
	new Ajax.Updater('compare_queue', 'http://www.grouprecipes.com/clear_compare.php', {
	method: 'get'
	});
}

// stumble browse type, narrow or broad
function setDeviation(scope){
	new Ajax.Request('http://www.grouprecipes.com/set_deviation.php', {
	method: 'get',
	parameters: 'scope=' + scope
	});
}

// email recipe
function sendEmail(recipeID){
	document.getElementById('email-div').style.display='inline';
	document.getElementById('email').style.display='block';
	address = document.getElementById('address').value;
	document.getElementById('email-div').innerHTML = '<span class="loading-small">Submitting</span> <img src="http://www.grouprecipes.com/images/dot.gif" alt="" />';
	new Ajax.Updater('email-div', 'http://www.grouprecipes.com/send_recipe.php', {
	method: 'get',
	parameters: 'recipeID=' + recipeID + '&address=' + address,
	onComplete: document.getElementById('email').style.display='none'
 });
}

// get recipe compatibility
function suggestions(recipeID, cuisine, main_ingredient, viewing_title, tags, category, subcategory){
	document.getElementById('algo_div').innerHTML = '<div style="text-align:center;"><img src="http://www.grouprecipes.com/images/spinner.gif" alt="" /> <span class="loading green">Calculating Your Taste Compatibility. . .</span></div>';
	new Ajax.Updater('algo_div', 'http://www.grouprecipes.com/recipe_get_suggestion.php', {
	method: 'get',
	parameters: 'recipeID=' + recipeID + '&cuisine=' + encodeURIComponent(cuisine) + '&main_ingredient=' + encodeURIComponent(main_ingredient) + '&viewing_title=' + encodeURIComponent(viewing_title) + '&tags=' + encodeURIComponent(tags) + '&category=' + encodeURIComponent(category) + '&subcategory=' + encodeURIComponent(subcategory),
	onComplete: showResponse
	 });
}

function showResponse(){
	Element.setOpacity('algo_div', 0.0); 
	Effect.Appear('algo_div', { duration: 1.5 });
}

function helpSlide(){
	Effect.Appear('help', { duration: 1.0 });
}

// send recipe to cell phone
function mobileRecipe(){
	document.getElementById('phone-div').style.display='inline';
	document.getElementById('phone').style.display='block';
	gateway = document.getElementById('gateway').value;
	phone_number = document.getElementById('phone_number').value;
	recipeID = document.getElementById('recipeID').value;
	document.getElementById('phone').innerHTML = '<img src="http://www.grouprecipes.com/images/fork_loading.gif" alt="" /> <span class="loading">Sending</span>';
	new Ajax.Updater('phone-div', 'http://www.grouprecipes.com/phone.php', {
	method: 'get',
	parameters: 'recipeID=' + recipeID + '&phone_number=' + phone_number + '&gateway=' + gateway,
	onComplete: document.getElementById('phone').style.display='none'
 });
}

// body slides
function shrinkBody(id){
	new Effect.SlideUp(id, {duration: 0.3, fps:60, queue:'end', transition: Effect.Transitions.linear});
	$(id + '_div').innerHTML = '<img src="http://www.grouprecipes.com/images/bullet_arrow_down.gif" class="recipe_header_min" style="cursor:pointer; cursor:hand;" onclick="growBody(\'' + id + '\');">';
}
function growBody(id){
	new Effect.SlideDown(id, {duration: 0.3, fps:60, queue:'end', transition: Effect.Transitions.linear});
	$(id + '_div').innerHTML = '<img src="http://www.grouprecipes.com/images/bullet_arrow_up.gif" class="recipe_header_min" style="cursor:pointer; cursor:hand;" onclick="shrinkBody(\'' + id + '\');">';
}

function getRelated(title, main_ingredient, subcategory, course, recipeID) {
	$('see_more_related_status').show();
	new Ajax.Updater('see_more_related', 'http://www.grouprecipes.com/recipe_get_similar.php', {
		method: 'get',
		parameters: 'title=' + encodeURIComponent(title) + '&main_ingredient=' + main_ingredient + '&subcategory=' + subcategory + '&course=' + course + '&recipeID=' + recipeID,
		onComplete: function() {
			new Effect.Appear('see_more_related', {duration:1.5});
			$('see_more_related_status').hide();
		}
 	});
}	

function looksGood(answer, loggedin, recipeID) {
	$('looks_good_content').hide();
	if( loggedin == 'no' ){
		$('looks_good_content').innerHTML = '<span class="green">You tryin\' to get jive? You need to <a href="http://www.grouprecipes.com/login/">login.</a></span>';	
		new Effect.Appear('looks_good_content', {duration:1.0});
		return;
	}
	if( loggedin == 'yes'){
		new Ajax.Updater('looks_good_content', 'http://www.grouprecipes.com/recipe_looks_good.php', {
			method: 'get',
			parameters: 'recipeID=' + recipeID + '&answer=' + answer,
			onComplete: function() {
				new Effect.Appear('looks_good_content', {duration:1.0});
			}
		});	
	}
}

// validate comment form
 function checkForm() {
comments = document.getElementById("comments").value;

  if (comments == "") {
document.getElementById("commentsError").style.display = "inline";
document.getElementById("comments").select();
document.getElementById("comments").focus();
  return false;
  } 
  return true;
  } 
 function checkFormAlterations() {
alterations = document.getElementById("alterations").value;

  if (alterations == "") {
document.getElementById("alterationsError").style.display = "inline";
document.getElementById("alterations").select();
document.getElementById("alterations").focus();
  return false;
  } 
  return true;
  } 

  function hideAllErrors() {
document.getElementById("comments").style.display = "none"
  }

/* popit */
function popIt(URL,width,height) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=" + width + ",height= " + height + "');");
}

<!--
// preload fork
if (document.images)
{  
	todayimg = new Image(19,45); 
	todayimg.src="http://www.grouprecipes.com/images/ratings/fork_on.gif"; 
	
}
//-->