var address, page, system;

page = require("webpage").create();

system = require("system");

address = void 0;

if (system.args.length === 1) {
  console.log("Usage: netlog.js <some URL>");
  phantom.exit(1);
} else {

  // page.onResourceRequested = function (req) {
  //   console.log('requested: ' + JSON.stringify(req, undefined, 4));
  // };
  
  // page.onResourceReceived = function (res) {
  //   console.log('received: ' + JSON.stringify(res, undefined, 4));
  // };
  translate = function(langFrom, langTo, txt) {
		var ret = 'fail'
  address = 'https://www.googleapis.com/language/translate/v2?key=AIzaSyAtSdna9KErU3SjYc96Qwd1zre8rRw70F8&q=' + system.args[3] + '&source=' + system.args[1] + '&target=' + system.args[2];
	console.log(address)
  page.open(address, function(status) {
    if (status !== "success") {
			ret = "FAIL to load the address"
      console.log("FAIL to load the address");
    } else {
			ret = page.content
      console.log(page.content);
    }
		return ret
  });
  };
	var ret = "timeout"
	// while loop here
  ret = translate("en", "es", "Work order id");

	console.log(ret);
  phantom.exit(1);
	
}

