<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
//deploy
var livechatzone_host = "https://support.livechat.contact";
var lcz_site_key = 'prxio';
var livechatzone_refreshinterval = 10000; //#customerchatrefreshinterval
var loadmessages_in_progress = false;
var loadmsgInterval = false;
var currentLocation = window.location.href;
var hideIfNoOpperator = false;

var lcz_open_after = 0;


var use_ai = true;

// ?lcvis=reset&amp;openchat=1
if (typeof test_operator === 'undefined') {
	var test_operator = false;
} else {
	if (test_operator &gt; 0) {
		//alert("Forcing test operator: ID"+test_operator);
	}
}
function generateID(length = 8, charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") {
	return new Array(length)
		.fill(null)
		.map(() =&gt; charset.charAt(Math.floor(Math.random() * charset.length)))
		.join('');
}
//

var lcz_vis_key = localStorage.getItem("livechatzone_visitor");

if (!lcz_vis_key || lcz_vis_key == 'undefined' || lcz_vis_key == null || lcz_vis_key == 'null') {
	localStorage.setItem("livechatzone_visitor", null);
	var visitorid = (new Date()).getMilliseconds() + Math.floor(Math.random() * 1000) + generateID(128);
	localStorage.setItem("livechatzone_visitor", visitorid);
	lcz_vis_key = localStorage.getItem("livechatzone_visitor");
	//alert("aaa"+lcz_vis_key);
} else {
	//found customer id
}

//alert("found customer vis:"+lcz_vis_key);


if (typeof lcz_vis_key_forced !== 'undefined') {

	if (lcz_vis_key_forced == 'reset') {

		var visitorid = (new Date()).getMilliseconds() + Math.floor(Math.random() * 1000) + generateID(128);;
		localStorage.setItem("livechatzone_visitor", visitorid);
		var lcz_vis_key = localStorage.getItem("livechatzone_visitor");
		alert('Chat session reset, new key: ' + lcz_vis_key);

	} else {

		var lcz_vis_key = lcz_vis_key_forced;
		localStorage.setItem("livechatzone_visitor", lcz_vis_key_forced);
		var lcz_vis_key = localStorage.getItem("livechatzone_visitor");
		alert('Opening chat session ' + lcz_vis_key);
	}
}




//runs from remote






