// JavaScript Document
/*if(user_id == '18489') {
	...
}*/
function select_all(id)
{
    $(id).focus();
    $(id).select();
}




var alertTimerId = 0;

function time_close_categories ( )
{
 
	// Start the timer
	clearTimeout ( alertTimerId );
	alertTimerId = setTimeout ( "hide_search_categories()", 2200 ); 
}
function hide_search_categories ( )
{
	Effect.Fade('search_categories_all');
}





function prep_text_field_focus(id, value) {
	
	if($(id).value == value) { $(id).value = ''; }
}
function prep_text_field_blur(id, value) {
	
	if($(id).value == '') { $(id).value = value; }
}

var matcher_method = "temp_epantry";
function set_matcher_method(method) {
	
	$('matcher_method').value = method;
	matcher_method = method;
	//alert(method);
	//show_primary_ingredient_list();
	if(method == "temp_epantry") { 
		show_this('temp_matcher_primary_ingredient');
		hide_this('matcher_primary_ingredient');
	}
	else if(method == "epantry") {
		show_this('matcher_primary_ingredient');
		hide_this('temp_matcher_primary_ingredient');
	}
}

var loading = "<div class=\"loading\">&nbsp;</div>";

function get_time() {
	
	var d = new Date();
	return d.getTime();	
}

function set_class(id, class_name) {
	
	$(id).className = class_name;
}

function fade_this(id) {
	Effect.Fade(id);	
}

function stop_promo() {
	clearTimeout ( promo_timer_id );	
}

var promo_timer_id = 0;
var promo_count = -1;
function start_promo ( )
{
 
	// Start the timer
	promo_count ++;
	if(promo_count == 1) { show_promo(2); }
	else if(promo_count == 2) { show_promo(3);}
	else if(promo_count == 3) { show_promo(4);}
	else if(promo_count == 4) { show_promo(1); promo_count = 0; }	
	promo_timer_id = setTimeout ( "start_promo()", 8000 ); 
}




var previous_promo = "1";
var number_of_promos = 4;
function show_promo(id) {
	
	set_class('promo_button' + previous_promo, 'promo_button');
	set_class('promo_button' + id, 'promo_button_selected');
	
	
	Effect.Fade('promo' + previous_promo);
	Effect.Appear('promo' + id, { queue: 'end' });
	
	previous_promo = id;

}


var previous_matcher_tab = '1';
function show_matcher_tab(id) {
	
	 
	if(id != previous_matcher_tab) {
		if(id == '1') { 
		
			set_class("matcher_tab_l_" + id, 'tab_left_left_selected');
			set_class('matcher_tab_c_' + id, 'tab_left_center_selected');
			set_class('matcher_tab_r_' + id, 'tab_left_right_selected');
			
			if(previous_matcher_tab == '1') {
				
				set_class("matcher_tab_l_" + previous_matcher_tab, 'tab_left_left');
				set_class('matcher_tab_c_' + previous_matcher_tab, 'tab_left_center');
				set_class('matcher_tab_r_' + previous_matcher_tab, 'tab_left_right');
			}
			else {
				
				set_class("matcher_tab_l_" + previous_matcher_tab, 'tab_regular_left');
				set_class('matcher_tab_c_' + previous_matcher_tab, 'tab_regular_center');
				set_class('matcher_tab_r_' + previous_matcher_tab, 'tab_regular_right');
			}
		}
		else {
			
			set_class("matcher_tab_l_" + id, 'tab_regular_left_selected');
			set_class('matcher_tab_c_' + id, 'tab_regular_center_selected');
			set_class('matcher_tab_r_' + id, 'tab_regular_right_selected');
			
			if(previous_matcher_tab == '1') {
				
				set_class("matcher_tab_l_" + previous_matcher_tab, 'tab_left_left');
				set_class('matcher_tab_c_' + previous_matcher_tab, 'tab_left_center');
				set_class('matcher_tab_r_' + previous_matcher_tab, 'tab_left_right');
			}
			else {
				
				set_class("matcher_tab_l_" + previous_matcher_tab, 'tab_regular_left');
				set_class('matcher_tab_c_' + previous_matcher_tab, 'tab_regular_center');
				set_class('matcher_tab_r_' + previous_matcher_tab, 'tab_regular_right');
			}
		}
	}
	
	
	
	/*Effect.Fade('matcher_panel_' + previous_matcher_tab);
	Effect.Appear('matcher_panel_' + id, { queue: 'end' });*/
	
	if((id == 1) || (id == 2)) {
		
		$('matcher_panel_0').style.display = "";
	}
	else {
		
		$('matcher_panel_0').style.display = "none";
	}
	
	$('matcher_panel_' + previous_matcher_tab).style.display = "none";
	$('matcher_panel_' + id).style.display = "";
	
	previous_matcher_tab = id;

}

function prep_field_focus(field, value) {
	
	Effect.Fade('ingredient_alert');
	Effect.BlindUp('ingredient_alert');
	if($(field).value == value) { $(field).value=''; }
}
function prep_field_loose_focus(field, value) {
	
	if($(field).value == '') { $(field).value=value; }
}

function set_username() {
	if(document.getElementById('username').value == '') {
		document.getElementById('username').className = 'username_clear';
	}
}

function reset_username() {
	if($('username').value == '') {
		document.getElementById('username').className = 'username';
	}
}
function set_password() {
	if(document.getElementById('password').value == '') {
		document.getElementById('password').className = 'password_clear';
	}
}

function reset_password() {
	if($('password').value == '') {
		document.getElementById('password').className = 'password';
	}
}
function clear_search() {
	if(document.getElementById('search').value == 'Search Recipes by Title') {
		document.getElementById('search').value = '';
	}
}
function reset_search() {
	if(document.getElementById('search').value == '') {
		document.getElementById('search').value = 'Search Recipes by Title';
	}
}


function submit_login_form() {
	
	//alert("called");
	var new_time = get_time();
		
	var username = $('username').value;
	var password = $('password').value;
		
	var url = base_url + '/system/application/ajax/sign_up.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'check_login', username: username, password: password, time: new_time },
		onComplete: showResponse 

	});
	
	function showResponse(req){
		//alert(req.responseText);
		if(req.responseText == "success") {
			document.login_form.submit();
		}
		else {
			$('signup_message').innerHTML = req.responseText;
			Effect.Appear('signup_message');
		}
	}
}

function search_epantry_primary_ingredients() {
	
	var new_time = get_time();
	var search_terms = $('epantry_primary_ingredient').value;
	
	if(search_terms == '') {
		$('epantry_primary_ingredient_list').style.display = 'none';
	}
	else {
		$('epantry_primary_ingredient_list').style.display = '';
		function showResponse(req){
			//alert(req.responseText);
			$('epantry_primary_ingredient_list').innerHTML = req.responseText;
		}
		
		var url = base_url + '/system/application/ajax/user.php';
		new Ajax.Request(url, {
			method: 'get',
			parameters: {do_this: 'search_epantry_primary_ingredients', search_terms: search_terms, user_id: user_id, time: new_time },
			onComplete: showResponse 
	
		});
		
		
	}
}

function clear_primary_ingredients() {
	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'clear_primary_ingredients', user_id: user_id, time: new_time },
		onComplete: showResponse 

	});
	
	function showResponse(req){
		//alert(req.responseText);
	}
}

