var g_Ajax = null; var g_idleTimeout = 90 * 60 * 1000; var g_TrackingTimer; function currentTime() { var date = new Date(); return date.getTime(); } var g_timeStart = currentTime(); var g_title = document.title.substring(0, 150); var g_referrer = document.referrer; var g_State = 0; function _getAjax() { obj = null; if (window.XMLHttpRequest) obj = new XMLHttpRequest(); else if (window.ActiveXObject) { obj = new ActiveXObject("Microsoft.XMLHTTP") if (!obj) { try { obj = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { obj = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { obj = null; } } } } return obj; } function fetch( a_call ) { this.onload = a_call; this.a_ajax = _getAjax(); this.attemp = 0; this.busy = false; this.onError = function( a_args ) { this.attemp++; this.busy = false; if ( this.attemp>=1 ) { //alert("Ошибка отправки данных на сервер! Возможно сервер не доступен! "+ a_args ); this.a_ajax = null; return false; } this.send( a_args ); } this.send=function( a_args ) { if ( this.busy ) return false; if ( !this.a_ajax ) return false; var self = this; this.busy = true; try { this.a_ajax.open( 'POST', a_args.url , true); this.a_ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); //this.a_ajax.setRequestHeader("Content-length", a_args.data.length); //this.a_ajax.setRequestHeader("Connection", "close"); } catch(e) { //this.onError( a_args ); return false; } this.a_ajax.onreadystatechange = function() { try { if ( self.a_ajax.readyState == 4 ) { if ( self.a_ajax.status == 200 ) { self.attemp = 0; self.busy = false; //alert( self.a_ajax.responseText ); if ( self.onload ) self.onload( self.a_ajax.responseText,self ); else eval( self.a_ajax.responseText ); } } } catch(e) { self.onError( e ); return false; } } try { self.a_ajax.send( a_args.data ); } catch(e) { //this.onError( a_args ); return false; } } }; function openWnd(url,wnd_name,width,height,a_refresh,dontop ) { var wnd=top[wnd_name]; if ( typeof(a_refresh)!='undefined' && wnd!=null) { wnd.close(); wnd = null; } if ( wnd!=null && typeof(wnd)=='object' && typeof(wnd.document)!='undefined' && !wnd.closed ) { if (wnd.document.location.href!=url ) { wnd.location.href=url; } wnd.focus(); } else { var wnd = window.open(url,wnd_name,'width='+width+',height='+height+',status=yes,menubar=no,resizable=yes,scrollbars=yes,left='+String((screen.width-width)/2)+',top='+String((screen.height-height)/2)); if (typeof(donttop) == 'undefined') { top[wnd_name] = wnd; } } return wnd; } function create( name, attributes ) { var el = document.createElement( name ); if ( typeof(attributes) == 'object' ) { for ( var i in attributes ) { var val = ( attributes[i]==null ) ? '' : attributes[i]; switch( i.toLowerCase() ) { case 'class': el.className = val; // for IE compatibility break; case 'style': if ( typeof(el.style.cssText)=='undefined' ) el.setAttribute("style",val ); else el.style.cssText = val; // for IE compatibility break; case 'onchange': el.onchange = new Function( val ); break; case 'onclick': el.onclick = new Function( val ); break; default: el.setAttribute( i, val ); break; } } } for ( var i = 2; i _b.offsetHeight) ? _b.scrollHeight: _b.offsetHeight; return r; } function getDocumentWidth() { var _b = ( document.documentElement ) ? document.documentElement : document.body; return ( (_b.scrollWidth > _b.offsetWidth)?_b.scrollWidth:_b.offsetWidth ); } function defineMargin( f,s,fnc,style ) { var l = getStyle( document.body,f ); l = ( l =='auto' ) ? 0 : parseInt( l ); if ( !l ) { var r = getStyle( document.body,'marginRight'); r = ( r =='auto' ) ? 0 : parseInt( r ); if ( !r ) l = ( parseInt( fnc() ) - parseInt( getStyle(document.body,style) ) ) /2; else l = ( parseInt( fnc() )-r -parseInt( getStyle(document.body,style) ) ) /2; } return (l>0) ? l : 0; } function mLeft() { return defineMargin( 'marginLeft','marginRight',getDocumentWidth,'width'); } function mRight() { return defineMargin( 'marginRight','marginLeft',getDocumentWidth,'width'); } function getClientWidth() { var rez = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth; return parseInt(rez); } function getClientHeight() { var rez = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight; return parseInt(rez); } function getBodyScrollTop() { return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop); } function getBodyScrollLeft() { return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft); } function getClientCenterX() { return getClientWidth()/2+getBodyScrollLeft() - mLeft(); } function getClientCenterY() { return getClientHeight()/2+getBodyScrollTop(); } function Dialog() { this._image = null; this._invite = null; this._dlg = null; this._shadow = null; this._nick = null; this._oldR = null; this.create = function() { if ( this._dlg ) return; this._shadow = create('div',{ style:"z-index:1010;display:none;position:absolute;top:0px;left:0px;background-color:#333;-moz-opacity:0.4;opacity:.40;filter:alpha(opacity=40);"}); this._dlg = create('div',{style:"width:402px;background:white; border:1px solid #000;padding:0px;z-index:1011;position:absolute;"}, create('div',{ style:"background:blue;" }, create('b',{}, create('font',{ color:"white" },'Приглашение!')) ), create('table',{width:"100%"}, create('tbody',{}, create('tr',{}, create('td',{width:"20%"},this._image = create('img',{id:"user_img",width:"200px"})), create('td',{width:"80%",style:"border:1px solid #000;vertical-align:top;height:100%;"},this._invite = create('div',{id:"_dlg_text"})) ), create('tr',{}, create('td',{}), create('td',{align:"right"},'Ваше имя:', this._nick = create('input',{type:"text",id:"_n",name:"_n"} ) ) ), create('tr',{}, create('td',{}), create('td',{align:"right"}, create('input',{type:"button",value:"Принять",onclick:"startSeans();"}), create('input',{type:"button",value:"Отклонить",onclick:"cancelSeans();"}) ) ) ) ) ); document.body.appendChild( this._shadow ); document.body.appendChild( this._dlg ); }; this.test = function() { if ( !this._dlg ) this.create(); } this.setText = function ( a_text ) { this.test(); this._invite.innerHTML = a_text; } this.setImg = function( a_user_id ) { this.test(); this._image.src= '/live-help/operator/userImg.php?user_id='+escape(a_user_id); this._image.style.width="150px"; } this.center = function(){ this._dlg.style.left = getClientCenterX() - parseInt( this._dlg.offsetWidth )/2+'px'; this._dlg.style.top = getClientCenterY() - parseInt( this._dlg.offsetHeight )/2+'px'; } this.show = function( a_show ) { this.test(); this._dlg.style.display = ( a_show ) ? "block" : "none"; this._shadow.style.display = ( a_show ) ? "block" : "none"; if ( a_show ) { this.center(); this._shadow.style.left = -mLeft()+'px'; this._shadow.style.height = getDocumentHeight()+'px'; this._shadow.style.width = getDocumentWidth()+'px'; this._oldR = window.onscroll; window.onscroll = doCenter; } else if ( this._oldR ) window.onscroll = this._oldR; } this.nickName = function() { this.test(); return this._nick.value; } }; function _setState( a_state ) { if ( g_State == a_state ) return; g_State = a_state; } var _inviteDialog = new Dialog; function doCenter() { _inviteDialog.center(); } function _initSeans( message,user_id ) { if ( g_State!=1 ) return; _inviteDialog.show( true ); _inviteDialog.setImg( user_id ); _inviteDialog.setText( message ); _setState(2); } function cancelSeans() { _inviteDialog.show( false ); _setState( 3 ); return false; } function startSeans() { var n = _inviteDialog.nickName(); openWnd('/live-help/client/chat.php?nick='+encodeURIComponent(n),'addaccess',600,500,true ); _inviteDialog.show( false ); _setState( 1 ); return false; } function stopTracking() { g_Ajax.abort(); g_Ajax = null; } function cookie() { var cookieEnabled=(navigator.cookieEnabled)? true : false //if not IE4+ nor NS6+ if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ document.cookie="testcookie" cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false } return cookieEnabled; } function startAjaxTracking() { if ( !cookie() ) return; RequestData = 'STATE='+escape(g_State); if ( !g_State ) RequestData = RequestData+'&TITLE=' + encodeURIComponent(g_title) + '&URL=' + escape(document.location) + '&REFERRER=' + escape(g_referrer); g_Ajax.send({url:"/live-help/client/trackClient.php",data:RequestData}); var l_time = currentTime(); l_timeElapsed = l_time - g_timeStart; if ( l_timeElapsed < g_idleTimeout ) { window.clearTimeout( g_TrackingTimer ); g_TrackingTimer = window.setTimeout('startAjaxTracking();', 3000 ); } } g_Ajax = new fetch(); startAjaxTracking();