function toggle_collapse_and_text(id, text_container) {
	e = document.getElementById(id);
	if(!e) return;
	if(e.style.visibility == "visible") {
		e.style.visibility = "hidden";
		e.style.position = "absolute";
		text_container.firstChild.className="down-arrow";
	} else {
		e.style.position = "relative";
		e.style.visibility = "visible";
		text_container.firstChild.className="up-arrow";
	}
}

function add_password_change_info_popup() {
  var wis = document.getElementById('what-is-cp-password-change');
  wis.parentNode.replaceChild(
    hide_block_popup("What is this?", [
      _mkel("p", "By changing your control panel password you will be able to maintain a separate password for logging into FTP and logging into this control panel. Maintaining separate passwords will help to improve your website security so we recommend that you do this as soon as possible.")
    ], {
      initialContentElement: wis,
      noWrapper: true
    })[0],
    wis
  );
}

function recalculate_icon_box_for_iphone(id, width, icon_width, icon_height, icon_count) {
  var w = document.getElementById(id).clientWidth;
  if(w != width && small_screen) {
    var icons_per_row = Math.floor((w)/icon_width);
    var rows = (icon_count - 1) / icons_per_row;
    rows=Math.round(rows+0.5);
    document.getElementById(id+"-icons").style.height =
      (( icon_height * rows ) + 10) + "px";
  }
}
function recalculate_width_for_iphone() {
	var t = document.getElementById('effective-body');
	if(small_screen && document.getElementById("cpright")) {
    if(document.getElementById("ftp-access-top")) {
      var fmi = document.getElementById("b-fileman-icon");
      if(fmi) {
        var fli = fmi.cloneNode(true);
        var flia = fli.getElementsByTagName("A").item(0);
        flia.href='ftp-locking.cgi';
        flia.lastChild.data = "FTP Locking";
        flia.firstChild.id="b-ftp-unlock-icon";
        var append_to = fmi.parentNode.parentNode.lastChild;
        if(append_to.childNodes.length == 4) {
          fmi.parentNode.parentNode.appendChild(append_to.cloneNode(false));
          append_to = fmi.parentNode.parentNode.lastChild;
        }
        append_to.appendChild(fli);
      }
    }
		// Hide the right column.
		var ds = [];
		var cns = t.childNodes;
		for(var i=0; i<cns.length; i++) if(cns.item(i).tagName == "DIV") ds.push(cns.item(i));
		var maybe_hide = [ds[0], ds[1]];
		var messages = ["Show Icons", "Show Information"];
		var hide_which = 1;
		maybe_hide[hide_which].parentNode.removeChild(maybe_hide[hide_which]);
		var sw = _mkel("div", {
			className: "flick-link"
		}, [
			_mkel("a", {
				href: "#",
				onclick: function() {
					hide_which = 1 - hide_which;
					maybe_hide[hide_which].parentNode.appendChild(maybe_hide[1-hide_which]);
					maybe_hide[hide_which].parentNode.removeChild(maybe_hide[hide_which]);
					this.firstChild.data = messages[hide_which];
					return false;
				}
			}, [messages[hide_which]])
		]);
		t.parentNode.insertBefore(sw, t);

	}
}