function submit_register_form() {
	
	var submit_form = true;
	if(check_username() == "fail") { submit_form = false; }
	else if(check_vpassword() == "fail") { submit_form = false; }
	else if(check_email() == "fail") { submit_form = false; }
	else if(check_vemail() == "fail") { submit_form = false; }
	else if($('agree').checked == false) {
		
		submit_form = false; 
		$('agree_status').innerHTML = '<span class="signup_fail">You must agree to the terms and conditions!</span>';
		
	
	}
	if(submit_form == true) {
		document.signup_form.submit();
	}
		
}

function submitsearch()
{
  document.search_form.submit();
}

function check_username() {
	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/sign_up.php';
	var new_username = $('new_username').value;
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'check_username', username: new_username, time: new_time },
		onComplete: showResponse 

	});
	
	function showResponse(req){
		//alert(req.responseText);
		var split_result = req.responseText.split("|");
		var status = split_result[0];
		var result = split_result[1];
		$('username_check').innerHTML= result;
		
	}
}

function check_vpassword() {
	
	var new_time = get_time();
	var password = $('new_password').value;
	var vpassword = $('vpassword').value;
	
	if(password == '') {
		$('new_password_status').innerHTML = '<span class="signup_fail">Choose a password</span>';
		$('vpassword_status').innerHTML = '';
		return "fail";
	}
	else {
		
		if(vpassword == '') {
			$('new_password_status').innerHTML = '';
			$('vpassword_status').innerHTML = '<span class="signup_fail">Verify your password</span>';
			return "fail";
		}
		else if(password != vpassword) {
			$('vpassword_status').innerHTML = '<span class="signup_fail">do not match</span>';
			$('new_password_status').innerHTML = '<span class="signup_fail">do not match</span>';
			return "fail";
		}
		else {
			$('new_password_status').innerHTML = '<span class="signup_pass">&nbsp;</span>';
			$('vpassword_status').innerHTML = '<span class="signup_pass">&nbsp;</span>';
			return "success";
		}
	}
}

function check_email() {
	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/sign_up.php';
	var new_email = $('new_email').value;
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'check_email', new_email: new_email, time: new_time },
		onComplete: showResponse 

	});
	
	function showResponse(req){
		//alert(req.responseText);
		var split_result = req.responseText.split("|");
		var status = split_result[0];
		var result = split_result[1];
		$('email_status').innerHTML= result;
		return status;
		
	}
}

function check_vemail() {
	if(check_email() == "pass") {
		var email = $('new_email').value;
		var vemail = $('vemail').value;
		
		if(vemail == '') {
			$('vemail_status').innerHTML = '<span class="signup_fail">Verify email address</span>';
			return "fail";
		}
		else if(email != vemail) {
			$('vemail_status').innerHTML = '<span class="signup_fail">do not match</span>';
			$('email_status').innerHTML = '<span class="signup_fail">do not match</span>';
			return "fail";
		}
		else {
			$('vemail_status').innerHTML = '<span class="signup_pass">&nbsp;</span>';
			$('email_status').innerHTML = '<span class="signup_pass">&nbsp;</span>';
			return "success";
		}
	}
	else {
		HighlightEffect('email_status');
	}
}

function load_epantry(pantry_id) {
	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'load_epantry', user_id: user_id, pantry_id: pantry_id, time: new_time },
		onComplete: showResponse 

	});
	
	function showResponse(req){
		
		//alert(req.responseText);
		$('epantry').innerHTML= req.responseText;	
			
	}
}

function load_recipe(recipe_id, recalculate) {
	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/browse.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'load_recipe', user_id: user_id, recalculate: recalculate, recipe_id: recipe_id, time: new_time },
		onComplete: showResponse 

	});
	
	function showResponse(req){
		
		//alert(req.responseText);
		$('recipe_' + recipe_id).innerHTML= req.responseText;	
			
	}
}

function load_recipe_percentage(recipe_id, ingredient_id) {
	
	if($('recipe_ingredient_' + recipe_id + '_' + ingredient_id)) {
		toggle_this('recipe_ingredient_' + recipe_id + '_' + ingredient_id);
		toggle_this('recipe_ingredient_check_' + recipe_id + '_' + ingredient_id);
	}
	if($('recipe_ingredient_' + recipe_id + '_' + ingredient_id + '1')) {
		//alert("There's a second ingredient in this recipe");
		toggle_this('recipe_ingredient_' + recipe_id + '_' + ingredient_id + '1');
		toggle_this('recipe_ingredient_check_' + recipe_id + '_' + ingredient_id + '1');
	}
	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/browse.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'load_recipe_percentage', user_id: user_id, recipe_id: recipe_id, time: new_time },
		onComplete: showResponse 

	});
	
	function showResponse(req){
		
		//alert(req.responseText);
		$('recipe_percentage' + recipe_id).innerHTML= req.responseText;
		
		
	}
}

function load_recipe_temp_percentage(recipe_id, ingredient_id, method) {
	
	if($('recipe_ingredient_' + recipe_id + '_' + ingredient_id)) {
		toggle_this('recipe_ingredient_' + recipe_id + '_' + ingredient_id);
		toggle_this('recipe_ingredient_check_' + recipe_id + '_' + ingredient_id);
	}
	if($('recipe_ingredient_' + recipe_id + '_' + ingredient_id + '1')) {
		//alert("There's a second ingredient in this recipe");
		toggle_this('recipe_ingredient_' + recipe_id + '_' + ingredient_id + '1');
		toggle_this('recipe_ingredient_check_' + recipe_id + '_' + ingredient_id + '1');
	}
	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/browse.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'load_recipe_temp_percentage', user_id: user_id, method: method, recipe_id: recipe_id, time: new_time },
		onComplete: showResponse 

	});
	
	function showResponse(req){
		
		//alert(req.responseText);
		$('recipe_percentage' + recipe_id).innerHTML= req.responseText;
		
		
	}
}

function quick_update_epantry(ingredient_id, recipe_id) {
	
	var recipes = $('recipe_ids').innerHTML.split(",");
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'quick_update_epantry', user_id: user_id, ingredient_id: ingredient_id, recipe_id: recipe_id, time: new_time },
		onComplete: showResponse 

	});
	
	function showResponse(req){
		
		//alert(req.responseText);
		//alert("recipe count: " + recipes.length);
		for(i=0; i < recipes.length; i++) {
      		
			//alert("run: " + i + " recipe_id: " + recipes[i]);
			//alert(recipes[i]);
			load_recipe_percentage(recipes[i], ingredient_id);
			
 		}
		
		
	}
}

function quick_update_temp_epantry(ingredient_id, recipe_id) {
	
	var recipes = $('recipe_ids').innerHTML.split(",");
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'quick_update_temp_epantry', user_id: user_id, ingredient_id: ingredient_id, recipe_id: recipe_id, time: new_time },
		onComplete: showResponse 

	});
	
	function showResponse(req){
		
		//alert(req.responseText);
		for(i=0; i < recipes.length; i++) {
      	load_recipe_temp_percentage(recipes[i], ingredient_id, "temp_epantry");
			//alert(recipes[i]);
 		}
		
		
	}
}

/*function quick_update_epantry_add(ingredient_id, recipe_id) {
	
	var recipes = $('recipe_ids').innerHTML.split(",");
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'quick_update_epantry_add', user_id: user_id, ingredient_id: ingredient_id, recipe_id: recipe_id, time: new_time },
		onComplete: showResponse 

	});
	
	function showResponse(req){
		
		//alert(req.responseText);
		for(i=0; i < recipes.length; i++) {
      	load_recipe_temp_percentage(recipes[i], ingredient_id, "epantry");
			//alert(recipes[i]);
 		}
		
		
	}
}*/




