function blanktext(){
	$('#temp_txt').val($('textarea[@name=q]').val());
	$('textarea[@name=q]').val('');
 }	
 function showtemp() {
	if($('textarea[@name=q]').val() == '')
	$('textarea[@name=q]').val($('#temp_txt').val());		   
  }

$(document).ready(function(){
if(!search){
	if(getid)
	{
			jQuery.get('/ajax_get_recipe.php', {'id':getid}, 
			function(msg){
			$("#recipeall").show(); 
			if(msg == 0){
				msg = '<div class="recipe" id="recipe"><h2 class="skinny">No match found</h2></div>';
				$("#recipeall").html(msg); 
				//$("#recipe").css("height","500px");
			} else {
				var a_arr = msg.split("||||"); 
				$("#recipeall").html(a_arr[0]); 
				$("#recipe").css("height","auto");
				$('textarea[name=q]').text(a_arr[1]);
			    goto_recipe('recipe')

			}
			}
		)
	} else {
		jQuery.get('/ajax_get_recipe.php', {'init':'1'}, 
				function(msg){
				$("#recipeall").show(); 
				if(msg == 0){
					msg = '<div class="recipe" id="recipe"><h2 class="skinny">No match found</h2></div>';
					$("#recipeall").html(msg); 
					//$("#recipe").css("height","500px");
				} else {
					var a_arr = msg.split("||||"); 
					$("#recipeall").html(a_arr[0]); 
					$("#recipe").css("height","auto");
					$('textarea[name=q]').text(a_arr[1]);
				    //goto_recipe('recipe')
				}
				}
			)
	}
	

}

  $('#search form textarea').keydown(function(e){
    if(e.which == 9 || e.which == 13)
    {
      $('#search form').submit()
      return false
    }
  })
 
  $('#search form').submit(function(){
	$("#additional_recipes").hide(); 
	if($('textarea[@name=q]').val() == ''){
		$('#recipeall div.recipe').hide();
		msg = '<div class="recipe" id="recipe"><h2 class="skinny">Please give any text</h2></div>';
		$("#recipeall").html(msg);
		//$("#recipe").css("height","500px");
	    goto_recipe('recipe')
		return false;
	}
	$("#recipeall").show(); 
    jQuery.get('/ajax_get_recipe.php', {'q':$('textarea[@name=q]').val()}, 
		function(msg){
		$("#recipeall").show(); 
		if(msg == 0){
			msg = '<div class="recipe" id="recipe"><h2 class="skinny">No match found</h2></div>';
			$("#recipeall").html(msg); 
		    goto_recipe('recipe')
			//$("#recipe").css("height","500px");
		} else {
			$("#recipeall").html(msg); 
			$("#recipe").css("height","auto");
			goto_recipe('recipe')

		}
 
		}
	)
    return false
    })
})

jQuery.ajaxSetup({ 
  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept",
    "text/javascript")} 
})

function goto_recipe(moveto_page)
{
  var whereto = $("#" + moveto_page).offset().top;
  $('html, body').animate({scrollTop: whereto}, 400);
}