// insert JavaScript source code here

var com;

if (!com) com = {};
if (!com.jdsi) com.jdsi = {};
com.jdsi.datasnaprest = {};

//this is the global variable
dsr = com.jdsi.datasnaprest;

(function () {
  //this base URL is using a relative path to avoid a cross domain issue
  var baseURL = "../../DataSnapREST/DataSnapREST.dll/datasnap/rest/tservermethods1/";

    com.jdsi.datasnaprest.echoString = echoString;
    com.jdsi.datasnaprest.reverseString = reverseString;
    com.jdsi.datasnaprest.reverseStringRaw = reverseStringRaw;
    com.jdsi.datasnaprest.getCustomer = getCustomer;
    com.jdsi.datasnaprest.setBaseURL = setBaseURL;

    function setBaseURL(url) {
      baseURL = url;
    }

    function echoString()
    { var s = utils.getJSONSync(baseURL, "EchoString", $("#echoin").val());
      $("#echoout").text(s.result[0]);
    }

    function reverseString()
    { var s = utils.getJSONSync(baseURL, "ReverseString",
        $("#reversein").val());
      $("#reverseout").text(s.result[0]);
    }

    function reverseStringRaw()
    { var s = utils.getRawStringSync(baseURL, "ReverseStringRaw",
        $("#reverserawin").val());
      $("#reverserawout").text(s);
    }

    function getCustomer(val)
    { var s = utils.getJSONSync(baseURL, "GetCustomer",
        $("#custno").val());
      if (s.result[0].Error) {
       $("#name").text(s.result[0].Error);
      }
      else
      {
        $("#name").text(s.result[0].Name);
        $("#city").text(s.result[0].City);
        $("#credlimit").text(s.result[0].CreditLimit);
        $("#active").text(s.result[0].Active);
      }
    }



})();
