var Cloudim={Options:{},Chat:{},Api:{},Events:{},Utils:{}};Cloudim.Options={debug:false,accept_chats:false,Tab:{position:"right",margin:"20px"},Chat:{needName:false,needEmail:false,silent:false}}; Cloudim.Chat={iframe:null,server:"cloudim.ru",is_init:false,user_data:null,page_title:null,title_index:0,site_visible:true,visible:false,blink_interval:null,last_hash:window.location.hash,init:function(a){if(!Cloudim.Chat.is_init){var d=""; for(var b in a){d+="&"+b+"="+encodeURIComponent(a[b]);}Cloudim.Chat.is_init=true;Cloudim.Chat.iframe=document.createElement("iframe");Cloudim.Chat.iframe.id="cloudim_chat"; Cloudim.Chat.iframe.width="310";Cloudim.Chat.iframe.height="0";Cloudim.Chat.iframe.scrolling="no";Cloudim.Chat.iframe.frameBorder="0";Cloudim.Chat.iframe.style.position="fixed"; Cloudim.Chat.iframe.style.bottom="0px";Cloudim.Chat.iframe.style[Cloudim.Options.Tab.position]=Cloudim.Options.Tab.margin;Cloudim.Chat.iframe.style.zIndex="999"; Cloudim.Chat.iframe.style.width="310px";Cloudim.Chat.iframe.style.height="0px";Cloudim.Chat.iframe.style.minHeight="0px";Cloudim.Chat.iframe.src=window.location.protocol+"//"+(Cloudim.Options.debug?"cloudim.local":Cloudim.Chat.server)+"/im/?&silent="+encodeURIComponent(Cloudim.Options.Chat.silent)+"&accept_chats="+encodeURIComponent(Cloudim.Options.accept_chats)+"&need[name]="+encodeURIComponent(Cloudim.Options.Chat.needName)+"&need[email]="+encodeURIComponent(Cloudim.Options.Chat.needEmail)+"&"+d+"&url="+encodeURIComponent(window.location.href)+"&referer="+encodeURIComponent(document.referrer)+"&page="+encodeURIComponent(document.title.substr(0,50)); Cloudim.Chat.iframe.allowTransparency=true;document.body.appendChild(Cloudim.Chat.iframe);var c=document.createElement("div");c.id="cldm_eula_widget-wrapper"; c.style.display="none";c.innerHTML='
'; document.body.appendChild(c);Cloudim.Chat.addEvent(document.getElementById("cldm_eula_widget-wrapper"),"click",function(){document.getElementById("cldm_eula_widget-wrapper").style.display="none"; });Cloudim.Chat.page_title=document.title;}},showChat:function(a){Cloudim.Chat.iframe.height="475";Cloudim.Chat.iframe.style.height="475px";Cloudim.Events._callEvent("onOpen"); },chatHeight:function(a){if(typeof a.height!=="undefined"){Cloudim.Chat.iframe.height=a.height;Cloudim.Chat.iframe.style.height=a.height+"px";}},showPanel:function(){if(Cloudim.Chat.iframe.height>0){Cloudim.Events._callEvent("onClose"); }else{Cloudim.Events._callEvent("onShowTab");}Cloudim.Chat.iframe.height="40";Cloudim.Chat.iframe.style.height="40px";},showWelcome:function(){Cloudim.Chat.iframe.height="200"; Cloudim.Chat.iframe.style.height="200px";},showEula:function(a){document.getElementById("cldm_eula_widget-wrapper").style.display="";document.getElementById("cldm_eula--frame").src=a; },scriptMessage:function(b){if(typeof b.data=="string"&&b.data.substr(0,4)=="!im_"){var a=Cloudim.Utils.evalJSON(b.data.substr(4));if(typeof Cloudim.Chat[a.callback]!="undefined"){Cloudim.Chat[a.callback](a.data); }}},saveChatSession:function(c){var d=new Date(new Date().getTime()+60*60*1000);document.cookie="__cldm_sess="+encodeURIComponent(c.session)+"; path=/; expires="+d.toUTCString(); var a=new Date(new Date().getTime()+356*24*60*60*1000);document.cookie="__cldm_vis="+encodeURIComponent(c.visit)+"; path=/; expires="+a.toUTCString();if(Cloudim.Utils.getCookie("__cloudim")){var b=new Date(0); document.cookie="__cloudim=; path=/; expires="+b.toUTCString();}},addEvent:function(c,b,a){if(c.addEventListener){c.addEventListener(b,a,false);}else{if(c.attachEvent){c.attachEvent("on"+b,a); }else{c["on"+b]=a;}}},callMessageEvent:function(a){if((!Cloudim.Chat.visible&&!Cloudim.Chat.site_visible)&&!Cloudim.Chat.blink_interval){Cloudim.Chat.blink_interval=setInterval(Cloudim.Chat.blinkTitle,1000); }Cloudim.Events._callEvent("onMessage",a);},callClientMessageEvent:function(a){Cloudim.Events._callEvent("onClientMessage",a);},callTypingEvent:function(a){Cloudim.Events._callEvent("onTyping",a); },callPreInitEvent:function(){var a={session:Cloudim.Utils.getCookie("__cldm_sess"),visit:Cloudim.Utils.getCookie("__cldm_vis")};Cloudim.Utils.cloudimFunctionCall("sendChatUser",a); },callInitEvent:function(a){Cloudim.Events._callEvent("onInit",a);},callReadyEvent:function(){Cloudim.Events._callEvent("onReady");},callOnlineEvent:function(){Cloudim.Rules._runRules(); Cloudim.Events._callEvent("onOnline");},callBlurEvent:function(){Cloudim.Chat.visible=false;},callFocusEvent:function(){Cloudim.Chat.visible=true;},callOperatorChangeEvent:function(a){Cloudim.Events._callEvent("onOperatorChange",a); },callExternalEvent:function(a){Cloudim.Events._callEvent("onExternalEvent",a);},returnCallback:function(a){if(typeof Cloudim.Api.return_callbacks[a.callback_index]!="undefined"){if(typeof Cloudim.Api.return_callbacks[a.callback_index]=="string"){window[Cloudim.Api.return_callbacks[a.callback_index]](a.result); }else{Cloudim.Api.return_callbacks[a.callback_index](a.result);}Cloudim.Api.return_callbacks[a.callback_index]=undefined;}},blinkTitle:function(){if(Cloudim.Chat.title_index%2){var a=Cloudim.Chat.page_title; if(Cloudim.Chat.visible||Cloudim.Chat.site_visible){clearInterval(Cloudim.Chat.blink_interval);Cloudim.Chat.blink_interval=null;}}else{var a="*** Новое сообщение! ***"; }Cloudim.Chat.title_index++;document.title=a;}};Cloudim.Utils={initJSON:function(){(function($){$.toJSON=function(o){if(typeof(JSON)=="object"&&JSON.stringify){return JSON.stringify(o); }var type=typeof(o);if(o===null){return"null";}if(type=="undefined"){return undefined;}if(type=="number"||type=="boolean"){return o+"";}if(type=="string"){return $.quoteString(o); }if(type=="object"){if(typeof o.toJSON=="function"){return $.toJSON(o.toJSON());}if(o.constructor===Date){var month=o.getUTCMonth()+1;if(month<10){month="0"+month; }var day=o.getUTCDate();if(day<10){day="0"+day;}var year=o.getUTCFullYear();var hours=o.getUTCHours();if(hours<10){hours="0"+hours;}var minutes=o.getUTCMinutes(); if(minutes<10){minutes="0"+minutes;}var seconds=o.getUTCSeconds();if(seconds<10){seconds="0"+seconds;}var milli=o.getUTCMilliseconds();if(milli<100){milli="0"+milli; }if(milli<10){milli="0"+milli;}return'"'+year+"-"+month+"-"+day+"T"+hours+":"+minutes+":"+seconds+"."+milli+'Z"';}if(o.constructor===Array){var ret=[]; for(var i=0;i