// My Kitchen Object
// (C) Copyright 2008, AMR Systems, LLC
// Author: Nick Benik
// Last Update: 7-17-2007
// Last Update By: Al Sierra 03-11-09

var MyKitchen = {
	_ingredients: [],
	_highlighted: [],
	_exclude:[],
	_kitchenListType: false,
	_DishSaveImg: false,
	_isInExcludeMode: false,
	init: function() {
		// get highlighted ingredients from the cookie
		var cookieval = decodeURIComponent(getCookie('hi_list'));
		//alert('load from cookie init: ' + cookieval);
		if (cookieval != 'null') {
			var temparray = cookieval.split('|');
			MyKitchen._highlighted = temparray;	
		}
		this._kitchenListType = 'ingredient';
		this._load_from_cookie();
		this._load_from_server();
		this._save_to_cookie();
		this._save_to_exclude_cookie();
		//MySearch.init();
	},
	_save_dish_login: function(dishid) {
		// save dish ID in cookie
		setCookie('save_dish',dishid,120,'/',document.domain,false);			
		// redirect user to signin page
		location.href='signin.asp?msg=6';
	},
	SaveDish: function(divid) {
		if (!this._is_user) {
			var id = divid.substr(divid.lastIndexOf('-')+1);
			// user is not registered or logged in
			this._save_dish_login(id);
		} else {
			// save the div-id in global object (needed for excecution scope in AJAX)
			MyKitchen._DishSaveImg = divid;
			// get the element and ID number
			var id = divid.substr(divid.lastIndexOf('-')+1);
			var timg = $(divid).getElementsByTagName('IMG');
			timg = timg[0];
			timg.style.cursor='wait';
			timg.blur();
			// fire AJAX save call
			new Ajax.Request(
				'/575/save_dish.asp',
				{
					parameters: 'dishid='+encodeURIComponent(id),
					onSuccess: function(t) {
						try {
							var robj = eval("("+t.responseText+")");
						} catch(e) {
							alert("Sorry, there was an error contacting the website. \nPlease try again in a few seconds."); 
							var timg = $(MyKitchen._DishSaveImg).getElementsByTagName('IMG');
							timg = timg[0];
							timg.style.cursor='pointer';
							return false;
						}
						if (!robj.valid) { 
							switch (robj.reason) {
								case "BAD_DISH":
									alert('Sorry, This dish is no longer accessable.');
									break;
								case "BAD_USER":
									// user is not registered or logged in
									var id = MyKitchen._DishSaveImg.substr(MyKitchen._DishSaveImg.lastIndexOf('-')+1);
									MyKitchen._save_dish_login(id);
									break;
								default:
									alert("Sorry, An error occured while trying to save the Dish. \nPlease try again in a minute or two."); 
									var timg = $(MyKitchen._DishSaveImg).getElementsByTagName('IMG');
									timg = timg[0];
									timg.style.cursor='pointer';
									break;
								}
						} else {
							// success change image and kill the roleover code
							var thref = $(MyKitchen._DishSaveImg);
							var timg = thref.getElementsByTagName('IMG');
							timg = timg[0];
							timg.style.cursor='default';
							timg.src='/images/saved_btn.gif';
							thref.onmouseover = '';
							thref.onmouseout = '';
							thref.onclick = 'this.blur()';
						}
					},
					onException: function(t) {
						alert("Sorry, An error occured while trying to save the Dish. \nPlease try again in a minute or two."); 
						var thref = $(MyKitchen._DishSaveImg);
						var timg = thref.getElementsByTagName('IMG');
						timg = timg[0].style.cursor='pointer';
					},
					onFailure: function(t) {
						alert("Sorry, An error occured while trying to save the Dish. \nPlease try again in a minute or two."); 
						var thref = $(MyKitchen._DishSaveImg);
						var timg = thref.getElementsByTagName('IMG');
						timg = timg[0].style.cursor='pointer';
					}
				}
			);
		}		
	},
	addIngr: function(iname) {
		if (iname == "Enter Ingredient") {
			$('search_btn_img').style.cursor='pointer';
			$('search_btn_img_ex').style.cursor='pointer';
			return false;
		}
		if (iname=="") {
			if (!this._isInExcludeMode) {
				$('search_input').value = "Enter Ingredient";
			} else {
				$('search_input_ex').value = "Enter Ingredient";
			}
			$('search_btn_img').style.cursor='pointer';
			$('search_btn_img_ex').style.cursor='pointer';
			return false;
		}
		if (!this._isInExcludeMode) {
			// see if we already have this ingredient saved locally
			if (this._dupl_ingr(iname)) {
				// duplicate ingredient
				$('search_btn_img').style.cursor='pointer';
				//$('search_input').value = "Enter Ingredient";
				alert("That ingredient has already been added to your kitchen");
				$('search_input').value = "";
				return false;
			}
			// see if the ingredient is valid.
			new Ajax.Request(
				'/575/ingredient.asp',
				{
					parameters: 'add='+encodeURIComponent(iname)+'&isexclusion=0',
					onSuccess: function(t) {
						try {
							var robj = eval("("+t.responseText+")");
						} catch(e) {
							alert("Sorry, there was an error contacting the website. \nPlease try again in a few seconds."); 
							return false;
						}
						if (!robj.valid) { 
							if ((robj.name=='salt') || (robj.name=='pepper') || (robj.name=='sugar') || (robj.name=='water')) {
								alert("There is no need to add salt, pepper, sugar or water to your Supercook kitchen, as it is assumed most households have these ingredients");
							} else {
								alert("Sorry, we've never heard of the ingredient '"+robj.name+"'. \nKeep in mind you must enter one ingredient at a time.\nCan you check the spelling and try again?"); 
							}
							$('search_btn_img').style.cursor='pointer';
						} else {
							//$('search_input').style.color = '#CCCCCC'; //added by ct 7/23/2007
							$('search_input').value = "";
							$('search_input').focus()
							MyKitchen._kitchen_add.call(MyKitchen, robj.name);
						}
					}
				}
			);
		} else {
			//Addition by AL  3-11-09
			// see if we already have this ingredient saved locally
			if (this._dupl_ingr_exclude(iname)) {
				// duplicate ingredient
				$('search_btn_img_ex').style.cursor='pointer';
				//$('search_input_ex').value = "Enter Ingredient";
				alert("That ingredient has already been added to your exclude list");
				$('search_input_ex').value = "";
				return false;
			}
			$('search_input_ex').value = "";
			$('search_input_ex').focus()

			// see if the ingredient is valid.
			new Ajax.Request(
				'/575/ingredient.asp',
				{
					parameters: 'add='+encodeURIComponent(iname)+'&isexclusion=1',
					onSuccess: function(t) {
						try {
							var robj = eval("("+t.responseText+")");
						} catch(e) {
							alert("Sorry, there was an error contacting the website. \nPlease try again in a few seconds."); 
							return false;
						}
						//alert(robj.valid);
						if (!robj.valid) { 
							if ((robj.name=='salt') || (robj.name=='pepper') || (robj.name=='sugar') || (robj.name=='water')) {
								alert("There is no need to add salt, pepper, sugar or water to your Supercook kitchen, as it is assumed most households have these ingredients");
							} else {
								alert("Sorry, we've never heard of the ingredient '"+robj.name+"'. \nKeep in mind you must enter one ingredient at a time.\nCan you check the spelling and try again?"); 
							}
							$('search_btn_img_ex').style.cursor='pointer';
						} else {
							//$('search_input_ex').style.color = '#CCCCCC'; //added by ct 7/23/2007
							$('search_input_ex').value = "";
							$('search_input_ex').focus();
							MyKitchen._kitchen_exclude_add.call(MyKitchen, robj.name);
						}
					}
				}
			);
		}
		return false;
	},
	delIngr: function(iname) {
		if (!this._isInExcludeMode){
			// get the ingredient index
			var i, ingr, tn, ta;
			i = iname.substr(iname.lastIndexOf('-')+1);
			ingr = this._ingredients[i];
			//alert(ingr);
			// regardless of anything, remove the ingredient from the HTML
			tn = $('ki-'+i);
			tn.parentNode.removeChild(tn);
			// remove the ingredient from the ingredients list
			ta = this._highlighted.without(ingr);
			this._highlighted = [];
			this._highlighted = ta;
			ta = this._ingredients.without(ingr);
			this._ingredients = [];
			this._ingredients = ta;
			this._save_to_cookie.call(this);
			// re-render the ingredients
			this._render_kitchen.call(this, false);

			setCookie('hi_list',this._highlighted,120,'/',document.domain,false);					
			// send add command to server if user is registered
			if(this._is_user()) {
				new Ajax.Request(
						'/575/ingredient.asp',
						{ parameters: 'del='+encodeURIComponent(ingr)+'&isexclusion=0' }
				);
			}
			// TODO: refresh search results here
		} else {
			//Addition by AL  3-11-09
			
			// get the ingredient index
			var i, ingr, tn, ta;
			i = iname.substr(iname.lastIndexOf('-')+1);
			ingr = this._exclude[i];
			// regardless of anything, remove the ingredient from the HTML
			tn = $('ki_ex-'+i);
			tn.parentNode.removeChild(tn);
			// remove the ingredient from the exclude list
			ta = this._exclude.without(ingr);
			this._exclude = [];
			this._exclude = ta;
			this._save_to_exclude_cookie.call(this);
			// re-render the ingredients
			MySearch._pagecurrent=1;
			this._render_kitchen_exclude.call(this, false);
			// send add command to server if user is registered
			if(this._is_user()) {
				new Ajax.Request(
						'/575/ingredient.asp',
						{ parameters: 'del='+encodeURIComponent(ingr)+'&isexclusion=1' }
				);
			}
		}
	},
	togIngr: function(iname) {
		MySearch._pagecurrent=1;
		var tn = $(iname);
		if (tn.className == "kitchen_data_hirow") {
			// remove from the highlight list
			tn.className = "";
			for (var i=0; i< this._highlighted.length; i++) {
				if (this._highlighted[i]==tn.innerHTML) {
					this._highlighted.splice(i,1);
					i = this._highlighted.length +1;
				}
			}		
		} else {
			// add to the highlight list
			tn.className = "kitchen_data_hirow";
			this._highlighted.push(tn.innerHTML);
		}
		tn.blur();

		// update cookies
		var temp = this.GetHighlighted();
		temp = encodeURIComponent(temp.join('|'));
		setCookie('hi_list',temp,120,'/',document.domain,false);

		// refresh search results
		MySearch.GetResults();
		setTimeout("$('"+iname+"').style.cursor = 'pointer'",400);
	},
	GetHighlighted: function() {
		return this._trim_array(this._highlighted.clone());
	},
	GetIngredients: function() {
		// return a copy of the ingredient list
		return this._trim_array(this._ingredients.clone());
	},
	//Addition by AL  3-11-09
	GetExclude: function() {
		// return a copy of the ingredient list
		return this._trim_array(this._exclude.clone());
	},
	//Addition by AL  3-11-09
	KitchenTabMouseOver: function(type) {
		if(this._kitchenListType != type){
			$('kitchen').style.backgroundImage = "url(/images/kitchen_bg_tab_over.gif)";
		}
	},
	//Addition by AL  3-11-09
	KitchenTabMouseOut: function() {
		if(this._kitchenListType == 'ingredient'){
			$('kitchen').style.backgroundImage = "url(/images/kitchen_bg_tab_1.gif)";
		} else if(this._kitchenListType == 'exclude'){
			$('kitchen').style.backgroundImage = "url(/images/kitchen_bg_tab_2.gif)";
		}
	},
	//Addition by AL  3-11-09
	ToggleKitchenListing: function(type) {
		if(type == 'ingredient'){
			this._isInExcludeMode = false;
			$('search').style.backgroundImage = "url(/images/search_bg.gif)";
			$('search_copy').innerHTML = "Enter an ingredient you have in your kitchen e.g. “salmon”. For best results, add all the ingredients you have at home.";
			$('search_copy').style.color = "#436511";
			$('search_btn_ex').style.display="none";
			$('search_btn').style.display="block";
			$('search_input_ex').style.display="none";
			$('search_input').style.display="block";
			$('search_input').value = "Enter Ingredient";
			$('search_input').style.color = "#CCCCCC";
			$('kitchen_exclude_content').style.display="none";
			$('kitchen_content').style.display="block";
			$('kitchen_header').style.cursor="default";
			$('exclude_header').style.cursor="pointer";
			$('adad').style.display="block";
			$('kitchen').style.backgroundImage = "url(/images/kitchen_bg_tab_1.gif)";
			$('c_exclude_box').style.display="none";
			$('recommend_box').style.display="block";
			this._kitchenListType = 'ingredient';
		} else if(type == 'exclude'){
			this._isInExcludeMode = true;
			$('search').style.backgroundImage = "url(/images/search_bg_exclude.gif)";
			$('search_copy').innerHTML = "Enter an ingredient you want to Exclude from the search results, e.g. “pork”, or exclude whole categories by clicking them below.";
			$('search_copy').style.color = "#FFFFFF";
			$('search_btn').style.display="none";
			$('search_btn_ex').style.display="block";
			$('search_input').style.display="none";
			$('search_input_ex').style.display="block";
			$('search_input_ex').value = "Enter Ingredient";
			$('search_input_ex').style.color = "#CCCCCC";
			$('kitchen_content').style.display="none";
			$('kitchen_exclude_content').style.display="block";
			$('kitchen_header').style.cursor="pointer";
			$('exclude_header').style.cursor="default";
			$('adad').style.display="none";
			$('kitchen').style.backgroundImage = "url(/images/kitchen_bg_tab_2.gif)";
			$('recommend_box').style.display="none";
			$('c_exclude_box').style.display="block";
			this._kitchenListType = 'exclude';
		}
	},
	_trim_array: function(arrayin) {
		var r = [];
		var l = arrayin.length;
		var t;
		for (var i=0; i<l; i++) {
			if (undefined!==arrayin[i] || arrayin[i] != NULL) {
				t = arrayin[i];
				t = t.replace(/^\s+/, '');
				t = t.replace(/\s+$/, '');
				if (t!='') {r.push(t);}
			}
		}
		return r;
	},
	_is_user: function() {
		var vu = getCookie('validuser');
		if (vu=="Y") {
			return true;
		} else {
			return false;
		}
	},
	_dupl_ingr: function(iname) {
		if (this._ingredients.indexOf(iname) == -1) {
			return false;
		} else {
			return true;
		}
	},
	//Addition by AL  3-11-09
	_dupl_ingr_exclude: function(iname) {
		if (this._exclude.indexOf(iname) == -1) {
			return false;
		} else {
			return true;
		}
	},
	_kitchen_add: function(iname) {		
		$('search_btn_img').style.cursor='pointer';
		if (!this._dupl_ingr(iname)) {
			// deal with local data cache
			var index = this._ingredients.length;
			this._ingredients[index] = iname;
			this._save_to_cookie.call(this);
			// Add to HTML
			this._add_ingr.call(this, index, iname, false);
		}
		// send add command to server if user is registered
		if(this._is_user()) {
			new Ajax.Request(
					'/575/ingredient.asp',
					{ parameters: 'add='+encodeURIComponent(iname)+'&isexclusion=0' }
			);
		}
		// refresh search results
		MySearch.GetResults();
	},
	//Addition by AL  3-11-09
	_kitchen_exclude_add: function(iname) {		
		$('search_btn_img_ex').style.cursor='pointer';
		if (!this._dupl_ingr_exclude(iname)) {
			// deal with local data cache
			var index = this._exclude.length;
			this._exclude[index] = iname;
			this._save_to_exclude_cookie.call(this);
			// Add to HTML
			this._add_exclude_ingr.call(this, index, iname, false);
		}
		// send add command to server if user is registered
		if(this._is_user()) {
			new Ajax.Request(
					'/575/ingredient.asp',
					{ parameters: 'add='+encodeURIComponent(iname)+'&isexclusion=1' }
			);
		}
		// refresh search results
		MySearch.GetResults();
	},
	_save_to_cookie: function() {
		// this function relies upon cookie functions in another JS file
		deleteCookie('ki_list','/',document.domain);
		if (this._ingredients.length==0) { return true; }
		// build the cookie
		var temp = MyKitchen._ingredients.join("|");
		temp = encodeURIComponent(temp);
		setCookie('ki_list',temp,120,'/',document.domain,false);			
	},
	//Addition by AL  3-11-09
	_save_to_exclude_cookie: function() {
		// this function relies upon cookie functions in another JS file
		deleteCookie('ex_list','/',document.domain);
		if (this._exclude.length==0) { return true; }
		// build the cookie
		var temp = MyKitchen._exclude.join("|");
		temp = encodeURIComponent(temp);
		setCookie('ex_list',temp,120,'/',document.domain,false);			
	},
	_load_from_cookie: function() {
		// this function relies upon cookie functions in another JS file to load the ingredients cookie
		//Addition by AL  3-11-09
		// get exclude ingredients from the cookie
		var cookieval = decodeURIComponent(getCookie('ex_list'));
		if (cookieval != 'null') { 
			var temparray = cookieval.split('|');
			MyKitchen._exclude = temparray;	
		}
		
		// get kitchen ingredients from the cookie
		var cookieval = decodeURIComponent(getCookie('ki_list'));
		if (cookieval == 'null') { return true; }
		var temparray = cookieval.split('|');
		MyKitchen._ingredients = temparray;

		// get highlighted ingredients from the cookie
		var cookieval = decodeURIComponent(getCookie('hi_list'));
		//alert('load from cookie function: ' + cookieval);
		if (cookieval == 'null') { return true; }
		var temparray = cookieval.split('|');
		MyKitchen._highlighted = temparray;
	},
	//Modified by AL  3-11-09
	_load_from_server: function() {
		// load ingredients list from the server if we are a registered user
		// then merge with the cookie list on this computer (shared computer is most likely a family computer)
		new Ajax.Request(
			'/575/load_kitchen.asp',
			{
				onSuccess: function(t) {
					try {
						var robj = eval("("+t.responseText+")");
					} catch(e) {
						alert("Sorry, there was an error contacting the website. \nPlease reload the page."); 
						return false;
					}
					var isOK;
					var kitchen_ingredients = robj.ki_ingredients;
					var exclude_ingredients = robj.ex_ingredients;
					
					//Kitchen Ingredients
					for (var i1=0; i1<kitchen_ingredients.length; i1++ ) {
						isOK = true;
						for (var i2=0; i2<MyKitchen._ingredients.length; i2++ ) {
							if (kitchen_ingredients[i1] == MyKitchen._ingredients[i2]) { isOK = false; break;}
						}
						// non-dup ingredient, add it to our list
						if ( isOK ) { MyKitchen._ingredients.push(kitchen_ingredients[i1]); }
					}
					
					// now sort the ingredient list
					var ta = MyKitchen._ingredients.sort();
					MyKitchen._ingredients = [];
					MyKitchen._ingredients = ta;
					// display the update ingredients
					MyKitchen._render_kitchen.call(MyKitchen, 'fast');
					
					//Kitchen Exclude Ingredients
					for (var i1=0; i1<exclude_ingredients.length; i1++ ) {
						isOK = true;
						for (var i2=0; i2<MyKitchen._exclude.length; i2++ ) {
							if (exclude_ingredients[i1] == MyKitchen._exclude[i2]) { isOK = false; break;}
						}
						// non-dup ingredient, add it to our list
						if ( isOK ) { MyKitchen._exclude.push(exclude_ingredients[i1]); }
					}
					
					// now sort the exclude list
					var ta = MyKitchen._exclude.sort();
					MyKitchen._exclude = [];
					MyKitchen._exclude = ta;
					// display the update exclude ingredients
					MyKitchen._render_kitchen_exclude.call(MyKitchen, 'fast');

					//moved down here from the init function 08/24/07 ct
					MySearch.init();
				}
			}
		);
	},
	_render_kitchen: function(animate) {
		var p, i;
		// clears and then rebuilds the display of the "My Kitchen" pane	
		p = $('kitchen_content');
		while( p.hasChildNodes() ) { p.removeChild( p.lastChild ); }
		// build
		$('kitchen_content').scrollTop = 0;
		for (i=0; i<this._ingredients.length; i++) {
			// Add to HTML
			this._add_ingr.call(this, i, this._ingredients[i], animate);
		}
		if (animate!='fast') {
			// refresh search results
			MySearch.GetResults();
		}
	},
	//Addition by AL  3-11-09
	_render_kitchen_exclude: function(animate) {
		var p, i;
		// clears and then rebuilds the display of the "My Kitchen" pane	
		p = $('kitchen_exclude_content');
		while( p.hasChildNodes() ) { p.removeChild( p.lastChild ); }
		// build
		$('kitchen_exclude_content').scrollTop = 0;
		for (i=0; i<this._exclude.length; i++) {
			// Add to HTML
			this._add_exclude_ingr.call(this, i, this._exclude[i], animate);
		}
		if (animate!='fast') {
			// refresh search results
			MySearch.GetResults();
		}
	},
	_add_ingr: function(index,iname, animate) {
		// adds item HTML to the "My Kitchen" pane
		var i, tempnode1, tempnode2, lastnode, cloneDIV, newNode;

		MySearch._pagecurrent=1;

		// find the last column DIV
		tempnode2 = $('kitchen_content');
		tempnode1 = tempnode2.getElementsByTagName('div');
		for (i=0; i<tempnode1.length; i++) {
			if (tempnode1[i].className == "kitchen_col") {
				lastnode=tempnode1[i];
			}
		}
		
		if (lastnode === undefined) {
			newNode = true;
		} else {
			if (lastnode.getElementsByTagName('div').length/3 < 1) {
				// we still have space to add one item here
				tempnode1 = lastnode;
			} else {
				newNode = true;
			}
		}
		if (newNode) {
			// add a new column DIV to the kitchen DIV
			tempnode1 = Builder.node('div', {className:'kitchen_col'});
			tempnode2.appendChild(tempnode1);
		}
					
		// at this point "tempnode1" should have the DIV we need to add the ingredient DIV to
		// clone the template DIV, configure it, attach it to the DOM, then attach events to the Anchors
		cloneDIV = $('ki-template').cloneNode(true);
		cloneDIV.setAttribute('id', 'ki-'+index);
		// modify the Text and link IDs
		tempnode2 = cloneDIV.getElementsByTagName('A');
		tempnode2[0].id = 'kid-'+index;
		tempnode2[1].innerHTML = iname;
		tempnode2[1].id = 'kit-'+index;
		// Highlight the ingredient if it is saved as such
		for (i=0; i < this._highlighted.length; i++) {
			if (this._highlighted[i] == iname) tempnode2[1].className = 'kitchen_data_hirow';
		}
		
		// modify the Text and link IDs
		tempnode2 = cloneDIV.getElementsByTagName('DIV');
		// set the row style by even/odd
		if ((tempnode1.childNodes.length % 2) == 0 ) {
			tempnode2[1].className = 'kitchen_data_offrow';
		} else {
			tempnode2[1].className = 'kitchen_data_onrow';
		}
		tempnode1.appendChild(cloneDIV);
		if (!animate) {
			cloneDIV.show();
		} else {
			cloneDIV.show();
			Element.hide('ki-'+index);
			if (animate=='fast') {
				//new Effect.Appear('ki-'+index, {duration:'.2',queue: 'end'});
				Element.show('ki-'+index);
			} else {
				new Effect.Appear('ki-'+index, {queue: 'end'});
			}
		}
		// deal with the scollbar
		setTimeout("$('kitchen_content').scrollTop = 5000",100);
	},
	//Addition by AL  3-11-09
	_add_exclude_ingr: function(index,iname, animate) {
		// adds item HTML to the "My Kitchen" pane
		var i, tempnode1, tempnode2, lastnode, cloneDIV, newNode;

		MySearch._pagecurrent=1;

		// find the last column DIV
		tempnode2 = $('kitchen_exclude_content');
		tempnode1 = tempnode2.getElementsByTagName('div');
		for (i=0; i<tempnode1.length; i++) {
			if (tempnode1[i].className == "kitchen_col") {
				lastnode=tempnode1[i];
			}
		}
		
		if (lastnode === undefined) {
			newNode = true;
		} else {
			if (lastnode.getElementsByTagName('div').length/3 < 1) {
				// we still have space to add one item here
				tempnode1 = lastnode;
			} else {
				newNode = true;
			}
		}
		if (newNode) {
			// add a new column DIV to the kitchen DIV
			tempnode1 = Builder.node('div', {className:'kitchen_col'});
			tempnode2.appendChild(tempnode1);
		}
					
		// at this point "tempnode1" should have the DIV we need to add the ingredient DIV to
		// clone the template DIV, configure it, attach it to the DOM, then attach events to the Anchors
		cloneDIV = $('ki_ex-template').cloneNode(true);
		cloneDIV.setAttribute('id', 'ki_ex-'+index);
		// modify the Text and link IDs
		tempnode2 = cloneDIV.getElementsByTagName('A');
		tempnode2[0].id = 'kiexd-'+index;
		tempnode2 = cloneDIV.getElementsByTagName('SPAN');
		tempnode2[0].innerHTML = iname;
		tempnode2[0].id = 'kiexs-'+index;  
		tempnode2[0].style.color = '#FF0012';
		// modify the Text and link IDs
		tempnode2 = cloneDIV.getElementsByTagName('DIV');
		// set the row style by even/odd
		if ((tempnode1.childNodes.length % 2) == 0 ) {
			tempnode2[1].className = 'kitchen_data_offrow';
		} else {
			tempnode2[1].className = 'kitchen_data_onrow';
		}
		tempnode1.appendChild(cloneDIV);
		if (!animate) {
			cloneDIV.show();
		} else {
			cloneDIV.show();
			Element.hide('ki_ex-'+index);
			if (animate=='fast') {
				//new Effect.Appear('ki_ex-'+index, {duration:'.2',queue: 'end'});
				Element.show('ki_ex-'+index);
			} else {
				new Effect.Appear('ki_ex-'+index, {queue: 'end'});
			}
		}
		// deal with the scollbar
		setTimeout("$('kitchen_exclude_content').scrollTop = 5000",100);
	}
}