﻿var Sawbuck = window.Sawbuck || {}; Sawbuck.UserManager = function () { function K(a) { $j.ajax({ type: "POST", url: "/service/WebService.asmx/SetMessageStatus", data: Sawbuck.Utilities.toJson({ messageID: a }), contentType: "application/json; charset=utf-8", dataType: "json", processData: false, success: function (a) { }, error: function () { } }) } function J(a) { email = a["email"].value.trim(); if (!k.test(email)) { u(a, "Not a valid email address"); return false } $j.ajax({ type: "POST", url: "/service/WebService.asmx/RetrievePassword", data: Sawbuck.Utilities.toJson({ Email: email }), contentType: "application/json; charset=utf-8", dataType: "json", processData: false, success: function (b) { if (b.d == true) { $j(".dialogBox").dialog("close"); alert("An email has been sent with instructions on resetting your password") } else { u(a, "That email address is not in our system.") } }, error: function () { } }) } function I() { $j.ajax({ type: "POST", url: "/service/WebService.asmx/DeleteAccount", data: Sawbuck.Utilities.toJson({}), contentType: "application/json; charset=utf-8", dataType: "json", processData: false, success: function (a) { if (c) { FB.api({ method: "auth.revokeAuthorization" }); FB.logout() } window.location = "/logout/" }, error: function () { } }) } function H(a, b, c) { form = $j("#changePasswordForm").children("form"); a = Sawbuck.Utilities.trim(a); pw = Sawbuck.Utilities.trim(b); pw2 = Sawbuck.Utilities.trim(c); if (!a || !pw || !pw2) { u(form, "All fields are required"); return false } if (pw.length < 5) { u(form, "Password must be at least 5 characters long"); return false } if (pw != pw2) { u(form, "Passwords do not match"); return false } $j.ajax({ type: "POST", url: "/service/WebService.asmx/ChangePassword", data: Sawbuck.Utilities.toJson({ OldPassword: a, NewPassword: pw, NewPasswordConfirm: pw2 }), contentType: "application/json; charset=utf-8", dataType: "json", processData: false, success: function (a) { $j(form).children("input").val(""); if (a.d == true) { $j("#changePasswordForm").dialog("close"); $j("#passwordChangeSuccess").show(); setTimeout(function () { $j("#passwordChangeSuccess").fadeOut("slow") }, m) } else { u(form, "Invalid credentials. Please try again.") } }, error: function () { } }) } function G(a) { $j.ajax({ type: "POST", url: "/service/WebService.asmx/InviteUser", data: Sawbuck.Utilities.toJson({ Email: a }), contentType: "application/json; charset=utf-8", dataType: "json", processData: false, success: function (a) { $j("#addUserForm").dialog("close"); $j("#addUserInviteSent").show(); setTimeout(function () { $j("#addUserInviteSent").fadeOut("slow") }, m) }, error: function () { } }) } function F(a) { email = $j(a).find("input[name=email_address]").val(); pw = $j(a).find("input[name=password]").val(); if (Sawbuck.Utilities.trim(email).length < 2 || Sawbuck.Utilities.trim(pw).length < 2) { u(a, "Must enter your email address and password") } else if (!k.test(email)) { u(a, "Not a valid email address") } else { data = { Email: email, Password: pw, Url: window.location.toString() }; $j.ajax({ type: "POST", url: "/service/WebService.asmx/Login", data: Sawbuck.Utilities.toJson(data), contentType: "application/json; charset=utf-8", dataType: "json", processData: false, dataFilter: function (a, b) { return a.replace(/"\\\/Date\(([0-9-]+)\)\\\/"/gi, "$1") }, success: function (b) { var f = b.d.Msg; d = (b.d.Preferences & 1) == 1; e = b.d.Alerts; if (f == 1) { i = b.d.FirstName; j = b.d.LastName; c = b.d.FacebookID; r() } else if (f == 2048) A(email, true); else u(a, "Invalid credentials.") }, error: function () { u(a, "There was a problem signing you in.") } }) } } function E() { $j.ajax({ type: "POST", data: "{FacebookID: null}", url: "/service/WebService.asmx/DeleteFacebookID", contentType: "application/json; charset=utf-8", dataType: "json", processData: false, success: function (a) { }, error: function () { } }) } function D(a) { var b = parseInt(a.authResponse.userID); c = c || b; data = { FacebookID: b }; $j.ajax({ type: "POST", url: "/service/WebService.asmx/ConnectToFacebook", data: Sawbuck.Utilities.toJson(data), contentType: "application/json; charset=utf-8", dataType: "json", processData: false, success: function (a) { }, error: function () { } }) } function C(a) { if (!a.authResponse) return false; var b = parseInt(a.authResponse.userID); c = c || b; data = { FacebookID: b }; $j.ajax({ type: "POST", url: "/service/WebService.asmx/LoginFacebook", data: Sawbuck.Utilities.toJson(data), contentType: "application/json; charset=utf-8", dataType: "json", processData: false, success: function (a) { var b = a.d.Msg; d = (a.d.Preferences & 1) == 1; e = a.d.Alerts; if (b == 1) { i = a.d.FirstName; j = a.d.LastName; r() } if (b == 8) { FB.api("/me", w) } }, error: function () { u(form, "There was a problem signing you in.") } }) } function B(a, b) { var c = true; if (b == true) { $j.ajax({ type: "POST", url: "/service/WebService.asmx/RLVerifyEmail", data: Sawbuck.Utilities.toJson({ Email: a }), contentType: "application/json; charset=utf-8", dataType: "json", processData: false, success: function (b) { if (b.d == true) { $j.ajax({ type: "POST", url: "/service/WebService.asmx/UpdateAccountInfo", data: Sawbuck.Utilities.toJson({ Email: a, FirstName: "", LastName: "" }), contentType: "application/json; charset=utf-8", dataType: "json", processData: false, success: function (b) { if (b.d == true) { t(a); A(a) } else { $j(".updatedEmailSection .error").text("The email address you entered is already in use.") } }, error: function () { } }) } else { z(a) } }, error: function () { } }) } else { $j.ajax({ type: "POST", url: "/service/WebService.asmx/UpdateAccountInfo", data: Sawbuck.Utilities.toJson({ Email: a, FirstName: "", LastName: "" }), contentType: "application/json; charset=utf-8", dataType: "json", processData: false, success: function (b) { if (b.d == true) { t(a); A(a) } else { $j(".updatedEmailSection .error").text("The email address you entered is already in use.") } }, error: function () { } }) } } function A(a, b) { if (!a) a = g; if (!$j("#registrationConfirmation").length) { var c = document.createElement("div"); c.setAttribute("id", "registrationConfirmation"); c.setAttribute("class", "dialogBox resizable"); c.setAttribute("title", "Registration Confirmation"); document.body.appendChild(c); $j("#registrationConfirmation").dialog({ bgiframe: true, modal: true, autoOpen: false, width: 390, maxWidth: 390, minWidth: 390 }) } $j(".dialogBox:visible input").val(""); $j(".dialogBox:visible").dialog("close"); $j("#registrationConfirmation").dialog("open"); followUpText = "<p>A confirmation email"; followUpText += b ? " was previously" : " has been"; followUpText += " sent to <b>" + a + "</b>. Please click the link in the email to validate your registration.</p><br/>"; followUpText += "<p><a href='#' onclick='Sawbuck.UserManager.resendConfirmationEmail(); return false;'>Re-Send Email</a>"; followUpText += " &#160;or&#160; "; followUpText += "<a href='#' onclick=\"$j('.updatedEmailSection').fadeIn(); return false;\">Update Email Address</a></p>"; followUpText += "<div class='updatedEmailSection' style='display: none'><br/><div class='error'></div>"; followUpText += "<input type='text' style='width: 250px; margin-right: 5px;' value='" + a + "' size='40' id='updatedEmailField' name='email'/>"; followUpText += "<a class='s_button' style='float: left; clear: none;' onclick=\"Sawbuck.UserManager.updateUnconfirmedEmail($j('#updatedEmailField').val(),false); return false;\"><span class='s_button'>Update</span></a></div>"; $j("#registrationConfirmation").html(followUpText) } function z(a) { if (!$j("#emailConfirmation").length) { var b = document.createElement("div"); b.setAttribute("id", "emailConfirmation"); b.setAttribute("class", "dialogBox resizable"); b.setAttribute("title", "Email Confirmation"); document.body.appendChild(b); $j("#emailConfirmation").dialog({ bgiframe: true, modal: true, autoOpen: false, width: 390, maxWidth: 390, minWidth: 390 }) } $j(".dialogBox:visible input").val(""); $j(".dialogBox:visible").dialog("close"); $j("#emailConfirmation").dialog("open"); followUpText = "<div id='showConfirmationEmail'> <p>"; followUpText += "<div style='padding-bottom:10px;'>You will receive an email with a link to activate your account.</div>"; followUpText += "Please confirm your email address:"; followUpText += "<strong style='display: block; font-size: 20px;'>" + a + "</strong>"; followUpText += "<a href='#' style='display: block; font-size: 11px; margin-bottom: 15px;' class='changeLink' onclick=\"$j('#emailConfirmation #showChangeEmail').show(); $j('#emailConfirmation #showConfirmationEmail').hide(); \">Change Email</a>"; followUpText += "</p> </div>"; followUpText += "<div id='showChangeEmail' style='display: none;'> <p>"; followUpText += "Please change your email address:"; followUpText += "<span id='confirmEmail'>"; followUpText += "<input type='text' style='display: block; margin: 5px 0pt 15px; font-size: 17px; width: 350px; padding: 2px 5px;' value='" + a + "' size='40' id='updatedEmailField' name='email'/>"; followUpText += "</span>"; followUpText += "</p> </div>"; followUpText += "<a class='s_button' style='float: left; clear: none;' onclick=\"Sawbuck.UserManager.updateUnconfirmedEmail($j('#updatedEmailField').val(), ('" + a + "' != $j('#updatedEmailField').val())); return false;\"><span class='s_button'>Confirm Email</span></a></div>"; $j("#emailConfirmation").html(followUpText) } function y(a, b) { if (a != b) return true; else return false } function x(a) { firstName = $j(a).find("input[name=first_name]").val(); lastName = $j(a).find("input[name=last_name]").val(); email = $j(a).find("input[name=email_address]").val(); email2 = email; pw = $j(a).find("input[name=password]").val(); pw2 = $j(a).find("input[name=confirm_password]").val(); agree = $j(a).find("input[name=terms_of_use]:checked").length == 1; email = Sawbuck.Utilities.trim(email); email2 = Sawbuck.Utilities.trim(email2); pw = Sawbuck.Utilities.trim(pw); pw2 = Sawbuck.Utilities.trim(pw2); if (Sawbuck.Utilities.trim(firstName).length < 2 || Sawbuck.Utilities.trim(lastName).length < 2) { u(a, "Must enter your first and last name") } else if (!k.test(email)) { u(a, "Not a valid email address") } else if (pw.length < 5) { u(a, "Password must be at least 5 characters long") } else if (pw != pw2) { u(a, "Passwords do not match") } else if (!agree) { u(a, 'Must click "I Agree to the Terms Of Use"') } else { data = { Email: email, Password: pw, Password1: pw2, FirstName: firstName, LastName: lastName, Url: window.location.toString() }; $j.ajax({ type: "POST", url: "/service/WebService.asmx/Register_2", data: Sawbuck.Utilities.toJson(data), contentType: "application/json; charset=utf-8", dataType: "json", processData: false, success: function (b) { var c = b.d.Msg; d = (b.d.Preferences & 1) == 1; e = b.d.Alerts; if (c === 1) s(email); else { switch (c) { case 0: u(a, "There was a problem completing your registration."); break; case -1: u(a, "The email address you entered is already in our system."); break; case -2: u(a, "You have already registered. Please sign in."); break; case -3: u(a, "Invalid registration data. Please try again."); break; case -4: u(a, "Your passwords did not match. Please try again."); break; case -5: A(email, true); break; default: s(email); break } } }, error: function () { u(a, "There was a problem completing your registration.") } }) } } function w(a) { data = { Email: a.email, FirstName: a.first_name, LastName: a.last_name, FacebookID: c, Password: "", Password1: "", Url: window.location.toString() }; $j.ajax({ type: "POST", url: "/service/WebService.asmx/RegisterTest", data: Sawbuck.Utilities.toJson(data), contentType: "application/json; charset=utf-8", dataType: "json", processData: false, success: function (a) { var b = a.d.Msg; d = (a.d.Preferences & 1) == 1; e = a.d.Alerts; if (b === 1) r(); else { switch (b) { case 0: u(form, "There was a problem completing your registration."); break; case -1: u(form, "The email address you entered is already in our system."); break; case -2: u(form, "You have already registered. Please sign in."); break; case -3: u(form, "Invalid registration data. Please try again."); break; case -4: u(form, "Your passwords did not match. Please try again."); break; case -5: A(email, true); break } } }, error: function () { u(form, "There was a problem completing your registration.") } }) } function v(a, b, c) { var d = $j("#updateInfoForm").children("form"); a = Sawbuck.Utilities.trim(a); b = Sawbuck.Utilities.trim(b); c = Sawbuck.Utilities.trim(c); if (!a || !b || !c) { u(d, "All fields are required"); return false } if (!k.test(c)) { u(d, "Not a valid email address"); return false } $j.ajax({ type: "POST", url: "/service/WebService.asmx/UpdateAccountInfo", data: Sawbuck.Utilities.toJson({ Email: c, FirstName: a, LastName: b }), contentType: "application/json; charset=utf-8", dataType: "json", processData: false, success: function (b) { if (b.d == true) { $j("#updateInfoForm").dialog("close"); $j("#plFname").text(a); $j("#plEmail").text(c); $j("#updateInfoSuccess").show(); setTimeout(function () { $j("#updateInfoSuccess").fadeOut("slow") }, m); window.location.href = "http://" + window.location.host + window.location.pathname } else { u(d, "The email address you entered is already in use.") } }, error: function () { } }) } function u(a, b) { var c = $j(a).find(".error_warning")[0]; $j(c).text(b); $j(c).show() } function t(a) { if (!a) a = g; $j.ajax({ type: "POST", url: "/service/WebService.asmx/ResendVerificationLetter", data: Sawbuck.Utilities.toJson({ Url: window.location.toString() }), contentType: "application/json; charset=utf-8", dataType: "json", processData: false, success: function (b) { if (a) alert("Your confirmation email has been re-sent to " + a + "."); else alert("Your confirmation email has been re-sent.") }, error: function () { } }) } function s(a) { for (var c in l["onRegister"]) { l["onRegister"][c]({ userID: b }) } A(a) } function r() { q(); p(); n(); a = true; for (var c in l["onLogin"]) { l["onLogin"][c]({ userID: b }) } $j("#signInWindow").dialog("close"); $j("#registrationWindow").dialog("close") } function q() { $j(".registerLink").hide(); $j(".signInLink").hide(); $j(".logoutLink").show(); $j(".userStatus .loggedIn").show(); $j(".userStatus .loggedOut").hide(); $j(".userStatus .name").text(i + " " + j); if (c) $j(".navBar .userStatus label").before('<img style="" class="facebookProfilePic" src="http://graph.facebook.com/' + c + '/picture" align="absmiddle" width="31" height="31" />') } function p() { $j(".rssLink").each(function () { this.href = this.href.replace(/\/rss/, "/rss/" + b) }) } function o() { for (var a in l) { if (a == "onlogout" || a == "onLogout") { l[a]() } } window.location = "/logout/" } function n() { if (cookie = Sawbuck.Utilities.readCookie("User")) { b = cookie.substring("UserID=".length, cookie.length) } } var a = false; var b, c = null; var d = false; var e = 2; var f = 0; var g; var h = false; var i = "", j = ""; var k = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/; var l = {}; var m = 5e3; n(); try { $j(".registrationForm").keyup(function (a) { if (window.event && event.keyCode && event.keyCode == 13) { a.preventDefault(); a.stopImmediatePropagation(); a.stopPropagation(); x(this); return false } else if (a.which == 13) { x(this); a.preventDefault(); a.stopImmediatePropagation(); a.stopPropagation(); return false } }); $j(".signInForm").keyup(function (a) { if (window.event && event.keyCode && event.keyCode == 13) { F(this); a.preventDefault(); a.stopImmediatePropagation(); a.stopPropagation(); return false } else if (a.which == 13) { F(this); a.preventDefault(); a.stopImmediatePropagation(); a.stopPropagation(); return false } }) } catch (L) { console.log(L) } return { init: function (c) { b = c.userID || b; f = c.partnerID || f; a = c.loggedIn || a; d = c.emailAlertsOn || d; e = c.emailAlertsFrequency || e; g = c.email || g; h = c.pending || h; if (a) p() }, addListener: function (a, b) { l[a] = l[a] || []; l[a].push(b) }, isLoggedIn: function () { return a }, alertsOn: function () { return d }, getAlertsFrequency: function () { return e }, logout: function () { Sawbuck.Utilities.deleteCookie("User"); d = false; a = false; b = null; if (c) { try { FB.logout(o) } catch (e) { o() } } else o() }, facebookRegister: w, register: x, resendConfirmationEmail: t, signIn: F, signInWithFacebook: function () { FB.login(C, { scope: "email,publish_stream" }) }, connectToFacebook: function () { FB.login(D) }, detachFacebook: E, handleFBStatus: function (b) { if (b.authResponse && !c) { c = parseInt(b.authResponse.userID); if (!a) C(b) } }, updateInfo: function (a, b, c) { v(a, b, c) }, displayConfirmationEmail: z, displayConfirmationText: A, updateUnconfirmedEmail: function (a, b) { B(a, b) }, changePassword: function (a, b, c) { H(a, b, c) }, addUser: G, deleteAccount: I, forgotPassword: function (a) { J(a) }, showForgotPassword: function () { $j(".dialogBox").dialog("close"); $j("#forgotPasswordWindow").dialog("open") }, showRegistrationDialog: function (b) { b = b === true ? 1 : b; if (g && h) { A(g, true) } else if (!a && !h) { $j("#registrationWindow .mlsReason1, #registrationWindow .mlsReason2").hide(); $j("#registrationWindow").dialog("open"); switch (b) { case 1: $j("#registrationWindow .mlsReason1").show(); break; case 2: $j("#registrationWindow .mlsReason2").show(); break; case 3: $j("#registrationWindow .mlsReason3").show(); break; default: break } } return false }, showSignInDialog: function () { if (g) { A(g, true) } else if (!a) $j("#signInWindow").dialog("open"); return false }, modo: function (b) { if (!a) $j("#" + b).dialog("open"); return false }, getFBUserID: function () { return c }, getUserID: function () { return b }, getPartnerID: function () { return f }, emailAlertsOn: function (a) { d = true; e = a }, emailAlertsOff: function (a) { d = false; e = 2 }, markMessageRead: K} } (); if (Sawbuck.Deferred && Sawbuck.Deferred.UserManager) Sawbuck.Deferred.UserManager.resolve()
