
/******************************************************************************
 * SolucionXpress 2.5
 * Copyright (C) 2006, SolucionWeb SA
 * Guatemala, C.A.
 ******************************************************************************
 * Author : Mario J. Wunderlich
 * Contact: jwunder@solucionweb.com
 * Version: 1
 */

var SxCore = {
  	// Record the version of this library
  	nVersion: '1.0.0',

  	// Utility: emptyFunction, used for shorthand function execution.
  	emptyFunction: function() { },

  	// Returns the version of this SDK.
  	getVersion: function()
  	{
  	  	return SxCore.nVersion;
  	},

  	// Returns the piece-wise version of this SDK.
  	getVersionBits: function()
  	{
  	  	return SxCore.getVersion().split('.');
  	},

  	// Returns the major-version number
  	getVersionMajor: function()
  	{
  	  	return SxCore.getVersionBits()[0];
  	},

  	// Returns the major-version number
  	getVersionMinor: function()
  	{
  	  	return SxCore.getVersionBits()[1];
  	},

	// Extend: idea stolen from Prototype library.
  	extend: function(dest, source)
  	{
  	  	for (prop in source)
  	  	{
  	  	  	try {
	  	  		dest[prop] = source[prop];
	  	  	} catch(e) { }
	  	}
  	  	return dest;
  	},

	// Extend: idea stolen from Prototype library.
  	extendIf: function(dest, source)
  	{
  	  	for (prop in source)
  	  	{
  	  	  	try {
  	  	  		if ( !dest[prop] || dest[prop]==undefined )
	  	  			dest[prop] = source[prop];
	  	  	} catch(e) { }
	  	}
  	  	return dest;
  	},

	tryThese: function()
	{
	  	var fptr;
	  	var result = false;
	  	for (var i=0; i<arguments.length; ++i)
	  	{
	  	  	fptr = arguments[i];
	  	  	try {
	  	  	  	result = fptr();
	  	  	  	break;
	  	  	} catch(e) { }
	  	}
	  	return result;
	},

	tryTheseUntil: function(untilVal)
	{
	  	var until = arguments[0];

	  	var fptr;
	  	var result;
	  	var count = 0;
	  	for (var i=1; i<arguments.length; ++i)
	  	{
	  	  	fptr = arguments[i];
	  	  	try {
	  	  	  	result = fptr();
	  	  	  	count++;
	  	  	  	if ( result == until )
		  	  	  	break;
	  	  	} catch(e) { }
	  	}
	  	return count;
	},

	tryAll: function()
	{
	  	var results = [];
	  	for (var i=0; i<arguments.length; ++i)
	  	{
	  	  	try {
	  	  	  	var value = arguments[i]();
	  	  	  	results.push(value);
	  	  	} catch(e) {
	  	  	  	results.push(false);
	  	  	}
	  	}
	  	return results;
	},

	classCreate: function()
	{
	    return function() {
			this.initialize.apply(this, arguments);
	    }
	},

	Class: {
		create: function()
		{
			return function() {
				this.initialize.apply(this, arguments);
	    	}
	  	},

	  	inherit: function(ancestor)
	  	{
	  		function dummy() {}
	  		dummy.prototype = ancestor.prototype;

	  		descendant = SxCore.Class.create();
	  		descendant.prototype = new dummy();
	  		descendant.prototype.constructor = descendant;
	  		descendant.baseConstructor = ancestor.prototype.initialize || ancestor;
	  		descendant.superClass = ancestor.prototype;
	  		return descendant;
	  	},

	  	extend: function(dst, src)
	  	{
			for (prop in src)
				dst[prop] = src[prop];
			return dst;
	  	}
	}
}

