var TellAFriendObj=Class.create({initialize:function(){this.divID="TAF";this.asin="";this.toList="";if(this.getURLParam("TAFAction")=="display"){if(BrowserInfo.getIsIE()){Event.observe(window,"load",function(){this.startFunction(this.getURLParam("ASIN"))}.bind(this))}else{document.observe("dom:loaded",function(){this.startFunction(this.getURLParam("ASIN"))}.bind(this))}}},attachEvents:function(){$("TAFTo").onclick=function(){this.checkTo()}.bind(this);$("TAFTo").onblur=$("TAFTo").onclick;$(this.divID).select(".TAFClose").each(function(closeElem){closeElem.onclick=this.closeDisplay.bindAsEventListener(this)}.bind(this));$("TAFSend").onclick=function(){$("TAFSend").style.opacity=0.5;this.ajaxSubscribe()}.bindAsEventListener(this)},ajaxSubscribe:function(){if(this.validateEmailList()){$("TAFMainError").style.display="none";var url=this.getTAFSecureUrl()+"&TAFAction=send&layoutId=3&";url+="ASIN="+this.asin;url+="&TAFTo="+encodeURIComponent($("TAFTo").value);if($("TAFCCMe").checked==true){url+="&TAFCCMe=true&"}new Ajax.Request(url,{method:"post",onSuccess:function(transport){try{var response=eval("("+transport.responseText+")");if(response.error!=undefined){this.showErrorPopUp()}else{if(response.fatal!=undefined||response.success==undefined){this.showFatalPopUp()}else{if(response.success!=undefined){this.showThankYouPopUp()}}}}catch(e){this.showErrorPopUp()}}.bind(this)})}else{$("TAFMainError").style.display="block";$("TAFSend").style.opacity=1}},callOmniture:function(event){if($("emwaOmnitureCode")==undefined){var omnitureCode=document.createElement("span");omnitureCode.setAttribute("id","emwaOmnitureCode");omnitureCode.style.visibility="hidden";$$("body")[0].appendChild(omnitureCode)}else{$("emwaOmnitureCode").innerHTML=""}new Ajax.Request(this.getOmnitureSecureUrl()+"&slot=left-1&ASIN="+this.parentAsin+"&childASIN="+this.childAsin+"&events="+event+"&campaign=tellafriend",{method:"post",evalScripts:true,onComplete:function(transport){$("emwaOmnitureCode").innerHTML=transport.responseText}.bind(this)})},closeDisplay:function(){display.ajax.closeDisplay()},checkTo:function(){if($("TAFTo").value==this.toList){$("TAFTo").value=""}else{if($("TAFTo").value==""){$("TAFTo").value=this.toList}}},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""},onPopupAjaxComplete:function(event){$$("body")[0].stopObserving(this.divID+":AjaxSuccess");Event.stopObserving($$("body")[0],this.divID+":AjaxSuccess");Event.stop(event);this.signedIn=($("TAFSignedIn")!=undefined)?$("TAFSignedIn").value:"false";if(this.signedIn=="true"){this.toList=$("TAFTo").value;this.attachEvents();display.ajax.showItems()}else{if($("TAFSigninURL")==undefined){this.onPopupAjaxFail(event)}else{this.signInUrl=$("TAFSigninURL").value;document.location=this.signInUrl}}},onPopupAjaxFail:function(event){$$("body")[0].stopObserving(this.divID+":AjaxFail");Event.stopObserving(event);Event.stop(event);if($("TAFErrorInfo")!=undefined){$("TAFErrorInfo").innerHTML="We have encountered an error.  Please try your request later.";$("TAFErrorInfo").show()}},startFunction:function(asin){this.asin=asin;$$("body")[0].observe(this.divID+":AjaxSuccess",this.onPopupAjaxComplete.bind(this));$$("body")[0].observe(this.divID+":AjaxFail",this.onPopupAjaxFail.bind(this));display.ajax.render(this.divID,this.getTAFSecureUrl()+"&ASIN="+this.asin+"&TAFAction=display&layoutId=3&layoutDomain=Bebe")},showErrorPopUp:function(){$("TAFMain").style.display="none";$("TAFSuccess").style.display="block";$("TAFError").style.display="none";$("TAFMainError").style.display="block";$("TAFSend").style.opacity=1;$("TAFTo").addClassName("tafError")},showFatalPopUp:function(){$("TAFMain").style.display="none";$("TAFSuccess").style.display="none";$("TAFError").style.display="block"},showThankYouPopUp:function(){$("TAFMain").style.display="none";$("TAFSuccess").style.display="block";$("TAFError").style.display="none"},validateEmail:function(str){var at="@";var dot=".";var lat=str.indexOf(at);var lstr=str.length;var ldot=str.indexOf(dot);if(str.indexOf(at)==-1){return false}if(str.indexOf(at)==-1||str.indexOf(at)==0||str.indexOf(at)==lstr){return false}if(str.indexOf(dot)==-1||str.indexOf(dot)==0||str.indexOf(dot)==lstr){return false}if(str.indexOf(at,(lat+1))!=-1){return false}if(str.substring(lat-1,lat)==dot||str.substring(lat+1,lat+2)==dot){return false}if(str.indexOf(dot,(lat+2))==-1){return false}if(str.indexOf(" ")!=-1&&str.indexOf(" ")!=0){return false}return true},validateEmailList:function(){var isValid=true;var value;if($("TAFTo")){value=$("TAFTo").value}if(value!=this.toList){var emailList=value.split(",");for(i=0;i<emailList.length;i++){if(!this.validateEmail(emailList[i])){isValid=false;$("TAFTo").addClassName("tafError");alert(emailList[i]+" contains errors, please fix them and try again.");break}}if(isValid){$("TAFTo").removeClassName("tafError")}}else{$("TAFTo").addClassName("tafError");isValid=false}return isValid},getTAFSecureUrl:function(){if($("TAFPageSecureURL")!=undefined){return $("TAFPageSecureURL").value}if(typeof (SecureUrls)!="undefined"&&typeof (SecureUrls.tellAFriend)!="undefined"){return SecureUrls.tellAFriend}return""},getOmnitureSecureUrl:function(){if(typeof (SecureUrls)!="undefined"&&typeof (SecureUrls.omnitureOverlay)!="undefined"){return SecureUrls.omnitureOverlay}return""}});var tellAFriend=new TellAFriendObj();