

/**
 * Copyright 2006 Easyvoyage S.A.
 * http://www.easyvols.fr
 *
 * Author : Yannick GALLY (ygally@easyvoyage.fr)
 *
 * Sources:
 *   - prototype framwork
**/
(function() {
	var window = this,
			document = window.document;

	//-------------------- util.commons.js
	window.EasyCommons = {
		Version: '1.0.1'
	};

	window.$ = function() {
		var elements = [], i, element;
		for (i = 0; i < arguments.length; ++i) {
			element = arguments[i];
			if (typeof element == 'string') {
				element = document.getElementById(element);
			}
			elements.push(element);
		}
		if (arguments.length == 1 && elements.length > 0) {
			return elements[0];
		}
		return elements;
	};
	window.$C = function(elType) { return document.createElement(elType); };
	function exists(something) { return something && true || false; }
	window.exists = exists;
	window.canUseDHTML = function() { return exists(document.getElementById); };
	window.canUseW3CDOM = function() { return document.getElementById && exists(document.createElement); };
	function getObjNN4(obj,name) {
		var x = obj.layers;
		var foundLayer, i, tmp;
		for (i = 0; i < x.length; i++) {
			if (x[i].id == name) {
				foundLayer = x[i];
			} else if (x[i].layers.length) {
				tmp = getObjNN4(x[i], name);
				if (tmp) {
					foundLayer = tmp;
				}
			}
		}
		return foundLayer;
	}
	window.getObjNN4 = getObjNN4;
	function ObjectReference(name) {
		this.obj = null;
		this.style = null;
		if (document.getElementById) {
			this.obj = document.getElementById(name);
		}
		else if (document.all) {
			this.obj = document.all[name];
			this.style = document.all[name].style;
		}
		else if (document.layers) {
			this.obj = document.layers[name];
			this.style = this.obj;
		}
		else if (document.layers) {
			this.obj = getObjNN4(document, name);
			this.style = this.obj;
		}
	}
	window.ObjectReference = ObjectReference;
	function findPosX(obj) {
		var curleft = 0;
		if (obj.offsetParent) {
			while (obj.offsetParent) {
				curleft += obj.offsetLeft;
				obj = obj.offsetParent;
			}
		}
		else if (obj.x) {
			curleft += obj.x;
		}
		return curleft;
	}
	window.findPosX = findPosX;
	function findPosY(obj) {
		var curtop = 0;
		if (obj.offsetParent) {
			while (obj.offsetParent) {
				curtop += obj.offsetTop;
				obj = obj.offsetParent;
			}
		}
		else if (obj.y) {
			curtop += obj.y;
		}
		return curtop;
	}
	window.findPosY = findPosY;
	window.findObjectLeft = function(obj) {
		obj = new ObjectReference(obj).obj;
		return obj ? findPosX(obj) : 0;
	};
	window.getObjectLeft = function(obj) {
		obj = new ObjectReference(obj).obj;
		return obj ? obj.offsetLeft : 0;
	};
	window.findObjectTop = function(obj) {
		obj = new ObjectReference(obj).obj;
		return obj ? findPosY(obj) : 0;
	};
	window.getObjectTop = function(obj) {
		obj = new ObjectReference(obj).obj;
		return obj ? obj.offsetTop : 0;
	};
	window.util_groups = [];
	window.initGroup = function(name) {
		var a = arguments, i;
		if (a.length < 3) {
			return;
		}
		window.util_groups[name] = [];
		for (i = 1; i < a.length; ++i) {
			window.util_groups[name][i - 1] = a[i];
		}
	};
}());

