ch_p_url = "";

function ch_au(p,v) { if (v) { window.ch_p_url += '&' + p + '=' + v; } }
function ch_aue(p,v) { if (v) { ch_au(p,escape(v)); } }

(function () {
  var w = window;
  var d = document;
  var r = Math.round(Math.random() * 1000);
  var ip = false;
  var ref = document.referrer;

  var m = String(window.location.href).match(/#chitikatest=(.+)/);
  if (m) {
    ip = 'us';
    ref = "http://www.google.com/search?q="+m[1];
  } else if (String(window.location.href).match(/#chitikatest/)) {
    ip = 'us';
    ref = "http://www.google.com/search?q=mortgage";
  }

  if (typeof(w.ch_client) != "undefined"){
    w.ch_p_url = ((window.location.protocol=="https:") ? "https:" : "http:") + "//mm.chitika.net/minimall?type=pixel";
  }
  else{
    w.ch_p_url = ((window.location.protocol=="https:") ? "https:" : "http:") + "//searchnet.chitika.net/minimall?type=pixel";
  }

  ch_aue('client', w.ch_client);
  ch_aue('sid', w.ch_sid);
  ch_aue('url', window.location);
  ch_aue('ref', ref);
  ch_aue('ip', ip);
  ch_aue('account_tag', w.account_tag);
  ch_aue('tracker_id', w.ch_tracker_id);
  ch_au('cb', r);

  if (String(ref).match(/(google|search.yahoo|search.msn|search.live|ask|search.aol).com/)) {
    if (w.ch_js_callback) {
      eval(w.ch_js_callback);
    }
    if (w.ch_js_src_callback) {
      document.write(unescape("%3Cscript%20type%3D%22text/javascript%22%20src%3D%22"+w.ch_js_src_callback+"%22%3E%3C/script%3E"));
    }
    if (w.ch_img_callback) {
      document.write(unescape("%3Cimg%20src%3D%22"+w.ch_img_callback+"%22%20width%3D%221%22%20height%3D%221%22%20border%3D%220%22%20/%3E"));
    }
    if (w.ch_output == "img") {
      document.write(unescape("%3Cimg%20src%3D%22"+w.ch_p_url+"%22%20border%3D%220%22%20alt%3D%22%22%20/%3E"));
    } else {
      document.write(unescape("%3Cscript%20type%3D%22text/javascript%22%20src%3D%22"+w.ch_p_url+"%22%3E%3C/script%3E"));
    }
  } else {
    if (w.ch_js_callback) {
      w.ch_callback_type = "js";
      w.ch_callback_data = w.ch_js_callback;
    }
    if (w.ch_img_callback) {
      w.ch_callback_type = "img";
      w.ch_callback_data = w.ch_img_callback;
    }
    if (w.ch_js_src_callback) {
      w.ch_callback_type = "jssrc";
      w.ch_callback_data = w.ch_js_src_callback;
    }

    ch_aue('callback_type', w.ch_callback_type);
    ch_aue('callback_data', w.ch_callback_data);

    var s = d.createElement("script");
    s.type = "text/javascript";
    s.src = w.ch_p_url;
    s.text = "";
    d.getElementsByTagName("head")[0].appendChild(s);
  }

  w.ch_p_url = null;
  w.ch_sid = null;
})();
