var bookProductPage = (((typeof document.forms[0].PageType != "undefined")&&(document.forms[0].PageType.value == "onixProduct")) && ((typeof document.forms[0].Subsection != "undefined")&&(document.forms[0].Subsection.value == "Titles"))) if(bookProductPage)//Is it a onix book page { var smallImg = smallCoverExist(); var pdf = pdfExist(); if(smallImg)//if small image exist { var largeImg = largeCoverExist(smallImg); if(largeImg) { var imgParent = document.getElementById('edDeskBody').getElementsByTagName('img')[0].parentNode; var oAnchor = document.createElement('a'); oAnchor.className = 'downloadCoverLink'; oAnchor.setAttribute('href',largeImg); oAnchor.setAttribute('target','_blank'); oAnchor.appendChild(document.createTextNode('Download cover image')); imgParent.appendChild(oAnchor); } } else { //var oImg = document.getElementById('edDeskBody').getElementsByTagName('img')[0]; //oImg.src = 'templates/layout/$file/noCover.gif'; } if(pdf) { var imgParent = document.getElementById('edDeskBody').getElementsByTagName('img')[0].parentNode; //imgParent.appendChild(document.createElement('br')); var oAnchor = document.createElement('a'); oAnchor.className = 'downloadCoverLink pdflink'; oAnchor.setAttribute('href',pdf); oAnchor.setAttribute('target','_blank'); oAnchor.appendChild(document.createTextNode('View sample pages')); imgParent.appendChild(oAnchor); } } function largeCoverExist(imgPath) { var winLoc = window.location.toString(); if(winLoc.indexOf('macmillan.com.au') != -1)//Is it the test site { var largeImgPath = imgPath.replace('/mea/covers/','/mea/downloadcovers/'); } else { var largeImgPath = imgPath.replace('/mea/','/mea/downloadcovers/'); } var imgLoad = new HeaderLoader(largeImgPath); if(imgLoad.exist) { return largeImgPath; } else { return; } } function smallCoverExist() { var oImg = document.getElementById('edDeskBody').getElementsByTagName('img'); if(typeof oImg != 'undefined' && oImg.length > 0) { var imgPath = replaceURL(oImg[0].getAttribute('src')); var imgLoad = new HeaderLoader(imgPath); if(imgLoad.exist) { return imgPath; } else { return; } } } function pdfExist() { var oImg = document.getElementById('edDeskBody').getElementsByTagName('img'); if(typeof oImg != 'undefined' && oImg.length == 1) { var imgPath = replaceURL(oImg[0].getAttribute('src')); var winLoc = window.location.toString(); if(winLoc.indexOf('macmillan.com.au') != -1)//Is it the test site { var pdfPath = imgPath.replace('/mea/covers/','/mea/downloadpdfs/'); } else { var pdfPath = imgPath.replace('/mea/','/mea/downloadpdfs/'); } pdfPath = pdfPath.toLowerCase().replace('jpg','pdf'); var pdfLoad = new HeaderLoader(pdfPath); if(pdfLoad.exist) { return pdfPath; } else { return; } } } function replaceURL(imgPath) { var winLoc = window.location.toString(); if(imgPath.indexOf('macmillan.com.au') != -1 && winLoc.indexOf('macmillan.com.au') == -1) { return imgPath.replace('http://www.macmillan.com.au/mea/covers/','http://primarydev.itechne.com/files/mea/'); } else { return imgPath; } }