function IndexStyle() {
  function account_info_row(title, content) {
    var c = content;
    if(title.constructor!==Array) title=[title];
    c.unshift(
      _mkel("p", {className: "lititle"}, title)
    );
    return _mkel("li", c);
  }
  function large_content(c) {
    return _mkel("p", {className: "liattrlrg"}, c);
  }
  function small_content(c) {
    return _mkel("p", {className: "liattr"}, c);
  }
  function maybe_link(include_link, link, content) {
    return include_link ?  _mkel("a", {href: link}, content) : content;
  }

  function usage_with_maybe_link(include_link, link, count, max, units) {
    if(units) units=" "+units;
    else units="";
    content = [ count + "/", _mkel("strong", max), units ];
  
    var overuse = false;
    var percent;
    if(max!="unlimited") {
      if(max > 0) percent = count*100 / max;
      else percent = 100; 
      if(percent > 70) overuse = true;
    }

    var usage_bar = _mkel("div", {className: "bar"}, [
      _mkel("p", {className: overuse ? "lvlred" : "lvl"}, [], function() {
        this.style.width=Math.floor(Math.min(100,(percent||0)))+"%";
      })
    ]);
    return [
      small_content(maybe_link(include_link, link, content)),
      usage_bar
    ];
  }

  this.populateAccountInfo = function() {
    var top = document.getElementById("account-info-inner");
    _add_nodes(top, [
      account_info_row("Domain Name:", [ large_content( package_info.ftp_user ) ]),
      account_info_row("Package Type:", [ large_content( package_info.name ) ]),
      account_info_row("Server Type:", [ large_content( package_info.web_server_type.match(/windows/) ? "Windows" : "Linux" ) ]),
      account_info_row(
        [_mkel("abbr", {title: "Temporary"}, ["Temp"]), " Web Address:"],
        [ large_content(
          _mkel("a", {
            href: "http://" + package_info.web_server_ipn + "/" + package_info.ftp_user + "/",
            title: "Visit Website",
            target: "_blank"
            }, ["Visit Website"]) 
        ) ]
      ),
      account_info_row("Web Space:",
        usage_with_maybe_link(package_info.features.du, "du.cgi", package_info.space_used, package_info.webspace, "MB")
      ),
      account_info_row("Bandwidth:",
        usage_with_maybe_link(package_info.features.bwstats, "bw.cgi", package_info.bandwidth.total, package_info.bandwidth.max, "MB")
      ),
      account_info_row("Web Server:", [ maybe_link(package_info.features.server_info, "server-details.cgi", package_info.web_server) ]),
      account_info_row("Mail Boxes:",
        usage_with_maybe_link(package_info.max_mailboxes != "0", 'email-mailbox-config.cgi', package_info.mailboxes, package_info.max_mailboxes)
      ),
      account_info_row("Mail Server:", [ small_content("mail." + package_info.ftp_user) ]),
      package_info.max_ms_databases ?
        account_info_row("MS SQL Databases:",
          usage_with_maybe_link(true, 'database-ms.cgi', package_info.ms_databases, package_info.max_ms_databases)
        ):
        "",
      account_info_row("MySQL Databases:",
        usage_with_maybe_link(package_info.max_databases, 'database.cgi', package_info.databases, package_info.max_databases)
      ),
      account_info_row("Subdomains:",
        usage_with_maybe_link(package_info.max_subdomains, 'sub-domain.cgi', package_info.subdomains, package_info.max_subdomains)
      )
    ]);
  }
  this.populateFTPDetails = function() {
    var top = document.getElementById("ftp-details-inner");

    function password_clickable() {
      var password_content = _mkel("kbd", package_info.ftp_password);
      return _mkel("a", {
        href: "#",
        onclick: function() {this.parentNode.replaceChild(password_content, this); return false}
      }, ["click here to show"]);
    }

    _add_nodes(top, [
      account_info_row("Username:", [ small_content( package_info.ftp_user ) ]),
      account_info_row("Password:", [ small_content( password_clickable() ) ] ),
      account_info_row("FTP Server:", [ small_content( "ftp." + package_info.ftp_user ) ]),
      account_info_row("FTP Server IP:", [ small_content( package_info.ftp_ip ) ]),
      account_info_row("FTP Users:", 
        usage_with_maybe_link(package_info.max_ftp, 'ftp-user.cgi', package_info.ftp_users, package_info.max_ftp)
      )
    ]);
  }
  this.populateContactInfo = function() {
    document.getElementById("contact-info-name").appendChild(document.createTextNode(e_contacts.company_name));
    var top = document.getElementById("contact-info-inner");
    _add_nodes(top, [
      e_contacts.home_web ? account_info_row("Home Page:", [ large_content( maybe_link(true, e_contacts.home_web, e_contacts.home_web) ) ]) : "",
      e_contacts.support_web ? account_info_row("Support Site:", [ large_content( maybe_link(true, e_contacts.support_web, e_contacts.support_web) ) ]) : "",
      e_contacts.sales_email ? account_info_row("Sales Email:", [ large_content( maybe_link(true, 'mailto:' + e_contacts.sales_email, e_contacts.sales_email) ) ]) : "",
      e_contacts.support_email ? account_info_row("Support Email:", [ large_content( maybe_link(true, 'mailto:' + e_contacts.support_email, e_contacts.support_email) ) ]) : ""
    ]);
  }
  this.showHeadOfPageWarnings = function() {
    

    if(
      package_info.ftp_users > 0 &&
      package_info.max_ftp != 0
    ) document.getElementById("effective-body").appendChild(_mkel(
      "p", {style: {fontSize: "smaller", width: "100%"}, id: 'unlock-ftp-advice'},
      ['To unlock FTP for additional FTP users choose "Additional FTP Accounts" below.']
    ));
  }
}