//lcz_vis_key
jQuery(function () {

	//todo check why on test page this info is not complete, vis key not existing
	if (lcz_site_key &amp;&amp; lcz_site_key != 'undefined' &amp;&amp; lcz_vis_key &amp;&amp; lcz_vis_key != 'undefined') {

		//var site_key = lcz_site_key;


		jQuery("#livechatzone_wrapper").show();
		jQuery("#livechatzone_exit").hide();

		var livechatzone_status = 'closed';

		function livechatzone_close() {
			jQuery("#livechatzone_wrapper").delay(300).css({ left: '20', top: (jQuery(window).height() - 40) });
			jQuery("#livechatzone_wrapper").show(); //mxl-ai1 added because i think wrapper should be sure its open at this point
			jQuery("#livechatzone_button_closed").show();
			jQuery("#livechatzone_button_opened").hide();
			jQuery("#livechatzone_exit").hide();

			livechatzone_status = 'closed';
		}

		function livechatzone_closemobile() {
			jQuery("#livechatzone_wrapper").delay(300).css({ left: '20', top: (jQuery(window).height() - 40) });
			jQuery("#livechatzone_wrapper").show(); //mxl-ai1 added because i think wrapper should be sure its open at this point
			jQuery("#livechatzone_button_closed").show();
			jQuery("#livechatzone_button_opened").hide();
			jQuery("#livechatzone_exit").hide();

			livechatzone_status = 'closed';
		}

		function livechatzone_open() {
			jQuery("#livechatzone_wrapper").delay(300).css({ left: '10', top: (jQuery(window).height() - 500) });
			jQuery("#livechatzone_wrapper").show(); //mxl-ai1 added because i think wrapper should be sure its open at this point
			jQuery("#livechatzone_button_closed").hide();
			jQuery("#livechatzone_button_opened").show();
			jQuery("#livechatzone_exit").show();

			livechatzone_status = 'opened';
		}

		function livechatzone_openmobile() {
			jQuery("#livechatzone_wrapper").delay(300).css({ left: '10', top: '0' });
			jQuery("#livechatzone_wrapper").show(); //mxl-ai1 added because i think wrapper should be sure its open at this point
			jQuery("#livechatzone_button_closed").hide();
			jQuery("#livechatzone_button_opened").show();
			jQuery("#livechatzone_exit").show();

			livechatzone_status = 'opened';
		}

		function livechatzone_init() {
			jQuery("#livechatzone_wrapper").delay(10).css({ left: '0', top: (jQuery(window).height() - 40) });
			jQuery("#livechatzone_wrapper").show(); //mxl-ai1 added because i think wrapper should be sure its open at this point
			jQuery("#livechatzone_button_closed").show();
			jQuery("#livechatzone_button_opened").hide();
			livechatzone_status = 'closed';
		}
		function livechatzone_initmobile() {
			jQuery("#livechatzone_wrapper").delay(10).css({ left: '20', top: (jQuery(window).height() - 40) });
			jQuery("#livechatzone_wrapper").show(); //mxl-ai1 added because i think wrapper should be sure its open at this point
			jQuery("#livechatzone_button_closed").show();
			jQuery("#livechatzone_button_opened").hide();
			livechatzone_status = 'closed';
		}

		function livechatzone_detectmobile() {
			if (jQuery(window).width() &gt; 640) {
				return false;
			} else {
				return true;
			}
		}

		if (livechatzone_detectmobile()) {
			livechatzone_initmobile();
		} else {
			livechatzone_init();
		}


		//---
		/*
			var livechatzone_winurl = livechatzone_host+"/chat.php?site_key="+lcz_site_key+"&amp;t="+jQuery.now();
			
				jQuery.ajax({
					context: this,
					dataType : "html",
					url : livechatzone_winurl,
					success : function(results) {
						jQuery("#livechat_window").html(results);
					}
				});
		*/
		//------------------

		jQuery(window).on("resize", function () {

			if (livechatzone_detectmobile()) {
				if (livechatzone_status == 'opened') {
					livechatzone_openmobile();
				} else {
					livechatzone_closemobile();
				}
			} else {
				if (livechatzone_status == 'opened') {
					livechatzone_open();
				} else {
					livechatzone_close();
				}
			}

			// Invoke the resize event immediately
		}).resize();



		jQuery("#livechatzone_button_opened").click(function () {
			if (livechatzone_detectmobile()) {
				livechatzone_closemobile();
			} else {
				livechatzone_close();
			}
		});
		jQuery("#livechatzone_button_closed").click(function () {
			if (livechatzone_detectmobile()) {
				livechatzone_openmobile();
			} else {
				livechatzone_open();
			}
		});


		/*
		//moved in submenu
		jQuery("#livechatzone_button_endchat").click(function(){
			
			var exit = confirm("Are you sure you want to end the session?");
			

	
			if(exit==true){

				
				jQuery.post(livechatzone_host+"/inc/remotepayload/ajax.endchat.php?t="+jQuery.now(), {site_key: lcz_site_key, vis_key: lcz_vis_key}, function(result){
					if(result){ 
						alert(result); 
					}else{
						
						//resets the chat id
						localStorage.removeItem("livechatzone_visitor");
				
						if (livechatzone_detectmobile()) {
							livechatzone_closemobile();
						}else{
							livechatzone_close();
						}
						
						window.location = window.location; //'?site_key='+lcz_site_key+'&amp;vis_key='+lcz_vis_key+'&amp;logout=true';
						//location.reload();
					}
					jQuery("span").html(result);
				});
			
			}
		
		});		

		*/


		// -------------------------- 

		function customer_message_html(msg){ 
			if (msg.viewed == 1) {
				var isread = "&lt;span class='isread_cust'&gt;â€¢&lt;/span&gt;";
			} else {
				var isread = "&lt;span class='noread_cust'&gt;â€¢&lt;/span&gt;";
			}   
			var date = new Date(msg.t * 1000);
			var formattedDate = date.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' });

			if(!msg.name){
				msg.name = "You";
			}
			html ="&lt;div class='livechatzone_msgln livechatzone_msg_owner_customer'&gt;" +
			"&lt;div class='livechatzone_msgln_timestamp_cust'&gt;"+formattedDate+"&lt;/div&gt;" +
			"&lt;div class='livechatzone_msg_you_label'&gt;"+msg.name+"&lt;/div&gt;" +msg.msg+" "+isread+" &lt;br&gt;&lt;/div&gt;";
		
			return html;
		}

		function operator_message_html(msg){
			if (msg.viewed == 1) {
				var isread = "&lt;span class='isread_cust'&gt;â€¢&lt;/span&gt;";
			} else {
				var isread = "&lt;span class='noread_cust'&gt;â€¢&lt;/span&gt;";
			}   
			var date = new Date(msg.t * 1000);
			var formattedDate = date.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' });

			if(!msg.name){
				msg.name = "";
			}
			html ="&lt;div class='livechatzone_msgln livechatzone_msg_owner_operator'&gt; "+
			"&lt;div class='livechatzone_agentimg_userchat'&gt;&lt;/div&gt;" +
			"&lt;div class='livechatzone_msgbg_op'&gt;" +
			"&lt;div class='livechatzone_msgln_timestamp_op'&gt;"+formattedDate+"&lt;/div&gt;"+
			"&lt;div class='livechatzone_msgln_opname'&gt;"+msg.name+"&lt;/div&gt;"+msg.msg+ " "+isread+" "+
			"&lt;br&gt;&lt;/div&gt;&lt;/div&gt;";
		
			return html;
		}

		function system_message_html(msg){
			html = "&lt;div class='livechatzone_msgln livechatzone_msg_owner_system'&gt;"+msg.msg+"&lt;br&gt;&lt;/div&gt;";
			return html;
		}

		//Load the file containing the chat log
		var last_msg_id = 0; //stores highest msg id so it knows what messages to show from the loaded ones
		function loadMessages() {
			//alert( lcz_vis_key);
			//var oldscrollHeight = jQuery("#chatbox").attr("scrollHeight") - 20; //Scroll height before the request
			if(!loadmessages_in_progress){
				loadmessages_in_progress = true;
				jQuery.ajax({
					url: livechatzone_host + "/inc/remotepayload/ajax.loadmessages-ai1.php?t=" + jQuery.now(),
					type: 'GET',
					data: { site_key: lcz_site_key, vis_key: lcz_vis_key, customerview: true, ai_mode: use_ai },
					contentType: 'application/json; charset=utf-8',
					cache: false,
					success: function (ret) {
						
						loadmessages_in_progress = false;

						if(ret.messages){
							for (const msg of ret.messages) {
								//alert(msg.id+" &gt; "+last_msg_id+" = "+msg.msg);
								if(msg.id &gt; last_msg_id){
									if(msg.owner == 'customer'){
										jQuery("#livechatzone_chatbox").append(customer_message_html(msg));
									}else if(msg.owner == 'operator'){
										jQuery("#livechatzone_chatbox").append(operator_message_html(msg));
									}else{
										jQuery("#livechatzone_chatbox").append(system_message_html(msg));
									}
									last_msg_id = msg.id;

									//Auto-scroll			
									var newscrollHeight = jQuery("#livechatzone_chatbox").prop('scrollHeight'); // jQuery("#chatbox").attr("scrollHeight") + 20; //Scroll height after the request
									//if(newscrollHeight &gt; oldscrollHeight){
									jQuery("#livechatzone_chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
									//}	

								}
								if(msg.id == last_msg_id){
									if(msg.oid==0){ //ai operator
										
										if(msg.owner == 'customer'){
											jQuery(".lcz_title").html("AI Assistant&lt;br&gt;"+"Answering....");

											jQuery("#livechatzone_usermsg").prop("disabled", true);
											jQuery("#livechatzone_usermsg").prop("placeholder", "AI is writing...");
											jQuery("#livechatzone_submitmsg").css("visibility", "hidden");

											var currentTime = new Date().getTime();
											var messageTime = new Date(msg.t * 1000).getTime(); // Convert unix timestamp to milliseconds
											var timeDifference = currentTime - messageTime;
											var twoMinutes = 2 * 60 * 1000; // 2 minutes in milliseconds

											if (timeDifference &gt; twoMinutes) {
												var sendmsg = "There was an issue processing your last response, please rephrase it.";
												var owner = "system";
												jQuery.post(livechatzone_host + "/inc/remotepayload/ajax.savemsg_custom.php?t=" + jQuery.now(), { site_key: lcz_site_key, vis_key: lcz_vis_key, ai_mode: use_ai, msg: sendmsg, owner: owner, no_duplicates: true }, function (result) {
													if (result) {
														alert(result);
													}
												});
											}
										}else{
											
											//update ai name
											jQuery(".lcz_title").html("AI Assistant&lt;br&gt;"+msg.name);

											jQuery("#livechatzone_usermsg").prop("disabled", false);
											jQuery("#livechatzone_usermsg").prop("placeholder", "Enter your message");
											jQuery("#livechatzone_submitmsg").css("visibility", "visible");
										}
									}else{
										//update operator name
										if(msg.owner == 'operator'){
											jQuery(".lcz_title").html("Livechat operator (human)&lt;br&gt;"+ret.current_operator_name);
										}
									}
								}
							}
						}
						//alert(collect_messages);
						

						//jQuery("#livechatzone_chatbox").html(html); //Insert chat log into the #chatbox div	
						////alert(html);
						
						//Auto-scroll			
						//var newscrollHeight = jQuery("#livechatzone_chatbox").prop('scrollHeight'); // jQuery("#chatbox").attr("scrollHeight") + 20; //Scroll height after the request
						////if(newscrollHeight &gt; oldscrollHeight){
						//jQuery("#livechatzone_chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
						////}	

						jQuery("#livechatzone_chatbox_send_ongoing").remove();


						if(ret.status != 'closed_by_customer'){
							jQuery('#livechatzone_button_endchat').show();
							jQuery('#livechatzone_status_endchat').html('');
						}else{
							jQuery('#livechatzone_button_endchat').hide();
							//jQuery('#livechatzone_status_endchat').html(' Type a message to resume it.');
							jQuery('#livechatzone_output').append('&lt;div style=\"background-color:#ccc;\"  class=\"livechatzone_msgln xxinchat-error\"&gt; This chat session has ended. &lt;/div&gt;');
							setTimeout(function(){ jQuery('.xxinchat-error').remove() }, 7000);
						}
					},
				});
			}else{
				console.log('loadmessages is still in progress');
			}
		}


		function loadMessagesDownload() {

			window.location = livechatzone_host + "/inc/remotepayload/ajax.downloadmessages.php?site_key=" + lcz_site_key + "&amp;vis_key=" + lcz_vis_key + "&amp;customerview=true&amp;t=" + jQuery.now();

			/*
			//alert( lcz_vis_key);
			//var oldscrollHeight = jQuery("#chatbox").attr("scrollHeight") - 20; //Scroll height before the request
			jQuery.ajax({
				url: livechatzone_host+"/inc/remotepayload/ajax.downloadmessages.php?t="+jQuery.now(),
				type: 'GET',
				data: { site_key: lcz_site_key, vis_key: lcz_vis_key, customerview: true} ,
				contentType: 'application/json; charset=utf-8',
				cache: false,
				success: function(html){		
					jQuery("#livechatzone_chatbox").html(html); //Insert chat log into the #chatbox div	
					//alert(html);
					//Auto-scroll			
					var newscrollHeight = jQuery("#livechatzone_chatbox").prop('scrollHeight'); // jQuery("#chatbox").attr("scrollHeight") + 20; //Scroll height after the request
					//if(newscrollHeight &gt; oldscrollHeight){
						jQuery("#livechatzone_chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
					//}	

					jQuery("#livechatzone_chatbox_send_ongoing").remove();
				},
			});
			
			*/
		}



		//	var loadmsgInterval ;

		var livechatzone_initload_success = false; //updated in livechatzone_initload and checked periodically after sendrequest to know if init finished.

		function livechatzone_initload() {

			//RUN ALL
			//this may be called again if anything chaned, to go to the right action code (chat phase)

			//	?blablablacallback=? forces use of jsonp that is cross site and works if a func with same name is present to run the result on callback.

			jQuery.getJSON(livechatzone_host + "/inc/remotepayload/ajax.chatstart-ai1.php?t=" + jQuery.now(), { site_key: lcz_site_key, vis_key: lcz_vis_key, current_url: currentLocation, test_op: test_operator, ai_mode: use_ai }, function (data) {

				if (lcz_site_key &amp;&amp; lcz_site_key != 'undefined' &amp;&amp; lcz_vis_key &amp;&amp; lcz_vis_key != 'undefined') {

					//This part runs only once when everything starts, gets a code from ajax, then does accordingly.

					//alert("xxx"+data['code']);
					if (data['code'] == '111') {
						//start chat
						jQuery("#livechatzone_wrapper").show(); //mxl-ai1 added because i think wrapper should be sure its open at this point
						jQuery("#livechatzone_requestinfo").hide();
						jQuery("#livechatzone_startchat").show();

						if (data['opname']) {
							var opname = data['opname'];
						} else {
							var opname = "  ";
						}

						jQuery("#livechatzone_button_opened").html('&lt;div class="livechatzone_agentimg"&gt;&lt;/div&gt;&lt;div class="lcz_title"&gt;&lt;b&gt;' + opname + '&lt;/b&gt;&lt;br&gt;Sales Consultant&lt;/div&gt; &lt;div class="livechatzone_button_leaf"&gt;&lt;/div&gt;');
						jQuery("#livechatzone_startchat").load(livechatzone_host + "/inc/remotepayload/html.startchat-ai1.php?t=" + jQuery.now(), { site_key: lcz_site_key, vis_key: lcz_vis_key }, function (response, status, xhr) {

							if (status == 'success') {

								loadMessages();

								if (livechat_debug) {
									alert("livechat debug mode enabled, chat will not update");
								} else {
									if (window.loadmsgInterval) {
										clearInterval(window.loadmsgInterval);
									}
									window.loadmsgInterval = setInterval(loadMessages, livechatzone_refreshinterval);
									//alert("azassdhasa:"+window.loadmsgInterval);
								}

								livechatzone_initload_success = true;

								//----todo ---

								jQuery("#livechatzone_emoji-picker").load(livechatzone_host + "/inc/remotepayload/html.emojipicker.php?t=" + jQuery.now(), { site_key: lcz_site_key, vis_key: lcz_vis_key }, function (response, status, xhr) {
									if (status == 'success') {
										//alert('emojis loaded');
									}

									if (status == 'error') {
										alert("Error #2916: Emojis " + response);
									}
								});



								//-------------------

							}

							if (status == 'error') {
								alert("Error #728: StartChat " + response);
							}
						});

					} else if (data['code'] == '204') {
						//request info
						jQuery("#livechatzone_requestinfo").show();
						jQuery("#livechatzone_startchat").hide();
						//jQuery("#livechatzone_button_opened").html('&lt;div class="lcz_title"&gt;&amp;nbsp;&lt;/div&gt; &lt;div class="livechatzone_button_leaf"&gt;&lt;/div&gt;');
						jQuery("#livechatzone_button_opened").html('&lt;div class="livechatzone_agentimg"&gt;&lt;/div&gt;&lt;div class="lcz_title"&gt;&lt;b&gt;Please enter your message&lt;/b&gt;&lt;br&gt;Agents are online!&lt;/div&gt; &lt;div class="livechatzone_button_leaf"&gt;&lt;/div&gt;');
						jQuery("#livechatzone_requestinfo").load(livechatzone_host + "/inc/remotepayload/html.requestinfo.php?t=" + jQuery.now(), { site_key: lcz_site_key, vis_key: lcz_vis_key, op_name: data['op_name'], ai_mode: use_ai }, function (response, status, xhr) {
							if (window.loadmsgInterval) {
								clearInterval(window.loadmsgInterval);
							}

							jQuery("#livechatzone_wrapper")[0].offsetHeight; // Trigger a reflow


						});
						//alert(data['msg']);

					} else if (data['code'] == '704') {

						//AI MODE request info same as code 204
						//request info
						jQuery("#livechatzone_requestinfo").show();
						jQuery("#livechatzone_startchat").hide();
						//jQuery("#livechatzone_button_opened").html('&lt;div class="lcz_title"&gt;&amp;nbsp;&lt;/div&gt; &lt;div class="livechatzone_button_leaf"&gt;&lt;/div&gt;');
						jQuery("#livechatzone_button_opened").html('&lt;div class="livechatzone_agentimg"&gt;&lt;/div&gt;&lt;div class="lcz_title"&gt;&lt;b&gt;Please enter your message&lt;/b&gt;&lt;br&gt;&lt;!-- Agents are not online --&gt;&lt;/div&gt; &lt;div class="livechatzone_button_leaf"&gt;&lt;/div&gt;');
						jQuery("#livechatzone_requestinfo").load(livechatzone_host + "/inc/remotepayload/html.requestinfo.php?t=" + jQuery.now(), { site_key: lcz_site_key, vis_key: lcz_vis_key, op_name: data['op_name'], ai_mode: use_ai }, function (response, status, xhr) {
							if (window.loadmsgInterval) {
								clearInterval(window.loadmsgInterval);
							}

							jQuery("#livechatzone_wrapper")[0].offsetHeight; // Trigger a reflow

						});
						//alert(data['msg']);


					} else if (data['code'] == '777' || data['code'] == '510') {

						//AI MODE start chat same as code 111
						//start chat
						jQuery("#livechatzone_wrapper").show(); //mxl-ai1 added because i think wrapper should be sure its open at this point
						jQuery("#livechatzone_requestinfo").hide();
						jQuery("#livechatzone_startchat").show();


						var opname = "AI Assistant";


						jQuery("#livechatzone_button_opened").html('&lt;div class="livechatzone_agentimg"&gt;&lt;/div&gt;&lt;div class="lcz_title"&gt;&lt;b&gt;' + opname + '&lt;/b&gt;&lt;br&gt;Sales Consultant&lt;/div&gt; &lt;div class="livechatzone_button_leaf"&gt;&lt;/div&gt;');
						jQuery("#livechatzone_startchat").load(livechatzone_host + "/inc/remotepayload/html.startchat-ai1.php?t=" + jQuery.now(), { site_key: lcz_site_key, vis_key: lcz_vis_key, ai_mode: use_ai }, function (response, status, xhr) {

							if (status == 'success') {

								loadMessages();

								if (livechat_debug) {
									alert("livechat debug mode enabled, chat will not update");
								} else {
									if (window.loadmsgInterval) {
										clearInterval(window.loadmsgInterval);
									}
									window.loadmsgInterval = setInterval(loadMessages, livechatzone_refreshinterval);
									//alert("azassdhasa:"+window.loadmsgInterval);
								}

								livechatzone_initload_success = true;

								//----todo ---

								jQuery("#livechatzone_emoji-picker").load(livechatzone_host + "/inc/remotepayload/html.emojipicker.php?t=" + jQuery.now(), { site_key: lcz_site_key, vis_key: lcz_vis_key }, function (response, status, xhr) {
									if (status == 'success') {
										//alert('emojis loaded');
									}

									if (status == 'error') {
										alert("Error #2916: Emojis " + response);
									}
								});



								//-------------------

							}

							if (status == 'error') {
								alert("Error #728: StartChat " + response);
							}
						});


					} else if (data['code'] == '0000') {
						alert("Error #0000: " + data['msg']);
					} else {
						
						alert("unknown response code: "+data['code']+" "+data['msg']);
						//jQuery("#livechatzone_startchat").hide();
						//jQuery("#livechatzone_requestinfo").show();
						//jQuery("#livechatzone_requestinfo").html(" [" + data['code'] + "] " + data['msg']);
						
					}

					/*
					jQuery.each(data, function(index, element) {
						jQuery('body').append(jQuery('&lt;div&gt;', {
							text: element.name
						}));
					});
					*/

				} else {
					alert("Error #099 missing keys");
				}

			})

				.fail(function (jqXHR, textStatus, errorThrown) {

					//alert('ERROR #718 ChatStart request failed! status: ' + textStatus + " err:" + errorThrown); 

					//pass error via url, for a weird reason this loads even if no err.
					var url = window.location.href;
					if (window.location.search.indexOf('lvcerr=') == -1) { //only if not exist yet
						if (url.indexOf('?') &gt; -1) {
							url += '&amp;lvcerr=718'
						} else {
							url += '?lvcerr=718'
						}

					}
					if (window.location.search.indexOf('openchat=') == -1) { //only if not exist yet
						if (url.indexOf('?') &gt; -1) {
							url += '&amp;openchat=2'
						} else {
							url += '?openchat=2'
						}

					}
					window.location.href = url;


				})
				.done(function (data) {
					//this keeps running till done 
				})
			//.success(function() { 
			//	alert('deprecated');		
			//})
			//.error(function(data) { alert("error"+data); })
			//.complete(function() { alert("complete"); })

		} //livechatzone_initload() loads a code via ajax and goes to the corresponding initial load action


		function livechatzone_sendReqdata() {
			var form = jQuery('#livechatzone_reqdataform');
			var data = jQuery(form).serialize(); //new FormData( jQuery(form)[ 0 ] );

			jQuery.post(livechatzone_host + "/inc/remotepayload/ajax.requestinfo.php?t=" + jQuery.now(), { formdata: data, site_key: lcz_site_key, vis_key: lcz_vis_key, test_op: test_operator, ai_mode: use_ai }, function (result) {
				if (result == 'SUCCESS') {


					livechatzone_initload();


					//alert("Status: "+status);


					/**/
					//livechatzone_initload_success
					//@@TODO: MUST: this should first check if livechatzone_initloaded() finished loadin without error, or called at the end of that func.
					//@@TODO: The above function for some weird reason runs loadMessages but does not put data in the #livechatzone_chatbox div. It does run ok if page refreshes , so below is a temporary super-ugly fix, to refresh page once user enters data and starts chat

					var url = window.location.href;
					if (window.location.search.indexOf('openchat=') == -1) { //only if not exist yet
						if (url.indexOf('?') &gt; -1) {
							url += '&amp;openchat=1'
						} else {
							url += '?openchat=1'
						}

					}
					window.location.href = url;

					//end ugly fix ----------------


				} else {
					alert(result);
				}

				jQuery("#livechatzone_wrapper")[0].offsetHeight; // Trigger a reflow

				//jQuery("span").html(result);			
			});

			return false;
		}


		jQuery(document).on("click", "#livechatzone_enter", function () {
			livechatzone_sendReqdata();
		});


		//If user submits the form
		jQuery(document).on("click", "#livechatzone_submitmsg", function () {

			var clientmsg = jQuery("#livechatzone_usermsg").val();
			//alert('s msg'+clientmsg);

			//jQuery('&lt;div id="livechatzone_chatbox_send_ongoing"&gt;Sending message...&lt;/div&gt;').insertAfter(jQuery('[class^="livechatzone_msgln"]').last());
			//jQuery('&lt;div id="livechatzone_chatbox_send_ongoing"&gt;Sending message...&lt;/div&gt;').insertAfter(jQuery('[id^="afterchatlines"]').last());
			
			jQuery("#afterchatlines").html('&lt;div id="livechatzone_chatbox_send_ongoing"&gt;Sending message...&lt;/div&gt;');
			//jQuery('#afterchatlines').html('Sending message...');


			jQuery.post(livechatzone_host + "/inc/remotepayload/ajax.savemsg.php?t=" + jQuery.now(), { msg: clientmsg, site_key: lcz_site_key, vis_key: lcz_vis_key, ai_mode: use_ai }, function (result) {
				if (result) { alert(result); }
				//jQuery("span").html(result);

			});
			jQuery("#livechatzone_usermsg").val("");
			return false;
		});




		jQuery(document).on("click", "#livechatzone_exit", function () {
			//var exit = confirm("Are you sure you want to end the session?");
			//if(exit==true){
			//window.location = '?site_key='+lcz_site_key+'&amp;vis_key='+lcz_vis_key+'&amp;logout=true&amp;t="+jQuery.now();
			//jQuery.post(livechatzone_host+"/inc/remotepayload/ajax.endchat.php?t="+jQuery.now(), {site_key: lcz_site_key, vis_key: lcz_vis_key}, function(result){
			//if(result){ 
			//	alert(result); 
			//}else{

			if (livechatzone_detectmobile()) {
				livechatzone_closemobile();
			} else {
				livechatzone_close();
			}

			//}
			//jQuery("span").html(result);
			//});

			//}		
		});

		
		jQuery(document).on("click", "#livechatzone_button_talktohuman", function (e) {
			var msg = "[human_operator_requested]";
			var owner = "operator";
			jQuery.post(livechatzone_host + "/inc/remotepayload/ajax.savemsg_custom.php?t=" + jQuery.now(), { site_key: lcz_site_key, vis_key: lcz_vis_key, ai_mode: use_ai, msg: msg, owner: owner }, function (result) {
				if (result) {
					alert(result);
				}
			});
		});


		jQuery(document).on("click", "#livechatzone_button_endchat", function (e) {

			var exit = confirm("Are you sure you want to end the session?");

			if (exit == true) {

				jQuery.post(livechatzone_host + "/inc/remotepayload/ajax.endchat.php?t=" + jQuery.now(), { site_key: lcz_site_key, vis_key: lcz_vis_key, ai_mode: use_ai }, function (result) {
					if (result) {
						alert(result);
					} else {

						//resets the chat id
						localStorage.removeItem("livechatzone_visitor");

						if (livechatzone_detectmobile()) {
							livechatzone_closemobile();
						} else {
							livechatzone_close();
						}

						window.location = window.location; //'?site_key='+lcz_site_key+'&amp;vis_key='+lcz_vis_key+'&amp;logout=true';
						//location.reload();
					}
					jQuery("span").html(result);
				});

			}

		});

		//file upload starts ----



		jQuery(document).on("click", "#livechatzone_download-chat-history", function (e) {
			//alert('feat not ready yet.');
			loadMessagesDownload();
		});

		jQuery(document).on("click", "#livechatzone_process-file-button", function (e) {
			e.preventDefault();
			jQuery('#livechatzone_file_input').trigger('click');
		});

		jQuery(document).on("change", "#livechatzone_file_input", function (e) {
			let files = new FormData(), // you can consider this as 'data bag'
				url = livechatzone_host + "/inc/remotepayload/upload.php?chat_vis=" + lcz_vis_key + "&amp;site_key=" + lcz_site_key+"&amp;ai_mode="+ use_ai + "&amp;t=" + jQuery.now();

			files.append('livechatzone_file', jQuery('#livechatzone_file_input')[0].files[0]); // append selected file to the bag named 'file'

			jQuery.ajax({
				type: 'post',
				url: url,
				processData: false,
				contentType: false,
				data: files,
				success: function (response) {
					//jQuery("#livechatzone_output").html(response);
					//document.write(response);
					if (response) {
						alert("Err #4199 " + response);
					}
				},
				error: function (err) {
					alert("Err #4102 " + err);
					jQuery("#livechatzone_output").html(err);
				}
			});
		});


		jQuery('#livechatzone_file_input').hide(); //css("visibility", "hidden")


		//----file upload ends

		//designer 2
		jQuery(document).on("click", ".livechatzone_download-main", function (event) {
			jQuery(this).find('.livechatzone_download-submenu').toggle();
		})


		//jQuery('#livechatzone_emoji-picker').html("&lt;a href=''&gt;ddd&lt;/a&gt;");

		jQuery(document).on("mouseover", ".lcz-emojis", function () { //mouseover
			//alert("aaa");
			jQuery(".lcz-emojilist").css("visibility", "visible");
		});


		jQuery(document).on("mouseout", ".lcz-emojis", function () {
			//alert("bbb");
			jQuery(".lcz-emojilist").css("visibility", "hidden");
		});
		/**/
		/*
		jQuery(document).on("click",".lcz-emojis", function(event){ 
			 jQuery(".lcz-emojilist").toggle();
		});
		
		
		jQuery(document).on("click",".lcz-emojis", function(){ //mouseover
		//alert("aaa");
			jQuery(".lcz-emojilist").css("visibility", "visible");
		}).mouseout(function() {
			jQuery(".lcz-emojilist").css("visibility", "hidden");
		});											
		*/

		jQuery(document).on("click", ".fg-emoji-picker-item", function (event) {
			event.preventDefault();
			//event.stopPropagation();
			//alert("ccc");
			//alert(jQuery(this).attr('data-code'));
			jQuery('#livechatzone_usermsg').val(jQuery('#livechatzone_usermsg').val() + ' ' + jQuery(this).attr('href') + ' ');
			jQuery(".lcz-emojilist").css("visibility", "hidden");

		});



		jQuery("#provideuserinfo_fields").hide(); //also removed from css
		jQuery(document).on("click", "#provideuserinfo_button", function (e) {
			jQuery("#provideuserinfo_fields").slideToggle("slow", function () {
				// Animation complete.
				jQuery("#provideuserinfo_button").hide();
			});
		});


		jQuery("#livechatzone_button_closed").html('&lt;img src="' + livechatzone_host + '/img/livechatbutton.png" class="livechatzone_buttonimg"/&gt;&lt;div class="lcz_title"&gt;Chat with us&lt;!--. We are online!--&gt;&lt;/div&gt; &lt;div class="livechatzone_button_leaf"&gt;&lt;/div&gt;');
		jQuery("#livechatzone_button_opened").html('&lt;div class="livechatzone_agentimg"&gt;&lt;/div&gt;&lt;div class="lcz_title"&gt;&amp;nbsp;&lt;/div&gt; &lt;div class="livechatzone_button_leaf"&gt;&lt;/div&gt;');


		//opens the chat by default if openchat param is set
		if (window.location.search.indexOf('openchat=') &gt; -1) {
			if (livechatzone_detectmobile()) {
				livechatzone_openmobile();
			} else {
				livechatzone_open();
			}
		}


		if (!livechat_debug) {

			if(lcz_open_after&gt;0){
				//open after x
				setTimeout(function () {
					//open after x miliseconds
					if (livechatzone_status != 'opened') {
						if (livechatzone_detectmobile()) {
							//livechatzone_openmobile();
							//do not open on mobile as it takes entire screen
						} else {
							livechatzone_open();
						}
					}
				}, lcz_open_after*1000);
			}

		} else {
			alert("Livechat is under maintenance, our technicians are working on it.");
			//livechatzone_open();
		}


		livechatzone_initload();




		//----

	} else {
		alert("Livechat missconfigured key. s:" + lcz_site_key + ' v:' + lcz_vis_key);
	}
});



</pre></body></html>