var categories = new Array();
 			 categories[1]=  	"Fruit";
			 categories[2]= 	"Poultry";
	 	 	 categories[3]= 	"BakingGoods";
	 	 	 categories[4]= 	"Vegetables";
	 	 	 categories[5]= 	"Meat";
	 	 	 categories[7]= 	"Seafood";
	 	 	 categories[8]= 	"PastaBreadsGrains";
	 	 	 categories[9]= 	"HerbsSpices";
	 	 	 categories[10]= 	"Dairy";
	 	 	 categories[11]= 	"SoupsSaucesCondiments";
	 	 	 categories[12]=	"BeveragesAlcohol";
	 	 	 categories[14]= 	"NutsSeeds";
			 categories[15]= 	"PopularItems";
			 categories[16]= 	"SearchResults";
			 categories[17]=    "StarterKit";
			 categories[18]=    "CollegeDorm";
			 categories[19]=    "Single";
			 categories[20]=    "Couple";
			 categories[21]=    "Family";
			 
			 
			 
var order = new Array();
 			 order[1]=   "BakingGoods";
			 order[2]= 	"BeveragesAlcohol";
	 	 	 order[3]= 	"Dairy";
	 	 	 order[4]= 	 "Fruit"; 
	 	 	 order[5]= 	 "HerbsSpices";
	 	 	 order[6]= 	 "Meat";
			 order[7]=  "Misc.";
	 	 	 order[8]= 	 "NutsSeeds";
	 	 	 order[9]= 	"PastaBreadsGrains";
	 	 	 order[10]=  "Poultry";
	 	 	 order[11]= "SoupsSaucesCondiments";
	 	 	 order[12]=	 "Seafood";
	 	 	 order[13]=  "Vegetables";
			 
function doWipe(idtext) {
setTimeout('Element.hide(\'s_option\')', 500);
}
function SetChecked(val,chkName) {
var form='subform';
dml=document.forms[form];
len = dml.elements.length;
var i=0;
for( i=0 ; i<len ; i++) {
if (dml.elements[i].name==chkName) {
dml.elements[i].checked=val;
}
}
}
function GoCurrentSearch(){
new Ajax.Updater('current_search','functions/current_search.php',{onLoading:function(request){},onComplete:function(request){},asynchronous:true, evalScripts:true});
}
function GoCurrentSearch2(filters){
new Ajax.Updater('current_search','functions/current_search.php?'+filters,{onLoading:function(request){},onComplete:function(request){Element.removeClassName('search_panel', 'bopacity'); Element.hide('rload');},asynchronous:true, evalScripts:true});
}
function GoRestore(){
	
}
function GoResultOutput(filters){
	new Ajax.Updater('recipe_output', 't_recipe2.php?'+filters,{onLoading:function(request){$('search_panel').addClassName('bopacity'); Element.show('rload');},onComplete:function(request){GoCurrentSearch2(filters);},asynchronous:true, evalScripts:true});
}
function GoAdditional(id){
	//if(id == 0){ Element.hide('subfilters'); Element.hide('filter_add');}
	//else { Element.show('filter_add'); Element.hide('subfilters');}
	new Ajax.Updater('sub_filters', 'functions/t_filters.php?af='+id,{onLoading:function(request){},onComplete:function(request){},asynchronous:true, evalScripts:true});
}
function GoSA(){
	new Ajax.Updater('sub1', 'functions/t_filters.php?sa=1',{onLoading:function(request){},onComplete:function(request){},asynchronous:true, evalScripts:true});
}
function GoFilters(filter,num_tabs){
	new Ajax.Updater('filters', 'functions/t_filters.php?f='+filter,{onLoading:function(request){Element.show('floading'); Element.hide('filters');},onComplete:function(request){Element.hide('floading'); Element.show('filters');},asynchronous:true, evalScripts:true});
	for(i=1;i<=num_tabs;i++){
		Element.removeClassName('filter'+i, 'tab_selected');
	}
	$('filter'+filter).addClassName('tab_selected');
}