function store_drag_prefs() {
	var e = document.getElementById("cpleft");
	if(!e) return;
	var cn = e.childNodes;
	var prefs_discovered = [];
	for(var i=0; i < cn.length; i++) {
		var n = cn.item(i);
		if(n.tagName=="DIV") {
			var id = n.id.replace(/^box-for-/, "");
			var icon_box = n.lastChild;
			var collapsed = (icon_box.style.display == "none") ? 1 : 0;
			prefs_discovered.push(id + ":" + collapsed);
		}
	}
	var cv = prefs_discovered.join(",");
	var expiry_date = new Date();
	expiry_date.setDate(expiry_date.getDate() + 365);
	document.cookie = "layout-prefs=" + escape(cv) + ";" + 
										"expires=" + expiry_date.toGMTString();
}
function load_drag_prefs() {
  var md = document.cookie.match(/layout-prefs=([^;]*)/);
  if(!md) return;
  var prefs_original = unescape(md[1]).split(/,/);
  var prefs = [];
  for(var i=0; i<prefs_original.length; i++) {
    var config = prefs_original[i].split(/:/);
    prefs.push({
      name: config[0],
      collapsed: parseInt(config[1])
    });
  } 
  return prefs;
}
function clear_drag_prefs() {
	var expiry_date = new Date();
	document.cookie = "layout-prefs=;" + 
										"expires=" + expiry_date.toGMTString();
	window.location.reload();
}

function add_icon_tray_body(draggable_div, icons, known_max_count) {
  var box_top = _mkel("div", {className: "extcontent icon-box-body"});
  draggable_div.appendChild(box_top);
  var current_line = _mkel("ul", {className: "icon-line"});
  box_top.appendChild(current_line);
  
  function build_icon(is) {
    return _mkel("li", {
      id: "b-" + is.code.replace(/i:/, "i-") + "-icon"
    }, [
      _mkel("a", {href: is.target, title: is.name}, [ is.name ])
    ]);
  }
  var first_top_offset;

  for(var i=0; i<icons.length; i++) {
    var e = build_icon(icons[i]);
    current_line.appendChild(e);
  }
  return juggle_tray_body(box_top, known_max_count);
}







function juggle_tray_body(tb, known_max_count) {

  



  var cn = tb.childNodes;

  var to_move = [];
  
  function find_nodes_to_juggle() {
    for(var i = 0; i<cn.length; i++) {
      var ncn = cn.item(i).childNodes;
      for(var j=0; j<ncn.length; j++)
        to_move.push(ncn.item(j));
    }
  }
  find_nodes_to_juggle();

  
  var section_proto = tb.firstChild.cloneNode(false);

  
  function remove_all_sections() {
    while(cn.length) tb.removeChild(tb.lastChild);
  }
  remove_all_sections();

  var known_max_count;

  function add_nodes(line) {
    var first_top_offset;
    for(var j=0; (known_max_count === undefined || j<known_max_count) && to_move.length > 0; j++) {
      var e = to_move.shift();
      line.appendChild(e);
      if(known_max_count) {
        
      } else if(first_top_offset === undefined) {
        first_top_offset = e.offsetTop;
      } else if(e.offsetTop > first_top_offset) {
        
        to_move.unshift(e);
        known_max_count = j;
        break;
      }
    }
  }
  
  while(to_move.length > 0) {
    var line = section_proto.cloneNode(false);
    tb.appendChild( line );
    add_nodes( line );
  }
  return known_max_count;
}

