if(typeof(AUTO123) == "undefined") AUTO123 = new Object();

AUTO123.NewCars = function() {
  return {
    getDefaultCB: function(args) {
      return {
        success: AUTO123.NewCars.callback_ajax_success,
        failure: AUTO123.NewCars.callback_ajax_failure,
        argument: args
      }
    },

    callback_ajax_success: function(o) {
      var onSuccess = o.argument[0];
      var active = o.argument[2];
      if(onSuccess) {
        eval("var results = (" + o.responseText + ")");
        onSuccess(results, o);
      }
    },
    
    callback_ajax_failure: function(o) {
      var onFailure = o.argument[1];
      if(onFailure) {
        eval("var results = (" + o.responseText + ")");
        onFailure(results, o);
      }
    },    

    getMakes: function(active, onSuccess, onFailure) {
      if(active)
        active = 1;
      else
        active = 0;
      
      var url = "/site/support/ajax_get_makes.spy?active=" + encodeURIComponent(active.toString()) + "&t=" + encodeURIComponent(new Date().getTime().toString());
      var cb = AUTO123.NewCars.getDefaultCB([onSuccess, onFailure, active]);
      YAHOO.util.Connect.asyncRequest("GET", url, cb, null);
    },
    
    getBodyStyles: function(onSuccess, onFailure, language) {
      var url = "/site/support/ajax_get_bodystyles_simple.spy?language=" + encodeURIComponent(language) + "&t=" + encodeURIComponent(new Date().getTime().toString());
      var cb = AUTO123.NewCars.getDefaultCB([onSuccess, onFailure, null]);
      YAHOO.util.Connect.asyncRequest("GET", url, cb, null);
    },
    
    getPrices: function(onSuccess, onFailure, language) {
      var url = "/site/support/ajax_get_prices.spy?language=" + encodeURIComponent(language) + "&t=" + encodeURIComponent(new Date().getTime().toString());
      var cb = AUTO123.NewCars.getDefaultCB([onSuccess, onFailure, null]);
      YAHOO.util.Connect.asyncRequest("GET", url, cb, null);
    },
    
    getPerformanceOptions: function(onSuccess, onFailure, language) {
      var url = "/site/support/ajax_get_performanceoptions.spy?language=" + encodeURIComponent(language) + "&t=" + encodeURIComponent(new Date().getTime().toString());
      var cb = AUTO123.NewCars.getDefaultCB([onSuccess, onFailure, null]);
      YAHOO.util.Connect.asyncRequest("GET", url, cb, null);
    },
    
    getEquipment: function(onSuccess, onFailure, language) {
      var url = "/site/support/ajax_get_equipment.spy?language=" + encodeURIComponent(language) + "&t=" + encodeURIComponent(new Date().getTime().toString());
      var cb = AUTO123.NewCars.getDefaultCB([onSuccess, onFailure, null]);
      YAHOO.util.Connect.asyncRequest("GET", url, cb, null);
    },
    
    getFuelEconomy: function(onSuccess, onFailure, language) {
      var url = "/site/support/ajax_get_fueleconomy.spy?language=" + encodeURIComponent(language) + "&t=" + encodeURIComponent(new Date().getTime().toString());
      var cb = AUTO123.NewCars.getDefaultCB([onSuccess, onFailure, null]);
      YAHOO.util.Connect.asyncRequest("GET", url, cb, null);
    },
    
    getPowertrainOptions: function(onSuccess, onFailure, language) {
      var url = "/site/support/ajax_get_powertrain.spy?language=" + encodeURIComponent(language) + "&t=" + encodeURIComponent(new Date().getTime().toString());
      var cb = AUTO123.NewCars.getDefaultCB([onSuccess, onFailure, null]);
      YAHOO.util.Connect.asyncRequest("GET", url, cb, null);
    }
  }
}();
