
function TaggingSuggestion(name,popularity){this.name=name;this.popularity=popularity;};TaggingSuggestion.prototype.toString=function(){return this.name;};function TaggingSuggestionsContainer(firstText){this.firstText=firstText;this.suggestionsByKey={};this.suggestionsByPopularity=new Array();};TaggingSuggestionsContainer.prototype.hasKey=function(key){var firstChar=key.length>1?key.charAt(0):key;if(this.suggestionsByKey[firstChar]){return true;};return false;};TaggingSuggestionsContainer.prototype.getSuggestions=function(key,maxSuggestions){var firstChar=key.length>1?key.charAt(0):key;if(!maxSuggestions||maxSuggestions<=0){maxSuggestions=10;};var result=new Array();if(this.firstText){if(this.hasKey(firstChar)){for(var i=0;i<this.suggestionsByKey[firstChar].length;i++){if(this.suggestionsByKey[firstChar][i].name.indexOf(key)!=-1){result.push(this.suggestionsByKey[firstChar][i]);if(result.length==maxSuggestions){break;}}}}}else{for(var i=0;i<this.suggestionsByPopularity.length;i++){if(this.suggestionsByPopularity[i].name.indexOf(key)!=-1){result.push(this.suggestionsByPopularity[i]);if(result.length==maxSuggestions){break;}}}};return result;};TaggingSuggestionsContainer.prototype.getSuggestionsAsStrings=function(key,maxSuggestions){var suggestions=this.getSuggestions(key,maxSuggestions);var result=new Array();for(var i=0;i<suggestions.length;i++){result.push(suggestions[i].name);};return result;};TaggingSuggestionsContainer.prototype.addSuggestions=function(key,suggestions){var firstChar=key.length>1?key.charAt(0):key;if(!suggestions){suggestions=[];};if(!this.hasKey(firstChar)){this.suggestionsByKey[firstChar]=suggestions;if(this.suggestionsByPopularity.length>0&&suggestions.length>0){suggestions.reverse();var s=suggestions.pop();for(var i=0;i<this.suggestionsByPopularity.length;i++){if(this.suggestionsByPopularity[i].popularity<=s.popularity){var tmp=this.suggestionsByPopularity[i].name+"-"+this.suggestionsByPopularity[i].popularity;this.suggestionsByPopularity.splice(i,0,s);s=suggestions.pop();}else if(i==this.suggestionsByPopularity.length-1){this.suggestionsByPopularity.push(s);while(s=suggestions.pop()){this.suggestionsByPopularity.push(s);}};if(!s){break;}}}else if(this.suggestionsByPopularity.length==0){this.suggestionsByPopularity=suggestions;}}else{}};document.suggestionsContainer=new TaggingSuggestionsContainer();function TaggingSuggestionBox(inputId,container,suggestionUrl,appID,onEnter,onDone){this.inputId=inputId;this.container=container;this.onEnter=onEnter;this.onDone=onDone;this.suggestionUrl=suggestionUrl;this.appID=appID||"retail";this.data=new Array();this.selectedRow=-1;this.key="";};TaggingSuggestionBox.prototype.init=function(allowComma,alignLeft,allowEnter){if(allowComma==undefined){allowComma=true;};allowComma==allowComma||true;if(alignLeft==undefined){alignLeft=true;};if(allowEnter==undefined){allowEnter=false;};this.alignLeft=alignLeft;this.allowEnter=allowEnter;this.inputBox=document.getElementById(this.inputId);if(!this.inputBox)return;this.inputBox.setAttribute("autocomplete","off");TaggingUtils.observe(this.inputBox,"keydown",TaggingUtils.bindAsEventListener(function(evt){if(TaggingUtils.isIE){var key=TaggingUtils.getEventKeyCode(evt);if(this.isVisible()){if(key==38){this.highlightPrev();return;}else if(key==40){this.highlightNext();return;}}};TaggingInputKeyDown(evt,this.allowEnter);},this),false);TaggingUtils.observe(this.inputBox,"keypress",TaggingUtils.bindAsEventListener(function(evt){if(!TaggingUtils.isIE){var key=TaggingUtils.getEventKeyCode(evt);if(this.isVisible()){if(key==38){this.highlightPrev();return;}else if(key==40){this.highlightNext();return;}}};TaggingInputKeyPress(evt,allowComma,(this.allowEnter&&!this.isVisible()));},this),false);TaggingUtils.observe(this.inputBox,"keyup",TaggingUtils.bindAsEventListener(function(evt){var key=TaggingUtils.getEventKeyCode(evt);if(this.isVisible()){if(key==38){return;}else if(key==40){return;}else if(key==13){if(this.selectedRow!=-1){this.inputBox.value=this.replaceLastTagFromInput(this.inputBox.value,this.data[this.selectedRow]);}else{this.onEnter(this);};this.hide();TaggingUtils.stopEvent(evt);return;}}else if(key==13){this.onEnter(this);TaggingUtils.stopEvent(evt);return;};var keys=TaggingUtils.trim(this.inputBox.value.toLowerCase()).split(",");var suggestKey=keys[keys.length-1];suggestKey=TaggingUtils.trim(suggestKey);if(suggestKey!=this.key){this.hide();this.key=suggestKey;if(suggestKey&&suggestKey.length!=0){this.startFetchSuggestions(suggestKey);}}},this),false);this.inputBox.oncontextmenu=function(){return false;};TaggingUtils.observe(this.inputBox,"blur",TaggingUtils.bindAsEventListener(function(){setTimeout(TaggingUtils.bindAsEventListener(function(){this.hide();},this),100);},this),false);};TaggingSuggestionBox.prototype.reset=function(){this.selectedRow=-1;this.key="";this.removeData();};TaggingSuggestionBox.prototype.isVisible=function(){var sTable=document.getElementById("suggest-table");return(sTable&&sTable.style.display!=""&&sTable.style.display!="none");};TaggingSuggestionBox.prototype.removeData=function(){var sTable=document.getElementById("suggest-table");if(sTable)document.body.removeChild(sTable);};function parse(t,key){var tobuild='';var start=t.indexOf(key);tobuild=t.substring(0,start);tobuild+="<font style='text-decoration:underline;font-weight:bold;'>";tobuild+=key;tobuild+="</font>";tobuild+=t.substring(start+key.length,t.length);return tobuild;};TaggingSuggestionBox.prototype.addData=function(){if(this.data.length>0){var sTable=document.createElement("table");sTable.cellSpacing='0px';sTable.cellPadding='2px';sTable.style.position='absolute';sTable.style.zIndex='105';sTable.id="suggest-table";var iFrame=document.getElementById("suggest-table-iframe");if(!iFrame){if(TaggingUtils.isIE&&TaggingUtils.isMinIE5_5){iframe=document.createElement("iframe");iframe.id="suggest-table-iframe";iframe.frameborder="0px";iframe.scrolling="no";iframe.src="javascript:false;";iframe.style.position="absolute";iframe.style.zIndex=104;iframe.style.display="none";iframe.style.borderStyle="none";document.body.appendChild(iframe);}};for(var i=0;i<this.data.length;i++){var sTR=sTable.insertRow(-1);var sTD=sTR.insertCell(-1);sTR.position=i;sTR.suggestion=this.data[i].name;sTD.innerHTML=parse(this.data[i].name,this.key);var pTD=sTR.insertCell(-1);pTD.align="right";pTD.innerHTML=this.data[i].popularity+" "+(this.data[i].popularity>1?TaggingOptions.usages:TaggingOptions.usage);TaggingUtils.observe(sTR,"mouseover",TaggingUtils.bindAsEventListener(this.highlightOnMouseOver,this),false);TaggingUtils.observe(sTR,"mousedown",TaggingUtils.bindAsEventListener(this.selectOnClick,this),false);};document.body.appendChild(sTable);}};TaggingSuggestionBox.prototype.startFetchSuggestions=function(key){if(this.container.hasKey(key)){this.data=this.container.getSuggestions(key,20);this.show();}else{var firstChar=key.length>1?key.charAt(0):key;if(this.fetchingChar!=firstChar){this.fetchingChar=firstChar;var opts={method:'GET',asynchronous:true,sameInstance:true,parameters:"appID="+this.appID+"&key="+firstChar,key:key,onSuccess:TaggingUtils.bind(function(transport){this.successFetchSuggestions(transport,opts);},this),onError:TaggingUtils.bind(function(transport){this.failedFetchSuggestions(transport,opts);},this),onTimeout:TaggingUtils.bind(function(transport){this.failedFetchSuggestions(transport,opts);},this)};var ajax=new TaggingAjax.Request(opts);ajax.makeRequest(this.suggestionUrl);}}};TaggingSuggestionBox.prototype.successFetchSuggestions=function(xmlObj,options){var response=TaggingUtils.trim(xmlObj.responseText);if(response.indexOf("Error")!=0&&response.indexOf("[")==0&&response.lastIndexOf("]")==response.length-1){var tmp=eval(xmlObj.responseText);this.container.addSuggestions(options.key,tmp);var keys=TaggingUtils.trim(this.inputBox.value.toLowerCase()).split(",");var currentUserValue=keys[keys.length-1];if(currentUserValue&&currentUserValue.length>0){currentUserValue=TaggingUtils.trim(currentUserValue);if(currentUserValue.charAt(0)==options.key.charAt(0)){this.data=this.container.getSuggestions(currentUserValue,20);this.show();}}}};TaggingSuggestionBox.prototype.failedFetchSuggestions=function(xmlObj,options){this.hide();};TaggingSuggestionBox.prototype.show=function(){if(this.data.length>0){var keys=TaggingUtils.trim(this.inputBox.value.toLowerCase()).split(",");this.key=keys[keys.length-1];this.addData();var sTable=document.getElementById("suggest-table");sTable.style.display=(TaggingUtils.isIE||TaggingUtils.isOpera)?'block':"table";var top=TaggingUtils.getPageTop(this.inputBox,'offsetTop')+this.inputBox.offsetHeight-1+'px';var horizontalOffset;if(this.alignLeft==true){horizontalOffset=TaggingUtils.getPageLeft(this.inputBox,'offsetLeft')+'px';}else{horizontalOffset=TaggingUtils.getPageLeft(this.inputBox,'offsetLeft')+this.inputBox.offsetWidth-sTable.offsetWidth+'px';};sTable.style.left=horizontalOffset;sTable.style.top=top;var iFrame=document.getElementById("suggest-table-iframe");if(iFrame){iFrame.style.top=top;iFrame.style.left=horizontalOffset;iFrame.style.width=sTable.offsetWidth;iFrame.style.height=sTable.offsetHeight;iFrame.style.display="block";iFrame.style.zIndex=sTable.style.zIndex-1;}}};TaggingSuggestionBox.prototype.hide=function(){var sTable=document.getElementById("suggest-table");if(sTable){sTable.style.display='none';document.body.removeChild(sTable);};var iFrame=document.getElementById("suggest-table-iframe");if(iFrame){iFrame.style.display="none";};this.reset();};TaggingSuggestionBox.prototype.selectOnClick=function(evt){this.inputBox.value=this.replaceLastTagFromInput(this.inputBox.value,this.data[this.selectedRow]);this.hide();};TaggingSuggestionBox.prototype.highlightOnMouseOver=function(evt){var position=0;var parent;if(window.event){position=window.event.srcElement.parentNode.position;parent=window.event.srcElement;}else{position=evt.target.parentNode.position;parent=evt.target;}while(parent.tagName.toLowerCase()!="tr"){parent=parent.parentNode;};position=parent.position;var sTable=document.getElementById("suggest-table");if(this.selectedRow!=-1){sTable.rows[this.selectedRow].className='';};this.selectedRow=position;sTable.rows[this.selectedRow].className='hovered';};TaggingSuggestionBox.prototype.highlightNext=function(updateValue){if(this.data&&this.data.length){var sTable=document.getElementById("suggest-table");if(this.selectedRow!=-1){sTable.rows[this.selectedRow].className='';};this.selectedRow++;if(this.selectedRow>=this.data.length){this.selectedRow=this.data.length-1;};if(!updateValue){this.inputBox.value=this.replaceLastTagFromInput(this.inputBox.value,this.data[this.selectedRow]);};sTable.rows[this.selectedRow].className='hovered';}};TaggingSuggestionBox.prototype.highlightPrev=function(updateValue){if(this.data&&this.data.length){if(this.selectedRow<=-1){return;};var sTable=document.getElementById("suggest-table");sTable.rows[this.selectedRow].className='';this.selectedRow--;if(this.selectedRow<0){this.selectedRow=-1;this.inputBox.value=this.replaceLastTagFromInput(this.inputBox.value,this.key);}else{if(!updateValue){this.inputBox.value=this.replaceLastTagFromInput(this.inputBox.value,this.data[this.selectedRow]);};sTable.rows[this.selectedRow].className='hovered';}}};TaggingSuggestionBox.prototype.replaceLastTagFromInput=function(value,tag){if(!value)return tag;var tags=value.split(",");tags[tags.length-1]=tag;return tags.join(",");};function TaggingProductTags(options){this.asin=options.asin;this.image=options.image;this.title=options.title;this.authors=options.authors;this.appID=options.appID||"retail";this.popupTitle=options.popupTitle||"Tag this product";this.onTagAdded=options.onTagAdded;this.onTagRemoved=options.onTagRemoved;this.onTagRenamed=options.onTagRenamed;this.onTagReplaced=options.onTagReplaced;this.popupOnCloseListeners=[];if(options.tags){this.tags=options.tags;}else{this.tags=new Array();};var productTags=this;this.suggestBox=new TaggingSuggestionBox(this.asin+"-tag-input",document.suggestionsContainer,TaggingOptions.suggestionUrl,this.appID,function(suggest){productTags.startTagProduct(suggest,TaggingOptions.tagObjectUrl);},function(suggest,success,tagInput){suggest.hide();tagInput.focus();tagInput.focus();});};TaggingProductTags.prototype.addOnPopupCloseListener=function(listener){this.popupOnCloseListeners.push(listener);listener.productTags=this;};TaggingProductTags.prototype.notifyOnPopupClose=function(){for(var i=0;i<this.popupOnCloseListeners.length;i++){if(this.popupOnCloseListeners[i].notify){this.popupOnCloseListeners[i].notify();}}};TaggingProductTags.prototype.initHandlers=function(useShortcut){this.useShortcut=useShortcut;var compactEditEle=document.getElementById(this.asin+"-compact-edit");if(compactEditEle){compactEditEle.href="javascript:void(0)";compactEditEle.onclick=null;if(!TaggingUtils.TaggingPopUpPanelDocEventRegistered){TaggingUtils.observe(document.body,"mousemove",TaggingUtils.bindAsEventListener(TaggingPopUpPanel.onMouseDrag,window),false,this.popupTitle);TaggingUtils.TaggingPopUpPanelDocEventRegistered=true;};TaggingUtils.observe(compactEditEle,"click",TaggingUtils.bindAsEventListener(this.showEditPopup,this),false);};var compactAddEle=document.getElementById(this.asin+"-compact-add");if(compactAddEle){compactAddEle.href="javascript:void(0)";compactAddEle.onclick=null;if(!TaggingUtils.TaggingPopUpPanelDocEventRegistered){TaggingUtils.observe(document.body,"mousemove",TaggingUtils.bindAsEventListener(TaggingPopUpPanel.onMouseDrag,window),false,this.popupTitle);TaggingUtils.TaggingPopUpPanelDocEventRegistered=true;};TaggingUtils.observe(compactAddEle,"click",TaggingUtils.bindAsEventListener(this.showAddPopup,this),false);};var editEle=document.getElementById(this.asin+"-edit");if(editEle){var anchor=TaggingUtils.findNodes(editEle,"a",null)[0];anchor.href="javascript:void(0)";anchor.onclick=function(){return false;};if(!TaggingUtils.TaggingPopUpPanelDocEventRegistered){TaggingUtils.observe(document.body,"mousemove",TaggingUtils.bindAsEventListener(TaggingPopUpPanel.onMouseDrag,window),false,this.popupTitle);TaggingUtils.TaggingPopUpPanelDocEventRegistered=true;};TaggingUtils.observe(editEle,"click",TaggingUtils.bindAsEventListener(this.showEditPopup,this),false);if(this.useShortcut){TaggingUtils.observe(document,"keyup",TaggingUtils.bindAsEventListener(function(ev){var key=TaggingUtils.getEventKeyCode(ev);if(key==27&&TaggingProductTags.editPanel){TaggingProductTags.editPanel.hide();TaggingProductTags.editPanel.input.blur();this.popupSuggestBox.hide();TaggingProductTags.editPanel=null;TaggingUtils.stopEvent(ev);return;};if(key==84){var target=TaggingUtils.getEventTarget(ev);var nodeName=target.nodeName.toUpperCase();if(nodeName=="INPUT"||nodeName=="TEXTAREA"){return;};if(TaggingProductTags.addTagInProgress){return;};if(this.shortcutTimeout){clearTimeout(this.shortcutTimeout);this.shortcutTimeout=null;var editPanel=this.createPopup(ev,this.useShortcut,true);editPanel.show(null);editPanel.showAddTab();editPanel.disableEditTab(this.tags.length==0);}else{this.shortcutTimeout=setTimeout(TaggingUtils.bind(function(){this.shortcutTimeout=null;},this),300);}}},this),false);}else{TaggingUtils.observe(document,"keyup",TaggingUtils.bindAsEventListener(function(ev){var key=TaggingUtils.getEventKeyCode(ev);if(key==27&&TaggingProductTags.editPanel){TaggingProductTags.editPanel.hide();TaggingProductTags.editPanel=null;}},this),false);}};var addEle=document.getElementById(this.asin+"-tag-add");if(addEle){var anchor=document.createElement("a");anchor.href="javascript:void(0)";var productTags=this;anchor.onclick=function(){return productTags.startTagProduct(productTags.suggestBox,TaggingOptions.tagObjectUrl);};var button=document.createElement("img");button.src=addEle.src;button.title=addEle.title;button.align=addEle.align;if(document.all){button.style.cursor="hand";}else{button.style.cursor="pointer";};button.style.borderWidth="0px";anchor.appendChild(button);addEle.style.display="none";addEle.parentNode.insertBefore(anchor,addEle);};if(this.suggestBox){this.suggestBox.init();}};TaggingProductTags.prototype.addTag=function(tag){if(!this.containsTag(tag)){this.tags[this.tags.length]=tag;}};TaggingProductTags.prototype.containsTag=function(tag){if(this.tags){for(var i=0;i<this.tags.length;i++){if(this.tags[i]==tag){return true;}}};return false;};TaggingProductTags.prototype.tagsReplaced=function(tags){var tagsSpan=document.getElementById(this.asin+"-tags");while(tagsSpan.firstChild){tagsSpan.removeChild(tagsSpan.firstChild);};for(var i=0;i<tags.length;i++){this.addTagAnchor(tags[i]);this.addTag(tags[i]);}};TaggingProductTags.prototype.addTagAnchor=function(tag){var tagsSpan=document.getElementById(this.asin+"-tags");var newTag=document.createElement("A");var length=TaggingOptions.trimmedTagLength||40;var ltext=tag.length>length?(tag.substring(0,length)+"..."):tag;ltext=ltext.replace(new RegExp(" ","g"),"&nbsp;");newTag.innerHTML=ltext;newTag.setAttribute("href",TaggingOptions.tagUrl.replace("TAG",tag));if(this.tags.length>0){tagsSpan.appendChild(document.createTextNode(", "));};tagsSpan.appendChild(newTag);};TaggingProductTags.prototype.startReplaceTags=function(replacingTags,removedTags,renamedTags,replaceUrl,onDone){var paramString="appID="+this.appID+"&ASIN="+this.asin;for(var i=0;i<replacingTags.length;i++){paramString+="&tgTag="+replacingTags[i];};var opts={method:'POST',asynchronous:true,sameInstance:true,parameters:paramString,replacingTags:replacingTags,removedTags:removedTags,renamedTags:renamedTags,onDone:onDone,onSuccess:TaggingUtils.bind(function(transport){var renamed=opts.renamedTags;var removed=opts.removedTags;if(this.onTagRenamed){var size=this.tags.length;for(var i=0;i<size;i++){var tag=this.tags[i];if(renamed[tag]){this.onTagRenamed(this,tag,renamed[tag]);}}};if(this.onTagRemoved){for(var i=0;i<removed.length;i++){this.onTagRemoved(this,removed[i]);}};this.successReplaceTags(transport,opts);if(this.onTagReplaced){this.onTagReplaced(this);};if(opts.onDone){opts.onDone(transport,opts);}},this),onError:TaggingUtils.bind(function(transport){this.failedReplaceTags(transport,opts);if(opts.onDone){opts.onDone(transport,opts);}},this),onTimeout:TaggingUtils.bind(function(transport){this.failedReplaceTags(transport,opts);if(opts.onDone){opts.onDone(transport,opts);}},this)};var ajax=new TaggingAjax.Request(opts);ajax.makeRequest(replaceUrl);};TaggingProductTags.prototype.successReplaceTags=function(xmlObj,options){var response=TaggingUtils.trim(xmlObj.responseText);if(response.indexOf("ok")==0){var oldTags=this.tags;this.tags=new Array();this.tagsReplaced(options.replacingTags);if(this.onTagsReplaced){this.onTagsReplaced(this,oldTags,this.tags);}};var editElem=document.getElementById(this.asin+"-edit");if(editElem&&this.tags.length==0){editElem.style.display="none";};var compactEditElem=document.getElementById(this.asin+"-compact-edit");if(compactEditElem&&this.tags.length==0){compactEditElem.style.display="none";}};TaggingProductTags.prototype.failedReplaceTags=function(xmlObj,options){};TaggingProductTags.prototype.startTagProduct=function(suggest,tagObjectUrl){if(TaggingProductTags.addTagInProgress){return;};var addTagElem=document.getElementById(this.asin+"-tag-add-rn");if(addTagElem){window.location=addTagElem.href;}else{var input=suggest.inputBox;if(input){if(input.readOnly){return;};var tag=TaggingUtils.trim(input.value);tag=tag.toLowerCase();if(!tag||tag.length==0){return;};tag=TaggingProcessInput(tag);var tags=tag.split(",");tag=null;for(var i=0;i<tags.length;i++){if(!this.containsTag(tags[i])){if(tag){tag+=","+tags[i];}else{tag=tags[i];}}};if(!tag){try{input.value="";}catch(e){};return;}else{input.value=tag;};input.blur();input.readOnly=true;TaggingProductTags.addTagInProgress=true;var opts={method:'POST',asynchronous:true,sameInstance:true,suggest:suggest,parameters:"appID="+this.appID+"&tgTag="+encodeURIComponent(tag)+"&ASIN="+this.asin,onSuccess:TaggingUtils.bind(function(transport){this.successTagProduct(transport,opts);},this),onError:TaggingUtils.bind(function(transport){this.failedTagProduct(transport,opts);},this),onTimeout:TaggingUtils.bind(function(transport){this.failedTagProduct(transport,opts);},this)};var ajax=new TaggingAjax.Request(opts);ajax.makeRequest(tagObjectUrl);return true;};return false;}};TaggingProductTags.prototype.successTagProduct=function(xmlObj,options){var response=TaggingUtils.trim(xmlObj.responseText);var tagInput=options.suggest.inputBox;var tag=TaggingUtils.trim(tagInput.value);tag=tag.toLowerCase();tag=TaggingProcessInput(tag);var tags=tag.split(",");var showEdit=false;for(var i=0;i<tags.length;i++){tag=tags[i];if(response.indexOf(tag+":"+this.asin+":ok")!=-1){this.addTagAnchor(tag);this.addTag(tag);if(this.onTagAdded){this.onTagAdded(this,tag);};showEdit=true;}};try{tagInput.value="";}catch(e){};if(showEdit){var editElem=document.getElementById(this.asin+"-edit");if(editElem){editElem.style.display="";};var compactEditElem=document.getElementById(this.asin+"-compact-edit");if(compactEditElem){compactEditElem.style.display="";}};tagInput.readOnly=false;TaggingProductTags.addTagInProgress=false;if(options.suggest.onDone){options.suggest.onDone(options.suggest,true,tagInput);}};TaggingProductTags.prototype.failedTagProduct=function(xmlObj,options){var tagInput=options.suggest.inputBox;tagInput.readOnly=false;TaggingProductTags.addTagInProgress=false;if(options.suggest.onDone){options.suggest.onDone(options.suggest,false);}};TaggingProductTags.prototype.showEditPopup=function(ev){if(TaggingProductTags.addTagInProgress){return;};var editPanel=this.createPopup(ev,this.useShortcut,false);var element=TaggingUtils.getEventTarget(ev);editPanel.show(element);editPanel.showEditTab();editPanel.disableEditTab(this.tags.length==0);TaggingUtils.stopEvent(ev);return false;};TaggingProductTags.prototype.showAddPopup=function(ev){if(TaggingProductTags.addTagInProgress){return;};var editPanel=this.createPopup(ev,this.useShortcut,false);var element=TaggingUtils.getEventTarget(ev);editPanel.show(element);editPanel.showAddTab();editPanel.disableEditTab(this.tags.length==0);TaggingUtils.stopEvent(ev);return false;};TaggingProductTags.prototype.createPopup=function(ev,useTabs,showFromShortcut){var productTags=this;if(TaggingProductTags.editPanel){TaggingProductTags.editPanel.hide();};var editPanel=new TaggingPopUpPanel("editTagsLayer",this,useTabs,this.popupTitle);TaggingProductTags.editPanel=editPanel;if(this.suggestBox){editPanel.inputBox=this.suggestBox.inputBox;};editPanel.showFromShortcut=showFromShortcut;this.populateEditPanel(editPanel);this.populateAddPanel(editPanel);this.popupSuggestBox=new TaggingSuggestionBox(editPanel.name+":tabs:addTab:input",document.suggestionsContainer,editPanel.showFromShortcut?TaggingOptions.suggestionUrlQP:TaggingOptions.suggestionUrl,this.appID,function(suggest){if(productTags.startTagProduct(suggest,editPanel.showFromShortcut?TaggingOptions.tagObjectUrlQP:TaggingOptions.tagObjectUrl)){if(TaggingUtils.isIE&&!TaggingUtils.isMinIE6){editPanel.addButton.style.width="0px";editPanel.input.style.width="0px";}else{editPanel.addButton.style.display="none";editPanel.input.style.display="none";};editPanel.addProgress.style.display="";}},function(suggest,success,tagInput){suggest.hide();editPanel.addProgress.style.display="none";if(TaggingUtils.isIE&&!TaggingUtils.isMinIE6){editPanel.addButton.style.width="";editPanel.input.style.width="";}else{editPanel.addButton.style.display="";editPanel.input.style.display="";};productTags.populateAddPanel(editPanel);productTags.populateEditPanel(editPanel);if(editPanel.visible){if(document.getElementById(editPanel.name+":tabs:editTab").style.display=="none"){if(tagInput){tagInput.focus();tagInput.focus();}}};editPanel.disableEditTab(productTags.tags.length==0);});this.popupSuggestBox.init();var title=productTags.title;var image=productTags.image;if((image&&image.length>0)||(title&&title.length>0)){if(title){var length=TaggingOptions.trimmedTitleLength||55;title=title.length>length?(title.substring(0,length)+"..."):title;};var html='<table cellspacing="0" cellpadding="0"><tr><td>';if(image&&image.length>0){html+='<img align="left" src="'+image+'" style="margin-right: 10px">';};html+='</td><td>';if(title&&title.length>0){html+='<b class="small">'+title+'</b>';};if(productTags.authors&&productTags.authors.length>0){html+='<br> by ';var authors="";for(var i=0;i<productTags.authors.length;i++){if(i==0){authors+=productTags.authors[i];}else{authors+=", "+productTags.authors[i];}};authors=authors.length>30?(authors.substring(0,30)+"..."):authors;html+=authors;};html+='</td></tr></table>';editPanel.prodInfoSpan.innerHTML=html;}else{editPanel.prodInfoSpan.innerHTML="";};editPanel.saveProgress.style.display="none";editPanel.addProgress.style.display="none";if(TaggingUtils.isIE&&!TaggingUtils.isMinIE6){editPanel.addButton.style.width="";editPanel.input.style.width="";editPanel.saveEditButton.style.width="";editPanel.cancelButton.style.width="";}else{editPanel.addButton.style.display="";editPanel.input.style.display="";editPanel.saveEditButton.style.display="";editPanel.cancelButton.style.display="";};if(editPanel.addButton){editPanel.addButton.onclick=function(){if(productTags.startTagProduct(productTags.popupSuggestBox,editPanel.showFromShortcut?TaggingOptions.tagObjectUrlQP:TaggingOptions.tagObjectUrl)){if(TaggingUtils.isIE&&!TaggingUtils.isMinIE6){editPanel.addButton.style.width="0px";editPanel.input.style.width="0px";}else{editPanel.addButton.style.display="none";editPanel.input.style.display="none";};editPanel.addProgress.style.display="";}}};if(editPanel.closeButton){editPanel.closeButton.onclick=function(evt){editPanel.hide();TaggingProductTags.editPanel=null;TaggingUtils.stopEvent(ev);return false;};};if(editPanel.cancelButton){editPanel.cancelButton.onclick=function(evt){editPanel.hide();TaggingProductTags.editPanel=null;TaggingUtils.stopEvent(ev);return false;};};if(editPanel.saveEditButton){editPanel.saveEditButton.onclick=function(){var removeAllTags=true;var content=editPanel.editTagsSpan.childNodes;var removedTags=new Array();var renamedTags={};var replacingTags=new Array();var areRenamed=false;var map={};for(var j=0;j<content.length;j++){var child=content[j];if(child.nodeName.toUpperCase()=="DIV"){var inputChild=child.firstChild;var tag=TaggingUtils.trim(inputChild.value);map[child.id]=tag;}};var size=productTags.tags.length;for(var i=0;i<size;i++){var removed=true;if(map["t"+i]){removed=false;var tag=map["t"+i];tag=tag.toLowerCase();if(!tag){removed=true;}else if(tag!=productTags.tags[i]){renamedTags[productTags.tags[i]]=tag;areRenamed=true;};if(!removed&&!TaggingUtils.isInArray(replacingTags,tag)){replacingTags.push(tag);}};if(removed){removedTags.push(productTags.tags[i]);}};if(removedTags.length>0||areRenamed){if(TaggingUtils.isIE&&!TaggingUtils.isMinIE6){editPanel.saveEditButton.style.width="0px";editPanel.cancelButton.style.width="0px";}else{editPanel.saveEditButton.style.display="none";editPanel.cancelButton.style.display="none";};editPanel.saveProgress.style.display="";productTags.startReplaceTags(replacingTags,removedTags,renamedTags,editPanel.showFromShortcut?TaggingOptions.replaceUrlQP:TaggingOptions.replaceUrl,function(){editPanel.saveProgress.style.display="none";if(TaggingUtils.isIE&&!TaggingUtils.isMinIE6){editPanel.saveEditButton.style.width="";editPanel.cancelButton.style.width="";}else{editPanel.saveEditButton.style.display="";editPanel.cancelButton.style.display="";};productTags.populateAddPanel(editPanel);productTags.populateEditPanel(editPanel);editPanel.disableEditTab(productTags.tags.length==0);});}};};return editPanel;};TaggingProductTags.prototype.populateAddPanel=function(editPanel){var tagsSpan=editPanel.addTagsSpan;editPanel.addTagsSpan.innerHTML="";for(var i=0;i<this.tags.length;i++){var tag=this.tags[i];var newTag=document.createElement("A");var ltext=tag.length>25?(tag.substring(0,25)+"..."):tag;ltext=ltext.replace(new RegExp(" ","g"),"&nbsp;");newTag.innerHTML=ltext;newTag.setAttribute("href",TaggingOptions.tagUrl.replace("TAG",tag));newTag.title=tag;if(i>0){tagsSpan.appendChild(document.createTextNode(", "));};tagsSpan.appendChild(newTag);}};TaggingProductTags.prototype.populateEditPanel=function(editPanel){editPanel.editTagsSpan.innerHTML="";var i=0;for(i=0;i<this.tags.length;i++){var tag=this.tags[i];var popDiv=document.createElement("DIV");popDiv.className="tagEdit";popDiv.id="t"+i;editPanel.editTagsSpan.appendChild(popDiv);var popInput=document.createElement("INPUT");popInput.type="text";popInput.value=tag;popInput.maxLength=128;popInput.className="tiny edit-tag";popInput.style.width="220px";popInput.onkeydown=TaggingUtils.bindAsEventListener(TaggingInputKeyDown,window);popInput.onkeypress=TaggingUtils.bindAsEventListener(TaggingInputKeyPress,window);popInput.oncontextmenu=function(){return false;};popDiv.appendChild(popInput);popDiv.appendChild(document.createTextNode(" "));var popA=document.createElement("A");popA.href="javascript:void(0)";popA.id=tag;popA.onclick=function(){var contentId=this.parentNode.id;var content=editPanel.editTagsSpan;var nodes=content.childNodes;for(i=0;i<nodes.length;i++){if(nodes[i].id==contentId){var tmp=nodes[i];content.removeChild(tmp);return tmp;}}};var popImg=document.createElement("IMG");popImg.align="absmiddle";popImg.title=TaggingOptions.removeTitle;popImg.src=TaggingOptions.removeImgUrl;popImg.style.border=0;popA.appendChild(popImg);popDiv.appendChild(popA);popDiv.appendChild(document.createElement("br"));}};function TaggingPopUpPanel(name,productTags,showTabs,title){this.name=name;this.productTags=productTags;this.showTabs=showTabs;this.title=title;var w=document.getElementById(name);if(w){w.parentNode.removeChild(w);};TaggingPopUpPanel.createWindow(name,this.title);var tabs=TaggingPopUpPanel.createTabs(name+":tabs","Add tags","Edit tags",showTabs);document.getElementById(this.name+":content").appendChild(tabs);this.whichDog=document.getElementById(name);this.iFrame=document.getElementById(name+":iframe");if(!this.iFrame){if(TaggingUtils.isIE&&TaggingUtils.isMinIE5_5){var iframe=document.createElement("iframe");iframe.id=name+":iframe";iframe.frameborder="0px";iframe.scrolling="no";iframe.src="javascript:false;";iframe.style.position="absolute";iframe.style.display="none";iframe.style.borderStyle="none";document.body.appendChild(iframe);this.iFrame=iframe;}};this.titleBar=document.getElementById(name+":titleBar");this.addProgress=document.getElementById(name+":tabs:addTab:addProgress");this.saveProgress=document.getElementById(name+":tabs:editTab:saveProgress");this.closeButton=document.getElementById(name+":closeButton");this.saveEditButton=document.getElementById(name+":tabs:editTab:saveButton");this.cancelButton=document.getElementById(name+":tabs:editTab:cancelButton");this.addButton=document.getElementById(name+":tabs:addTab:addButton");this.input=document.getElementById(name+":tabs:addTab:input");this.input.value="";this.tagsSpan=document.getElementById(name+":tabs:addTab:tags");this.prodInfoSpan=document.getElementById(name+":tabs:addTab:prodInfo");this.addTagsSpan=document.getElementById(name+":tabs:addTab:tags");this.editTagsSpan=document.getElementById(name+":tabs:editTab:tags");if(showTabs){this.addTabTitle=document.getElementById(name+":tabs:addTab:title");this.editTabTitle=document.getElementById(name+":tabs:editTab:title");this.editTabTitleDisabled=document.getElementById(name+":tabs:editTab:titleDisabled");this.addTabTitle.onclick=TaggingUtils.bindAsEventListener(this.showAddTab,this);this.editTabTitle.onclick=TaggingUtils.bindAsEventListener(this.showEditTab,this);};this.titleBar.onmousedown=TaggingUtils.bindAsEventListener(this.titleBarMouseDown,this);this.titleBar.onmouseup=TaggingUtils.bindAsEventListener(this.titleBarMouseUp,this);this.disableEdit=false;};TaggingPopUpPanel.prototype.titleBarMouseDown=function(evt){this.offsetx=TaggingUtils.getEventPageX(evt);this.offsety=TaggingUtils.getEventPageY(evt);this.nowX=parseInt(this.whichDog.style.left);this.nowY=parseInt(this.whichDog.style.top);this.okToMove=TaggingUtils.isLeftClick(evt);};TaggingPopUpPanel.prototype.titleBarMouseUp=function(evt){if(TaggingUtils.isLeftClick(evt)){this.okToMove=false;}};TaggingPopUpPanel.onMouseDrag=function(evt){var editPanel=TaggingProductTags.editPanel;if(editPanel){if(editPanel.visible&&editPanel.okToMove){editPanel.whichDog.style.left=editPanel.nowX+TaggingUtils.getEventPageX(evt)-editPanel.offsetx;editPanel.whichDog.style.top=editPanel.nowY+TaggingUtils.getEventPageY(evt)-editPanel.offsety;if(editPanel.iFrame){editPanel.iFrame.style.top=editPanel.whichDog.style.top;editPanel.iFrame.style.left=editPanel.whichDog.style.left;}};return true;}};TaggingPopUpPanel.prototype.showAddTab=function(ev){document.getElementById(this.name+":tabs:editTab").style.display='none';document.getElementById(this.name+":tabs:addTab").style.display='block';setTimeout(TaggingUtils.bind(function(){this.input.focus();},this),10);this.productTags.populateAddPanel(this);this.productTags.populateEditPanel(this);try{if(this.input.focus){this.input.focus();};if(this.input.blur){this.input.blur();}}catch(e){};if(this.iFrame){this.iFrame.style.width=this.whichDog.offsetWidth;this.iFrame.style.height=this.whichDog.offsetHeight;};if(ev){TaggingUtils.stopEvent(ev);};return false;};TaggingPopUpPanel.prototype.showEditTab=function(ev){if(this.disableEdit){return;};document.getElementById(this.name+":tabs:editTab").style.display='block';document.getElementById(this.name+":tabs:addTab").style.display='none';this.productTags.populateAddPanel(this);this.productTags.populateEditPanel(this);try{if(this.saveEditButton.focus){this.saveEditButton.focus();};if(this.saveEditButton.blur){this.saveEditButton.blur();}}catch(e){};if(this.iFrame){this.iFrame.style.width=this.whichDog.offsetWidth;this.iFrame.style.height=this.whichDog.offsetHeight;};if(ev){TaggingUtils.stopEvent(ev);};return false;};TaggingPopUpPanel.prototype.disableEditTab=function(disableEdit){this.disableEdit=disableEdit;if(this.showTabs){this.editTabTitle.style.disabled=this.disableEdit;if(this.disableEdit){this.showAddTab();this.editTabTitle.style.display="none";this.editTabTitleDisabled.style.display="";}else{this.editTabTitle.style.display="";this.editTabTitleDisabled.style.display="none";}}};TaggingPopUpPanel.prototype.hide=function(){this.whichDog.style.display="none";if(this.iFrame){this.iFrame.style.display="none";};this.visible=false;if(this.inputBox){this.inputBox.readOnly=false;};this.productTags.notifyOnPopupClose();};TaggingPopUpPanel.prototype.show=function(triggerElement){this.whichDog.style.zIndex=100;this.whichDog.style.display="block";this.visible=true;if(triggerElement){var left=TaggingUtils.getPageLeft(triggerElement);var top=(TaggingUtils.getPageTop(triggerElement)+triggerElement.offsetHeight);var a=TaggingUtils.getPageSizeWithScroll();if(left+this.whichDog.offsetWidth>a.width){left=a.width-this.whichDog.offsetWidth-40;};if(top+this.whichDog.offsetHeight>a.height){top=a.height-this.whichDog.offsetHeight-40;};this.whichDog.style.top=top+'px';this.whichDog.style.left=left+'px';}else{var bw=document.all?document.body.clientWidth:window.innerWidth;var bh=document.all?document.body.clientHeight:window.innerHeight;var iebody=(document.compatMode&&document.compatMode!="BackCompat")?document.documentElement:document.body;var left=document.all?iebody.scrollLeft:pageXOffset;var top=document.all?iebody.scrollTop:pageYOffset;left=(bw/ 2+ left- parseInt(this.whichDog.offsetWidth)/ 2);top=(bh/ 2+ top- parseInt(this.whichDog.offsetHeight)/ 2);if(top<0)top=0;if(left<0)left=0;this.whichDog.style.left=left+"px";this.whichDog.style.top=top+"px";};if(this.iFrame){this.iFrame.style.width=this.whichDog.offsetWidth;this.iFrame.style.height=this.whichDog.offsetHeight;this.iFrame.style.zIndex=this.whichDog.style.zIndex-1;this.iFrame.style.top=this.whichDog.style.top;this.iFrame.style.left=this.whichDog.style.left;this.iFrame.style.display="block";};if(this.inputBox){this.inputBox.readOnly=true;}};TaggingPopUpPanel.createWindow=function(id,title){var div=document.createElement("DIV");div.style.position="absolute";div.style.borderWidth="1px";div.style.borderStyle="solid";div.style.borderColor="#2A2A19";div.style.backgroundColor="white";div.style.visibility="visible";div.style.display="none";div.id=id;div.innerHTML='<table width="300px" cellspacing="0" cellpadding="0">'+' <tr>'+'   <td>'+'     <table style="color: white; padding: 0 0 2px 5px;" bgcolor="#CC6600" width="100%" cellspacing="0" cellpadding="0">'+'       <tr>'+'           <td id="'+id+':titleBar" style="cursor: move" width="100%">'+'               <b class="tiny">'+title+'</b>'+'            </td>'+'            <td style="cursor: hand" valign="top">'+'                <a href="#">'+'                    <img border="0" align="absbottom" id="'+id+':closeButton" title="Close window" '+'                         src="'+TaggingOptions.closeImgUrl+'">'+'               </a>'+'           </td>'+'        </tr>'+'     </table>'+'    </td>'+'  </tr>'+'  <tr>'+'    <td>'+'      <div style="border: solid 3px #EFEDD4; padding:  15px 11px 11px 11px" id="'+id+':content"></div>'+'    </td>'+'  </tr>'+'</table>';document.body.insertBefore(div,document.body.firstChild);return div;};TaggingPopUpPanel.createTabs=function(id,title1,title2,showTabs){var div=document.createElement("DIV");div.id=id;var html='<div id="'+id+':addTab:prodInfo" class="tinyproduct"></div>'+'<div id="'+id+':addTab" border="0" style="width:100%">'+'  <table class="tinytabs" cellspacing="0" border="0" width="100%">';if(showTabs){html+='<tr>'+'  <td class="spacing"></td>'+'  <td class="on"><a href="javascript:void(0)" onclick="return false">'+title1+'</a></td>'+'  <td class="off"><a href="javascript:void(0)" id="'+id+':editTab:title">'+title2+'</a><span style="display:none;color:gray;" id="'+id+':editTab:titleDisabled">'+title2+'</span></td>'+'  <td width="5px"></td>'+'</tr>'+'<tr class="top">'+'  <td class="border-topleft">&nbsp;</td>'+'  <td>&nbsp;</td>'+'  <td class="border-top">&nbsp;</td>'+'  <td class="border-topright">&nbsp;</td>'+'</tr>';}else{html+='<tr class="top">'+'  <td class="border-topleft">&nbsp;</td>'+'  <td class="border-top" width="100%">&nbsp;</td>'+'  <td class="border-top">&nbsp;</td>'+'  <td class="border-topright">&nbsp;</td>'+'</tr>';};html+='  </table>'+'  <div class="tinytabs" style="width:100%">'+'    <div class="border-bottom" style="padding: 12px;">'+'    <table cellspacing="0" cellpadding="0" class="tags">'+'    <tr valign="top">'+'      <td style="line-height: 1.2em"><b class="tiny" style="white-space: nowrap;">Your tags:&nbsp;</b></td>'+'      <td class="tiny" style="line-height: 1.5em">'+'        <span id="'+id+':addTab:tags"></span>'+'        <span style="white-space: nowrap;padding-left:3px;">'+'          <input id="'+id+':addTab:input" style="width: 100px;" class="tiny" value="" align="absbottom" maxlength="128">'+'          <input id="'+id+':addTab:addButton" title="Add tags" type="image" src="'+TaggingOptions.addImgUrl+'" align="absmiddle" border="0">'+'          <img id="'+id+':addTab:addProgress" src="'+TaggingOptions.progressImgUrl+'" style="display:none;">'+'        </span>'+'      </td>'+'    </tr>'+'    </table>'+'    <div class="tiny" style="color: #666666; padding: 5px 0 0 0;">(Separate multiple tags using commas)</div>'+'   </div>'+'  </div>'+'</div>'+'<div id="'+id+':editTab" style="display: none;" style="width:100%">'+'  <table class="tinytabs" cellspacing="0" border="0" width="100%">';if(showTabs){html+='<tr>'+'  <td class="spacing"></td>'+'  <td class="off"><a href="javascript:void(0)" id="'+id+':addTab:title">'+title1+'</a></td>'+'  <td class="on"><a href="javascript:void(0)" onclick="return false">'+title2+'</a></td>'+'  <td width="5px"></td>'+'</tr>'+'<tr class="top" style="background: #F5F5F5">'+'  <td class="border-topleft">&nbsp;</td>'+'  <td class="border-top">&nbsp;</td>'+'  <td>&nbsp;</td>'+'  <td class="border-topright">&nbsp;</td>'+'</tr>';}else{html+='<tr class="top">'+'  <td class="border-topleft">&nbsp;</td>'+'  <td class="border-top" width="100%">&nbsp;</td>'+'  <td class="border-top">&nbsp;</td>'+'  <td class="border-topright">&nbsp;</td>'+'</tr>';};html+='  </table>'+'  <div class="tinytabs" style="width:100%">'+'    <div class="border-bottom" style="background: #F5F5F5">'+'    <div style="background: #F5F5F5; height: 124px; overflow: auto; " id="'+id+':editTab:tags" >'+'    </div>'+'    <div style="background: #F5F5F5; text-align: right; padding: 7px;">'+'       <input id="'+id+':editTab:saveButton" title="Save changes" type="image" align="absmiddle" src="'+TaggingOptions.saveChangesImgUrl+'" border="0">'+'       <img id="'+id+':editTab:saveProgress" src="'+TaggingOptions.progressImgUrl+'" style="display:none;">'+'       <input id="'+id+':editTab:cancelButton" title="Cancel changes" type="image" align="absmiddle" src="'+TaggingOptions.cancelImgUrl+'" border="0">'+'    </div>'+'    </div>'+'  </div>'+'</div>';div.innerHTML=html;return div;};function startTag(tag,asin){var productTags=document[asin];productTags.addTagInProgress=true;var snake=document.getElementById(asin+"-snake");if(snake){snake.style.display="inline";};var opts={method:'POST',asynchronous:true,sameInstance:true,tag:tag,asin:productTags.asin,parameters:"appID="+productTags.appID+"&tgTag="+encodeURIComponent(tag)+"&ASIN="+productTags.asin,onSuccess:TaggingUtils.bind(function(transport){successTagAdd(transport,opts);},this),onError:TaggingUtils.bind(function(transport){failTagAdd(transport,opts);},this),onTimeout:TaggingUtils.bind(function(transport){failTagAdd(transport,opts);},this)};var ajax=new TaggingAjax.Request(opts);ajax.makeRequest(TaggingOptions.tagObjectUrl);return true;};function successTagAdd(xmlObj,options){var tag=options.tag;var productTags=document[options.asin];var unlink=document.getElementById(tag+"-"+options.asin+"-suggestion-grey");var link=document.getElementById(tag+"-"+options.asin+"-suggestion-link");if(unlink&&link){unlink.style.display="";link.style.display="none";};var snake=document.getElementById(options.asin+"-snake");if(snake){snake.style.display="none";};if(productTags&&!productTags.containsTag(tag)){productTags.addTagAnchor(tag);productTags.addTag(tag);var editElem=document.getElementById(options.asin+"-edit");if(editElem){editElem.style.display="";};var compactEditElem=document.getElementById(options.asin+"-compact-edit");if(compactEditElem){compactEditElem.style.display="";}};productTags.addTagInProgress=false;};function failTagAdd(xmlObj,options){var snake=document.getElementById(options.asin+"-snake");if(snake){snake.style.display="none";};var productTags=document[options.asin];productTags.addTagInProgress=false;};


