CBSi.namespace("app.Email.SendPanel");(function(){var c=YAHOO.util.Dom;var d=YAHOO.lang.JSON;var a=YAHOO.util.Connect;var b=0;CBSi.app.Email.SendPanel={init:function(e){if(typeof(e)=="undefined"){e={}}this.panelType=(typeof(e.panelType)!="undefined")?e.panelType:1;this.panelTitle=(typeof(e.panelTitle)!="undefined")?e.panelTitle:"E-mail this to a Friend";this.location=(typeof(e.location)!="undefined")?e.location:"";this.title=(typeof(e.title)!="undefined")?e.title:"";this.email=(typeof(e.email)!="undefined")?e.email:"";if(b==1){this._debug("panelType",this.panelType);this._debug("panelTitle",this.panelTitle);this._debug("email",this.email);this._debug("location",this.location);this._debug("title",this.title)}this.emailFriendFormState=new Array();this.containerID=e.containerID;var f=this._createPanelContainer(this.containerID);this.emailFriendPanel=CBSi.panel.create("emailPanel",{width:"360px",height:"380px",underlay:"shadow",visible:false,draggable:true,constraintoviewport:true,zIndex:5002,close:true});this.emailFriendPanel.setHeader(this.panelTitle);this.emailFriendPanel.setBody('<div id="emailLoading"><div align="center"><div class="loadingImg"></div><p>Loading...</p></div></div>');this.emailFriendPanel.render(f);this.emailFriendPanel.show();this.emailFriendPanel.center();this.load(this.panelType);return false},_createPanelContainer:function(f){var e=c.get(f);if(!e){e=document.createElement("div");e.id=f;e.className="yui-skin-spln";document.body.appendChild(e)}return e},_toggleDisplay:function(f,g){var e=c.get(f);if(typeof(e)=="undefined"){return""}if(g){c.setStyle(f,"display",g)}else{e.style.display=(e.style.display=="none"||e.style.display==""?"block":"none")}return},_displayProcessingMsg:function(g){var f=(typeof(g)!="undefined")?g+"...":"Processing...";var e='<div id="emailLoading"><div align="center"><div class="loadingImg"></div><p>'+f+"</p></div></div>";this._toggleDisplay("emailHeader","none");this._toggleDisplay("emailError","none");this._toggleDisplay("emailDisclaimer","none");c.get("emailContent").innerHTML=e;return},submitEmailForm:function(f){this._debug("submitEmailForm","");a.setForm(f);this._displayProcessingMsg();var e="/data/email/send-friend";var h={success:this._showSendResponse,failure:this._displayError,scope:this};var g=a.asyncRequest("POST",e,h,null);return false},_showSendResponse:function(g){g.responseText=g.responseText.replace(/<!--.*-->/g,"");var f;try{f=d.parse(g.responseText)}catch(j){f={code:-1,desc:"error",msg:"Invalid JSON response"}}if(f.code==1){var h='<div align="center"><p><strong>Thank You!</strong></p><p>Your e-mail has been sent.</p><p><a href="#" onclick="CBSi.app.Email.SendPanel.load(1,1); return false;"><strong>Send to another recipient</strong></a></p><p><a href="#" onclick="CBSi.app.Email.SendPanel.close(); return false;"><strong>Close</strong></a></p></div>'}else{var h='<div align="center"><p><strong>We\'re Sorry!</strong></p><p>There was an error sending your e-mail.</p><p><a href="#" onclick="CBSi.app.Email.SendPanel.load(1); return false;"><strong>Please try again.</strong></a></p></div>'}c.get("emailPanelContent").innerHTML=h},close:function(){this.emailFriendPanel.hide()},load:function(e,g){this._debug("load with default view",e);if(typeof(e)=="undefined"){if(this.panelType==1){e=1}else{if(this.panelType==2){e=2;g=2}}}if(e==2){this._saveFormState()}if(g==2){this.close()}if(g==1){this.emailFriendFormState.emails="";this.emailFriendFormState.message=""}var f='<div id="emailPanelContent">';f+='<div id="emailHeader"></div>';f+='<div id="emailError" class="warn"></div>';f+='<div id="emailContent"></div>';f+='<em id="emailDisclaimer">E-mail addresses provided will not be used for solicitation.</em>';f+="</div>";this.emailFriendPanel.setBody(f);this.displayPanel(e);return false},displayPanel:function(e,f){this._debug("displayPanel");if(typeof f=="undefined"){f={}}this._displayProcessingMsg("Loading...");c.get("emailError").innerHTML="";switch(e){case 1:this._getEmailFormHTML();break;case 2:this._contactListHTML();break;case 3:this._addContactFormHTML();break;case 4:this._editContactFormHTML(f);break;case 5:this._deleteContactFormHTML(f);break}},_renderForm:function(f,e){this._debug("_renderForm");this._toggleDisplay("emailHeader","block");this._toggleDisplay("emailError","block");this._toggleDisplay("emailDisclaimer","block");this._insertHeader(e);c.get("emailContent").innerHTML=f;if(this.panelType==1){this._loadFormState()}},loadContacts:function(f){this._debug("loadContacts");var e="";for(i=0;i<f.length;i++){var g=f.elements[i];if(g.type=="checkbox"&&g.checked==true){if(this.emailFriendFormState.emails.search(g.value)==-1){if(e){e+=","+g.value}else{e=g.value}}}}if(typeof(this.emailFriendFormState.emails)!="undefined"&&this.emailFriendFormState.emails.length>0){this.emailFriendFormState.emails+=","+e}else{this.emailFriendFormState.emails=e}if(this.panelType==1){this.displayPanel(1)}else{this._loadFormState();this.emailFriendPanel.hide()}},manageContacts:function(g,e){a.setForm(g);var f="";switch(e){case"create":f="/emailafriend/add_contact";break;case"update":f="/emailafriend/update";break;case"delete":f="/emailafriend/delete";break}var j={success:function(l){var k=l.responseText.replace(/<!--.*-->/g,"");if(k==1){this.displayPanel(2)}else{this._displayError(k)}},failure:function(k){this._displayError()},scope:this};var h=a.asyncRequest("POST",f,j,null);return false},_displayError:function(g){var e="There was an error processing your request please close this window and try to send again";var f=(typeof(g)=="undefined")?e:g;c.get("emailError").innerHTML="<p>"+f+"</p>";return false},_insertHeader:function(f){var e=c.get("emailHeader");if(typeof(e)!="undefined"&&typeof(f)!="undefined"){content="<h5>"+f+"</h5>";e.innerHTML=content}return},_getEmailFormHTML:function(){var f="/emailafriend/email-panel?location="+this.location+"&email="+this.email+"&title="+this.title;var e;var h={success:function(j){this._renderForm(j.responseText)},failure:function(j){this._displayError()},scope:this};var g=a.asyncRequest("GET",f,h,null);return false},_contactListHTML:function(){var f="/emailafriend/contact_list";var e;var h={success:function(j){this._renderForm(j.responseText,"Contact List")},failure:function(j){this._displayError()},scope:this};var g=a.asyncRequest("GET",f,h,null);return false},_addContactFormHTML:function(){var f="/emailafriend/create";var e;var h={success:function(j){this._renderForm(j.responseText,"Create New Contact")},failure:function(j){this._displayError()},scope:this};var g=a.asyncRequest("GET",f,h,null);return false},_editContactFormHTML:function(e){if(typeof(e)=="undefined"){e={}}var g="/emailafriend/edit?nickname="+e.nickname+"&email="+e.email;var f;var j={success:function(k){this._renderForm(k.responseText,"Edit Contact")},failure:function(k){this._displayError()},scope:this};var h=a.asyncRequest("GET",g,j,null);return false},_deleteContactFormHTML:function(e){if(typeof(e)=="undefined"){e={}}var g="/emailafriend/deleteconf?nickname="+e.nickname+"&contact_email="+e.email;var f;var j={success:function(k){this._renderForm(k.responseText,"Delete Contact")},failure:function(k){this._displayError()},scope:this};var h=a.asyncRequest("GET",g,j,null);return false},_saveFormState:function(){this._debug("_saveFormState");if(typeof(document.emailfriendform)!="undefined"){this.emailFriendFormState.emails=document.emailfriendform.emails.value;this.emailFriendFormState.self_email=document.emailfriendform.self_email.value;this.emailFriendFormState.subject=document.emailfriendform.subject.value;this.emailFriendFormState.message=document.emailfriendform.message.value}},_loadFormState:function(){this._debug("_loadFormState");if(c.inDocument("emailfriendform")==1){this._debug("emailfriendform exists");if(typeof(this.emailFriendFormState.emails)!="undefined"){document.emailfriendform.emails.value=this.emailFriendFormState.emails}if(typeof(this.emailFriendFormState.self_email)!="undefined"){document.emailfriendform.self_email.value=this.emailFriendFormState.self_email}if(typeof(this.emailFriendFormState.subject)!="undefined"){document.emailfriendform.subject.value=this.emailFriendFormState.subject}if(typeof(this.emailFriendFormState.message)!="undefined"){document.emailfriendform.message.value=this.emailFriendFormState.message}}},_debug:function(h,g){if(b!=1){return}var f=navigator.userAgent.toLowerCase();var e="";if(typeof(h)!="undefined"){if(typeof(g)!="undefined"){e=" = "+g}if(f.indexOf("firefox")!=-1){console.log(h+e)}else{alert(h+e)}}return}}})();
