var background=chrome.extension.getBackgroundPage(),setting=background.setting,updateSession=background.updateSession;function toggleRule(a){var b=a.data.line,c=b.attr("row"),c=setting.order[c];"default"==c.position&&("enabled"==c.status?(c.status="disabled",trackDisable(c.identifier)):"disabled"==c.status&&(c.status="enabled",trackEnable(c.identifier)));b.blur();a.data.list.finishEdit(b);a.data.list.updateLine(b);save()}
var settingProps=[{header:"",property:"status",type:"button",caption:"",events:{command:toggleRule,update:setStatus,createNew:setStatusNew}},{header:$$("title"),property:"title",type:"input"},{header:$$("mode"),property:"type",type:"select",option:"static",options:[{value:"wild",text:$$("WildChar")},{value:"regex",text:$$("RegEx")},{value:"clsid",text:$$("CLSID")}]},{header:$$("pattern"),property:"value",type:"input"},{header:$$("user_agent"),property:"userAgent",type:"select",option:"static",options:[{value:"",
text:"Chrome"},{value:"ie9",text:"MSIE9"},{value:"ie8",text:"MSIE8"},{value:"ie7",text:"MSIE7"},{value:"ff7win",text:"Firefox 7"},{value:"ip5",text:"iPhone"},{value:"ipad5",text:"iPad"}]},{header:$$("helper_script"),property:"script",type:"input"}],table,dirty=!1;function save(){dirty=!0}function doSave(){dirty&&(dirty=!1,setting.update())}
function setReadonly(a){var a=a.data.line,b=a.attr("row");0>b||(b=setting.order[b],a=$(".listvalue",a),"custom"!=b.position?a.addClass("readonly"):a.removeClass("readonly"))}$(window).blur(doSave);function refresh(){table.refresh()}
$(document).ready(function(){table=new List({props:settingProps,main:$("#tbSetting"),lineEvents:{update:setReadonly},getItems:function(){return setting.order},getItemProp:function(a,b){return b in setting.order[a]?setting.order[a][b]:setting.getItem(setting.order[a])[b]},setItemProp:function(a,b,c){b in setting.order[a]?setting.order[a][b]=c:setting.getItem(setting.order[a])[b]=c},defaultValue:setting.createRule(),count:function(){return setting.order.length},insert:function(a,b){setting.addCustomRule(b);
this.move(setting.order.length-1,a)},remove:function(a){if("custom"!=setting.order[a].position)return!0;delete setting.rules[setting.order[a].identifier];setting.order.splice(a,1)},validate:function(a,b){return setting.validateRule(b)}});$(table).bind("updated",save);$("#addRule").bind("click",function(){table.editNewLine()});$(table).bind("select",function(){var a=table.selectedLine;0>a?($("#moveUp").attr("disabled","disabled"),$("#moveDown").attr("disabled","disabled"),$("#deleteRule").attr("disabled",
"disabled")):(0!=a?$("#moveUp").removeAttr("disabled"):$("#moveUp").attr("disabled","disabled"),a!=setting.order.length-1?$("#moveDown").removeAttr("disabled"):$("#moveDown").attr("disabled","disabled"),"custom"!=setting.order[a].position?$("#deleteRule").attr("disabled","disabled"):$("#deleteRule").removeAttr("disabled"))});$("#moveUp").click(function(){var a=table.selectedLine;table.move(a,a-1,!0)});$("#moveDown").click(function(){var a=table.selectedLine;table.move(a,a+1,!0)});$("#deleteRule").click(function(){table.remove(table.selectedLine)});
table.init();updateSession.bind("update",refresh)});window.onbeforeunload=function(){updateSession.unbind("update",refresh)};function setStatusNew(a){with(a.data)s="Custom",color="#33f",$("button",line).text(s).css("background-color",color)}
function setStatus(a){with(a.data){a=line.attr("row");a=setting.order[a];setting.getItem(a);var b;"enabled"==a.status?(a=$$("Enabled"),b="#0A0"):"disabled"==a.status?(a=$$("Disabled"),b="indianred"):(a=$$("Custom"),b="#33f");$("button",line).text(a).css("background-color",b)}}
function showTime(a){if(0==a)return"Never";a=Date.now()-a;if(0>a)return"Never";a/=1E3;60>a?a=[a,"second"]:(a/=60,60>a?a=[a,"minute"]:(a/=60,a=60>a?[a,"hour"]:[a/24,"day"]));var b=Math.floor(a[0]);return b+" "+a[1]+(1!=b?"s":"")+" ago"}$(document).ready(function(){$("#log_enable").change(function(a){setting.misc.logEnabled=a.target.checked;save()})[0].checked=setting.misc.logEnabled;$("#tracking").change(function(a){setting.misc.tracking=a.target.checked;save()})[0].checked=setting.misc.tracking});
$(document).ready(function(){var a="http://code.google.com/p/np-activex/wiki/ExtensionHelp?wl=",a=a+$$("wikicode");$(".help").each(function(){this.href=a})});$(window).load(function(){background.firstUpgrade&&(background.firstUpgrade=!1,alert($$("upgrade_show")))});
