var EnterEmailScreen=new Class({Extends:Screen,options:{email:""},initialize:function(b,a){this.parent(b,a);
this.emailField=new RegistrationEmailField(this.rootEl.getElement("input[type=email]"),{onValidationComplete:function(c){if(c){this.fireEvent("submit",this.getEmail())
}else{this.emailField.showTooltip()
}}.bind(this),onRegisteredEmailFound:function(c){this.fireEvent("registeredEmailFound",c)
}.bind(this)});
if(this.options.email){this.emailField.setEmail(this.options.email)
}this.rootEl.getElement("form").addEvent("submit",function(c){c.preventDefault();
this.validate()
}.bind(this))
},getEmail:function(){return $(this.emailField).get("value").trim()
},validate:function(){return this.emailField.validate()
},setFocus:function(){this.emailField.setFocus()
}});
var CreatePasswordScreen=new Class({Extends:Screen,options:{regMethod:null,promoId:null,referrerGuid:null,emails:{daily:false,weekly:false}},initialize:function(b,a){this.parent(b,a);
if(!(this.options.promoId||this.options.referrerGuid)){throw"CreatePasswordScreen: missing either a promoId or an inviter referrerGuid)"
}this.formEl=this.rootEl.getElement("form");
this.submitButtonEl=this.rootEl.getElement("button").set("disabled",false);
this.passwordField=new PasswordField(this.rootEl.getElement("input[type=password]"));
this.tosField=new FormField(this.rootEl.getElement("input[type=checkbox]"),{validators:[{tester:function(c){return(c.get("checked")===true)
},message:"You must agree to atomicHIE’s terms and conditions."}],tooltipStyle:"top"});
$(this.tosField).getParent("div").addEvent("click:relay(a)",function(c){c.preventDefault();
window.open("/terms-of-service","_blank","menubar=no,width=650,height=700,toolbar=no,scrollbars=yes,resizable=yes")
});
this.rootEl.getElement("form").addEvent("submit",function(c){c.preventDefault();
if(this.validate()){this.register()
}}.bind(this))
},validate:function(){if(!this.passwordField.validate()){this.passwordField.showTooltip();
return false
}if(!this.tosField.validate()){this.tosField.showTooltip();
return false
}return true
},setFocus:function(){this.passwordField.setFocus()
},setEmail:function(a){this.email=a
},register:function(){this.submitButtonEl.set("disabled",true);
new Request.JSONP({url:atomicHIE.SECURE_HOST+"/registerasync.php",data:Object.merge(this.formEl.toQueryObject(),{action:"register",emailAddress:this.email,method:this.options.regMethod,promoId:this.options.promoId,referrerGuid:this.options.referrerGuid,travelSaleReminder:this.options.emails.daily?"on":"off",travelUpcomingSales:this.options.emails.weekly?"on":"off"}),onSuccess:function(b){if(b.success){GA.trackRegistration(b.data.promoAlias);
omniture.trackRegistration(b.data.promoAlias);
atomicHIE.user=new User();
this.fireEvent("registrationComplete")
}else{var a=b.errors[0][0].toInt(),c=b.errors[0][1];
this.passwordField.showTooltip(c);
this.submitButtonEl.set("disabled",false)
}}.bind(this)}).send()
}});
var RegistrationPage=new Class({Implements:[Events,Options,Screen.SlideShowHelpers],options:{promoId:null,referrerGuid:"",targetUrl:"/sales"},initialize:function(c,b){this.setOptions(b);
this.rootEl=c.addEvent("click:relay(a)",function(f,d){var e=new URI(d.get("href"));
if(e.get("file")===new URI().get("file")){f.preventDefault();
this.showScreenById(e.get("fragment"))
}}.bind(this));
this.modalScreens=new SlideShow(c,{duration:1200}).addEvents({show:function(d){c.setStyle("overflow","hidden")
},showComplete:function(d){this.setFocus();
c.setStyle("overflow","visible")
}.bind(this)});
var a={promoId:this.options.promoId,referrerGuid:this.options.referrerGuid,regMethod:"sem",emails:{weekly:true},onRegistrationComplete:function(){omniture.trackFeature("two-steps:registration:registered");
setTimeout(function(){location.replace(this.options.targetUrl)
}.bind(this),250)
}.bind(this)};
if(true){this.createPasswordScreen=new CreatePasswordScreen(c.getElement("#create-password"),a);
this.enterEmailScreen=new EnterEmailScreen(c.getElement("#enter-email"),{email:new URI().getData("email"),onSubmit:function(d){this.createPasswordScreen.setEmail(d);
this.modalScreens.show(1);
omniture.trackFeature("two-steps:registration:create-password")
}.bind(this),onRegisteredEmailFound:function(d){this.sendToLogin(d)
}.bind(this)});
$(this.enterEmailScreen).addEvent("click:relay(a.login)",function(d){d.preventDefault();
this.sendToLogin(this.enterEmailScreen.getEmail())
}.bind(this));
this.modalScreens.show(0,{transition:"none"});
this.rootEl.setStyle("overflow","visible");
omniture.trackFeature("two-steps:registration:enter-email")
}else{this.registrationScreen=new RegistrationScreen(c.getElement("#register-screen"),a);
this.registrationScreen.addEvent("login",function(d){this.sendToLogin(d)
}.bind(this));
this.modalScreens.show(2,{transition:"none"})
}},sendToLogin:function(a){var b=Object.toQueryString({email:a||null,"return":this.options.targetUrl.encode64()||null});
location="/login"+(b?"?"+b:"")
}});
window.addEvent("domready",function(){new RegistrationPage($("modal"),{promoId:atomicHIE.data.promoId,referrerGuid:atomicHIE.data.referrerGuid,targetUrl:atomicHIE.data.targetUrl});
new BackgroundImage(atomicHIE.data.backgroundImageUrl,{showGradients:true})
});

