var isSoundEnabled=true;var processingSomething=false;var specificDepartment=null;var specificRouteId=null;var specificOperators=null;var chatName=null;var refreshInterval=1500;var operatorIsTyping=0;var clientIsTyping=0;var typingTimeoutTimer=null;var chatSessionActive=0;var chatSessionMdate=0;var JLiveChat={websiteRoot:"",hostedModeURI:false,debugging:false,currentURI:null,chatWindowOpen:false,chatWindowMode:null,serverURI:"index.php?option=com_jlivechat&view=popup&tmpl=component",proactiveRecheckInterval:10000,memberId:null,chatSessionId:null,popupWindowObj:null,iframeWindowObj:null,autopopupId:"jlivechat_autopopup",autopopupVisible:false,autoPopupHTML:null,autopopupObj:null,iframeId:"livechat_iframe",iframeOpen:false,closedPermanently:false,callbackFunc:null,alreadyInitialized:false,xhrDataType:"json",visitorSentLastMessage:true,initialize:function(){if(!JLiveChat.alreadyInitialized){JLiveChat.alreadyInitialized=true;JLiveChat.xhrDataType=(JLiveChat.hostedModeURI!=false?"jsonp":"json");JLiveChat.currentURI=String(document.location.href);JLiveChat.loadJS()}},loadJS:function(){var requiredJSLibs=[];if(typeof(window.jQuery)=="undefined"){requiredJSLibs.push(JLiveChat.websiteRoot+"/components/com_jlivechat/js/jquery-1.6.4.min.js")}if(requiredJSLibs.length>0){LazyLoad.loadOnce(requiredJSLibs,JLiveChat.jsLoaded)}else{JLiveChat.jsLoaded()}},jsLoaded:function(){jQuery.noConflict();if(JLiveChat.callbackFunc){JLiveChat.callbackFunc();JLiveChat.callbackFunc=null}if(JLiveChat.currentURI.indexOf("popup_mode")>-1){setPopupWindowStyles();var isInIFrame=(window.location!=window.parent.location)?true:false;if(!isInIFrame){attachCloseEvent()}}else{JLiveChat.checkProactive();setTimeout("JLiveChat.checkAutopopup();",1500)}},checkAutopopup:function(){if(JLiveChat.currentURI.indexOf("popup_mode")>-1||JLiveChat.currentURI.indexOf("tmpl=component")>-1||JLiveChat.chatWindowOpen){return false}var params={no_html:"1",do_not_log:"true",t:JLiveChat.timestamp(),task:"check_autopopup"};jQuery.ajax({type:"GET",url:JLiveChat.websiteRoot+"/"+JLiveChat.serverURI,dataType:JLiveChat.xhrDataType,data:params,cache:false,success:function(data){if(parseInt(data.show_popup)>0){JLiveChat.autoPopupHTML=data.display_html;var displayInSeconds=(parseInt(data.display_html_in_seconds)-1)*1000;var showPopup=true;if(data.display_html_on_uris.length>0){showPopup=false;var pageUri=null;jQuery.each(data.display_html_on_uris,function(index,item){pageUri=String(item);if(JLiveChat.currentURI.indexOf(pageUri)>-1){showPopup=true}})}if(showPopup){setTimeout("JLiveChat.showAutoPopup();",displayInSeconds)}}}});return true},showAutoPopup:function(){var body=jQuery(document.body);JLiveChat.autopopupObj=jQuery("<div />",{id:JLiveChat.autopopupId});JLiveChat.autopopupObj.html(JLiveChat.autoPopupHTML);body.append(JLiveChat.autopopupObj);JLiveChat.animateInAutopopup();var isMobile=(/iphone|ipad|ipod|android|blackberry/i.test(navigator.userAgent.toLowerCase()));if(isMobile){if(!navigator.userAgent.match(/(iPad|iPhone|iPod).*OS [5-9]_/i)&&!navigator.userAgent.match(/Android [3-9]/i)&&!navigator.userAgent.match(/BlackBerry[0-9\w\s\.]*\/[7-9]/i)){var updatePositionFunc=function(){var autoPopupHeight=parseInt(JLiveChat.autopopupObj.css("height"));var newPosition=window.pageYOffset+window.innerHeight-autoPopupHeight;JLiveChat.autopopupObj.css("top",String(newPosition)+"px")};jQuery(document).bind("scroll",updatePositionFunc);updatePositionFunc()}}},animateInAutopopup:function(){JLiveChat.autopopupObj.animate({marginBottom:0},650);JLiveChat.autopopupVisible=true},animateOutAutopopup:function(){if(!JLiveChat.autopopupVisible){return false}JLiveChat.autopopupObj.animate({marginBottom:"-90px"},"slow");JLiveChat.autopopupVisible=false;return true},closeAutopopup:function(closeDelay){if(!closeDelay){closeDelay=1500}setTimeout("JLiveChat.animateOutAutopopup();",closeDelay)},checkProactive:function(){if(document.location.protocol=="https:"||JLiveChat.currentURI.indexOf("popup_mode")>-1||JLiveChat.currentURI.indexOf("tmpl=component")>-1){return false}var params={no_html:"1",do_not_log:"true",t:JLiveChat.timestamp(),task:"check_proactive"};jQuery.ajax({type:"GET",url:JLiveChat.websiteRoot+"/"+JLiveChat.serverURI,dataType:JLiveChat.xhrDataType,data:params,cache:false,success:function(data){if(data){if(data.proactive&&!JLiveChat.chatWindowOpen){JLiveChat.memberId=parseInt(data.proactive.member_id);JLiveChat.chatSessionId=parseInt(data.proactive.chat_session_id);JLiveChat.openLiveChatWindow(null,"iframe")}else{if(parseInt(data.proactive_setting)==1&&!JLiveChat.chatWindowOpen){setTimeout("JLiveChat.checkProactive();",JLiveChat.proactiveRecheckInterval)}}}else{setTimeout("JLiveChat.checkProactive();",JLiveChat.proactiveRecheckInterval)}}});return true},describe:function(obj){if(obj==null){return null}switch(typeof(obj)){case"object":var message="";for(key in obj){message+=", ["+key+"]: ["+obj[key]+"]"}if(message.length>0){message=message.substring(2)}return message;default:return""+obj}},debug:function(message){if(JLiveChat.debugging){alert("AjaxJS Message:\n\n"+message)}},error:function(message){if(JLiveChat.debugging){alert("AjaxJS ERROR:\n\n"+message)}},trim:function(str){return str.replace(/(^\s+|\s+$)/g,"")},strip:function(str){return str.replace(/\s+/,"")},urlencode:function(str){if(!str){return str}var histogram={},histogram_r={},code=0,tmp_arr=[];var ret=str.toString();var replacer=function(search,replace,str){var tmp_arr=[];tmp_arr=str.split(search);return tmp_arr.join(replace)};histogram["!"]="%21";histogram["%20"]="+";ret=encodeURIComponent(ret);for(search in histogram){replace=histogram[search];ret=replacer(search,replace,ret)}return ret.replace(/(\%([a-z0-9]{2}))/g,function(full,m1,m2){return"%"+m2.toUpperCase()});return ret},timestamp:function(){return Number(new Date())},openLiveChatWindow:function(popupUri,popupMode){if(JLiveChat.iframeOpen&&JLiveChat.chatWindowMode!="iframe"){JLiveChat.closeIFramePopup()}JLiveChat.chatWindowOpen=true;JLiveChat.chatWindowMode=popupMode;if(!popupUri){popupUri=JLiveChat.websiteRoot+"/"+JLiveChat.serverURI+"&popup_mode="+popupMode}if(popupMode=="iframe"){if(JLiveChat.iframeOpen){return false}JLiveChat.iframeOpen=true;JLiveChat.closeAutopopup(1);var popW=504;var popH=404;if(window.webkit){popW=514;popH=414}var body=document.getElementsByTagName("body").item(0);if(!JLiveChat.iframeWindowObj){JLiveChat.iframeWindowObj=document.createElement("iframe");JLiveChat.iframeWindowObj.src=popupUri;JLiveChat.iframeWindowObj.id=JLiveChat.iframeId;JLiveChat.iframeWindowObj.name=JLiveChat.iframeId;JLiveChat.iframeWindowObj.width=popW;JLiveChat.iframeWindowObj.height=popH;JLiveChat.iframeWindowObj.frameborder=0;JLiveChat.iframeWindowObj.scrolling="no";JLiveChat.iframeWindowObj.allowautotransparency=true;JLiveChat.iframeWindowObj.style.overflow="hidden";JLiveChat.iframeWindowObj.style.display="block";JLiveChat.iframeWindowObj.style.zIndex=10000;JLiveChat.iframeWindowObj.style.bottom=0;JLiveChat.iframeWindowObj.style.right=0;JLiveChat.iframeWindowObj.style.border="none";body.appendChild(JLiveChat.iframeWindowObj)}if(!jQuery(JLiveChat.iframeWindowObj).is(":visible")){JLiveChat.closedPermanently=false;JLiveChat.iframeWindowObj=document.createElement("iframe");JLiveChat.iframeWindowObj.src=popupUri;JLiveChat.iframeWindowObj.id=JLiveChat.iframeId;JLiveChat.iframeWindowObj.name=JLiveChat.iframeId;JLiveChat.iframeWindowObj.width=popW;JLiveChat.iframeWindowObj.height=popH;JLiveChat.iframeWindowObj.frameborder=0;JLiveChat.iframeWindowObj.scrolling="no";JLiveChat.iframeWindowObj.allowautotransparency=true;JLiveChat.iframeWindowObj.style.overflow="hidden";JLiveChat.iframeWindowObj.style.display="block";JLiveChat.iframeWindowObj.style.zIndex=10000;JLiveChat.iframeWindowObj.style.bottom=0;JLiveChat.iframeWindowObj.style.right=0;JLiveChat.iframeWindowObj.style.border="none";body.appendChild(JLiveChat.iframeWindowObj)}JLiveChat.showIFramePopup();setTimeout("JLiveChat.monitorIFramePopup();",300)}else{if(JLiveChat.iframeOpen){JLiveChat.closeIFramePopup()}JLiveChat.closeAutopopup(null);var screenWidth=760,screenHeight=420;if(screen.availWidth&&screen.availHeight){screenWidth=screen.availWidth;screenHeight=screen.availHeight}var livechatPopupWidth=500;var livechatPopupHeight=400;if(window.webkit){livechatPopupWidth=502;livechatPopupHeight=402}var leftPos=(screenWidth-livechatPopupWidth)/2,topPos=(screenHeight-livechatPopupHeight)/2;JLiveChat.popupWindowObj=window.open(popupUri,"LiveChatWindow","menubar=0,scrollbars=0,status=1,resizable=0,location=0,toolbar=0,height="+livechatPopupHeight+",width="+livechatPopupWidth+",left="+leftPos+",top="+topPos);if(window.focus&&JLiveChat.popupWindowObj){JLiveChat.popupWindowObj.focus()}}return true},closeIFramePopup:function(){if(JLiveChat.iframeWindowObj){if(JLiveChat.iframeOpen||!JLiveChat.closedPermanently){JLiveChat.iframeOpen=false;JLiveChat.closedPermanently=true;jQuery(JLiveChat.iframeWindowObj).addClass("jlc-hide")}}return true},showIFramePopup:function(){jQuery(JLiveChat.iframeWindowObj).removeClass("jlc-popup-minimized")},hideIFramePopup:function(){jQuery(JLiveChat.iframeWindowObj).addClass("jlc-popup-minimized")},monitorIFramePopup:function(){if(!JLiveChat.iframeOpen||JLiveChat.closedPermanently){return false}var recheck=true;if(window.location.hash=="#close_window"){window.location.hash="#";JLiveChat.closeIFramePopup()}else{if(window.location.hash=="#minimize_window"){window.location.hash="#";JLiveChat.hideIFramePopup()}else{if(window.location.hash=="#restore_window"){window.location.hash="#";JLiveChat.showIFramePopup()}}}if(recheck){setTimeout("JLiveChat.monitorIFramePopup();",300)}return true},closeWnd:function(){var isInIFrame=(window.location!=window.parent.location)?true:false;if(!isInIFrame){window.close()}else{window.parent.window.location.hash="#close_window"}return true},endSession:function(){if(chatSessionActive==1){chatSessionActive=0;var params={t:JLiveChat.timestamp(),task:"end_session"};jQuery.ajax({type:"GET",url:JLiveChat.websiteRoot+"/"+JLiveChat.serverURI,dataType:JLiveChat.xhrDataType,data:params,cache:false,async:false})}},minimizeWnd:function(){var isInIFrame=(window.location!=window.parent.location)?true:false;if(!isInIFrame){return false}jQuery("#minimize-window-button").attr("onclick","");jQuery("#minimize-window-button").click(function(){JLiveChat.restoreIFramePopup()});window.parent.window.location.hash="#minimize_window";return true},restoreIFramePopup:function(){var isInIFrame=(window.location!=window.parent.location)?true:false;if(!isInIFrame){return false}jQuery("#minimize-window-button").attr("onclick","");jQuery("#minimize-window-button").click(function(){JLiveChat.minimizeWnd()});window.parent.window.location.hash="#restore_window";return true},startChatSession:function(){if(processingSomething==false){processingSomething=true;var connectingLayer=jQuery("#connecting_layer");var errorLayer=jQuery("#error_layer");var chatNameInput=jQuery("#chat_name");connectingLayer.css("display","inline-block");errorLayer.css("display","none");var params={t:JLiveChat.timestamp(),task:"start_session",name:chatNameInput.attr("value")};if(specificOperators){params.operators=specificOperators}else{if(specificRouteId){params.routeid=specificRouteId}else{if(specificDepartment){params.department=specificDepartment}}}jQuery.ajax({type:"POST",url:JLiveChat.websiteRoot+"/"+JLiveChat.serverURI,dataType:JLiveChat.xhrDataType,data:params,cache:false,success:function(data){if(data.success==0){errorLayer.text(data.error);connectingLayer.css("display","none");errorLayer.css("display","inline-block");processingSomething=false}else{chatName=String(chatNameInput.attr("value"));connectingLayer.css("display","inline-block");errorLayer.css("display","none");JLiveChat.monitorPendingChatSession()}}})}return false},monitorPendingChatSession:function(){var params={t:JLiveChat.timestamp(),task:"check_session"};var isInIFrame=(window.location!=window.parent.location)?true:false;if(isInIFrame){params.popup_mode="iframe"}else{params.popup_mode="popup"}if(specificOperators){params.operators=specificOperators}else{if(specificRouteId){params.routeid=specificRouteId}else{if(specificDepartment){params.department=specificDepartment}}}jQuery.ajax({type:"POST",url:JLiveChat.websiteRoot+"/"+JLiveChat.serverURI,dataType:JLiveChat.xhrDataType,data:params,cache:false,success:function(data){var chatActive=parseInt(data.chat_active);var chatAccepted=parseInt(data.chat_accepted);if(chatActive==0){JLiveChat.setOffline()}else{if(chatActive==1&&chatAccepted==1){JLiveChat.setSessionActive()}else{setTimeout("JLiveChat.monitorPendingChatSession();",refreshInterval)}}}})},setOffline:function(){processingSomething=false;var preChatContainer=jQuery("#jlc_prechat_container");var offlineContainer=jQuery("#jlc_offline_container");var livechatToolbar=jQuery("#jlc_toolbar_container span");preChatContainer.css("display","none");livechatToolbar.css("display","none");offlineContainer.css("display","block")},setSessionActive:function(){var inChatWrapper=jQuery("#jlc_inchat_container");var preChatWrapper=jQuery("#jlc_prechat_container");JLiveChat.initTxtInput();preChatWrapper.css("display","none");inChatWrapper.css("display","block");jQuery("#livechat_container .livechat_toolbar").addClass("livechat_toolbar_active");if(isSoundEnabled){jQuery("#jlc_toolbar_container span").css("display","block")}jQuery(window).focus();jQuery("#msg-input").focus();JLiveChat.refreshSession()},leaveMessage:function(){if(processingSomething==false){processingSomething=true;var params={t:JLiveChat.timestamp(),task:"leave_message",message_name:jQuery("#message_name").val()};if(jQuery("#message_phone")){params.message_phone=jQuery("#message_phone").val()}params.message_email=jQuery("#message_email").val();params.message_txt=jQuery("#message_txt").val();if(specificOperators){params.operators=specificOperators}else{if(specificRouteId){params.routeid=specificRouteId}else{if(specificDepartment){params.department=specificDepartment}}}jQuery.ajax({type:"POST",url:JLiveChat.websiteRoot+"/"+JLiveChat.serverURI,dataType:JLiveChat.xhrDataType,data:params,cache:false,success:function(data){var success=parseInt(data.success);var errorMsg="";jQuery.each(data.errors,function(index,item){errorMsg+=String(item);errorMsg+="\n"});alert(errorMsg);if(success==1){JLiveChat.closeWnd()}else{processingSomething=false}}})}return false},sendMsg:function(msg){clientIsTyping=0;JLiveChat.visitorSentLastMessage=true;var resetInput=false;if(!msg){resetInput=true;msg=String(jQuery("#msg-input").val())}if(resetInput){var resetFunc=function(){jQuery("#msg-input").val("")};setTimeout(resetFunc,500)}var params={t:JLiveChat.timestamp(),task:"send_message",m:msg};jQuery.ajax({type:"POST",url:JLiveChat.websiteRoot+"/"+JLiveChat.serverURI,dataType:JLiveChat.xhrDataType,data:params,cache:false,success:function(){},error:function(theXHR,theTextStatus,theErrorThrown){alert("Your last message was not sent! Please try again.");jQuery("#msg-input").val(msg)}});return false},initTxtInput:function(){jQuery("#msg-input").bind("keydown",function(event){if(event.keyCode==13){JLiveChat.sendMsg(null)}else{clientIsTyping=1;if(typingTimeoutTimer){clearTimeout(typingTimeoutTimer)}var typingTimeoutFunc=function(){clientIsTyping=0};typingTimeoutTimer=setTimeout(typingTimeoutFunc,900)}})},refreshSession:function(){var params={t:JLiveChat.timestamp(),task:"refresh_session",client_is_typing:parseInt(clientIsTyping)};var isInIFrame=false;if(String(document.location.href).indexOf("popup_mode=iframe")>-1||String(document.location.href).indexOf("popup_mode/iframe")>-1){isInIFrame=true;try{if(!window.parent.JLiveChat.iframeOpen&&window.location!=window.parent.location){return false}}catch(err){}}if(isInIFrame){params.popup_mode="iframe"}else{params.popup_mode="popup"}jQuery.ajax({type:"POST",url:JLiveChat.websiteRoot+"/"+JLiveChat.serverURI,dataType:JLiveChat.xhrDataType,data:params,cache:false,success:function(data){if(data){if(data.is_typing.length>0){jQuery("#status-display").css("display","block")}else{jQuery("#status-display").css("display","none")}chatSessionActive=parseInt(data.is_active);if(chatSessionMdate!=parseInt(data.chat_mdate)){chatSessionMdate=parseInt(data.chat_mdate);jQuery("#session-content-display-inner").html(data.chat_content);if(isSoundEnabled&&!JLiveChat.visitorSentLastMessage){JLiveChat.playNewChatSoundNotification()}JLiveChat.visitorSentLastMessage=false;if(clientIsTyping==0){jQuery(window).focus();jQuery("#msg-input").focus()}jQuery("#session-content-display").animate({scrollTop:jQuery("#session-content-display-inner").height()},1200)}if(chatSessionActive==1){setTimeout("JLiveChat.refreshSession();",refreshInterval)}else{jQuery("#status-display").css("display","none");jQuery("#msg-input").attr("disabled",true)}}},error:function(theXHR,theTextStatus,theErrorThrown){try{if(chatSessionActive==1){setTimeout("JLiveChat.refreshSession();",refreshInterval)}else{jQuery("#status-display").css("display","none");jQuery("#msg-input").attr("disabled",true)}}catch(err){}}})},toggleSoundNotifications:function(){var muteIcon=jQuery("#mute_icon");if(muteIcon){if(isSoundEnabled){isSoundEnabled=false;muteIcon.removeClass("unmute_sound_icon");muteIcon.addClass("mute_sound_icon")}else{isSoundEnabled=true;muteIcon.removeClass("mute_sound_icon");muteIcon.addClass("unmute_sound_icon")}}},playNewChatSoundNotification:function(){try{var soundObject=soundManager.getSoundById("newMessageSound");soundObject.play()}catch(e){}}};var AutoPopupChecker={close:function(closeDelay){JLiveChat.closeAutopopup(closeDelay)}};function requestLiveChat(popupUri,mode){JLiveChat.openLiveChatWindow(popupUri,mode)}function prepYUI(){var bodyObj=document.getElementsByTagName("body").item(0);if(bodyObj){bodyObj.className="yui-skin-sam"}}function closeWnd(){return JLiveChat.closeWnd()}function sendMsg(msg){return JLiveChat.sendMsg(msg)}function sendMsgAndClearEvent(eventObject){return JLiveChat.sendMsg()}function leaveMessage(){return JLiveChat.leaveMessage()}function startChatSession(){return JLiveChat.startChatSession()}function setSessionActive(){return JLiveChat.setSessionActive()}function setOffline(){return JLiveChat.setOffline()}function minimizeWnd(){return JLiveChat.minimizeWnd()}function attachCloseEvent(){jQuery(window).bind("beforeunload",function(){JLiveChat.endSession()});jQuery(window).bind("unload",function(){JLiveChat.endSession()})}function setPopupWindowStyles(){if(jQuery.browser.msie&&parseInt(jQuery.browser.version)<=6){jQuery("#msg-input").css("width","479px")}else{jQuery("#msg-input").css("width","99.5%")}jQuery("#msg-input").css("height","40px");jQuery("#msg-input").css("padding","0px");jQuery("#msg-input").css("margin","0px");jQuery("#msg-input").css("border","1px solid #383C3F");jQuery("#msg-input").css("float","left");jQuery("#msg-input").css("font-size","13px");jQuery("#msg-input").css("font-family","Arial, helvetica, sans");if(jQuery.browser.msie){jQuery("#jlc_prechat_container input[type=text]").css("width","470px");jQuery("#jlc_prechat_container input[type=text]").css("border","1px solid #888888");jQuery("#jlc_prechat_container input[type=text]").css("font-size","15px");jQuery("#jlc_prechat_container input[type=text]").css("padding","4px 0 4px 0");jQuery("#jlc_prechat_container input[type=text]").css("margin","2px 0 0 0");jQuery("#jlc_offline_container input[type=text]").css("border","1px solid #888888");jQuery("#jlc_offline_container input[type=text]").css("font-size","15px");jQuery("#jlc_offline_container input[type=text]").css("padding","3px 0 3px 3px");jQuery("#jlc_offline_container input[type=text]").css("margin","2px 0 0 0");jQuery("#jlc_offline_container textarea").css("padding","1px");jQuery("#jlc_offline_container textarea").css("width","98.9%");jQuery("#jlc_offline_container textarea").css("height","40px");setTimeout("checkYUIMenus()",10)}if(jQuery("#chat_name")){jQuery("#chat_name").bind("keydown",function(event){if(event.keyCode==13){startChatSession()}})}if(jQuery("#message_name")){jQuery("#message_name").bind("keydown",function(event){if(event.keyCode==13){leaveMessage()}})}if(jQuery("#message_email")){jQuery("#message_email").bind("keydown",function(event){if(event.keyCode==13){leaveMessage()}})}if(jQuery("#message_phone")){jQuery("#message_phone").bind("keydown",function(event){if(event.keyCode==13){leaveMessage()}})}}function checkYUIMenus(){JLiveChat.initialize();jQuery("#route-filter-menubutton").css("width","470px");jQuery("#route-filter-menubutton button").css("width","470px");jQuery("#yui-gen0").css("width","470px");if(jQuery.browser.msie&&parseInt(jQuery.browser.version)<=6){jQuery("#route-filter-container").css("margin-left","-2px")}if(jQuery.browser.msie&&parseInt(jQuery.browser.version)==7){jQuery("#route-filter-container").css("margin-left","-1px")}}var onRouteDepartmentSelectedMenuItemChange=function(event){var oMenuItem=event.newValue;specificDepartment=oMenuItem.value;this.set("label",('<em class="yui-button-label">'+oMenuItem.cfg.getProperty("text")+"</em>"))};var onRouteOperatorSelectedMenuItemChange=function(event){var oMenuItem=event.newValue;specificOperators=oMenuItem.value;this.set("label",('<em class="yui-button-label">'+oMenuItem.cfg.getProperty("text")+"</em>"))};