function ScrollToElement(theElement, offset){

	if(offset == null) { var offset = 0; }
  /*var selectedPosX = 0;
  var selectedPosY = 0;
              
  while(theElement != null){
    selectedPosX += theElement.offsetLeft;
    selectedPosY += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }
                        		      
 window.scrollTo(selectedPosX - 100, selectedPosY - 100);*/
 Effect.ScrollTo(theElement, {offset: offset}); 

}


//document.recipematcher_form.submit();
function submit_recipematcher_home() {
	
	$('thinking').style.display = '';
	document.recipematcher_form.submit();
	/*var new_time = get_time();
	var url = base_url + '/system/application/ajax/user.php';
	function showResponse(req){
		
		alert(req.responseText);
		
		if(req.responseText != '') {
				
		}
		else { 
			$('thinking').style.display = 'none';
			Effect.ScrollTo('ad_unit', { queue: 'front', transition: Effect.Transitions.spring });
			Effect.Appear('ingredient_alert', { queue: 'end' });
		}
		
	}
	
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'check_home_ingredients', ip_address: ip_address, time: new_time},
		onComplete: showResponse

	});*/
		
		
}




var previous_pantry_id = 1;
function show_pantry_page(pantry_id) {
	
	load_epantry(pantry_id);
	document.getElementById('epantry_' + previous_pantry_id + '_span').style.color = '#aaaaaa';
	document.getElementById('epantry_' + pantry_id + '_span').style.color = '#3591f1';
	
	previous_pantry_id = pantry_id;

}

var previous_shopping_list_page = 'eshopping_list_1_div';
var previous_shopping_list_page_link = 'eshopping_list_1_span';
function show_shopping_list_page(page, page_link) {
	
	//document.getElementById(previous_page).style.display = 'none';
	//document.getElementById(page).style.display = '';
	var the_duration = 1;
	var y = 0;
	function do_animation()
	{
	  y++;
	  if(y == 1) { 
	  	Effect.BlindUp(previous_shopping_list_page, { duration: the_duration }); 
		Effect.Fade(previous_shopping_list_page, { duration: the_duration }); 
	  }
	  else if(y == 5) 
	  {
		 Effect.BlindDown(page, { duration: the_duration });
		  Effect.Appear(page, { duration: the_duration });
	  }  
	  if(y < 6) { setTimeout(do_animation, (the_duration * 250)); }
	}
	do_animation();
	
	document.getElementById(previous_shopping_list_page_link).style.color = '#aaaaaa';
	document.getElementById(page_link).style.color = '#3591f1';
	
	previous_shopping_list_page = page;
	previous_shopping_list_page_link = page_link;
}

function update_epantry(grocery_id, user_id, grocery_span, from_span){
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'update_epantry', grocery_id: grocery_id, user: user_id, time: new_time},
		onComplete: showResponse 

	});
	
	function showResponse(req){
		$('notice').innerHTML= req.responseText;
		
		if(from_span == 'from_span') {
			
			if($(grocery_id).checked == true) { $(grocery_span).className = "epantry_item_added"; }
			else if($(grocery_id).checked == false) { $(grocery_span).className = "epantry_item_deleted" ; }
		}
		else {
			//if from span
			if($(grocery_id).checked == true) { $(grocery_span).className = "epantry_item_deleted"; }
			else if($(grocery_id).checked == false) { $(grocery_span).className = "epantry_item_added"; }
			if($(grocery_id).checked == true) { $(grocery_id).checked = false; }
			else if($(grocery_id).checked == false) { $(grocery_id).checked = true; }
		}
		
	}
}

function update_eshopping_groceries(grocery_id, user_id, grocery_span, from_span){
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'update_eshopping_list_all', grocery_id: grocery_id, user: user_id, time: new_time},
		onComplete: showResponse 

	});
	
	function showResponse(req){
		$('notice').innerHTML= req.responseText;
		
		if(from_span == 'from_span') {
			
			//if from span
			if($(grocery_id).checked == true) { $(grocery_span).className = "eshopping_list_item_deleted"; }
			else if($(grocery_id).checked == false) { $(grocery_span).className = "eshopping_list_item_added"; }
			if($(grocery_id).checked == true) { $(grocery_id).checked = false; }
			else if($(grocery_id).checked == false) { $(grocery_id).checked = true; }
		}
		else {
			
			if($(grocery_id).checked == true) { $(grocery_span).className = "eshopping_list_item_added"; }
			else if($(grocery_id).checked == false) { $(grocery_span).className = "eshopping_list_item_deleted" ; }
		}
		
	}
}



function update_eshopping_list(grocery_id, user_id, method) {
	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'update_eshopping_list', grocery_id: grocery_id, user: user_id, time: new_time},
		onComplete: showResponse

	});
	
	function showResponse(req){
		$('eshopping_list').innerHTML= req.responseText;
		document.getElementById('shopping_list_textbox').value = '';
	}
}

function move_eshopping_list_to_pantry() {
	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'move_eshopping_list_to_pantry', user: user_id},
		onComplete: showResponse

	});
	
	function showResponse(req){
		$('eshopping_list').innerHTML= req.responseText;
		document.getElementById('shopping_list_textbox').value = '';
	}
}

function show_suggestions() {
	
	var value = document.getElementById('shopping_list_textbox').value;
	if(document.getElementById('shopping_list_textbox').value.length > 2) {
		
		document.getElementById('suggestions').style.display = "";
		document.getElementById('suggestions').style.position = 'absolute';
		document.getElementById('suggestions').style.top = document.getElementById('shopping_list_textbox').style.top;
		document.getElementById('suggestions').style.width = '400px';
		
		var new_time = get_time();
		
		var url = base_url + '/system/application/ajax/user.php';
		function showResponse(req){
			//alert("hello");
			$('suggestions').innerHTML= req.responseText;
		}
		
		
		new Ajax.Request(url, {
			method: 'get',
			parameters: {do_this: 'update_suggestions', value: value, user_id: user_id, time: new_time},
			onComplete: showResponse
	
		});
		
		
	}
	else {
		document.getElementById('suggestions').style.display = "none";
	}
	
}
function hide_suggestions() {
	
	document.getElementById('suggestions').style.display = "none";
	//Effect.Fade('suggestions', { duration: .5 }); 
}



function print_recipe(recipe_id, method)
{
	var new_time = get_time();
	var url = base_url + '/system/application/ajax/user.php';
	
	
	
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'print_recipe', recipe_id: recipe_id, method: method, user_id: user_id, time: new_time},
		onComplete: showResponse

	});
	
	function showResponse(req){
		//alert(req.responseText);
		var a = window.open('','','width=950,height=700');
		a.document.open("text/html");
		a.document.write(req.responseText);
		
		a.print();
	}
	
}




function fade_to(from_this, to_this, the_duration)
{
   var y = 0;
   function do_animation()
   {
      y++;
      if(y == 1) { Effect.Fade(from_this, { duration: the_duration }); }
      else if(y == 5) 
      {
         Effect.Appear(to_this, { duration: the_duration });
      }  
      if(y < 6) { setTimeout(do_animation, (the_duration * 250)); }
   }
   do_animation();
}