function icon_tray(name, icons, id, collapse, known_max_count) {
  var top = document.getElementById("cpleft");
  var draggable_div = _mkel("div", {id: "box-for-" + id});
  top.appendChild(draggable_div);
  draggable_div.appendChild(_mkel("div", {className: "extheading"}, [
    _mkel("img", {src: "/images/bg_dragger.png", alt: name}),
    _mkel("div", {className: "collapsebox expand"}, [
      _mkel("a", {
        href: "#", 
        title: "collapse", 
        onclick: function() {
          var s = draggable_div.lastChild.style;
          s.display = (s.display == "none") ? "" : "none";
          store_drag_prefs();
          return false;
        }
      }, [unhtml("&nbsp;")])
    ]),
    _mkel("p", [name])
  ]));

  known_max_count = add_icon_tray_body(draggable_div, icons, known_max_count);
  if(collapse) draggable_div.lastChild.style.display = "none";
  return known_max_count;
}

function all_icon_trays(tf) {
  var default_order = [
    {name: 'files', collapsed: 0},
    {name: 'email', collapsed: 0},
    {name: 'web_stats', collapsed: 0},
    {name: 'web_tools', collapsed: 0},
    {name: 'ws_help', collapsed: 0},
    {name: 'web_res', collapsed: 0},
    {name: 'ecomm', collapsed: 0},
    {name: 'installable', collapsed: 0}
  ];
  var tray_order = load_drag_prefs() || default_order;
  var seen_tray = {};

  var full_order = tray_order.concat(default_order);
  
  var known_max_count;
  chain(full_order, function(v, lf) {
    var g = v.name;
    if(icons[g] && !seen_tray[g]) {
      known_max_count = icon_tray(icons[g].name, icons[g].icons, g, v.collapsed, known_max_count);
      seen_tray[g] = true
    }
    lf();
  }, tf, 100);
}

function make_icon_box_list_sortable() {
   Sortable.create("cpleft",
     {tag: "div", onUpdate: store_drag_prefs, format: '^(.*)$'});
}

function add_icon_search() {
  var menu_search = new MenuSearch({
    topElementId: "cpleft",
    sectionClassName: "icon-line",
    existingClearButtonID: "search-clear-button"
  });
  menu_search.moreKeywords = function(subsection_top) {
    return []; 
  };
  menu_search.onSectionEmpty = function() {
    this.style.display = "none";
    return true; 
  };
  var known_max_count;
  menu_search.onSectionNotEmpty = function(item_count) {
    this.style.display = "";
    //juggle_tray_body(this.parentNode, known_max_count);
    return true; 
  };
  menu_search.prepare("icon-search");
}












function position_fixed(x, y, client_x, client_y, element, fix_width) {

	element.style.position="absolute";
	element.style.left = client_x + x + 'px';
	element.style.top = client_y + y + 'px';

	document.body.appendChild(element);

	if(fix_width) {	
		var cn = element.childNodes;
		var w = element.clientWidth - 4;
		for(var i=0; i<cn.length; i++) {
			cn.item(i).style.width=w + "px";
		} 
	}
}








function position_centred(e, element, fix_width) {

	e = e || window.event;

	var x = 0;
	var y = 0;

	if( typeof( window.pageYOffset ) == 'number' ) {
			x = window.pageXOffset;
			y = window.pageYOffset;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			x = document.documentElement.scrollLeft;
			y = document.documentElement.scrollTop;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			x = document.body.scrollLeft;
			y = document.body.scrollTop;
	}
	var vp_y = window.innerHeight || document.documentElement.clientHeight;
	var vp_x = window.innerWidth || document.documentElement.clientWidth;

	element.style.visibility='hidden';
	position_fixed(x, y, (vp_x - element.clientWidth)/2, (vp_y - element.clientHeight)/2, element, fix_width);
	element.style.top = y + (vp_y - element.clientHeight)/2 + "px";
	element.style.left = x + (vp_x - element.clientWidth)/2 + "px";
	element.style.visibility='visible';
}















function FTPAccessUI(top, options) {
  this.topElement = top;
  this.options = options;
}


