var myreg = new RegExp('([0-9]{13}|[0-9]{10})'); function loadContent(file){ var head = document.getElementsByTagName('head').item(0) var scriptTag = document.getElementById('loadScript'); if(scriptTag) head.removeChild(scriptTag); script = document.createElement('script'); mycharset = document.characterSet ? document.characterSet : document.charset; file += '&enc='+mycharset; script.src = file; script.type = 'text/javascript'; script.charset = mycharset; script.id = 'loadScript'; head.appendChild(script); } function ISBNClass() { function book(isbn,title,thumb,price,location) { this.ean=isbn; this.title = title; this.thumb=thumb; this.price = price; this.location=location; return this; } function findBook(isbn) { for (i=0;i-1 ? this.books[i].title : false; } function getBookThumb(isbn) { i=this.findBook(isbn); return i>-1 ? this.books[i].thumb : false; } function getBookPrice(isbn) { i=this.findBook(isbn); return i>-1 ? this.books[i].price : false; } function getBookLink(isbn) { i=this.findBook(isbn); return i>-1 ? this.books[i].location : false; } function addBook(isbn,title,thumb,price,location) { //console.log('b: ' + this.findBook(isbn)); bookPos = this.findBook(isbn); if(bookPos<0) { this.books.push(new book(isbn,title,thumb,price,location)); //console.log('added ' + isbn + ' at position ' + (bookPos+1) + ' url: ' + location); } else { this.books[bookPos].title = title; this.books[bookPos].thumb = thumb; this.books[bookPos].price = price; this.books[bookPos].location = location; //console.log('edited (title:'+title+') ' + isbn + ' at position ' + bookPos); } //console.log('a'); } this.books=new Array(); this.addBook=addBook; this.findBook=findBook; this.getBookTitle=getBookTitle; this.getBookThumb=getBookThumb; this.getBookPrice=getBookPrice; this.getBookLink=getBookLink; return this; } var timerId; var myisbns = new ISBNClass(); //console.log('test:' +myisbns.findBook('12312312313')); function updateBokssonDiv(isbn) { titel = myisbns.getBookTitle(isbn); thumb = myisbns.getBookThumb(isbn); pris = myisbns.getBookPrice(isbn); booklocation = myisbns.getBookLink(isbn); if (document.getElementById('bokssondiv')) { /* fixa den stackars länken */ document.getElementById(isbn).href = booklocation; if (document.getElementById(isbn+'_pris')) { isbnpris=document.getElementById(isbn+'_pris'); isbnpris.replaceChild(document.createTextNode(pris),isbnpris.firstChild); isbntitel=document.getElementById(isbn+'_titel'); isbntitel.href = booklocation; isbntitel.replaceChild(document.createTextNode(titel),isbntitel.firstChild); isbnthumb = document.getElementById(isbn+'_imglink'); isbnthumb.href = booklocation; isbnthumb.firstChild.src = thumb; } return true; } return false; } function findPosY(obj) { var curtop = 0; if(obj.offsetParent) while(1) { curtop += obj.offsetTop; if(!obj.offsetParent) break; obj = obj.offsetParent; } else if(obj.y) curtop += obj.y; return curtop; } function createBokssonDiv(tempX,tempY,isbn) { //console.log('tempX: ' + tempX + ' tempY:' +tempY); /* ta bort om redan finns .. */ //console.log('skapar jidder: ' + isbn); bokssondiv = document.getElementById('bokssondiv') if (bokssondiv) bokssondiv.parentNode.removeChild(bokssondiv); bokssondiv = document.createElement('div'); bokssondiv.onmouseover = function (e) { window.clearTimeout(timerId); } bokssondiv.onmouseout = function (e) { timerId = window.setTimeout('closeBokssonDiv()',100); } //divven bokssondiv.style.position='absolute'; bokssondiv.style.left = tempX + 'px'; bokssondiv.style.top = tempY + 'px'; bokssondiv.style.height = '311px'; bokssondiv.style.width = '147px'; // bra browers if (window.XMLHttpRequest) { bokssondiv.style.backgroundImage = 'url(http://www.boksson.se/img/ruta.png)'; bokssondiv.style.backgroundRepeat = 'no-repeat'; bokssondiv.style.backgroundPosition = 'top left'; } else { // daliga browsers fran ms. bokssondiv.style.border = '1px solid'; bokssondiv.style.background = 'white'; } bokssondiv.style.zIndex = 1001; bokssondiv.style.align = 'center'; bokssondiv.style.padding = '5px'; bokssondiv.id = 'bokssondiv'; // bild bokssonImgA = document.createElement('a'); bokssonImgA.id = isbn+'_imglink'; //console.log(isbn+'_imglink'); bokssonImgA.href = myisbns.getBookLink(isbn); bokssonimg = document.createElement('img'); bokssonimg.src = myisbns.getBookThumb(isbn); bokssonimg.style.margin = '6px 2px 2px 6px'; bokssonimg.style.padding = '0pt'; bokssonimg.style.border = '1px solid #ccc'; bokssonimg.id = isbn+'_thumb'; bokssonImgA.appendChild(bokssonimg); // titel bokssontitel = document.createElement('p'); bokssontitel.style.marginLeft = '8px'; bokssonTitelLank = document.createElement('a'); bokssonTitelLank.href = myisbns.getBookLink(isbn); bokssonTitelLank.appendChild(document.createTextNode(myisbns.getBookTitle(isbn))); bokssonTitelLank.id = isbn+'_titel'; bokssonTitelLank.style.color = '#648B0D'; bokssonTitelLank.style.fontFamily = 'arial'; bokssontitel.appendChild(bokssonTitelLank); // pris bokssonpris = document.createElement('p'); bokssonpris.id = isbn+'_pris'; bokssonpris.style.marginLeft = '8px'; bokssonpris.style.font = '0.8em arial'; bokssonpris.appendChild(document.createTextNode(myisbns.getBookPrice(isbn))); // logo bokssonlogoP = document.createElement('p'); bokssonlogoP.align = 'right'; bokssonlogoP.style.marginRight = '20px'; bokssonlogoA = document.createElement('a'); bokssonlogoA.href = 'http://www.boksson.se/'; bokssonlogoA.title = 'Boksson'; bokssonlogoImg = document.createElement('img'); bokssonlogoImg.src = 'http://www.boksson.se/img/boksson-mini.gif'; bokssonlogoA.appendChild(bokssonlogoImg); bokssonlogoP.appendChild(bokssonlogoA); // satt ihop bokssondiv.appendChild(bokssonImgA); bokssondiv.appendChild(bokssontitel); bokssondiv.appendChild(bokssonpris); bokssondiv.appendChild(bokssonlogoP); isbn_a.parentNode.appendChild(bokssondiv); } function closeBokssonDiv() { bokssondiv = document.getElementById('bokssondiv'); if (bokssondiv != null) { bokssondiv.parentNode.removeChild(bokssondiv); } } /* alterNode(node,match_length,result) node, node to alter, match_length length of string matched result, start position of string to replace */ function alterNode(node,match_length,result) { firstStr = node.nodeValue.slice(0,result); isbnStr = node.nodeValue.slice(result,result+match_length); secondStr = node.nodeValue.slice(result+match_length,node.nodeValue.length); strippedString = isbnStr.replace(/[^0-9a-z]/g,''); isbn_a = document.createElement('a'); isbn_a.className = 'isbnid'; isbn_a.rel = isbnStr; // okey, this is nasty, but i need something to store this ;) isbn_a.id = strippedString; // spara isbn i id-taggen för framtida bruk.. :p isbn_a.onmouseover = function(e) { if (document.all) { // grab the x-y pos.s if browser is IE tempX = event.srcElement.offsetLeft; tempY = event.srcElement.offsetTop+15; } else { // grab the x-y pos.s if browser is NS tempX = e.target.offsetLeft; tempY = e.target.offsetTop+15; } if (timerId>0) { window.clearTimeout(timerId); closeBokssonDiv(); } if (myisbns.findBook(this.id)<0) { myisbns.addBook(this.id,'Laddar titel','http://www.boksson.se/img/load.gif','Laddar data'); //alert(isNaN(this.id)); if (isNaN(this.id)) { loadContent('http://www.boksson.se/isbn_js_search.php?query='+this.rel); } else { loadContent('http://www.boksson.se/isbn_js_check.php?isbn='+this.id); } } createBokssonDiv(tempX,tempY,this.id); }; isbn_a.onmouseout = function (e) { timerId = window.setTimeout('closeBokssonDiv()',500); }; isbn_a.href = 'http://www.boksson.se/unknown,'+isbnStr+'.html'; isbn_a.appendChild(document.createTextNode(isbnStr)); //console.log(node); parentRef = node.parentNode; parentRef.removeChild(node); //console.log('lägger till: ' + firstStr); parentRef.appendChild(document.createTextNode(firstStr)); //console.log('lägger till: ' + isbnStr); parentRef.appendChild(isbn_a); //console.log('lägger till: ' + secondStr); parentRef.appendChild(document.createTextNode(secondStr)); //node.parent.replaceNode( } function traverse(node) { if (node.childNodes.length>0) { for (var i=0;i