function show_hide_sr_suggestions() {

	if(document.getElementById('suggestion_input').style.display == "") {
		
		document.getElementById('suggestion_input').style.display = 'none';
		document.getElementById('suggestions').style.display = 'none';
		
	}
	else {
		
		show_sr_suggestions();
	}
}
function show_sr_suggestions() {
	
	document.getElementById('suggestion_input').style.display = "";
	if((document.getElementById('ingredient_textbox').value.length > 2) || ((document.getElementById('ingredient_textbox').value.length == 0))) {
		
		document.getElementById('ingredient_textbox').focus();
		
	
		var value = document.getElementById('ingredient_textbox').value;
		document.getElementById('suggestions').style.display = "";
		document.getElementById('suggestions').style.position = 'absolute';
		document.getElementById('suggestions').style.top = document.getElementById('suggestion_input').style.top;
		document.getElementById('suggestions').style.width = '475px';
		
		var new_time = get_time();
		
		var url = base_url + '/system/application/ajax/user.php';
		function showResponse(req){
			//alert("hello");
			$('suggestions').innerHTML= req.responseText;
		}
		
		
		new Ajax.Request(url, {
			method: 'get',
			parameters: {do_this: 'update_sr_suggestions', value: value, user_id: user_id, time: new_time},
			onComplete: showResponse
	
		});
	}
		
	/*}
	else {
		document.getElementById('suggestions').style.display = "none";
	}*/
}

function update_sr_ingredients (grocery_id, user_id) {
	
	//alert(user_id);
	var new_time = get_time();
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'update_sr_ingredients', grocery_id: grocery_id, user: user_id, time: new_time},
		onComplete: showResponse

	});
	
	function showResponse(req){
		$('ingredients').innerHTML= req.responseText;
		document.getElementById('ingredient_textbox').value = '';
		document.getElementById('suggestion_input').style.display = 'none';
		
		
	}
}



function update_sr_ingredients_amount (grocery_id, amount_id) {
	
	var amount = $(amount_id).value;
	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'update_sr_ingredients_amount', user: user_id, amount: amount, grocery_id: grocery_id, time: new_time},
		onComplete: showResponse

	});
	
	function showResponse(req){
		//$('ingredients').innerHTML= req.responseText;
		document.getElementById('ingredient_textbox').value = '';
		document.getElementById('suggestion_input').style.display = 'none';
		
		
	}
}

function update_sr_ingredients_prep (grocery_id, prep_id) {
	
	var prep = $(prep_id).value;
	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'update_sr_ingredients_prep', prep: prep, grocery_id: grocery_id, user: user_id, time: new_time},
		onComplete: showResponse

	});
	
	function showResponse(req){
		//$('ingredients').innerHTML= req.responseText;
		document.getElementById('ingredient_textbox').value = '';
		document.getElementById('suggestion_input').style.display = 'none';
		
		
	}
}

function show_sr_ingredients() {

	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'show_sr_ingredients', user: user_id, time: new_time},
		onComplete: showResponse

	});
	
	function showResponse(req){
		$('ingredients').innerHTML= req.responseText;
		document.getElementById('ingredient_textbox').value = '';
		document.getElementById('suggestion_input').style.display = 'none';
		
		
	}
}

function update_home_ingredients_epantry(option) {
	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	
	
	
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'update_home_ingredients_epantry', option: option, user_id: user_id, time: new_time},
		onComplete: showResponse

	});
	
	function showResponse(req){
		//$('ingredients').innerHTML= req.responseText;
		//alert(req.responseText);
	}
}
function show_home_ingredients() {
	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	
	
	
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'show_home_ingredients', ip_address: ip_address, user_id: user_id, time: new_time},
		onComplete: showResponse

	});
	
	function showResponse(req){
		$('ingredients').innerHTML= req.responseText;
		//alert(req.responseText);
	}
}

function include_common_ingredients_home() {
	
	var new_time = get_time();
	var add_remove = 'remove';
	if($('include_common_ingredients').checked == true) { add_remove = 'add'; }
	var url = base_url + '/system/application/ajax/user.php';
	
	
	
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'include_common_ingredients_home', add_remove: add_remove, time: new_time},
		onComplete: showResponse

	});
	
	function showResponse(req){
		//$('ingredients').innerHTML= req.responseText;
		//alert(req.responseText);
	}
}


function update_home_suggestions() {
	
	if(document.getElementById('new_ingredient').value.length > 2) {
		
		document.getElementById('new_ingredient').focus();
		
		var value = document.getElementById('new_ingredient').value;
		document.getElementById('suggestions').style.display = "";
		document.getElementById('suggestions').style.width = '350px';
		
		var new_time = get_time();
		
		var url = base_url + '/system/application/ajax/user.php';
		function showResponse(req){
			$('suggestions').innerHTML= req.responseText;
			
		}
		
		new Ajax.Request(url, {
			method: 'get',
			parameters: {do_this: 'update_home_suggestions', value: value, ip_address: ip_address, user_id: user_id, time: new_time},
			onComplete: showResponse
	
		});
	}
	else if (document.getElementById('new_ingredient').value.length == 0) {
		
		document.getElementById('suggestions').style.display = "none";
		//hide_home_suggestions();
	}
}

function update_home_ingredients(grocery_id) {
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
		//alert("update called");
		
		function showResponse(req){
			//alert("hello");
			$('ingredients').innerHTML= req.responseText;
			document.getElementById('new_ingredient').value = '';
			document.getElementById('new_ingredient').focus();
			hide_home_suggestions();
			show_primary_ingredient_list();
		}
		
		new Ajax.Request(url, {
			method: 'get',
			parameters: {do_this: 'update_home_ingredients', grocery_id: grocery_id, ip_address: ip_address, user_id: user_id, time: new_time},
			onComplete: showResponse	
		});
}

function hide_home_suggestions() {
	
	//Effect.BlindUp('suggestions');
	document.getElementById('suggestions').style.display = "none";
}

function set_cuisine(value) {
	
	
	//alert("ok");
	if(value == parseInt(value)) {
		
		$('all').checked = false;
	}
	else {
		
		$('recipematcher_form').getInputs('checkbox').invoke('setValue', false);
		$('all').checked = true;
	}
}

function show_primary_ingredient_list() {

	//alert("called");
	//alert(ip_address);
	var new_time = get_time();
	
	var url = base_url + '/system/application/ajax/user.php';
	function showResponse(req){
		$('primary_ingredient_list').innerHTML= req.responseText;
		$('primary_ingredient_list').style.display = '';
		
	}
	
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'show_primary_ingredients_list', matcher_method: matcher_method, ip_address: ip_address, user_id: user_id, time: new_time},
		onComplete: showResponse

	});
		
		
	
}

function update_home_primary_ingredient(grocery_id) {
	
	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'update_home_primary_ingredient', grocery_id: grocery_id, matcher_method: matcher_method, ip_address: ip_address, user_id: user_id, time: new_time},
		onComplete: showResponse

	});
	
	function showResponse(req){
		//alert(req.responseText);
		if(matcher_method == "temp_epantry") {
			show_primary_ingredient_list();
		}
		else if(matcher_method == "epantry") {
			$('epantry_primary_ingredient').value= req.responseText;
		}
		
		$('home_search_button').style.display = '';
		
	}
}




function tease_review(number, source) {
	
	if(number == 1) {
		$('review_star1').src = source+"star.jpg";
		$('review_star2').src = source+"star_blank.jpg";
		$('review_star3').src = source+"star_blank.jpg";
		$('review_star4').src = source+"star_blank.jpg";
		$('review_star5').src = source+"star_blank.jpg";
	}
	else if(number == 2) {
		$('review_star1').src = source+"star.jpg";
		$('review_star2').src = source+"star.jpg";
		$('review_star3').src = source+"star_blank.jpg";
		$('review_star4').src = source+"star_blank.jpg";
		$('review_star5').src = source+"star_blank.jpg";
	}
	else if(number == 3) {
		$('review_star1').src = source+"star.jpg";
		$('review_star2').src = source+"star.jpg";
		$('review_star3').src = source+"star.jpg";
		$('review_star4').src = source+"star_blank.jpg";
		$('review_star5').src = source+"star_blank.jpg";
	}
	else if(number == 4) {
		$('review_star1').src = source+"star.jpg";
		$('review_star2').src = source+"star.jpg";
		$('review_star3').src = source+"star.jpg";
		$('review_star4').src = source+"star.jpg";
		$('review_star5').src = source+"star_blank.jpg";
	}
	else if(number == 5) {
		$('review_star1').src = source+"star.jpg";
		$('review_star2').src = source+"star.jpg";
		$('review_star3').src = source+"star.jpg";
		$('review_star4').src = source+"star.jpg";
		$('review_star5').src = source+"star.jpg";
	}
}

