var debug=false,step=0,sections=["welcome","discover","wireless","secure","finish"],wizform;
$(function(){wizform=$("#WizardForm");if(debug){wizform.find("input[name=corp-ssid]").val("Corporate");wizform.find("input[name=corp-passphrase]").val("testtest");wizform.find("input[name=admin-name]").val("admin");wizform.find("input[name=admin-pass1]").val("admin");wizform.find("input[name=admin-pass2]").val("admin")}showSection("welcome");wizform.find("input.ui-button").button();wizform.find("input[name=nextButton]").click(function(){next();return false});wizform.find("input[name=backButton]").click(function(){back()});
wizform.find("select[name=lang]").focus().val(currentLocale).change(function(){location.href="/wizard.jsp?lang="+wizform.find("select[name=lang]").val()}).keypress(function(b){b.which==13&&next()});wizform.find(".restore-button").click(function(){$("#BackupFile, #BackupFile-confirm").setvisible(true);return false});$("#BackupFile").jupload().bind("jupload_uploaded",function(b,c){$("#BackupFile-confirm .confirm-text").text(V.localizeMsg(Msg.I_ConfirmRestore,c))});wizform.find('input[name="confirm"]').click(function(){location.href=
"/op/restore"});wizform.find('input[name="cancel"]').click(function(){$("#BackupFile").jupload("cancel")});wizform.find("input[name=refreshButton]").click(function(){$("#discovered").jtable("refresh")});wizform.find("input[name=do-guest]").change(function(){$(".enable-guest-access").toggle(wizform.find("input[name=do-guest]").is(":checked"))});wizform.find("input[name=finishButton]").click(commit);var a=wizform.find("select[name=countryCode]");$.jpost("/stat/sysinfo",{},function(b){$.each(b.data[0].ccodes,
function(c,d){$("<option></option>").val(d.code).text(d.name).appendTo(a)});a.val("840")});$.jpost("/list/wlangroup",{name:"Default"},function(b){wizform.data("wlangroup_id",b.data[0]._id)});$("#discovered").jtable({url:"/stat/device",params:{state:2,"default":true},selectable:"true",hidetoolbar:true,pagesize:7}).jtable("addcol",Msg.MACAddress,"mac").jtable("addcol",Msg.IPAddress,"ip").jtable("addcol",Msg.Version,"version").jtable("addcol",Msg.Uptime,"uptime",true,Renderer.uptime).bind("jtable_locate",
function(b,c){$.jcmd.locate_ap(c)}).bind("jtable_refresh-done",function(b,c){c.selectall()}).jtable("addfilter","default",true).jtable("refresh")});function next(){if(verifySection(sections[step])){step++;showSection(sections[step])}}function back(){step--;showSection(sections[step])}
function verifySection(a){if(a=="wireless"){if(!V.checkEmpty(wizform.find("input[name=corp-ssid]"),"Secure SSID")||!V.checkSsid(wizform.find("input[name=corp-ssid]"),"Secure SSID"))return false;if(!V.checkEmpty(wizform.find("input[name=corp-passphrase]"),"Security Key")||!V.checkPassphrase(wizform.find("input[name=corp-passphrase]"),"Security Key"))return false;if(wizform.find("input[name=do-guest]").is(":checked"))if(!V.checkEmpty(wizform.find("input[name=guest-ssid]"),"Guest SSID")||!V.checkSsid(wizform.find("input[name=guest-ssid]"),
"Guest SSID"))return false}else if(a=="secure"){if(!V.checkEmpty(wizform.find("input[name=admin-name]"),"Admin Name")||!V.checkAdminName(wizform.find("input[name=admin-name]"),"Admin Name"))return false;if(!V.checkAdminPasswords(wizform.find("input[name=admin-pass1]"),wizform.find("input[name=admin-pass2]"),"Admin Password","Confirm"))return false}return true}
function showSection(a){$("div.section-content").hide();$("ul.wizard-navigation li").removeClass("active");$("#WizardForm").data("section",a);wizform.find("input[name=backButton]").setvisible(a!="welcome");wizform.find("input[name=nextButton]").setvisible(a!="finish");wizform.find("input[name=refreshButton]").setvisible(a=="discover");wizform.find("input[name=finishButton]").setvisible(a=="finish");switch(a){case "welcome":$("#Indicator").animate({marginLeft:"0"},250);$("#WelcomeTab").addClass("active");
$("#WelcomeContent").show();break;case "discover":$("#Indicator").animate({marginLeft:"20%"},250);$("#DiscoverTab").addClass("active");$("#DiscoverContent").show();break;case "wireless":$("#Indicator").animate({marginLeft:"40%"},250);$("#WirelessTab").addClass("active");$("#WirelessContent").show();wizform.find("input[name=corp-ssid]").select().focus();break;case "secure":$("#Indicator").animate({marginLeft:"60%"},250);$("#SecureTab").addClass("active");$("#SecureContent").show();wizform.find("input[name=admin-name]").select().focus();
break;case "finish":$("#WizardSummary").empty();$("#WizardSummary").append($("<dt></dt>").text("Secure SSID"));$("#WizardSummary").append($("<dd></dd>").text(wizform.find("input[name=corp-ssid]").val()));if(wizform.find("input[name=do-guest]").attr("checked")){$("#WizardSummary").append($("<dt></dt>").text("Guest SSID"));$("#WizardSummary").append($("<dd></dd>").text(wizform.find("input[name=guest-ssid]").val()))}$("#WizardSummary").append($("<dt></dt>").text("Admin Name"));$("#WizardSummary").append($("<dd></dd>").text(wizform.find("input[name=admin-name]").val()));
$("#confirm-corp-ssid").text($("#corp-ssid").val());$("#confirm-guest-ssid").text($("#guest-ssid").val());$("#confirm-do-guest").toggle($("#do-guest").is(":checked"));$("#confirm-admin-name").text($("#admin-name").val());$("#Indicator").animate({marginLeft:"80%"},250);$("#FinishTab").addClass("active");$("#FinishContent").show();break}}function commit(){$("div.modal").show();commit_admin()}
function commit_admin(){$.jcmd("sitemgr","add-default-admin",{name:wizform.find("input[name=admin-name]").val(),lang:wizform.find("select[name=lang]").val(),x_password:wizform.find("input[name=admin-pass1]").val()},commit_corp)}function commit_corp(){$.jpost("/add/wlanconf",{wlangroup_id:wizform.data("wlangroup_id"),enabled:true,name:wizform.find("input[name=corp-ssid]").val(),security:"wpapsk",x_passphrase:wizform.find("input[name=corp-passphrase]").val()},commit_guest)}
function commit_guest(){wizform.find("input[name=do-guest]").is(":checked")?$.jpost("/add/wlanconf",{name:wizform.find("input[name=guest-ssid]").val(),wlangroup_id:wizform.data("wlangroup_id"),enabled:true,is_guest:true,security:"open"},commit_adopted):commit_adopted()}function commit_adopted(){var a=[];$("#discovered").jtable("getselected").each(function(){a.push($(this).attr("mac"))});$.jcmd("devmgr","adopt",{macs:a},commit_system)}
function commit_system(){$.jpost("/set/setting/country",{code:wizform.find('select[name="countryCode"]').val()},commit_last)}function commit_last(){$.jcmd("system","set-installed",{},function(){location.href="/login"})};
