var page_command;
function courselisting_init(){
page_command=new PageAction();
if(document.getElementById("fTerm")){
document.getElementById("fTerm").onchange=load_depts;
}
$("#TextbookForm").keypress(disableEnterKeypress);
document.getElementById("course-bookdisplay").style.display="none";
var _1=document.getElementById("fTerm");
if(_1.value!="0|0"){
load_depts();
}
var _2=document.getElementById("search_section").value;
if(_2.length>0){
load_search_prods(_2);
}
check_action();
}
function check_action(){
if(page_command.execute){
execute_request(page_command.url,page_command.command);
page_command.execute=false;
}
setTimeout("check_action()",800);
}
function submit_request(_3,_4){
page_command.url=_3;
page_command.command=_4;
page_command.execute=true;
}
function execute_request(_5,_6){
var _7=null;
var _8=null;
var _9=document.getElementById("xmlrequest");
_9.innerHTML="";
_9.style.display="none";
if(window.XMLHttpRequest){
_7=new XMLHttpRequest();
}else{
if(window.ActiveXObject){
_7=new ActiveXObject("Microsoft.XMLHTTP");
}else{
_9.innerHTML="<div id=\"flash\" class=\"error\"><p>You must have ActiveX enabled.</p></div>";
_9.style.display="block";
}
}
if(_7!=null){
_7.onreadystatechange=function(){
if(_7.readyState==4){
if(_7.status==200){
switch(_6){
case "load_depts":
process_dept(_7);
break;
case "load_courses":
process_courses(_7);
break;
case "load_sections":
process_sections(_7);
break;
case "load_products":
process_products(_7);
break;
}
}else{
_9.innerHTML="<div id=\"flash\" class=\"error\"><p>There has been an error processing your request.</p></div>";
_9.style.display="block";
}
}
};
if(document.getElementById("debug_xml")){
_9.innerHTML=_5;
_9.style.display="block";
}
var t=new Date().getTime();
_7.open("GET",_5+"&t="+t,true);
_7.send(null);
}
}
function PageAction(){
this.execute=false;
this.command=null;
this.url=null;
}
function load_depts(){
var _b=document.getElementById("fCourse");
var _c=document.getElementById("fSection");
var _d=document.getElementById("fDept");
var _e=document.getElementById("fTerm");
var _f=document.getElementById("course-bookdisplay");
_f.style.display="none";
_f.innerHTML="";
_b.disabled=true;
_c.disabled=true;
_d.disabled=true;
_b.options.length=0;
_c.options.length=0;
_d.options.length=0;
_d.options[0]=new Option("Loading...");
campusterm_id=_e.value;
pos=campusterm_id.indexOf("|");
campus_id=campusterm_id.substr(0,pos);
term_id=campusterm_id.substr(pos+1,campusterm_id.length+1);
url="textbooks_xml.asp?control=campus&campus="+campus_id+"&term="+term_id;
submit_request(url,"load_depts");
}
function get_term(){
var _10=document.getElementById("fTerm");
campusterm_id=_10.value;
pos=campusterm_id.indexOf("|");
campus_id=campusterm_id.substr(0,pos);
term_id=campusterm_id.substr(pos+1,campusterm_id.length+1);
return term_id;
}
function process_dept(req){
var doc=req.responseXML;
var _13=doc.getElementsByTagName("department");
var _14=document.getElementById("fDept");
_14.options.length=0;
if(_13.length==0){
_14.options[0]=new Option("-- Course info not available --","");
_14.disabled=true;
}else{
for(i=0;i<_13.length;i++){
var _15=_13[i];
_14.options[i]=new Option(_15.getAttribute("abrev")+"-"+_15.getAttribute("name"),_15.getAttribute("id"));
}
_14.disabled=false;
}
}
function load_courses(){
var _16=document.getElementById("fCourse");
var _17=document.getElementById("fSection");
var _18=document.getElementById("course-bookdisplay");
_18.style.display="none";
_18.innerHTML="";
_16.disabled=true;
_17.disabled=true;
_16.options.length=0;
_17.options.length=0;
_16.options[0]=new Option("Loading...");
var _19=document.getElementById("fDept").value;
url="textbooks_xml.asp?control=department&dept="+_19+"&term="+get_term();
submit_request(url,"load_courses");
}
function process_courses(req){
var doc=req.responseXML;
var _1c=doc.getElementsByTagName("course");
var _1d=document.getElementById("fCourse");
_1d.options.length=0;
for(i=0;i<_1c.length;i++){
var _1e=_1c[i];
_1d.options[i]=new Option(_1e.getAttribute("name"),_1e.getAttribute("id"));
}
_1d.disabled=false;
}
function load_sections(){
var _1f=document.getElementById("fSection");
var _20=document.getElementById("course-bookdisplay");
_20.style.display="none";
_20.innerHTML="";
_1f.disabled=true;
_1f.options.length=0;
_1f.options[0]=new Option("Loading...");
var _21=document.getElementById("fCourse").value;
url="textbooks_xml.asp?control=course&course="+_21+"&term="+get_term();
submit_request(url,"load_sections");
}
function process_sections(req){
var doc=req.responseXML;
var _24=doc.getElementsByTagName("section");
var _25=document.getElementById("fSection");
_25.options.length=0;
for(i=0;i<_24.length;i++){
var _26=_24[i];
_25.options[i]=new Option(_26.getAttribute("name")+"-"+_26.getAttribute("instructor"),_26.getAttribute("id"));
}
_25.disabled=false;
if(_25.options.length==1){
_25.options.selectedIndex=0;
load_products();
}
}
function load_products(){
var _27=document.getElementById("fSection").value;
var _28=document.getElementById("course-bookdisplay");
_28.style.display="block";
_28.innerHTML="<h3>Loading textbooks...</h3>";
url="textbooks_xml.asp?control=section&section="+_27;
submit_request(url,"load_products");
}
function process_products(req){
var doc=req.responseText;
document.getElementById("course-bookdisplay").innerHTML=doc;
isbn_init();
initProducts();
initLightbox();
}
function initProducts(){
if(document.getElementById("rcdCount")){
initProdOption();
initProdQty();
if($(".jumpbooks-substitutions").length>0){
get_isbns();
}
if($(".barchart-list").length>0){
get_barcharts();
}
}else{
if(!document.getElementById("course-bookdisplay").hasChildNodes()){
document.getElementById("xmlrequest").innerHTML="<div id=\"flash\" class=\"error\"><p>The textbooks for this section can not be found at this time.</p></div>";
document.getElementById("xmlrequest").style.display="block";
document.getElementById("course-bookdisplay").style.display="none";
}
}
}
function initProdOption(){
var _2b=document.getElementById("rcdCount").value;
$(".product-sku").click(updateTotal);
$(".book-pref > select").change(updateTotal);
for(i=1;i<=_2b;i++){
$("input:enabled[name='sku_"+i+"']:eq(0)").attr("checked","checked");
}
updateTotal();
}
function initProdQty(){
$(".product-qty").blur(productQtyAction);
}
function productQtyAction(){
updateTotal();
}
function productOptionAction(){
document.getElementById("quickProdOption").selectedIndex=0;
updateTotal();
}
function updateProdOption(){
var _2c=document.getElementById("quickProdOption");
var _2d=document.getElementById("rcdCount").value;
var _2e;
_2e=_2c.selectedIndex;
if(_2e>0){
_2e-=1;
for(i=1;i<=_2d;i++){
if(document.getElementById("no-product-"+i).value=="0"){
if(document.getElementById("sku_"+i).options.length>1&&document.getElementById("pf_type_id-"+i).value=="2"){
document.getElementById("sku_"+i).selectedIndex=_2e;
}
}
}
updateTotal();
}
}
function updateTypes(_2f){
var _30=document.getElementById("f"+_2f);
var _31=document.getElementById("rcdCount").value;
var _32;
if(_30.checked){
_32=1;
}else{
_32=0;
}
for(i=1;i<=_31;i++){
if(document.getElementById("no-product-"+i).value=="0"){
if(document.getElementById("product-opt-"+i).value==_2f){
document.getElementById("qty-"+i).value=_32;
}
}
}
updateTotal();
}
function updateTotal(){
var _33=document.getElementById("course-bookdisplay-total-amt");
var _34=document.getElementById("rcdCount").value;
var _35=0;
var _36=0;
$(".product-rowid").each(function(){
var i=$(this).val();
if(document.getElementById("no-product-"+i).value=="0"){
var _38=document.getElementById("qty-"+i).value*1;
if(_38==0){
document.getElementById("qty-"+i).value="0";
}
if(_38>0){
_36+=_38;
switch(document.getElementById("pf_type_id-"+i).value*1){
case 1:
var _39=new Array();
var _3a=document.getElementById("gmprice-"+i).value;
_39=_3a.split(",");
_35+=_38*_39[document.getElementById("sku_"+i).selectedIndex];
break;
case 2:
case 6:
if($("#sku_"+i+" :selected").text().indexOf("Used")>=0){
if($("#sku_"+i+" :selected").text().indexOf("(Rental)")>=0){
_35+=_38*$("#product-used-rental-price-"+i).val();
$("#rental_flag-"+i).val("1");
$("#courseproduct-avail-message-"+i).text($("#product-used-rental-message-"+i).val());
$("#courseproduct-price-message-"+i).text(displayCurrency($("#product-used-rental-price-"+i).val()));
}else{
_35+=_38*$("#product-used-price-"+i).val();
$("#rental_flag-"+i).val("0");
$("#courseproduct-avail-message-"+i).text($("#product-used-message-"+i).val());
$("#courseproduct-price-message-"+i).text(displayCurrency($("#product-used-price-"+i).val()));
}
}else{
if($("#sku_"+i+" :selected").text().indexOf("(Rental)")>=0){
_35+=_38*$("#product-new-rental-price-"+i).val();
$("#rental_flag-"+i).val("1");
$("#courseproduct-avail-message-"+i).text($("#product-new-rental-message-"+i).val());
$("#courseproduct-price-message-"+i).text(displayCurrency($("#product-new-rental-price-"+i).val()));
}else{
_35+=_38*$("#product-new-price-"+i).val();
$("#rental_flag-"+i).val("0");
$("#courseproduct-avail-message-"+i).text($("#product-new-message-"+i).val());
$("#courseproduct-price-message-"+i).text(displayCurrency($("#product-new-price-"+i).val()));
}
}
break;
case 3:
case 7:
_35+=_38*document.getElementById("gmprice-"+i).value;
break;
default:
_35+=_38*document.getElementById("gmprice-"+i).value;
break;
}
}
}
});
if(document.getElementById("btn-addtocart")){
if(_36>0){
document.getElementById("btn-addtocart").disabled=false;
}else{
document.getElementById("btn-addtocart").disabled=true;
}
}
if(document.getElementById("btn-reserve")){
if(_36>0){
document.getElementById("btn-reserve").disabled=false;
}else{
document.getElementById("btn-reserve").disabled=true;
}
}
_33.innerHTML=displayCurrency(_35);
if($(".get-rentals").length>0){
get_rentals();
}
}
function load_search_prods(_3b){
var _3c=document.getElementById("course-bookdisplay");
_3c.style.display="block";
_3c.innerHTML="<h3>Loading textbooks...</h3>";
var url="textbooks_xml.asp?control=section&section="+_3b;
submit_request(url,"load_products");
}
function reserve_to_cart(){
var _3e=document.getElementById("rcdCount").value;
for(i=1;i<=_3e;i++){
if(document.getElementById("purch_opt-"+i)){
document.getElementById("purch_opt-"+i).value="R";
}
}
document.getElementById("TextbookForm").submit();
}
function get_barcharts(){
var url="textbooks_xml.asp";
$("table.data").each(function(i){
var _41=new Array();
var _42=this.id.split("-",2)[1];
$(this).find(".product-field-isbn").each(function(){
_41.push($(this).val());
});
$.get(url,{control:"barcharts",isbns:_41.join(","),sectionId:_42},function(_43){
$("#barchart-list-"+_42).html(_43);
addProductSeed("barchart_"+_42);
initProdQty();
isbn_init();
});
});
}
function get_rentals(){
var _44=new Array();
var _45=new Array();
var _46=new Array();
$(".product-field-pf_id").each(function(){
_44.push($(this).val());
_46.push($(this).attr("id").split("-",2)[1]);
_45.push($("#sku_"+$(this).attr("id").split("-",2)[1]).val());
});
url="textbooks_xml.asp";
$.getJSON(url,{control:"rental",pfIds:_44.join(","),rowCounts:_46.join(","),skus:_45.join(","),sectionId:$("#fSection").val()},function(_47){
$.each(_47.items,function(i,_49){
$("#rental_message-"+_49.row).html(_49.message);
});
});
}
function get_isbns(){
var url="textbooks_xml.asp";
$("table.data").each(function(){
var _4b=this.id.split("-",2)[1];
var _4c=new Array();
$(this).find(".product-field-isbn").each(function(){
_4c.push($(this).val());
});
$.get(url,{control:"jumpbooks",isbns:_4c.join(","),sectionId:_4b},function(_4d){
$("#jumpbooks-substitutions-"+_4b).html(_4d);
addProductSeed("jump_"+_4b);
initProdQty();
isbn_init();
initActiveResult(substituteItem,"substitute");
initActiveResult(cancelItem,"cancel");
});
});
}
function addProductSeed(_4e){
if($("#product-seeds").length>0){
if($("#product-seeds").val().length==0){
$("#product-seeds").val(_4e);
}else{
var _4f=$("#product-seeds").val().split(",");
_4f.push(_4e);
$("#product-seeds").val(_4f.join(","));
}
}
}
function substituteItem(o){
$(".product-field-isbn[@value="+o.isbn10+"],.product-field-isbn[@value="+o.isbn13+"]").each(function(){
$("#qty-"+getRowId(this.id)).val(0);
$("#qty-"+o.rowId).val(1);
$("#substitute-"+o.rowId).hide();
$("#cancel-"+o.rowId).show();
updateTotal();
});
}
function cancelItem(o){
$(".product-field-isbn[@value="+o.isbn10+"],.product-field-isbn[@value="+o.isbn13+"]").each(function(){
$("#qty-"+getRowId(this.id)).val(1);
$("#qty-"+o.rowId).val(0);
$("#cancel-"+o.rowId).hide();
$("#substitute-"+o.rowId).show();
updateTotal();
});
}
function getRowId(_52){
return _52.split("-",2)[1];
}
function initActiveResult(_53,_54){
var _54=(_54==null)?"":_54;
$(".activeresult-action-"+_54).each(function(_55){
$(this).click(function(){
var _56=this.id.split("-",2)[1];
var _57=new Object();
$(".param-"+_56).each(function(i){
var key=this.id.split("-",3)[2];
_57[key]=this.value;
});
_53(_57);
return false;
});
});
}
function initProductSearchResult(){
initActiveResult(setProduct,"select");
}
function initCatalogSearchResult(){
initActiveResult(setCatalog);
}
function displayCurrency(_5a){
var _5b=_5a.toString();
if(_5a==0){
_5b="000";
}
if(_5b.length==2){
_5b="0"+_5b;
}
if(_5b.length==1){
_5b="00"+_5b;
}
var _5c=_5b.length;
return "$"+_5b.substr(0,_5c-2)+"."+_5b.substr(_5c-2,_5c);
}

