//==========================================
//retire les caractères de contrôle
//==========================================
function trim (myString){
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}
//==========================================
//strpos
//==========================================
function strpos( haystack, needle, offset){ 
    var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
    return i === -1 ? false : i;
}
//==========================================
//trouve la position sur la page de ma div	
//==========================================	
function findPos(obj){
	var curleft = curtop = 0;
	if (obj.offsetParent){
	do{
	curleft += obj.offsetLeft;
	curtop += obj.offsetTop;
	}
	while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}
//==========================================
//recup le cookie
//==========================================
function getCookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	for ( i = 0; i < a_all_cookies.length; i++ ){
	a_temp_cookie = a_all_cookies[i].split( '=' );
	cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	if ( cookie_name == check_name ){
	b_cookie_found = true;
	if ( a_temp_cookie.length > 1 ){
	cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
	}
	return cookie_value;
	break;
	}
	a_temp_cookie = null;
	cookie_name = '';
	}
	if ( !b_cookie_found ){
	return "";
	}
}
//==========================================
// cherche si une valeure est dans un tableau
//==========================================
Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
	if(this[i] == p_val) return i;
	}
	return false;
 }
//==========================================
// ecrit un cookie
//==========================================
function setCookie( name, value, expires, path, domain, secure ){
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) expires = expires * 1000 * 60 * 60 * 24;
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}
//==========================================
// remplace les saut de ligne en <br>
//==========================================
function nl2br( str ) {
    return str.replace(/([^>])\n/g, '$1<br />\n');
}
//==========================================
// vérifie si une var est un chiffre
//==========================================
function isnum( mixed_var ){
    if (mixed_var === '') return false;
    return !isNaN(mixed_var * 1);
}
//==========================================
// additionne un tableau
//==========================================
Array.prototype.sum = function(){
    for(var s = 0, i = this.length; i; s += parseInt(this[--i]));
    return s;
};
//==========================================
// Detecte la Position de la souris
//==========================================
function position(e) {
	if (navigator.appName.substring(0,3) == "Net") {
	x = e.pageX;
	y = e.pageY;
	}else {
	x = event.x+document.body.scrollLeft;
	y = event.y+document.body.scrollTop;
	}
	Xmouse = x;Ymouse = y;
}
//==========================================
if(navigator.appName.substring(0,3) == "Net") document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = position;
//==========================================
// succes du chargement ajax
//==========================================
function sucText(xhr,MyDiv) {
	document.getElementById(MyDiv).innerHTML = xhr.responseText;
}
//==========================================
// erreure du chargement ajax
//==========================================
function errText(xhr,MyDiv) {
	document.getElementById(MyDiv).innerHTML = xhr.responseText;
}
//==========================================
// permet le passage de fonction entre Objets == bind ???
//==========================================
function Get_RefFonction( o_, fct_){
  return( function(){o_[ fct_]()});
}
//==========================================
// cherche Si une var est la clef d'un tableau
//==========================================
function is_array_key(tbl,k){
	if(tbl[k]!=undefined) return true; else return false;
}
//==========================================
// cherche si un objet est le Parent d'un autre
//==========================================
function isParent(obj,parent){
	if (obj.offsetParent){
	do{
	if(obj.id==parent) return true;
	}
	while (obj = obj.offsetParent);
	}
	return false;
}
//===================================================================	
//objet AJAX
//===================================================================
var Ajax_request = 	function() {
	this.request.apply(this, arguments);
}
Ajax_request.prototype = {
request: function (url, options)
{	
	this.getObject();
	if ( typeof(options) == 'undefined' ) options = new Array();
	if ( typeof(options) == 'object' ){
	method = options['method'] || 'post';
	this.MyDiv = options['div'];
	successEnd = options['onSuccess'] || this.debugSuccessMessage.bind(this);
	errorEnd = options['onError'] || this.defaultErrorMessage.bind(this);
	paramString = typeof(options['params']) == 'undefined' ? '' : (options['method'] == 'get' ? '?'+options['params'] : options['params']);
	if ( typeof(options['async']) != 'undefined' && typeof(options['async']) != 'boolean' ) {
	alert('si la valeur de \'async\' est definie, elle doit etre de type booleen');
	return;
	}
	else async = typeof(options['async']) == 'undefined' || typeof(options['async']) != 'boolean'? true : options['async'];
	ico = options['ico'];
	if(!document.getElementById(ico)) ico = false;			
	this.setProperties(method,successEnd,errorEnd,paramString,async,ico);
	}						
	if ( typeof(url) != 'string' ) {
	alert('url de format invalide ( l\'url est obligatoire )');
	return;
	}
	else this.properties['url'] = url;					
	this.setReadyProcess();
	this.processRequest();
},
getObject: function() {
	if(window.XMLHttpRequest) this.Ajax_object = new XMLHttpRequest();
	else if (window.ActiveXObject) { 
	try {
	this.Ajax_object = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e) {
	try {
	this.Ajax_object = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch (e1) {
	this.Ajax_object = null;
	}
	}
	}else{
	alert("AJAX impossible sur votre navigateur");
	}
	this.properties = new Array();
},
setProperties: function() {
	this.properties = {
	method : arguments[0],
	successEnd : arguments[1],
	errorEnd : arguments[2],
	paramString : arguments[3],
	async : arguments[4],
	ico : arguments[5]
	}
},
setReadyProcess: function() {
	this.Ajax_object.onreadystatechange = function() {
	if (this.Ajax_object.readyState == 4 ) {
	if(this.properties['ico']) document.getElementById(this.properties['ico']).style.display = "none";
	responseText = this.Ajax_object.responseText;
	responseXML = this.Ajax_object.responseXML;
	this.responseText = this.Ajax_object.responseText;
	this.responseXML = this.Ajax_object.responseXML;
	if ( this.Ajax_object.status == 200 ) this.properties['successEnd'](this.Ajax_object,this.MyDiv);
	else this.properties['errorEnd'](this.Ajax_object,this.MyDiv);
	}
	}.bind(this);
},
defaultErrorMessage: function(xhr)  {
	alert('Error ' + xhr.status + ' -- ' + xhr.statusText);
},
debugSuccessMessage: function(xhr,MyDiv) {
	document.getElementById(MyDiv).innerHTML = xhr.responseText;
},
processRequest: function() {
	if(this.properties['ico']) document.getElementById(this.properties['ico']).style.display = "block";
	this.Ajax_object.open(
	this.properties['method'],
	this.properties['method'] == 'post' ?
	this.properties['url'] : this.properties['url']+this.properties['paramString'],
	this.properties['async']
	);
	if ( this.properties['method'] == 'post' )
	this.Ajax_object.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	this.Ajax_object.send(this.properties['method'] == 'post' ? this.properties['paramString'] : null);
}
}
//==========================================
// Permet de contrer le moteur javascript dans un bug de reference de fonction
//==========================================
Function.prototype.bind = function(object) {
	var __method = this;
	return function() {
		return __method.apply(object, arguments);
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Variables contenant les reponses Texte ou XML => permet dans une page HTML d'avoir acces facilement a la reponse de la requete AJAX  //
var responseText = new String();
var responseXML = new Object();
var MyDiv = new String();
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
