JavaScript Libraries

The JavaScript libraries listed here are provided freely. We do ask that if you use these libraries, or these ideas, that you refer to us in your documentation and notes.

Ajax

Required libraries

Syntax

var oAjax = new Cathmhaol.Ajax();

Methods:

  • void displayError(string message)
    Displays the message string in the status bar.
  • void displayState()
    Displays "AJAX Session State: [state]" in the status bar. [state] corresponds to one of the following: "Uninitialized", "Loading", "Loaded", "Interactive", or "Complete".
  • void displayStatus()
    Displays "AJAX Session HTTP Status: [status]" in the status bar. [status] is the verbose version of the HTTP Status Code returned to the XmlHttpRequest object.
  • void open(string uri, boolean asynchronous)
    Opens the XmlHttpRequest object, sending an HTTP GET to the URI specified.
  • void post(string uri, boolean asynchronous, iNode formObject)
    Opens the XmlHttpRequest object, sending an HTTP POST to the URI specified. You may include name/value pairs for form elements in the URI in the normal format (e.g. firstName=John&lastName=Public) or you may include the formObject and let the script do the work of creating name/value pairs.
  • integer readyState()
    Returns the readyState of the XmlHttpRequest object. The readyState is one of
    • 0: Uninitialized
    • 1: Loading
    • 2: Loaded
    • 3: Interactive
    • 4: Complete
  • void setRequestHeader(string header, string value)
    Alias to the setRequestHeader method of the XmlHttpRequest object
  • integer status()
    Returns the HTTP Status Code representing the status of the XmlHttpRequest object.

Properties:

  • ASYNC
    A value indicating whether or not the XmlHttpRequest object should communicate asynchronously.
    Type: boolean
    Default: false
  • RequestObject
    The XmlHttpRequest object.
    Type: XmlHttpRequest or MSXML
  • URL
    The URI the XmlHttpRequest object will open.
    Type: String

Example

var oAJAX = new Cathmhaol.Ajax();
function callback() {
  if (oAJAX.RequestObject.status == 200) {
    return oAJAX.RequestObject.responseText;
  }
}
oAJAX.RequestObject.onreadystatechange = callback;

AjaxPool

Required libraries

  • Cathmhaol.AjaxConnection
  • Cathmhaol.AjaxRequest

Syntax

var oAjax = new Cathmhaol.AjaxPool([numberOfConnections]);

Methods:

  • void send(string uri, boolean async, function callback, string|node data, integer wait)
    Queues an XmlHttpRequest and sends the request when the connection object is available.
    uri
    The resource to use.
    asnyc
    Make the call asynchronously.
    callback
    The JavaScript function to execute when the response returns.
    data
    A string or a DOM node to send to the resource.
    wait
    The number of milliseconds to wait before timeout.

Properties:

Example

var oConPool = new Cathmhaol.AjaxPool(); oConPool.send("http://www.cathmhaol.com/license/index.asp", true, function(xhr) { /* handler for xhr.responseText */ }, "get");

A full-page, basic example can be found here.

Calendar

Required libraries

Syntax

Cathmhaol.Calendar;

Methods:

  • date dateAdd(string interval, integer numberOfIntervals, string|date startDate)
    Returns a date that is the starting date with the specified number of intervals added. The interval must be one of: y(ear), q(uarter), m(onth), d(ay), w(eek), h(our), (mi)n(ute), or s(econd).

    var d = Cathmhaol.Calendar.dateAdd("n", 5, "1/1/1970 13:00:00"); // d = 1/1/1970 1:05:00 PM

  • float dateDiff(string interval, string|date startDate, string|date endDate)
    Returns a number of intervals between the starting date and the ending date. The interval must be one of: y(ear), q(uarter), m(onth), d(ay), w(eek), h(our), (mi)n(ute), or s(econd).

    var d = Cathmhaol.Calendar.dateDiff("m", new Date(1970, 0, 1), "1/1/1971"); // d = 12

  • integer dayOfTheWeek(date d)
    Returns an integer that represents the day of the week for the specified day

    var dow = Cathmhaol.Calendar.dayOfTheWeek(new Date(1970, 0, 1)); // dow = 4

  • integer daysInMonth(date d)
    Returns an integer that represents the number of days in the specified month.

    var days = Cathmhaol.Calendar.daysInMonth(new Date(1970, 0, 1)); // days = 31

  • boolean isLeapYear(integer year)
    Returns true if the specified year contains a Leap Day.

    var bLeap = Cathmhaol.Calendar.isLeapYear(2008); // bLeap = true

  • boolean isSupportedLanguage(string languageCode)
    Returns true if the specified language code is defined in the MONTHS associative array.

    var bSupported = Cathmhaol.Calendar.isSupportedLanguage("zh"); // bSupported = false

  • date ordinalDate(integer year, integer month, integer ordinalIndex, integer Weekday)
    Returns an ordinal date given a year, a zero-based month index, an ordinal index between 1 (first) and 5 (fifth), and a day of the week.

    var d = Cathmhaol.Calendar.ordinalDate(2008, 2, 5, Cathmhaol.Calendar.SUNDAY) // d = 30-MAR-08

