$(document).ready(function(){if(localStorage.reset&&localStorage.reset=="true"){showTip("Options Reseted");localStorage.removeItem("reset")}buildSelect();restoreOptions();bindSelect();bindActionPanel()});function buildSelect(){for(var a=["V","S","E"],b=$('<select disabled="disabled"></select>'),c=48;c<91;c++)if(!(c>57&&c<65)){var d=String.fromCharCode(c);$("<option></option>").attr({value:d}).text(d).appendTo(b)}b.appendTo($(".select")).each(function(e){this.value=a[e]})}
function bindSelect(){$("#shortcuts_table").click(function(a){var b=a.target;a=$(b).parent().siblings("td");b.tagName=="SELECT"&&$("input",a).attr("checked")&&$("select",$("#menu_shortcuts")).not(b).each(function(){$("option[disabled]",$(this)).removeAttr("disabled");$("option[value="+this.value+"]",$(b)).attr({disabled:"disabled"})});if(b.type=="checkbox"){a=$("select",a);$(b).attr("checked")?a.removeAttr("disabled"):a.attr({disabled:"disabled"})}})}
function bindActionPanel(){$("#action_panel").click(function(a){if(a.target.tagName=="INPUT")switch(a.target.value){case "Reset":localStorage.clear();localStorage.reset=true;location.href=location.href;break;case "Save":if(checkDuplicateKeys()){$("#tip").addClass("error");showTip("Shortcut Keys Conflict");return}saveOptions();$("#tip").removeClass("error");showTip("Options Saved");break;case "Close":chrome.extension.sendRequest({action:"exit"});break}})}
function saveOptions(){localStorage.format=$('input[name="format"]:checked').attr("id");var a={};$("input:checkbox",$("#menu_shortcuts")).each(function(){var b=this.id,c=this.checked,d=$("select",$(this).parent().siblings("td.select")).attr("value");a[""+b]={enable:c,key:d}});localStorage.msObj=JSON.stringify(a);chrome.extension.sendRequest({action:"update_shortcuts"})}
function restoreOptions(){localStorage.format&&$("#"+localStorage.format).attr({checked:"checked"}).siblings("input:checked").removeAttr("checked");if(msObj=localStorage.msObj){msObj=JSON.parse(msObj);for(var a in msObj){var b=msObj[a],c=$("#"+a),d=$("select",c.parent().siblings("td.select"));if(b.enable){c.attr({checked:"checked"});d.removeAttr("disabled")}d.attr({value:b.key})}}}
function checkDuplicateKeys(){var a="",b=0;$("select",$("td.select")).each(function(){var c=this.value;a+=c;if(a.match(RegExp(c,"gi")).length>1)b=1});return b}function showTip(a){$("#tip").slideDown("fast").delay(2E3).fadeOut("slow").find("span").text(a)};