function tease_review_reset(source) {
	$('review_star1').src = source+"star_blank.jpg";
	$('review_star2').src = source+"star_blank.jpg";
	$('review_star3').src = source+"star_blank.jpg";
	$('review_star4').src = source+"star_blank.jpg";
	$('review_star5').src = source+"star_blank.jpg";
}


function tease_review2(number, source) {
	if(number == .5) {
		$('review_star11').src = source+"star_half_left_big.jpg";
		$('review_star12').src = source+"star_blank_half_right_big.jpg";
		$('review_star21').src = source+"star_blank_half_left_big.jpg";
		$('review_star22').src = source+"star_blank_half_right_big.jpg";
		$('review_star31').src = source+"star_blank_half_left_big.jpg";
		$('review_star32').src = source+"star_blank_half_right_big.jpg";
		$('review_star41').src = source+"star_blank_half_left_big.jpg";
		$('review_star42').src = source+"star_blank_half_right_big.jpg";
		$('review_star51').src = source+"star_blank_half_left_big.jpg";
		$('review_star52').src = source+"star_blank_half_right_big.jpg";
		$('rating_number').innerHTML = "<span style=\"color:#FF0000; font-size:12px;\">Very Poor</span>";
	}
	else if(number == 1) {
		$('review_star11').src = source+"star_half_left_big.jpg";
		$('review_star12').src = source+"star_half_right_big.jpg";
		$('review_star21').src = source+"star_blank_half_left_big.jpg";
		$('review_star22').src = source+"star_blank_half_right_big.jpg";
		$('review_star31').src = source+"star_blank_half_left_big.jpg";
		$('review_star32').src = source+"star_blank_half_right_big.jpg";
		$('review_star41').src = source+"star_blank_half_left_big.jpg";
		$('review_star42').src = source+"star_blank_half_right_big.jpg";
		$('review_star51').src = source+"star_blank_half_left_big.jpg";
		$('review_star52').src = source+"star_blank_half_right_big.jpg";
		$('rating_number').innerHTML = "<span style=\"color:#cc2500; font-size:12px;\">Not So Good</span>";
	}
	else if(number == 1.5) {
		$('review_star11').src = source+"star_half_left_big.jpg";
		$('review_star12').src = source+"star_half_right_big.jpg";
		$('review_star21').src = source+"star_half_left_big.jpg";
		$('review_star22').src = source+"star_blank_half_right_big.jpg";
		$('review_star31').src = source+"star_blank_half_left_big.jpg";
		$('review_star32').src = source+"star_blank_half_right_big.jpg";
		$('review_star41').src = source+"star_blank_half_left_big.jpg";
		$('review_star42').src = source+"star_blank_half_right_big.jpg";
		$('review_star51').src = source+"star_blank_half_left_big.jpg";
		$('review_star52').src = source+"star_blank_half_right_big.jpg";
		$('rating_number').innerHTML = "<span style=\"color:#9e4600; font-size:12px;\">Edible</span>";
	}
	else if(number == 2) {
		$('review_star11').src = source+"star_half_left_big.jpg";
		$('review_star12').src = source+"star_half_right_big.jpg";
		$('review_star21').src = source+"star_half_left_big.jpg";
		$('review_star22').src = source+"star_half_right_big.jpg";
		$('review_star31').src = source+"star_blank_half_left_big.jpg";
		$('review_star32').src = source+"star_blank_half_right_big.jpg";
		$('review_star41').src = source+"star_blank_half_left_big.jpg";
		$('review_star42').src = source+"star_blank_half_right_big.jpg";
		$('review_star51').src = source+"star_blank_half_left_big.jpg";
		$('review_star52').src = source+"star_blank_half_right_big.jpg";
		$('rating_number').innerHTML = "<span style=\"color:#696b00; font-size:12px;\">Not bad</span>";
	}
	else if(number == 2.5) {
		$('review_star11').src = source+"star_half_left_big.jpg";
		$('review_star12').src = source+"star_half_right_big.jpg";
		$('review_star21').src = source+"star_half_left_big.jpg";
		$('review_star22').src = source+"star_half_right_big.jpg";
		$('review_star31').src = source+"star_half_left_big.jpg";
		$('review_star32').src = source+"star_blank_half_right_big.jpg";
		$('review_star41').src = source+"star_blank_half_left_big.jpg";
		$('review_star42').src = source+"star_blank_half_right_big.jpg";
		$('review_star51').src = source+"star_blank_half_left_big.jpg";
		$('review_star52').src = source+"star_blank_half_right_big.jpg";
		$('rating_number').innerHTML = "<span style=\"color:#2f9000; font-size:12px;\">Pretty Good</span>";
	}
	else if(number == 3) {
		$('review_star11').src = source+"star_half_left_big.jpg";
		$('review_star12').src = source+"star_half_right_big.jpg";
		$('review_star21').src = source+"star_half_left_big.jpg";
		$('review_star22').src = source+"star_half_right_big.jpg";
		$('review_star31').src = source+"star_half_left_big.jpg";
		$('review_star32').src = source+"star_half_right_big.jpg";
		$('review_star41').src = source+"star_blank_half_left_big.jpg";
		$('review_star42').src = source+"star_blank_half_right_big.jpg";
		$('review_star51').src = source+"star_blank_half_left_big.jpg";
		$('review_star52').src = source+"star_blank_half_right_big.jpg";
		$('rating_number').innerHTML = "<span style=\"color:#169616; font-size:12px;\">Good</span>";
	}
	else if(number == 3.5) {
		$('review_star11').src = source+"star_half_left_big.jpg";
		$('review_star12').src = source+"star_half_right_big.jpg";
		$('review_star21').src = source+"star_half_left_big.jpg";
		$('review_star22').src = source+"star_half_right_big.jpg";
		$('review_star31').src = source+"star_half_left_big.jpg";
		$('review_star32').src = source+"star_half_right_big.jpg";
		$('review_star41').src = source+"star_half_left_big.jpg";
		$('review_star42').src = source+"star_blank_half_right_big.jpg";
		$('review_star51').src = source+"star_blank_half_left_big.jpg";
		$('review_star52').src = source+"star_blank_half_right_big.jpg";
		$('rating_number').innerHTML = "<span style=\"color:#07925b; font-size:12px;\">Very Good</span>";
	}
	else if(number == 4) {
		$('review_star11').src = source+"star_half_left_big.jpg";
		$('review_star12').src = source+"star_half_right_big.jpg";
		$('review_star21').src = source+"star_half_left_big.jpg";
		$('review_star22').src = source+"star_half_right_big.jpg";
		$('review_star31').src = source+"star_half_left_big.jpg";
		$('review_star32').src = source+"star_half_right_big.jpg";
		$('review_star41').src = source+"star_half_left_big.jpg";
		$('review_star42').src = source+"star_half_right_big.jpg";
		$('review_star51').src = source+"star_blank_half_left_big.jpg";
		$('review_star52').src = source+"star_blank_half_right_big.jpg";
		$('rating_number').innerHTML = "<span style=\"color:#03878f; font-size:12px;\">Delicious</span>";
	}
	else if(number == 4.5) {
		$('review_star11').src = source+"star_half_left_big.jpg";
		$('review_star12').src = source+"star_half_right_big.jpg";
		$('review_star21').src = source+"star_half_left_big.jpg";
		$('review_star22').src = source+"star_half_right_big.jpg";
		$('review_star31').src = source+"star_half_left_big.jpg";
		$('review_star32').src = source+"star_half_right_big.jpg";
		$('review_star41').src = source+"star_half_left_big.jpg";
		$('review_star42').src = source+"star_half_right_big.jpg";
		$('review_star51').src = source+"star_half_left_big.jpg";
		$('review_star52').src = source+"star_blank_half_right_big.jpg";
		$('rating_number').innerHTML = "<span style=\"color:#0276d2; font-size:12px;\">Excellent!</span>";
	}
	else if(number == 5) {
		$('review_star11').src = source+"star_half_left_big.jpg";
		$('review_star12').src = source+"star_half_right_big.jpg";
		$('review_star21').src = source+"star_half_left_big.jpg";
		$('review_star22').src = source+"star_half_right_big.jpg";
		$('review_star31').src = source+"star_half_left_big.jpg";
		$('review_star32').src = source+"star_half_right_big.jpg";
		$('review_star41').src = source+"star_half_left_big.jpg";
		$('review_star42').src = source+"star_half_right_big.jpg";
		$('review_star51').src = source+"star_half_left_big.jpg";
		$('review_star52').src = source+"star_half_right_big.jpg";
		$('rating_number').innerHTML = "<span style=\"color:#006cff; font-size:12px;\">Awesome!</span>";
	}
	
}

