// Generated by CoffeeScript 1.6.2
(function() {
  'use strict';
  var loadData, maAppName;

  maAppName = 'mgViewApp';

  window.maApp = angular.module(maAppName, ['ngRoute', 'maComponents']);

  maApp.config([
    '$routeProvider', function($routeProvider) {
      return $routeProvider.when('/', {
        templateUrl: 'view/mgPostcalc.html',
        controller: 'mgPostcalcCtrl'
      }).when('/main', {
        templateUrl: 'view/main.html',
        controller: 'MainCtrl'
      }).when('/co_input', {
        templateUrl: 'view/co_Input.html',
        controller: 'MainCtrl'
      }).when('/co_input_orig', {
        templateUrl: 'view/co_Input_orig.html',
        controller: 'MainCtrl'
      }).when('/messu', {
        templateUrl: 'view/messuesite_2013.html',
        controller: 'MainCtrl'
      }).otherwise({
        redirectTo: '/'
      });
    }
  ]);

  maApp.factory("AppData", function($rootScope) {
    return {
      message: "init",
      refreshCounter: 0
    };
  });

  angular.element(document).ready(function() {
    var data, data_json;

    if (window.ma.isDemo()) {
      data = ma_app.exampleData();
      data_json = JSON.stringify(data);
      return window.ma.FormEvent("SetData", data_json);
    }
  });

  window.log = function(msg) {
    if (console) {
      return console.log(msg);
    }
  };

  window.ma = {};

  window.ma.callbackMsg = "";

  window.ma.Data = {};

  window.ma_app = window.ma_app || {};

  loadData = function(data) {
    var $scope;

    $scope = angular.element(document.body).scope();
    return setTimeout(function() {
      return $scope.$broadcast("appDataChanged", data);
    }, 10);
  };

  window.ma.isDemo = function() {
    var isDemo, ua;

    ua = navigator.userAgent.toLowerCase();
    isDemo = true;
    if (/firefox/.test(ua)) {

    } else if (/safari/.test(ua)) {

    } else if (/chrome/.test(ua)) {

    } else if (/opera/.test(ua)) {

    } else if (/msie 7/.test(ua)) {
      isDemo = false;
    } else if (/msie/.test(ua)) {

    } else {
      isDemo = false;
    }
    return isDemo;
  };

  window.ma.Callback = function(msg) {
    var url;

    url = "#/" + Math.random() + "/callback.html";
    window.ma.callbackMsg = msg;
    return window.open(url, '_self', '', false);
  };

  window.ma.FormEvent = function(action, param) {
    var data, err, json, ret;

    json = "";
    ret = "";
    if (!action && ma.isDemo()) {
      data = ma_app.exampleData();
      loadData(data);
    } else {
      if (action === "AddData") {
        if (param) {
          json += param.replace("*ksQS*", "'");
        } else {
          ret = "'AddData' parameter is missing (ma.FormEvent)";
        }
      } else if (action === "SetData") {
        if (param) {
          json += param.replace("*ksQS*", "'");
          try {
            window.ma.Data = JSON.parse(json);
          } catch (_error) {
            err = _error;
            ret = "'SetData' JSON.parse failed (ma.FormEvent), error: " + err;
            alert(ret);
          }
          if (ret === "") {
            ret = "" + action;
            try {
              loadData(window.ma.Data);
            } catch (_error) {
              err = _error;
              ret = "'SetData' loadData() failed (ma.FormEvent), error: " + err;
              alert(ret);
            }
          }
        } else {
          ret = "'SetData' parameter is missing (ma.FormEvent)";
        }
      } else {
        ret = "No action defined: '" + param + "' (ma.FormEvent)";
      }
    }
    return ret;
  };

}).call(this);

/*
//@ sourceMappingURL=app.map
*/
