function PileTagCounter(_1,_2){
this.span=_1;
this.anchor=_2;
var p=this.findCounterPosition(this.span.innerHTML);
this.counterSpan={position:p,has:(p.start>=0&&p.end>=1)};
if(this.counterSpan.has){
var _4=this.span.innerHTML;
this.counterSpan.prefix=_4.substring(0,this.counterSpan.position.start);
this.counterSpan.sufix=_4.substring(this.counterSpan.position.end,_4.length);
var _5=_4.substring(this.counterSpan.position.start,this.counterSpan.position.end);
this.counter=parseInt(_5);
}
this.counterAnchor={};
this.counterAnchor.has=_2&&_2.getAttribute("title");
};
PileTagCounter.prototype.increment=function(){
this.counter++;
if(this.counterSpan.has){
this.span.innerHTML=this.counterSpan.prefix+this.counter+this.counterSpan.sufix;
}
if(this.counterAnchor.has){
this.anchor.setAttribute("title",this.anchor.getAttribute("title").replace(this.counter-1,this.counter));
}
};
PileTagCounter.prototype.decrement=function(){
this.counter--;
if(this.counterSpan.has){
this.span.innerHTML=this.counterSpan.prefix+this.counter+this.counterSpan.sufix;
}
if(this.counterAnchor.has){
this.anchor.setAttribute("title",this.anchor.getAttribute("title").replace(this.counter+1,this.counter));
}
};
PileTagCounter.prototype.findCounterPosition=function(_6){
var _7="0123456789";
var r={start:-1,end:-1};
var i=0;
for(i=0;i<_6.length;i++){
if(_7.indexOf(_6.charAt(i))>=0){
if(r.start<0){
r.start=i;
}
}else{
if(r.start>-1){
r.end=i;
break;
}
}
}
if(r.start>-1&&r.end<0){
r.end=_6.length;
}
return r;
};
function PileTagControl(_a,_b,_c){
this.piles=_b;
this.objId=this.piles.objId;
this.appY=this.piles.appY;
this.tag=_a.getAttribute("tag");
this.container=_a;
this.status=_c;
this.inProgress=false;
var _d=TaggingUtils.findNodes(_a,"span","counter");
var as=TaggingUtils.findNodes(_a,"a");
if(_d&&_d.length>0){
this.counter=new PileTagCounter(_d[0],as&&as.length>0?as[0]:null);
}
};
PileTagControl.prototype.init=function(){
if(this.piles.useCSSforImages){
this.check=document.createElement("i");
this.check.className=(this.piles.useCSSforImages==2)?"check swSprite s_checkUnmarked":"checkBtnOff";
this.container.insertBefore(this.check,this.container.firstChild);
this.setStatus(this.status);
this.check.control=this;
this.check.tagAction="yes";
TaggingUtils.observe(this.check,"click",TaggingUtils.bindAsEventListener(this.triggerAction,this),false);
TaggingUtils.observe(this.check,"mouseover",TaggingUtils.bindAsEventListener(this.onMouseOver,this),false);
TaggingUtils.observe(this.check,"mouseout",TaggingUtils.bindAsEventListener(this.onMouseOut,this),false);
}else{
this.imgYes=document.createElement("img");
this.imgYes.className="pill-yes";
this.setStatus(this.status);
this.container.insertBefore(this.imgYes,this.container.firstChild);
this.imgYes.control=this;
this.imgYes.tagAction="yes";
TaggingUtils.observe(this.imgYes,"click",TaggingUtils.bindAsEventListener(this.triggerAction,this),false);
TaggingUtils.observe(this.imgYes,"mouseover",TaggingUtils.bindAsEventListener(this.onMouseOver,this),false);
TaggingUtils.observe(this.imgYes,"mouseout",TaggingUtils.bindAsEventListener(this.onMouseOut,this),false);
}
};
PileTagControl.prototype.setStatus=function(_f){
if(this.piles.useCSSforImages){
this.status=_f;
this.check.title=TaggingOptions.piles.clickTagSuggest.replace("TAG",this.tag);
if(this.status=="yes"){
this.check.className=(this.piles.useCSSforImages==2)?"check swSprite s_checkMarked":"checkBtnOn";
this.check.title=TaggingOptions.piles.undoTagSuggest.replace("TAG",this.tag);
}else{
this.check.className=(this.piles.useCSSforImages==2)?"check swSprite s_checkUnmarked":"checkBtnOff";
}
}else{
this.status=_f;
this.imgYes.title=TaggingOptions.piles.clickTagSuggest.replace("TAG",this.tag);
if(this.status=="yes"){
this.imgYes.src=TaggingOptions.piles.yesCheckedImg;
this.imgYes.title=TaggingOptions.piles.undoTagSuggest.replace("TAG",this.tag);
}else{
this.imgYes.src=TaggingOptions.piles.yesImg;
}
}
};
PileTagControl.prototype.onMouseOver=function(evt){
if(!this.inProgress){
var e=evt||window.event;
var _12=e.target||e.srcElement;
if(this.piles.useCSSforImages){
if(_12.tagAction=="yes"&&this.status!="yes"&&_12.className!="checkBtnOn"&&_12.className!="check swSprite s_checkMarked"){
_12.className=(this.piles.useCSSforImages==2)?"check swSprite swSprite s_checkHover":"checkBtnOver";
}
}else{
if(_12.tagAction=="yes"&&this.status!="yes"&&_12.src!=TaggingOptions.piles.yesCheckedImg){
_12.src=TaggingOptions.piles.yesHoverImg;
}
}
}
};
PileTagControl.prototype.onMouseOut=function(evt){
if(!this.inProgress){
var e=evt||window.event;
var _15=e.target||e.srcElement;
if(this.piles.useCSSforImages){
if(_15.tagAction=="yes"&&this.status!="yes"&&_15.className!="checkBtnOff"&&_15.className!="check swSprite s_checkUnmarked"){
_15.className=(this.piles.useCSSforImages==2)?"check swSprite s_checkUnmarked":"checkBtnOff";
}
}else{
if(_15.tagAction=="yes"&&this.status!="yes"&&_15.src!=TaggingOptions.piles.yesImg){
_15.src=TaggingOptions.piles.yesImg;
}
}
}
};
PileTagControl.prototype.triggerAction=function(evt){
if(!this.inProgress&&this.piles.ackStartWorkingControler(this)){
this.inProgress=true;
var _17=this.appY;
if(TaggingProductTags.editPanel){
TaggingProductTags.editPanel.hide();
TaggingProductTags.editPanel=null;
}
var e=evt||window.event;
var _19=e.target||e.srcElement;
var _1a=_19.src;
if(this.piles.useCSSforImages){
_19.className="snake";
}else{
_19.src=TaggingOptions.piles.progressImg;
}
var _1b={method:"GET",asynchronous:true,sameInstance:true,trigger:_19,previousImg:_1a};
if(!this.status||this.status!=_19.tagAction){
_1b.parameters="appID="+_17+"&tgTag="+this.tag+"&ASIN="+this.objId;
_1b.onSuccess=TaggingUtils.bind(function(_1c){
this.doneTagging(_1c,_1b);
},this);
_1b.onError=TaggingUtils.bind(function(_1d){
this.failedTagging(_1d,_1b);
},this);
_1b.onTimeout=TaggingUtils.bind(function(_1e){
this.failedTagging(_1e,_1b);
},this);
var _1f=new TaggingAjax.Request(_1b);
_1f.makeRequest(_19.tagAction=="yes"?TaggingOptions.piles.tagObjectUrlYes:TaggingOptions.piles.tagObjectUrlNo);
}else{
_1b.parameters="appID="+_17+"&tgTag="+this.tag+"&ASIN="+this.objId;
_1b.onSuccess=TaggingUtils.bind(function(_20){
this.doneRemove(_20,_1b);
},this);
_1b.onError=TaggingUtils.bind(function(_21){
this.failedRemove(_21,_1b);
},this);
_1b.onTimeout=TaggingUtils.bind(function(_22){
this.failedRemove(_22,_1b);
},this);
var _1f=new TaggingAjax.Request(_1b);
_1f.makeRequest(_19.tagAction=="yes"?TaggingOptions.piles.removeObjecTagUrlYes:TaggingOptions.piles.removeObjecTagUrlNo);
}
}
};
PileTagControl.prototype.doneTagging=function(_23,_24){
var _25=TaggingUtils.trim(_23.responseText);
var _26=_24.trigger;
var n="error";
if(_25.indexOf(this.tag+":"+this.objId+":ok")!=-1){
n="success";
if(_26.tagAction=="yes"){
this.setStatus("yes");
this.addTagToYTUI();
if(this.counter){
this.counter.increment();
}
}
}else{
_26.src=_24.previousImg;
}
this.inProgress=false;
this.piles.ackDoneWorkingControler(this,"tag",_26.tagAction,n);
};
PileTagControl.prototype.failedTagging=function(_28,_29){
if(!_28&&TaggingOptions.piles.newTagsCustomerUrl){
document.location=TaggingOptions.piles.newTagsCustomerUrl;
}else{
_29.trigger.src=_29.previousImg;
this.inProgress=false;
}
this.piles.ackDoneWorkingControler(this);
this.piles.ackDoneWorkingControler(this,"tag",_29.trigger.tagAction,"error");
};
PileTagControl.prototype.doneRemove=function(_2a,_2b){
var _2c=TaggingUtils.trim(_2a.responseText);
var _2d=_2b.trigger;
var n="error";
if(_2c.indexOf(this.objId+":ok")!=-1){
n="success";
_2d.src=TaggingOptions.piles.yesImg;
this.setStatus();
if(this.counter){
this.counter.decrement();
}
this.removeTagFromYTUI();
}else{
_2d.src=_2b.previousImg;
}
this.inProgress=false;
this.piles.ackDoneWorkingControler(this,"remove",_2d.tagAction,n);
};
PileTagControl.prototype.failedRemove=function(_2f,_30){
_30.trigger.src=_30.previousImg;
this.inProgress=false;
this.piles.ackDoneWorkingControler(this,"remove",_30.trigger.tagAction,"error");
};
PileTagControl.prototype.addTagToYTUI=function(){
var _31=document[this.objId];
if(_31&&!_31.containsTag(this.tag)){
_31.addTagAnchor(this.tag);
_31.addTag(this.tag);
var _32=document.getElementById(this.objId+"-edit");
if(_32){
_32.style.display="";
}
var _33=document.getElementById(this.objId+"-compact-edit");
if(_33){
_33.style.display="";
}
}
};
PileTagControl.prototype.removeTagFromYTUI=function(){
var _34=document[this.objId];
if(_34&&_34.containsTag(this.tag)){
var _35=_34.tags;
if(_35&&_35.length>=1){
for(i=0;i<_35.length;i++){
if(_35[i]==this.tag){
_35.splice(i,1);
_34.tags=new Array();
_34.tagsReplaced(_35);
break;
}
}
}
}
if(_34.tags.length==0){
var _36=document.getElementById(this.objId+"-edit");
if(_36){
_36.style.display="none";
}
var _37=document.getElementById(this.objId+"-compact-edit");
if(_37){
_37.style.display="none";
}
}
};
function PilesTagger(_38){
this.objId=_38.objId;
this.appY=_38.appY;
this.id=this.objId+"-piles";
this.notifyEle=document.getElementById(this.objId+"-piles-feedback");
this.notifyEle.parentNode.style.display="";
this.workingControlers=0;
if(_38.fruit){
this.useCSSforImages=2;
}else{
if(this.appY=="lm"||this.appY=="sylt"){
this.useCSSforImages=0;
}else{
this.useCSSforImages=1;
}
}
};
PilesTagger.prototype.init=function(){
var _39=document[this.objId]||new Object();
var _3a=document.getElementById(this.id);
if(_39&&_3a){
this.triggers=new Array();
var tmp=TaggingUtils.findNodes(_3a,"div","tag");
var i=0;
for(;i<tmp.length;i++){
var _3d=null;
if(typeof _39.containsTag=="function"&&_39.containsTag(tmp[i].getAttribute("tag"))){
_3d="yes";
}
var c=new PileTagControl(tmp[i],this,_3d);
this.triggers.push(c);
c.init();
}
_39.onTagAdded=TaggingUtils.bind(this.onTagAdded,this);
_39.onTagsReplaced=TaggingUtils.bind(this.onTagsReplaced,this);
}
};
PilesTagger.prototype.ackStartWorkingControler=function(_3f){
if(!TaggingProductTags.addTagInProgress||(TaggingProductTags.addTagInProgress&&this.workingControlers>0)){
TaggingProductTags.addTagInProgress=true;
this.workingControlers++;
}
return this.workingControlers>0;
};
PilesTagger.prototype.ackDoneWorkingControler=function(_40,_41,_42,_43){
var _44="";
if(_43=="success"){
_44=TaggingOptions.piles[_43+"_"+_42+"_"+_41];
}else{
_44=TaggingOptions.piles.errorMsg;
}
if(_44){
_44=_44.replace("TAG",_40.tag);
}
_44=_44||"&nbsp;";
this.updateNotify(this.notifyEle,_44,_43=="error");
if(this.workingControlers>0){
this.workingControlers--;
if(this.workingControlers==0){
TaggingProductTags.addTagInProgress=false;
}
}
};
PilesTagger.prototype.onTagAdded=function(src,tag){
for(i=0;i<this.triggers.length;i++){
if(this.triggers[i].tag==tag){
this.triggers[i].setStatus("yes");
if(this.triggers[i].counter){
this.triggers[i].counter.increment();
}
return;
}
}
};
PilesTagger.prototype.onTagsReplaced=function(src,_48,_49){
if(!_49){
_49=new Array();
}
for(i=0;i<this.triggers.length;i++){
var _4a=this.triggers[i].status;
var _4b=false;
for(j=0;j<_49.length;j++){
if(this.triggers[i].tag==_49[j]){
_4a="yes";
_4b=true;
break;
}
}
if(!_4b&&_4a=="yes"){
_4a=null;
}
if(this.triggers[i].status!=_4a){
this.triggers[i].setStatus(_4a);
if(this.triggers[i].container){
if(_4a=="yes"){
this.triggers[i].counter.increment();
}else{
this.triggers[i].counter.decrement();
}
}
}
}
};
PilesTagger.prototype.updateNotify=function(obj,_4d,_4e){
var _4f={};
obj.frame=0;
obj.steps=50;
obj.innerHTML=_4d;
obj.error=_4e;
if(_4d!="&nbsp;"){
_4f.updateNotify=function(o){
if(o.frame<o.steps){
o.frame++;
var _51=(o.steps-o.frame);
var rgb=(o.error)?{r:parseInt("0xFF"),g:parseInt("0x00"),b:parseInt("0x00")}:{r:parseInt("0xD6"),g:parseInt("0xDD"),b:parseInt("0xEA")};
var r=255-parseInt(_51*(255-rgb.r)/o.steps);
var g=255-parseInt(_51*(255-rgb.g)/o.steps);
var b=255-parseInt(_51*(255-rgb.b)/o.steps);
o.style.color=(o.error)?"#DD0000":"#000000";
o.style.background="rgb("+r+","+g+","+b+")";
setTimeout(function(){
_4f.updateNotify(o);
},10);
}
};
_4f.updateNotify(obj);
}
};


