function updateadres_a(postcode, huisnummer)
{
  new Ajax.Request('/postcodelookup', {
    parameters: {
      postcode: postcode,
      huisnummer: huisnummer
    },
    onComplete: function(response, json) {
      for (i in json) {
        if (i == 'straat') {
          $('a_straat').value = json[i];
        }
        if (i == 'plaats') {
          $('a_plaats').value = json[i];
        }
      }
    }
  });
}

function checkadres_a()
{
  var postcode = $F('a_postcode');
  var huisnummer = $F('a_huisnummer');
  if ((postcode != '') && (huisnummer != '')) {
    updateadres_a(postcode, huisnummer);
  }
}

function updateadres_b(postcode, huisnummer)
{
  new Ajax.Request('/postcodelookup', {
    parameters: {
      postcode: postcode,
      huisnummer: huisnummer
    },
    onComplete: function(response, json) {
      for (i in json) {
        if (i == 'straat') {
          $('b_straat').value = json[i];
        }
        if (i == 'plaats') {
          $('b_plaats').value = json[i];
        }
      }
    }
  });
}

function checkadres_b()
{
  var postcode = $F('b_postcode');
  var huisnummer = $F('b_huisnummer');
  if ((postcode != '') && (huisnummer != '')) {
    updateadres_b(postcode, huisnummer);
  }
}

function checkform()
{
  if ($F('b_land') == 'NL') {
    $('b_straat').addClassName('readonly');
    $('b_straat').readOnly = true;
    $('b_plaats').addClassName('readonly');
    $('b_plaats').readOnly = true;
  }
  else {
    $('b_straat').removeClassName('readonly');
    $('b_straat').readOnly = false;
    $('b_plaats').removeClassName('readonly');
    $('b_plaats').readOnly = false;
  }
}

window.onload = function() { 
  checkform();
}
