function lookupPostcode() {
  var postcodeField = document.getElementById("zip");
  if (postcodeField) {
    var parts = [];
    for (var i = 0; i < 3; i++) {
      var addressField = document.getElementById("address" + (i + 1));
      if (addressField) {
        parts[i] = addressField.value;
      }
    }
    window.open("/grazia/lookupPostcode?postcode=" + encodeURIComponent(postcodeField.value) + "&oldAddress=" + encodeURIComponent(parts.join(" | ")), "postcodePopup", "width=400,height=400");
  }
}

function insertAddress(address) {
  var parts = address.split(/\s*\|\s*/);
  for (var i = 0; i < 3; i++) {
    var addressField = document.getElementById("address" + (i + 1));
    if (addressField) {
      addressField.value = parts[i] || "";
    }
  }
  showAddressFields();
}

function showCountryRow() {
	if ($('#countryRow').is(":visible")) {
		$('#countryRow').hide();
		$('#addressBlock').hide();
		$('#manuallookup').show();
		$('#ziplookup').show();
		$('#select_persons_editPublicProfile_country').val('en_GB');
		$('#select_home_registerUser1_country').val('en_GB');
	} else {
		$('#countryRow').show();
		$('#addressBlock').show();
		$('#manuallookup').hide();
		$('#ziplookup').hide();
	}
}

function showAddressFields() {
	$('#addressBlock').show();
}

function showTerms(){
jQuery("#warnDialog").dialog({ buttons: { "Close": function() { jQuery(this).dialog("close"); } }, minWidth: 400 });
}; 

function bodyHub(body) {
	if (jQuery(".ad").height()>2) {
		jQuery("body").addClass("ad-enable");
		if (jQuery("ul.dropdown.linear li.on ul li").length==1) {
			jQuery("ul.dropdown.linear li.on ul").hide();
		} else {
			jQuery(".ad").css("margin-top", "24px");
		}
	}
}
