﻿//-----------------------------------------------------------------------
// Copyright (C) Motorwebs Corporation. All rights reserved.
//-----------------------------------------------------------------------
// Widgets Main

var __widget_contactForm = null;
var __widget_vehicleSearch = null;

function pageLoad() {
  __widget_contactForm = $find('widget-contactForm');
  __widget_vehicleSearch = $find('widget-vehicleSearch');
  if (location.hash != "") backButton(location.hash);
}

function onSuccess(response, context, methodName) {
  switch (context) {
    case 'contactFormSend':
      __widget_contactForm.onServiceSuccess(response);
      break;
    case 'vehicleSearch':
      __widget_vehicleSearch.onServiceSuccess(response);
      break;
  }
}

function onFailure(error, context, methodName) {
  var msg = "The " + methodName + " method called by " + context + " Failed! - " + error.get_message();
  alert(msg);
}

function backButton(hash) {

  var history = $common.createHistoryObj(hash);

  var request = new Motorwebs.NET35.Default.VehicleSearchRequest();
  request.name = "backButton";
  request.Condition = history.cond;
  request.PriceRange = history.pricerange;
  request.Year = history.year;
  request.Make = history.make;
  request.Model = history.model;
  Widgets.VehicleSearchEvents(request, onSuccess, onFailure, 'vehicleSearch');
}