(function(a){a.fn.editable=function(c,e){if("disable"==c)a(this).data("disabled.editable",true);else if("enable"==c)a(this).data("disabled.editable",false);else if("destroy"==c)a(this).unbind(a(this).data("event.editable")).removeData("disabled.editable").removeData("event.editable");else{var b=a.extend({},a.fn.editable.defaults,{target:c},e),g=a.editable.types[b.type].plugin||function(){},i=a.editable.types[b.type].submit||function(){},s=a.editable.types[b.type].buttons||a.editable.types.defaults.buttons,
q=a.editable.types[b.type].content||a.editable.types.defaults.content,t=a.editable.types[b.type].element||a.editable.types.defaults.element,o=a.editable.types[b.type].reset||a.editable.types.defaults.reset,r=b.callback||function(){},u=b.onedit||function(){},v=b.onsubmit||function(){},w=b.onreset||function(){},x=b.onerror||o;b.tooltip&&a(this).attr("title",b.tooltip);b.autowidth="auto"==b.width;b.autoheight="auto"==b.height;return this.each(function(){var d=this,y=a(d).width(),z=a(d).height();a(this).data("event.editable",
b.event);a.trim(a(this).html())||a(this).html(b.placeholder);a(this).bind(b.event,function(k){if(true!==a(this).data("disabled.editable"))if(!d.editing)if(false!==u.apply(this,[b,d])){k.preventDefault();k.stopPropagation();b.tooltip&&a(d).removeAttr("title");if(0==a(d).width()){b.width=y;b.height=z}else{if(b.width!="none")b.width=b.autowidth?a(d).width():b.width;if(b.height!="none")b.height=b.autoheight?a(d).height():b.height}a(this).html().toLowerCase().replace(/(;|")/g,"")==b.placeholder.toLowerCase().replace(/(;|")/g,
"")&&a(this).html("");d.editing=true;d.revert=a(d).html();a(d).html("");var f=a("<form />");if(b.cssclass)"inherit"==b.cssclass?f.attr("class",a(d).attr("class")):f.attr("class",b.cssclass);if(b.style)if("inherit"==b.style){f.attr("style",a(d).attr("style"));f.css("display",a(d).css("display"))}else f.attr("style",b.style);var j=t.apply(f,[b,d]),l;if(b.loadurl){var m=setTimeout(function(){j.disabled=true;q.apply(f,[b.loadtext,b,d])},100);k={};k[b.id]=d.id;a.isFunction(b.loaddata)?a.extend(k,b.loaddata.apply(d,
[d.revert,b])):a.extend(k,b.loaddata);a.ajax({type:b.loadtype,url:b.loadurl,data:k,async:false,success:function(h){window.clearTimeout(m);l=h;j.disabled=false}})}else if(b.data){l=b.data;if(a.isFunction(b.data))l=b.data.apply(d,[d.revert,b])}else l=d.revert;q.apply(f,[l,b,d]);j.attr("name",b.name);s.apply(f,[b,d]);a(d).append(f);g.apply(f,[b,d]);a(":input:visible:enabled:first",f).focus();b.select&&j.select();j.keydown(function(h){if(h.keyCode==27){h.preventDefault();o.apply(f,[b,d])}});if("cancel"==
b.onblur)j.blur(function(){m=setTimeout(function(){o.apply(f,[b,d])},500)});else if("submit"==b.onblur)j.blur(function(){m=setTimeout(function(){f.submit()},200)});else a.isFunction(b.onblur)?j.blur(function(){b.onblur.apply(d,[j.val(),b])}):j.blur(function(){});f.submit(function(h){m&&clearTimeout(m);h.preventDefault();if(false!==v.apply(f,[b,d]))if(false!==i.apply(f,[b,d]))if(a.isFunction(b.target)){h=b.target.apply(d,[j.val(),b]);a(d).html(h);d.editing=false;r.apply(d,[d.innerHTML,b]);a.trim(a(d).html())||
a(d).html(b.placeholder)}else{h={};h[b.name]=j.val();h[b.id]=d.id;a.isFunction(b.submitdata)?a.extend(h,b.submitdata.apply(d,[d.revert,b])):a.extend(h,b.submitdata);if("PUT"==b.method)h._method="put";a(d).html(b.indicator);var p={type:"POST",data:h,dataType:"html",url:b.target,success:function(n){p.dataType=="html"&&a(d).html(n);d.editing=false;r.apply(d,[n,b]);a.trim(a(d).html())||a(d).html(b.placeholder)},error:function(n){x.apply(f,[b,d,n])}};a.extend(p,b.ajaxoptions);a.ajax(p)}a(d).attr("title",
b.tooltip);return false})}});this.reset=function(k){if(this.editing)if(false!==w.apply(k,[b,d])){a(d).html(d.revert);d.editing=false;a.trim(a(d).html())||a(d).html(b.placeholder);b.tooltip&&a(d).attr("title",b.tooltip)}}})}};a.editable={types:{defaults:{element:function(){var c=a('<input type="hidden"></input>');a(this).append(c);return c},content:function(c){a(":input:first",this).val(c)},reset:function(c,e){e.reset(this)},buttons:function(c,e){var b=this;if(c.submit){if(c.submit.match(/>$/))var g=
a(c.submit).click(function(){g.attr("type")!="submit"&&b.submit()});else{g=a('<button type="submit" />');g.html(c.submit)}a(this).append(g)}if(c.cancel){if(c.cancel.match(/>$/))var i=a(c.cancel);else{i=a('<button type="cancel" />');i.html(c.cancel)}a(this).append(i);a(i).click(function(){(a.isFunction(a.editable.types[c.type].reset)?a.editable.types[c.type].reset:a.editable.types.defaults.reset).apply(b,[c,e]);return false})}}},text:{element:function(c){var e=a("<input />");c.width!="none"&&e.width(c.width);
c.height!="none"&&e.height(c.height);e.attr("autocomplete","off");a(this).append(e);return e}},textarea:{element:function(c){var e=a("<textarea />");if(c.rows)e.attr("rows",c.rows);else c.height!="none"&&e.height(c.height);if(c.cols)e.attr("cols",c.cols);else c.width!="none"&&e.width(c.width);a(this).append(e);return e}},select:{element:function(){var c=a("<select />");a(this).append(c);return c},content:function(c,e,b){if(String==c.constructor)eval("var json = "+c);else var g=c;for(var i in g)if(g.hasOwnProperty(i))if("selected"!=
i){c=a("<option />").val(i).append(g[i]);a("select",this).append(c)}a("select",this).children().each(function(){if(a(this).val()==g.selected||a(this).text()==a.trim(b.revert))a(this).attr("selected","selected")})}}},addInputType:function(c,e){a.editable.types[c]=e}};a.fn.editable.defaults={name:"value",id:"id",type:"text",width:"auto",height:"auto",event:"click.editable",onblur:"cancel",loadtype:"GET",loadtext:"Loading...",placeholder:"Click to edit",loaddata:{},submitdata:{},ajaxoptions:{}}})(jQuery);
var defaultPageUrl="dashboard";$(document).ready(function(){var a=window.location.pathname;if(window.location.pathname=="/")a=defaultPageUrl;a=a.split("/");if(typeof a[1]=="string"){var c=a[1].toLowerCase().replace(/-/g," "),e="";if(a[2]!=undefined&&c!="reset password")e=a[2].toLowerCase().replace(/-/g," ");a="";c=(c+" "+e).split(" ");for(e=0;e<c.length;e++)a+=c[e].substr(0,1).toUpperCase()+c[e].substr(1);a="init"+a;window[a]!=undefined&&window[a]()}});
function initDialplan(){$("ul.country li input[type=checkbox]").each(function(){$(this).parent().parent().find("input[type=checkbox]").length==$(this).parent().parent().find("input:checked").length&&$(this).parent().parent().parent().find("> input[type=checkbox]").attr("checked","checked")})}
function dialplanToggle(a,c){if(a.checked==false){$("."+c).find("input[type=checkbox]").removeAttr("checked");$("."+c).parent().parent().parent().find("> input[type=checkbox]").attr("checked")&&$("."+c).parent().parent().parent().find("> input[type=checkbox]").removeAttr("checked")}else{$("."+c).find("input[type=checkbox]").attr("checked","checked");$("."+c).parent().parent().find("input[type=checkbox]").length==$("."+c).parent().parent().find("input:checked").length&&$("."+c).parent().parent().parent().find("> input[type=checkbox]").attr("checked",
"checked")}$("#verification").val().length>0&&validateDialplan()}var dialplanTimeout;
function validateDialplan(a){clearTimeout(dialplanTimeout);if(a==undefined)dialplanTimeout=setTimeout("validateDialplan(true)",400);else if(a==true)if($("#verification").val().length<10){$("#verificationStatus").attr("class","error");$("#verificationStatus").attr("alt","Error");$("#verificationStatusText").html("Phone number must be at least 10 digits long.")}else{$("#verificationStatusText").html("");$("#verificationStatus").attr("class","processing");$("#verificationStatus").attr("alt","Processing...");
for(var c=a="",e=$("form input[type=text],input[type=checkbox]:checked"),b={},g=0;g<e.length;g++){id=$(e[g]).attr("id");a=$(e[g]).attr("name");if(a!=null&&a.match(/Country/)||a.match(/Verification/)){c=$(e[g]).attr("value");if(c==null)c="";b[a]=c}}$.post("/konnect-internet-call-out/manage-calling-areas/verify_dialplan.json",b,function(i){if(i.result==true){$("#verificationStatus").attr("class","allowed");$("#verificationStatus").attr("alt","Allowed")}else{$("#verificationStatus").attr("class","not-allowed");
$("#verificationStatus").attr("alt","Not Allowed")}},"json")}}
function initUsersAccess(){$("ul.settings input.location").click(function(){$(this).attr("checked")?$(this).parent().parent().find("input.device").attr("checked","checked").attr("disabled","disabled"):$(this).parent().parent().find("input.device").removeAttr("checked").removeAttr("disabled")});$("ul.settings input.device").click(function(){if($(this).parent().parent().parent().find("input.device").length==$(this).parent().parent().parent().find("input.device:checked").length){$(this).parent().parent().parent().find("input.location").attr("checked","checked");
$(this).parent().parent().parent().find("input.device").attr("disabled","disabled")}});$.each($("ul.settings input.location"),function(){if($(this).attr("checked")||$(this).parent().parent().find("input.device").length==$(this).parent().parent().find("input.device:checked").length)$(this).parent().parent().find("input.device").attr("checked","checked").attr("disabled","disabled")})}
function toggleDialplanVisibility(a,c){if($("#"+a+"PstnTerminationEnabled").attr("checked")){$("#dialplan").show();c!=true&&$("#dialplan").find("input[type=checkbox]").attr("checked","checked")}else{$("#dialplan").hide();$("#dialplan").find("input[type=checkbox]").removeAttr("checked")}if(c){a=$("#dialplan ul ul");$.each(a,function(){$(this).find("input[type=checkbox]").length==$(this).find("input:checked").length&&$(this).parent().find("> input[type=checkbox]").attr("checked","checked")})}}
function getPasswordStrength(a){var c=0;if(a.length<5)c+=3;else if(a.length>4&&a.length<8)c+=6;else if(a.length>7&&a.length<16)c+=12;else if(a.length>15)c+=18;if(a.match(/[a-z]/))c+=1;if(a.match(/[A-Z]/))c+=5;if(a.match(/\d+/))c+=5;if(a.match(/(.*[0-9].*[0-9].*[0-9])/))c+=5;if(a.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))c+=5;if(a.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))c+=5;return c}
function verifyPassword(){var a=$("#UserPassword").val(),c=getPasswordStrength(a);a=a.length;if(a>1)if(a<8){$("#password-meter").css("background","red");$("#password-meter").html("Password Too Short (8 characters minimum)")}else{var e=a="";if(c>24){a="Strong";e="green"}else if(c>18){a="Mediocre";e="orange"}else{a="Poor";e="red"}$("#password-meter").css("background",e);$("#password-meter").html("Password Strength: "+a)}}
function verifyPasswordAgain(){var a=$("#UserPassword").val(),c=$("#UserPasswordAgain").val();if(a.length>1){var e="",b=";";if(a==c){e="Passwords Match";b="green"}else{e="Passwords Do Not Match";b="red"}$("#password-matches").css("background",b);$("#password-matches").html(e)}}
function showFilters(){var a=$("#CompaniesCdrFilterBy").val().replace(/[^a-z\-]/,"");if(a!=""){$("#CompaniesCdrFilterExtensionsValue").hide();$("#CompaniesCdrFilterCallTypesValue").hide();switch(a){case "extensions":$("#CompaniesCdrFilterExtensionsValue").show();break;case "call-types":$("#CompaniesCdrFilterCallTypesValue").show();break}}}
function initKonnectInternetCallOutDetails(){if($("#CompaniesCdrFilterBy").val()=="extensions")$("#CompaniesCdrFilterExtensionsValue").show();else $("#CompaniesCdrFilterBy").val()=="call-types"&&$("#CompaniesCdrFilterCallTypesValue").show();$("#CompaniesCdrDate").change(function(){$("#CompaniesCdrFilterBy").val("");$("#CompaniesCdrFilterExtensionsValue").val("");$("#CompaniesCdrFilterCallTypesValue").val("");$("#CompaniesCdrSummary").submit()});$("#CompaniesCdrFilterBy").change(function(){showFilters()});
$("#CompaniesCdrFilterExtensionsValue").change(function(){$("#CompaniesCdrFilterCallTypesValue").val("");$("#CompaniesCdrSummary").submit()});$("#CompaniesCdrFilterCallTypesValue").change(function(){$("#CompaniesCdrFilterExtensionsValue").val("");$("#CompaniesCdrSummary").submit()})}
function initChangePassword(){if($("#UserCurrentPassword").attr("defaultValue")==""||$("#UserPassword").attr("defaultValue")==""){$("#UserCurrentPassword").attr("value","");$("#UserPassword").attr("value","");$("#UserPasswordAgain").attr("value","")}$("#UserCurrentPassword").focus()}function initResetPassword(){if($("#UserPassword").attr("defaultValue")==""){$("#UserPassword").attr("value","");$("#UserPasswordAgain").attr("value","")}$("#UserPassword").focus()}
var initYourKonnectNetworkEdit=function(){var a={indicator:"Saving...",cancel:"Cancel",submit:"Save",placeholder:"Click to edit",style:"display: inline"};$(".location").editable("/companies_locations/rename/",a);$(".phone-number").editable("/companies_locations/phone_number/",a)},initKonnectInternetCallOutManage=initYourKonnectNetworkEdit;
