try {
  // load for nq='t'
  eval(_enq_loadfunc("/js-common/util/jslb_ajax_c.js"));
  eval(_enq_loadfunc("/js-common/util/zipcode.js"));
  eval(_enq_loadfunc("/js-common/common.js"));
  eval(_enq_loadfunc("/js-common/cookie.js"));
  eval(_enq_loadfunc("/js-common/cookiechk.js"));
  document.write('<link href="' + location.protocol + '//' + location.host + '/lib-common/common.css" rel="stylesheet" type="text/css">');
}
catch (e) {
}

function enqarg() {}

enqarg.prototype = {
  id: null,
  no: null,
  subject: "",
  customer_title: "",
  mode: "",
  fin_url: "",
  mailto: "",
  language: "",
  c: "",
  nn: "",
  nq: "",
  tagid: "enqform",
  template: "",
  iframe: "",
  width: null,
  height: null
};

function enqform(arg)
{
  if (arg.id == null) {
    alert("id is not defined.");
    return;
  }
  if (arg.no == null) {
    alert("no is not defined.");
    return;
  }

  var o = document.getElementById(arg.tagid);
  if (o == null) {
    alert('id="' + arg.tagid + '" does not found');
    return;
  }

  var q = "";
  var arr = window.location.search.substring(1).split('&');
  for (var i = 0; i < arr.length; i++) {
    var val = arr[i].split('=', 2);
    if (val[0] == 'q') {
      q = val[1];
    }
  }
  if (document.referrer && (document.referrer.indexOf('google') > 0)) {
    q = 'google';
  }

  if (!arg.nq || (arg.nq != "t")) {
    iframeform(arg, o, q);
    return;
  }

  // nq = 't'
  try {
    var url = location.protocol + '//' + location.host + '/php/enqform.php';
    var data = {
      "id": arg.id,
      "no": arg.no,
      "q": q,
      "c": arg.c,
      "nn": arg.nn,
      "nq": arg.nq,
      "sj": arg.subject,
      "ct": arg.customer_title,
      "md": arg.mode,
      "mt": arg.mailto,
      "l": arg.language,
      "t": arg.template,
      "fu": escape(arg.fin_url),
      "js": true,
      "if": false
    };
    var req = sendRequest(function(){}, data, 'POST', url, false);
    if (!req.responseText) {
      alert('Error: Cannot access enquete form');
      //return;
    }
    o.innerHTML = req.responseText;
    try {
      var arr = document.getElementsByName('txtZipcode');
      for (var i = 0; i < arr.length; i++) {
        if (arr[i].tagName == "INPUT") {
          arr[i].onkeyup = function() { zipcode.trans(this); };
        }
      }
    } catch (e) {}
  }
  catch (e) {
    iframeform(arg, o, q);
    return;
  }
}

function _enq_loadfunc(path)
{
  var xhr = null;
  var url = location.protocol + '//' + location.host + path;
  if (window.XMLHttpRequest) xhr = new XMLHttpRequest();
  else if (window.ActiveXObject)
    try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
  xhr.open("GET", url, false);
  xhr.send("");
  return xhr.responseText;
}

function iframeform(arg, o, q)
{
  var url = location.protocol + '//' + location.host + '/php/enqform.php?id=' + arg.id;
  var data = {
    "no": arg.no,
    "q": q,
    "c": arg.c,
    "nn": arg.nn,
    "nq": arg.nq,
    "sj": arg.subject,
    "ct": arg.customer_title,
    "md": arg.mode,
    "mt": arg.mailto,
    "l": arg.language,
    "t": arg.template,
    "fu": escape(arg.fin_url),
    "js": true,
    "if": (arg.iframe == '') ? true : arg.iframe
  };
  for (var i in data) {
    if (typeof data[i] == 'function') {
      continue;
    }
    url += '&' + i + '=' + data[i];
  }
  var oIframe = document.createElement('iframe');
  oIframe.frameBorder = "0";
  oIframe.scrolling = "no";
  oIframe.src = url;
  o.appendChild(oIframe);

  var _width = arg.width;
  var _height = arg.height;
  if (document.all && !window.opera) {
    oIframe.onreadystatechange = function() {
      if (this.readyState == 'complete') {
        var d = this.contentWindow.document;
        var w = d.body.scrollWidth;
        var h = d.body.scrollHeight;
        if (w < o.clientWidth) {
          w = o.clientWidth;
        }
        if (h < o.clientHeight) {
          h = o.clientHeight;
        }
        if (w < o.offsetWidth) {
          w = o.offsetWidth;
        }
        if (h < o.offsetHeight) {
          h = o.offsetHeight;
        }
        if (_width == null) {
          this.width = w;
        } else {
          this.width = _width;
        }
        if (_height == null) {
          this.height = h;
        } else {
          this.height = _height;
        }
        this.onreadysttechange = null;
      }
    };
  } else {
    oIframe.onload = function() {
      var d = this.contentWindow.document;
      var w = d.body.scrollWidth;
      if (w < o.clientWidth) {
        w = o.clientWidth;
      }
      if (w < o.offsetWidth) {
        w = o.offsetWidth;
      }
      if (_width == null) {
        this.width = w;
      } else {
        this.width = _width;
      }
      var h = d.body.scrollHeight;
      h += 10;
      if (this._margin) {
        h += this._margin;
      }
//      if (h < o.clientHeight) {
//        h = o.clientHeight;
//      }
//      if (h < o.offsetHeight) {
//        h = o.offsetHeight;
//      }
      if (_height == null) {
        this.height = h;
      } else {
        this.height = _height;
      }
    }
  }
}
