function ErreurObj(txt){this.txt=txt;this.caller=getCaller(ErreurObj.caller);this.toString=function(){return"Erreur : "+this.txt+" Fonction : "+this.caller;};}function isset(toTest){return(typeof toTest!="undefined");}function inArray(text){for(a=0;a<this.length;a++){if(this[a]==text){return true;}}}Array.prototype.inArray=inArray;function getCaller(rawCaller){rawCaller=rawCaller.toString();if(rawCaller==null){return"";}return rawCaller.substring(rawCaller.indexOf("function ")+9,rawCaller.indexOf("(")).replace(" ","");}function Ajax(){if(this.onCreate()){this.asyn=true;this.data="";this.url="";this.cible="";this.method="GET";this.returnFormat="txt";this.obj;this.init();}}Ajax.prototype.init=function(){this.onCreate();this.obj=null;if(window.XMLHttpRequest){this.obj=new XMLHttpRequest();}else{if(window.ActiveXObject){var ieversions=["Microsoft.XMLHTTP","MSXML2.XMLHTTP","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.7.0"];for(var i=0;!this.obj&&i<ieversions.length;i++){try{this.obj=new ActiveXObject(ieversions[i]);}catch(e){affiche_message("Fonction non supportée par le navigateur");}}}}};var compteurRequetesEnCours=0;Ajax.prototype.onFailure=function(errorCode){};Ajax.prototype.onComplete=function(response){};Ajax.prototype.onCreate=function(){window.defaultStatus=">.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>  Chargement en cours ...  ";return true;};function enleve_loader(){window.defaultStatus="gescom.fr";}Ajax.prototype.setParamFromForm=function(obj){if(!isNaN(obj)){obj=document.forms[obj];}if(typeof obj=="string"){eval("obj = document."+obj);}if(!isset(obj)){return ErreurObj("Donnée Invalide");}this.method=(isset(obj.method)&&(["GET","POST"].inArray(obj.method.toUpperCase())))?obj.method.toUpperCase():this.method;this.url=obj.action;for(i=0;i<obj.elements.length;i++){if(this.data!=null){this.data+="&";}this.data+=obj.elements[i].name+"="+escape(obj.elements[i].value);}};Ajax.prototype.setParam=function(arr){if(typeof arr!="object"&&!isset(arr)){return ErreurObj("Donnée Invalide");}for(k in arr){switch(k){case"cible":this.cible=arr[k];break;case"url":this.url=arr[k];break;case"method":this.method=(["GET","POST"].inArray(arr[k].toUpperCase()))?arr[k].toUpperCase():this.method;break;case"data":if(typeof arr[k]=="string"){if(this.data!=""){this.data+="&";}this.data+=arr[k];}else{if(typeof arr[k]!="object"){break;}for(j in arr[k]){if(typeof arr[k][j]!="function"){if(this.data!=""){this.data+="&";}this.data+=j+"="+encodeURIComponent(arr[k][j]);}}}break;case"asynchronus":this.asyn=arr[k];break;case"onComplete":this.onComplete=arr[k];break;case"onFailure":this.onFailure=arr[k];break;case"returnFormat":this.returnFormat=arr[k];break;}}};Ajax.prototype.execute=function(valeur){this.obj.open(this.method,this.url,this.asyn);if(this.method=="POST"){this.obj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");}if(this.asyn){_tempAJAX_Reference_=this;this.obj.onreadystatechange=function(){if(_tempAJAX_Reference_.obj.readyState==4&&_tempAJAX_Reference_.obj.status==200){if(_tempAJAX_Reference_.returnFormat!="txt"){response=_tempAJAX_Reference_.obj.responseXML;}else{response=_tempAJAX_Reference_.obj.responseText;}if(typeof _tempAJAX_Reference_.onComplete=="string"){eval(_tempAJAX_Reference_.onComplete);}else{_tempAJAX_Reference_.onComplete(response);}enleve_loader();}else{if(_tempAJAX_Reference_.obj.readyState==4){errorCode=_tempAJAX_Reference_.obj.status;if(typeof _tempAJAX_Reference_.onFailure=="string"){eval(_tempAJAX_Reference_.onFailure);}else{_tempAJAX_Reference_.onFailure(errorCode);}}}};this.obj.send(this.data);}else{this.obj.send(this.data);if(this.obj.status=="200"){if(this.returnFormat!="txt"){enleve_loader();response=this.obj.responseXML;}else{response=this.obj.responseText;}enleve_loader();if(typeof this.onComplete=="string"){eval(this.onComplete);}else{this.onComplete(response);}}else{errorCode=this.obj.status;if(typeof this.onFailure=="string"){eval(this.onFailure);}else{this.onFailure(errorCode);}}enleve_loader();}};
