// GuideChat  - ver. 2.0
// Work with cookies
// Copyright(c) 2008 WaveAccess, http://wave-access.com

var sWindowParams = 'width=400,height=370,toolbar=0,left=300,top=400';

var sGuestJid = 'guest_86a6319cc13ef752d1ae67';
var sJabberServer = '70.38.112.42';

function clickCounter(){    
    renderButton(presence, jid);
}

function renderButton(status, jid){
    if (jid != sGuestJid)  
        status='offline';    
    try{    
        if (status == 'online'){
	    var obj = document.getElementById("chatOnlineButtonDiv");
	    var chatBtn = document.createElement('IMG');
	    chatBtn.id = 'chatBtn';
	    chatBtn.src = '/img/btnonline_normal.png';
            chatBtn.onclick = Chat;
            chatBtn.style.cssText = "cursor:pointer;";
	    obj.onmouseover= handleOver; 
	    obj.onmouseout= handleOut; 
        }
    obj.appendChild(chatBtn);
    }
    catch(err){}
}

function handleOver(e)
{
    var chatBtn = document.getElementById("chatBtn");
    chatBtn.src = '/img/btnonline_hover.png';
}

function handleOut(e)
{
    var chatBtn = document.getElementById("chatBtn");
    chatBtn.src = '/img/btnonline_normal.png';
}

function Chat(){
	try{
		//setCookie(-1);
		//CloseChatDiv();
		window.open('/GuideChat/gc.html','new','width=460,height=450,toolbar=0, left=300,top=400');
	}
 	catch(err){}
}

//Following code checks if DOM is loaded. 
///////////////////////////////////////////////////////////////////////
// thanks!:) original from http://dean.edwards.name/weblog/2005/10/add-event/
// with input from Tino Zijdel, Matthias Miller, Diego Perini, Tanny O'Haley, Hedger Wang
// Author: Dr. Dirk Fischer, Keln/Cologne, Germany : Tested with www.browsershots.org : thanks!
// Version 1.2
function addEvent(o, t, h) {
    var s = /chrome/i.test(navigator.userAgent) ? false
: window.execScript ? "i"
: /safari/i.test(navigator.userAgent) ? "s"
: document.clientWidth || window.opera && !window.getSelection ? "k"
: document.addEventListener ? false : "o",
d = "DOMContentLoaded";
    if (t.toLowerCase() == "load") o = initLoad(o, s);
    if (!o) return false;
    if (o.addEventListener && !(s && t == d)) o.addEventListener(t, h, false);
    else {
        if (!h.$$guid) h.$$guid = addEvent.guid++;
        if (!o.evs) o.evs = {};
        var hs = o.evs[t];
        if (!hs) { hs = o.evs[t] = {}; if (o['on' + t]) hs[0] = o['on' + t]; }
        hs[h.$$guid] = h; o['on' + t] = handleEvent;
        if (t == d && addEvent.waitDOM == -1) initDOMLoad(o, h, s);
    }
    function initLoad(o, s) {
        if (o && (o == window || o == document || o == document.body)) {
            if (s == "k") o = document;
            else element = window;
            if (!addEvent.waitLoad && s && s != "k" && s != "s") {
                if (document.ids) document.tags.body.position = "absolute";
                addEvent.waitLoad = true;
                addEvent(o, 'load', function() { addEvent.waitLoad = false; });
                (function() {
                    if (addEvent.waitLoad) {
                        var o = document.body;
                        if (!testLoad(o) && !testLoad((o = document)) & !testLoad((o = window)))
                            setTimeout(arguments.callee, 10); else { addEvent(o, 'load', o.onload); o.onload = handleEvent; } 
                    }
                })();
            } 
        } return o;
    }
    function testLoad(o) { return !o || typeof o.onload != "function" || o.onload == handleEvent ? false : true; }
    function initDOMLoad(o, h, s) {
        addEvent.waitDOM = true;
        if (s == "s" || s == "k")
            (function() {
                if (addEvent.waitDOM) {
                    if (/loaded|complete/i.test(document.readyState))
                        doDOMLoad(); else setTimeout(arguments.callee, 10);
                } 
            })();
        else if (s == "i")
            (function() {
                if (addEvent.waitDOM) {
                    /*@cc_on@*//*@if (@_win32 || @_win64)
                    var e = document.createElement('doc:rdy');
                    try { e.doScroll('left'); e = null; doDOMLoad(); } catch (err) { setTimeout(arguments.callee, 10); }
                    @end@*/
                } 
            })();
        else addEvent(o, "load", h);
    }
    function doDOMLoad() { var t = "DOMContentLoaded"; addEvent.waitDOM = false; (window["on" + t])({ "type": t }); }
}
addEvent.guid = 1;
addEvent.waitDOM = -1;
function removeEvent(o, t, h) {
    if (o.removeEventListener) o.removeEventListener(t, h, false);
    else if (o.evs && o.evs[t] && h.$$guid) delete o.evs[t][h.$$guid];
}
function handleEvent(ev) {
    var r = true;
    ev = ev || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
    var hs = this.evs[ev.type];
    for (var i in hs) {
        this.$$h = hs[i];
        if (this.$$h(ev) === false) r = false;
    }
    if (this.$$h) this.$$h = null;
    return r;
}
function fixEvent(ev) {
    if (ev) { ev.preventDefault = fixEvent.preventDefault; ev.stopPropagation = fixEvent.stopPropagation; }
    return ev;
}
fixEvent.preventDefault = function() { this.returnValue = false; }
fixEvent.stopPropagation = function() { this.cancelBubble = true; }
///////////////////////////////////////////////////////////////////////

addEvent(window, 'DOMContentLoaded', clickCounter);
