
/***************************************************************************
 *				classes.js
 *				----------
 *	Cree le		: 7 Fevrier 2007
 *	Derniere modif.	: 10 Aout 2007
 *	Auteur		: Asselin Benoit Developpement
 *	Site		: http://www.ab-d.fr/
 *
 ***************************************************************************/



var Doc = {
	id : function(id) {
		return document.getElementById(id) || false;
	},
	body : function() {
		return document.getElementsByTagName('body')[0];
	}
}



var CBrowser = {
	userAgent : navigator.userAgent.toLowerCase(),
	find : false,
	position : 0,
	check : function(p_string) {
		var v_position = this.userAgent.indexOf(p_string) + 1;
		if ( !this.find && v_position ) {
			this.find = true;
			this.position = v_position;
			return true;
		} else {
			return false;
		}
	},
	unknown : function() {
		return (this.find ? false : true);
	},
	version : function() {
		var v_version = this.userAgent.substring(this.position, this.userAgent.length);
		var v_result = v_version.match(/([\d\.]+)/);
		if (v_result) {
			return v_result[1];
		} else {
			return navigator.appVersion.charAt(0);
		}
	},
	os : function() {
		this.find = false; /* raz.test */
		if	(this.check('linux'))	{ return 'linux'; }
		else if	(this.check('x11'))	{ return 'unix'; }
		else if	(this.check('mac'))	{ return 'mac'; }
		else if	(this.check('win'))	{ return 'win'; }
		else	/* unknow */		{ return 'unknown'; }
	}
}
var Browser = {
	webkit	: CBrowser.check('applewebkit'),
	opera	: CBrowser.check('opera'),
	firefox	: CBrowser.check('firefox'),
	msie	: CBrowser.check('msie'),
	unknown	: CBrowser.unknown(),
	version	: CBrowser.version(),
	os	: CBrowser.os()
}



function ClassAJAX(v_method) {
	this.method = (v_method) ? (v_method) : 'POST';
	this.connexion = false;
	
	this.text = '';
	this.xml = '';
	
	this.setConnexion();
}

ClassAJAX.prototype = {
	setConnexion : function() {
		if (window.XMLHttpRequest) {
			this.connexion = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			try {
				this.connexion = new ActiveXObject('Msxml2.XMLHTTP');
			} catch (e) {
				this.connexion = new ActiveXObject('Microsoft.XMLHTTP');
			}
		} else {
/*			alert('Votre navigateur ne supporte pas le XMLHttpRequest. Merci de charger la derni\xE8re version de Mozilla Firefox.');	*/
		}
	},
	send : function(v_openFile, f_state, v_send) {
		if (this.connexion) {
			if (this.method == 'GET') {
				this.connexion.open('GET', v_openFile +'?'+ v_send, true);
				this.connexion.onreadystatechange = f_state;
				this.connexion.send(null);
			} else {
				this.connexion.open('POST', v_openFile, true);
				this.connexion.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				this.connexion.onreadystatechange = f_state;
				this.connexion.send(v_send);
			}
		}
	},
	sendReturn : function() {
		if (this.connexion.readyState == 4 && this.connexion.status == 200) {
			this.text = this.connexion.responseText;
			this.xml = this.connexion.responseXML;
			return true;
		} else {
			return false;
		}
	}
}



var v_fixDblKey = 0;
function fixDblKey() { /* fix.safari */
	if (v_fixDblKey != 0) {
		return true;
	} else {
		v_fixDblKey = setTimeout('v_fixDblKey = 0;', 10);
		return false;
	}
}



/* prototypejs.org 1.5.1.1 */
var $A = Array.from = function(iterable) {
	if (!iterable) return [];
	if (iterable.toArray) {
		return iterable.toArray();
	} else {
		var results = [];
		for (var i = 0, length = iterable.length; i < length; i++)
			results.push(iterable[i]);
		return results;
	}
}

Function.prototype._bind = function() {
	var __method = this, args = $A(arguments), object = args.shift();
	return function() {
		return __method.apply(object, args.concat($A(arguments)));
	}
}

Function.prototype._bindEvent = function(object) {
	var __method = this, args = $A(arguments), object = args.shift();
	return function(event) {
		return __method.apply(object, [event || window.event].concat(args));
	}
}

var FixEvent = {
	element : function(e) {
		return e.target || e.srcElement;
	},
	isLeftClick : function(e) {
		return	( (e.which) && (e.which == 1) )	||
			((e.button) && (e.button == 1))	;
	},
	pointerX : function(e) {
		return e.pageX || ( e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) );
	},
	pointerY : function(e) {
		return e.pageY || ( e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) );
	},
	stop : function(e) {
		if (e.preventDefault) {
			e.preventDefault();
			e.stopPropagation();
		} else {
			e.returnValue = false;
			e.cancelBubble = true;
		}
	}
}


