
// Developed by Robert Nyman/DOMAssistant team
// Code/licensing: http://domassistant.googlecode.com/
// Documentation: http://www.domassistant.com/documentation
// Version 2.8
var Legato = {};
Legato.DOMLoad = function () {
	var DOMLoaded = false,
	DOMLoadTimer = null,
	functionsToCall = [],
	addedStrings = {},
	errorHandling = null,
	execFunctions = function () {
		for (var i=0, il=functionsToCall.length; i<il; i++) {
			try {
				functionsToCall[i]();
			}
			catch (e) {
				if (errorHandling && typeof errorHandling === "function") {
					errorHandling(e);
				}
			}
		}
		functionsToCall = [];
	},
	DOMHasLoaded = function () {
		if (DOMLoaded) {
			return;
		}
		DOMLoaded = true;
		execFunctions();
	};
	/* Internet Explorer */
	/*@cc_on
	@if (@_win32 || @_win64)
		document.write("<script id=\"ieScriptLoad\" defer src=\"//:\"><\/script>");
		document.getElementById("ieScriptLoad").onreadystatechange = function() {
			if (this.readyState === "complete") {
				DOMHasLoaded();
			}
		};
	@end @*/
	/* Mozilla, Chrome, Opera */
	if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", DOMHasLoaded, false);
	}
	/* Safari, iCab, Konqueror */
	if (/KHTML|WebKit|iCab/i.test(navigator.userAgent)) {
		DOMLoadTimer = setInterval(function () {
			if (/loaded|complete/i.test(document.readyState)) {
				DOMHasLoaded();
				clearInterval(DOMLoadTimer);
			}
		}, 10);
	}
	/* Other web browsers */
	window.onload = DOMHasLoaded;

	return {
		DOMReady : function () {
			for (var i=0, il=arguments.length, funcRef; i<il; i++) {
				funcRef = arguments[i];
				if (!funcRef.DOMReady && !addedStrings[funcRef]) {
					if (typeof funcRef === "string") {
						addedStrings[funcRef] = true;
						funcRef = new Function(funcRef);
					}
					funcRef.DOMReady = true;
					functionsToCall.push(funcRef);
				}
			}
			if (DOMLoaded) {
				execFunctions();
			}
		},

		setErrorHandling : function (funcRef) {
			errorHandling = funcRef;
		}
	};
}();
Legato.DOMReady = Legato.DOMLoad.DOMReady;

/**
 *
 * Adds custom padding to the left-hand side of a string.
 *
 */
function str_pad_left(str, length, with_what)
{

    while ( str.length < length )
        str = with_what + str;

    return str;

}

/**
 *
 * Loops through a select list, finds a particular value, and selects it.
 *
 */
function selectOptionWithValue( select_id, val )
{

	var all_options = $$( select_id ).options;

	var all_options_length = all_options.length;
	var i;
	for( i = 0; i < all_options_length; i++ )
	{

		if ( val == all_options[i].value )
		{
			all_options[i].selected = true;
			return;
		}

	}

}

function selectOptionFirst( select_id )
{

	var all_options = $$( select_id ).options;

	var all_options_length = all_options.length;

	if ( 0 < all_options_length )
	{
		all_options[0].selected = true;
	}
	
}

function showStagingMessage()
{
	
	alert( 'Staging/Demo Site\n------------------------\n\nThe purpose of this site is to provide a demonstration of the workings of the final product.\n\nThis is site is under constant development.\nExpect frequent changes and updates.\n\n(This message will not be visible on the live production site.)' );
	
}