//document.getElementById('livesearch').attachEvent('onkeydown',liveSearchKeyPress);

function liveSearchKeyPress(event){
	alert('hit');
}
function GoIngredientSearch(searchvalue,event){
	 var len;
// len = $('s_option').descendants().length - 7;
     
	 //alert(len);
var key = event.which || event.keyCode;

 switch (key) {
   case Event.KEY_UP:
   len = $('s_option').childElements().length;
      var down;
	 down = 0;
	 for(i=1;i<=len;i++){
	 if($('ic'+i).hasClassName('hightlightdropdown')){
		down = 1;
        var p = i -1;
		if(p != 0){
		$('ic'+p).addClassName('hightlightdropdown'); 
		$('ic'+i).removeClassName('hightlightdropdown');
		}
		break;
	 }
	 }
     if(down == 0) $('ic'+len).addClassName('hightlightdropdown');
     break;
     case Event.KEY_DOWN:
	  len = $('s_option').childElements().length;
	 var down;
	 down = 0;
	 for(i=1;i<len;i++){
	 if($('ic'+i).hasClassName('hightlightdropdown')){
		down = 1;
        var p = i +1;
		$('ic'+p).addClassName('hightlightdropdown'); 
		$('ic'+i).removeClassName('hightlightdropdown');
		break;
	 }
	 }
	 if($('ic'+len).hasClassName('hightlightdropdown')){ }
     else if(down == 0) $('ic1').addClassName('hightlightdropdown');
     break;
	 case Event.KEY_RETURN:
	 len = $('s_option').childElements().length;
	  for(i=1;i<len;i++){
	 if($('ic'+i).hasClassName('hightlightdropdown')){
		 $('s').value = $('ic'+i).readAttribute('iname');
	 }
	 }
     GoCategory('SearchResults',0);
	 doWipe('s_option');
     break;
	 default:
	 if(searchvalue.length < 2) Element.hide('s_option');
		else {
		Element.show('s_option');
		new Ajax.Updater('s_option', 'functions/ingredient_search.php?id='+searchvalue,{asynchronous:true, evalScripts:true});
		}
	break;
 }
		
}
function RefreshItem(oldid){	
var id = oldid.replace("product_", "");
new Ajax.Updater('p_'+id,'t_ingredient_selection.php?rfi='+id,{onLoading:function(request){},onComplete:function(request){Element.removeClassName('ingred_sel', 'bopacity'); Element.hide('riload');},asynchronous:true, evalScripts:true});
}
function RefreshItem2(id){	
new Ajax.Updater('p_'+id,'t_ingredient_selection.php?rfi='+id,{onLoading:function(request){},onComplete:function(request){Element.removeClassName('ingred_sel', 'bopacity'); Element.hide('riload');},asynchronous:true, evalScripts:true});
}
function GoCategory(newLocation,page){
	
if(newLocation == '' || newLocation == 'main' || newLocation == 'null'){
new Ajax.Updater('ingred_sel','t_ingredient_selection.php',{onLoading:function(request){Element.show('loading'); Element.hide('content_cat_drag'); Element.hide('ingred_sel'); Element.hide('content_cat_select');},onComplete:function(request){Element.hide('loading'); Element.show('content_cat'); Element.show('ingred_sel');},asynchronous:true, evalScripts:true});
new Ajax.Updater('items', 'icupdate.php',{onLoading:function(request){$('items').addClassName('bopacity');}, onComplete:function(request){Element.removeClassName('items', 'bopacity');}, parameters:'action=ccat&id=0' ,  evalScripts:true, asynchronous:true});
dhtmlHistory.add('main',''); 
}
else{
	var categoryid = categories.indexOf(newLocation);
	var orderid = order.indexOf(newLocation);
	if(categoryid > 0){
		if(categoryid > 17 && categoryid < 22){
		//alert(newLocation);
		if(page != 0){ 
		if(page == 'a'){ page = 0; }
			new Ajax.Updater('items', 'icupdate.php', { parameters:'action=ccat&id=0' ,  evalScripts:true, asynchronous:true});
			new Ajax.Updater('f_ingr', 't_ingredient_selection.php?&d=1&sko='+categoryid+'&page=' + page,{asynchronous:true, evalScripts:true});
			new Ajax.Updater('c_ingr', 't_ingredient_selection.php?&i=1&sko='+categoryid+'&page=' + page,{onLoading:function(request){Element.show('iloading');},onComplete:function(request){Element.hide('iloading');},asynchronous:true, evalScripts:true});  
			
		}
		else {
			new Ajax.Updater('items', 'icupdate.php', { parameters:'action=ccat&id=0' ,  evalScripts:true, asynchronous:true});
			new Ajax.Updater('ingred_sel', 't_ingredient_selection.php?sko='+categoryid,{onLoading:function(request){Element.show('iloading'); Element.hide('content_cat');},onComplete:function(request){Element.hide('iloading'); Element.hide('loading'); Element.show('ingred_sel');  Element.show('content_cat_select');},asynchronous:true, evalScripts:true});
		}
		}
	else if(categoryid == 17){
		//alert(newLocation);
			new Ajax.Updater('items', 'icupdate.php', { parameters:'action=ccat&id=0' ,  evalScripts:true, asynchronous:true});
			new Ajax.Updater('ingred_sel', 't_ingredient_selection.php?sk=1',{onLoading:function(request){ Element.show('content_cat'); Element.show('loading'); Element.hide('content_cat_select');},onComplete:function(request){ Element.hide('loading'); Element.show('ingred_sel');},asynchronous:true, evalScripts:true});

		//new Ajax.Updater('items', 'icupdate.php', { parameters:'action=ccat&id=0' ,  evalScripts:true, asynchronous:true});
			//new Ajax.Updater('f_ingr', 'ingredient_selection.php?&d=1&sk=1',{asynchronous:true, evalScripts:true});
			//new Ajax.Updater('c_ingr', 'ingredient_selection.php?sk=1',{onLoading:function(request){Element.show('iloading'); Element.hide('content_cat'); Element.hide('ingred_sel');},onComplete:function(request){Element.hide('iloading'); Element.show('content_cat_drag');},asynchronous:true, evalScripts:true}); 
			//new Ajax.Updater('items', 'icupdate.php', { parameters:'action=ccat&id=0' ,  evalScripts:true, asynchronous:true});
			//new Ajax.Updater('ingred_sel', 'ingredient_selection.php?sk=1',{onLoading:function(request){Element.show('iloading'); Element.hide('content_cat'); Element.hide('ingred_sel');},onComplete:function(request){Element.hide('iloading'); Element.show('content_cat_drag'); Element.show('ingred_sel');},asynchronous:true, evalScripts:true});
	}
	else if(categoryid == 15){
		if(page != 0){ 
		if(page == 'a'){ page = 0; }
			new Ajax.Updater('items', 'icupdate.php', { parameters:'action=ccat&id=0' ,  evalScripts:true, asynchronous:true});
			new Ajax.Updater('f_ingr', 't_ingredient_selection.php?&d=1&pi=1&page=' + page,{asynchronous:true, evalScripts:true});
			new Ajax.Updater('c_ingr', 't_ingredient_selection.php?&i=1&pi=1&page=' + page,{onLoading:function(request){Element.show('iloading');},onComplete:function(request){Element.hide('iloading');},asynchronous:true, evalScripts:true});  
			
		}
		else {
			new Ajax.Updater('items', 'icupdate.php', { parameters:'action=ccat&id=0' ,  evalScripts:true, asynchronous:true});
			new Ajax.Updater('ingred_sel', 't_ingredient_selection.php?&pi=1&page=' + page,{onLoading:function(request){Element.show('loading'); Element.hide('content_cat'); Element.hide('ingred_sel');  Element.hide('content_cat_select');},onComplete:function(request){Element.hide('loading'); Element.show('content_cat_drag'); Element.show('ingred_sel');},asynchronous:true, evalScripts:true});
		}
	}
	else if(categoryid == 16){
		//alert($('s').value);
		//var form = $('searchform');
		//var input = form['s'];
//var search_term = $(input).getValue();
var search_term = $('s').value;
		if(search_term.length == 0){
		new Ajax.Updater('ingred_sel', 't_ingredient_selection.php',{onLoading:function(request){Element.show('loading'); Element.hide('content_cat_drag'); Element.hide('ingred_sel');},onComplete:function(request){Element.hide('loading'); Element.show('content_cat'); Element.show('ingred_sel');},asynchronous:true, evalScripts:true});
		dhtmlHistory.add('main',''); 
		new Ajax.Updater('items', 'icupdate.php', { parameters:'action=ccat&id=0' ,  evalScripts:true, asynchronous:true});
		}
		else if(search_term.length <= 2) alert('Search Term Must Be Longer than 2 Letters.');
		else {
			
			if(page != 0){ 
			if(page == 'a'){ page = 0; }
				new Ajax.Updater('f_ingr', 't_ingredient_selection.php?d=1&s='+ search_term +'&page=' + page,{asynchronous:true, evalScripts:true});
				new Ajax.Updater('c_ingr', 't_ingredient_selection.php?i=1&s='+ search_term +'&page=' + page,{onLoading:function(request){Element.show('iloading');},onComplete:function(request){Element.hide('iloading');},asynchronous:true, evalScripts:true});  
				new Ajax.Updater('items', 'icupdate.php',{onLoading:function(request){$('items').addClassName('bopacity');}, onComplete:function(request){Element.removeClassName('items', 'bopacity');}, parameters:'action=ccat&id=0' ,  evalScripts:true, asynchronous:true});

			}
			else{
			new Ajax.Updater('ingred_sel', 't_ingredient_selection.php?s='+ search_term +'&page=' + page,{onLoading:function(request){Element.show('loading'); Element.hide('content_cat'); Element.hide('ingred_sel');},onComplete:function(request){Element.hide('loading'); Element.show('content_cat_drag'); Element.show('ingred_sel');},asynchronous:true, evalScripts:true});
			new Ajax.Updater('items', 'icupdate.php',{onLoading:function(request){$('items').addClassName('bopacity');}, onComplete:function(request){Element.removeClassName('items', 'bopacity');}, parameters:'action=ccat&id=0' ,  evalScripts:true, asynchronous:true});

			Element.hide('s_option');
			}
		}
	}
	else {
			if(page != 0){ 
			if(page == 'a'){ page = 0; }
			new Ajax.Updater('f_ingr', 't_ingredient_selection.php?d=1&c='+ categoryid +'&page=' + page,{asynchronous:true, evalScripts:true});
			new Ajax.Updater('c_ingr', 't_ingredient_selection.php?i=1&c='+ categoryid +'&page=' + page,{onLoading:function(request){Element.show('iloading');},onComplete:function(request){Element.hide('iloading');},asynchronous:true, evalScripts:true});  
			}
			else new Ajax.Updater('ingred_sel', 't_ingredient_selection.php?c='+ categoryid +'&page=' + page,{onLoading:function(request){Element.show('loading'); Element.hide('content_cat'); Element.hide('ingred_sel');},onComplete:function(request){Element.hide('loading'); Element.show('content_cat_drag'); Element.show('ingred_sel');},asynchronous:true, evalScripts:true});
	}
	dhtmlHistory.add(newLocation,page);
	new Ajax.Updater('items', 'icupdate.php',{onLoading:function(request){$('items').addClassName('bopacity');}, onComplete:function(request){Element.removeClassName('items', 'bopacity');}, parameters:'action=ccat&id='+orderid  ,  evalScripts:true, asynchronous:true});

	}
	else{
		new Ajax.Updater('ingred_sel', 't_ingredient_selection.php',{onLoading:function(request){Element.show('loading'); Element.hide('content_cat_drag'); Element.hide('ingred_sel');},onComplete:function(request){Element.hide('loading'); Element.show('content_cat'); Element.show('ingred_sel');},asynchronous:true, evalScripts:true});
		dhtmlHistory.add('main',''); 
		new Ajax.Updater('items', 'icupdate.php',{onLoading:function(request){$('items').addClassName('bopacity');}, onComplete:function(request){Element.removeClassName('items', 'bopacity');}, parameters:'action=ccat&id=0' ,  evalScripts:true, asynchronous:true});

	}
}
}
function GoRemovePantry(sid){
	$('main_body').setOpacity(0.3);
	$('main_header').setOpacity(0.3);
	$('bottom_body').setOpacity(0.3);
	Element.show('emcart');
	$('emcart').setOpacity(1);
	$('rall1').writeAttribute('href', 'javascript:GoRemoveAll('+sid+');');
	$('rall2').writeAttribute('href', 'javascript:GoRemoveAllPantry('+sid+');');
}
function GoRemovedPantry(){
	$('main_body').setOpacity(1);
	$('main_header').setOpacity(1);
	$('bottom_body').setOpacity(1);
	Element.hide('emcart');
}
function WriteLoad(message){
$("loadmessage").innerHTML = message;
}
function GoRemoveAll(sid){
new Ajax.Updater('items', 'icupdate.php',{onLoading:function(request){}, onComplete:function(request){GoRemovedPantry();},parameters:'action=clear&sid='+sid, asynchronous:true, evalScripts:true});
}
function GoRemoveAllPantry(sid){
new Ajax.Updater('items', 'icupdate.php',{onLoading:function(request){GoRemovedPantry();}, onComplete:function(request){},parameters:'action=ritemall&sid='+sid, asynchronous:true, evalScripts:true});
new Ajax.Updater('items', 'icupdate.php',{onLoading:function(request){}, onComplete:function(request){},parameters:'action=clear&sid='+sid, asynchronous:true, evalScripts:true});
}
function GoRemoveItem(id,name,sid){
	$('main_body').setOpacity(0.3);
	$('main_header').setOpacity(0.3);
	$('bottom_body').setOpacity(0.3);
	Element.show('ritem');
	$('ritem').setOpacity(1);
        //Insertion.Bottom('ritemname', " "+name+" OPTIONS");
$('ritem1').writeAttribute('href', 'javascript:GoRemoveId('+id+','+sid+');');
$('ritem2').writeAttribute('href', 'javascript:GoRemovePId('+id+','+sid+');');
$("ritemname").innerHTML = "&nbsp;&nbsp;REMOVE "+name+" OPTIONS";

}
function GoRemovedItem(){
	$('main_body').setOpacity(1);
	$('main_header').setOpacity(1);
	$('bottom_body').setOpacity(1);
	Element.hide('ritem');
}
function GoRemoveId(id,sid){
new Ajax.Updater('items', 'icupdate.php',{onLoading:function(request){$('items').addClassName('bopacity'); $('items').addClassName('bopacity'); $('ingred_sel').addClassName('bopacity'); Element.show('riload');}, onComplete:function(request){Element.removeClassName('items', 'bopacity'); GoRemovedItem(); RefreshItem2(id);},parameters:'action=remove&id='+id+'&sid='+sid, asynchronous:true, evalScripts:true});
}
function GoRemovePId(id,sid){
new Ajax.Updater('items', 'icupdate.php',{onLoading:function(request){$('items').addClassName('bopacity'); GoRemovedItem(); $('items').addClassName('bopacity'); $('ingred_sel').addClassName('bopacity'); Element.show('riload');}, onComplete:function(request){},parameters:'action=remove&id='+id+'&pan=1&sid='+sid, asynchronous:true, evalScripts:true});
new Ajax.Updater('items', 'icupdate.php',{onLoading:function(request){}, onComplete:function(request){Element.removeClassName('items', 'bopacity'); RefreshItem2(id);},parameters:'action=ritem&id='+id+'&sid='+sid, asynchronous:true, evalScripts:true});
}
function GoAllergy(id){
new Ajax.Updater('profile_output','http://www.recipekey.com/new/index.php?id=allergy&aid='+id,{onLoading:function(request){$('profile_output').setOpacity(0.3); $('search_panel').addClassName('bopacity'); Element.show('rload');},onComplete:function(request){$('profile_output').setOpacity(1); GoResultOutput();},asynchronous:true, evalScripts:true});
}
function HideDirections(){
	new Ajax.Updater('profile_output','http://www.recipekey.com/new/index.php?hided=1',{onLoading:function(request){},onComplete:function(request){},asynchronous:true, evalScripts:true});
}
function GoVeggie(id){
new Ajax.Updater('profile_output','http://www.recipekey.com/new/index.php?id=diet&did='+id,{onLoading:function(request){$('profile_output').setOpacity(0.3); $('search_panel').addClassName('bopacity'); Element.show('rload');},onComplete:function(request){$('profile_output').setOpacity(1); GoResultOutput();},asynchronous:true, evalScripts:true});
}
function Tutorial(id){
	$('main_body').setOpacity(0.3);
	$('main_header').setOpacity(0.3);
	$('bottom_body').setOpacity(0.3);
	Element.show('tutorial');
	new Ajax.Updater('tutorial_output','http://www.recipekey.com/new/index.php?tutorial='+id,{onLoading:function(request){},onComplete:function(request){},asynchronous:true, evalScripts:true});
}
function CloseTutorial(){
	$('main_body').setOpacity(1);
	$('main_header').setOpacity(1);
	$('bottom_body').setOpacity(1);
	Element.hide('tutorial');
}
function CloseDirections(){
	Element.removeClassName('main_body', 'bopacity');
	Element.removeClassName('main_header', 'bopacity');
	Element.removeClassName('bottom_body', 'bopacity');
	Element.hide('pdirections');
}
function ShowDirections(){
	$('main_body').addClassName('bopacity');
	$('main_header').addClassName('bopacity');
	$('bottom_body').addClassName('bopacity');
	Element.show('pdirections');
}
function ShowAllHidden(id,cid){
	for(i=2;i<=cid;i++){
	Element.show(id+'_'+i);	
	}
	Element.hide('hideshow_'+id);
	Element.show('hidehide_'+id);
	new Ajax.Updater('show_hide','http://www.recipekey.com/new/index.php?showhidden='+id,{onLoading:function(request){},onComplete:function(request){},asynchronous:true, evalScripts:true});
}
function HideAllHidden(id,cid){
	for(i=2;i<=cid;i++){
	Element.hide(id+'_'+i);	
	}
	Element.show('hideshow_'+id);
	Element.hide('hidehide_'+id);
	new Ajax.Updater('show_hide','http://www.recipekey.com/new/index.php?showhidden='+id,{onLoading:function(request){},onComplete:function(request){},asynchronous:true, evalScripts:true});
}
function Add_Selected(num){
	//new Ajax.Updater('profile_info', 'http://www.recipekey.com/new/edit_profile.php?upd=1',{onLoading:function(request){},onComplete:function(request){ },asynchronous:true, evalScripts:true});	
var form = $('starterkit');
$('ingred_sel').addClassName('bopacity'); Element.show('aiload'); $('items').addClassName('bopacity');
	for(i=0;i<=num;i++){
	var starter_kit_id = form['ski_'+i];
	if(starter_kit_id != null){
	new Ajax.Updater('items', 'icupdate.php', {onLoading:function(request){}, onComplete:function(request){}, parameters:'action=add&sid=0&id=' + $F(starter_kit_id) ,  evalScripts:true, asynchronous:true});
	}
	new Ajax.Updater('c_ingr', 't_ingredient_selection.php?&skc=1',{onLoading:function(request){}, onComplete:function(request){ Element.removeClassName('ingred_sel', 'bopacity'); Element.hide('aiload'); Element.removeClassName('items', 'bopacity');}, asynchronous:true, evalScripts:true});
	}
}