var req;
var fld;

function loadXMLDoc(url) 
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processReqChange() 
{
    // only if req shows "complete"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
         response  = req.responseXML.documentElement;
         method    = response.getElementsByTagName('method')[0].firstChild.data;
         result    = response.getElementsByTagName('result')[0].firstChild.data;
         eval(method + '(\'\', result)');
        } else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}

function hkasse_lookup() {  
  var pid = document.getElementById("hkasse_productnu");
  if(pid) {
    var pnu = pid.value; 
    var txt = document.getElementById("hkasse_txt");
    if(pnu == '') {
      if(txt) {
        txt.innerHTML = '';
      }
    }
    else {
      var url = "/wsp/shgdan/ajax.cgi?func=catalog.hkasse_lookup&JSON=&productnu="+pnu;
      jQuery.get(url,
        function(data){
          if(txt) {
            txt.innerHTML = data;
          }
        }
      );
    }
  }
}

function city_lookup() {  
  var zipcode = document.getElementById("ORDERS.D_ZIPCODE");
  var city = document.getElementById("ORDERS.D_CITY");
  var city_input = document.getElementById("city_input");
  if(zipcode && city && city_input) {
    var code = zipcode.value; 
    if(code != '') {
      var url = "/wsp/shgdan/ajax.cgi?func=order.zipcode&JSON=&o_zipcode="+code;
      jQuery.get(url,
        function(data){
          city.innerHTML = data;
          city_input.value = data; 
        }
      );
    }
  }
}
