// JavaScript Document
/*if(user_id == '18489') {
	...
}*/
			
function get_time() {
	
	var d = new Date();
	return d.getTime();	
}

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


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 Keyword') {
		document.getElementById('search').value = '';
	}
}
function reset_search() {
	if(document.getElementById('search').value == '') {
		document.getElementById('search').value = 'Search Recipes by Keyword';
	}
}

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

function check_username() {
	
	var new_time = get_time();
		
	var url = base_url + '/system/application/ajax/user.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);
		if(req.responseText == "exists") {
			$('username_check').innerHTML= "<div id='username_fail'>Username is not available</div>";
		}
		else {
			$('username_check').innerHTML = "<div id='username_pass'>Username is available!</div>";
		}
	}
}

function quick_update_epantry(ingredient_id, 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: 'quick_update_epantry', user_id: user_id, ingredient_id: ingredient_id, recipe_id: recipe_id, time: new_time },
		onComplete: showResponse 

	});
	
	function showResponse(req){
		var split_result = req.responseText.split("|");
		$('recipe_ingredient_' + ingredient_id).src = split_result[0];
		$('recipe_ingredient_' + ingredient_id).title = split_result[1];
		$('recipe_ingredient_update' + recipe_id).style.display = '';
		$('recipe_ingredient_update' + recipe_id).innerHTML = split_result[2];
		$('percentage_' + recipe_id).innerHTML = split_result[3];
		
	}
}

function check_password() {
	
	if($('vpassword').value != '') {
		if($('new_password').value != $('vpassword').value) {
		
			$('password_check').innerHTML= "<div id='password_fail'>Passwords do not match!</div>";
		}
		else {
			
			$('password_check').innerHTML = "<div id='password_pass'>Passwords match</div>";
		}
	}
	}


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 = '';
	var new_time = get_time();
	var url = base_url + '/system/application/ajax/user.php';
	function showResponse(req){
		if(req.responseText != '') {
			document.recipematcher_form.submit();	
		}
		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_page = 'epantry_1_div';
var previous_pantry_page_link = 'epantry_1_span';
function show_pantry_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_pantry_page, { duration: the_duration }); 
		Effect.Fade(previous_pantry_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_pantry_page_link).style.color = '#aaaaaa';
	document.getElementById(page_link).style.color = '#3591f1';
	
	previous_pantry_page = page;
	previous_pantry_page_link = page_link;
}

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_eshopping_list()
{
	var a = window.open('','','width=950,height=700');
	a.document.open("text/html");
	a.document.write("<div align='center' style='font-family:Verdana, Arial, Helvetica, sans-serif'><h1>eShopping List</h1>" + document.getElementById('eshopping_list').innerHTML + "<br><br><span style='color:#555555;' ><strong>Powered By RecipeMatcher.com</strong></span></div>");
	a.document.close();
	a.print();
}

function print_recipe()
{
	var a = window.open('','','width=950,height=700');
	a.document.open("text/html");
	a.document.write("<div align='center' style='font-family:Verdana, Arial, Helvetica, sans-serif'>" + document.getElementById('recipe').innerHTML + "<br><br><span style='color:#555555;' ><strong>Powered By RecipeMatcher.com</strong></span></div>");
	a.document.close();
	a.print();
}

function print_ingredients()
{
	//alert($('ingredients_i_need').innerHTML);
	var a = window.open('','','width=950,height=700');
	a.document.open("text/html");
	a.document.write("<div align='center' style='font-family:Verdana, Arial, Helvetica, sans-serif'>" + document.getElementById('ingredients_i_need').innerHTML + "<br><br><span style='color:#555555;' ><strong>Powered By RecipeMatcher.com</strong></span></div>");
	a.document.close();
	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 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, 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){
			//alert("hello");
			$('suggestions').innerHTML= req.responseText;
			
		}
		
		new Ajax.Request(url, {
			method: 'get',
			parameters: {do_this: 'update_home_suggestions', value: value, ip_address: ip_address, 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();
		}
		
		new Ajax.Request(url, {
			method: 'get',
			parameters: {do_this: 'update_home_ingredients', grocery_id: grocery_id, ip_address: ip_address, 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() {

	if($('primary_ingredient_list').style.display == 'none') {
		//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', ip_address: ip_address, time: new_time},
			onComplete: showResponse
	
		});
		
		
	}
	else {
		
		$('primary_ingredient_list').style.display = 'none';
	}
}

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, ip_address: ip_address, time: new_time},
		onComplete: showResponse

	});
	
	function showResponse(req){
		$('primary_ingredient').innerHTML= req.responseText;
		$('primary_ingredient_list').style.display = 'none';
		$('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>";
}

var recipe_rated = false;
function submit_review_check() {
	
	if(recipe_rated == true) {
		
		document.review_form.submit();
	}
	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, 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_favorites', recipe_id: recipe_id, user_id: user, 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 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
  })
}