function tease_review_reset2(source) {
	$('review_star11').src = source+"star_blank_half_left_big.jpg";
	$('review_star12').src = source+"star_blank_half_right_big.jpg";
	$('review_star21').src = source+"star_blank_half_left_big.jpg";
	$('review_star22').src = source+"star_blank_half_right_big.jpg";
	$('review_star31').src = source+"star_blank_half_left_big.jpg";
	$('review_star32').src = source+"star_blank_half_right_big.jpg";
	$('review_star41').src = source+"star_blank_half_left_big.jpg";
	$('review_star42').src = source+"star_blank_half_right_big.jpg";
	$('review_star51').src = source+"star_blank_half_left_big.jpg";
	$('review_star52').src = source+"star_blank_half_right_big.jpg";
	
		$('rating_number').innerHTML = "<span style=\"color:#777777; font-size:12px;\">Click stars to rate</span>";
}

function submit_written_recipe_review() {
	
	
	//alert("called");
	var recipe_id = $('recipe_id').value;
	var review = $('new_review').value;
	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'submit_written_recipe_review', recipe_id: recipe_id, review: review, user_id: user_id, time: new_time},
		onComplete: showResponse 

	});
	
	function showResponse(req){
		
		//alert(req.responseText);
		toggle_this('pre_review');
		toggle_this('submit_success');
		
		
	}
}

var recipe_rated = false;
function submit_review_check() {
	
	if(recipe_rated == true) {
		
		//document.review_form.submit();
		submit_written_recipe_review();
	}
	else{
		
		/*new Effect.Highlight('pre_rating', 
		{
			startcolor: "#FF0000",
			endcolor: "#ffffff",
			restorecolor: "#ffffff",
			duration: 1
		});*/
		
		
		Effect.Shake('pre_rating', {duration: 1, distance: 30});		
		
		hide_this('pre_review_submit'); 
		show_this('review_submit');
	}
}



function rate_recipe(recipe_id, user_id, rating, source) {
	
	var new_time = get_time();
	
	var url = base_url + '/system/application/ajax/user.php';
	
	function showResponse(req){
		
		
		if(rating == 1) {
			
			$('final_star1').src = source+"star.jpg";
			$('final_star2').src = source+"star_blank.jpg";
			$('final_star3').src = source+"star_blank.jpg";
			$('final_star4').src = source+"star_blank.jpg";
			$('final_star5').src = source+"star_blank.jpg";
		}
		else if(rating == 2) {
			
			$('final_star1').src = source+"star.jpg";
			$('final_star2').src = source+"star.jpg";
			$('final_star3').src = source+"star_blank.jpg";
			$('final_star4').src = source+"star_blank.jpg";
			$('final_star5').src = source+"star_blank.jpg";
		}
		else if(rating == 3) {
			
			$('final_star1').src = source+"star.jpg";
			$('final_star2').src = source+"star.jpg";
			$('final_star3').src = source+"star.jpg";
			$('final_star4').src = source+"star_blank.jpg";
			$('final_star5').src = source+"star_blank.jpg";
		}
		else if(rating == 4) {
			
			$('final_star1').src = source+"star.jpg";
			$('final_star2').src = source+"star.jpg";
			$('final_star3').src = source+"star.jpg";
			$('final_star4').src = source+"star.jpg";
			$('final_star5').src = source+"star_blank.jpg";
		}
		else if(rating == 5) {
			
			$('final_star1').src = source+"star.jpg";
			$('final_star2').src = source+"star.jpg";
			$('final_star3').src = source+"star.jpg";
			$('final_star4').src = source+"star.jpg";
			$('final_star5').src = source+"star.jpg";
		}
		$('pre_rating').style.display = "none";
		$('rating').style.display = "";
		//alert(req.responseText);
	}
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'rate_recipe', recipe_id: recipe_id, user_id: user_id, rating: rating, time: new_time },
		onComplete: showResponse

	});
}

