////////////////////////////////////////////////////////////////////////////////////////////// // WARNING ajaxParameter should be include before including this script ////////////////////////////////////////////////////////////////////////////////////////////// var HTTP_GET = "GET"; var HTTP_POST = "POST"; /** * Check if the session has expired checking parameter in result page */ function isSessionExpired(result) { return (result.indexOf("") != -1); } /** * Create XmlObject */ function getXmlObject(obj) { var myXmlHttp = false; /* Compilation conditionnelle d'IE */ /*@cc_on @if(@_jscript_version >= 5) try { myXmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(error) { try { myXmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(Errot) { myXmlHttp = false; } } @else myXmlHttp = false; @end @*/ if (!myXmlHttp && typeof XMLHttpRequest != 'undefined') { try { myXmlHttp = new XMLHttpRequest(); } catch(error) { myXmlHttp = false; } } if (myXmlHttp) { myXmlHttp.onreadystatechange=function() { if (myXmlHttp.readyState == 4) /* 4 : ?tat "complete" */ { try { if (myXmlHttp.status == 200) { /* 200 : code HTTP pour OK */ //Check for session status , if session expired redirect if (isSessionExpired(myXmlHttp.responseText)) window.self.location.href = REDIRECT_PAGE; /*if (isSessionExpired(myXmlHttp.responseText)) document.write(myXmlHttp.responseText);*/ try { obj.receive(myXmlHttp.responseText); } catch(aReceiveError) {} } else { window.self.location.href = REDIRECT_PAGE; //alert("A server error occurs, please make sure that Cookie management is enabled"); } } catch(error) { //obj.receive(""); // TODO séparer les appels ajax de traitement de réponses //obj.setErrorCode(error); } } } } return myXmlHttp; } /** * Send date * @param obj obj which implements receive() method * @param string [HTTP_GET|HTTP_POST] * @param string url of datas * @param string data to send with the following structure : var1=value1&var2=value2... */ function sendData(obj, method, url, data) { var myXmlHttp = getXmlObject(obj); if (!myXmlHttp) return false; if(method == HTTP_GET) { var myDate = new Date(); data += "&dummydata=" + myDate.getTime(); //alert(url+"?"+data); if(data == 'null') myXmlHttp.open(HTTP_GET, url, true); else myXmlHttp.open(HTTP_GET, url+"?"+data, true); myXmlHttp.send(null); } else if(method == HTTP_POST) { myXmlHttp.open(HTTP_POST, url, true); myXmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); myXmlHttp.send(data); } return true; } /*------------------------------- Static method --------------------------------*/ function getObj(id){ return document.getElementById(id); } function getSelectValue(obj) { var retVal = ""; if(getObj(obj).selectedIndex > -1 && getObj(obj).options[getObj(obj).selectedIndex].value!="") retVal = getObj(obj).options[getObj(obj).selectedIndex].value; else retVal = getObj(obj).options[0].value; return retVal; } function getSelectHtml(obj) { return getObj(obj).options[getObj(obj).selectedIndex].text; } /* Text functions */ var charsToDelete = new Array(); charsToDelete[0] = String.fromCharCode(9); // tabulation charsToDelete[1] = String.fromCharCode(10); // lineFeed charsToDelete[2] = String.fromCharCode(13); // carriageReturn function trim(string){ var retVal = ""; for(var count=0;count