function PriceAvailability(isbn,quantity) { this.isbn = isbn; this.quantity = 1; if(quantity)this.quantity = quantity; // GET request variables this.searchVars = new Array(); this.searchVars['ClientID'] = 'PAL'; //this.searchVars['ClientPassword'] = 'xxxx'; this.searchVars['ProductIDType'] = '15'; if(isbn)this.searchVars['ProductIDValue'] = isbn; this.searchVars['SupplyQuantity'] = this.quantity; this.searchVars['CurrencyCode'] = 'AUD'; if(typeof PriceAvailability._initialized == 'undefined') { PriceAvailability.prototype.load = function() { this.loadAjax(); this.getPrice(); this.getAvailability(); this.getShipDate(); }; // old ajax function PriceAvailability.prototype.loadAjax = function() { //var sUrl = 'http://palgravedev.itechne.com/site/OnixPA02.nsf/PAService?readform&' + this.getSearchVars(); //var sUrl = 'http://secondarydev.itechne.com/macmillan/OnixPA01.nsf/PAService?readform&' + this.getSearchVars(); //var sUrl = 'http://secondarydev.itechne.com/site/OnixPA02.nsf/PAService?readform&' + this.getSearchVars(); //var sUrl = 'http://primarydev.itechne.com/files/priceandavailability/' + this.isbn + '.xml?' + this.getSearchVars(); var sUrl = '/site/OnixPA02.nsf/PAService?readform&' + this.getSearchVars(); var oXHR = createXHR(); oXHR.open('GET',sUrl,false); oXHR.send(null); if(!(oXHR.readyState == 4 && (oXHR.status == 200 || oXHR.status == 304))) return false; try { var responseType = oXHR.responseXML.getElementsByTagName('ResponseType')[0].hasChildren; } catch (err) {} if(!responseType) { this.xml = oXHR.responseXML; } else { this.xml = null; } }; PriceAvailability.prototype.getSearchVars = function() { var tempArray = new Array(); for(i in this.searchVars) { tempArray.push(i + '=' + this.searchVars[i]); } return (tempArray.join('&')); }; PriceAvailability.prototype.parseXML = function(text) { // code for IE if (window.ActiveXObject) { var doc=new ActiveXObject("Microsoft.XMLDOM"); doc.async="false"; doc.loadXML(text); } else { // code for Mozilla, Firefox, Opera, etc. var parser=new DOMParser(); var doc=parser.parseFromString(text,"text/xml"); } return doc; }; PriceAvailability.prototype.getPrice = function() { if(!this.xml)return; var getLevel1 = XMLWalk(this.xml.childNodes, "PriceAvailabilityResponse"); var getLevel2 = XMLWalk(getLevel1, "ProductPriceAvailability"); var getLevel3 = XMLWalk(getLevel2, "SupplierPriceAvailability"); var getLevel4 = XMLWalk(getLevel3, "RetailPrice"); var getLevel5 = XMLWalk(getLevel4, "PriceAmount"); //alert(getLevel5[0].nodeValue); var oPrice = getLevel5[0].nodeValue; //var oPrice = this.xml.getElementsByTagName('SupplierPriceAvailability')[0].getElementsByTagName('PriceAmount')[0].firstChild.nodeValue; //if book not found if(oPrice == 'Entry not found in index')return; if(oPrice.indexOf('$') != -1) { this.price = oPrice; } else { this.price = '$' + oPrice; } }; PriceAvailability.prototype.getAvailability = function() { if(!this.xml)return; // XMLWalk for Instock var getLevel1 = XMLWalk(this.xml.childNodes, "PriceAvailabilityResponse"); var getLevel2 = XMLWalk(getLevel1, "ProductPriceAvailability"); var getLevel3 = XMLWalk(getLevel2, "SupplierPriceAvailability"); var getLevel4 = XMLWalk(getLevel3, "InStock"); if (!getLevel4[0]) return; var oAvailability = getLevel4[0].nodeValue; //var oAvailability = this.xml.getElementsByTagName('SupplierPriceAvailability')[0].getElementsByTagName('InStock')[0].firstChild; if(!oAvailability)return; //oAvailability = oAvailability.nodeValue; if(oAvailability.toLowerCase().indexOf('true') != -1) { this.available = true; } }; PriceAvailability.prototype.getShipDate = function() { if(!this.xml || this.available)return; var getLevel1 = XMLWalk(this.xml.childNodes, "PriceAvailabilityResponse"); var getLevel2 = XMLWalk(getLevel1, "ProductPriceAvailability"); var getLevel3 = XMLWalk(getLevel2, "SupplierPriceAvailability"); var getLevel4 = XMLWalk(getLevel3, "ExpectedShipDate"); //var shipDate = getLevel4[0].nodeValue; if (getLevel4[0] == null) return; var shipDate = getLevel4[0].nodeValue; //var shipDate = this.xml.getElementsByTagName('SupplierPriceAvailability')[0].getElementsByTagName('ExpectedShipDate')[0].firstChild; //if(!shipDate || shipDate.nodeValue.length != 8)return; //if(!shipDate || shipDate.length != 8)return; if (!shipDate)return; if (shipDate.length != 8)return; //shipDate = shipDate.nodeValue; var year = parseInt(shipDate.substring(0,4)); // strip leading zeros if (shipDate.substring(4,5)=="0") { var month = parseInt(shipDate.substring(5,6)); } else { var month = parseInt(shipDate.substring(4,6)); } if (shipDate.substring(6,7)=="0") { var day = parseInt(shipDate.substring(7,8)); } else { var day = parseInt(shipDate.substring(6)); } //parse string as date var tempDate = new Date(); //tempDate.setYear(year); //tempDate.setDate(day); //tempDate.setMonth(month - 1); tempDate.setFullYear(year,month - 1,day); var currentDate = new Date(); //tempDate.setHours(0,0,0,0); //currentDate.setHours(0,0,0,0); if(tempDate < currentDate)return; this.shipDate = tempDate; /* var oP = document.createElement('p'); oP.appendChild(document.createTextNode(this.isbn + ': ' + shipDate + ' ' + tempDate.toGMTString())); document.body.appendChild(oP); */ }; PriceAvailability.prototype.parseShipDateAsString = function() { if(this.shipDate) { var tempArray = new Array(); if(this.shipDate.getDate() < 10) { tempArray.push('0' + this.shipDate.getDate().toString()); } else { tempArray.push(this.shipDate.getDate().toString()); } if(this.shipDate.getMonth() < 10) { tempArray.push('0' + (this.shipDate.getMonth() + 1).toString()); } else { tempArray.push((this.shipDate.getMonth() + 1).toString()); } tempArray.push(this.shipDate.getFullYear().toString()); var shipDate = tempArray.join('/'); } else { var shipDate = null; } return shipDate; }; /* PriceAvailability.prototype.getShipDateString = function() { if(this.shipDate) { var tempArray = new Array(); if(this.shipDate.getDate() < 10) { tempArray.push('0' + this.shipDate.getDate().toString()); } else { tempArray.push(this.shipDate.getDate().toString()); } if(this.shipDate.getMonth() < 10) { tempArray.push('0' + (this.shipDate.getMonth() + 1).toString()); } else { tempArray.push((this.shipDate.getMonth() + 1).toString()); } tempArray.push(this.shipDate.getFullYear().toString()); var shipDate = tempArray.join('/'); } else { var shipDate = 'no date available'; } return 'Available - ' + shipDate; }; */ PriceAvailability.prototype.getShipDateString = function() { var shipDate = this.parseShipDateAsString(); if(!shipDate) { shipDate = 'no date available'; } return 'Available - ' + shipDate; }; PriceAvailability.prototype.getShipDateStringBookDetail = function() { var shipDate = this.parseShipDateAsString(); if(!shipDate) { shipDate = 'no date available'; } return 'Available: ' + shipDate + ''; }; PriceAvailability.prototype.getShipDateStringForSummary = function() { var shipDate = this.parseShipDateAsString(); if(!shipDate) { return 'no date available'; } else { return shipDate; } }; } PriceAvailability._initialized = true; this.load(); } function createXHR() //create cross-browser XHR object { if (typeof XMLHttpRequest != "undefined") { return new XMLHttpRequest(); } else if (window.ActiveXObject) { var aVersions = [ "MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.3.0"]; for (var i = 0; i < aVersions.length; i++) { try { var oXHR = new ActiveXObject(aVersions[i]); return oXHR; } catch (oError) { //Do nothing } } } throw new Error("XMLHttp object could not be created."); } function XMLWalk(nodesToWalk, FindByName) { for (var i=0; i < nodesToWalk.length; i++) { if (nodesToWalk[i].nodeType == 1 && nodesToWalk[i].nodeName == FindByName) { return nodesToWalk[i].childNodes; } } }