function rate_recipe2(recipe_id, user_id, rating, source) {
	
	//alert(recipe_id); alert(user_id); alert(rating); alert(source);
	var new_time = get_time();
	recipe_rated = true;
	//alert(rating);
	var url = base_url + '/system/application/ajax/user.php';
	
	function showResponse(req){
		
		//alert(req.responseText);
		if(rating == .5) {
			$('final_star11').src = source+"star_half_left_big.jpg";
			$('final_star12').src = source+"star_blank_half_right_big.jpg";
			$('final_star21').src = source+"star_blank_half_left_big.jpg";
			$('final_star22').src = source+"star_blank_half_right_big.jpg";
			$('final_star31').src = source+"star_blank_half_left_big.jpg";
			$('final_star32').src = source+"star_blank_half_right_big.jpg";
			$('final_star41').src = source+"star_blank_half_left_big.jpg";
			$('final_star42').src = source+"star_blank_half_right_big.jpg";
			$('final_star51').src = source+"star_blank_half_left_big.jpg";
			$('final_star52').src = source+"star_blank_half_right_big.jpg";
		}
		else if(rating == 1) {
			$('final_star11').src = source+"star_half_left_big.jpg";
			$('final_star12').src = source+"star_half_right_big.jpg";
			$('final_star21').src = source+"star_blank_half_left_big.jpg";
			$('final_star22').src = source+"star_blank_half_right_big.jpg";
			$('final_star31').src = source+"star_blank_half_left_big.jpg";
			$('final_star32').src = source+"star_blank_half_right_big.jpg";
			$('final_star41').src = source+"star_blank_half_left_big.jpg";
			$('final_star42').src = source+"star_blank_half_right_big.jpg";
			$('final_star51').src = source+"star_blank_half_left_big.jpg";
			$('final_star52').src = source+"star_blank_half_right_big.jpg";
		}
		else if(rating == 1.5) {
			$('final_star11').src = source+"star_half_left_big.jpg";
			$('final_star12').src = source+"star_half_right_big.jpg";
			$('final_star21').src = source+"star_half_left_big.jpg";
			$('final_star22').src = source+"star_blank_half_right_big.jpg";
			$('final_star31').src = source+"star_blank_half_left_big.jpg";
			$('final_star32').src = source+"star_blank_half_right_big.jpg";
			$('final_star41').src = source+"star_blank_half_left_big.jpg";
			$('final_star42').src = source+"star_blank_half_right_big.jpg";
			$('final_star51').src = source+"star_blank_half_left_big.jpg";
			$('final_star52').src = source+"star_blank_half_right_big.jpg";
		}
		else if(rating == 2) {
			$('final_star11').src = source+"star_half_left_big.jpg";
			$('final_star12').src = source+"star_half_right_big.jpg";
			$('final_star21').src = source+"star_half_left_big.jpg";
			$('final_star22').src = source+"star_half_right_big.jpg";
			$('final_star31').src = source+"star_blank_half_left_big.jpg";
			$('final_star32').src = source+"star_blank_half_right_big.jpg";
			$('final_star41').src = source+"star_blank_half_left_big.jpg";
			$('final_star42').src = source+"star_blank_half_right_big.jpg";
			$('final_star51').src = source+"star_blank_half_left_big.jpg";
			$('final_star52').src = source+"star_blank_half_right_big.jpg";
		}
		else if(rating == 2.5) {
			$('final_star11').src = source+"star_half_left_big.jpg";
			$('final_star12').src = source+"star_half_right_big.jpg";
			$('final_star21').src = source+"star_half_left_big.jpg";
			$('final_star22').src = source+"star_half_right_big.jpg";
			$('final_star31').src = source+"star_half_left_big.jpg";
			$('final_star32').src = source+"star_blank_half_right_big.jpg";
			$('final_star41').src = source+"star_blank_half_left_big.jpg";
			$('final_star42').src = source+"star_blank_half_right_big.jpg";
			$('final_star51').src = source+"star_blank_half_left_big.jpg";
			$('final_star52').src = source+"star_blank_half_right_big.jpg";
		}
		else if(rating == 3) {
			$('final_star11').src = source+"star_half_left_big.jpg";
			$('final_star12').src = source+"star_half_right_big.jpg";
			$('final_star21').src = source+"star_half_left_big.jpg";
			$('final_star22').src = source+"star_half_right_big.jpg";
			$('final_star31').src = source+"star_half_left_big.jpg";
			$('final_star32').src = source+"star_half_right_big.jpg";
			$('final_star41').src = source+"star_blank_half_left_big.jpg";
			$('final_star42').src = source+"star_blank_half_right_big.jpg";
			$('final_star51').src = source+"star_blank_half_left_big.jpg";
			$('final_star52').src = source+"star_blank_half_right_big.jpg";
		}
		else if(rating == 3.5) {
			$('final_star11').src = source+"star_half_left_big.jpg";
			$('final_star12').src = source+"star_half_right_big.jpg";
			$('final_star21').src = source+"star_half_left_big.jpg";
			$('final_star22').src = source+"star_half_right_big.jpg";
			$('final_star31').src = source+"star_half_left_big.jpg";
			$('final_star32').src = source+"star_half_right_big.jpg";
			$('final_star41').src = source+"star_half_left_big.jpg";
			$('final_star42').src = source+"star_blank_half_right_big.jpg";
			$('final_star51').src = source+"star_blank_half_left_big.jpg";
			$('final_star52').src = source+"star_blank_half_right_big.jpg";
		}
		else if(rating == 4) {
			$('final_star11').src = source+"star_half_left_big.jpg";
			$('final_star12').src = source+"star_half_right_big.jpg";
			$('final_star21').src = source+"star_half_left_big.jpg";
			$('final_star22').src = source+"star_half_right_big.jpg";
			$('final_star31').src = source+"star_half_left_big.jpg";
			$('final_star32').src = source+"star_half_right_big.jpg";
			$('final_star41').src = source+"star_half_left_big.jpg";
			$('final_star42').src = source+"star_half_right_big.jpg";
			$('final_star51').src = source+"star_blank_half_left_big.jpg";
			$('final_star52').src = source+"star_blank_half_right_big.jpg";
		}
		else if(rating == 4.5) {
			$('final_star11').src = source+"star_half_left_big.jpg";
			$('final_star12').src = source+"star_half_right_big.jpg";
			$('final_star21').src = source+"star_half_left_big.jpg";
			$('final_star22').src = source+"star_half_right_big.jpg";
			$('final_star31').src = source+"star_half_left_big.jpg";
			$('final_star32').src = source+"star_half_right_big.jpg";
			$('final_star41').src = source+"star_half_left_big.jpg";
			$('final_star42').src = source+"star_half_right_big.jpg";
			$('final_star51').src = source+"star_half_left_big.jpg";
			$('final_star52').src = source+"star_blank_half_right_big.jpg";
		}
		else if(rating == 5) {
			$('final_star11').src = source+"star_half_left_big.jpg";
			$('final_star12').src = source+"star_half_right_big.jpg";
			$('final_star21').src = source+"star_half_left_big.jpg";
			$('final_star22').src = source+"star_half_right_big.jpg";
			$('final_star31').src = source+"star_half_left_big.jpg";
			$('final_star32').src = source+"star_half_right_big.jpg";
			$('final_star41').src = source+"star_half_left_big.jpg";
			$('final_star42').src = source+"star_half_right_big.jpg";
			$('final_star51').src = source+"star_half_left_big.jpg";
			$('final_star52').src = source+"star_half_right_big.jpg";
		}
		$('pre_rating').style.display = "none";
		$('rating').style.display = "";
		
	}
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'rate_recipe', recipe_id: recipe_id, user_id: user_id, rating: rating, time: new_time },
		onComplete: showResponse

	});
}

function add_to_favorites(recipe_id) {
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'add_to_favorites', recipe_id: recipe_id, user_id: user_id, time: new_time},
		onComplete: showResponse 

	});
	
	function showResponse(req){
		
		//alert(req.responseText);
		$('add_to_favorites').style.display = "none";
		$('added_to_favorites').style.display = "";
	}
}

function add_to_fans(recipe_id, user) {
	var new_time = get_time();
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'add_to_fans', recipe_id: recipe_id, user_id: user, time: new_time},
		onComplete: showResponse 

	});
	
	function showResponse(req){
		
		//alert(req.responseText);
		show_recipe_fans(recipe_id, user_id);
	}
}

function remove_from_favorites(recipe_id, user, hide_this) {
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'remove_from_favorites', recipe_id: recipe_id, user_id: user, time: new_time},
		onComplete: showResponse 

	});
	
	function showResponse(req){
		
		//alert(req.responseText);
		$(hide_this).style.display = "none";
		load_profile_panel('favorite_recipes');
	}
}

function get_comments(user, my_id, start_row) {
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'get_comments', user_id: user, my_id: user_id, start_row: start_row, time: new_time},
		onComplete: showResponse 

	});
	
	function showResponse(req){
		
		//alert(req.responseText);
		$('comments').innerHTML= req.responseText;
	}
}

function delete_comment(user, my_id, comment_id, start_row) {
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'delete_comment', comment_id: comment_id, my_id: user_id, start_row: start_row, user_id: user, time: new_time},
		onComplete: showResponse 

	});
	
	function showResponse(req){
		
		//alert(req.responseText);
		$('comments').innerHTML= req.responseText;
	}
}

