function toggle_menu_sublist(class_name) {
  $$(".menu.block div.sublist").each(function(sub) {
    if (sub.hasClassName(class_name)) {
      sub.toggle();
    } else {
      sub.hide();
    }
  });
}

function apply_for_visa(frm) {
  var dest = frm.dest_country.value;
  var from = frm.from_country.value;
  if (!dest) {
    alert("Please select visiting country");
  } else if (!from) {
    alert("Please select resident country");
  }
  var valid_dest = $H({
    "2fr": true, 
    "2it": true, 
    "2se": true,
    "2dk": true, 
    "2ca": true
  });
  var valid_from = $H({
    "dz": true, 
    "cn": true, 
    "eg": true, 
    "lb": true, 
    "th": true, 
    "id": true, 
    "ma": true, 
    "gb": true
  });
  if (!dest || !from || !valid_dest.get(dest) || !valid_from.get(from)) {
    return false;
  }
  var url_map = $H({
    "cn": "cn.tlscontact.com/",
    "dz": "www.tlscontact.com/",
    "eg": "www.tlscontact.com/",
    "lb": "www.tlscontact.com/",
    "th": "www.tlscontact.com/",
    "id": "www.tlscontact.com/",
    "ma": "www.tlscontact.com/",
    "gb": "www.tlscontact.com/"
  });
  document.location.href = "https://" + url_map.get(from) + from + dest;
}

function toggle_site_map() {
  $$(".sitemap.area").first().toggleClassName("inactive");
}

function set_from_country(opt) {
  var dest = opt.value || "";
  var from_map = $H({
    "": [],
    "2fr": ["dz", "cn", "eg", "id", "lb", "th", "gb"],
    "2it": ["dz", "lb", "ma"],
    "2se": ["eg"],
    "2dk": ["eg"],
    "2ca": ["dz"]
  });
  var label_map = $H({
    "": "Resident Country",
    "dz": "Algeria",
    "cn": "China",
    "eg": "Egypt",
    "id": "Indonesia",
    "lb": "Lebanon",
    "th": "Thailand",
    "ma": "Morocco",
    "gb": "United Kingdom"
  });
  var from_sel = new Element("select", {name: "from_country"});
  if (from_map.get(dest).size() != 1) {
    from_sel.insert((new Element("option", {value: ""})).update(label_map.get("")));
  }
  from_map.get(dest).each(function(from) {
    from_sel.insert((new Element("option", {value: from})).update(label_map.get(from)));
  });
  Element.replace(opt.form.from_country, from_sel)
}