Properties:

  • DAYS
    An associative array containing day names objects. The key in the associative array is a language code (e.g. English is "en", Spanish is "es", and German is "de"). The member is an 7-member array containing a day name objects with a longName property and a shortName property.
  • FRIDAY
    Integer representing the day of the week, i.e. 5.
  • MONDAY
    Integer representing the day of the week, i.e. 1.
  • MONTHS
    An associative array containing month names. The key in the associative array is a language code (e.g. English is "en", Spanish is "es", and German is "de"). The member is an 12-member array containing month names.
  • SATURDAY
    Integer representing the day of the week, i.e. 6.
  • SUNDAY
    Integer representing the day of the week, i.e. 0.
  • THURSDAY
    Integer representing the day of the week, i.e. 4.
  • TUESDAY
    Integer representing the day of the week, i.e. 2.
  • WEDNESDAY
    Integer representing the day of the week, i.e. 3.

DateInput

Required libraries

  • Cathmhaol.Calendar

Syntax

var oDateInput = new Cathmhaol.DateInput(string|node htmlInput[, date value[, string|node helper[, string languageCode]]]);

Methods:

  • void close()
    Closes and destroys the DateInput object.

  • string getLanguageCode()
    Returns a string that contains the language code being used.

  • string[] getLanguageCodes()
    Returns an string array containing all the supported language codes. Supported language codes are limited to those supported in the Cathmhaol.Calendar object.

  • void open([integer top[, integer left]])
    Opens the DateInput object.

  • void setLanguageCode(string languageCode)
    Sets the language code in the Calendar object if the value passed in the languageCode is supported. The default value of the language code is "en".

    var oCalendar = new Cathmhaol.Calendar(new Date(2008, 1, 1));
    oCalendar.setLanguageCode("es");
    var lang = oCalendar.getLanguageCode(); // lang = "es"

  • void show(integer top, integer left)
    Displays the DateInput object at the specified coordinates.

Properties:

Example

window.onload = function() {
  var oBirthdayHelp = new Cathmhaol.DateInput("birthday");
  var oAnniversaryHelp = new Cathmhaol.DateInput("anniversary", "1/1/1970");
  var oDateHelp = new Cathmhaol.DateInput("birthday", "", '<img src="http://www.cathmhaol.com/images/calendar.gif">');
}

A full-page, basic example can be found here.

Email

Required libraries

Syntax

var oEmail = new Cathmhaol.Email();

Methods:

  • void addRecipient(emailAddress)
    Adds the email address to the list of recipients.
  • string getRecipients()
    Returns the list of recipients as a semi-colon separated string (e.g. info@mailinator.com;moreinfo@mailinator.com).
  • void send()
    Opens the email in the installed email client using a mailto link.

Properties:

  • body
    The body of the email.
    Type: String
  • subject
    The subject of the email.
    Type: String

Example

var oEmail = new Cathmhaol.Email();
oEmail.addRecipient("info@mailinator.com");
oEmail.addRecipient("spoof@mailinator.com");
oEmail.body = "This is a test";
oEmail.subject = "Test";
oEmail.send();

Error

Required libraries

Syntax

var oDebug = new Cathmhaol.Error();

Methods:

  • void clear()
    Sets the description and source to empty strings and the errNumber to 0.
  • void raise(object err, string source, integer errorNumber)
    Sets the description to the description of the err object, the source, and the errorNumber.
  • void show()
    Shows the current error.

Properties:

  • description
    The string representing the description given for the error raised.
    Type: String
  • errNumber
    The number assigned to the error raised.
    Type: Number
  • source
    The string description of the source of the error raised.
    Type: String

