function PinManager(){}
PinManager.EnablePasswordSync=function(a,e){function g(c){if(c.error){$(a).html(c.error+" Disabling password synchronization.");$(a).dialog("option","buttons",{Ok:function(){$(this).dialog("close")}})}else if(!c.nodes||!c.nodes.ROOT||!c.nodes.ROOT.data){b.Xmarks.LogWrite("Enable passwords case 3");PinManager.CreatePin(a,e)}else{b.Xmarks.LogWrite("Enable passwords case 4");h(c.nodes.ROOT.data)}}function f(){$(a).html('This browser already has Xmarks encrypted passwords.  Please verify your password PIN to access your existing passwords: <br /><div style="margin: 1em"><input type="password" id="password-pin" onkeydown="document.getElementById(\'password-pin-fail\').style.display = \'none\';"/> <br /><input style="margin-left: 1em" type="checkbox" id="pin-remember" checked="checked"> Remember PIN</div><div style="color: red; font-style: italic; display: none" id="password-pin-fail">Invalid PIN, please try again.</div>');$(a).dialog("option",
"buttons",{"I forgot my PIN":d,Confirm:function(){i(b.PasswordStore.DoesPinUnlockLocalData,b.PasswordStore)}});$(a).dialog("open");document.getElementById("password-pin").addEventListener("keyup",function(c){c.keyCode==13&&i(b.PasswordStore.DoesPinUnlockLocalData,b.PasswordStore)});document.getElementById("password-pin").focus()}function h(c){$(a).html('Please verify your password PIN to access your Xmarks passwords: <br /><div style="margin: 1em"><input type="password" id="password-pin" onkeydown="document.getElementById(\'password-pin-fail\').style.display = \'none\';"/> <br /><input style="margin-left: 1em" type="checkbox" id="pin-remember" checked="checked"> Remember PIN</div><div style="color: red; font-style: italic; display: none" id="password-pin-fail">Invalid PIN, please try again.</div>');
$(a).dialog("option","buttons",{"I forgot my PIN":d,Confirm:function(){i(b.PasswordStore.VerifyPinData,b.PasswordStore,c)}});$(a).dialog("open");document.getElementById("password-pin").addEventListener("keyup",function(j){j.keyCode==13&&i(b.PasswordStore.VerifyPinData,b.PasswordStore,c)});document.getElementById("password-pin").focus()}function i(c,j,k){if(c.call(j,document.getElementById("password-pin").value,k)){b.TurnOnPasswordSync(document.getElementById("password-pin").value,document.getElementById("pin-remember").checked);
$(a).dialog("close");e&&e()}else{document.getElementById("password-pin-fail").style.display="block";document.getElementById("password-pin").value="";document.getElementById("password-pin").focus()}}function d(){$(a).html("Unfortunately we cannot recover your PIN or your access your Xmarks passwords.  You can either reset your PIN and clear all of your password data or cancel and disable password sync for this computer.");$(a).dialog("option","buttons",{Cancel:function(){$(this).dialog("close")},"Reset PIN":function(){PinManager.ResetPin(a,
e)}});$(a).dialog("open")}$(a).html("Initializing password synchronization.");$(a).dialog("option","buttons",{});$(a).dialog("open");var b=chrome.extension.getBackgroundPage();b.AuthenticateUser(function(){var c=b.Xmarks.Settings.GetUserSettings();if(c.username)if(c.passwordsrevision)if(b.Xmarks.Settings.Get(b.Xmarks.Settings.GetUserHash()+"password-pin")){b.Xmarks.LogWrite("Enable passwords case 1");b.TurnOnPasswordSync(b.Base64.decode(b.Xmarks.Settings.Get(b.Xmarks.Settings.GetUserHash()+"password-pin")),
true);$(a).dialog("close");e()}else{b.Xmarks.LogWrite("Enable passwords case 2");f()}else b.GetPasswordState(g);else{$(a).html("User authentication canceled, turning off password sync.");$(a).dialog("option","buttons",{Ok:function(){$(this).dialog("close")}});$(a).dialog("open")}})};
PinManager.VerifyCurrentPin=function(a,e){function g(){if(f.Xmarks.Settings.Get(f.Xmarks.Settings.GetUserHash()+"password-pin")!=f.Base64.encode(document.getElementById("password-pin").value)){document.getElementById("password-pin-fail").style.display="block";document.getElementById("password-pin").value="";document.getElementById("password-pin").focus()}else{$(a).dialog("close");e()}}var f=chrome.extension.getBackgroundPage();if(f.Xmarks.Settings.Get("sync-type-passwords","false")=="false"){$(a).html("Password sync is currently disabled.  You must enable password sync first.");
$(a).dialog("option","buttons",{Ok:function(){$(this).dialog("close")}});$(a).dialog("open")}else{$(a).html('Please verify your password PIN: <br /><input style="margin: 1em" type="password" id="password-pin" onkeydown="document.getElementById(\'password-pin-fail\').style.display = \'none\';"/> <br /><div style="color: red; font-style: italic; display: none" id="password-pin-fail">Invalid PIN, please try again.</div>');$(a).dialog("option","buttons",{Confirm:g});$(a).dialog("open");document.getElementById("password-pin").addEventListener("keyup",
function(h){h.keyCode==13&&g()});document.getElementById("password-pin").focus()}};PinManager.ResetPin=function(a,e){$(a).html("<strong>Are you sure you want to reset your PIN?</strong> This will erase all of your current Xmarks password data.");$(a).dialog("option","buttons",{Cancel:function(){$(this).dialog("close")},"Reset PIN":function(){PinManager.CreatePin(a,e)}});$(a).dialog("open")};
PinManager.CreatePin=function(a,e){function g(){var d=null;if(document.getElementById("password-pin1").value!=document.getElementById("password-pin2").value)d="The PINs you entered do not match.";else if(document.getElementById("password-pin1").value.length<4)d="The PIN is too short, it must be at least 4 characters long.";else if(document.getElementById("password-pin1").value.length>255)d="The PIN is too long, it must be no more than 255 characters long.";if(d){$(a).html("<div><strong>PIN Error</strong>: "+
d+"</div>"+h);document.getElementById("password-pin1").focus()}else{chrome.extension.getBackgroundPage().TurnOnPasswordSync(document.getElementById("password-pin1").value,document.getElementById("pin-remember").checked);$(a).html("Your PIN was successfully created.  We will use this PIN to secure your passwords before we sync them so that only you can ever access them.  <strong>Do not lose this PIN</strong>, Xmarks cannot help you retrieve it.");$(a).dialog("option","buttons",{Close:f});$(a).dialog("open")}}
function f(){$(this).dialog("close");chrome.extension.getBackgroundPage().HandleAction("upload",{dataType:"passwords"});e&&e()}var h='<div style="margin: 1em 1em 0 1em; white-space: nowrap;" oninput="PinManager.PinStrength(\'password-pin1\', \'password-strength\')">New PIN: <input type="password" id="password-pin1"/></div><div style="margin: 0 1em 0.25em 1em; white-space: nowrap;">Confirm: <input type="password" id="password-pin2"/><br /><input type="checkbox" id="pin-remember" checked="checked"> Remember PIN</div><div id="password-strength" style="text-align: center; font-size: 10pt"></div>',
i;$(a).html("<div>Xmarks secures your passwords by encrypting them with a prive PIN of your choosing.  It's important that you remember this PIN because we cannot retrieve it for you.  Your PIN can be any combination of letters, numbers and symbols.</div>"+h);$(a).dialog("option","buttons",{"Create PIN":g});$(a).dialog("open");document.getElementById("password-pin1").addEventListener("keyup",function(d){d.keyCode==13&&g()});document.getElementById("password-pin2").addEventListener("keyup",function(d){d.keyCode==
13&&g()});document.getElementById("password-pin1").focus()};PinManager.pinInputTimer=null;
PinManager.PinStrength=function(a,e){if(PinManager.pinInputTimer){window.clearTimeout(PinManager.pinInputTimer);PinManager.pinInputTimer=null}PinManager.pinInputTimer=window.setTimeout(function(){var g=document.getElementById(a).value,f=TestPassword(g),h="Strong",i="#2A911B",d=f*5;if(g.length<4){h="Too short";i="#333333";d=0}else if(f<17){h="Weak";i="#57040F"}else if(f<24){h="Good";i="#ED9D2B"}else if(f>40)d=200;document.getElementById(e).innerHTML="PIN strength: "+h+'<div style="text-align: center; border: 1px solid #ccc; width: 200px; margin-top: 5px; margin: auto; padding: 1px; background: white;"><div style="background-color: '+
i+"; height: 10px; width: "+d+'px"></div></div>'},300)};
