
var INPUT_NAME_PREFIX='items';var tableRows=0;var itemArray=new Array();var isNewForm=true;var theItems="";var INPUT_NAME_PREFIX='inputName';var ROW_BASE=1;var nextRow=0;var theItemCouponNum=0;var list_type=1;var ishare=false;var rowNumber=0;var numberOfItems=0;var itemInput="";var isIE=(navigator.appName=="Microsoft Internet Explorer")?true:false;var fromparse=false;function addRowToTable()
{this.itemInput=document.listCreationForm.itemNameInput.value;if(itemInput==''){alert("Please enter a value!");return;}
matchedKeyword=document.getElementById('keywordPlaceHolder').getAttribute('value');matchedKeywordPrice=document.getElementById('keywordPricePlaceHolder').getAttribute('value');discountId=document.getElementById('discountIdHolder').getAttribute('value');if((discountId!='undefined'&&discountId!="")&&(matchedKeywordPrice!='undefined'&&matchedKeywordPrice!="")&&(matchedKeyword!='undefinded'&&matchedKeyword!="")){addRowToTableHelper(this.itemInput,discountId,matchedKeyword,matchedKeywordPrice,false);addInfoBox(discountId);}else
addRowToTableHelper(this.itemInput,-1,null,null,false);}
function addInfoBox(discountid){dpos=0;for(var i=0;i<discountObj.discounts.length;i++){if(discountObj.discounts[i].discountid==discountid){dpos=i;break;}}
couponobj=discountObj.discounts[dpos];var aDiv=document.getElementById('rowDiv'+(rowNumber-1));var sp=document.createElement('span');sp.setAttribute('id','cinfo'+couponobj.discountid);setClassAttribute(sp,'hint');xp=document.createElement('span');setClassAttribute(xp,'fltrthint');xp.appendChild(document.createTextNode('x'));xp.onclick=function(){sp.style.display='none';}
sp.appendChild(xp);var hp=document.createElement('span');setClassAttribute(hp,'hint-pointer');sp.appendChild(hp);var title=document.createElement('p');setClassAttribute(title,'hinttitle');title.appendChild(document.createTextNode(couponobj.item_name));sp.appendChild(title);sp.appendChild(document.createTextNode(couponobj.description));sp.appendChild(document.createElement('hr'));tbl=document.createElement('table');tbl.setAttribute('width','100%');tbl.insertRow(0);tbl.rows[0].insertCell(0);tbl.rows[0].insertCell(1);tbl.rows[0].cells[0].setAttribute('align','left');tbl.rows[0].cells[1].setAttribute('align','right');tbl.rows[0].cells[1].setAttribute('valign','bottom');biz=document.createElement('p');setClassAttribute(biz,'biznamehint');biz.appendChild(document.createTextNode(couponobj.merchantname));tbl.rows[0].cells[0].appendChild(biz);bizadr=document.createElement('p');setClassAttribute(bizadr,'bizadr');bizadr.appendChild(document.createTextNode(couponobj.merchant_address));sc=document.createElement('span');sc.style.display='block';cityst=couponobj.merchant_city+", "+couponobj.merchant_state;sc.appendChild(document.createTextNode(cityst));bizadr.appendChild(sc);ph=document.createElement('span');ph.style.display='block';ph.appendChild(document.createTextNode(couponobj.merchant_phone));bizadr.appendChild(ph);tbl.rows[0].cells[0].appendChild(bizadr);logohnt=document.createElement('img');setClassAttribute(logohnt,'logohint');if(couponobj.logo!="")
logohnt.setAttribute('src',couponobj.logo);else
logohnt.setAttribute('src','../Graphics/tamlicon.png');logohnt.setAttribute('border','0');tbl.rows[0].cells[1].appendChild(logohnt);sp.appendChild(tbl);aDiv.appendChild(sp);}
function addRowToTableHelper(itemInput,discount_id,matchedKeyword,matchedKeywordPrice,disableDelete)
{var itemInput=TrimUsingWhileLoop(itemInput);itemInput=checkCharacters(itemInput);if(itemInput==" ")
return;var tbl=document.getElementById('itemTableArea');var rowDiv=document.createElement('div');rowDiv.setAttribute('id','rowDiv'+rowNumber);setClassAttribute(rowDiv,'items');var rowDisp=document.createElement('ul');setClassAttribute(rowDisp,'itemline');var listField;var showDiscount;if(listField==undefined)
{listField=document.createElement('li');if(itemInput.length>31){listField.appendChild(document.createTextNode(itemInput));listField.appendChild(document.createElement('br'));setheight=setRowDivHeight(itemInput);rowDiv.style.height=setheight;}else{listField.appendChild(document.createTextNode(itemInput));}
setClassAttribute(listField,'item');}
if(!disableDelete)
{var btnfield=document.createElement('li');setClassAttribute(btnfield,'deleteBtn');var buttonImage=document.createElement('img');buttonImage.setAttribute('src','../Graphics/cross.gif');buttonImage.setAttribute('id','image'+rowNumber);buttonImage.setAttribute('alt',"Delete "+itemInput);buttonImage.onclick=function(){deleteCurrentRow(this)};setClassAttribute(buttonImage,'deleteImg');btnfield.appendChild(buttonImage);rowDisp.appendChild(btnfield);}
rowDisp.appendChild(listField);if(discount_id!=-1&&discount_id!=""&&matchedKeyword!=null&&matchedKeywordPrice!=null){var dscField=document.createElement('li');dscImage=document.createElement('img');dscImage.setAttribute('src','../Graphics/star_icon.gif');setClassAttribute(dscField,'dscField');dscImage.setAttribute('title','More Info');dscImage.onclick=function(){hideHints(discount_id);document.getElementById(('cinfo'+discount_id)).style.display='inline';var left=0;var lnode=rowDiv;while(lnode.tagName!="BODY"&&lnode.tagName!="HTML"){left+=lnode.offsetLeft;lnode=lnode.offsetParent;}
offset=left+327;document.getElementById(('cinfo'+discount_id)).style.left=offset+'px';};dscField.appendChild(dscImage);rowDisp.appendChild(dscField);var discountIdField=document.createElement('li');discountIdField.appendChild(document.createTextNode(discount_id));discountIdField.style.display='none';rowDisp.appendChild(discountIdField);var matchedKeywordField=document.createElement('li');matchedKeywordField.appendChild(document.createTextNode(matchedKeyword));matchedKeywordField.style.display='none';rowDisp.appendChild(matchedKeywordField);var matchedKeywordPriceField=document.createElement('li');matchedKeywordPriceField.appendChild(document.createTextNode(matchedKeywordPrice))
matchedKeywordPriceField.style.display='none';rowDisp.appendChild(matchedKeywordPriceField);}
rowDiv.appendChild(rowDisp);if(rowNumber%2==0)
rowDiv.style.background='#f1f5fa';if(numberOfItems==0)
{tbl.appendChild(rowDiv);}
else
{var nodes=tbl.getElementsByTagName('div');var topDiv=nodes[0].id;var oldTopRow=document.getElementById(topDiv);tbl.insertBefore(rowDiv,oldTopRow);}
var subm=document.getElementById('submitItems');if(subm!=undefined)
subm.disabled=false;rowNumber++;numberOfItems++;document.listCreationForm.items.value="";if(!fromparse){document.listCreationForm.items.focus();}
document.getElementById('keywordPricePlaceHolder').value='';document.getElementById('discountIdHolder').value='';matchedKeyword=document.getElementById('keywordPlaceHolder').value='';}
function hideHints(discountid){tbl=document.getElementById('itemTableArea');sps=tbl.getElementsByTagName('span');for(var i=0;i<sps.length;i++){id=sps[i].id;if(id.search('cinfo')!=-1){sps[i].style.display='none';}}}
function deleteCurrentRow(obj){var tbl=document.getElementById('itemTableArea');var substr=obj.id;substr=substr.substring(5,substr.length);try{var cell=document.getElementById('rowDiv'+substr);tbl.removeChild(cell);numberOfItems--;}catch(exp){alert(exp+"   "+substr);}}
function addSpecialOrIncentiveToTable(itemName,coupon_id,matchedKeyword,matchedKeywordPrice,disDelete)
{if(itemName==""||coupon_id==""){return;}
if(disDelete==null||disDelete==""){disDelete=false;}
addRowToTableHelper(itemName,coupon_id,matchedKeyword,matchedKeywordPrice,disDelete);addInfoBox(coupon_id);}
function getItemString()
{var itemTableArea=document.getElementById('itemTableArea');var usersItems=itemTableArea.getElementsByTagName('ul');var itemString="";for(var i=0;i<usersItems.length;i++)
{var indvItem=usersItems[i];if(indvItem.childNodes[5]!=null){itemString+=getItemLine(indvItem.childNodes[1].childNodes)+"_-_";itemString+=indvItem.childNodes[3].firstChild.nodeValue+"-:";itemString+=indvItem.childNodes[4].firstChild.nodeValue+"-__";itemString+=indvItem.childNodes[5].firstChild.nodeValue+"#";}else{itemString+=getItemLine(indvItem.childNodes[1].childNodes)+"#";}}
return itemString;}
function getItemLine(nodes){var itemstr="";for(var i=0;i<nodes.length;i++){if(nodes[i].innerHTML!="")
itemstr+=nodes[i].nodeValue;}
return itemstr;}
function submitNewOrUpdateList(newOrListID,share)
{isshare=share;var itemString=getItemString();if(itemString==''){alert('Your list is empty. Please make a list first and then share it.');return;}
if(share)
showdivlayer(this,'sharefriend','no');reg=new RegExp("[^a-zA-Z0-9&+:()._%$# -]");itemString=itemString.replace(reg,"");itemString=encodeURIComponent(itemString);var listName=document.getElementById('listName').value;if(listName=="Name your list"||listName=="")
{var d=new Date();if(!isshare)
listName=(d.getMonth()+1)+"-"+d.getDate()+"-"+d.getFullYear();else
listName="Shared: "+(d.getMonth()+1)+"-"+d.getDate()+"-"+d.getFullYear();}
if(!isshare)
var loadingDiv=document.getElementById("status");else
var loadingDiv=document.getElementById("shareloading");var loadingImg=document.getElementById('statusImg');if(loadingImg==null)
{loadingImg=document.createElement('img');}
showDiv('status');loadingImg.setAttribute('src','../Graphics/loading.gif');loadingImg.setAttribute('id','statusImg');loadingDiv.appendChild(loadingImg);xmlHttp=GetXmlHttpObject();if(xmlHttp==null)
{alert("Browser does not support HTTP Request");return;}
if(xmlHttp.readyState!=0)
{xmlHttp.abort();alert("xmlHttp was aborted because xmlHttp.readyState != 0");}
var url="../Scripts/save_list.php";if(newOrListID=="new")
{url+="?itemString="+itemString;url+="&listName="+listName;if(share)
url+="&share=1";}
else
{url+="?listID="+document.getElementById('listID').value;url+="&itemString="+itemString;url+="&listName="+listName;if(share)
url+="&share=1";}
xmlHttp.open("GET",url,true);xmlHttp.onreadystatechange=stateChanged_saveList;xmlHttp.send(null);}
function stateChanged_saveList()
{if(xmlHttp.readyState==4||xmlHttp.readyState=="completed")
{var response=xmlHttp.responseText;var statusDiv=document.getElementById('status');var statusImg=document.getElementById('statusImg');var statusPElement=document.getElementById('statusPElement');if(statusPElement==null)
{statusPElement=document.createElement('p');}
else
{clearInnerHTML(statusPElement);}
statusPElement.setAttribute('id','statusPElement');setClassAttribute(statusPElement,'statusPElement');if(response.substr(0,1)=='0'&&response.search('Error')==-1&&isshare)
{listid=document.getElementById('listID');listid.value=response.substr(2,response.length);clearInnerHTML(document.getElementById('sharestatus'));hideDiv('shareloading');showDiv('shareme');}
else if(response.substr(0,1)=='0')
{statusImg.setAttribute('src','../Graphics/tick.gif');var successText=document.createTextNode('List was successfully saved!');statusPElement.appendChild(successText);hideDiv('saveagain');showDiv('sendfriend');listid=document.getElementById('listID');listid.setAttribute('value',response.substr(2,response.length));clearInnerHTML(document.getElementById('sharestatus'));}
else if(response.substr(0,1)=='2')
{if(!isshare){statusImg.setAttribute('src','../Graphics/cross.gif');var unsuccessText=document.createTextNode(response);statusPElement.appendChild(unsuccessText);showDiv('saveagain');}else{hideDiv('shareloading');var stat=document.getElementById('sharestatus');stat.appendChild(document.createTextNode('There was a problem saving your list to be shareed. Please try again'));showDiv('sharestatus');}}
else
{if(!isshare){statusImg.setAttribute('src','../Graphics/cross.gif');var unsuccessText=document.createTextNode(response);statusPElement.appendChild(unsuccessText);}else{hideDiv('shareloading');var stat=document.getElementById('sharestatus');stat.appendChild(document.createTextNode('There was a problem saving your list to be shareed. Please try again'));showDiv('sharestatus');}}
statusImg.refresh;statusDiv.appendChild(statusPElement);}}
function addToItemBox(){var itemBox=document.getElementById('poundList');var itemstr=theItems.substr(0,theItems.length-1);try{itemBox.setAttribute('value',itemstr);}catch(e){alert("Could not set the value of the list to be posted\n"+e);}
var nameEl=document.getElementById('listName');var postName=document.getElementById('nameOfList');if(nameEl!=null){var theName=nameEl.value;postName.setAttribute('value',theName);}}
function addToCellBox(){var itemBox=document.getElementById('cellPoundList');var itemstr=getItemString();if(navigator.appName=="Microsoft Internet Explorer"){itemBox.setAttribute('value',itemstr);}else{itemBox.value=itemstr;}
var nameEl=document.getElementById('listName');var postName=document.getElementById('nameOfList');if(nameEl!=null){var theName=nameEl.value;postName.setAttribute('value',theName);}}
function TrimUsingWhileLoop(str)
{while(str.charAt(0)==(" "))
{str=str.substring(1);}
while(str.charAt(str.length-1)==" ")
{str=str.substring(0,str.length-1);}
return str;}
function confirmSend(){theItems=getItemString();if(theItems==""){return alert("Please add items to your list before sending");}else{return confirm('Do you want to send your list now?');}}
function confirmSendFromPrintView(){return confirm('Do you want to send your list now?');}
function print_current_list(){var items=getItemString();while(items.match("%23")){items=items.replace("%23","_");}
var titleBox=document.getElementById('listName');var store=document.getElementById('storelist');if(store!=null){var storeid=store.value;}
theURL="../list/print_list.php?title=";theURL+=titleBox.value;theURL+="&items="+encodeURIComponent(items)+"&from=1";if(list_type==1){theURL+="&list_type=local";}else if(list_type==2){theURL+="&list_type=grocer&store_id="+storeid;}
NewWindow(theURL,"list",'550','550',"yes","center");}
var win=null;function NewWindow(mypage,myname,w,h,scroll,pos){if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center"&&pos!="random")||pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';win=window.open(mypage,myname,settings);}
function showDiv(id){if(document.getElementById){document.getElementById(id).style.display='block';}
else{if(document.layers){document.id.display='block';}
else{document.all.id.style.display='block';}}}
function hideDiv(id){try{if(document.getElementById){document.getElementById(id).style.display='none';}
else{if(document.layers){document.id.display='none';}
else{document.all.id.style.display='none';}}}catch(exp){alert(exp+"  "+id);}}
function check_all_boxes(table_name){rows=document.getElementById(table_name).getElementsByTagName('input');var unique_id;var checkbox;for(var i=0;i<rows.length;i++){checkbox=rows[i];if(checkbox&&checkbox.type=='checkbox'){unique_id=checkbox.name+checkbox.value;if(checkbox.disabled==false){checkbox.checked=true;}}}}
function set_print(){setPrint_xmlHttp=GetXmlHttpObject();if(setPrint_xmlHttp==null)
{alert("Browser does not support HTTP Request");return;}
if(setPrint_xmlHttp.readyState!=0){setPrint_xmlHttp.abort();}
num_items=document.getElementById('num_items');sent_from=document.getElementById('sent_from');var url="../Scripts/set_print.php";if(list_type!=null){url+="?list_type="+list_type;}
if(num_items!=null){url+="&num_items="+num_items.value;}
if(sent_from!=null){url+="&sent_from="+sent_from.value;}
setPrint_xmlHttp.open("GET",url,true);setPrint_xmlHttp.send(null);}
function setEnabled(){var btn=document.getElementById("manualSendToCell");btn.setAttribute('disabled',false);}
function confirmSendOtherPhone(){theItems=getItemString();regex=/^[- ()0-9]+$/;if(theItems==""){return alert("Please add items to your list before sending");}else{confirmSend=confirm('Do you want to send your list now?');if(confirmSend){if(document.itemForm.txtphone.value!=""){if(document.itemForm.txtphone.value.length>9&&document.itemForm.txtphone.value.length<15){if(document.itemForm.txtphone.value.match(regex)){if(checkReservedNums(document.itemForm.txtphone.value)){return true;}else{alert("You entered a reserved phone number, please verify the number you intend to send the list to.");}}else{alert("Please enter a valid phone number, including the area code");return false;}}else{alert("Please enter a valid phone number, including the area code");return false;}}else{alert("Please enter a valid phone number, including the area code");return false;}}}}
function checkReservedNums(num){var theNum=num.replace("(","");theNum=theNum.replace(")","");theNum=theNum.replace("-","");var area=theNum.substr(0,3);var middleNum=theNum.substr(3,3);if(area=="900"){return false;}
if(area=="866"){return false;}
if(area=="877"){return false;}
if(middleNum=="555"){return false;}
return true;}
function confirmSendEmail(){theItems=getItemString();regex=/^.+?@.+?\..+$/;if(theItems==""){return alert("Please add items to your list before sending");}else{confirmSend=confirm('Do you want to send your list now?');if(confirmSend){if(document.itemForm.email.value!=""){if(document.itemForm.email.value.match(regex)){return true;}else{alert("Please enter a valid email address");return false;}}else{alert("Please enter a valid email address");return false;}}}}
function setItemsFocus(){if(document.listCreationForm.items!=null&&!fromparse){document.listCreationForm.items.focus();}}
function remindItems(){remindItems_xmlHttp=GetXmlHttpObject();if(remindItems_xmlHttp==null)
{alert("Browser does not support HTTP Request");return;}
if(remindItems_xmlHttp.readyState!=0){remindItems_xmlHttp.abort();alert("xmlHttp was aborted because xmlHttp.readyState != 0");}
var url="../Scripts/getListReminders.php";remindItems_xmlHttp.open("GET",url,true);remindItems_xmlHttp.onreadystatechange=stateChanged_remindItems;remindItems_xmlHttp.send(null);}
function stateChanged_remindItems(){if(remindItems_xmlHttp.readyState==4||remindItems_xmlHttp.readyState=="completed"){var remindResponse=remindItems_xmlHttp.responseText;if(remindResponse=="empty"){alert("You have yet to set any reminders.\n You can add the reminders under item reminders in the account settings");}else{if(window.ActiveXObject){var xmlobject=new ActiveXObject("Microsoft.XMLDOM");xmlobject.async="false";xmlobject.loadXML(remindResponse);}else{var xmlobject=(new DOMParser()).parseFromString(remindResponse,"text/xml");}
var root=xmlobject.getElementsByTagName('reminders')[0];var reminders=root.getElementsByTagName("reminder");if(reminders.length==0){alert("By our records you do not need to remember to pick up any items.");}else{remindersStr="Don't forget these items:\n\n";for(var i=0;i<reminders.length;i++){var reminder=reminders[i];var item=reminder.getElementsByTagName("item")[0].firstChild.nodeValue;var lastReminded=reminder.getElementsByTagName("lastreminded")[0].firstChild.nodeValue;remindersStr+=item+"    You were last reminded: "+lastReminded+"\n\n";}
alert(remindersStr);}}}}
function fillListDynamically(listString)
{isNewForm=true;listString=decodeURIComponent(listString);try{while(true)
{var poundPosition=listString.indexOf("#");if(poundPosition==-1)
{break;}
else
{var itemValue=listString.substring(0,poundPosition);while(itemValue.indexOf('+')!=-1)
{itemValue=itemValue.replace('+',' ');}
addRowToTableHelper(itemValue,-1,false,false);listString=listString.substring(poundPosition+1);}}}catch(exp){alert(exp);}}
function fillDiscountListDynamically(discountString)
{discountString=decodeURIComponent(discountString);if(discountString!=''){var pieces=discountString.split('~');for(var i=0;i<pieces.length;i++){strips=pieces[i].split('_-_');id=strips[1].split('-:');matchedKey=id[1].split('-__');price=matchedKey[1];addSpecialOrIncentiveToTable(strips[0],id[0],matchedKey[0],price,false);}}}
function setClassAttribute(settingElement,value)
{if(settingElement==undefined||value=="")
return;else
{if(navigator.appName=="Microsoft Internet Explorer")
{settingElement.setAttribute('className',value);}
else
{settingElement.setAttribute('class',value);}}}
function checkCharacters(itemstr){reg=new RegExp("[^a-zA-Z0-9&+:()._%$# -]");itemstr=itemstr.replace(reg," ");return itemstr;}
function setRowDivHeight(itemstr){strlen=itemstr.length;heightCnt=0;pad=0;while(strlen>0){heightCnt+=20;pad+=3.2;strlen-=30;}
return heightCnt+Math.floor(pad)+'px';}
function createAccountNotUser(){var type=document.getElementById('list_type_id');var storeid=document.getElementById('storelist');storeid=storeid.options[storeid.selectedIndex].value
var listName=document.getElementById('listName').value;if(listName=="Enter Unique Name")
{var d=new Date();listName=(d.getMonth()+1)+"-"+d.getDate()+"-"+d.getFullYear();}
var items=getItemString();var url="../account/create_account.php?list="+encodeURIComponent(items);url+="&listname="+listName;url+="&storeid="+storeid;url+="&type="+type.value;window.location=url;}
function sharelist(){var senvars=true;var listid=document.getElementById('listID').value;if(listid==null||listid=='undefined'){alert('An error occured. Sorry we are not able to share your list at this time. \nPlease go to saved lists and share it from there.');return;}
var f_name=document.getElementById('f_name').value;var f_email=document.getElementById('f_email').value;if(f_email=='undefined')
f_email='';checkDiv=document.getElementById('checkedboxes');var checkedMails='';if(checkDiv!=null){inps=checkDiv.getElementsByTagName('input');for(var i=0;i<inps.length;i++){if(inps[i].checked)
checkedMails+=inps[i].value+'_';}}
if(checkedMails==''){if(f_name==''||f_name=='undefined'){alert("Please enter your friend's name");sendvars=false;}else if(f_email==''||f_email=='undefined'){alert("Please enter your friend's email address");sendvars=false;}else if(f_email.search(/^.+?@.+?\..+$/)<0){alert("Please enter a valid email address.");sendvars=false;}else if((f_email==''||f_email=='undefined')&&(f_name==''||f_name=='undefined')){alert("Please enter a friend's name and email to share your list.");sendvars=false;}else{sendvars=true;}}else{sendvars=true;}
var message=document.getElementById('message').value;var emails=f_email+'_'+checkedMails;xmlHttp=GetXmlHttpObject();if(xmlHttp==null)
{alert("Browser does not support HTTP Request");return;}
if(xmlHttp.readyState!=0)
{xmlHttp.abort();alert("xmlHttp was aborted because xmlHttp.readyState != 0");}
var url="../Scripts/share_list.php";url+="?listid="+listid;url+="&f_name="+encodeURIComponent(f_name);url+="&f_email="+encodeURIComponent(emails);url+="&message="+encodeURIComponent(message);if(sendvars){xmlHttp.open("GET",url,true);xmlHttp.onreadystatechange=stateChanged_shareList;xmlHttp.send(null);}}
function stateChanged_shareList(){if(xmlHttp.readyState==4||xmlHttp.readyState=="completed")
{var response=xmlHttp.responseText;var statusTxt='';if(response.substr(0,1)=='0'){statusTxt=response.substr(1,response.length);hideDiv('shareme');statusDiv=document.getElementById('sharestatus');clearInnerHTML(statusDiv);var messages=statusTxt.split('_');for(var i=0;i<messages.length;i++){if(messages[i]!=null&&messages[i]!=''){statusDiv.appendChild(document.createTextNode(messages[i].substr(3,response.length)));statusDiv.appendChild(document.createElement('br'));statusDiv.appendChild(document.createElement('br'));}}
showDiv('sharestatus');}else if(response.substr(0,1)=='69'){statusTxt=response.substr(3,response.length);hideDiv('shareme');statusDiv=document.getElementById('sharestatus');clearInnerHTML(statusDiv);var messages=statusTxt.split('_');for(var i=0;i<messages.length;i++){if(messages[i]!=null&&messages[i]!=''){statusDiv.appendChild(document.createTextNode(messages[i].substr(3,response.length)));statusDiv.appendChild(document.createElement('br'));statusDiv.appendChild(document.createElement('br'));}}
showDiv('sharestatus');}else{statusTxt=response;statusDiv=document.getElementById('sharestatus');clearInnerHTML(statusDiv);var messages=statusTxt.split('_');for(var i=0;i<messages.length;i++){if(messages[i]!=null&&messages[i]!=''){statusDiv.appendChild(document.createTextNode(messages[i].substr(3,response.length)));statusDiv.appendChild(document.createElement('br'));statusDiv.appendChild(document.createElement('br'));}}
showDiv('sharestatus');}}}
function highlightoption(id){div=document.getElementById('optionheader');tags=div.getElementsByTagName('a');for(var i=0;i<tags.length;i++){var tagid=tags[i].id;setClassAttribute(document.getElementById(tagid),'normaltext');}
setClassAttribute(document.getElementById(id),'boldtext');}
function highlightMakeOption(id){div=document.getElementById('addItemOptionRow');tags=div.getElementsByTagName('a');for(var i=0;i<tags.length;i++){var tagid=tags[i].id;setClassAttribute(document.getElementById(tagid),'normaltext');}
setClassAttribute(document.getElementById(id),'boldtext');}
function showOptions(option){switch(option){case'mobile':highlightoption('mobile');hideDiv('divSendPhone');hideDiv('divMyPhones');hideDiv('emailoptions');hideDiv('divSendSavedEmail');hideDiv('status');hideDiv('savebtn');hideDiv('sharelist');hideDiv('divSendEmail');Effect.Appear('divMyPhones',{duration:0.8});showDiv('mobileoptions');break;case'email':highlightoption('email');hideDiv('divSendPhone');hideDiv('divMyPhones');hideDiv('divSendEmail');hideDiv('mobileoptions');hideDiv('status');hideDiv('savebtn');hideDiv('sharelist');Effect.Appear('divSendSavedEmail',{duration:0.8});showDiv('emailoptions');break;case'save':highlightoption('savethelist');hideDiv('mobileoptions');hideDiv('divSendPhone');hideDiv('divMyPhones');hideDiv('emailoptions');hideDiv('divSendSavedEmail');hideDiv('sharelist');hideDiv('status');hideDiv('divSendEmail');Effect.Appear('savelist',{duration:0.8});showDiv('savebtn');break;case'share':highlightoption('sharethelist');hideDiv('mobileoptions');hideDiv('divSendPhone');hideDiv('divMyPhones');hideDiv('emailoptions');hideDiv('divSendSavedEmail');hideDiv('savebtn');hideDiv('status');hideDiv('divSendEmail');Effect.Appear('savelist',{duration:0.8});showDiv('sharelist');break;}}
function showMakeOptions(option)
{switch(option){case'single':highlightMakeOption('single');hideDiv('addItemTextArea');hideDiv('addItemFile');Effect.Appear('addItemSingle',{duration:0.8});showDiv('addItemSingle');break;case'multiple':highlightMakeOption('multiple');hideDiv('addItemSingle');hideDiv('addItemFile');Effect.Appear('addItemTextArea',{duration:0.8});showDiv('addItemTextArea');break;case'file':highlightMakeOption('file');hideDiv('addItemTextArea');hideDiv('addItemSingle');Effect.Appear('addItemFile',{duration:0.8});showDiv('addItemFile');break;}}
function submitMultipleEntries()
{var mea=document.getElementById('multipleEntryArea');parseMultipleEntries(mea.value);mea.value='';}
function parseMultipleEntries(input)
{if(input=="")
{return;}
var tokens=new Array();tokens=input.split('\n');for(var i=0;i<tokens.length;i++)
{fromparse=true;if(tokens[i]!="")
addRowToTableHelper(tokens[i],-1,null,null,false);}}
function getUploadedFileContents()
{xmlHttp=GetXmlHttpObject();if(xmlHttp==null)
{alert("Browser does not support HTTP Request");return;}
if(xmlHttp.readyState!=0){xmlHttp.abort();alert("xmlHttp was aborted because xmlHttp.readyState != 0");}
var url="../Scripts/get_uploaded_file_contents.php";xmlHttp.open("GET",url,true);xmlHttp.onreadystatechange=stateChanged_fileContents;xmlHttp.send(null);}
function stateChanged_fileContents()
{if(xmlHttp.readyState==4||xmlHttp.readyState=="completed")
{try{var text=xmlHttp.responseText;var mea=document.getElementById('multipleEntryArea');mea.value=text;submitMultipleEntries();}catch(e){alert("Sorry an error occurred:\n\n"+e);}}}
function getRecipeIngredients(id){if(id.length==0)
{return"";}
xmlHttp=GetXmlHttpObject();if(xmlHttp==null)
{alert("Browser does not support HTTP Request");return;}
if(xmlHttp.readyState!=0){xmlHttp.abort();alert("xmlHttp was aborted because xmlHttp.readyState != 0");}
var url="../Scripts/get_ingredients.php";url=url+"?id="+id;url=url+"&sid="+Math.random();xmlHttp.open("GET",url,true);xmlHttp.onreadystatechange=stateChanged_Recipe;xmlHttp.send(null);ingDiv=document.getElementById('ingredients');var loadimg=document.createElement('img');loadimg.setAttribute('src','../Graphics/loading.gif');ingDiv.appendChild(loadimg);}
function stateChanged_Recipe(){var ingDiv=document.getElementById("ingredients");ingDiv.setAttribute('style','display:none');if(xmlHttp.readyState==4||xmlHttp.readyState=="completed")
{clearInnerHTML(ingDiv);xmlstring=xmlHttp.responseText;if(window.ActiveXObject){var xmlobject=new ActiveXObject("Microsoft.XMLDOM");xmlobject.async="false";xmlobject.loadXML(xmlHttp.responseText);}else{var xmlobject=(new DOMParser()).parseFromString(xmlstring,"text/xml");}
var root=xmlobject.getElementsByTagName('recipe')[0];var recipetitle=root.getElementsByTagName("title");var items=root.getElementsByTagName("ingredient");if(navigator.appName=="Microsoft Internet Explorer"){var thename=document.createTextNode(recipetitle[0].firstChild.nodeValue);title=document.createElement("<p style='display:block; font-size:13px; font-weight:bold; margin: 0 2px 0 0; padding:0;;'></p>");title.appendChild(thename);ingDiv.appendChild(title);}else{title=document.createElement("p");title.appendChild(document.createTextNode(recipetitle[0].firstChild.nodeValue));title.setAttribute('style','display:block; font-size:13px; font-weight:bold; margin: 0 2px 0 0; padding:0;');ingDiv.appendChild(title);}
for(var i=0;i<items.length;i++){var ingr=items[i].firstChild.nodeValue;if(navigator.appName=="Microsoft Internet Explorer"){var ieinputDiv=document.createElement("<div style='margin:8px 0 0 0; display:block;'></div>");var ieingredientDiv=document.createElement("<input type='checkbox' style='text-align:left;' id='ing"+i+"' onclick=\"addToList('ing"+i+"');\" value='"+ingr+"'/>");var text=document.createTextNode(ingr);ieinputDiv.appendChild(ieingredientDiv);ieinputDiv.appendChild(text);ingDiv.appendChild(ieinputDiv);}else{var inputDiv=document.createElement("div");var ingredient=document.createElement("input");ingredient.setAttribute('id','ing'+i);ingredient.setAttribute('name','selected_items[]');ingredient.setAttribute('type','checkbox');ingredient.setAttribute('value',ingr);ingredient.setAttribute('style','margin:8px 0 0 0;');ingredient.setAttribute('onclick',"addToList('ing"+i+"');");inputDiv.appendChild(ingredient);inputDiv.appendChild(document.createTextNode(ingr));ingDiv.appendChild(inputDiv);}}
var checkAllDiv=document.createElement('div');checkAllDiv.setAttribute('style','margin:5px 0 0 0;');if(navigator.appName=="Microsoft Internet Explorer"){var ieanchor=document.createElement("<a  onclick=\"check_all_boxes_addrow('ingredients')\"></a>");var linktext=document.createTextNode("Check All");ieanchor.appendChild(linktext);checkAllDiv.appendChild(ieanchor);ingDiv.appendChild(checkAllDiv);}else{var anchor=document.createElement('a');anchor.setAttribute('onclick',"check_all_boxes_addrow('ingredients')");anchor.appendChild(document.createTextNode("Check All"));checkAllDiv.appendChild(anchor);ingDiv.appendChild(checkAllDiv);}
new Effect.Appear('ingredients',{duration:1.0});}}
function addToList(checkBoxID)
{var chkBx=document.getElementById(checkBoxID);if(chkBx==undefined)
{alert('Error occured during list adding/deleting');return;}
if(chkBx.checked)
{addRowToTableHelper(chkBx.value,false,false);}}
function check_all_boxes_addrow(elementName){rows=document.getElementById(elementName).getElementsByTagName('input');var unique_id;var checkbox;for(var i=0;i<rows.length;i++){checkbox=rows[i];if(checkbox&&checkbox.type=='checkbox'){unique_id=checkbox.name+checkbox.value;if(checkbox.disabled==false){checkbox.checked=true;addRowToTableHelper(checkbox.value,false,false);}}}}
function clearInnerHTML(obj){while(obj.firstChild){obj.removeChild(obj.firstChild);}}
function GetXmlHttpObject()
{var objXMLHttp=null
if(window.XMLHttpRequest)
{objXMLHttp=new XMLHttpRequest()}
else if(window.ActiveXObject)
{objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")}
return objXMLHttp;}
function setSendEnabled(){snd=document.getElementById('sendagain');if(snd.disabled)
snd.disabled=false;}
function sendMobileAgain(){number=document.getElementById('mobilePhoneNumber').value;phoneid=document.getElementById('phoneid').value;provider=document.getElementById('providers').selectedIndex;list=document.getElementById('sendagainlist').value;xmlHttp=GetXmlHttpObject();if(xmlHttp==null)
{alert("Browser does not support HTTP Request");return;}
if(xmlHttp.readyState!=0){xmlHttp.abort();alert("xmlHttp was aborted because xmlHttp.readyState != 0");}
var url="../Scripts/send_list.php";url+="?accountPhone="+encodeURIComponent(phoneid);url+="&number="+encodeURIComponent(number);url+="&list="+encodeURIComponent(list);url+="&provider="+encodeURIComponent(provider);xmlHttp.open("GET",url,true);xmlHttp.onreadystatechange=function(){if(xmlHttp.readyState==4||xmlHttp.readyState=="completed")
{var response=xmlHttp.responseText;if(response!='-1'){stat=document.getElementById('sendingstatus');stat.firstChild.innerHTML=response;Effect.Appear('sendingstatus',{duration:0.9});}}}
xmlHttp.send(null);}
function showlists(){var bx=document.getElementById('managelists');var x=getleft(bx);var y=(400/2)-(bx.offsetHeight/2);var theX=(x+750)+'px';bx.style.top=(y-130)+'px';bx.style.left=theX;if(listObj!=null){fillInRows(listObj.lists);showDiv('managelists');}else{alert("Please create a list and save it first");}}
function getleft(obj){var iLeft=0;var oNode=obj
while(oNode.tagName!="BODY"&&oNode.tagName!="HTML"){iLeft+=oNode.offsetLeft;oNode=oNode.parentNode;}
return iLeft;}
function fillInRows(obj){var bx=document.getElementById('selected_list');var list=bx.options[bx.selectedIndex].value;var lt="";for(i in obj){if(obj[i].list_id==list){var thelist=obj[i].list;var slit=thelist.split('#');var str="";str+="<ol style='font-size:12px;'>";for(j=0;j<slit.length;j++){if(slit[j]!=""){if(j%2==0)
str+="<li style='background-color:#f1f5fa; padding:2px 0;'>"+slit[j]+"</li>";else
str+="<li style='padding:2px 0;'>"+slit[j]+"</li>";}}
str+="</ol>";var pre=document.getElementById('listpre').innerHTML=str;document.getElementById('liststr').setAttribute('value',thelist);document.getElementById('discountstr').setAttribute('value',obj[i].discountstr);document.getElementById('listID').setAttribute('value',obj[i].list_id);document.getElementById('listName').setAttribute('value',obj[i].listName);break;}}}
function addlist(){clearInnerHTML(document.getElementById("itemTableArea"));numberOfItems=0;clearInnerHTML(document.getElementById('savethelist'));document.getElementById('savethelist').appendChild(document.createTextNode('Update List'));var na=document.getElementById('savethelist');var savelistbtn=document.getElementById('savelistbtn');savelistbtn.setAttribute('value','Update List');savelistbtn.onclick=function(){listid=document.getElementById('listID').value;submitNewOrUpdateList(listid,false);}
var list=document.getElementById('liststr').value;fillListDynamically(encodeURIComponent(list));var discountstr=document.getElementById('discountstr').value;fillDiscountListDynamically(encodeURIComponent(discountstr));hideDiv('managelists');}
function reverseString(str){newstr="";var i=str.length;i=i-1;for(var x=i;x>=0;x--)
{newstr+=str.charAt(x);}
return newstr;}