"use strict";var REDIPS={};REDIPS.drag=(function(){var init,img_onmousemove,handler_onmousedown,handler_onmouseup,handler_onmousemove,handler_onresize,set_trc,set_color,box_offset,calculate_cells,getScrollPosition,autoscrollX,autoscrollY,clone_object,clone_limit,elementControl,trash_delete,enable_drag,save_content,obj_margin=null,mouseButton=0,mouseX=null,mouseY=null,window_width=0,window_height=0,scroll_width=null,scroll_height=null,edgeX=0,edgeY=0,bgcolor_old=null,tables=[],autoscrollX_flag=0,autoscrollY_flag=0,moved_flag=0,cloned_flag=0,cloned_id=0,currentCell=[],div_drag=null,div_box=null,table=null,table_old=null,table_source=null,row=null,row_old=null,row_source=null,cell=null,cell_old=null,cell_source=null,obj=false,obj_old=false,hover_color='#6A93D4',bound=25,speed=10,mark_cname='mark',marked_cell='deny',trash='trash',trash_ask=true,drop_option='multiple',delete_cloned=true;init=function(){var self=this,i,imgs,evt,tables_nodeList;div_drag=document.getElementById('drag');tables_nodeList=div_drag.getElementsByTagName('table');for(i=0;i<tables_nodeList.length;i++){tables[i]=tables_nodeList[i];}handler_onresize();window.onresize=handler_onresize;enable_drag(true);imgs=div_drag.getElementsByTagName('img');for(i=0;i<imgs.length;i++){imgs[i].onmousemove=img_onmousemove;}div_drag.onselectstart=function(e){evt=e||window.event;if(!elementControl(evt)){return false;}};window.onscroll=calculate_cells;};img_onmousemove=function(){return false;};handler_onmousedown=function(e){var evt=e||window.event,offset;if(elementControl(evt)){return true;}obj_old=obj||this;obj=this;if(obj.className.indexOf('clone')===-1){obj.style.zIndex=999;}mouseX=evt.clientX;mouseY=evt.clientY;set_trc(evt);table_source=table;row_source=row;cell_source=cell;if(evt.which){mouseButton=evt.which;}else{mouseButton=evt.button;}if(mouseButton===1){moved_flag=0;cloned_flag=0;document.onmousemove=handler_onmousemove;document.onmouseup=handler_onmouseup;REDIPS.drag.myhandler_clicked();}if(table!==null||row!==null||cell!==null){bgcolor_old=tables[table].rows[row].cells[cell].style.backgroundColor;}offset=box_offset(obj);obj_margin=[mouseY-offset[0],offset[1]-mouseX,offset[2]-mouseY,mouseX-offset[3]];return false;};handler_onmouseup=function(e){var evt=e||window.event,target_cell,source_cell,target_table,i,target_elements,target_elements_length;mouseButton=0;obj.style.left=0;obj.style.top=0;obj.style.zIndex=10;document.onmousemove=null;document.onmouseup=null;scroll_width=document.documentElement.scrollWidth;scroll_height=document.documentElement.scrollHeight;autoscrollX_flag=autoscrollY_flag=0;if(cloned_flag===1&&(table===null||row===null||cell===null)){obj.parentNode.removeChild(obj);REDIPS.drag.myhandler_notcloned();}else if(table===null||row===null||cell===null){REDIPS.drag.myhandler_notmoved();}else{if(table<tables.length){target_table=tables[table];target_cell=target_table.rows[row].cells[cell];}else if(table_old===null||row_old===null||cell_old===null){target_table=tables[table_source];target_cell=target_table.rows[row_source].cells[cell_source];}else{target_table=tables[table_old];target_cell=target_table.rows[row_old].cells[cell_old];}target_cell.style.backgroundColor=bgcolor_old;if(moved_flag===0){REDIPS.drag.myhandler_notmoved();target_cell.appendChild(obj);}else if(cloned_flag===1&&table_source===table&&row_source===row&&cell_source===cell){obj.parentNode.removeChild(obj);REDIPS.drag.myhandler_notcloned();}else if(cloned_flag===1&&REDIPS.drag.delete_cloned===true&&(evt.clientX<target_table.offset[3]||evt.clientX>target_table.offset[1]||evt.clientY<target_table.offset[0]||evt.clientY>target_table.offset[2])){obj.parentNode.removeChild(obj);REDIPS.drag.myhandler_notcloned();}else if(target_cell.className.indexOf(REDIPS.drag.trash)>-1){obj.parentNode.removeChild(obj);if(REDIPS.drag.trash_ask){setTimeout(trash_delete,10);}else{REDIPS.drag.myhandler_deleted();if(cloned_flag===1){clone_limit();}}}else if(REDIPS.drag.drop_option==='switch'){source_cell=tables[table_source].rows[row_source].cells[cell_source];obj.parentNode.removeChild(obj);target_elements=target_cell.getElementsByTagName('DIV');target_elements_length=target_elements.length;for(i=0;i<target_elements_length;i++){source_cell.appendChild(target_elements[0]);}target_cell.appendChild(obj);if(target_elements_length){REDIPS.drag.myhandler_switched();if(cloned_flag===1){clone_limit();}}else{REDIPS.drag.myhandler_dropped();if(cloned_flag===1){clone_limit();}}}else{REDIPS.drag.myhandler_dropped();target_cell.appendChild(obj);if(cloned_flag===1){clone_limit();}}if(table_source!==null&&row_source!==null){tables[table_source].rows[row_source].className=tables[table_source].rows[row_source].className;}target_cell.parentNode.className=target_cell.parentNode.className;calculate_cells();}table_old=row_old=cell_old=null;};handler_onmousemove=function(e){var evt=e||window.event,bound=REDIPS.drag.bound;if(moved_flag===0&&obj.className.indexOf('clone')>-1){clone_object();cloned_flag=1;REDIPS.drag.myhandler_cloned();set_color();}else if(moved_flag===0){REDIPS.drag.myhandler_moved();set_color();}moved_flag=1;if(evt.clientX>obj_margin[3]&&evt.clientX<window_width-obj_margin[1]){obj.style.left=(evt.clientX-mouseX)+"px";}if(evt.clientY>obj_margin[0]&&evt.clientY<window_height-obj_margin[2]){obj.style.top=(evt.clientY-mouseY)+"px";}if(evt.clientX<div_box[1]&&evt.clientX>div_box[3]&&evt.clientY<div_box[2]&&evt.clientY>div_box[0]&&(evt.clientX<currentCell[3]||evt.clientX>currentCell[1]||evt.clientY<currentCell[0]||evt.clientY>currentCell[2])){set_trc(evt);if(table<tables.length&&(table!==table_old||cell!==cell_old||row!==row_old)){if(table_old!==null&&row_old!==null&&cell_old!==null){tables[table_old].rows[row_old].cells[cell_old].style.backgroundColor=bgcolor_old;}set_color();}}if(evt.which){mouseButton=evt.which;}else{mouseButton=evt.button;}if(mouseButton!==1){handler_onmouseup(evt);return;}edgeX=bound-(window_width/2>evt.clientX?evt.clientX-obj_margin[3]:window_width-evt.clientX-obj_margin[1]);if(edgeX>0){if(edgeX>bound){edgeX=bound;}edgeX*=evt.clientX<window_width/2?-1:1;if(autoscrollX_flag++===0){window.onscroll=null;autoscrollX('start');}}else{edgeX=0;}
edgeY=bound-(window_height/2>evt.clientY?evt.clientY-obj_margin[0]:window_height-evt.clientY-obj_margin[2]);if(edgeY>0){if(edgeY>bound){edgeY=bound;}edgeY*=evt.clientY<window_height/2?-1:1;if(autoscrollY_flag++===0){window.onscroll=null;autoscrollY('start');}}else{edgeY=0;}evt.cancelBubble=true;if(evt.stopPropagation){evt.stopPropagation();}};handler_onresize=function(){if(typeof(window.innerWidth)==='number'){window_width=window.innerWidth;window_height=window.innerHeight;}else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){window_width=document.documentElement.clientWidth;window_height=document.documentElement.clientHeight;}else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){window_width=document.body.clientWidth;window_height=document.body.clientHeight;}scroll_width=document.documentElement.scrollWidth;scroll_height=document.documentElement.scrollHeight;calculate_cells();};set_trc=function(evt){var cell_current,row_offset,cells,has_content,mark_found,i;for(table=0;table<tables.length;table++){if(tables[table].offset[3]<evt.clientX&&evt.clientX<tables[table].offset[1]&&tables[table].offset[0]<evt.clientY&&evt.clientY<tables[table].offset[2]){row_offset=tables[table].row_offset;for(row=0;row<row_offset.length-1&&row_offset[row][0]<evt.clientY;row++){currentCell[0]=row_offset[row][0];currentCell[2]=row_offset[row+1][0];if(evt.clientY<=currentCell[2]){break;}}if(row===row_offset.length-1){currentCell[0]=row_offset[row][0];currentCell[2]=tables[table].offset[2];}do{cells=tables[table].rows[row].cells.length-1;for(cell=cells;cell>=0;cell--){currentCell[3]=row_offset[row][3]+tables[table].rows[row].cells[cell].offsetLeft;
currentCell[1]=currentCell[3]+tables[table].rows[row].cells[cell].offsetWidth;if(currentCell[3]<=evt.clientX&&evt.clientX<currentCell[1]){break;
}}}while(cell===-1&&row-- >0);if(row<0||cell<0){table=table_old;row=row_old;cell=cell_old;}cell_current=tables[table].rows[row].cells[cell];if(cell_current.className.indexOf(REDIPS.drag.trash)===-1){mark_found=cell_current.className.indexOf(REDIPS.drag.mark_cname)>-1?true:false;if((mark_found===true&&marked_cell==='deny')||(mark_found===false&&marked_cell==='allow')){if((table_old!==null&&row_old!==null&&cell_old!==null)){table=table_old;row=row_old;cell=cell_old;}break;}}if(REDIPS.drag.drop_option==='single'&&cell_current.childNodes.length>0){if(cell_current.childNodes.length===1&&cell_current.firstChild.nodeType===3){break;}has_content=false;for(i=cell_current.childNodes.length-1;i>=0;i--){if(cell_current.childNodes[i].className&&cell_current.childNodes[i].className.indexOf('drag')>-1){has_content=true;break;}}if(has_content&&table_old!==null&&row_old!==null&&cell_old!==null){if(table_source!==table||row_source!==row||cell_source!==cell){table=table_old;row=row_old;cell=cell_old;break;}}}break;}}};set_color=function(){if(table!==null&&row!==null&&cell!==null){bgcolor_old=tables[table].rows[row].cells[cell].style.backgroundColor;tables[table].rows[row].cells[cell].style.backgroundColor=REDIPS.drag.hover_color;table_old=table;row_old=row;cell_old=cell;}};box_offset=function(box){var scrollPosition=getScrollPosition(),oLeft=0-scrollPosition[0],oTop=0-scrollPosition[1],box_old=box;do{oLeft+=box.offsetLeft;oTop+=box.offsetTop;box=box.offsetParent;}while(box);return[oTop,oLeft+box_old.offsetWidth,oTop+box_old.offsetHeight,oLeft];};calculate_cells=function(){var i,j,tr,row_offset;for(i=0;i<tables.length;i++){row_offset=[];tr=tables[i].getElementsByTagName('tr');for(j=tr.length-1;j>=0;j--){row_offset[j]=box_offset(tr[j]);}tables[i].offset=box_offset(tables[i]);tables[i].row_offset=row_offset;}div_box=box_offset(div_drag);};getScrollPosition=function(){var scrollX,scrollY;if(typeof(window.pageYOffset)==='number'){scrollX=window.pageXOffset;scrollY=window.pageYOffset;}else if(document.body&&(document.body.scrollLeft||document.body.scrollTop)){scrollX=document.body.scrollLeft;scrollY=document.body.scrollTop;}else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)){scrollX=document.documentElement.scrollLeft;scrollY=document.documentElement.scrollTop;}else{scrollX=scrollY=0;}return[scrollX,scrollY];};autoscrollX=function(call){var old=0,scrollPosition=getScrollPosition()[0];if(mouseButton===1&&((edgeX<0&&scrollPosition>0)||(edgeX>0&&scrollPosition<(scroll_width-window_width)))){window.scrollBy(edgeX,0);old=scrollPosition;scrollPosition=getScrollPosition()[0];obj.style.left=(parseInt(obj.style.left,10)+scrollPosition-old)+"px";mouseX-=scrollPosition-old;setTimeout(REDIPS.drag.autoscrollX,REDIPS.drag.speed);}else{if(call!==null){calculate_cells();}window.onscroll=calculate_cells;autoscrollX_flag=0;}};autoscrollY=function(call){var top,old=0,scrollPosition=getScrollPosition()[1];if(mouseButton===1&&((edgeY<0&&scrollPosition>0)||(edgeY>0&&scrollPosition<(scroll_height-window_height)))){window.scrollBy(0,edgeY);old=scrollPosition;scrollPosition=getScrollPosition()[1];top=(isNaN(parseInt(obj.style.top,10))?0:parseInt(obj.style.top,10));obj.style.top=(top+scrollPosition-old)+"px";mouseY-=scrollPosition-old;setTimeout(REDIPS.drag.autoscrollY,REDIPS.drag.speed);}else{if(call!==null){calculate_cells();}window.onscroll=calculate_cells;autoscrollY_flag=0;}};clone_object=function(){var obj_new=obj.cloneNode(true),offset,offset_dragged;document.getElementById('obj_new').appendChild(obj_new);offset=box_offset(obj);offset_dragged=box_offset(obj_new);obj_new.style.top=(offset[0]-offset_dragged[0])+"px";obj_new.style.left=(offset[3]-offset_dragged[3])+"px";obj_new.onmousedown=handler_onmousedown;obj_new.className=obj_new.className.replace('clone','');obj_new.innerHTML+='d';obj_new.id='c'+cloned_id+':'+obj.id;cloned_id+=1;mouseX-=parseInt(obj_new.style.left,10);mouseY-=parseInt(obj_new.style.top,10);obj_old=obj;obj=obj_new;};clone_limit=function(){var match_arr,limit_type,limit,classes;classes=obj_old.className;match_arr=classes.match(/climit(\d)_(\d+)/);if(match_arr!==null){limit_type=parseInt(match_arr[1],10);limit=parseInt(match_arr[2],10);limit-=1;classes=classes.replace(/climit\d_\d+/g,'');if(limit<=0){classes=classes.replace('clone','');if(limit_type===2){classes=classes.replace('drag','');obj_old.onmousedown=null;obj_old.style.cursor='pointer';REDIPS.drag.myhandler_clonedend2();}else{REDIPS.drag.myhandler_clonedend1();}}else{classes=classes+' climit'+limit_type+'_'+limit;}classes=classes.replace(/^\s+|\s+$/g,'').replace(/\s{2,}/g,' ');obj_old.className=classes;}};elementControl=function(evt){var formElement,srcName;if(evt.srcElement){srcName=evt.srcElement.tagName;}else{srcName=evt.target.tagName;}switch(srcName){case'A':case'INPUT':case'SELECT':case'OPTION':formElement=true;break;default:formElement=false;}return formElement;};trash_delete=function(){var div_text='element',border;if(obj.className.indexOf('t1')>0){border='green';}else if(obj.className.indexOf('t2')>0){border='blue';}else{border='orange';}if(obj.getElementsByTagName('INPUT').length||obj.getElementsByTagName('SELECT').length){div_text='form element';}else if(obj.innerText||obj.textContent){div_text='"'+(obj.innerText||obj.textContent)+'"';}if(confirm('Delete '+div_text+' ('+border+') from\n table '+table_source+', row '+row_source+' and column '+cell_source+'?')){REDIPS.drag.myhandler_deleted();if(cloned_flag===1){clone_limit();}}else{if(cloned_flag!==1){tables[table_source].rows[row_source].cells[cell_source].appendChild(obj);calculate_cells();}REDIPS.drag.myhandler_undeleted();}};enable_drag=function(enable){var i,divs,borderStyle,cursor,handler;if(enable===true){handler=handler_onmousedown;borderStyle='solid';cursor='pointer';}else{handler=null;borderStyle='dotted';cursor='pointer';}divs=document.getElementById('drag').getElementsByTagName('div');for(i=0;i<divs.length;i=i+1){if(divs[i].className.indexOf('drag')>-1){divs[i].onmousedown=handler;divs[i].style.borderStyle=borderStyle;divs[i].style.cursor=cursor;}}};save_content=function(){var query='',tbl_rows,cells,tbl_cell,t,r,c,d;for(t=0;t<tables.length;t++){tbl_rows=tables[t].rows.length;for(r=0;r<tbl_rows;r++){cells=tables[t].rows[r].cells.length;for(c=0;c<cells;c++){tbl_cell=tables[t].rows[r].cells[c];if(tbl_cell.childNodes.length>0){for(d=0;d<tbl_cell.childNodes.length;d++){if(tbl_cell.childNodes[d].tagName==='DIV'){query+=tbl_cell.childNodes[d].id+'_'+t+'_'+c+'$';}}}}}}if(query===''){alert('Table is empty!');}else{query=query.substring(0,query.length-1);ingredient(query);}};return{obj:obj,obj_old:obj_old,hover_color:hover_color,bound:bound,speed:speed,mark_cname:mark_cname,marked_cell:marked_cell,trash:trash,trash_ask:trash_ask,drop_option:drop_option,delete_cloned:delete_cloned,init:init,enable_drag:enable_drag,save_content:save_content,autoscrollX:autoscrollX,autoscrollY:autoscrollY,myhandler_clicked:function(){},myhandler_moved:function(){},myhandler_notmoved:function(){},myhandler_dropped:function(){},myhandler_switched:function(){},myhandler_cloned:function(){},myhandler_clonedend1:function(){},myhandler_clonedend2:function(){},myhandler_notcloned:function(){},myhandler_deleted:function(){},myhandler_undeleted:function(){}};}());function toggle_confirm(chk){REDIPS.drag.trash_ask=chk.checked;}function toggle_delete_cloned(chk){REDIPS.drag.delete_cloned=chk.checked;}function toggle_dragging(chk){REDIPS.drag.enable_drag(chk.checked);}function set_drop_option(radio_button){REDIPS.drag.drop_option=radio_button.value;}window.onload=function(){REDIPS.drag.init();};var xmlhttp;function stateChanged(){if (xmlhttp.readyState==4){document.getElementById("txtfield").innerHTML=xmlhttp.responseText;}}function ingredient(st){var url="new_get.php?";var add = document.getElementById("searchtext").value;var minus = document.getElementById("donttext").value;var br_ch = navigator.appName;xmlhttp=GetXmlHttpObject();if (xmlhttp==null){alert ("Browser does not support HTTP Request");return;}url=url+"&i="+st+"&a="+add+"&m="+minus+"&b="+br_ch;xmlhttp.onreadystatechange=stateChanged;xmlhttp.open("GET",url,true);xmlhttp.send(null);}function nextpage(st){var url="new_get.php?";xmlhttp=GetXmlHttpObject();if (xmlhttp==null){alert ("Browser does not support HTTP Request");return;}url=url+"&k="+st;xmlhttp.onreadystatechange=stateChanged;xmlhttp.open("GET",url,true);xmlhttp.send(null);}function welcome(){document.getElementById("welcome").style.visibility="hidden";}function GetXmlHttpObject(){if (window.XMLHttpRequest){return new XMLHttpRequest();}if (window.ActiveXObject){return new ActiveXObject("Microsoft.XMLHTTP");}return null;}function cate(st){var url="new_get.php?";xmlhttp=GetXmlHttpObject();if (xmlhttp==null){  alert ("Browser does not support HTTP Request");  return;}url=url+"&c="+st;xmlhttp.onreadystatechange=stateChanged;xmlhttp.open("GET",url,true);xmlhttp.send(null);}function pausescroller(content, divId, divClass, delay){this.content=content;this.tickerid=divId;this.delay=delay;this.mouseoverBol=0;this.hiddendivpointer=1;document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute;width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute;  width: 100%;  visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>');var scrollerinstance=this;if (window.addEventListener){window.addEventListener("load", function(){scrollerinstance.initialize()}, false)}else if (window.attachEvent){window.attachEvent("onload", function(){scrollerinstance.initialize()})}else if (document.getElementById){setTimeout(function(){scrollerinstance.initialize()}, 500)}}pausescroller.prototype.initialize=function(){this.tickerdiv=document.getElementById(this.tickerid);this.visiblediv=document.getElementById(this.tickerid+"1");this.hiddendiv=this.hiddendiv=document.getElementById(this.tickerid+"2");this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv));this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px";this.getinline(this.visiblediv, this.hiddendiv);this.hiddendiv.style.visibility="visible";var scrollerinstance=this;document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1};document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0};if (window.attachEvent){window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})}setTimeout(function(){scrollerinstance.animateup()}, this.delay);};pausescroller.prototype.animateup=function(){var scrollerinstance=this;if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px";this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px";setTimeout(function(){scrollerinstance.animateup()}, 100);}else{this.getinline(this.hiddendiv, this.visiblediv);this.swapdivs();setTimeout(function(){scrollerinstance.setmessage()}, this.delay);}};pausescroller.prototype.swapdivs=function(){var tempcontainer=this.visiblediv;this.visiblediv=this.hiddendiv;this.hiddendiv=tempcontainer;};pausescroller.prototype.getinline=function(div1, div2){div1.style.top=this.visibledivtop+"px";div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px";};pausescroller.prototype.setmessage=function(){var scrollerinstance=this;if (this.mouseoverBol==1){setTimeout(function(){scrollerinstance.setmessage()}, 100)}else{var i=this.hiddendivpointer;var ceiling=this.content.length;this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1;this.hiddendiv.innerHTML=this.content[this.hiddendivpointer];this.animateup();}};pausescroller.getCSSpadding=function(tickerobj){if (tickerobj.currentStyle){return tickerobj.currentStyle["paddingTop"]}else if (window.getComputedStyle){return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")}else{return 0}}
function namesearch(){		var url="new_get.php?";	xmlhttp=GetXmlHttpObject();	if (xmlhttp==null){	  alert ("Browser does not support HTTP Request");  	return;}	var br_ch = navigator.appName; var food = document.getElementById("foodname").value;	url=url+"&f="+food+"&b="+br_ch;	xmlhttp.onreadystatechange=stateChanged;	xmlhttp.open("GET",url,true);	xmlhttp.send(null);}