Example

this._oErr = new Cathmhaol.Error();

...

this._oErr.description = "Unable to open connection";
this._oErr.errNumber = -1;
this._oErr.source = "AJAX request";
this._oErr.show();

EventHandler

Required libraries

Syntax

var oEventHandler = new Cathmhaol.EventHandler();

Methods:

  • void add(iNode object, string eventType, object eventHandler)
    Adds the JavaScript function or command string passed in eventHandler to the DOM node passed as the object for the eventType.

Properties:

Example

var BEHAVIOR = new Cathmhaol.EventHandler();
BEHAVIOR.add(window, "load", window_onload);

var BEHAVIOR = new Cathmhaol.EventHandler();
BEHAVIOR.add(oNode, "blur", "alert('Hello world!');");

Event

Required libraries

Syntax

var event = new Cathmhaol.Event();

Methods:

  • void subscribe(function handler[, object scope[, boolean adjust]])
    Adds the JavaScript function as a handler when the event is triggered.
  • void trigger([variant args])
    Triggers the events and passes the provided arguments (optional) into the handlers.
  • void unsubscribe()
    Removes all handlers from the event.

Properties:

Example

myobject = function() {
};
myobject.prototype = {
  aborted: new Cathmhaol.Event(),
  _stateChange: function(newState) {
    if (newState == "aborted") {
      this.aborted.trigger();
    }
  }
};

var o = new myobject();
o.aborted.subscribe(function() {
    alert("Oops! We aborted.");
  }, o, true);

Financial

Required libraries

Syntax

Cathmhaol.Financial;

Methods:

  • object[] amortize(float principal, float apr, integer years, boolean balloonPayment)
    Returns an array that contains the amortization schedule for a given amount with a given annual percentage rate over a period of years. The array contains a Amortization Payment object with the properties payment, principal, interest, and balance. The balance is computed after the payment.
  • integer breakEvenPoint(float fixedCost, float sellingPrice, float variableCost)
    Returns the number of units that must be sold at the specified selling price given the fixed cost and variable cost associated with production and sale of the units.
  • float compoundInterest(float principal, float apr, integer periods)
    Returns the amount of interest compounded on the princicpal given the interest rate and the number of periods.
  • string formatDecimal(float amount, integer precision)
    Formats a float to the specified precision and returns a string
    var s = Cathmhaol.Financial.formatDecimal(1000, 2) // s = "1000.00"
  • float futureValue(float payment, float apr, integer numberOfPayments)
    Returns the future value of periodic payments given the amount of the payment, the rate of interest, and the number of payments.
  • float mean(float[] data)
    Returns the mean of the values presented in the data collection.
  • float median(float[] data)
    Returns the median of the values presented in the data collection, or the value that falls directly between the highest and lowest values.
  • string ruleOfSeventyTwo(boolean returnPercentage, float amount)
    Returns a string that will contain either the percentage or the number of years required to double your investment (e.g. "7%" or "7 years"). If bReturnPercentage is true, the result will be expressed as a percentage, otherwise, the result will be the number of years required.
  • float standardDeviation(float[] data)
    Returns the standard deviation of the values presented in the data collection.
  • float zScore(float earnings, float netSales, float marketValueOfEquity, float workingCapital, float retainedEarnings, float totalAssets, float totalLiabilities)
    Returns the Altman Z-Score that is used as a predictor of bankruptcy. A score of 2.99+ indicates business is sound, while a score between 1.81 and 2.98 indicates caution and 1.80 and below indicates that a business is in trouble.

Properties:

Example

/* calculate the amortization for a $7000 note with 6.75% interest for three years with a balloon payment */
var aAmortization = Cathmhaol.Financial.amortize(7000, 6.75, 3, true);

Gps

Required libraries

Syntax

Cathmhaol.Gps;

Methods:

  • double distance(Cathmhaol.Gps.Location start, Cathmhaol.Gps.Location stop)
    Returns the number of kilometers between the two coordinates.

    var d = Cathmhaol.Gps.distance(work, home); // d = 11.690123

  • double kilometers(double miles)
    Returns the number of kilometers for the specified number of miles.

    var d = Cathmhaol.Gps.kilometers(6.2); // d = 10

  • double miles(double kilometers)
    Returns the number of miles for the specified number of kilometers.

    var d = Cathmhaol.Gps.miles(10); // d = 6.2