function hide_comment(user, my_id, comment_id, start_row) {
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'hide_comment', comment_id: comment_id, my_id: user_id, start_row: start_row, user_id: user, time: new_time},
		onComplete: showResponse 

	});
	
	function showResponse(req){
		
		//alert(req.responseText);
		$('comments').innerHTML= req.responseText;
	}
}

function show_comment(user, my_id, comment_id, start_row) {
	//alert("show");
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'show_comment', comment_id: comment_id, my_id: user_id, start_row: start_row, user_id: user, time: new_time},
		onComplete: showResponse 

	});
	
	function showResponse(req){
		
		//alert(req.responseText);
		$('comments').innerHTML= req.responseText;
	}
}

function post_comment() {
	//alert("show");
	
	var to_user = $('to_user').value;
	var from_user = $('from_user').value;
	var comment = $('new_comment1').value;
	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'post_comment', to_user: to_user, from_user: from_user, comment: comment, time: new_time},
		onComplete: showResponse 

	});
	
	function showResponse(req){
		
		//alert(req.responseText);
		$('comments').innerHTML = req.responseText;
		$('new_comment1').value = "";
	}
}

function show_this(id) {
	$(id).style.display = '';
}

function hide_this(id) {
	$(id).style.display = 'none';
}


function toggle_this(id) {
	if($(id).style.display == 'none') {
		
		$(id).style.display = '';
	}
	else {
		$(id).style.display = 'none';
	}
}
function expose_this(id) {
	if($(id).style.display == 'none') {
		
		$(id).style.display = '';
	}
	else {
		$(id).style.display = 'none';
	}
}




function show_recipe_fans(recipe_id, user_id) {
	
	//alert(user_id);
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'show_recipe_fans', recipe_id: recipe_id, user_id: user_id, time: new_time},
		onComplete: showResponse 

	});
	
	function showResponse(req){
		//alert(req.responseText);
		$('recipe_fans').innerHTML= req.responseText;
		
	}
}


function show_recipe_favs(recipe_id, user_id) {
	
	//alert(user_id);
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'show_recipe_favs', recipe_id: recipe_id, user_id: user_id, time: new_time},
		onComplete: showResponse 

	});
	
	function showResponse(req){
		//alert(req.responseText);
		$('recipe_favs').innerHTML= req.responseText;
		
	}
}



function members_search() {
	
	
	var new_time = get_time();
	
	var url = base_url + '/system/application/ajax/members.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'members_search', time: new_time},
		onComplete: showResponse 

	});
	
	function showResponse(req){
		//alert(req.responseText);
		$('members').innerHTML= req.responseText;
		$('search_terms').focus();
		
	}
}

function do_members_search() {
	
	
	var new_time = get_time();
	var search_terms = $('search_terms').value;
	//alert(search_terms);
	
	var url = base_url + '/system/application/ajax/members.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'members_search', search_terms: search_terms, time: new_time},
		onComplete: showResponse 

	});
	
	function showResponse(req){
		//alert(req.responseText);
		$('members').innerHTML= req.responseText;
		
	}
}

function show_top_favorites(type) {
	
	var new_time = get_time();
	//$('top_favorites').innerHTML= loading;
	
	if(type == 'today') {
		$('top_favorites_today').className = 'top_favorites_today_selected';
		$('top_favorites_this_month').className = 'top_favorites_this_month';
		$('top_favorites_all_time').className = 'top_favorites_all_time';
	}
	else if(type == 'this_month') {
		$('top_favorites_today').className = 'top_favorites_today';
		$('top_favorites_this_month').className = 'top_favorites_this_month_selected';
		$('top_favorites_all_time').className = 'top_favorites_all_time';
	}
	else if(type == 'all_time') {
		$('top_favorites_today').className = 'top_favorites_today';
		$('top_favorites_this_month').className = 'top_favorites_this_month';
		$('top_favorites_all_time').className = 'top_favorites_all_time_selected';
	}
	
	var url = base_url + '/system/application/ajax/user.php';
	new Ajax.Request(url, {
		method: 'get',
		parameters: {do_this: 'show_top_favorites', type: type, time: new_time},
		onComplete: showResponse 

	});
	
	function showResponse(req){
		//(req.responseText);
		$('top_favorites').innerHTML= req.responseText;
		
	}
	
	
}




function HighlightEffect(element){
   new Effect.Highlight(element, 
  {
	startcolor: "#ffff99",
	endcolor: "#ffffff",
	restorecolor: "#ffffff",
	duration: 1
  })
}


function show_login(type, message) {
	
	//alert(message);
	show_signup_content(type);
	overlay_layer(document.getElementById('main'), 'pop_over', message);
	if(type == 'login') { $('username').focus();  }
	else if(type == 'signup') { $('new_username').focus(); }
	
}

function hide_overlay_layer(lyr)
{
	//document.getElementById(lyr + "s").style.display = "none";
	Effect.Fade(lyr + "_content", {duration: 1});
	Effect.Fade(lyr, {duration: 1});
}

function get_corner(obj2)
{
	var curleft = curtop = 0;
	if ($(obj2).offsetParent) {
		curleft = $(obj2).offsetLeft
		curtop = $(obj2).offsetTop
		while (obj2 = $(obj2).offsetParent) {
			curleft += $(obj2).offsetLeft
			curtop += $(obj2).offsetTop
		}
	}
	//alert(curleft + ' - ' + curtop);
	return [curleft,curtop];
}

function overlay_layer(obj, lyr, message) //div to cover, layer to cover it with. 
{
	
	var show_message = '';
	if(message != null) { show_message = true; }
	
	//alert(show_message);
	
	if(show_message == true) { 
	
		//alert("showing message");
		$('signup_message').style.display = '';
		$('signup_message').innerHTML = 'You must be logged in to ' + message;
		
	}
	
	
	
	//document.getElementById(lyr + "s").style.display = ''
	Effect.Appear(lyr + "_content", {duration: 1});
	Effect.Appear(lyr, { to: .75, duration: 1 });
	//alert(document.getElementById(lyr + "s").style.display);
	
	var coors = get_corner(obj);
	var cover_this = obj;
	var cover_with = lyr;
	var cover_with_content = $(lyr + "_content");
	
	
	$(cover_with).style.top = coors[1] + 'px';
	$(cover_with).style.left = coors[0] + 'px';
	$(cover_with).style.width = $(cover_this).offsetWidth + "px";
	$(cover_with).style.height =  $(cover_this).offsetHeight + "px";
	
	$(cover_with_content).style.top = coors[1] + 100 + 'px';
	$(cover_with_content).style.left = coors[0] + 'px';
	$(cover_with_content).style.width = $(cover_this).offsetWidth + "px";
	$(cover_with_content).style.height =  $(cover_this).offsetHeight + "px";
	
	
	
	ScrollToElement('pop_over_content', -20);
	
	
	//$(cover_with_content).style.top = (((coors[1] + ($(cover_this).offsetHeight / 2)) - ($(cover_with_content).offsetHeight / 2)) + "px");
	//$(cover_with_content).style.top = '40px';
}

function show_signup_content(id) {
	
	set_class('signup_button_login', 'signup_button_login');
	set_class('signup_button_signup', 'signup_button_signup');
	set_class('signup_button_' + id, 'signup_button_' + id + '_selected');
	
	$('login_content').style.display = "none";
	$('signup_content').style.display = "none";
	$(id + '_content').style.display = "";
	
	//Effect.Fade('signup_message');
	
}


function set_search_category(cat_id, cat_name) {
	$('category').value = cat_id;	
	$('selected_search_category').innerHTML = cat_name;
	Effect.Fade('search_categories_all',{ duration: .5 });
}


