
var OfferType={"New":0,"Used":1,"Rental":2,"International":3};var sellerType={"Original":0,"Reseller":1};var BookType={'Required':0,"Optional":1};var allColors=new Array("red","green","blue","yellow","orange","purple","#CC3233","#65AA00","#3365CC","#309262","#D6AE02","#DD5512","#DD4377","#3365CC");var colorCounter=0;function stopEventBubbling(e){if(e&&e.preventDefault)e.preventDefault();if(e)e.cancelBubble=true;if(e&&e.stopPropagation)e.stopPropagation();}
function getNextColor(){var c=allColors[colorCounter];colorCounter++;if(colorCounter>=allColors.length)
colorCounter=0;return c;}
function CourseSection(courseName,courseNumber,dept,section,section_id){this.courseName=courseName;this.courseNumber=courseNumber;this.dept=dept;this.section=section;this.section_id=section_id;this.books=new Array();this.setBook=function(bid,title,author,isbn13,isbn10,type){if(isbn13||isbn10){var b=new Book(bid,title,author,isbn13,isbn10,type);isbn=isbn10;if(isbn10==null)isbn=isbn13;this.books[isbn]=b;}}
this.getBook=function(isbn){return this.books[isbn];}
this.block=null;this.booksBlock=null;this.getBlock=function(){if(this.block!=null&&browserType()!='IE'){this.booksBlock.innerHTML="";for(var i in this.books){if(typeof this.books[i]=='function')continue;this.booksBlock.appendChild(this.books[i].getBlock());}
return this.block;}
this.block=document.createElement('div');this.block.style.borderLeft="2px solid "+getNextColor();this.block.style.paddingLeft="8px";this.block.style.marginBottom="15px";this.block.style.width="97%";var heading=document.createElement('div');heading.innerHTML=this.courseName;heading.style.fontSize="24px";heading.style.borderBottom="1px solid #260D00";this.block.appendChild(heading);this.booksBlock=document.createElement('div');this.booksBlock.style.marginLeft="8px";this.booksBlock.style.marginTop="10px";for(var i in this.books){if(typeof this.books[i]=='function')continue;this.booksBlock.appendChild(this.books[i].getBlock());}
this.block.appendChild(this.booksBlock);return this.block;}
this.checkRestrictions=function(){for(var i in this.books){if(typeof this.books[i]=='function')continue;this.books[i].checkRestrictions();}}}
function Book(id,title,author,isbn13,isbn10,type){this.id=id;this.isbn13=isbn13;this.isbn10=isbn10
this.title=title;this.author=author;this.type=type;this.offers=new Array();this.addOffer=function(type,merchant,price,url){var o=new Offer(type,merchant,price,url);this.offers.push(o);this.offers.sort(sortOffers);Restrictions.add_available_type(type);Restrictions.add_available_merchant(merchant);Restrictions.set_max_price(price);}
this.block=null;this.offersBlock=null;this.getBlock=function(){if(this.block!=null&&browserType()!='IE'){this.offersBlock.innerHTML="";for(var i in this.offers){if(typeof this.offers[i]=='function')continue;if(this.offers[i].price>0)
this.offersBlock.appendChild(this.offers[i].getBlock());}
return this.block;}
this.block=document.createElement('div');this.block.style.borderLeft="2px solid "+getNextColor();this.block.style.paddingLeft="8px";this.block.style.marginBottom="10px";var heading=document.createElement('div');var span=document.createElement('div');span.innerHTML=this.title;span.style.cssFloat="left";span.style.fontSize="18px";heading.appendChild(span);span=document.createElement('div');span.innerHTML=this.type;span.style.cssFloat="right";span.style.fontSize="12px";span.style.fontColor="red";heading.appendChild(span);heading.style.borderBottom="1px solid #260D00";heading.style.height="18px";this.block.appendChild(heading);this.offersBlock=document.createElement('div');this.offersBlock.style.marginTop="10px";for(var i in this.offers){if(typeof this.offers[i]=='function')continue;if(this.offers[i].price>0)
this.offersBlock.appendChild(this.offers[i].getBlock());}
this.block.appendChild(this.offersBlock);return this.block;}
this.checkRestrictions=function(){for(var i in this.offers){if(typeof this.offers[i]=='function')continue;this.offers[i].checkRestrictions();}}}
function Offer(type,merchant,price,url){this.type=type;this.merchant=merchant;this.price=price;this.url=url;this.getLink=function(text,target,title){var a=document.createElement('a');a.href=this.url;if(target==null)a.target="_blank";else a.target=target;if(text==null)a.innerHTML=this.url;else a.innerHTML=text;if(title!=null)a.title=title;a.onclick=function(e){if(this.href!="")
window.open(this.href);stopEventBubbling(e);return false;}
return a;}
this.block=null;this.getBlock=function(){Restrictions.add_available_type(this.type);Restrictions.add_available_merchant(this.merchant);Restrictions.set_max_price(this.price);if(this.block&&browserType()!='IE')return this.block;this.block=document.createElement('div');this.block.obj=this;var b=document.createElement('div');b.appendChild(this.getLink(this.merchant));b.style.width="60%";this.block.appendChild(b);b=document.createElement('div');b.innerHTML=this.type;b.style.width="20%";b.style.marginLeft="60%";b.style.marginTop="-18px";this.block.appendChild(b);b=document.createElement('div');b.innerHTML="$"+formatPrice(this.price);b.style.width="20%";b.style.marginTop="-18px";b.style.marginLeft="80%";this.block.appendChild(b);this.block.style.padding="5px";this.block.style.borderBottom="1px solid #260D00";this.block.style.height="20px";this.block.style.cursor="pointer";this.block.onmouseover=function(){this.style.background="#CFE5FF";}
this.block.onmouseout=function(){this.style.background="";}
this.block.onclick=function(){if(this.obj.url!="")
window.open(this.obj.url);}
return this.block;}
this.hidden=false;this.checkRestrictions=function(){if(!this.block)return;if(this.price>=Restrictions.price_min&&this.price<=Restrictions.price_max&&(Restrictions.all_merchants||Restrictions.selected_merchants.contains(this.merchant))&&(Restrictions.all_types||Restrictions.selected_types.contains(this.type))){this.block.style.display="";this.hidden=false;}else{this.hidden=true;this.block.style.display="none";}}}
function sortOffers(offer1,offer2){return offer1.price-offer2.price;}
Array.prototype.contains=function(value){for(var i in this){if(this[i]==value)
return true;}
return false;}
function supports_local_storage(){return(typeof window.localStorage!='undefined'&&!(isChrome()));}
var CourseSections={'sections':new Array(),'getCourseSection':function(section_id,courseName,courseNumber,dept,section){if(!this.sections[section_id]){var tsec=new CourseSection(courseName,courseNumber,dept,section,section_id);this.sections[section_id]=tsec;CourseSectionChooser.addSection(tsec);}
return this.sections[section_id];},'updateDisplay':function(){for(var i in this.sections){if(typeof this.sections[i]=='function')continue;this.sections[i].checkRestrictions();}}};function clearElement(el){while(el.childNodes.length>0){el.removeChild(0);}}
var CourseSectionChooser={'control':document.getElementById('course_section_chioces'),'all':null,'search':null,'booksearch':null,'sections':new Array(),'create':function(){if(!this.control)this.control=document.getElementById('course_section_chioces');clearElement(this.control);this.sections=new Array();this.all=this.createBlock("All Sections");this.all.onclick=function(){this.obj.selectEvent(this,CourseSections.sections);}
this.control.appendChild(this.all);for(var i in CourseSections.sections){if(typeof CourseSections.sections[i]=='function')continue;this.addSection(CourseSections.sections[i]);}
this.search=this.createBlock("Course Search");this.search.id="section_chooser_search";this.search.onclick=function(){this.obj.selectEvent(this);CourseSearch.display();}
this.control.appendChild(this.search);this.booksearch=this.createBlock("Book Search");this.booksearch.onclick=function(){this.obj.selectEvent(this);BookSearch.display();}
this.control.appendChild(this.booksearch);},'addSection':function(section){var block=this.createBlock(section.courseName);block.section=section;block.onclick=function(){this.obj.selectEvent(this,new Array(this.section));}
var d;if(d=document.getElementById("section_chooser_search"))
this.control.insertBefore(block,d);else
this.control.appendChild(block);this.sections.push(block);},'createBlock':function(title,search){var div=document.createElement('div');if(search){var inp=document.createElement('input');inp.type="text";inp.value=title;inp.defaultValue=title;inp.onfocus=function(){if(inp.value==inp.defaultValue)
inp.value="";}
inp.onblur=function(){if(inp.value==""){inp.value=inp.defaultValue;}}
div.appendChild(inp);}else
div.innerHTML=title;div.obj=this;div.style.cursor="pointer";div.style.padding='3px';div.style.borderBottom="1px solid #260D00";return div;},'selectEvent':function(obj,sec_arr){this.all.style.backgroundColor="";this.search.style.backgroundColor="";this.booksearch.style.backgroundColor="";for(var i=0;i<this.sections.length;i++){this.sections[i].style.backgroundColor="";}
obj.style.backgroundColor="#FCFBEF";if(sec_arr)
refreshBookList(sec_arr);},'highlightSection':function(sid){for(var i=0;i<this.sections.length;i++){if(this.sections[i].section.section_id==sid)
$(this.sections[i]).effect("highlight",{},1000);}},'getBlock':function(sid){for(var i=0;i<this.sections.length;i++){if(this.sections[i].section.section_id==sid)
return this.sections[i];}}}
function EnumSelector(divId,name){this.name=name;this.divId=divId;this.block=document.getElementById(divId);this.all=null;this.allCB=new Array();this.updateDOM=function(){if(!this.block)this.block=document.getElementById(this.divId);this.block.innerHTML="";this.allCB=new Array();var span=document.createElement('div');this.all=this.createCheckBox('All',Restrictions.get_all_dynamic(this.name));span.appendChild(this.all);span.appendChild(document.createTextNode('All'));if(this.name!="types")
this.block.appendChild(span);this.all.onchange=function(){Restrictions.set_all_dynamic(this.obj.all.checked,this.obj.name);CourseSections.updateDisplay();}
for(var i=0;i<Restrictions['available_'+this.name].length;i++){this.addItem(Restrictions['available_'+this.name][i],Restrictions.get_selected_dynamic(Restrictions['available_'+this.name][i],this.name));}}
this.addItem=function(title,checked){var span=document.createElement('div');var cb=this.createCheckBox(title,checked);span.appendChild(cb);var span2=document.createElement('span');span2.innerHTML=title;span.appendChild(span2);this.block.appendChild(span);this.allCB.push(cb);cb.onchange=function(){RR("book_pref",title,this.checked);Restrictions['selected_'+this.obj.name]=new Array();for(var i=0;i<this.obj.allCB.length;i++){Restrictions.set_selected_dynamic(this.obj.allCB[i].id,this.obj.allCB[i].checked,this.obj.name);}
CourseSections.updateDisplay();}}
this.createCheckBox=function(title,checked){var cb=document.createElement('input');cb.type='checkbox';if(checked){cb.checked=checked;cb.defaultChecked=checked;}
cb.id=title;cb.obj=this;return cb;}};var localStorageBoolean={'get':function(key){if(window.localStorage.getItem(key)){var r=window.localStorage.getItem(key);return(r=="true");}else{return false;}},'isSet':function(key){for(var i=0;i<window.localStorage.length;i++){if(window.localStorage.key(i)==key)
return true;}
return false;}}
var CookieManager={'get':function(c_name){if(document.cookie.length>0){c_start=document.cookie.indexOf(c_name+"=");if(c_start!=-1){c_start=c_start+c_name.length+1;c_end=document.cookie.indexOf(";",c_start);if(c_end==-1)c_end=document.cookie.length;return unescape(document.cookie.substring(c_start,c_end));}}
return"";},'set':function(c_name,value,expiredays)
{var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);document.cookie=c_name+"="+escape(value)+((expiredays==null)?"":";expires="+exdate.toGMTString());},'exists':function(c_name){if(document.cookie.length>0){c_start=document.cookie.indexOf(c_name+"=");if(c_start!=-1){return true;}}
return false;}}
var localBooleanManager={'get':function(key){if(supports_local_storage()){if(window.localStorage.getItem(key)){var r=window.localStorage.getItem(key);return(r=="true");}
return false;}else{if(this.isSet(key))
return(CookieManager.get(key)=="true");return false;}},'isSet':function(key){if(supports_local_storage()){for(var i=0;i<window.localStorage.length;i++){if(window.localStorage.key(i)==key)
return true;}
return false;}else{return CookieManager.exists(key);}},'set':function(key,value){if(supports_local_storage()){window.localStorage.setItem(key,value);}else{CookieManager.set(key,value,365);}}}
var Restrictions={'price_min':0,'price_max':1,'max_possible_price':1.0,'all_merchants':false,'all_types':false,'available_types':new Array(),'available_merchants':new Array(),'selected_merchants':new Array(),'selected_types':new Array(),'merchant_selector':new EnumSelector('merchant_selector','merchants'),'type_selector':new EnumSelector('type_selector','types'),'default_merchants':/Duke|Amazon|Barnes|Chegg|Half/i,'default_types':/New|Used|Rental/i,'data_prefix':"book_restriction_",'add_available_type':function(type){if(!this.available_types.contains(type)){this.available_types.push(type);this.type_selector.updateDOM();}},'add_available_merchant':function(merchant){if(!this.available_merchants.contains(merchant)){this.available_merchants.push(merchant);this.merchant_selector.updateDOM();}},'set_max_price':function(price){price=price*1.0;if(price>this.max_possible_price){this.max_possible_price=price;$('#price_slider').slider('option','max',price);updatePriceRange();}},'get_all_dynamic':function(type){var all;var data_key=this.data_prefix+"all_"+type;if(localBooleanManager.isSet(data_key)){all=localBooleanManager.get(data_key);this['all_'+type]=all;return all;}else{localBooleanManager.set(data_key,this['all_'+type]);return this['all_'+type];}},'set_all_dynamic':function(boo,type){this['all_'+type]=boo;localBooleanManager.set(this.data_prefix+'all_'+type,this['all_'+type]);},'get_selected_dynamic':function(name,type){var a;var data_key=this.data_prefix+type+"_"+name;if(localBooleanManager.isSet(data_key)){a=localBooleanManager.get(data_key);if(a)this['selected_'+type].push(name);return a;}else{var v=this['default_'+type].test(name);localBooleanManager.set(data_key,v);return v;}},'set_selected_dynamic':function(name,boo,type){if(boo){this['selected_'+type].push(name);}else{for(var i in this['selected_'+type]){if(typeof this['selected_'+type][i]=='function')continue;if(this['selected_'+type][i]==name)
this['selected_'+type].slice(i);}}
var data_key=this.data_prefix+type+"_"+name;localBooleanManager.set(data_key,boo);}};var CourseSearch={'block':null,'searchbox':null,'results':null,'srchcount':0,'wait':200,'word':"",'prev_t':null,'lastword':"",'throbber':null,'search':function(input,cnt,nextpage){if(input==this.word&&input!=""&&cnt==this.srchcount&&input!=this.lastword){$.ajax({type:"GET",url:"ajax/json_search.php?query="+input+"&r="+random,success:function(msg){if(cnt==CourseSearch.srchcount){CourseSearch.displayResults(msg);CourseSearch.lastword=input;}}});}},'displayResults':function(json){if(json==="-1"){alert("Your sessions appears to have expired.  Please refresh the page.");return;}
var data=eval('('+json+')');this.results.innerHTML="";for(var i=0;i<data['courses'].length;i++){this.results.appendChild(this.getRow(data['courses'][i]['Title'],data['courses'][i]['ID']));}},'getRow':function(title,id){var div=document.createElement('div');div.courseID=id;div.style.width="100%";div.style.padding="5px";div.style.cursor="pointer";div.style.borderTop="1px solid #260D00";div.style.fontSize="18px";div.innerHTML=title;div.onmouseover=function(){this.style.background="#CFE5FF";}
div.onmouseout=function(){this.style.background="";}
div.onclick=function(){CourseSearch.getSection(this);}
return div;},'getSection':function(row){$.ajax({type:"GET",url:"ajax/json_getSections.php?class="+row.courseID+"&r="+random,success:function(msg){CourseSearch.selectSection(row,msg);}});},'selectSection':function(row,json){if(json==="-1"){alert("Session expired.  Please refresh the page.");return;}
var data=eval('('+json+')');var b=document.createElement('div');b.style.marginLeft="10px";for(var i=0;i<data['sections'].length;i++){var r=data['sections'][i]
b.appendChild(this.getSecRow(r["ID"],r["Type"],r["SecNum"],r["Days"],r['begin'],r['end']));}
this.results.insertBefore(b,row.nextSibling);},'getSecRow':function(sid,type,secnum,days,begin,end){var div=document.createElement('div');div.sectionID=sid;div.style.width="100%";div.style.padding="5px";div.style.cursor="pointer";div.style.borderTop="1px solid #260D00";div.style.fontSize="14px";div.innerHTML=type+" "+secnum+"("+fromStrDay(days)+": "+minToTime(begin)+"-"+minToTime(end)+")";var throbber=document.createElement('img');throbber.style.display="none";throbber.style.cssFloat="right";throbber.src='/images/ajax-loader.gif';div.appendChild(throbber);div.throbber=throbber;var msg=document.createElement('span');msg.style.display="none";msg.style.cssFloat="right";div.appendChild(msg);div.msg=msg;div.onmouseover=function(){this.style.background="#CFE5FF";}
div.onmouseout=function(){this.style.background="";}
div.onclick=function(){this.throbber.style.display="";loadBooksFromAJAX(sid,this.throbber,this.msg);}
return div;},'getBlock':function(){if(this.block!=null&&browserType()!='IE'){if(this.searchbox.value==this.searchbox.defaultValue)
this.searchbox.value="";this.searchbox.focus();return this.block;}
this.block=document.createElement('div');this.block.style.width="95%";this.searchbox=document.createElement('input');this.searchbox.type="text";this.searchbox.value="Search for Courses";this.searchbox.defaultValue="Search for Courses";this.searchbox.CourseSearch=this;this.searchbox.onfocus=function(){var cs=this.CourseSearch;if(cs.searchbox.value==cs.searchbox.defaultValue)
cs.searchbox.value="";}
this.searchbox.onblur=function(){var cs=this.CourseSearch;if(cs.searchbox.value=="")
cs.searchbox.value=cs.searchbox.defaultValue;}
this.searchbox.onkeyup=function(e){var cs=this.CourseSearch;if(cs.searchbox.value==cs.searchbox.defaultValue)
return;cs.srchcount=cs.srchcount+1;cs.word=cs.searchbox.value;if(cs.prev_t!=null)
window.clearTimeout(cs.prev_t);cs.prev_t=window.setTimeout("CourseSearch.search('"+cs.word+"',"+cs.srchcount+");",cs.wait);}
this.searchbox.style.width="400px";this.searchbox.style.height="30px";this.searchbox.style.fontSize="20px";this.searchbox.style.marginLeft="175px";this.searchbox.style.marginTop="20px";this.block.appendChild(this.searchbox);this.throbber=document.createElement('img');this.results=document.createElement('div');this.results.style.width="100%";this.results.style.marginTop="25px";this.results.style.padding="10px";this.block.appendChild(this.results);return this.block;},'display':function(){var main=document.getElementById('books_main');main.innerHTML="";main.appendChild(this.getBlock());this.searchbox.focus();}}
var SearchStatus={"NotSent":0,"Sent":1,"Received":2,"Show":3};var BookSearch={'block':null,'searchbox':null,'results':null,'throbber':null,'page':1,'srchcount':0,'wait':200,'word':"",'prev_t':null,'lastword':"",'nextPage':"",'nextPageNum':-1,'reqPage':-1,'reqWord':"",'results':new Array(),'requests':new Array(),'search':function(){var s=getHash();s=s.substr(s.indexOf("=")+1);var word=Url.decode(s.substr(0,s.indexOf("&page")));var page=parseInt(s.substr(s.indexOf("=")+1));BookSearch.searchbox.value=word;var q="query="+word+"&page="+page;if(!this.requests[q]){this.throbber.style.display="";this.requests[q]=SearchStatus.Show;this.ajaxSearch(q);}if(this.requests[q]==SearchStatus.Received){this.requests[q]=SearchStatus.Show;this.useResults(q);}else if(this.requests[q]==SearchStatus.Sent){this.requests[q]=SearchStatus.Show;}},'ajaxSearch':function(query,isNextPage,pagenum){if(this.results[query]&&this.results[query]!=null){this.useResults(query);return;}
$.ajax({type:"GET",url:"amazon/book_search.php?"+query+"&r="+random,success:function(msg){BookSearch.results[query]=msg;BookSearch.useResults(query);}});},'useResults':function(query){if(this.requests[query]==SearchStatus.Sent){this.requests[query]=SearchStatus.Received;}else if(this.requests[query]==SearchStatus.Show){this.requests[query]=SearchStatus.Received;var s=query;s=s.substr(s.indexOf("=")+1);var word=Url.decode(s.substr(0,s.indexOf("&page")));var page=s.substr(s.indexOf("=")+1);this.throbber.style.display="none";this.lastword=word;this.page=page;this.displayResults(this.results[query]);var nextPage=parseInt(BookSearch.page)+1;var q="query="+word+"&page="+nextPage;if(!this.requests[q]){BookSearch.requests[q]=SearchStatus.Sent;BookSearch.ajaxSearch(q,true,nextPage);}}},'displayResults':function(json){if(json==="-1"){alert("Your sessions appears to have expired.  Please refresh the page.");return;}
var data=eval('('+json+')');this.results.innerHTML="";var data=eval("("+json+")");for(var i=0;i<data.length;i++){this.results.appendChild(this.getRow(data[i]['title'],data[i]['author'],data[i]['image'],data[i]['isbn'],data[i]['image_height'],data[i]['image_width']));}
var div=document.createElement('div');var more=document.createElement('input');more.type="button";more.value="more";more.onclick=function(){BookSearch.getMore();}
this.results.appendChild(more);this.results.appendChild(div);window.scrollTo(0,0);},'getMore':function(){this.page++;Hash.go("query="+this.lastword+"&page="+this.page);},'getBook':function(isbn,misc,title,throbber){$.ajax({type:"GET",url:"campusbooks/getBooks.php?isbn="+isbn+"&r="+random,success:function(msg){throbber.style.display="none";var json=eval('('+msg+')');var a=json[isbn];misc.setBook(isbn,title,"",isbn,isbn,"");var book=misc.getBook(isbn);for(var j=0;j<a.length;j++){var offer=a[j];book.addOffer(offer['Type'],offer["Merchant"],offer['Price'],offer["URL"]);}
CourseSectionChooser.selectEvent(CourseSectionChooser.getBlock(-99),new Array(misc));}});},'getRow':function(title,author,picURL,isbn,img_height,img_width){var div=document.createElement('div');div.isbn=isbn;div.bookTitle=title;div.style.width="100%";div.style.padding="10px";div.style.cursor="pointer";div.style.borderTop="1px solid #260D00";div.style.fontSize="18px";div.onmouseover=function(){this.style.background="#CFE5FF";}
div.onmouseout=function(){this.style.background="";}
div.onclick=function(){var misc=CourseSections.getCourseSection(-99,"Misc. Books");this.throbber.style.display="";BookSearch.getBook(this.isbn,misc,this.bookTitle,this.throbber);}
var throbber=document.createElement('img');throbber.style.display="none";throbber.style.cssFloat="right";throbber.src='/images/ajax-loader.gif';div.appendChild(throbber);div.throbber=throbber;var img=document.createElement('img');img.style.marginLeft="0";img.src=picURL;if(picURL&&/http/.test(picURL))
div.appendChild(img);if(img_height)
div.style.height=(parseInt(img_height)+0)+"px";var div2=document.createElement('div');div2.style.padding="5px";div2.style.paddingLeft="10px";if(img_height){div2.style.marginLeft=img_width+"px";div2.style.marginTop="-"+img_height+"px";}
var h1=document.createElement('h4');h1.innerHTML=title;div2.appendChild(h1);var h2=document.createElement('div');h2.style.fontSize="16px";h2.innerHTML="Author: "+author;div2.appendChild(h2);h2=document.createElement('div');h2.style.fontSize="16px";h2.innerHTML="ISBN: "+isbn;div2.appendChild(h2);div.appendChild(div2);return div;},'getBlock':function(){if(this.block!=null&&browserType()!='IE'){this.searchbox.onfocus();this.searchbox.focus();return this.block;}
this.block=document.createElement('div');this.block.style.width="95%";var d=document.createElement('div');d.style.width="515px";d.style.margin="0 150px";d.style.marginTop="20px";this.throbber=document.createElement('img');this.throbber.style.display="none";this.throbber.style.marginLeft="-40px";this.throbber.style.marginBottom="-20px";this.throbber.src='/images/ajax-loader.gif';d.appendChild(this.throbber);var form=document.createElement('form');this.searchbox=document.createElement('input');this.searchbox.type="text";this.searchbox.value="Search by Title, Author, etc.";this.searchbox.defaultValue="Search by Title, Author, etc.";this.searchbox.BookSearch=this;this.searchbox.onfocus=function(){var cs=this.BookSearch;if(cs.searchbox.value==cs.searchbox.defaultValue)
cs.searchbox.value="";}
this.searchbox.onblur=function(){var cs=this.BookSearch;if(cs.searchbox.value=="")
cs.searchbox.value=cs.searchbox.defaultValue;}
form.onsubmit=function(e){stopEventBubbling(e);BookSearch.page=1;BookSearch.lastword=BookSearch.searchbox.value;Hash.go("query="+BookSearch.searchbox.value+"&page=1");return false;}
this.searchbox.style.width="400px";this.searchbox.style.height="30px";this.searchbox.style.fontSize="20px";form.appendChild(this.searchbox);var enter=document.createElement('input');enter.type="button";enter.value="Search";enter.style.marginLeft="25px";enter.onclick=function(){Hash.go("query="+BookSearch.searchbox.value+"&page=1");}
form.appendChild(enter);d.appendChild(form);this.block.appendChild(d);this.results=document.createElement('div');this.results.style.width="100%";this.results.style.marginTop="25px";this.results.style.padding="10px";this.block.appendChild(this.results);return this.block;},'display':function(){var main=document.getElementById('books_main');main.innerHTML="";main.appendChild(this.getBlock());this.searchbox.focus();}}
function hashHandler(){if(Hash.getHashP().indexOf("sids")==0)
loadBooksFromHash()
else if(Hash.getHashP().indexOf('query')==0){CourseSectionChooser.booksearch.onclick();BookSearch.display();BookSearch.search();}else if(Hash.getHashP().indexOf("isbn")==0){}}
function loadBooksFromJSON(json,sids){var count=0;for(var i=0;i<sids.length;i++){var a=json[sids[i]];for(var j=0;j<a.length;j++){count++;var b=a[j];var sec=CourseSections.getCourseSection(b['SectionID'],b['Course'],b['Class'],b['Dept'],b['Section']);sec.setBook(b["ID"],b['Title'],"",b['ISBN'],b['ISBN'],b['Type']);var book=sec.getBook(b['ISBN']);for(var k=0;k<b['offers'].length;k++){var offer=b['offers'][k];book.addOffer(offer['Type'],offer["Merchant"],offer['Price'],offer["URL"]);}}}
return(count>0);}
function loadBooksFromAJAX(sid,throbber,message){$.ajax({type:"GET",url:"campusbooks/getBooks.php?sids="+sid+"&r="+random,success:function(msg){if(throbber)throbber.style.display="none";var json=parseJSON(msg);var res=loadBooksFromJSON(json,new Array(sid));if(res){var block=CourseSectionChooser.getBlock(sid);CourseSectionChooser.selectEvent(block,new Array(block.section));CourseSectionChooser.highlightSection(sid);}else{message.style.display="";message.innerHTML="We currently have no books on record for this section.";try{setTimeout(function(msg){msg.style.display='none';},3000,message);}catch(err){;}}}});}
function loadBooksFromHash(){if(getHash()==""){CourseSectionChooser.search.onclick();return;}
booksMainLoading();$.ajax({type:"GET",url:"campusbooks/getBooks.php?"+getHash()+"&r="+random,success:function(msg){var json=parseJSON(msg);var sids=getHash().substr(getHash().indexOf("=")+1).split("-");loadBooksFromJSON(json,sids);CourseSectionChooser.selectEvent(CourseSectionChooser.all,CourseSections.sections);if(isNewUser){$("#merchant_selector").tooltip(0).show();}}});}
function booksMainLoading(){document.getElementById('books_main').innerHTML="";var div=document.createElement("div");div.style.width="95%";div.style.paddingTop="30px";var img=document.createElement("img");img.src="/images/loading-bar.gif";img.style.marginLeft="220px";div.appendChild(img);var div2=document.createElement('div');div2.innerHTML="Getting book prices...";div2.style.width="100%";div2.style.textAlign="center";div2.style.fontSize="20px";div.appendChild(div2);document.getElementById('books_main').appendChild(div);}
function updatePriceRange(event,ui){var min=$('#price_slider').slider('values',0);var max=$('#price_slider').slider('values',1);Restrictions.price_min=min;Restrictions.price_max=max;document.getElementById("price_range_tag").innerHTML="$"+min+" - $"+max;CourseSections.updateDisplay();}
function loadBookViewer(){CourseSectionChooser.create();$("#price_slider").slider({animate:true,range:true,min:0,max:1000,values:[0,1000]});$('#price_slider').bind("slide",updatePriceRange);$('#price_slider').bind("slidechange",updatePriceRange);updatePriceRange();if(isNewUser){$("#merchant_selector").tooltip({opacity:0.9,tip:"#merchant_tip"});}}
var isNewUser=(function(){if(!!(window.attachEvent&&!window.opera))return false;if(CookieManager.exists("book_user_cnt")){var i=parseInt(CookieManager.get("book_user_cnt"));if(i<2){i++;CookieManager.set("book_user_cnt",i,90);return true;}else{CookieManager.set("book_user_cnt",i,90);return false;}}else{CookieManager.set("book_user_cnt",1,90);return true;}})();function RR(type,val1,val2){$.ajax({type:"GET",url:"/ajax/r.php?type="+type+"&val1="+val1+"&val2="+val2+"&r="+random,success:function(msg){}});}
function refreshBookList(arr){var main=document.getElementById('books_main');main.innerHTML="";for(var i in arr){if(typeof arr[i]=='function')continue;main.appendChild(arr[i].getBlock());}
CourseSections.updateDisplay();}
function parseJSON(data){if(JSON&&JSON.parse&&typeof JSON.parse=='function'){return JSON.parse(data);}else{return eval('('+data+')');}}
var Url={encode:function(string){return escape(this._utf8_encode(string));},decode:function(string){return this._utf8_decode(unescape(string));},_utf8_encode:function(string){string=string.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n<string.length;n++){var c=string.charCodeAt(n);if(c<128){utftext+=String.fromCharCode(c);}
else if((c>127)&&(c<2048)){utftext+=String.fromCharCode((c>>6)|192);utftext+=String.fromCharCode((c&63)|128);}
else{utftext+=String.fromCharCode((c>>12)|224);utftext+=String.fromCharCode(((c>>6)&63)|128);utftext+=String.fromCharCode((c&63)|128);}}
return utftext;},_utf8_decode:function(utftext){var string="";var i=0;var c=c1=c2=0;while(i<utftext.length){c=utftext.charCodeAt(i);if(c<128){string+=String.fromCharCode(c);i++;}
else if((c>191)&&(c<224)){c2=utftext.charCodeAt(i+1);string+=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2;}
else{c2=utftext.charCodeAt(i+1);c3=utftext.charCodeAt(i+2);string+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3;}}
return string;}}