/* YAHOO does does support non-asynchronous calls and this is what is needed here... old school stuff here!!! */
// ---------------------------------------------------------------------------------------------------------- //
function createXMLHttpRequestObject()
{
  var http = null;
  if(window.XMLHttpRequest) { http = new XMLHttpRequest(); }
  else if(window.ActiveXObject) { http = new ActiveXObject("Microsoft.XMLHTTP"); }
  return http;
}

function get_xmlwait(http, url)
{
  _xmlHttpRequest_sendRequest(http, false, "GET", url, null, null);
}

function _xmlHttpRequest_sendRequest(http, async, method, url, callback_func, postdata)
{
  methodOK = false;
  if(method == "GET") {
    methodOK = true;
    http.open(method, url, async);
  }
  else if(method == "POST") {
    methodOK = true;
    http.open(method, url, async);
    http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.setRequestHeader('Accept-Charset','ISO-8859-1');
  }

  if(methodOK) {
    if(async) {
      if(callback_func != null) {
        http.onreadystatechange = callback_func;
      }
    }
    if(method == "POST") { http.send(postdata); }
    else { http.send(null); }
  }
}
// ---------------------------------------------------------------------------------------------------------- //

validatepc_http = null;
function isValidPostalCode(pc, onValid, accept_fsa)
{
  if(accept_fsa == null) accept_fsa = false;
  if(validatepc_http == null) validatepc_http = createXMLHttpRequestObject();
  var url = "/site/support/validatepc.spy?pc=" + escape(pc.value);
  if(accept_fsa) url += "&accept_fsa=1";
  get_xmlwait(validatepc_http, url);
  response = validatepc_http.responseText;
  if(response != "" && response.charAt(0) == "{") {
    eval("var data = (" + response + ")");
    if(data.valid) {
      if(onValid != null) onValid(pc, data);
    }
    return data.valid;
  }
  return false;
}

function isValidPostalCode_cb(pc, data) {
  pc.value = data.pc;
}
