var EMWAItem=Class.create({initialize:function(){this.divID="emwa";this.childAsin="";this.parentAsin="";this.successLogin=false;if(this.getURLParam("emwaSubscribe")=="true"){this.successLogin=true;if(BrowserInfo.getIsIE()){Event.observe(window,"load",function(){this.startFunction(this.getURLParam("parentAsin"),this.getURLParam("childAsin"))}.bind(this))}else{document.observe("dom:loaded",function(){this.startFunction(this.getURLParam("parentAsin"),this.getURLParam("childAsin"))}.bind(this))}}},startFunction:function(parentAsin,childAsin){this.parentAsin=parentAsin;this.childAsin=childAsin;$$("body")[0].observe(this.divID+":AjaxSuccess",this.onPopupAjaxComplete.bindAsEventListener(this));$$("body")[0].observe(this.divID+":AjaxFail",this.onPopupAjaxFail.bindAsEventListener(this));var emwaDispatchPath=$("emwaDispatchPath").value+"&slot=left-1&ASIN="+this.childAsin+"&parentAsin="+this.parentAsin+"&layoutId=Display&layoutDomain=Bebe";display.ajax.render(this.divID,emwaDispatchPath)},callOmniture:function(name,event){var s=s_gi(s_account);var pageName="Emwa";if(name!=undefined){pageName=name}s.pageName=pageName;var events="prodView,event11,event20";if(event!=undefined){events+=","+event}s.events=events;s.channel="emwa";void (s.t())},onPopupAjaxComplete:function(event){$$("body")[0].stopObserving(this.divID+":AjaxSuccess");Event.stopObserving($$("body")[0],this.divID+":AjaxSuccess");Event.stop(event);this.signedIn=$("emwaSignedIn").value;this.signInUrl=$("emwaSignInURL").value;if(this.signedIn=="true"){this.attachEvents();display.ajax.showItems();this.callOmniture("emwa:subscribe","event2")}else{document.location=this.signInUrl}},onPopupAjaxFail:function(event){$$("body")[0].stopObserving(this.divID+":AjaxFail");Event.stopObserving(event);Event.stop(event);if($("swatchColorInfo")!=undefined){$("swatchColorInfo").innerHTML="WE HAD AN ERROR!"}},attachEvents:function(){$$(".closeEMWAButton").each(function(closeElem){Event.observe(closeElem,"click",this.closeEMWADisplay.bindAsEventListener(this))}.bind(this));Event.observe("confirmButton","click",function(event){$("confirmButton").stopObserving("confirmButton");$("confirmButton").style.opacity=0.5;this.ajaxSubscribe()}.bindAsEventListener(this))},ajaxSubscribe:function(){new Ajax.Request("/emwa/"+this.childAsin,{method:"post",parameters:{parentAsin:this.parentAsin,childAsin:this.childAsin,asin:this.childAsin},onSuccess:function(transport){if(transport.responseText.indexOf("GSSCALLFAILURE")!=-1){this.showErrorPopUp();this.callOmniture("emwa:error")}else{this.showThankYouPopUp();this.callOmniture("emwa:confirm","event3")}}.bind(this),onFailure:function(transport){this.showErrorPopUp();this.callOmniture("emwa:error")}.bind(this)})},showErrorPopUp:function(){$("emwaDisplay").style.display="none";$("emwaThankYou").style.display="none";$("emwaError").style.display="block"},showThankYouPopUp:function(){$("emwaDisplay").style.display="none";$("emwaThankYou").style.display="block";$("emwaError").style.display="none"},closeEMWADisplay:function(){display.ajax.closeDisplay()},getURLParam:function(parameter){var url=window.location.href;var paramStartIndex=url.indexOf(parameter+"=");if(paramStartIndex!=-1){var returnValueStartIndex=paramStartIndex+parameter.length+1;var returnValueEndIndex;if(url.indexOf("?",returnValueStartIndex)!=-1){var valueQuestion=url.indexOf("?",returnValueStartIndex);var valueAmper=url.indexOf("&",returnValueStartIndex);if(valueQuestion<valueAmper){returnValueEndIndex=valueQuestion}else{returnValueEndIndex=valueAmper}}else{returnValueEndIndex=url.indexOf("&",returnValueStartIndex)}returnValueEndIndex=returnValueEndIndex==-1?window.location.href.length:returnValueEndIndex;return url.substring(returnValueStartIndex,returnValueEndIndex)}return""}});