

var bBlocAjax=0;

function getXMLHttpResquest(){
var oXmlhttp;

if (window.XMLHttpRequest){
oXmlhttp = new XMLHttpRequest();
}
else if(window.ActiveXObject) {
oXmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
return oXmlhttp;
}


function IsiAjax(sURL) {
this.sTargetURL = sURL;
}
IsiAjax.prototype = {
sTargetURL   : "",
sTargetCtrlID  : "",
sResponse   : "",
lastStatus   : "",       // derniere etat obtenu par la requete HTTP
silentMode   : false,      // indique qu'on veut un mode silencieux, les erreurs ne sont pas affichees

init : function (){
this.oXmlhttp = getXMLHttpResquest();
},
afterResponse : function () {

},
freeMemory : function(){
delete this.oXmlhttp;
},

redirectResponseToOutput : function(sData) {
var oTarget = document.getElementById(this.sTargetCtrlID);
if (oTarget) {
oTarget.value = sData;
this.afterResponse ( oTarget);
}
this.freeMemory();
},


SyncExecute : function ( sData, sMethod, sSendType, sReturnType){

if (!sMethod ||!sReturnType){
return;
}

if (sMethod == "POST") {
this.oXmlhttp.open(sMethod, appendSessionId ( this.sTargetURL), false);
if (sSendType == "TEXT") {
this.oXmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
} else if (sSendType == "XML") {
this.oXmlhttp.setRequestHeader("Content-type", "text/xml");
}
} else {
this.oXmlhttp.open(sMethod, appendSessionId ( this.sTargetURL + "?" + sData), false);
sData = "";
}

this.oXmlhttp.send(sData);

if (this.oXmlhttp.readyState == 4) {
this.lastStatus = this.oXmlhttp.status;

if (this.oXmlhttp.status == 200) {

if (sReturnType == "XML") {
this.sResponse = this.oXmlhttp.responseXML;
} else {
this.sResponse = this.oXmlhttp.responseText;
}

if (this) {
this.redirectResponseToOutput(this.sResponse);
iws_ChangeStatusPage( ISI_PRODUCT_NAME);
}
} else {
if (this.silentMode == false) {
this._setWindowStatus ( this.oXmlhttp.status, this.oXmlhttp.statusText);
}
}

} else {
this.sResponse = false;
}

this.freeMemory();

return this.sResponse;
},


AsyncExecute : function(sData, sMethod, bCancelLastRequest, sSendType, sReturnType)
{
if (!sMethod ||!sReturnType){
return;
}

if (bCancelLastRequest){
if (this.oXmlhttp.readyState > 0){
this.oXmlhttp.abort();
}
}

if (sMethod == "POST"){
this.oXmlhttp.open(sMethod, appendSessionId ( this.sTargetURL), true);
if (sSendType == "TEXT") {
this.oXmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
} else if (sSendType == "XML") {
this.oXmlhttp.setRequestHeader("Content-type", "text/xml");
}
}
else {
this.oXmlhttp.open(sMethod, appendSessionId ( this.sTargetURL + "?" + sData), true);
sData = "";
}

var oAjaxChild = this;
this.oXmlhttp.onreadystatechange = function()
{
if (oAjaxChild.oXmlhttp.readyState == 4) {

if (oAjaxChild.oXmlhttp.status == 200) {

if (sReturnType == "XML")
oAjaxChild.sResponse = oAjaxChild.oXmlhttp.responseXML;
else
oAjaxChild.sResponse = oAjaxChild.oXmlhttp.responseText;

if (oAjaxChild) {
oAjaxChild.redirectResponseToOutput(oAjaxChild.sResponse);
iws_ChangeStatusPage( ISI_PRODUCT_NAME);
}
} else {
if (oAjaxChild.silentMode == false) {
oAjaxChild._setWindowStatus ( oAjaxChild.oXmlhttp.status, oAjaxChild.oXmlhttp.statusText);
}
}
oAjaxChild = null;
}
}

oAjaxChild.oXmlhttp.send(sData);

},

setOutput : function(sCtrlID){
this.sTargetCtrlID = sCtrlID;
},

_setWindowStatus : function ( num, txt) {
window.status = "IsiAjax failed - Error " + num + " : " + txt;
}
}


function IsiSuggestAjax(sURL)
{
this.sTargetURL = sURL;
var oIsiSuggestDIV;// = new IsiSuggestDIV();
}

IsiSuggestAjax.prototype = new IsiAjax();

IsiSuggestAjax.prototype.setOutput = function(ObjSuggest){
oIsiSuggestDIV = ObjSuggest;
}

IsiSuggestAjax.prototype.redirectResponseToOutput = function(sData) {

if (IsiSuggestDIV.prototype.isPrototypeOf(oIsiSuggestDIV)) {
try {
if (oIsiSuggestDIV.isValid()) {
if (sData) {
if (iws_isXmlAnalyserError( sData)) {
oIsiSuggestDIV.hideStrongly();
var elements = sData.split("#");
eval ( "alert (\"" + elements[1] + "\");" );
} else {

if (oIsiSuggestDIV.DeSerializeListOfValues(sData)) {
oIsiSuggestDIV.selectIndex();
oIsiSuggestDIV.updateInnerHTML();
oIsiSuggestDIV.show();
}
}
} else {
oIsiSuggestDIV.hideStrongly();
}
}

} catch (e) {
window.status = "Error in AJAX (client reception) [" + e.message + "]";
}
}
this.freeMemory();
}



function IsiJavaScriptAjax(sURL)
{
this.sTargetURL = sURL;
}

IsiJavaScriptAjax.prototype = new IsiAjax() ;

IsiJavaScriptAjax.prototype.redirectResponseToOutput = function(sData) {

if (sData) {
try {
eval(sData) ;
}
catch (e) { window.status = "Error in IsiJavaScriptAjax (client reception) [" + e.message + "]"; }
}
this.freeMemory();
}

function IsiTextDivAjax(sURL)
{
this.sTargetURL = sURL;

this.afterResponse = iws_majText;
}


IsiTextDivAjax.prototype = new IsiAjax() ;


function IsiAjaxTypeAction(sURL)
{
this.sTargetURL = sURL;
}

IsiAjaxTypeAction.prototype = new IsiAjax() ;

IsiAjaxTypeAction.prototype.redirectResponseToOutput = function(sData) {

if (sData) {
try {
var pIsiSerialize = new IsiSerialize(sData)
pIsiSerialize.Deserialize();

SetValueIfEmpty('inbJ_ACTIONPREV_' + TEXTBOX, pIsiSerialize.tDeSerializedString[0]);

if(iws_GetDateCtrlValue('idtHM_ACTIONPREV') == ""){
iws_SetDateCtrlValue('idtHM_ACTIONPREV',"01/01/1900 " + pIsiSerialize.tDeSerializedString[1]);
}
SetValueIfEmpty('icbC_EQUIPE_' + TEXTBOX, pIsiSerialize.tDeSerializedString[2]);
SetValueIfEmpty('icbC_EQUIPE_' + HIDDEN_VALUE, pIsiSerialize.tDeSerializedString[3]);

}
catch (e) { window.status = "Error in IsiAjaxTypeAction (client reception) [" + e.message + "]"; }
}
this.freeMemory();
}



function IsiSqlStatementAjax(sURL)
{
this.sTargetURL = sURL;
}

IsiSqlStatementAjax.prototype = new IsiAjax() ;

IsiSqlStatementAjax.prototype.redirectResponseToOutput = function(sData) {

if (sData) {
if (sData != ""){
if (confirm(sData)) {

if (document.getElementById("ihdConfirmation_"+HIDDEN)) {
document.getElementById("ihdConfirmation_"+HIDDEN).value = "OK";
}
} else {
if (document.getElementById("ihdConfirmation_"+HIDDEN)) {
document.getElementById("ihdConfirmation_"+HIDDEN).value = "ANNULER";
}
}
}
}
this.freeMemory();
}


function IsiTypeMessageAjax(sURL)
{
this.sTargetURL = sURL;
}

IsiTypeMessageAjax.prototype = new IsiAjax() ;

IsiTypeMessageAjax.prototype.redirectResponseToOutput = function(sData) {

if (sData) {
try {
var pIsiSerialize = new IsiSerialize(sData);
pIsiSerialize.Deserialize();

var oItxtA = document.getElementById('itxtA_' + TEXTBOX);
var oItxtCc = document.getElementById('itxtCc_' + TEXTBOX);
var oItxtBcc = document.getElementById('itxtCci_' + TEXTBOX);
var oItxtObjet = document.getElementById('itxtObjet_' + TEXTBOX);
var oHtmltxtMessage = document.getElementById('iHtmltxtMessage_' + TEXTBOX_MULTI);
var oHtmlMessage = document.getElementById('iHtmltxtMessage_' + TEXTDIV);
var cbFormat = document.getElementById('icbTypeEnvoie_' + TEXTBOX);

if (oItxtA)
oItxtA.value = pIsiSerialize.tDeSerializedString[0];

if (oItxtCc)
oItxtCc.value = pIsiSerialize.tDeSerializedString[1];

if (oItxtBcc)
oItxtBcc.value = pIsiSerialize.tDeSerializedString[2];

if (oItxtObjet)
oItxtObjet.value = pIsiSerialize.tDeSerializedString[3];

if (oHtmltxtMessage && oHtmlMessage && cbFormat){
if (((pIsiSerialize.tDeSerializedString[5] != 0) || (pIsiSerialize.tDeSerializedString[5] != "0")) && (!cbFormat.disabled)) {
iws_AfficheBarreOutil('iHtmltxtMessage', 'visible');
oHtmlMessage.style.visibility = 'visible';
oHtmltxtMessage.style.visibility = 'hidden';
iws_setComboValue ('icbTypeEnvoie', 1);

oHtmlMessage.innerHTML = pIsiSerialize.tDeSerializedString[4];
oHtmlMessage.focus();
}else{
iws_AfficheBarreOutil('iHtmltxtMessage', 'hidden');
oHtmlMessage.style.visibility = 'hidden';
oHtmltxtMessage.style.visibility = 'visible';
iws_setComboValue ('icbTypeEnvoie', 0);

oHtmltxtMessage.value = pIsiSerialize.tDeSerializedString[4];
}
}

bNoChangeOnLangue = true;
iws_setComboValue ( "icbLangueMail", pIsiSerialize.tDeSerializedString[6]);
bNoChangeOnLangue = false;
}
catch (e) { window.status = "Error in IsiTypeMessageAjax (client reception) [" + e.message + "]"; }
this.freeMemory();
}
}

function IsiAsyncTreeViewAjax(sURL)
{
this.sTargetURL = sURL;
}

IsiAsyncTreeViewAjax.prototype = new IsiAjax() ;

IsiAsyncTreeViewAjax.prototype.redirectResponseToOutput = function(sData) {
this.freeMemory();
}

var GET_VALUE = "GETVALUE";
var GET_TEXT = "GETTEXT";

function IsiAsyncCtrlConnexe(sURL)
{
this.sTargetURL = sURL;
}

IsiAsyncCtrlConnexe.prototype = new IsiAjax() ;

IsiAsyncCtrlConnexe.prototype.redirectResponseToOutput = function ( sData) {
var bHasChanged = false;
if (sData) {
var elements = sData.split("#");
var sAction = decodeURIComponent(elements[0]);
var sID = decodeURIComponent(elements[1]);
if (iws_isXmlAnalyserError ( sData)) {
eval ( "alert (\"" + sID + "\");" );
}
var oCtrlValue = document.getElementById(sID + "_" + HIDDEN_VALUE);
var oCtrlTxt = document.getElementById(sID + "_" + TEXTBOX);

if (elements[5] == "Err-SEVERAL_DATA")
{
return true;
}
if (oCtrlValue) {
if ( sAction == GET_VALUE) {
var _value = decodeURIComponent(elements[2]);
bHasChanged = (oCtrlValue.value != _value);
oCtrlValue.value = _value;
if (oCtrlTxt)
{
if (elements[3] != "") {
oCtrlTxt.value = decodeURIComponent(elements[3]);
}
if( _value == "" && oCtrlTxt.bIsAddable && oCtrlTxt.bIsAddable == "False")
{
oCtrlTxt.value =""
}

if (elements[3] != "" && oCtrlTxt.bIsAddable && oCtrlTxt.bIsAddable == "True")
{
oCtrlValue.value = oCtrlTxt.value;
}
}
} else if ( sAction == GET_TEXT) {


var _text = decodeURIComponent(elements[3]);
bHasChanged = (oCtrlTxt.value != _text);
oCtrlTxt.value = _text;

var oCtrlTxtFast = document.getElementById(sID + "_" + TEXTBOX_FAST_ID);
if (oCtrlTxtFast) {
oCtrlTxtFast.value = decodeURIComponent(elements[4]);
}

oCtrlValue.value = decodeURIComponent(elements[2]);
}


if (bHasChanged || bConnexSearch) {
try {
if (oCtrlTxt) {
iws_updateRelatedControls(oCtrlTxt);
bConnexSearch = false;
}
} catch(e) {}
}

if (elements[5]) {
bBlockOtherTreatment = true;
var oFullCtrl = iwsAllCtrls.getCtrl (sID);
var oMsg = GetMessagesForJavascript(true).GetMessage(elements[5]);
if ((oMsg.C_MESSAGE == "RESTRICTION-FILTER_NOT_ACCESS") || (oMsg.C_MESSAGE == "RESTRICTION-RESTRICTION_NOT_ACCESS"))
{
var sMsg = oMsg.L_MESSAGE + getCtrlCaption(sID, oFullCtrl.ctrlType) + ".";
alert(sMsg);
}
else
{
if (oMsg.C_MESSAGE == "Err-NO_EXIST")
{
sMsg = (oMsg.L_MESSAGE).replace("$c",oCtrlTxt.value) + ".";
alert(sMsg);
}
else
{
if (oMsg.C_MESSAGE == "Err-NOT_EXIST_BUT_CAN_EXIST")
{
sMsg = (oMsg.L_MESSAGE).replace("$c",oCtrlTxt.value);
if(confirm(sMsg))
{
bBlocAjax = 1;
document.getElementById("ihdItemClick").value = ""
onchangeState();
oCtrlTxt.focus();
SaveCtrlNameClick(sID+FIELD_SEPARATOR+ 'PROP',sID + "_" + TEXTBOX);
var oIwsCtrl = iwsAllCtrls.getCtrl(sID);
if (oIwsCtrl && oIwsCtrl.parentId){
sID = sID.replace(oIwsCtrl.parentId + "_" , oIwsCtrl.parentId + "$");
}
__doPostBack(sID +'$'+ LINK_BUTTON,'');
window.event.cancelBubble = true;
}
}
}
}
}
}
}
this.freeMemory();
}


function IsiScheduleAjax(sURL)
{
this.sTargetURL = sURL;

this.sAction = "";
this.sDate = "";
this.schViewType= "";
this.sCalendarId = "";
this.sActivityId = "";
this.sToCalendarId = "";
this.sBegin = "";
this.sEnd = "";
this.sId = "";
this.sValue = "";
this.eType = "";
this.pIsiSchedule = null;
}

IsiScheduleAjax.prototype = new IsiAjax();

IsiScheduleAjax.prototype.redirectResponseToOutput = function(sData) {

if (sData) {
this.pIsiSchedule.getAjaxReturn ( sData, this.sAction,
this.eType, this.sId, this.sValue,
this.sDate, this.schViewType, this.sCalendarId,
this.sActivityId, this.sToCalendarId, this.sBegin, this.sEnd);
}
this.freeMemory();
}

function IsiPreviewAjax(sURL)
{
this.sTargetURL = sURL;
this.sAction   = "";
this.sC_MEMO   = "";
this.sC_DOCOLE = "";
this.pIsiAttPreview = null;
}

IsiPreviewAjax.prototype = new IsiAjax();

IsiPreviewAjax.prototype.redirectResponseToOutput = function(sData) {

if (sData) {
this.pIsiAttPreview.getAjaxReturn ( sData, this.sAction);
}
this.freeMemory();
}

function IsiCaddyAjax(sURL)
{
this.sTargetURL = sURL;
}

IsiCaddyAjax.prototype = new IsiAjax();

IsiCaddyAjax.prototype.redirectResponseToOutput = function(sData) {

if (sData)
{

var urlVarAll = sData.split("#CADDY#");
var urlTraitementOK = urlVarAll[0];
var urlSumQteSouhaiteLigneDem = urlVarAll[1];
var urlsMessage = urlVarAll[2];
var urlBRefreshBandeau = urlVarAll[3];

if (urlTraitementOK == "OK" && urlBRefreshBandeau == "True")
{
var menuID = getMenuIDWithTag(igmenu_getItemById("mnuModule"), "PANIER");
igmenu_getItemById(menuID).setText("<IMG SRC='../../Images/MenuModule/panier.gif'><SPAN class='IsiCaddyNbItem'>&nbsp;" + urlSumQteSouhaiteLigneDem + "</SPAN>")
igmenu_getItemById(menuID).element.style.display = "inline";
igmenu_getItemById(menuID).element.style.visibility = "visible";
}

alert(urlsMessage);
}
}


function iws_ajax_dispose() {

delete IsiSuggestAjax;
delete IsiJavaScriptAjax;
delete IsiTextDivAjax;
delete IsiAjaxTypeAction;
delete IsiSqlStatementAjax;
delete IsiTypeMessageAjax;
delete IsiAsyncTreeViewAjax;
delete IsiAsyncCtrlConnexe;
delete IsiScheduleAjax;
delete IsiPreviewAjax;
delete IsiCaddyAjax;
delete IsiAjax;

}


