// JavaScript Document
/*********** Class Customer *************/
/*********** Version 1.0 ******************/
/*********** Author Yoann Phung Van *******/

if (typeof console != "object") {var console = {'log':function(){}};}

var Customer = function(wsPath, debugMode, postOrGet) {
  this.init(wsPath, debugMode);
}

$.extend(Customer.prototype, {
   
	// Proprietes
	wsUri: "",
	wsName: "",
	wsPath: getPathFromUrl(), 
	wsMethod: "",
	globalSessionId: "",
	debugMode: false, 
	
	init: function(wsPath, debugMode) {
		 // Constructeur
		 if(wsPath){
			this.setWsPath(wsPath);
		 }else{
			this.wsUri = this.wsPath;
		 }
		 if(debugMode){
			this.debugMode = debugMode;
		 }
	},
	//* Methodes de base ***************************
	
	setWsPath: function(wsPath) {
	 // Definition du chemin des webservices
	 this.wsPath = wsPath;
	 this.wsUri = this.wsPath;
	},	
	setWsName: function(wsName) {
	 // Definition du nom du webservice
	 this.wsName = wsName;
	 this.wsUri = this.wsPath + "/" + this.wsName;
	},		
	setWsMethod: function(wsMethod) {
	 // Definition de la method du webservice
	 this.wsMethod = wsMethod;
	 this.wsUri = this.wsPath + "/" + this.wsName + "/" + this.wsMethod;
	},	
	setGlobalSessionId: function(globalSessionId) {
	 // Definition du resultat retourne par le webservice
	 this.globalSessionId = globalSessionId;
	},
	getWsPath: function() {
	 // Recuperation du chemin des webservices
	 return this.wsPath;
	},	
	getWsMethod: function() {
	 // Recuperation de la method du webservice
	 return this.WsMethod;
	},
	getWsUri: function() {
	 // Recuperation de l'uri du webservice
	 return this.wsUri;
	},
	getWsName: function() {
	 // Recuperation du nom du webservice
	 return this.wsName;
	},
	getGlobalSessionId: function() {
	 // Recuperation du nom du webservice
	 return this.globalSessionId;
	},
	isDebugMode: function() {
	 // Est-on en mode debug ?
	 return this.debugMode;
	},
	//constitution de l'inputdata 
	customerData:function(update, sId, FirstName, LastName, Title, Email, AddressLine1, AddressLine2, AddressLine3, AddressExt1, AddressExt2 , AddressExt3, Zip, City, State, CountryName, CountryCode, LngCode, Phone, PhoneExt, BirthDate, DynamicProperties, Login, Password, Role){

		//Definition de l'inputData
		var inputData = "<Loreal_Reference_IN_SaveCustomerInfo>";
		if (update) inputData += "<SessionID>" + sId + "</SessionID>";
		
		if (FirstName && FirstName != '') inputData += "<FirstName>" + FirstName + "</FirstName>";
		if (LastName && LastName != '') inputData += "<LastName>" + LastName + "</LastName>";
		if (Title && Title != '') inputData += "<Title>" + Title + "</Title>";
		if (Email && Email != '') inputData += "<Email>" + Email + "</Email>";
		if (AddressLine1 && AddressLine1 != '') inputData += "<AddressLine1>" + AddressLine1 + "</AddressLine1>";
		if (AddressLine2 && AddressLine2 != '') inputData += "<AddressLine2>" + AddressLine2 + "</AddressLine2>";
		if (AddressLine3 && AddressLine3 != '') inputData += "<AddressLine3>" + AddressLine3 + "</AddressLine3>";
		if (AddressExt1 && AddressExt1 != '') inputData += "<AddressExt1>" + AddressExt1 + "</AddressExt1>";
		if (AddressExt2 && AddressExt2 != '') inputData += "<AddressExt2>" + AddressExt2 + "</AddressExt2>";
		if (AddressExt3 && AddressExt3 != '') inputData += "<AddressExt3>" + AddressExt3 + "</AddressExt3>";
		if (Zip && Zip != '') inputData += "<Zip>" + Zip + "</Zip>";
		if (City && City != '') inputData += "<City>" + City + "</City>";
		if (State && State != '') inputData += "<State>" + State + "</State>";
		if (CountryName && CountryName != '') inputData += "<CountryName>" + CountryName + "</CountryName>";
		if (CountryCode && CountryCode != '') inputData += "<CountryCode>" + CountryCode + "</CountryCode>";
		if (Phone && Phone != '') inputData += "<Phone>" + Phone + "</Phone>";
		if (PhoneExt && PhoneExt != '') inputData += "<PhoneExt>" + PhoneExt + "</PhoneExt>";
		if (BirthDate && BirthDate != '') inputData += "<BirthDate>" + BirthDate + "</BirthDate>";
		inputData += "<DynamicProperties>";
		//var DynamicProperties={link:'http://www.google.com', id:123};
		for(var obj in DynamicProperties){
			 if(DynamicProperties[obj]=="null"){
				 inputData += "<"+obj+"></"+obj+">";
			 }else{
			 	if (DynamicProperties[obj] != '') inputData += "<"+obj+">"+DynamicProperties[obj]+"</"+obj+">";
			 }
		}
		inputData += "</DynamicProperties>";
		if (Role && Role == "registered" && !update) {
			if (Login && Login != '') inputData += "<Login>" + Login + "</Login>";
			if (Password && Password != '') inputData += "<Password>" + Password + "</Password>";
		}
		if (Role && Role != '' && !update) inputData += "<Role>" + Role + "</Role>";
		inputData += "</Loreal_Reference_IN_SaveCustomerInfo>";
		
		return inputData;
	},	
	   
	//* Methodes webservices ************************
	InitSession:{		
		
		// Proprietes
		wsInputData: "",
		wsResult: "",
		wsError: "",
		sessionId: "",
		wsSuccess: false,
		
		call:function(){
			// Appel ajax
		    Customer.prototype.InitSession.callAjax();	
		},
		callAjax:function(){
			
			// Initialisation de l'appel
			Customer.prototype.InitSession.wsSuccess = false;
			Customer.prototype.setWsName("Customer.asmx");
			Customer.prototype.setWsMethod("InitSession");
			// Debug
			if(Customer.prototype.isDebugMode){
				console.log("InitSession uri : "+  Customer.prototype.getWsUri());
			}

			$.ajax({
				url: Customer.prototype.getWsUri(),
				cache: false,
				error: function (xhr, desc, exceptionobj) {
				  // Debug
				  if(Customer.prototype.isDebugMode){
						console.log("InitSession error : "+ xhr.responseText);
				  }
				  Customer.prototype.InitSession.wsSuccess = false;
				  //Callback
				  if (typeof(callBackInitSessionError) == 'function') callBackInitSessionError();

				},
				success: function(content){
				  var result = $(content).find("SessionID").text();
				  var errorMessage = $(content).find("Message").text();
				  // Debug
				  if(Customer.prototype.isDebugMode){
						console.log("InitSession result : "+  result);
				  }
				  Customer.prototype.InitSession.wsError = errorMessage;
				  Customer.prototype.InitSession.wsResult = content;
				  Customer.prototype.InitSession.sessionId = result;
				  Customer.prototype.InitSession.wsSuccess = true;
				  Customer.prototype.setGlobalSessionId(result);
				  
				  //Callback
				  if (typeof(callBackInitSession) == 'function') callBackInitSession();
				}
			});		
		},
		getXmlResult:function(){
			return Customer.prototype.InitSession.wsResult;
		},
		getXmlResultToString:function(){
			return xmlToString(Customer.prototype.InitSession.wsResult);
		},
		isSuccess: function() {
		    return Customer.prototype.InitSession.wsSuccess;
		},
		getSessionId:function(){
			return Customer.prototype.InitSession.sessionId;
		},
        getError:function(){
            return Customer.prototype.InitSession.wsError;
        }
		
	},
	
	CreatUserInfo:{
		
		// Proprietes
		wsInputData: "",
		wsResult: "",
		wsError: "",
		sessionId: "",
		wsSuccess: false,
		
		call:function(sId, FirstName, LastName, Title, Email, AddressLine1, AddressLine2, AddressLine3, AddressExt1, AddressExt2 , AddressExt3, Zip, City, State, CountryName, CountryCode, LngCode, Phone, PhoneExt, BirthDate, DynamicProperties, Login, Password, Role, TemplateEmailConfirmation){			
			
			//Récupération du sessionId			
			var sessionId = "";
			// Si le session Id est passé en paramètre
			if(sId && sId != null && sId != ""){
				sessionId = sId;
				// Appel ajax
				Customer.prototype.CreatUserInfo.callAjax(sessionId, FirstName, LastName, Title, Email, AddressLine1, AddressLine2, AddressLine3, AddressExt1, AddressExt2 , AddressExt3, Zip, City, State, CountryName, CountryCode, LngCode, Phone, PhoneExt, BirthDate, DynamicProperties, Login, Password, Role, TemplateEmailConfirmation);
				return true;
			}else{
				// Si le session Id doit être récupéré par un appel à initSession					
				if(Customer.prototype.globalSessionId == ""){
					Customer.prototype.InitSession.call();
					$(document).ajaxComplete(function(ev, xhr, s) { 
						if(xhr.status == 200 && s.url.indexOf("InitSession")>-1){						
							sessionId = Customer.prototype.InitSession.getSessionId();
						    // Appel ajax
						    Customer.prototype.CreatUserInfo.callAjax(sessionId, FirstName, LastName, Title, Email, AddressLine1, AddressLine2, AddressLine3, AddressExt1, AddressExt2 , AddressExt3, Zip, City, State, CountryName, CountryCode, LngCode, Phone, PhoneExt, BirthDate, DynamicProperties, Login, Password, Role, TemplateEmailConfirmation);	
							Customer.prototype.setGlobalSessionId(sessionId);
						    return true;
						}
					});			
					
				// Si le session Id a été récupéré précédemment et est présent en variable global					
				}else{
					
					sessionId = Customer.prototype.globalSessionId;
					// Appel ajax
					Customer.prototype.CreatUserInfo.callAjax(sessionId, FirstName, LastName, Title, Email, AddressLine1, AddressLine2, AddressLine3, AddressExt1, AddressExt2 , AddressExt3, Zip, City, State, CountryName, CountryCode, LngCode, Phone, PhoneExt, BirthDate, DynamicProperties, Login, Password, Role, TemplateEmailConfirmation);
					return true;
				}
			}			
			
        },
        
		callAjax:function(sId, FirstName, LastName, Title, Email, AddressLine1, AddressLine2, AddressLine3, AddressExt1, AddressExt2 , AddressExt3, Zip, City, State, CountryName, CountryCode, LngCode, Phone, PhoneExt, BirthDate, DynamicProperties, Login, Password, Role, TemplateEmailConfirmation){
            //initialisation de l'appel
            Customer.prototype.CreatUserInfo.wsSuccess = false;
            Customer.prototype.setWsName("Customer.asmx");
            Customer.prototype.setWsMethod("CreatUserInfo");

			//definition de l'inputdata
            Customer.prototype.CreatUserInfo.wsInputData = Customer.prototype.customerData(false, sId, FirstName, LastName, Title, Email, AddressLine1, AddressLine2, AddressLine3, AddressExt1, AddressExt2 , AddressExt3, Zip, City, State, CountryName, CountryCode, LngCode, Phone, PhoneExt, BirthDate, DynamicProperties, Login, Password, Role, TemplateEmailConfirmation);
			
            // Debug
            if(Customer.prototype.isDebugMode){
                console.log("CreatUserInfo Appel : "+  Customer.prototype.getWsUri());
                console.log("CreatUserInfo input Data : "+ Customer.prototype.CreatUserInfo.wsInputData);
            }
			
            $.ajax({
                url: Customer.prototype.getWsUri(),
                data: "inputData="+Customer.prototype.CreatUserInfo.wsInputData,
                cache: false,
                type : "POST",
                error: function (xhr, desc, exceptionobj) {
                    // Debug
                    if(Customer.prototype.isDebugMode){
                        console.log("CreatUserInfo Error : "+ xhr.responseText);
                    }
                    Customer.prototype.CreatUserInfo.wsSuccess = false;
					//Callback
				    if (typeof(callBackCreatUserInfoError) == 'function') callBackCreatUserInfoError();
					
                },
                success: function(content){
                    var result = $(content).find("SessionID").text();
                    var errorMessage = $(content).find("Message").text();
                    // Debug
                    if(Customer.prototype.isDebugMode){
                        console.log("CreatUserInfo sessionId : "+  result);
                    }					
					if(errorMessage=="" && (TemplateEmailConfirmation && TemplateEmailConfirmation!="")){
						Customer.prototype.SendEmailConfirmation.call(result, TemplateEmailConfirmation, "HTML");	
					}	
				    Customer.prototype.CreatUserInfo.wsError = errorMessage;
				    Customer.prototype.CreatUserInfo.wsResult = content;
				    Customer.prototype.CreatUserInfo.sessionId = result;
				    Customer.prototype.CreatUserInfo.wsSuccess = true;
                    Customer.prototype.setGlobalSessionId(result);
					
					//Callback
				    if (typeof(callBackCreatUserInfo) == 'function') callBackCreatUserInfo();

                }
            });
        },
		getXmlResult:function(){
			return Customer.prototype.CreatUserInfo.wsResult;
		},
		getXmlResultToString:function(){
			return xmlToString(Customer.prototype.CreatUserInfo.wsResult);
		},
		isSuccess: function() {
		 return Customer.prototype.CreatUserInfo.wsSuccess;
		},
		getSessionId:function(){
			return Customer.prototype.CreatUserInfo.sessionId;
		},
        getError:function(){
            return Customer.prototype.CreatUserInfo.wsError;
        }
		
	},
	
	SaveUserInfo:{
		
		// Proprietes
		wsInputData: "",
		wsResult: "",
		wsError: "",
		sessionId: "",
		wsSuccess: false,
	
		call:function(sId, FirstName, LastName, Title, Email, AddressLine1, AddressLine2, AddressLine3, AddressExt1, AddressExt2 , AddressExt3, Zip, City, State, CountryName, CountryCode, LngCode, Phone, PhoneExt, BirthDate, DynamicProperties, Login, Password, Role){			
			
			//Récupération du sessionId			
			var sessionId = "";
			// Si le session Id est passé en paramètre
			if(sId && sId != null && sId != ""){
				sessionId = sId;
				// Appel ajax
				Customer.prototype.SaveUserInfo.callAjax(sessionId, FirstName, LastName, Title, Email, AddressLine1, AddressLine2, AddressLine3, AddressExt1, AddressExt2 , AddressExt3, Zip, City, State, CountryName, CountryCode, LngCode, Phone, PhoneExt, BirthDate, DynamicProperties, Login, Password, Role);
				return true;
			}else{
				// Si le session Id doit être récupéré par un appel à initSession					
				if(Customer.prototype.globalSessionId == ""){
					Customer.prototype.InitSession.call();
					$(document).ajaxComplete(function(ev, xhr, s) { 
						if(xhr.status == 200 && s.url.indexOf("InitSession")>-1){						
							sessionId = Customer.prototype.InitSession.getSessionId();
						    // Appel ajax
						    Customer.prototype.SaveUserInfo.callAjax(sessionId, FirstName, LastName, Title, Email, AddressLine1, AddressLine2, AddressLine3, AddressExt1, AddressExt2 , AddressExt3, Zip, City, State, CountryName, CountryCode, LngCode, Phone, PhoneExt, BirthDate, DynamicProperties, Login, Password, Role);
							Customer.prototype.setGlobalSessionId(sessionId);
						    return true;
						}
					});			
					
				// Si le session Id a été récupéré précédemment et est présent en variable global					
				}else{
					
					sessionId = Customer.prototype.globalSessionId;
					// Appel ajax
					Customer.prototype.SaveUserInfo.callAjax(sessionId, FirstName, LastName, Title, Email, AddressLine1, AddressLine2, AddressLine3, AddressExt1, AddressExt2 , AddressExt3, Zip, City, State, CountryName, CountryCode, LngCode, Phone, PhoneExt, BirthDate, DynamicProperties, Login, Password, Role);
					return true;
				}
			}			
			
        },
        
		callAjax:function(sId, FirstName, LastName, Title, Email, AddressLine1, AddressLine2, AddressLine3, AddressExt1, AddressExt2 , AddressExt3, Zip, City, State, CountryName, CountryCode, LngCode, Phone, PhoneExt, BirthDate, DynamicProperties, Login, Password, Role){
            //initialisation de l'appel
            Customer.prototype.SaveUserInfo.wsSuccess = false;
            Customer.prototype.setWsName("Customer.asmx");
            Customer.prototype.setWsMethod("SaveUserInfo");

			//Definition de l'inputData
            Customer.prototype.SaveUserInfo.wsInputData = Customer.prototype.customerData(true, sId, FirstName, LastName, Title, Email, AddressLine1, AddressLine2, AddressLine3, AddressExt1, AddressExt2 , AddressExt3, Zip, City, State, CountryName, CountryCode, LngCode, Phone, PhoneExt, BirthDate, DynamicProperties, Login, Password, Role);
			
            // Debug
            if(Customer.prototype.isDebugMode){
                console.log("SaveUserInfo Appel : "+  Customer.prototype.getWsUri());
                console.log("SaveUserInfo input Data : "+ Customer.prototype.SaveUserInfo.wsInputData);
            }
            $.ajax({
                url: Customer.prototype.getWsUri(),
                data: "inputData="+Customer.prototype.SaveUserInfo.wsInputData,
                cache: false,
                type : "POST",
                error: function (xhr, desc, exceptionobj) {
                    // Debug
                    if(Customer.prototype.isDebugMode){
                        console.log("SaveUserInfo Error : "+ xhr.responseText);
                    }
					Customer.prototype.SaveUserInfo.wsSuccess = false;
					
					//Callback
				    if (typeof(callBackSaveUserInfoError) == 'function') callBackSaveUserInfoError();

                },
                success: function(content){
                    var result = $(content).find("SessionID").text();
                    var errorMessage = $(content).find("Message").text();
                    // Debug
                    if(Customer.prototype.isDebugMode){
                        console.log("SaveUserInfo sessionId : "+  result);
                    }
				    Customer.prototype.SaveUserInfo.wsError = errorMessage;
				    Customer.prototype.SaveUserInfo.wsResult = content;
				    Customer.prototype.SaveUserInfo.sessionId = result;
				    Customer.prototype.SaveUserInfo.wsSuccess = true;
                    Customer.prototype.setGlobalSessionId(result);
					
					//Callback
				    if (typeof(callBackSaveUserInfo) == 'function') callBackSaveUserInfo();
                }
            });
        },
		getXmlResult:function(){
			return Customer.prototype.SaveUserInfo.wsResult;
		},
		getXmlResultToString:function(){
			return xmlToString(Customer.prototype.SaveUserInfo.wsResult);
		},
		isSuccess: function() {
		 return Customer.prototype.SaveUserInfo.wsSuccess;
		},
		getSessionId:function(){
			return Customer.prototype.SaveUserInfo.sessionId;
		},
        getError:function(){
            return Customer.prototype.SaveUserInfo.wsError;
        }

	},
	

	GetUserInfo:{
	
		// Proprietes
		wsInputData: "",
		wsResult: "",
		wsError: "",
		sessionId: "",
		wsSuccess: false,
		
		call:function(sId){
			
			//Récupération du sessionId			
			var sessionId = "";
			// Si le session Id est passé en paramètre
			if(sId && sId != null && sId != ""){
				sessionId = sId;
				// Appel ajax
				Customer.prototype.GetUserInfo.callAjax(sessionId);	
				return true;
			}else{
				// Si le session Id doit être récupéré par un appel à initSession					
				if(Customer.prototype.globalSessionId == ""){
					Customer.prototype.InitSession.call();
					$(document).ajaxComplete(function(ev, xhr, s) { 
						if(xhr.status == 200 && s.url.indexOf("InitSession")>-1){						
							sessionId = Customer.prototype.InitSession.getSessionId();
						    // Appel ajax
						    Customer.prototype.GetUserInfo.callAjax(sessionId);	
							Customer.prototype.setGlobalSessionId(sessionId);
						    return true;
						}
					});			
					
				// Si le session Id a été récupéré précédemment et est présent en variable global					
				}else{
					
					sessionId = Customer.prototype.globalSessionId;
					// Appel ajax
					Customer.prototype.GetUserInfo.callAjax(sessionId);	
					return true;
				}
			}
		},
		
		callAjax:function(sessionId){
		    
			//initialisation de l'appel
			Customer.prototype.GetUserInfo.wsSuccess = false;
			Customer.prototype.setWsName("Customer.asmx");
			Customer.prototype.setWsMethod("GetUserInfo");

			//Definition de l'inputData
			Customer.prototype.GetUserInfo.wsInputData = "<GetCustomerInfo><SessionID>"+sessionId+"</SessionID></GetCustomerInfo>";
			// Debug
			if(Customer.prototype.isDebugMode){
				console.log("GetUserInfo Appel : "+  Customer.prototype.getWsUri());
				console.log("GetUserInfo input Data : "+ Customer.prototype.GetUserInfo.wsInputData);
			}	
		
			$.ajax({
				url: Customer.prototype.getWsUri(),
                type : "POST",
				data: "inputData="+Customer.prototype.GetUserInfo.wsInputData,
				cache: false,
				error: function (xhr, desc, exceptionobj) {
				  // Debug
				  if(Customer.prototype.isDebugMode){
						console.log("GetUserInfo Error : "+ xhr.responseText);
				  }
			      Customer.prototype.GetUserInfo.wsSuccess = false;
				  
				  //Callback
				  if (typeof(callBackGetUserInfoError) == 'function') callBackGetUserInfoError();
				  
				},
				success: function(content){
				  var result = $(content).find("SessionID").text();
				  var errorMessage = $(content).find("Message").text();
				  // Debug
				  if(Customer.prototype.isDebugMode){
						console.log("GetUserInfo sessionId : "+  result);
				  }
				  Customer.prototype.GetUserInfo.wsError = errorMessage;
				  Customer.prototype.GetUserInfo.wsResult = content;
				  Customer.prototype.GetUserInfo.sessionId = result;
				  Customer.prototype.GetUserInfo.wsSuccess = true;
				  Customer.prototype.setGlobalSessionId(result);
				  
				  //Callback
				  if (typeof(callBackGetUserInfo) == 'function') callBackGetUserInfo();
				}
			});			
		},
		getXmlResult:function(){
			return Customer.prototype.GetUserInfo.wsResult;
		},
		getXmlResultToString:function(){
			return xmlToString(Customer.prototype.GetUserInfo.wsResult);
		},
		isSuccess: function() {
		 return Customer.prototype.GetUserInfo.wsSuccess;
		},
		getSessionId:function(){
			return Customer.prototype.GetUserInfo.sessionId;
		},
        getError:function(){
            return Customer.prototype.GetUserInfo.wsError;
        },
		getInfo:function(info){
			var result = $(Customer.prototype.GetUserInfo.wsResult).find(info).text();
			return result;
		}	
		
	},
	
	SearchUser:{
	
		// Proprietes
		wsInputData: "",
		wsResult: "",
		wsError: "",
		sessionId: "",
		wsSuccess: false,
		
		call:function(criteres, orderby){
			// Appel ajax
			Customer.prototype.SearchUser.callAjax(criteres, orderby);	
			return true;
		},
		
		callAjax:function(criteres, orderby){
		    
			//initialisation de l'appel
			Customer.prototype.SearchUser.wsSuccess = false;
			Customer.prototype.setWsName("Customer.asmx");
			Customer.prototype.setWsMethod("SearchUser");

			var inputData = "<CustomerSearch>";
			inputData += "<SessionID />";
			inputData += "<Criterias>"+criteres+"</Criterias>";
			inputData += "<OrderBy>"+orderby+"</OrderBy>";
			inputData += "</CustomerSearch>";

			//Definition de l'inputData
			Customer.prototype.SearchUser.wsInputData = inputData;
			// Debug
			if(Customer.prototype.isDebugMode){
				console.log("SearchUser Appel : "+  Customer.prototype.getWsUri());
				console.log("SearchUser input Data : "+ Customer.prototype.SearchUser.wsInputData);
			}	
		
			$.ajax({
				url: Customer.prototype.getWsUri(),
                type : "POST",
				data: "inputData="+Customer.prototype.SearchUser.wsInputData,
				cache: false,
				error: function (xhr, desc, exceptionobj) {
				  // Debug
				  if(Customer.prototype.isDebugMode){
						console.log("SearchUser Error : "+ xhr.responseText);
				  }
			      Customer.prototype.SearchUser.wsSuccess = false;
				  //Callback
				  if (typeof(callBackSearchUserError) == 'function') callBackSearchUserError();
				  
				},
				success: function(content){
				  var result = $(content).find("SessionID").text();
				  var errorMessage = $(content).find("Message").text();
				  // Debug
				  if(Customer.prototype.isDebugMode){
						console.log("SearchUser sessionId : "+  result);
				  }
				  Customer.prototype.SearchUser.wsError = errorMessage;
				  Customer.prototype.SearchUser.wsResult = content;
				  Customer.prototype.SearchUser.sessionId = result;
				  Customer.prototype.SearchUser.wsSuccess = true;
				  Customer.prototype.setGlobalSessionId(result);
				  
				  //Callback
				  if (typeof(callBackSearchUser) == 'function') callBackSearchUser();
				}
			});			
		},
		getXmlResult:function(){
			return Customer.prototype.SearchUser.wsResult;
		},
		getXmlResultToString:function(){
			return xmlToString(Customer.prototype.SearchUser.wsResult);
		},
		isSuccess: function() {
		 return Customer.prototype.SearchUser.wsSuccess;
		},
		getSessionId:function(){
			return Customer.prototype.SearchUser.sessionId;
		},
        getError:function(){
            return Customer.prototype.SearchUser.wsError;
        },
		getInfo:function(info){
			var result = $(Customer.prototype.SearchUser.wsResult).find(info).text();
			return result;
		}	

	},
	InitCookie:{
	
	
	},
	
	SendEmailConfirmation:{
	
		// Proprietes
		wsInputData: "",
		wsResult: "",
		wsError: "",
		sessionId: "",
		wsSuccess: false,
		
		call:function(sId, xml, format){
			// Appel ajax
			
			//Récupération du sessionId			
			var sessionId = "";
			// Si le session Id est passé en paramètre
			if(sId && sId != null && sId != ""){
				sessionId = sId;
				// Appel ajax
				Customer.prototype.SendEmailConfirmation.callAjax(sessionId, xml, format);
				return true;
			}else{
				// Si le session Id doit être récupéré par un appel à initSession					
				if(Customer.prototype.globalSessionId == ""){
					Customer.prototype.InitSession.call();
					$(document).ajaxComplete(function(ev, xhr, s) { 
						if(xhr.status == 200 && s.url.indexOf("InitSession")>-1){						
							sessionId = Customer.prototype.InitSession.getSessionId();
						    // Appel ajax
						    Customer.prototype.SendEmailConfirmation.callAjax(sessionId, xml, format);
							Customer.prototype.setGlobalSessionId(sessionId);
						    return true;
						}
					});			
					
				// Si le session Id a été récupéré précédemment et est présent en variable global					
				}else{
					
					sessionId = Customer.prototype.globalSessionId;
					// Appel ajax
					Customer.prototype.SendEmailConfirmation.callAjax(sessionId, xml, format);
					return true;
				}
			}
				
			return true;
		},
		
		callAjax:function(sId, xml, format){
		    
			//initialisation de l'appel
			Customer.prototype.SendEmailConfirmation.wsSuccess = false;
			Customer.prototype.setWsName("Customer.asmx");
			Customer.prototype.setWsMethod("SendEmailConfirmation");

			var inputData = "<Loreal_Reference_IN_SendMail>";
			inputData +="<SessionID>"+sId+"</SessionID>";
			inputData +="<TemplateName>"+xml+"</TemplateName>";
			inputData +="<Format>"+format+"</Format>";
			inputData += "</Loreal_Reference_IN_SendMail>";

			//Definition de l'inputData
			Customer.prototype.SendEmailConfirmation.wsInputData = inputData;
			// Debug
			if(Customer.prototype.isDebugMode){
				console.log("SendEmailConfirmation Appel : "+  Customer.prototype.getWsUri());
				console.log("SendEmailConfirmation input Data : "+ Customer.prototype.SendEmailConfirmation.wsInputData);
			}	
		
			$.ajax({
				url: Customer.prototype.getWsUri(),
                type : "POST",
				data: "inputData="+Customer.prototype.SendEmailConfirmation.wsInputData,
				cache: false,
				error: function (xhr, desc, exceptionobj) {
				  // Debug
				  if(Customer.prototype.isDebugMode){
						console.log("SendEmailConfirmation Error : "+ xhr.responseText);
				  }
			      Customer.prototype.SendEmailConfirmation.wsSuccess = false;
				  
				  //Callback
				  if (typeof(callBackSendEmailConfirmationError) == 'function') callBackSendEmailConfirmationError();
				},
				success: function(content){
				  var result = $(content).find("SessionID").text();
				  var errorMessage = $(content).find("Message").text();
				  // Debug
				  if(Customer.prototype.isDebugMode){
						console.log("SendEmailConfirmation sessionId : "+  result);
				  }
				  Customer.prototype.SendEmailConfirmation.wsError = errorMessage;
				  Customer.prototype.SendEmailConfirmation.wsResult = content;
				  Customer.prototype.SendEmailConfirmation.sessionId = result;
				  Customer.prototype.SendEmailConfirmation.wsSuccess = true;
				  Customer.prototype.setGlobalSessionId(result);
				  //Callback
				  if (typeof(callBackSendEmailConfirmation) == 'function') callBackSendEmailConfirmation();
				}
			});			
		},
		getXmlResult:function(){
			return Customer.prototype.SendEmailConfirmation.wsResult;
		},
		getXmlResultToString:function(){
			return xmlToString(Customer.prototype.SendEmailConfirmation.wsResult);
		},
		isSuccess: function() {
		 return Customer.prototype.SendEmailConfirmation.wsSuccess;
		},
		getSessionId:function(){
			return Customer.prototype.SendEmailConfirmation.sessionId;
		},
        getError:function(){
            return Customer.prototype.SendEmailConfirmation.wsError;
        }
	
	
	},
	
	CustomerLogin:{

		// Proprietes
		wsInputData: "",
		wsResult: "",
		wsError: "",
		sessionId: "",
		wsSuccess: false,
		
		call:function(login, password){
			// Appel ajax
		    Customer.prototype.CustomerLogin.callAjax(login, password);
		},
		
		callAjax:function(login, password){
		    
			//initialisation de l'appel
			Customer.prototype.CustomerLogin.wsSuccess = false;
			Customer.prototype.setWsName("Customer.asmx");
			Customer.prototype.setWsMethod("CustomerLogin");

			//Definition de l'inputData
			Customer.prototype.CustomerLogin.wsInputData = "<Loreal_Reference_IN_CustomerLogin><SessionID></SessionID><Login>"+login+"</Login><Password>"+password+"</Password></Loreal_Reference_IN_CustomerLogin>";
			// Debug
			if(Customer.prototype.isDebugMode){
				console.log("CustomerLogin Appel : "+  Customer.prototype.getWsUri());
				console.log("CustomerLogin input Data : "+ Customer.prototype.CustomerLogin.wsInputData);
			}	
		
			$.ajax({
				url: Customer.prototype.getWsUri(),
				data: "inputData="+Customer.prototype.CustomerLogin.wsInputData,
                type : "POST",
				cache: false,
				error: function (xhr, desc, exceptionobj) {
				  // Debug
				  if(Customer.prototype.isDebugMode){
						console.log("CustomerLogin Error : "+ xhr.responseText);
				  }
			      Customer.prototype.CustomerLogin.wsSuccess = false;
				  
				  //Callback
				  if (typeof(callBackCustomerLoginError) == 'function') callBackCustomerLoginError();
				  
				},
				success: function(content){
				  var result = $(content).find("SessionID").text();
				  var errorMessage = $(content).find("Message").text();
				  // Debug
				  if(Customer.prototype.isDebugMode){
						console.log("CustomerLogin sessionId : "+  result);
				  }
				  Customer.prototype.CustomerLogin.wsError = errorMessage;
				  Customer.prototype.CustomerLogin.wsResult = content;
				  Customer.prototype.CustomerLogin.sessionId = result;
				  Customer.prototype.CustomerLogin.wsSuccess = true;
				  Customer.prototype.setGlobalSessionId(result);
				  
				  //Callback
				  if (typeof(callBackCustomerLogin) == 'function') callBackCustomerLogin();
				  
				}
			});			
		},
		getXmlResult:function(){
			return Customer.prototype.CustomerLogin.wsResult;
		},
		getXmlResultToString:function(){
			return xmlToString(Customer.prototype.CustomerLogin.wsResult);
		},
		isSuccess: function() {
		 return Customer.prototype.CustomerLogin.wsSuccess;
		},
		getSessionId:function(){
			return Customer.prototype.CustomerLogin.sessionId;
		},
        getError:function(){
            return Customer.prototype.CustomerLogin.wsError;
        }
	
	},
	
	TellAFriend:{
        
		// Proprietes
		wsInputData: "",
		wsResult: "",
		wsError: "",
		sessionId: "",
		wsSuccess: false,
		
		call:function(sId, firstNameFriend, emailFriend, firstNameUser, emailUser, templateName, customs){
			//Récupération du sessionId			
			var sessionId = "";
			// Si le session Id est passé en paramètre
			if(sId && sId != null && sId != ""){
				sessionId = sId;
				// Appel ajax
				Customer.prototype.TellAFriend.callAjax(sessionId, firstNameFriend, emailFriend, firstNameUser, emailUser, templateName, customs);
				return true;
			}else{
				// Si le session Id doit être récupéré par un appel à initSession					
				if(Customer.prototype.globalSessionId == ""){
					Customer.prototype.InitSession.call();
					$(document).ajaxComplete(function(ev, xhr, s) { 
						if(xhr.status == 200 && s.url.indexOf("InitSession")>-1){						
							sessionId = Customer.prototype.InitSession.getSessionId();
						    // Appel ajax
						    Customer.prototype.TellAFriend.callAjax(sessionId, firstNameFriend, emailFriend, firstNameUser, emailUser, templateName, customs);
							Customer.prototype.setGlobalSessionId(sessionId);
						    return true;
						}
					});			
					
				// Si le session Id a été récupéré précédemment et est présent en variable global					
				}else{
					
					sessionId = Customer.prototype.globalSessionId;
					// Appel ajax
					Customer.prototype.TellAFriend.callAjax(sessionId, firstNameFriend, emailFriend, firstNameUser, emailUser, templateName, customs);	
					return true;
				}
			}
			
        },
        callAjax:function(sId, firstNameFriend, emailFriend, firstNameUser, emailUser, templateName, customs){
            //initialisation de l'appel
            Customer.prototype.TellAFriend.wsSuccess = false;
            Customer.prototype.setWsName("Customer.asmx");
            Customer.prototype.setWsMethod("TellAFriend");
            var customsXml = "";
			if(customs && typeof(customs) == 'string'){ 
				// Star fixing webservice which is not working with additonal parameters added with &
				customs = customs.split("#");
				customs = customs[0];
				customs = customs.split("&");
				customs = customs[0];
				customsXml = "<Url><![CDATA["+customs+"]]></Url>";
				// End fixing			
			}else if(customs && (typeof(customs) == 'array' || typeof(customs) == 'object')){
				for(var obj in customs){
					 if (customs[obj] != '') customsXml += "<"+obj+"><![CDATA["+customs[obj]+"]]></"+obj+">";
				}
			} 
			
			// Debug
            if(Customer.prototype.isDebugMode){
                if(customs){
				 console.log("TellAFriend Type Customs : "+  typeof(customs));
				}
				console.log("TellAFriend customs : "+  customsXml);
            }
			
            //Definition de l'inputData
            var inputData = "<Loreal_Reference_IN_TellAFriend>";
			inputData += "<SessionID>"+sId+"</SessionID>";
			inputData += "<Customer><FirstName><![CDATA["+firstNameUser+"]]></FirstName><Email><![CDATA["+emailUser+"]]></Email></Customer>";
			inputData += "<Friend><FirstName><![CDATA["+firstNameFriend+"]]></FirstName><Email><![CDATA["+emailFriend+"]]></Email></Friend>";
			inputData += "<TemplateName>"+templateName+"</TemplateName>";
			inputData += "<Customs>"+customsXml+"</Customs>";
			inputData += "</Loreal_Reference_IN_TellAFriend>";
            
			Customer.prototype.TellAFriend.wsInputData = inputData ;
			
			// Debug
            if(Customer.prototype.isDebugMode){
                console.log("TellAFriend Appel : "+  Customer.prototype.getWsUri());
                console.log("TellAFriend input Data : "+ Customer.prototype.TellAFriend.wsInputData);
            }
            $.ajax({
                url: Customer.prototype.getWsUri(),
                data: "inputData="+Customer.prototype.TellAFriend.wsInputData,
                cache: false,
                type : "POST",
                error: function (xhr, desc, exceptionobj) {
                    // Debug
                    if(Customer.prototype.isDebugMode){
                        console.log("TellAFriend Error : "+ xhr.responseText);
                    }
                    Customer.prototype.TellAFriend.wsSuccess = false;
					
				    //Callback
				    if (typeof(callBackTellAFriendError) == 'function') callBackTellAFriendError();
					
                },
                success: function(content){
                    var result = $(content).find("SessionID").text();
                    var errorMessage = $(content).find("Message").text();
                    // Debug
                    if(Customer.prototype.isDebugMode){
                        console.log("TellAFriend sessionId : "+  result);
                    }
					Customer.prototype.TellAFriend.wsError = errorMessage;
					Customer.prototype.TellAFriend.wsResult = content;
					Customer.prototype.TellAFriend.sessionId = result;
					Customer.prototype.TellAFriend.wsSuccess = true;
					Customer.prototype.setGlobalSessionId(result);
					
				    //Callback
				    if (typeof(callBackTellAFriend) == 'function') callBackTellAFriend();
                }
            });
        },
		getXmlResult:function(){
			return Customer.prototype.TellAFriend.wsResult;
		},
		getXmlResultToString:function(){
			return xmlToString(Customer.prototype.TellAFriend.wsResult);
		},
		isSuccess: function() {
		 return Customer.prototype.TellAFriend.wsSuccess;
		},
		getSessionId:function(){
			return Customer.prototype.TellAFriend.sessionId;
		},
        getError:function(){
            return Customer.prototype.TellAFriend.wsError;
        }
    },
	
	CreateUserData:{
	
	
	},
	DeleteUserData:{
	
	
	},
	pdateUserData:{
	
	
	}		
});


