dojo.require("dijit.form.Form");dojo.require("dijit.form.ValidationTextBox");var in_count=0;var stay=false;function change_color(){var a=document.getElementById("id_important_notice");if(in_count%2==0){dojo.style(a,"color","orange")}else{dojo.style(a,"color","black")}in_count+=1}function init_home(){setInterval("change_color()",500);if(document.getElementById("id_login_form")){if(check_sid_ok("/cameras.shtml")){return}set_active_tab("home");dijit.byId("id_form_username").onFocus=redirect_website;dijit.byId("id_form_password").onFocus=redirect_website;dijit.byId("id_form_username").invalidMessage="Invalid email address";dijit.byId("id_form_username").isValid=function(){return dojo.byId("id_form_username").value!=""};dijit.byId("id_form_password").invalidMessage="Password can't be empty";dijit.byId("id_form_password").isValid=function(){return dojo.byId("id_form_password").value!=""};if(dojo.cookie("_hcun")){dojo.byId("id_form_username").value=dojo.cookie("_hcun");dojo.byId("id_remember_me").checked=true}dojo.connect(dojo.byId("id_form_username"),"onkeypress",function(c){if(c.keyCode==dojo.keys.ENTER){dijit.byId("id_form_password").focus()}});dojo.connect(dojo.byId("id_form_password"),"onkeypress",function(c){if(c.keyCode==dojo.keys.ENTER){c.preventDefault();login()}});var b=null;var a=null;if(document.istat){b=document.istat.org.value;a=document.istat.sdt.value}if(b!=null&&b!="(none)"&&b!=""&&a!=null&&a!="(none)"&&a!=""){dojo.xhrPost({url:"hc/login.action",content:{org:b,sdt:a},handleAs:"json",error:handle_sys_error,load:handle_login_rsp})}}}function handle_reset_pw_error(a){tdlg("Service Currently Unavailable","Please try again later.")}function handle_reset_pw_ok(a){if(!a.rc){tdlg("Failed to Reset Password","Invalid server response");return}if(a.rc=="ok"){tdlg("Reset Password","An email with the link to reset your password has been sent to your email address")}else{if(a.rc=="errun"){tdlg("Failed to Reset Password","Invalid email address")}else{if(a.rc=="errreg"){tdlg("Failed to Reset Password","The email address hasn't been registered")}else{if(a.rc=="errsend"){tdlg("Failed to Reset Password","Failed to send email")}else{tdlg("Failed to Reset Password",rc_msg(a.rc))}}}}}function forgot_password(){var f=new dijit.Dialog({title:"Forgot your password?",execute:"send_password(arguments[0])"});dojo.style(f.closeButtonNode,"visibility","hidden");var c=dce("center");var d=dce("div");d.style.padding="10px 0 10px 0";d.style.textAlign="left";var g=dce("div");g.style.cssFloat="left";g.style.margin="0 10px 0 0";g.innerHTML="Your Email Address";d.appendChild(g);var h=new dijit.form.ValidationTextBox({trim:"true",id:"id_form_fp_email"});h.invalidMessage="Invalid email address";h.isValid=function(){var j=dojo.byId("id_form_fp_email").value;return j!=""&&j.match(/.+@.+/)};d.appendChild(h.domNode);var a=dce("div");a.innerHTML="Your password will be sent to above email address";a.style.padding="10px 0 10px 0";d.appendChild(a);c.appendChild(d);var b=new dijit.form.Button({label:"Cancel"});var e=dojo.connect(b,"onClick",function(){f.hide();dojo.disconnect(handleOk);dojo.disconnect(e);h.destroy();f.destroy()});var i=new dijit.form.Button({label:"Send Me My Password"});handleOk=dojo.connect(i,"onClick",function(){if(!h.validate()){h.focus();return}var j=h.value;f.hide();dojo.disconnect(handleOk);dojo.disconnect(e);h.destroy();f.destroy();dojo.xhrPost({url:"hc/resetPasswordByEmail.action",content:{email:j.toUpperCase()},handleAs:"json",error:handle_reset_pw_error,load:handle_reset_pw_ok})});c.appendChild(b.domNode);c.appendChild(i.domNode);f.setContent(c);f.show();f._onKey=function(j){if(j.keyCode==dojo.keys.ESCAPE){b.onClick()}}}function handle_sys_error(a){alert(a.message);dojo.byId("id_login_err_msg").innerHTML="Sorry, service not available"}function handle_login_rsp(a){if(!a.rc){dojo.byId("id_login_err_msg").innerHTML="Sorry, internal system error";return}if(a.rc=="ok"){if(a.sid){set_sid(a.sid);dojo.byId("id_login_err_msg").innerHTML="";document.location="cameras.shtml"}else{tdlg("Failed to Login","Invalid server response")}}else{if(a.rc=="errauth"){dojo.byId("id_login_err_msg").innerHTML="Username and password do not match"}else{if(a.rc=="errstat"){dojo.byId("id_login_err_msg").innerHTML='You already have an active session.<a href="/support.shtml#15">Learn more...</a>'}else{if(a.rc=="errsys"){dojo.byId("id_login_err_msg").innerHTML="Sorry, service not available"}else{if(a.rc=="errtok"){clr_sid();dojo.byId("id_login_err_msg").innerHTML="Invalid login session"}else{if(a.rc=="errtz"){dojo.byId("id_login_err_msg").innerHTML="Invalid user timezone setting"}else{if(a.rc=="erracnt"){dojo.byId("id_login_err_msg").innerHTML="User account disabled"}else{if(a.rc=="errto"){dojo.byId("id_login_err_msg").innerHTML="Sorry, request time out"}else{if(a.rc="errhcexp"){dojo.byId("id_login_err_msg").innerHTML="Session expired"}else{dojo.byId("id_login_err_msg").innerHTML=a.rc}}}}}}}}}}function handle_get_sid_rsp(b){if(b.rc&&b.rc=="ok"&&b.authid){clr_sid();dojo.xhrPost({url:"hc/login.action",content:{email:dojo.byId("id_form_username").value.toUpperCase(),pw:calc_pw_hash(dojo.byId("id_form_username").value.toUpperCase(),dojo.byId("id_form_password").value,b.authid),sid:b.authid},handleAs:"json",error:handle_sys_error,load:handle_login_rsp})}else{var a=dojo.byId("id_form_username").value;if(a.match(/.*@.*/)){tdlg("Failed to Login","Error code: "+b.rc)}else{tdlg("Failed to Login","Malformed username")}}}function redirect_website(){var a=document.domain;if(a==="www.homecamera.com"&&stay==false){var b=dijit.byId("id_login_gotocamera");b._onKey=function(){};dojo.style(b.closeButtonNode,"visibility","hidden");b.show()}}function login(){if(dijit.byId("id_login_form").validate()){if(dojo.byId("id_remember_me").checked){dojo.cookie("_hcun",dojo.byId("id_form_username").value,{expires:365})}else{dojo.cookie("_hcun",null,{expires:-1})}clr_sid();dojo.xhrPost({url:"hc/getLoginSessionId.action",content:{email:dojo.byId("id_form_username").value.toUpperCase()},handleAs:"json",error:handle_sys_error,load:handle_get_sid_rsp})}}function remember_me(){dojo.byId("id_remember_me").checked=!dojo.byId("id_remember_me").checked}dojo.addOnLoad(init_home);
