// ------------------------------------------------------------------------------
// aba_tools unobtrusive.js v1.1.1, Wed May 31 23:27:19 CET 2006
// Copyright (c) 2006 Aurelien Barbier-Accary
// http://aurelien.barbier-accary.info
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// For details, see my web site: http://aurelien.barbier-accary.info
// ------------------------------------------------------------------------------

if ((window.UnObtrusive)
 && ((! window.UnObtrusive.Signature)
	|| (window.UnObtrusive.Signature != 'ABA tools - unobtrusive module')
	|| (parseFloat(window.UnObtrusive.Version.split(".")[0] + "." +
					window.UnObtrusive.Version.split(".")[1]) >= 1.1)))
{
	if (true)
		throw("'ABA unobtrusive 1.1.1' not loaded");
}
else window.UnObtrusive =
{
	Signature: 'ABA tools - unobtrusive module',
	Version: '1.1.1',
	LogStream: 'console',  // '' for no log or null, 'console' (firebug) and 'alert' otherwise
	Verbose: 2, // 0 (only errors), 1 (main actions), 2 (waiting), 3 (for each script)

	// ----- Public methods -----------------------------------------------------

	eventCaller: function(event) {
		event = event || window.event;
		return event.target || event.srcElement;
	},

	hasClassName: function(elt, className) {
		if (! elt)
			return;
		elt = elt.className || elt;
		if (className !== undefined){
			className = className.replace(/([\.\\\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1");
			return elt && new RegExp("(^|\\s)" + className + "(\\s|$)").test(elt);
		}
		else return;
	},

	addClassNames: function(elt, classNames) {
		if (! elt)
			return;
		classNames = classNames.split(/\s+/);
		for(var classId in classNames)
		if (typeof(classNames[classId]) !== 'function')
		{
			if (! window.UnObtrusive.hasClassName(elt, classNames[classId]))
				elt.className += (elt.className) ? " "+classNames[classId] : classNames[classId];
		}
	},

	removeClassNames: function(elt, classNames) {
		if (! elt)
			return;
		eltClassNames = elt.className.split(/\s+/);
		elt.className = "";
		for(var classId in eltClassNames)
		if (typeof(eltClassNames[classId]) !== 'function')
		{
			if (classNames.lastIndexOf(eltClassNames[classId]) < 0)
				elt.className += (elt.className) ? " "+eltClassNames[classId] : eltClassNames[classId];
		}
	},

	/*replaceClassName: function(elt, classNameSrc, classNameTgt) {
		if (! elt)
			return;
		elt.className = elt.className.replace(/(^| )classNameSrc( |$)/g,classNameTgt);
	},*/

	// Execute une ou des fonctions pour les objets de classe et de type donne
	// fils du noeud rootNode (rootNode peut etre un noeud ou un identifiant).
	// Par defaut className='', tagName='*' et rootNode=document
	// Exemple d'utilisation:
	//   window.UnObtrusive.applyByClassAndTagName(maFonction, 'onlyIfJavaScript', 'img', 'maDiv');
	//   -> pour chaque objet image de classe 'onlyIfJavaScript' dans 'maDiv',
	//   on appelle "maFonction(obj);"
	// Pour executer plusieurs fonctions on transmet un tableau de noms de fonctions
	applyByClassAndTagName: function (funcHandlers, className, tagName, rootNode) {
		// verification et re-initialisation des parametres
		if ((! funcHandlers) || ((! className) && (! tagName)))
			return;
		if (typeof(funcHandlers) != 'array')
		{
			var tmp = new Array();
			tmp.push(funcHandlers);
			funcHandlers = tmp;
		}
		if (! className)
			className = '';
		else
			var classRegExp = new RegExp("(^|\\s)" + className + "(\\s|$)");
		if (! tagName)
			tagName = '*';
		if (rootNode && (typeof(rootNode) == 'string'))
			rootNode = document.getElementById(rootNode);
		if (! rootNode)
			rootNode = document;
		// applications des fonctions aux objets des classes
		var objects = rootNode.getElementsByTagName(tagName);
		for(var io=0; io<objects.length; io++)
			if ((! className) || (objects[io].className == className)
				|| (objects[io].className.match(classRegExp)))
			{
				for(var ifh=0; ifh<funcHandlers.length; ifh++)
					funcHandlers[ifh](objects[io]);
			}
	},

	// ----- Private methods ----------------------------------------------------

	_log: function(msg, msgVerbose) {
		if (! msgVerbose)
			msgVerbose = window.UnObtrusive.Verbose;
		if (window.UnObtrusive.LogStream)
			if ((window.UnObtrusive.LogStream == 'console') && console && console.log)
			{
				if (msgVerbose <= window.UnObtrusive.Verbose)
					console.log('UnObtrusive: '+msg);
			}
			else
			{
				if (msgVerbose <= window.UnObtrusive.Verbose)
					alert('UnObtrusive: '+msg);
			}
	}
};

// ------------------------------------------------------------------------------