// ForumAdv *************************************************************************************************

var ForumAdv = function(wsPath, debugMode, postOrGet) {
  this.init(wsPath, debugMode);
}

$.extend(ForumAdv.prototype, {
   
	// Proprietes
	wsUri: "",
	wsName: "",
	wsPath: getPathFromUrl(), 
	wsMethod: "",
	globalSessionId: "",
	globalForumAdvId: "",
	debugMode: true, 
	
	init: function(wsPath, debugMode) {
		 // Constructeur
		 if(wsPath){
			this.setWsPath(wsPath);
		 }else{
			this.wsUri = this.wsPath;
		 }
		 if(debugMode){
			this.debugMode = debugMode;
		 }
	},
	//* Methodes de base ***************************
	
	setWsPath: function(wsPath) {
	 // Definition du chemin des webservices
	 this.wsPath = wsPath;
	 this.wsUri = this.wsPath;
	},	
	setWsName: function(wsName) {
	 // Definition du nom du webservice
	 this.wsName = wsName;
	 this.wsUri = this.wsPath + "/" + this.wsName;
	},		
	setWsMethod: function(wsMethod) {
	 // Definition de la method du webservice
	 this.wsMethod = wsMethod;
	 this.wsUri = this.wsPath + "/" + this.wsName + "/" + this.wsMethod;
	},	
	setGlobalSessionId: function(globalSessionId) {
	 // Definition du resultat retourne par le webservice
	 this.globalSessionId = globalSessionId;
	},
	setGlobalForumAdvId: function(globalForumAdvId) {
	 // Definition du resultat retourne par le webservice
	 this.globalForumAdvId = globalForumAdvId;
	},
	getWsPath: function() {
	 // Recuperation du chemin des webservices
	 return this.wsPath;
	},	
	getWsMethod: function() {
	 // Recuperation de la method du webservice
	 return this.WsMethod;
	},
	getWsUri: function() {
	 // Recuperation de l'uri du webservice
	 return this.wsUri;
	},
	getWsName: function() {
	 // Recuperation du nom du webservice
	 return this.wsName;
	},
	getGlobalSessionId: function() {
	 // Recuperation du nom du webservice
	 return this.globalSessionId;
	},
	getGlobalForumAdvId: function() {
	 // Recuperation du nom du webservice
	 return this.globalForumAdvId;
	},
	isDebugMode: function() {
	 // Est-on en mode debug ?
	 return this.debugMode;
	},
	   
	//* Methodes webservices ************************
	GetForumAdvInfo:{		
		
		// Proprietes
		wsInputData: "",
		wsResult: "",
		wsError: "",
		forumAdvId: "",
		wsSuccess: false,
		
		call:function(sId,forumName,forumId){
			
			//Récupération du sessionId			
			var sessionId = "";
			// Si le session Id est passé en paramètre
			if(sId && sId != null && sId != ""){
				sessionId = sId;
				// Appel ajax
				ForumAdv.prototype.GetForumAdvInfo.callAjax(sessionId,forumName,forumId);
				ForumAdv.prototype.setGlobalSessionId(sessionId);
				return true;
			}else{
				// Si le session Id doit être récupéré par un appel à initSession					
				if(ForumAdv.prototype.globalSessionId == ""){
					Customer.prototype.InitSession.call();
					$(document).ajaxComplete(function(ev, xhr, s) { 
						if(xhr.status == 200 && s.url.indexOf("InitSession")>-1){						
							sessionId = Customer.prototype.InitSession.getSessionId();
						    // Appel ajax
						    ForumAdv.prototype.GetForumAdvInfo.callAjax(sessionId,forumName,forumId);
							ForumAdv.prototype.setGlobalSessionId(sessionId);
						    return true;
						}
					});			
					
				// Si le session Id a été récupéré précédemment et est présent en variable global					
				}else{
					
					sessionId = ForumAdv.prototype.globalSessionId;
					// Appel ajax
					ForumAdv.prototype.GetForumAdvInfo.callAjax(sessionId,forumName,forumId);	
					ForumAdv.prototype.setGlobalSessionId(sessionId);
					return true;
				}
			}
		    
		},
		callAjax:function(sId,forumName,forumId){
			
			// Initialisation de l'appel
			ForumAdv.prototype.GetForumAdvInfo.wsSuccess = false;
			ForumAdv.prototype.setWsName("ForumAdv.asmx");
			ForumAdv.prototype.setWsMethod("GetForumAdvInfo");
			
			//Definition de l'inputData
            var inputData = "<Loreal_Reference_IN_GetForumAdvInfo>";
			inputData += "<SessionID>"+sId+"</SessionID>";
			if(forumId!="") inputData += "<ForumAdvId>"+forumId+"</ForumAdvId>";
			if(forumName!="") inputData += "<ForumAdvName>"+forumName+"</ForumAdvName>";
			inputData += "</Loreal_Reference_IN_GetForumAdvInfo>";
            
			ForumAdv.prototype.GetForumAdvInfo.wsInputData = inputData ;
			
			// Debug
			if(ForumAdv.prototype.isDebugMode){
				console.log("GetForumAdvInfo Appel : "+  ForumAdv.prototype.getWsUri());
			}
			$.ajax({
				url: ForumAdv.prototype.getWsUri(),
				data: "inputData="+ForumAdv.prototype.GetForumAdvInfo.wsInputData,
				type : "POST",
				cache: false,
				error: function (xhr, desc, exceptionobj) {
				  // Debug
				  if(ForumAdv.prototype.isDebugMode){
						console.log("GetForumAdvInfo Error : "+ xhr.responseText);
				  }
				  ForumAdv.prototype.GetForumAdvInfo.wsSuccess = false;
				  
				  //Callback
				  if (typeof(callBackGetForumAdvInfoError) == 'function') callBackGetForumAdvInfoError();
				},
				success: function(content){
				  var forumid = $(content).find("ForumAdvId").text();
				  var errorMessage = $(content).find("Message").text();
				  // Debug
				  if(ForumAdv.prototype.isDebugMode){
						console.log("GetForumAdvInfo forumid : "+  forumid);
				  }
				  ForumAdv.prototype.GetForumAdvInfo.wsError = errorMessage;
				  ForumAdv.prototype.GetForumAdvInfo.wsResult = content;
				  ForumAdv.prototype.GetForumAdvInfo.forumAdvId = forumid;
				  ForumAdv.prototype.GetForumAdvInfo.wsSuccess = true;
				  ForumAdv.prototype.setGlobalForumAdvId(forumid);
				  
				  //Callback
				  if (typeof(callBackGetForumAdvInfo) == 'function') callBackGetForumAdvInfo();
				}
			});		
		},
		
		getXmlResult:function(){
			return ForumAdv.prototype.GetForumAdvInfo.wsResult;
		},
		getXmlResultToString:function(){
			return xmlToString(ForumAdv.prototype.GetForumAdvInfo.wsResult);
		},
		isSuccess: function() {
		    return ForumAdv.prototype.GetForumAdvInfo.wsSuccess;
		},
		getForumAdvId:function(){
			return ForumAdv.prototype.GetForumAdvInfo.forumAdvId;
		},		
        getError:function(){
            return ForumAdv.prototype.GetForumAdvInfo.wsError;
        }
		
	},
	
	SaveForumAdvPostInfo:{		
		
		// Proprietes
		wsInputData: "",
		wsResult: "",
		wsError: "",
		forumAdvId: "",
		forumAdvPostId: "",
		wsSuccess: false,
		
		call:function(sId, forumAdvId, forumAdvPostId, fpParentId, fpSubject, fpText, fpApproved, fpValid, fpPrdCode, fpExtendedProperties){
			
			//Récupération du sessionId			
			var sessionId = "";
			// Si le session Id est passé en paramètre
			if(sId && sId != null && sId != ""){
				sessionId = sId;
				// Appel ajax
				ForumAdv.prototype.SaveForumAdvPostInfo.callAjax(sessionId, forumAdvId, forumAdvPostId, fpParentId, fpSubject, fpText, fpApproved, fpValid, fpPrdCode, fpExtendedProperties);
				ForumAdv.prototype.setGlobalSessionId(sessionId);
				return true;
			}else{
				// Si le session Id doit être récupéré par un appel à initSession					
				if(ForumAdv.prototype.globalSessionId == ""){
					Customer.prototype.InitSession.call();
					$(document).ajaxComplete(function(ev, xhr, s) { 
						if(xhr.status == 200 && s.url.indexOf("InitSession")>-1){						
							sessionId = Customer.prototype.InitSession.getSessionId();
						    // Appel ajax
						    ForumAdv.prototype.SaveForumAdvPostInfo.callAjax(sessionId, forumAdvId, forumAdvPostId, fpParentId, fpSubject, fpText, fpApproved, fpValid, fpPrdCode, fpExtendedProperties);
							ForumAdv.prototype.setGlobalSessionId(sessionId);
						    return true;
						}
					});			
					
				// Si le session Id a été récupéré précédemment et est présent en variable global					
				}else{
					
					sessionId = ForumAdv.prototype.globalSessionId;
					// Appel ajax
					ForumAdv.prototype.SaveForumAdvPostInfo.callAjax(sessionId, forumAdvId, forumAdvPostId, fpParentId, fpSubject, fpText, fpApproved, fpValid, fpPrdCode, fpExtendedProperties);
					ForumAdv.prototype.setGlobalSessionId(sessionId);
					return true;
				}
			}
		    
		},
		
		callAjax:function(sId, forumAdvId, forumAdvPostId, fpParentId, fpSubject, fpText, fpApproved, fpValid, fpPrdCode, fpExtendedProperties){
			
			// Initialisation de l'appel
			ForumAdv.prototype.SaveForumAdvPostInfo.wsSuccess = false;
			ForumAdv.prototype.setWsName("ForumAdv.asmx");
			ForumAdv.prototype.setWsMethod("SaveForumAdvPostInfo");
			
			//Definition de l'inputData
            var inputData = "<Loreal_Reference_IN_SaveForumAdvPostInfo>";
			inputData += "<SessionID>"+sId+"</SessionID>";
			inputData += "<ForumAdvId>"+forumAdvId+"</ForumAdvId>";
			if(forumAdvPostId && forumAdvPostId != "") inputData += "<ForumAdvPostId>"+forumAdvPostId+"</ForumAdvPostId>"; 
			if(fpParentId && fpParentId != "") inputData += "<FpParentId>"+fpParentId+"</FpParentId>"; 
			inputData += "<FpSubject>"+fpSubject+"</FpSubject>";
			inputData += "<FpText>"+fpText+"</FpText>";
			inputData += "<FpApproved>"+fpApproved+"</FpApproved>";
			inputData += "<FpValid>"+fpValid+"</FpValid>";
			if(fpPrdCode && fpPrdCode != "") inputData += "<FpPrdCode>"+fpPrdCode+"</FpPrdCode>";
			inputData += "<FpExtendedProperties>";
			for(var obj in fpExtendedProperties){
				 if (fpExtendedProperties[obj] != '') inputData += "<"+obj+">"+fpExtendedProperties[obj]+"</"+obj+">";
			}
			inputData += "</FpExtendedProperties>";
			inputData += "</Loreal_Reference_IN_SaveForumAdvPostInfo>";
            
			ForumAdv.prototype.SaveForumAdvPostInfo.wsInputData = inputData ;
			
			// Debug
			if(ForumAdv.prototype.isDebugMode){
				console.log("SaveForumAdvPostInfo Appel : "+  ForumAdv.prototype.getWsUri());
			}
			$.ajax({
				url: ForumAdv.prototype.getWsUri(),
				data: "inputData="+ForumAdv.prototype.SaveForumAdvPostInfo.wsInputData,
				type : "POST",
				cache: false,
				error: function (xhr, desc, exceptionobj) {
				  // Debug
				  if(ForumAdv.prototype.isDebugMode){
						console.log("SaveForumAdvPostInfo Error : "+ xhr.responseText);
				  }
				  ForumAdv.prototype.SaveForumAdvPostInfo.wsSuccess = false;
				  
				  //Callback
				  if (typeof(callBackSaveForumAdvPostInfoError) == 'function') callBackSaveForumAdvPostInfoError();
				  
				},
				success: function(content){
				  var forumId = $(content).find("ForumAdvId").text();
				  var postId = $(content).find("ForumAdvPostId").text();
				  var errorMessage = $(content).find("Message").text();
				  // Debug
				  if(ForumAdv.prototype.isDebugMode){
						console.log("SaveForumAdvPostInfo forumId : "+  forumId);
						console.log("SaveForumAdvPostInfo postId : "+  postId);
				  }
				  ForumAdv.prototype.SaveForumAdvPostInfo.wsError = errorMessage;
				  ForumAdv.prototype.SaveForumAdvPostInfo.wsResult = content;
				  ForumAdv.prototype.GetForumAdvInfo.forumAdvId = forumId;
				  ForumAdv.prototype.GetForumAdvInfo.forumAdvPostId = postId;
				  ForumAdv.prototype.SaveForumAdvPostInfo.wsSuccess = true;
				  ForumAdv.prototype.setGlobalForumAdvId(forumId);
				  
				  //Callback
				  if (typeof(callBackSaveForumAdvPostInfo) == 'function') callBackSaveForumAdvPostInfo();
				}
			});		
		},
		getXmlResult:function(){
			return ForumAdv.prototype.SaveForumAdvPostInfo.wsResult;
		},
		getXmlResultToString:function(){
			return xmlToString(ForumAdv.prototype.SaveForumAdvPostInfo.wsResult);
		},
		isSuccess: function() {
		    return ForumAdv.prototype.SaveForumAdvPostInfo.wsSuccess;
		},
		getForumAdvId:function(){
			return ForumAdv.prototype.SaveForumAdvPostInfo.forumAdvId;
		},
		getForumAdvPostId:function(){
			return ForumAdv.prototype.SaveForumAdvPostInfo.forumAdvPostId;
		},		
        getError:function(){
            return ForumAdv.prototype.SaveForumAdvPostInfo.wsError;
        }
		
	},
	
	// cette methode ne semble pas être valide
	DeleteForumAdvInfo:{		
		
		// Proprietes
		wsInputData: "",
		wsResult: "",
		wsError: "",
		forumAdvId: "",
		forumAdvPostId: "",
		wsSuccess: false,
		
		call:function(sId, forumAdvId, forumAdvPostId){
			
			//Récupération du sessionId			
			var sessionId = "";
			// Si le session Id est passé en paramètre
			if(sId && sId != null && sId != ""){
				sessionId = sId;
				// Appel ajax
				ForumAdv.prototype.DeleteForumAdvInfo.callAjax(sessionId, forumAdvId, forumAdvPostId);
				ForumAdv.prototype.setGlobalSessionId(sessionId);
				return true;
			}else{
				// Si le session Id doit être récupéré par un appel à initSession					
				if(ForumAdv.prototype.globalSessionId == ""){
					Customer.prototype.InitSession.call();
					$(document).ajaxComplete(function(ev, xhr, s) { 
						if(xhr.status == 200 && s.url.indexOf("InitSession")>-1){						
							sessionId = Customer.prototype.InitSession.getSessionId();
						    // Appel ajax
						    ForumAdv.prototype.DeleteForumAdvInfo.callAjax(sessionId, forumAdvId, forumAdvPostId);
							ForumAdv.prototype.setGlobalSessionId(sessionId);
						    return true;
						}
					});			
					
				// Si le session Id a été récupéré précédemment et est présent en variable global					
				}else{
					
					sessionId = ForumAdv.prototype.globalSessionId;
					// Appel ajax
					ForumAdv.prototype.DeleteForumAdvInfo.callAjax(sessionId, forumAdvId, forumAdvPostId);	
					ForumAdv.prototype.setGlobalSessionId(sessionId);
					return true;
				}
			}
		    
		},
		
		callAjax:function(sId, forumAdvId, forumAdvPostId){
			
			// Initialisation de l'appel
			ForumAdv.prototype.DeleteForumAdvInfo.wsSuccess = false;
			ForumAdv.prototype.setWsName("ForumAdv.asmx");
			ForumAdv.prototype.setWsMethod("DeleteForumAdvInfo");
			
			//Definition de l'inputData
            var inputData = "<Loreal_Reference_IN_DeleteForumAdvPostInfo>";
			inputData += "<SessionID>"+sId+"</SessionID>";
			inputData += "<ForumAdvId>"+forumAdvId+"</ForumAdvId>";
			inputData += "<ForumAdvPostId>"+forumAdvPostId+"</ForumAdvPostId>";
			inputData += "</Loreal_Reference_IN_DeleteForumAdvPostInfo>";
            
			ForumAdv.prototype.DeleteForumAdvInfo.wsInputData = inputData ;
			
			// Debug
			if(ForumAdv.prototype.isDebugMode){
				console.log("Appel : "+  ForumAdv.prototype.getWsUri());
			}
			$.ajax({
				url: ForumAdv.prototype.getWsUri(),
				cache: false,
				error: function (xhr, desc, exceptionobj) {
				  // Debug
				  if(ForumAdv.prototype.isDebugMode){
						console.log("Error : "+ xhr.responseText);
				  }
				  ForumAdv.prototype.DeleteForumAdvInfo.wsSuccess = false;
				  //Callback
				  if (typeof(callBackDeleteForumAdvInfoError) == 'function') callBackDeleteForumAdvInfoError();
				  
				},
				success: function(content){
				  var forumId = $(content).find("ForumAdvId").text();
				  var postId = $(content).find("ForumAdvPostId").text();
				  var errorMessage = $(content).find("Message").text();
				  // Debug
				  if(ForumAdv.prototype.isDebugMode){
						console.log("forumId : "+  forumId);
						console.log("postId : "+  postId);
				  }
				  ForumAdv.prototype.SaveForumAdvPostInfo.wsError = errorMessage;
				  ForumAdv.prototype.SaveForumAdvPostInfo.wsResult = content;
				  ForumAdv.prototype.GetForumAdvInfo.forumAdvId = forumId;
				  ForumAdv.prototype.GetForumAdvInfo.forumAdvPostId = postId;
				  ForumAdv.prototype.SaveForumAdvPostInfo.wsSuccess = true;
				  ForumAdv.prototype.setGlobalForumAdvId(forumId);
				  
				  //Callback
				  if (typeof(callBackDeleteForumAdvInfo) == 'function') callBackDeleteForumAdvInfo();
				}
			});		
		},
		getXmlResult:function(){
			return ForumAdv.prototype.DeleteForumAdvInfo.wsResult;
		},
		getXmlResultToString:function(){
			return xmlToString(ForumAdv.prototype.DeleteForumAdvInfo.wsResult);
		},
		isSuccess: function() {
		    return ForumAdv.prototype.DeleteForumAdvInfo.wsSuccess;
		},
		getForumAdvId:function(){
			return ForumAdv.prototype.DeleteForumAdvInfo.forumAdvId;
		},
		getForumAdvPostId:function(){
			return ForumAdv.prototype.SaveForumAdvPostInfo.forumAdvPostId;
		},
        getError:function(){
            return ForumAdv.prototype.DeleteForumAdvInfo.wsError;
        }
		
	}
	
});


function getPathFromUrl(){
	var url = document.location.href;
	var pos = 0;
	// integration : on se base sur le aspnet
	if(url.indexOf("/aspnet/")>-1){
		pos = url.indexOf("/aspnet/")+7;
		url = url.substring(0, pos) + "/ws";
		return url;
	// integration : on se base sur le .validation.
	}else if(url.indexOf(".validation.")>-1){
		pos = url.indexOf("/", url.indexOf(".validation."));
		url = url.substring(0, pos) + "/ws";
		return url;
	// integration : on se base sur le .validation.
	}else{
		if(url.indexOf("http://") > -1){
			url = url.substring(url.indexOf("http://") + 7);
		}
		pos = url.indexOf("/");
		url = "http://" + url.substring(0, pos) + "/ws";
		return url;
	}
}

function xmlToString(xmlObject){
   return (xmlObject.xml ? xmlObject.xml : (new XMLSerializer()).serializeToString(xmlObject));
}