text: ﻿/*
  CEncode a string 
  (== double up the quotes)
  You also have to do this for @literal strings  :(
  Non-literal strings have to encode \ (as \\), tabs and newslines as well
  */
  var cEncode= {
    encodeLiteral: function(source) {
      //loops through string inspecting charCodes and translating
      //returns encoded string 
      return source.replace(/"/g, '""');
    },
    encode: function(source) {
      //loops through string inspecting charCodes and translating
      //returns encoded string 
      var result = source;
      result= result.replace(/\\/g, '\\\\')
      result= result.replace(/\//g, '//')
      result= result.replace(/\n/g, '\\n')
      result= result.replace(/\r/g, '\\r')
      result= result.replace(/\t/g, '\\t')
      result= result.replace(/"/g, '\\"')
      return result; 
    },
    encodeFieldLiteral: function(sourceId, resultId) {
      //a simple helper for an input field or textarea
      //simple error trapping that ids are found
      var source= document.getElementById(sourceId);
      var result= document.getElementById(resultId);
      if (source == null) return false;
      if (result == null) return false;
      result.value= '@"' + this.encodeLiteral(source.value) + '"';
      return true;
    },
    encodeField: function(sourceId, resultId) {
      //a simple helper for an input field or textarea
      //simple error trapping that ids are found
      var source= document.getElementById(sourceId);
      var result= document.getElementById(resultId);
      if (source == null) return false;
      if (result == null) return false;
      result.value= this.encode(source.value);
      return true;
    }
  }