
// this function will be called by our JSON callback
// the parameter jData will contain an array with postalcode objects
function getLocation(jData) {
  if (jData == null) {
    // There was a problem parsing search results
    return;
  }

  // save place array in 'postalcodes' to make it accessible from mouse event handlers
  postalcodes = jData.postalcodes;
  
  if (postalcodes.length == 1) {
      // exactly one place for postalcode
      // directly fill the form, no suggest box required 
      plz = postalcodes[0].postalcode;
	  
	  document.getElementById('wetter').innerHTML = '<img src="http://www.wetter.com/home/woys/woys.php?,C,2,' + country + 'PLZ,' + plz + '" border="0" alt="" style="border: 1px solid #ff9c00;">';
  }
}

// this function is called when the user leaves the postal code input field
// it call the geonames.org JSON webservice to fetch an array of places 
// for the given postal code 
function postalCodeLookup() {

  if(placename == 'Munich') {
  	placename = 'München';
  }
  
  request = 'http://ws.geonames.org/postalCodeLookupJSON?placename=' + placename  + '&country=' + country  + '&callback=getLocation&maxRows=1';

  // Create a new script object
  aObj = new JSONscriptRequest(request);
  // Build the script tag
  aObj.buildScriptTag();
  // Execute (add) the script tag
  aObj.addScriptTag();
}

