<!-- Helper functions to interface with the NuGram Hosted Server -->
<!-- Copyright (C) 2008, Nu Echo Inc.                            -->

<!-- Variable required by the NuGram Server HTTP interface -->
var resource = null;
var context = null;
var account = null;
var password = null;
var operation = 'POST';

<!-- Internal variables -->
var GS_grammarServer = null;
var GS_sessionId = null;

<!-- Helper functions -->
function setupGrammarServer(address, acc, pwd) {
  GS_grammarServer = 'http://' + address;
  account = acc;
  password = pwd;
}

function serverUrl() { 
  return GS_grammarServer + '/voiceXML'; 
}

function grammarUrl(uri) {
  return GS_grammarServer + '/grammar/' + GS_sessionId + '/' + uri; 
}

function setupSessionId(xmlDoc) { 
  GS_sessionId = xmlDoc.documentElement.attributes.getNamedItem('id').value; 
}

function getGrammarUri(xmlDoc) { 
  var fullUri = xmlDoc.documentElement.attributes.getNamedItem('uri').value;
  return fullUri.substring('/grammar/'.length);
}

function initiateSessionCreation() {
  operation = 'POST'
  resource = 'session';
}

function initiateSessionDestroy() {
  operation = 'DELETE';
  resource = 'session/' + GS_sessionId;
}

function initiateInstantiation(name, ctx) {
   operation = 'POST';
   resource = '/grammar/' + GS_sessionId + name; 
   context = JSON.stringify(ctx);
}