// holds an instance of XMLHttpRequest
var xmlHttp = createXmlHttpRequestObject();
// holds the remote server address 
var serverAddress = "validate.php";
// when set to true, display detailed error messages
var showErrors = true;
// initialize the validation requests cache 
var cache = new Array();

// creates an XMLHttpRequest instance
function createXmlHttpRequestObject() 
{
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // this should work for all browsers except IE6 and older
  try
  {
    // try to create XMLHttpRequest object
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    // assume IE6 or older
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    // try every id until one works
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    {
      try 
      { 
        // try to create XMLHttpRequest object
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {} // ignore potential error
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
    displayError("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

// function that displays an error message
function displayError($message)
{
  // ignore errors if showErrors is false
  if (showErrors)
  {
    // turn error displaying Off
    showErrors = false;
    // display error message
 
    alert("Error encountered: \n" + $message);
    // retry validation after 10 seconds
    setTimeout("validate();", 10000);
  }
}

// the function handles the validation for any form field
function validate(inputValue, fieldID)
{
  // only continue if xmlHttp isn't void
  if (xmlHttp)
  {
    // if we received non-null parameters, we add them to cache in the
    // form of the query string to be sent to the server for validation
    if (fieldID)
    {
      // encode values for safely adding them to an HTTP request query string
      inputValue = encodeURIComponent(inputValue);
      fieldID = encodeURIComponent(fieldID);
      // add the values to the queue
      cache.push("inputValue=" + inputValue + "&fieldID=" + fieldID);
    }
    // try to connect to the server
    try
    {
      // continue only if the XMLHttpRequest object isn't busy
      // and the cache is not empty
      if ((xmlHttp.readyState == 4 || xmlHttp.readyState == 0) 
         && cache.length > 0)
      {
        // get a new set of parameters from the cache
        var cacheEntry = cache.shift();
        // make a server request to validate the extracted data
        xmlHttp.open("POST", serverAddress, true);
        xmlHttp.setRequestHeader("Content-Type", 
                                 "application/x-www-form-urlencoded");
        xmlHttp.onreadystatechange = handleRequestStateChange;
        xmlHttp.send(cacheEntry);
      }
    }
    catch (e)
    {
      // display an error when failing to connect to the server
      displayError(e.toString());
    }
  }
}

// the function handles the validation for any form field
function validate2(inputValue, fieldID)
{
  //without any ajax, populate the city if zip code is entered...
  var zipcode = inputValue;
  var city = '';
if (zipcode >= '1000' && zipcode <= '1499') city = 'København K';
if (zipcode >= '1500' && zipcode <= '1799') city = 'København V';
if (zipcode >= '1800' && zipcode <= '1999') city = 'Frederiksberg C';
if (zipcode == '2000') city = 'Frederiksberg'; 
if (zipcode == '2100') city = 'København Ø'; 
if (zipcode == '2200') city = 'København N'; 
if (zipcode == '2300') city = 'København S'; 
if (zipcode == '2400') city = 'København NV'; 
if (zipcode == '2450') city = 'København SV'; 
if (zipcode == '2500') city = 'Valby'; 
if (zipcode == '2600') city = 'Glostrup'; 
if (zipcode == '2605') city = 'Brøndby'; 
if (zipcode == '2610') city = 'Rødovre'; 
if (zipcode == '2620') city = 'Albertslund'; 
if (zipcode == '2625') city = 'Vallensbæk'; 
if (zipcode == '2630') city = 'Taastrup'; 
if (zipcode == '2635') city = 'Ishøj'; 
if (zipcode == '2640') city = 'Hedehusene'; 
if (zipcode == '2650') city = 'Hvidovre'; 
if (zipcode == '2660') city = 'Brøndby Strand'; 
if (zipcode == '2665') city = 'Vallensbæk Strand'; 
if (zipcode == '2670') city = 'Greve'; 
if (zipcode == '2680') city = 'Solrød Strand'; 
if (zipcode == '2690') city = 'Karlslunde'; 
if (zipcode == '2700') city = 'Brønshøj'; 
if (zipcode == '2720') city = 'Vanløse'; 
if (zipcode == '2730') city = 'Herlev'; 
if (zipcode == '2740') city = 'Skovlunde'; 
if (zipcode == '2750') city = 'Ballerup'; 
if (zipcode == '2760') city = 'Måløv'; 
if (zipcode == '2765') city = 'Smørum'; 
if (zipcode == '2770') city = 'Kastrup'; 
if (zipcode == '2791') city = 'Dragør'; 
if (zipcode == '2800') city = 'Kongens Lyngby'; 
if (zipcode == '2820') city = 'Gentofte'; 
if (zipcode == '2830') city = 'Virum'; 
if (zipcode == '2840') city = 'Holte'; 
if (zipcode == '2850') city = 'Nærum'; 
if (zipcode == '2860') city = 'Søborg'; 
if (zipcode == '2870') city = 'Dyssegård '; 
if (zipcode == '2880') city = 'Bagsværd'; 
if (zipcode == '2900') city = 'Hellerup'; 
if (zipcode == '2920') city = 'Charlottenlund'; 
if (zipcode == '2930') city = 'Klampenborg'; 
if (zipcode == '2942') city = 'Skodsborg'; 
if (zipcode == '2950') city = 'Vedbæk'; 
if (zipcode == '2960') city = 'Rungsted Kyst'; 
if (zipcode == '2970') city = 'Hørsholm'; 
if (zipcode == '2980') city = 'Kokkedal'; 
if (zipcode == '2990') city = 'Nivå'; 
if (zipcode == '3000') city = 'Helsingør'; 
if (zipcode == '3050') city = 'Humlebæk'; 
if (zipcode == '3060') city = 'Espergærde'; 
if (zipcode == '3070') city = 'Snekkersten'; 
if (zipcode == '3080') city = 'Tikøb'; 
if (zipcode == '3100') city = 'Hornbæk'; 
if (zipcode == '3120') city = 'Dronningmølle'; 
if (zipcode == '3140') city = 'Ålsgårde'; 
if (zipcode == '3150') city = 'Hellebæk'; 
if (zipcode == '3200') city = 'Helsinge'; 
if (zipcode == '3210') city = 'Vejby'; 
if (zipcode == '3220') city = 'Tisvildeleje'; 
if (zipcode == '3230') city = 'Græsted'; 
if (zipcode == '3250') city = 'Gilleleje'; 
if (zipcode == '3300') city = 'Frederiksværk'; 
if (zipcode == '3310') city = 'Ølsted'; 
if (zipcode == '3320') city = 'Skævinge'; 
if (zipcode == '3330') city = 'Gørløse'; 
if (zipcode == '3360') city = 'Liseleje'; 
if (zipcode == '3370') city = 'Melby'; 
if (zipcode == '3390') city = 'Hundested'; 
if (zipcode == '3400') city = 'Hillerød'; 
if (zipcode == '3450') city = 'Allerød'; 
if (zipcode == '3460') city = 'Birkerød'; 
if (zipcode == '3480') city = 'Fredensborg'; 
if (zipcode == '3490') city = 'Kvistgård'; 
if (zipcode == '3500') city = 'Værløse'; 
if (zipcode == '3520') city = 'Farum'; 
if (zipcode == '3540') city = 'Lynge'; 
if (zipcode == '3550') city = 'Slangerup'; 
if (zipcode == '3600') city = 'Frederikssund'; 
if (zipcode == '3630') city = 'Jægerspris'; 
if (zipcode == '3650') city = 'Ølstykke'; 
if (zipcode == '3660') city = 'Stenløse'; 
if (zipcode == '3670') city = 'Veksø Sjælland'; 
if (zipcode == '3700') city = 'Rønne'; 
if (zipcode == '3720') city = 'Aakirkeby'; 
if (zipcode == '3730') city = 'Nexø'; 
if (zipcode == '3740') city = 'Svaneke'; 
if (zipcode == '3751') city = 'Østermarie'; 
if (zipcode == '3760') city = 'Gudhjem'; 
if (zipcode == '3770') city = 'Allinge'; 
if (zipcode == '3782') city = 'Klemensker'; 
if (zipcode == '3790') city = 'Hasle'; 
if (zipcode == '4000') city = 'Roskilde'; 
if (zipcode == '4030') city = 'Tune'; 
if (zipcode == '4040') city = 'Jyllinge'; 
if (zipcode == '4050') city = 'Skibby'; 
if (zipcode == '4060') city = 'Kirke Såby'; 
if (zipcode == '4070') city = 'Kirke Hyllinge'; 
if (zipcode == '4100') city = 'Ringsted'; 
if (zipcode == '4105') city = 'Ringsted'; 
if (zipcode == '4129') city = 'Ringsted'; 
if (zipcode == '4130') city = 'Viby Sjælland'; 
if (zipcode == '4140') city = 'Borup'; 
if (zipcode == '4160') city = 'Herlufmagle'; 
if (zipcode == '4171') city = 'Glumsø'; 
if (zipcode == '4173') city = 'Fjenneslev'; 
if (zipcode == '4174') city = 'Jystrup Midtsj'; 
if (zipcode == '4180') city = 'Sorø'; 
if (zipcode == '4190') city = 'Munke Bjergby'; 
if (zipcode == '4200') city = 'Slagelse'; 
if (zipcode == '4220') city = 'Korsør'; 
if (zipcode == '4230') city = 'Skælskør'; 
if (zipcode == '4241') city = 'Vemmelev'; 
if (zipcode == '4242') city = 'Boeslunde'; 
if (zipcode == '4243') city = 'Rude'; 
if (zipcode == '4250') city = 'Fuglebjerg'; 
if (zipcode == '4261') city = 'Dalmose'; 
if (zipcode == '4262') city = 'Sandved'; 
if (zipcode == '4270') city = 'Høng'; 
if (zipcode == '4281') city = 'Gørlev'; 
if (zipcode == '4291') city = 'Ruds Vedby'; 
if (zipcode == '4293') city = 'Dianalund'; 
if (zipcode == '4295') city = 'Stenlille'; 
if (zipcode == '4296') city = 'Nyrup'; 
if (zipcode == '4300') city = 'Holbæk'; 
if (zipcode == '4320') city = 'Lejre'; 
if (zipcode == '4330') city = 'Hvalsø'; 
if (zipcode == '4340') city = 'Tølløse'; 
if (zipcode == '4350') city = 'Ugerløse'; 
if (zipcode == '4360') city = 'Kirke Eskilstrup'; 
if (zipcode == '4370') city = 'Store Merløse'; 
if (zipcode == '4390') city = 'Vipperød'; 
if (zipcode == '4400') city = 'Kalundborg'; 
if (zipcode == '4420') city = 'Regstrup'; 
if (zipcode == '4440') city = 'Mørkøv'; 
if (zipcode == '4450') city = 'Jyderup'; 
if (zipcode == '4460') city = 'Snertinge'; 
if (zipcode == '4470') city = 'Svebølle'; 
if (zipcode == '4480') city = 'Store Fuglede'; 
if (zipcode == '4490') city = 'Jerslev Sjælland'; 
if (zipcode == '4500') city = 'Nykøbing Sj'; 
if (zipcode == '4520') city = 'Svinninge'; 
if (zipcode == '4532') city = 'Gislinge'; 
if (zipcode == '4534') city = 'Hørve'; 
if (zipcode == '4540') city = 'Fårevejle'; 
if (zipcode == '4550') city = 'Asnæs'; 
if (zipcode == '4560') city = 'Vig'; 
if (zipcode == '4571') city = 'Grevinge'; 
if (zipcode == '4572') city = 'Nørre Asmindrup'; 
if (zipcode == '4573') city = 'Højby'; 
if (zipcode == '4581') city = 'Rørvig'; 
if (zipcode == '4583') city = 'Sjællands Odde'; 
if (zipcode == '4591') city = 'Føllenslev'; 
if (zipcode == '4592') city = 'Sejerø'; 
if (zipcode == '4593') city = 'Eskebjerg'; 
if (zipcode == '4600') city = 'Køge'; 
if (zipcode == '4621') city = 'Gadstrup'; 
if (zipcode == '4622') city = 'Havdrup'; 
if (zipcode == '4623') city = 'Lille Skensved'; 
if (zipcode == '4632') city = 'Bjæverskov'; 
if (zipcode == '4640') city = 'Faxe'; 
if (zipcode == '4652') city = 'Hårlev'; 
if (zipcode == '4653') city = 'Karise'; 
if (zipcode == '4654') city = 'Faxe Ladeplads'; 
if (zipcode == '4660') city = 'Store Heddinge'; 
if (zipcode == '4671') city = 'Strøby'; 
if (zipcode == '4672') city = 'Klippinge'; 
if (zipcode == '4673') city = 'Rødvig Stevns'; 
if (zipcode == '4681') city = 'Herfølge'; 
if (zipcode == '4682') city = 'Tureby'; 
if (zipcode == '4683') city = 'Rønnede'; 
if (zipcode == '4684') city = 'Holmegaard '; 
if (zipcode == '4690') city = 'Haslev'; 
if (zipcode == '4700') city = 'Næstved'; 
if (zipcode == '4720') city = 'Præstø'; 
if (zipcode == '4733') city = 'Tappernøje'; 
if (zipcode == '4735') city = 'Mern'; 
if (zipcode == '4736') city = 'Karrebæksminde'; 
if (zipcode == '4750') city = 'Lundby'; 
if (zipcode == '4760') city = 'Vordingborg'; 
if (zipcode == '4771') city = 'Kalvehave'; 
if (zipcode == '4772') city = 'Langebæk'; 
if (zipcode == '4773') city = 'Stensved'; 
if (zipcode == '4780') city = 'Stege'; 
if (zipcode == '4791') city = 'Borre'; 
if (zipcode == '4792') city = 'Askeby'; 
if (zipcode == '4793') city = 'Bogø By'; 
if (zipcode == '4800') city = 'Nykøbing F'; 
if (zipcode == '4840') city = 'Nørre Alslev'; 
if (zipcode == '4850') city = 'Stubbekøbing'; 
if (zipcode == '4862') city = 'Guldborg'; 
if (zipcode == '4863') city = 'Eskilstrup'; 
if (zipcode == '4871') city = 'Horbelev'; 
if (zipcode == '4872') city = 'Idestrup'; 
if (zipcode == '4873') city = 'Væggerløse'; 
if (zipcode == '4874') city = 'Gedser'; 
if (zipcode == '4880') city = 'Nysted'; 
if (zipcode == '4891') city = 'Toreby L'; 
if (zipcode == '4892') city = 'Kettinge'; 
if (zipcode == '4894') city = 'Øster Ulslev'; 
if (zipcode == '4895') city = 'Errindlev'; 
if (zipcode == '4900') city = 'Nakskov'; 
if (zipcode == '4912') city = 'Harpelunde'; 
if (zipcode == '4913') city = 'Horslunde'; 
if (zipcode == '4920') city = 'Søllested'; 
if (zipcode == '4930') city = 'Maribo'; 
if (zipcode == '4941') city = 'Bandholm'; 
if (zipcode == '4943') city = 'Torrig L'; 
if (zipcode == '4944') city = 'Fejø'; 
if (zipcode == '4951') city = 'Nørreballe'; 
if (zipcode == '4952') city = 'Stokkemarke'; 
if (zipcode == '4953') city = 'Vesterborg'; 
if (zipcode == '4960') city = 'Holeby'; 
if (zipcode == '4970') city = 'Rødby'; 
if (zipcode == '4983') city = 'Dannemare'; 
if (zipcode == '4990') city = 'Sakskøbing'; 
if (zipcode == '4992') city = 'Midtsjælland USF P'; 
if (zipcode == '5000') city = 'Odense C'; 
if (zipcode == '5029') city = 'Odense C'; 
if (zipcode == '5100') city = 'Odense C'; 
if (zipcode == '5200') city = 'Odense V'; 
if (zipcode == '5210') city = 'Odense NV'; 
if (zipcode == '5220') city = 'Odense SØ'; 
if (zipcode == '5230') city = 'Odense M'; 
if (zipcode == '5240') city = 'Odense NØ'; 
if (zipcode == '5250') city = 'Odense SV'; 
if (zipcode == '5260') city = 'Odense S'; 
if (zipcode == '5270') city = 'Odense N'; 
if (zipcode == '5290') city = 'Marslev'; 
if (zipcode == '5300') city = 'Kerteminde'; 
if (zipcode == '5320') city = 'Agedrup'; 
if (zipcode == '5330') city = 'Munkebo'; 
if (zipcode == '5350') city = 'Rynkeby'; 
if (zipcode == '5370') city = 'Mesinge'; 
if (zipcode == '5380') city = 'Dalby'; 
if (zipcode == '5390') city = 'Martofte'; 
if (zipcode == '5400') city = 'Bogense'; 
if (zipcode == '5450') city = 'Otterup'; 
if (zipcode == '5462') city = 'Morud'; 
if (zipcode == '5463') city = 'Harndrup'; 
if (zipcode == '5464') city = 'Brenderup Fyn'; 
if (zipcode == '5466') city = 'Asperup'; 
if (zipcode == '5471') city = 'Søndersø'; 
if (zipcode == '5474') city = 'Veflinge'; 
if (zipcode == '5485') city = 'Skamby'; 
if (zipcode == '5491') city = 'Blommenslyst'; 
if (zipcode == '5492') city = 'Vissenbjerg'; 
if (zipcode == '5500') city = 'Middelfart'; 
if (zipcode == '5540') city = 'Ullerslev'; 
if (zipcode == '5550') city = 'Langeskov'; 
if (zipcode == '5560') city = 'Aarup'; 
if (zipcode == '5580') city = 'Nørre Aaby'; 
if (zipcode == '5591') city = 'Gelsted'; 
if (zipcode == '5592') city = 'Ejby'; 
if (zipcode == '5600') city = 'Faaborg'; 
if (zipcode == '5610') city = 'Assens'; 
if (zipcode == '5620') city = 'Glamsbjerg'; 
if (zipcode == '5631') city = 'Ebberup'; 
if (zipcode == '5642') city = 'Millinge'; 
if (zipcode == '5672') city = 'Broby'; 
if (zipcode == '5683') city = 'Haarby'; 
if (zipcode == '5690') city = 'Tommerup'; 
if (zipcode == '5700') city = 'Svendborg'; 
if (zipcode == '5750') city = 'Ringe'; 
if (zipcode == '5762') city = 'Vester Skerninge'; 
if (zipcode == '5771') city = 'Stenstrup'; 
if (zipcode == '5772') city = 'Kværndrup'; 
if (zipcode == '5792') city = 'Årslev'; 
if (zipcode == '5800') city = 'Nyborg'; 
if (zipcode == '5853') city = 'Ørbæk'; 
if (zipcode == '5854') city = 'Gislev'; 
if (zipcode == '5856') city = 'Ryslinge'; 
if (zipcode == '5863') city = 'Ferritslev Fyn'; 
if (zipcode == '5871') city = 'Frørup'; 
if (zipcode == '5874') city = 'Hesselager'; 
if (zipcode == '5881') city = 'Skårup Fyn'; 
if (zipcode == '5882') city = 'Vejstrup'; 
if (zipcode == '5883') city = 'Oure'; 
if (zipcode == '5884') city = 'Gudme'; 
if (zipcode == '5892') city = 'Gudbjerg Sydfyn'; 
if (zipcode == '5900') city = 'Rudkøbing'; 
if (zipcode == '5932') city = 'Humble'; 
if (zipcode == '5935') city = 'Bagenkop'; 
if (zipcode == '5953') city = 'Tranekær'; 
if (zipcode == '5960') city = 'Marstal'; 
if (zipcode == '5970') city = 'Ærøskøbing'; 
if (zipcode == '5985') city = 'Søby Ærø'; 
if (zipcode == '6000') city = 'Kolding'; 
if (zipcode == '6040') city = 'Egtved'; 
if (zipcode == '6051') city = 'Almind'; 
if (zipcode == '6052') city = 'Viuf'; 
if (zipcode == '6064') city = 'Jordrup'; 
if (zipcode == '6070') city = 'Christiansfeld'; 
if (zipcode == '6091') city = 'Bjert'; 
if (zipcode == '6092') city = 'Sønder Stenderup'; 
if (zipcode == '6093') city = 'Sjølund'; 
if (zipcode == '6094') city = 'Hejls'; 
if (zipcode == '6100') city = 'Haderslev'; 
if (zipcode == '6200') city = 'Aabenraa'; 
if (zipcode == '6230') city = 'Rødekro'; 
if (zipcode == '6240') city = 'Løgumkloster'; 
if (zipcode == '6261') city = 'Bredebro'; 
if (zipcode == '6270') city = 'Tønder'; 
if (zipcode == '6280') city = 'Højer'; 
if (zipcode == '6300') city = 'Gråsten'; 
if (zipcode == '6310') city = 'Broager'; 
if (zipcode == '6320') city = 'Egernsund'; 
if (zipcode == '6330') city = 'Padborg'; 
if (zipcode == '6340') city = 'Kruså'; 
if (zipcode == '6360') city = 'Tinglev'; 
if (zipcode == '6372') city = 'Bylderup-Bov'; 
if (zipcode == '6392') city = 'Bolderslev'; 
if (zipcode == '6400') city = 'Sønderborg'; 
if (zipcode == '6430') city = 'Nordborg'; 
if (zipcode == '6440') city = 'Augustenborg'; 
if (zipcode == '6470') city = 'Sydals'; 
if (zipcode == '6500') city = 'Vojens'; 
if (zipcode == '6510') city = 'Gram'; 
if (zipcode == '6520') city = 'Toftlund'; 
if (zipcode == '6534') city = 'Agerskov'; 
if (zipcode == '6535') city = 'Branderup J'; 
if (zipcode == '6541') city = 'Bevtoft'; 
if (zipcode == '6560') city = 'Sommersted'; 
if (zipcode == '6580') city = 'Vamdrup'; 
if (zipcode == '6600') city = 'Vejen'; 
if (zipcode == '6621') city = 'Gesten'; 
if (zipcode == '6622') city = 'Bække'; 
if (zipcode == '6623') city = 'Vorbasse'; 
if (zipcode == '6630') city = 'Rødding'; 
if (zipcode == '6640') city = 'Lunderskov'; 
if (zipcode == '6650') city = 'Brørup'; 
if (zipcode == '6660') city = 'Lintrup'; 
if (zipcode == '6670') city = 'Holsted'; 
if (zipcode == '6682') city = 'Hovborg'; 
if (zipcode == '6683') city = 'Føvling'; 
if (zipcode == '6690') city = 'Gørding'; 
if (zipcode == '6700') city = 'Esbjerg'; 
if (zipcode == '6701') city = 'Esbjerg'; 
if (zipcode == '6705') city = 'Esbjerg Ø'; 
if (zipcode == '6710') city = 'Esbjerg V'; 
if (zipcode == '6715') city = 'Esbjerg N'; 
if (zipcode == '6720') city = 'Fanø'; 
if (zipcode == '6731') city = 'Tjæreborg'; 
if (zipcode == '6740') city = 'Bramming'; 
if (zipcode == '6752') city = 'Glejbjerg'; 
if (zipcode == '6753') city = 'Agerbæk'; 
if (zipcode == '6760') city = 'Ribe'; 
if (zipcode == '6771') city = 'Gredstedbro'; 
if (zipcode == '6780') city = 'Skærbæk'; 
if (zipcode == '6792') city = 'Rømø'; 
if (zipcode == '6800') city = 'Varde'; 
if (zipcode == '6818') city = 'Årre'; 
if (zipcode == '6823') city = 'Ansager'; 
if (zipcode == '6830') city = 'Nørre Nebel'; 
if (zipcode == '6840') city = 'Oksbøl'; 
if (zipcode == '6851') city = 'Janderup Vestj'; 
if (zipcode == '6852') city = 'Billum'; 
if (zipcode == '6853') city = 'Vejers Strand'; 
if (zipcode == '6854') city = 'Henne'; 
if (zipcode == '6855') city = 'Outrup'; 
if (zipcode == '6857') city = 'Blåvand'; 
if (zipcode == '6862') city = 'Tistrup'; 
if (zipcode == '6870') city = 'Ølgod'; 
if (zipcode == '6880') city = 'Tarm'; 
if (zipcode == '6893') city = 'Hemmet'; 
if (zipcode == '6900') city = 'Skjern'; 
if (zipcode == '6920') city = 'Videbæk'; 
if (zipcode == '6933') city = 'Kibæk'; 
if (zipcode == '6940') city = 'Lem St'; 
if (zipcode == '6950') city = 'Ringkøbing'; 
if (zipcode == '6960') city = 'Hvide Sande'; 
if (zipcode == '6971') city = 'Spjald'; 
if (zipcode == '6973') city = 'Ørnhøj'; 
if (zipcode == '6980') city = 'Tim'; 
if (zipcode == '6990') city = 'Ulfborg'; 
if (zipcode == '7000') city = 'Fredericia'; 
if (zipcode == '7007') city = 'Fredericia'; 
if (zipcode == '7029') city = 'Fredericia'; 
if (zipcode == '7080') city = 'Børkop'; 
if (zipcode == '7100') city = 'Vejle'; 
if (zipcode == '7120') city = 'Vejle Øst'; 
if (zipcode == '7130') city = 'Juelsminde'; 
if (zipcode == '7140') city = 'Stouby'; 
if (zipcode == '7150') city = 'Barrit'; 
if (zipcode == '7160') city = 'Tørring'; 
if (zipcode == '7171') city = 'Uldum'; 
if (zipcode == '7173') city = 'Vonge'; 
if (zipcode == '7182') city = 'Bredsten'; 
if (zipcode == '7183') city = 'Randbøl'; 
if (zipcode == '7184') city = 'Vandel'; 
if (zipcode == '7190') city = 'Billund'; 
if (zipcode == '7200') city = 'Grindsted'; 
if (zipcode == '7250') city = 'Hejnsvig'; 
if (zipcode == '7260') city = 'Sønder Omme'; 
if (zipcode == '7270') city = 'Stakroge'; 
if (zipcode == '7280') city = 'Sønder Felding'; 
if (zipcode == '7300') city = 'Jelling'; 
if (zipcode == '7321') city = 'Gadbjerg'; 
if (zipcode == '7323') city = 'Give'; 
if (zipcode == '7330') city = 'Brande'; 
if (zipcode == '7361') city = 'Ejstrupholm'; 
if (zipcode == '7362') city = 'Hampen'; 
if (zipcode == '7400') city = 'Herning'; 
if (zipcode == '7429') city = 'Herning'; 
if (zipcode == '7430') city = 'Ikast'; 
if (zipcode == '7441') city = 'Bording'; 
if (zipcode == '7442') city = 'Engesvang'; 
if (zipcode == '7451') city = 'Sunds'; 
if (zipcode == '7470') city = 'Karup J'; 
if (zipcode == '7480') city = 'Vildbjerg'; 
if (zipcode == '7490') city = 'Aulum'; 
if (zipcode == '7500') city = 'Holstebro'; 
if (zipcode == '7540') city = 'Haderup'; 
if (zipcode == '7550') city = 'Sørvad'; 
if (zipcode == '7560') city = 'Hjerm'; 
if (zipcode == '7570') city = 'Vemb'; 
if (zipcode == '7600') city = 'Struer'; 
if (zipcode == '7620') city = 'Lemvig'; 
if (zipcode == '7650') city = 'Bøvlingbjerg'; 
if (zipcode == '7660') city = 'Bækmarksbro'; 
if (zipcode == '7673') city = 'Harboøre'; 
if (zipcode == '7680') city = 'Thyborøn'; 
if (zipcode == '7700') city = 'Thisted'; 
if (zipcode == '7730') city = 'Hanstholm'; 
if (zipcode == '7741') city = 'Frøstrup'; 
if (zipcode == '7742') city = 'Vesløs'; 
if (zipcode == '7752') city = 'Snedsted'; 
if (zipcode == '7755') city = 'Bedsted Thy'; 
if (zipcode == '7760') city = 'Hurup Thy'; 
if (zipcode == '7770') city = 'Vestervig'; 
if (zipcode == '7790') city = 'Thyholm'; 
if (zipcode == '7800') city = 'Skive'; 
if (zipcode == '7830') city = 'Vinderup'; 
if (zipcode == '7840') city = 'Højslev'; 
if (zipcode == '7850') city = 'Stoholm Jyll'; 
if (zipcode == '7860') city = 'Spøttrup'; 
if (zipcode == '7870') city = 'Roslev'; 
if (zipcode == '7884') city = 'Fur'; 
if (zipcode == '7900') city = 'Nykøbing M'; 
if (zipcode == '7950') city = 'Erslev'; 
if (zipcode == '7960') city = 'Karby'; 
if (zipcode == '7970') city = 'Redsted M'; 
if (zipcode == '7980') city = 'Vils'; 
if (zipcode == '7990') city = 'Øster Assels'; 
if (zipcode == '7992') city = 'Sydjylland/Fyn USF B'; 
if (zipcode == '7992') city = 'Sydjylland/Fyn USF P'; 
if (zipcode == '7999') city = 'Kommunepost'; 
if (zipcode == '8000') city = 'Århus C'; 
if (zipcode == '8100') city = 'Århus C'; 
if (zipcode == '8200') city = 'Århus N'; 
if (zipcode == '8210') city = 'Århus V'; 
if (zipcode == '8220') city = 'Brabrand'; 
if (zipcode == '8229') city = 'Risskov Ø'; 
if (zipcode == '8230') city = 'Åbyhøj'; 
if (zipcode == '8240') city = 'Risskov'; 
if (zipcode == '8245') city = 'Risskov Ø'; 
if (zipcode == '8250') city = 'Egå'; 
if (zipcode == '8260') city = 'Viby J'; 
if (zipcode == '8270') city = 'Højbjerg'; 
if (zipcode == '8300') city = 'Odder'; 
if (zipcode == '8305') city = 'Samsø'; 
if (zipcode == '8310') city = 'Tranbjerg J'; 
if (zipcode == '8320') city = 'Mårslet'; 
if (zipcode == '8330') city = 'Beder'; 
if (zipcode == '8340') city = 'Malling'; 
if (zipcode == '8350') city = 'Hundslund'; 
if (zipcode == '8355') city = 'Solbjerg'; 
if (zipcode == '8361') city = 'Hasselager'; 
if (zipcode == '8362') city = 'Hørning'; 
if (zipcode == '8370') city = 'Hadsten'; 
if (zipcode == '8380') city = 'Trige'; 
if (zipcode == '8381') city = 'Tilst'; 
if (zipcode == '8382') city = 'Hinnerup'; 
if (zipcode == '8400') city = 'Ebeltoft'; 
if (zipcode == '8410') city = 'Rønde'; 
if (zipcode == '8420') city = 'Knebel'; 
if (zipcode == '8444') city = 'Balle'; 
if (zipcode == '8450') city = 'Hammel'; 
if (zipcode == '8462') city = 'Harlev J'; 
if (zipcode == '8464') city = 'Galten'; 
if (zipcode == '8471') city = 'Sabro'; 
if (zipcode == '8472') city = 'Sporup'; 
if (zipcode == '8500') city = 'Grenaa'; 
if (zipcode == '8520') city = 'Lystrup'; 
if (zipcode == '8530') city = 'Hjortshøj'; 
if (zipcode == '8541') city = 'Skødstrup'; 
if (zipcode == '8543') city = 'Hornslet'; 
if (zipcode == '8544') city = 'Mørke'; 
if (zipcode == '8550') city = 'Ryomgård'; 
if (zipcode == '8560') city = 'Kolind'; 
if (zipcode == '8570') city = 'Trustrup'; 
if (zipcode == '8581') city = 'Nimtofte'; 
if (zipcode == '8585') city = 'Glesborg'; 
if (zipcode == '8586') city = 'Ørum Djurs'; 
if (zipcode == '8592') city = 'Anholt'; 
if (zipcode == '8600') city = 'Silkeborg'; 
if (zipcode == '8620') city = 'Kjellerup'; 
if (zipcode == '8632') city = 'Lemming'; 
if (zipcode == '8641') city = 'Sorring'; 
if (zipcode == '8643') city = 'Ans By'; 
if (zipcode == '8653') city = 'Them'; 
if (zipcode == '8654') city = 'Bryrup'; 
if (zipcode == '8660') city = 'Skanderborg'; 
if (zipcode == '8670') city = 'Låsby'; 
if (zipcode == '8680') city = 'Ry'; 
if (zipcode == '8700') city = 'Horsens'; 
if (zipcode == '8721') city = 'Daugård'; 
if (zipcode == '8722') city = 'Hedensted'; 
if (zipcode == '8723') city = 'Løsning'; 
if (zipcode == '8732') city = 'Hovedgård'; 
if (zipcode == '8740') city = 'Brædstrup'; 
if (zipcode == '8751') city = 'Gedved'; 
if (zipcode == '8752') city = 'Østbirk'; 
if (zipcode == '8762') city = 'Flemming'; 
if (zipcode == '8763') city = 'Rask Mølle'; 
if (zipcode == '8765') city = 'Klovborg'; 
if (zipcode == '8766') city = 'Nørre Snede'; 
if (zipcode == '8781') city = 'Stenderup'; 
if (zipcode == '8783') city = 'Hornsyld'; 
if (zipcode == '8800') city = 'Viborg'; 
if (zipcode == '8830') city = 'Tjele'; 
if (zipcode == '8831') city = 'Løgstrup'; 
if (zipcode == '8832') city = 'Skals'; 
if (zipcode == '8840') city = 'Rødkærsbro'; 
if (zipcode == '8850') city = 'Bjerringbro'; 
if (zipcode == '8860') city = 'Ulstrup'; 
if (zipcode == '8870') city = 'Langå'; 
if (zipcode == '8881') city = 'Thorsø'; 
if (zipcode == '8882') city = 'Fårvang'; 
if (zipcode == '8883') city = 'Gjern'; 
if (zipcode == '8900') city = 'Randers C'; 
if (zipcode == '8920') city = 'Randers NV'; 
if (zipcode == '8930') city = 'Randers NØ'; 
if (zipcode == '8940') city = 'Randers SV'; 
if (zipcode == '8950') city = 'Ørsted'; 
if (zipcode == '8960') city = 'Randers SØ'; 
if (zipcode == '8961') city = 'Allingåbro'; 
if (zipcode == '8963') city = 'Auning'; 
if (zipcode == '8970') city = 'Havndal'; 
if (zipcode == '8981') city = 'Spentrup'; 
if (zipcode == '8983') city = 'Gjerlev J'; 
if (zipcode == '8990') city = 'Fårup'; 
if (zipcode == '9000') city = 'Aalborg'; 
if (zipcode == '9029') city = 'Aalborg'; 
if (zipcode == '9100') city = 'Aalborg'; 
if (zipcode == '9200') city = 'Aalborg SV'; 
if (zipcode == '9210') city = 'Aalborg SØ'; 
if (zipcode == '9220') city = 'Aalborg Øst'; 
if (zipcode == '9230') city = 'Svenstrup J'; 
if (zipcode == '9240') city = 'Nibe'; 
if (zipcode == '9260') city = 'Gistrup'; 
if (zipcode == '9270') city = 'Klarup'; 
if (zipcode == '9280') city = 'Storvorde'; 
if (zipcode == '9293') city = 'Kongerslev'; 
if (zipcode == '9300') city = 'Sæby'; 
if (zipcode == '9310') city = 'Vodskov'; 
if (zipcode == '9320') city = 'Hjallerup'; 
if (zipcode == '9330') city = 'Dronninglund'; 
if (zipcode == '9340') city = 'Asaa'; 
if (zipcode == '9352') city = 'Dybvad'; 
if (zipcode == '9362') city = 'Gandrup'; 
if (zipcode == '9370') city = 'Hals'; 
if (zipcode == '9380') city = 'Vestbjerg'; 
if (zipcode == '9381') city = 'Sulsted'; 
if (zipcode == '9382') city = 'Tylstrup'; 
if (zipcode == '9400') city = 'Nørresundby'; 
if (zipcode == '9430') city = 'Vadum'; 
if (zipcode == '9440') city = 'Aabybro'; 
if (zipcode == '9460') city = 'Brovst'; 
if (zipcode == '9480') city = 'Løkken'; 
if (zipcode == '9490') city = 'Pandrup'; 
if (zipcode == '9492') city = 'Blokhus'; 
if (zipcode == '9493') city = 'Saltum'; 
if (zipcode == '9500') city = 'Hobro'; 
if (zipcode == '9510') city = 'Arden'; 
if (zipcode == '9520') city = 'Skørping'; 
if (zipcode == '9530') city = 'Støvring'; 
if (zipcode == '9541') city = 'Suldrup'; 
if (zipcode == '9550') city = 'Mariager'; 
if (zipcode == '9560') city = 'Hadsund'; 
if (zipcode == '9574') city = 'Bælum'; 
if (zipcode == '9575') city = 'Terndrup'; 
if (zipcode == '9600') city = 'Aars'; 
if (zipcode == '9610') city = 'Nørager'; 
if (zipcode == '9620') city = 'Aalestrup'; 
if (zipcode == '9631') city = 'Gedsted'; 
if (zipcode == '9632') city = 'Møldrup'; 
if (zipcode == '9640') city = 'Farsø'; 
if (zipcode == '9670') city = 'Løgstør'; 
if (zipcode == '9681') city = 'Ranum'; 
if (zipcode == '9690') city = 'Fjerritslev'; 
if (zipcode == '9700') city = 'Brønderslev'; 
if (zipcode == '9740') city = 'Jerslev J'; 
if (zipcode == '9750') city = 'Østervrå'; 
if (zipcode == '9760') city = 'Vrå'; 
if (zipcode == '9800') city = 'Hjørring'; 
if (zipcode == '9830') city = 'Tårs'; 
if (zipcode == '9850') city = 'Hirtshals'; 
if (zipcode == '9870') city = 'Sindal'; 
if (zipcode == '9881') city = 'Bindslev'; 
if (zipcode == '9900') city = 'Frederikshavn'; 
if (zipcode == '9940') city = 'Læsø'; 
if (zipcode == '9970') city = 'Strandby'; 
if (zipcode == '9981') city = 'Jerup'; 
if (zipcode == '9982') city = 'Ålbæk'; 
if (zipcode == '9990') city = 'Skagen';

//alert(city);
if( fieldID == 'ship_postcode' ) {
  if (city!=null && city!='') document.getElementById('ship_city').value = city;
} else {
  if (city!=null && city!='') document.getElementById('city').value = city;
}   
    
}


// function that handles the HTTP response
function handleRequestStateChange() 
{
  // when readyState is 4, we read the server response
  if (xmlHttp.readyState == 4) 
  {
    // continue only if HTTP status is "OK"
    if (xmlHttp.status == 200) 
    {
      try
      {
        // read the response from the server
        readResponse();
      }
      catch(e)
 
      {
        // display error message
        displayError(e.toString());
      }
    }
    else
    {
      // display error message
      displayError(xmlHttp.statusText);
    }
  }
}

// read server's response 
function readResponse()
{
  // retrieve the server's response 
  var response = xmlHttp.responseText;
  // server error?
  if (response.indexOf("ERRNO") >= 0 
      || response.indexOf("error:") >= 0
      || response.length == 0)
    throw(response.length == 0 ? "Server error." : response);
  // get response in XML format (assume the response is valid XML)
  responseXml = xmlHttp.responseXML;
  // get the document element
  xmlDoc = responseXml.documentElement;
  //get the name, lastname etc.
  error = xmlDoc.getElementsByTagName("error")[0].firstChild.data;
  
  if (error == "0")
  {
  firstname = xmlDoc.getElementsByTagName("firstname")[0].firstChild.data;
  lastname = xmlDoc.getElementsByTagName("lastname")[0].firstChild.data;
  address = xmlDoc.getElementsByTagName("address")[0].firstChild.data;
  postcode = xmlDoc.getElementsByTagName("postcode")[0].firstChild.data;
  city = xmlDoc.getElementsByTagName("city")[0].firstChild.data;
  
  document.getElementById("telephoneFailed").innerHTML = '';
  if (firstname != null && firstname!='empty')  document.getElementById("firstname").value = firstname;
  if (lastname != null && lastname!='empty')  document.getElementById("lastname").value = lastname;
  if (address != null && address!='empty')  document.getElementById("street_address").value = address;
  if (postcode != null && postcode!='empty')  document.getElementById("postcode").value = postcode;
  if (city != null && city!='empty')  document.getElementById("city").value = city;
  
  if (firstname != null && firstname=='empty')  document.getElementById("firstname").value = '';
  if (lastname != null && lastname=='empty')  document.getElementById("lastname").value = '';
  if (address != null && address=='empty')  document.getElementById("street_address").value = '';
  if (postcode != null && postcode=='empty')  document.getElementById("postcode").value = '';
  if (city != null && city=='empty')  document.getElementById("city").value = '';
  
  }
  else
  {
  // find the HTML element that displays the error
  message = document.getElementById("telephoneFailed");
  message.innerHTML = error;
  message.style.display = 'block';

  document.getElementById("firstname").value = '';
  document.getElementById("lastname").value = '';
  document.getElementById("street_address").value = '';
  document.getElementById("postcode").value = '';
  document.getElementById("city").value = '';

  }
  // call validate() again, in case there are values left in the cache
//  setTimeout("validate();", 500);
}

// sets focus on the first field of the form
function setFocus()    
{
  document.getElementById("telephone").focus();
}

