/*
Command to look up info on an IP.
Uses ip-address.com/ip_tracer
*/
CmdUtils.CreateCommand({
  names: ["iptrace"],
  icon: "http://www.mozilla.com/favicon.ico",
  description: "Trace an IP Address.",
  help: "Either highlight an IP on the page or enter an IP with the command.  The preview pane should show information about the IP address and if you press enter it will create a new tab with more information.",
  author: {name: "Alex Beutel", email: "alex.beutel@gmail.com"},
  license: "GPL",
  homepage: "http://blog.ambmediadesign.com/",
  arguments: [{role: 'object', label: 'ip address', nountype: noun_arb_text}],
  preview: function preview(pblock, args) {
    var self = this;
    var url = "http://www.ip-adress.com/ip_tracer/"+args.object.text;
    var prev = pblock;
    pblock.innerHTML = "IP to search is <b>" + args.object.text + "</b>.<br /> AJAX go!";
    $.ajax({
       type: "GET",
       url: url,
       async: true,
       success: function(html) {
			prev.innerHTML = "";
			$(html).find("div")
				.filter(function (index) { 
					return $(this).attr("id") == "ipinfo"; 
				})
				.each(function(){ 
					var item_text = $(this).html(); 
					prev.innerHTML += item_text + "<br />"; 
				});
       }
    });
  },
  execute: function execute(args) {
    Utils.openUrlInBrowser("http://www.ip-adress.com/ip_tracer/" + args.object.text);
  }
});