Properties:

  • EARTH_RADIUS
    The estimated radius of the Earth at the equator.

Example

var oHome = new Cathmhaol.Gps.Location(new Cathmhaol.Gps.Latitude(33, 50, 40), new Cathmhaol.Gps.Longitude(-111, 50, 40));
var oWork = new Cathmhaol.Gps.Location(new Cathmhaol.Gps.Latitude(33, 59, 59), new Cathmhaol.Gps.Longitude(-111, 59, 59));
var commuteInMiles = Cathmhaol.Gps.miles(Cathmhaol.Gps.distance(oHome, oWork));

XhrWindow

Required libraries

Syntax

var oXhrWindow = new Cathmhaol.XhrWindow();

Methods:

  • void back()
    Displays the previous page in the modal window.
  • void cancel(xmlHttpRequest xhr)
    Cancels the process and closes the modal window. If executeFirst is true, the event is called before the modal window is closed, otherwise, the event is triggered after the modal window is closed.
  • void close()
    Destroys the modal window.
  • void end(xmlHttpRequest xhr)
    Ends the process and closes the modal window. If executeFirst is true, the event is called before the modal window is closed, otherwise, the event is triggered after the modal window is closed.
  • void forward()
    Displays the next page in the modal window.
  • void reset()
    Removes content from the header, body, buttons, and footer sections and hides the modal window.
  • void setBody(string html)
    Sets the content body.
  • void setButtons()
    Adds the buttons to the modal window.
  • void setContent(string header, string body, object[] buttons, string footer)
    Sets the content of the modal window. The buttons array should contain a "button" object that contains a DOM Node that is a button (with name, type, and value or innerHTML properties) and a handler that is a JavaScript function.
  • void setFooter(string html)
    Sets the content of the footer.
  • void setHeader(string html)
    Sets the content of the header.
  • void show()
    Shows the object
  • void start(node oForm)
    Starts the process using the specified form. Forms posted from within the modal window will also contain a CGI variable "post_type" that will contain the word "xhr_window". This CGI variable can then be evaluated in the query string or in the request object.

Properties:

  • allowClose
    Enables the close button
    Type: Boolean
    Default: true
  • allowPaging
    Enables the page back and page forward buttons.
    Type: Boolean
    Default: true
  • async
    Use XmlHttpRequest in asynchronous mode.
    Type: Boolean
    Default: true
  • backgroundColor
    The background color of the modal window. Uses CSS format.
    Type: String
    Default: #fff
  • border
    The border to give to the modal window. Uses CSS border property shorthand.
    Type: String
    Default: 1px solid #000
  • color
    Text color
    Type: String
    Default: #000
  • errorMessageTimeout
    The number of seconds to display the modal window when the XHR call fails.
    Type: Number
    Default: 5
  • executeFirst
    Boolean to indicate whether the function to be executed when the processes is ended should be executed before the modal window is closed.
    Type: Boolean
    Default: false
  • fontBody
    The font family to be used for the body of the modal window.
    Type: String
    Default: Times New Roman
  • fontFooter
    The font family to be used for the footer of the modal window.
    Type: String
    Default: Arial
  • fontHeader
    The font family to be used for the header of the modal window.
    Type: String
    Default: Arial
  • height
    The height of the panel. Height can be specified in pixels or as a percentage.
    Type: String
    Default: 400px
  • id
    The id of the panel
    Type: String
  • left
    The left border of the modal window
    Type: String
  • onCancel
    Event handler to call when canceling.
    Type: Function
  • onEnd
    Event handler to call when ending.
    Type: Function
  • onFail
    Event handler to call when when the XHR fails.
    Type: Function
  • padding
    Internal padding of the modal window. Uses CSS format.
    Type: String
    Default: 10px
  • timeout
    The number of milliseconds to wait for a response.
    Type: Number
  • top
    The top border of the modal window. Uses CSS format.
    Type: String
    Default: 100px
  • width
    The width of the panel. Width can be specified in pixels or as a percentage.
    Type: String
    Default: 400px

Example

function oForm_onSubmit() {
  var oForm = document.getElementById("frmMain");
  var oPanel = new Cathmhaol.XhrWindow();
  oPanel.onCancel = function() { alert("Canceling"); }
  oPanel.onEnd = function() { alert("Ending"); }
  oPanel.onFail = function() { alert("Error"); }
  oPanel.start(oForm);
  return false;
}

A full-page, basic example can be found here.