FTPAccessUI.prototype = {
  



  withTitle: function(t, a) {
    if(!this.options.noTitle) {
      a=[_mkel("h2", [t]), _mkel("div", {className: "bbox"}, a)];
    }
    return a;
  },
  





  infoPopup: function(extra_options) {
    var options = this.options;
    if(extra_options)
      for(var k in extra_options) options[k] = extra_options[k];

    return hide_block_popup("Why do I have to do this?", [
      _mkel("p", ["FTP is locked on all accounts as standard. This is to help prevent your site being attacked. You can unlock FTP for a set period of time; we recommend that you do this only for short periods. We would advise that you prepare any changes to your website and then, when you are ready to upload it, unlock FTP for one hour. If you need longer, then please select the relevant option below. However, we would advise you to only unlock FTP for short periods."]),
      _mkel("p", ["We require this because of the many PC viruses circulating that steal passwords stored within FTP clients. We recommend that you do not store your passwords inside your FTP software for this reason. Instead, you should manually re-enter passwords each time you wish to use FTP."])
    ], options)[0];
  },
  



  lockStatusNode: function(is_locked, other_content) {
    var c = [];
    if(is_locked) {
      c.push(_mkel("img", {src: "/images/icon_locked.png", alt: "Locked"}));
    } else {
      c.push(_mkel("img", {src: "/images/icon_unlocked.png", alt: "Unlocked"}));
    }
    c = c.concat(other_content);
    return _mkel("p", {className: "ftp-access-info"}, c);
  },
  




  ttlChoice: function(value, caption) {
    var t = this;
    return _mkel("div", [
      _mkel('input', {
        type: 'radio', 
        name: 'ttl', 
        'value': value,
        'id': 'ttl'+value+this.username
      }, function() {
        
        this.onclick = function() {
          this.checked = true; 
          t.ttl_chosen = this.value;
        }
        this.onchange = function() {
          if(this.checked) t.ttl_chosen = this.value;
        }
        if(this.value=='1') {
          this.checked=true;
          this.onclick();
        }
      }),
      " ",
      _mkel("label", {htmlFor: 'ttl'+value+t.username}, [caption])
    ]);
  },
  



  ttlChoices: function(choice_array) {
    return _mkel("div", {}, choice_array);
  },
  



  ttlChoiceList: function() {
    return this.ttlChoices([
      this.ttlChoice('1', "1 hour (recommended)"),
      this.ttlChoice('4', "4 hours"),
      this.ttlChoice('24', "1 day"),
      this.ttlChoice('168', "7 days (not recommended)"),
      this.ttlChoice('672', "28 days (not recommended)")
    ]);
  },
  



  ttlUnlockButton: function(e) {
    var t = this;
    e.onclick = function() {
      t.ajaxWithArgs({ttl: t.ttl_chosen||1});
      return false
    }
    return e;
  },
  




  ipUnlockButton: function(ip_address_input, e) {
    var t = this;
    e.onclick = function() {
      var acl = ip_address_input.value;
      var acl_parts = acl.split(/\s*,\s*/);
      for(var i=0; i<acl_parts.length; i++) {
        if(acl_parts[i].match(/^(192\.168|10)\./)) {
          alert("You have entered an internal IP address that is only accessible on your own network. Please enter your external network IP address");
          return false;
        } else if(!acl_parts[i].match(/^(\d+\.){3}\d+$/) ) {
          alert("You have entered an invalid IP address. Please try again.");
          return false;
        }
      }
      t.ajaxWithArgs({'ip-address': acl});
      return false
    }
    return e;
  },
  



  formContent: function() {
    var ip_address_input;
    return [
      _mkel("p", {className: "ftp-access-question"}, ["How long you would like to unlock FTP for:"]),
      this.ttlChoiceList(),
      _mkel("p", [ this.ttlUnlockButton(
        _mkel("input", {type: "submit", value: "Unlock by Time"})
      ) ]),
      _mkel("p", ["Or you can set an IP address to always have access. To set multiple addresses, separate them with a comma."]),
      _mkel("p", {style: {fontWeight: "bold"}}, ["Please enter it below."]),
      _mkel("p", [
        
        ip_address_input = _mkel("input", {type: "text", value: ip_address}),
        this.ipUnlockButton(ip_address_input, 
          _mkel("input", {type: "submit", value: "Unlock by IP"})
        )
      ])
    ];
  },
  



  lockFTPButton: function() {
    var t = this;
    return _mkel('input', {
      type: 'submit', 
      value: "Lock FTP now", 
      onclick: function() {
        t.ajaxWithArgs({ttl: '0'});
        return false;
      }
    })
  },
  





  showUI: function() {
    var reload_interval;
    var first_run = true;
    this.username = this.topElement.title;
    this.topElement.title = "";

    var opts = this.options;
    var te = this.topElement;

    var t = this;
    









    function ajax_with_args(args) {
      args = args || {};
      args.r = Math.random();
      args.v = "1.3";
      args.mode = opts.mode || "full";
      args.username = t.username;
      xmlhttp_simple_full("/ftp-access.cgi", args, undefined, reload_page);
    }

    this.ajaxWithArgs = ajax_with_args;

    





    function nice_time(ts) {
      var times = [
        {c: "day", s: 86400},
        {c: "hour", s: 3600},
        {c: "minute", s: 60}
      ];
      var now_local = (new Date()) / 1000;
      var seconds = ts - now_local;
      if(seconds<60) {
        ajax_with_args();
        if(reload_interval) {
          clearTimeout(reload_interval);
          reload_interval = undefined;
        }
        return "";
      }
      var components = [];
      for(var i=0; i<times.length; i++)
        if(seconds > times[i].s) {
          var remainder = seconds % times[i].s;
          var count = ((seconds-remainder) / times[i].s).toFixed(0);
          seconds = remainder;
          unit = times[i].c;
          if(count != 1) unit += "s";
          components.push(count + " " + unit);
        }
      return components.join(", ");
    } 
    




    function hide_block(hide_caption, block_content) {
      var link =  _mkel("div", {
          style: {
            width: "100%",
            textAlign: "center",
            paddingBottom: "5px"
          }
        }, [
          _mkel("img", {
            src: "/images/icon_info.png", 
            style: {
              padding: "0px 10px 0px 0px",
              marginBottom: "-3px"
            },
            alt: "Information"
          }),
          _mkel("a", {
            href: '#',
            onclick: function() {
              _add_nodes(this.parentNode.parentNode, block_content);
              this.parentNode.parentNode.removeChild(this.parentNode);
              return false;
              }
            }, [hide_caption])
          ]
        );
      return [ link ];
    }
    







    function reload_page(e) {
      var ftp_el = e.getElementsByTagName("ftp").item(0);
      var ntop = te.cloneNode(false);
      te.parentNode.replaceChild(ntop, te);
      te = ntop;
      var now_unix = e.getAttribute("now");
      var now_local = (new Date()) / 1000;
      if(ftp_el) {
        if( ftp_el.getAttribute("allowed-from") ) {
          _add_nodes(ntop, ip_acl(ftp_el.getAttribute("allowed-from")));
        } else if( ftp_el.getAttribute("expires") > now_unix ) {
          _add_nodes(ntop, expires(ftp_el.getAttribute("expires") - now_unix + now_local));
        } else if(opts.startHidden && first_run) {
          _add_nodes(ntop, hide_block("Unlock", choices(), true));
        } else {
          _add_nodes(ntop, choices());
        }
      } else {
        _add_nodes(ntop, coming_soon());
      }
      first_run = false;
    }
    





    function choices(override_info, no_click) {
      if(no_click)
        return t.withTitle("Unlock FTP",
          [
          _mkel("p", ["Unable to get FTP lock status. Please reload the page and try again."])
          ]
        );

      var content = [
        override_info || t.lockStatusNode(true, [
          "FTP is ", _mkel("strong", ["currently locked."])
        ])
      ];
      if(!opts.skipBodyInfoPopup)
        content.push( _mkel("div", [t.infoPopup()]) );

      content = content.concat( t.formContent() );
      return t.withTitle("Unlock FTP", content);
    }
    





    function expires(expires_ts) {
      return t.withTitle("Lock FTP", [
        t.lockStatusNode(false, [
          "FTP is ",
          _mkel("strong", "currently unlocked"),
          " and will be automatically locked in ",
          _mkel("span",
            [nice_time(expires_ts)],
            function() {
              var t = this;
              function reload() {
                t.firstChild.data = nice_time(expires_ts);
              }
              reload_interval = setInterval(reload, 15000);
            }
          ),
          "."
        ]),
        t.lockFTPButton()
      ]);
    }
    



    function coming_soon() {
      return choices(
        t.lockStatusNode(false, [
          "FTP is ",
          _mkel("strong", ["currently unlocked."])
        ]),
        true
      );
    }
    




    function ip_acl(ip_addresses) {
      return t.withTitle("Lock FTP", [
        t.lockStatusNode(false, [
          "FTP is ", _mkel("strong", "currently unlocked"),
          " for the IP address(es): ",
          ip_addresses
        ]),
        t.lockFTPButton()
      ]);
    }
    if(
      (typeof(small_screen) == 'undefined' || !small_screen) ||
      this.options.onSmallScreen
    ) ajax_with_args();
  }
}






