/*
* file created date: 12/10/2013
*
* Membership Modal Window core JS
* version 0.0.8
* updated 12/10/13
* doc : http://techwiki/display/tw/Membership+Modals
*
*/
var XO=XO||{};XO.membership=XO.membership||{};
XO.membership.modal=function(){var w=document.getElementsByTagName("head")[0],k=window.location.host.match(/(thebump|thenest|theknot|weddingchannel)|/ig).join(""),s=function(a){return parseInt(a.replace(/\./g,""),10)},t=!1,x=function(a){var b=a.modal.find("#modal-join-username"),d=a.modal.find("#username-tip"),e={opacity:1},g={height:Math.floor(d.height())+"px"};d.css({height:0,display:"block"});d.css({opacity:0});b.bind("focus",function(){d.animate(g,function(){d.animate(e)})})},u={thenest:{join:"join-lifestyle"},
theknot:{},weddingchannel:{},thebump:{}},y={theknot:{"modal-widget-login":{height:325}},thenest:{},thebump:{},weddingchannel:{}},m=[],z={theknot:!0,thebump:!0,thenest:!0,weddingchannel:!0}[k],c;c=function(){this.cfg={};void 0===window.jQuery&&this.load_dependency(this.js_dependencies.shift().url);if(void 0===XO.membership_modal_dependency_status||"waiting"!==XO.membership_modal_dependency_status&&"done"!==XO.membership_modal_dependency_status)XO.membership_modal_dependency_status="waiting",this.load_js_dependencies();
this.doc=document;this.bd=this.doc.body;this.widget_is_on_the_page=!1;this.close_button=this.modal=this.spinner=null;return this};c.prototype.apikey=null;c.prototype.set_site_configs=function(){this.site_configs=XO.membership.modalConfigs.skin_info};c.prototype.js_dependencies=[{name:"jquery",url:"//www.xoedge.com/jscripts/jquery/jquery-1.7.1.min.js",is_included:function(){return"undefined"!==typeof jQuery&&"undefined"!==typeof jQuery.fn&&150s(XO.version)}},{name:"xo social",url:"//www.xoedge.com/jscripts/shared/xo/xo.social/xo.social-0.0.1-min.js",is_included:function(){return"undefined"!==typeof tkSocial}},{name:"membership",url:"//www.xoedge.com/jscripts/shared/xo/xo.membership/xo.membership-latest.min.js",is_included:function(){return"undefined"!==typeof XO&&"undefined"!==typeof XO.membership&&"undefined"!==
typeof XO.membership.get_version&&9e&&(e+=1,c(f))},500)};d()?a.call(b):c(null)};c.prototype.execute_when_js_dependencies_are_loaded=function(a){var b=this,d=function(){var a=!1;"undefined"!==typeof jQuery&&"undefined"!==typeof b.site_configs&&"done"===
XO.membership_modal_dependency_status&&0>=XO.membership_modal_dependency_count&&(a=!0);return a},e=function(a){var d;(function(){d=[b.generic_configs.stylesheet_url,b.site_configs.stylesheet_url];b.insert_stylesheets(d,function(){})})();b.execute_when_css_dependencies_are_loaded(a)},c=0,f=function(p){p=setTimeout(function(){d()?e(a):(void 0===b.site_configs&&"undefined"!==typeof XO&&"undefined"!==typeof XO.membership&&"undefined"!==typeof XO.membership.modalConfigs&&"undefined"!==typeof XO.membership.modalConfigs.skin_info&&
b.set_site_configs(),10>c&&(c+=1,f(p)))},500)};d()?e(a):f(null)};c.prototype.version="0.0.8";c.prototype.create_message=function(a){var b=$("#"+this.cfg.type+"-error-wrapper"),d=a.method||"append",e=$("
",{"class":"msg "+a.type,html:a.text});a.dest=a.dest||b;a.dest[d](e);return e};c.prototype.generic_configs={stylesheet_url:"//www.xoedge.com/jscripts/test/membership.modal/6/css/shared.css","modal-widget-login-gate":{template:{login_form:'',
close_button:'X',client_side_error_wrapper:''}},"modal-widget-join":{template:{join_form:'',
close_button:'X',client_side_error_wrapper:''}},"modal-widget-login":{template:{login_form:'',
close_button:'X',client_side_error_wrapper:''}},"modal-widget-join-lifestyle":{template:{join_form:'',
close_button:'X',client_side_error_wrapper:''}},"modal-widget-forgot-password":{template:{forgot_password_form:'',
close_button:'X',client_side_error_wrapper:''}}};c.prototype.close_modal=function(){this.cfg.before_close(this.modal,this.cfg);$(this.doc).unbind("keyup.close-modal");this.close_button.unbind("click.close");this.modal.hide();this.cfg.after_close(this.modal,this.cfg)};c.prototype.bind_modal_close_event=function(){var a=this;this.close_button.bind("click.close",
function(b){a.close_modal()});$(this.doc).bind("keyup.close-modal",function(b){27===b.keyCode&&a.close_modal()})};c.prototype.open_modal=function(){var a=this;this.execute_when_js_dependencies_are_loaded(function(){null!==a.modal?(a.cfg.before_open(a.modal,a.cfg),a.bind_modal_close_event(),a.modal.show(),a.cfg.after_open(a.modal,a.cfg)):(a.merge_configs(),a.get_and_open_modal(),a.bind_modal_close_event())})};c.prototype.add_instance=function(a,b){this.instances[a]=b};c.prototype.trigger_js=function(a){var b=
this;(0,{"modal-widget-login-gate":function(){b.implement_login_functionality()},"modal-widget-join":function(){b.implement_registration_functionality();b.set_wedding_date_dropdowns();b.fix_privacy_policy_link()},"modal-widget-join-lifestyle":function(){b.implement_registration_functionality();x(b)},"modal-widget-login":function(){b.implement_login_functionality()},"modal-widget-forgot-password":function(){b.implement_request_password_via_form_submit()}}[a])()};c.prototype.implement_request_password_via_form_submit=
function(){var a=this,b=this.modal.find("form").first(),d=this.modal.find("#"+a.cfg.type+"-email"),e=b.find("button").last(),c=function(b){null!==a.success_message&&a.success_message.remove();a.success_message=a.create_message({type:"success",text:b,method:"html",dest:a.modal.find(".callout-b").first()})};b.bind("submit.reset-password",function(b){b.preventDefault();b=d.val();var p=""!==b.replace(/\s/g,"");$("#"+a.cfg.type+"-error-wrapper").html("");p?a.reset_password(b,e,{success:c}):a.create_message({type:"error",
text:"Email address is required. Please try again."})})};c.prototype.fix_privacy_policy_link=function(){"weddingchannel"===k&&this.modal.find(".cta-wrap-b .anchor-a").attr("href","//weddings.weddingchannel.com/advertising-promotion-partnership-opportunities/privacy-policy/articles/Privacy-Policy.aspx")};c.prototype.set_wedding_date_dropdowns=function(){var a=new Date,b=a.getMonth()+1,d=a.getDate(),a=a.getUTCFullYear()+1,e=this.modal.find("#modal-join-wedding-month"),c=this.modal.find("#modal-join-wedding-day"),
f=this.modal.find("#modal-join-wedding-year");e.val(b);c.val(d);f.val(a)};c.prototype.get_and_open_modal=function(){var a=$("",{"class":"modal-widget "+this.cfg.type,id:this.cfg.supplied_type}),b=null,d="modal-widget-join"===this.cfg.supplied_type,e="function"===typeof this.cfg.open_conversion;void 0===this.generic_configs[this.cfg.type.template]&&"undefined"!==typeof this.site_configs&&(this.set_site_configs(),b=this.update_template(this.site_configs[this.cfg.supplied_type].template,this.generic_configs[this.cfg.supplied_type].template));
"undefined"===typeof this.modal_is_opened&&(this.modal_is_opened=!0,a.html(b),this.modal=a,this.add_instance(this.cfg.type,a),d&&(e?this.cfg.open_conversion():window.cmCreateConversionEventTag?window.cmCreateConversionEventTag(this.cfg.conversion_event_value,"1","MEMBERSHIP"):"undefined"!==typeof console&&"warn"in console&&console.warn("window.cmCreateConversionEventTag is undefined -- CoreMetrics not on the page - unable to fire conversion event")),this.cfg.before_insert(this.modal,this.cfg),$(this.bd).prepend(a),
this.cfg.after_insert(this.modal,this.cfg),this.widget_is_on_the_page=!0,this.close_button=this.modal.find(".btn-close"),this.position_module(this.modal,this.cfg.position),this.trigger_js(this.cfg.type))};c.prototype.update_template=function(a,b){var d,e,c;for(d in b)b.hasOwnProperty(d)&&(e=RegExp("%"+d+"%","ig"),c=b[d],a=a.replace(e,c));return a};c.prototype.instances={};c.prototype.loaded_assets=[];c.prototype.check_if_asset_is_loaded=function(a){var b=this.loaded_assets.length,d=!1,e;for(e=0;e<
b;e+=1)if(this.loaded_assets[e]===a){d=!0;break}return d};c.prototype.register_loaded_asset=function(a){this.loaded_assets.push(a)};c.prototype.insert_stylesheets=function(a,b){var d=this,e=$("head"),c=0,f=$("",{type:"text/css",rel:"stylesheet"}),p=$("