function LivechatInvite()
{
    /**
    * Class Constructor 
    */
    this.ns = (navigator.appName.indexOf("Netscape") != -1);
    this.d = document;
    this.invite_layer = 'lc_invite_layer';
    this.private_invite_id = 'LC_Private_Invite';
    this.invite_body = ''
    this.httpp = (window.location.protocol.indexOf('https') != -1) ? 'https://' : 'http://';
    this.isPrivate = false;
    
    this.lc_timerID;
    this.lc_timerID_wait;

    this.lc_controlImage;
    this.lc_inviteImage;

    this.lc_MC = 0;
    this.lc_Z = 1;
    this.lc_W = 0;
    this.lc_I = 0;
    this.lc_R = 5000;
    
    this.analytics_id = 'UA-3575297-3';

    this.gRoutine = function()
    {
        if((this.analytics_id.indexOf('UA-') != -1) && (typeof window.urchinTracker == 'function')){
            _uacct = this.analytics_id;
            _udn = "none";
            _ulink = 1;
            urchinTracker();
            return true;
        }
        return false;
    };
    
    
    this.gRequest = function()
    {
        if(!this.gRoutine()){ return; }
        try{
            var path = 'ContactCenter Invites/';
            urchinTracker(path);
            __utmSetVar(path);
        }catch(e){}
    };
    

    this.lc_send_message = function() 
    {
        if (this.lc_timerID) { clearTimeout(this.lc_timerID); }
        if (this.lc_timerID_wait) { clearTimeout(this.lc_timerID_wait); }
  
        this.lc_controlImage = new Image;
        pageDate = new Date;
        currTime = pageDate.getTime();
  
        u = this.httpp + 'chat.link4.pl/licence/20379/control.cgi';
        u = u + '?' + currTime;
        u = u + '&S1283955770.b4a5728119';
  
        if (this.lc_MC == 0) {
            u = u + '&$';
            u = u + '&' + escape(document.location);
   
            if(document.referrer == '') {
                u = u + '&$';
            } else {
                u = u + '&' + escape(document.referrer);
            }
    
            u = u + '&1283955770';
            u = u + '&20379';
            u = u + '&$';
            u = u + '&1';
            u = u + '&1';
            u = u + '&0';
            u = u + '&0';
            u = u + '&0';
            u = u + '&$';
            u = u + '&$';
            u = u + '&$';
        
            if(document.title == '') {
                u = u + '&$';
            } else {
                u = u + '&' + encodeURI(document.title);
            }
            
            u = u + '&0';
        }

        this.lc_MC++;
        this.lc_controlImage.src = u;
        this.lc_timerID = setTimeout('LC_Invite.lc_send_message()', this.lc_R);
        this.lc_timerID_wait = setTimeout('LC_Invite.lc_after_send()', 500);
    };
    
    this.lc_after_send = function() 
    {
    
    
        if (this.lc_timerID_wait) { clearTimeout(this.lc_timerID_wait); }
        if (this.lc_controlImage.complete == true) {
        
            var w = this.lc_controlImage.width;
            
            if ((w == 33) || (w == 34) || (w == 24)) {
                if (this.lc_I == 0 && this.lc_Z == 1) {
                    if (0) {
                        window.open('' + httpp + 'chat.link4.pl/licence/20379/open_chat.cgi?invite=1&lang=pl&groups=0&dc=' + escape(document.cookie+';l='+document.location+';r='+document.referer+';s='+typeof lc_session),'Czat','width=604,height=247,resizable=no,scrollbars=no,status=1'); 
                    } else if (w == 34) {
                        this.lc_load_invite_ex();
                    } else {
                        this.lc_load_invite();
                    }
      
                } else {
                    if (this.lc_I == 0 && this.lc_W == 0) { this.lc_Z = 1; }
                }
    
            } else if (w == 35) {
                this.lc_MC = 0;
            } else if (( w >=128) && (w < 255)) {
                this.lc_R = (w - 127) * 1000;
            } else if (w == 255) {
                if (this.lc_timerID) { clearTimeout(this.lc_timerID); }
                if (this.lc_timerID_wait) { clearTimeout(this.lc_timerID_wait); } 
            } else {
                this.lc_W = 0;
                this.lc_Z = 1;
            }
    
            if (this.lc_I > 0) { 
                this.lc_I--; 
            }
  
        } else {
            this.lc_timerID_wait = setTimeout('LC_Invite.lc_after_send()', 500);
        }

    };
    

    this.drawInvite = function()
    {

        var invite_div = document.createElement('div');
	    invite_div.setAttribute('id', this.invite_layer);
	    invite_div.style.position = 'absolute';
	    invite_div.style.left = 0;
	    invite_div.style.top = 0;
	    invite_div.style.display = 'none';
	    invite_div.style.zIndex = 999;
		
        this.invite_body ='<div style="position:relative">';
        this.invite_body+='<a style="display:block;position:absolute;top:0;right:0;width:70px;height:25px;outline:none;background:url('+this.httpp+'chat.livechatinc.net/server/images/pixel.gif)" href="javascript:void(0)" onclick="LC_Invite.lc_popup_close()"></a>';
		this.invite_body+='<a href="javascript:void(0)" onclick="LC_Invite.lc_open_chat()" style="display:block;outline:none">';
		this.invite_body+='<img src="' + this.httpp + 'chat.link4.pl/licence/20379/gfx/invite_pl.jpg" border="0">';
		this.invite_body+='</a>';
        this.invite_body+='</div>';
		
	    invite_div.innerHTML = this.invite_body;
        document.getElementsByTagName("body").item(0).appendChild(invite_div);
        
        this.lc_send_message();
    };


    this.lc_load_invite = function() 
    {
        this.gRequest();
        this.lc_popup_show();
        lc_animate(this.invite_layer, 250, 50).floatIt();
    };


    this.lc_load_invite_ex = function() 
    {
        this.gRequest();
        this.isPrivate = true;
        var httpp = this.httpp;
        var head = document.getElementsByTagName('head')[0];
        
        script = document.createElement('script');
        script.id = this.private_invite_id;
        script.type = 'text/javascript';
        script.src = httpp + "chat.link4.pl" + "/invite.cgi?status=1&licence=20379&lang=pl&sess=S1283955770.b4a5728119&base_url=" + httpp + "chat.link4.pl&redirect=" + escape('' + httpp + 'chat.link4.pl/licence/20379/open_chat.cgi?invite=1&lang=pl&groups=0') + "&rand=" + Math.floor(Math.random() * 1000);
        head.appendChild(script);
    };

    this.lc_popup_hide = function() 
    {
        element = document.getElementById(this.invite_layer);
        element.style.display = "none";
        if(this.isPrivate){
            LC_PrivateInvite.removeJs(this.private_invite_id);
            element.innerHTML = this.invite_body;
        }
    };


    this.lc_popup_show = function() 
    {
        element = document.getElementById(this.invite_layer);
        element.style.display = "block";
    };


    this.lc_popup_close = function() 
    {
        this.lc_popup_hide();
        this.lc_logonImage = new Image;
        this.lc_logonImage.src = this.httpp + 'chat.link4.pl/tunnel.cgi?IWCS0014C^inviterefused^S1283955770.b4a5728119^$^'+"&rand=" + Math.floor(Math.random() * 1000);
    };


    this.lc_open_chat = function() 
    {
        this.lc_popup_hide();
        var httpp = this.httpp;
        win = window.open(unescape('' + httpp + 'chat.link4.pl/licence/20379/open_chat.cgi?invite=1&lang=pl&groups=0') + '&dc=' + escape(document.cookie + ';l=' + document.location + ';r=' + document.referer + ';s=' + typeof lc_session), 'Chat', 'width=784,height=510,resizable=0,scrollbars=0,status=1');
    };

    this.DomReadyMonitoring = function()
    {
       LC_Invite.drawInvite();
       /*
       if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null)) {
          LC_Invite.drawInvite();
       } else {
          setTimeout("LC_Invite.DomReadyMonitoring()", 200);
       }
       */
    };

}

function lc_animate(id, sx, sy)
{
	var d = LC_Invite.d;
	var ns = LC_Invite.ns;
        var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};

	el.floatIt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.floatIt()", 30);
	}
	return el;
}


function __addOnload(myfunc)
{
  if(window.addEventListener){
     window.addEventListener('load', myfunc, false);
  } else if(window.attachEvent){
    window.attachEvent('onload', myfunc);
  }
}

function lc_load_invite()
{
	return LC_Invite.lc_load_invite();
}

var LC_Invite = new LivechatInvite();
__addOnload(LC_Invite.DomReadyMonitoring);