function ftp_access_ui(options) {
  options = options || {};
  var es = _u_prototype.call(document, "getElementsByClassName", "ftp-access-box");
  for(var i=0; i<es.length; i++) new FTPAccessUI(es[i], options).showUI();
}




function FTPAccessUI2KX() {
  FTPAccessUI.apply(this, arguments);
  this.options.skipBodyInfoPopup = true;
}
FTPAccessUI2KX.prototype = new FTPAccessUI();
FTPAccessUI2KX.prototype.withTitle = function(t, a) {
  return [
    _mkel("div", {className: "extheading"}, [
      this.infoPopup({
        noWrapper: true,
        fakeAnchor: true,
        initialContentElement: _mkel("img", {
          src: "images/icon_question.gif", 
          alt: "Why do I have to do this?", 
          style: {
            position: "relative",
            zIndex: "15",
            cssFloat: "left",
            styleFloat: "left",
            top: "8px",
            left: "10px"
          }
        })
      }),
      _mkel("p", "Unlock FTP"),
      _mkel("div", {className: "collapsebox expand"}, [
        _mkel("a", {href: "#FIXME", title: "collapse"})
      ])
    ]),
    _mkel("div", {className: "extcontent", id: "unlkftp"}, a)
  ];
}
FTPAccessUI2KX.prototype.lockStatusNode = function(is_locked, other_content) {
  var c = [];
  if(is_locked) {
    c.push(_mkel("img", {src: "/images/additional-2kx/icon_locked.png", alt: "FTP is currently locked", className: "ialign"}));
  } else {
    c.push(_mkel("img", {src: "/images/additional-2kx/icon_unlocked.png", alt: "FTP is currently unlocked", className: "ialign"}));
  }
  c = c.concat(other_content);
  return _mkel("p", {className: "locknotice curved"}, c);
}
FTPAccessUI2KX.prototype.ttlChoice = function(value, caption) {
  var t = this;
  return _mkel("li", [
    _mkel("label", [
      _mkel('input', {
        type: 'radio', 
        name: 'ttl', 
        'value': value,
        'id': 'ttl'+value+this.username
      }, function() {
        
        this.onclick = function() {
          this.checked = true; 
          t.ttl_chosen = this.value;
        }
        this.onchange = function() {
          if(this.checked) t.ttl_chosen = this.value;
        }
        if(this.value=='1') {
          this.checked=true;
          this.onclick();
        }
      }),
      caption
    ])
  ]);
}
FTPAccessUI2KX.prototype.ttlChoices = function(choice_array) {
  return _mkel("ul", {}, choice_array);
}
FTPAccessUI2KX.prototype.lockFTPButton = function() {
  var t=this;
  return _mkel('input', {
    type: 'submit', 
    className: "curved",
    value: "Lock FTP now", 
    onclick: function() {
      t.ajaxWithArgs({ttl: '0'});
      return false;
    }
  })
}
FTPAccessUI2KX.prototype.formContent = function() {
  var ip_address_input;
  return [
    _mkel("p", {className: "ftp-access-question"}, ["How long you would like to unlock FTP for:"]),
    this.ttlChoiceList(),
    _mkel("p", [ this.ttlUnlockButton(
      _mkel("input", {type: "submit", value: "Unlock", className: "curved"})
    ) ]),
    _mkel("p", {style: {fontWeight: "bold"}}, ["Unlock by IP"]),
    _mkel("p", ["You can set an IP address to have access without time limits. To set multiple addresses, separate them with a comma."]),
    _mkel("p", [
      
      ip_address_input = _mkel("input", {className: "curved left", type: "text", value: ip_address}),
      this.ipUnlockButton(ip_address_input, 
        _mkel("input", {type: "submit", value: "Unlock", className: "right curved"})
      )
    ])
  ];
}

