﻿String.prototype.namespace=function(separator){var ns = this.split(separator||'.'),p=window;for(i=0;i<ns.length;i++){p=p[ns[i]]=p[ns[i]]||{};}};

"Tracker.Client".namespace();

var theObj = null;

// any Internet Explorer
var isMSIE = /*@cc_on!@*/false;

// Init - called from the client html page
Tracker.Client.Init = function(AppKey) {
    window.onload = function() {
        Tracker.Client.isDebug = false;

        try {
            // check for preview mode
            if (Tracker.Client.getUrlParam('mc_prv') == 1)
                return;

            Tracker.Client.baseUrl = 'http://cp.getpoint.co.il';
            Tracker.Client.debugMsg('init');

            Tracker.Client.appKey = AppKey;
            Tracker.Client.lastMsgId = 0;
            Tracker.Client.interval = 7000;     // poll messages interval
            Tracker.Client.intervalId = null;

            Tracker.Client.EnterPage();
            Tracker.Client.bFirst = true;       // first time flag (for messages)
            Tracker.Client.bFirstMsgRecieved = false;
            Tracker.Client.lstMsgNick = '';


            // Session keep-alive variables

            //Number of Reconnects
            Tracker.Client.reconnect_count = 0;
            // session timeout in miliseconds
            Tracker.Client.milisecTimeout = 0;
            //Maximum reconnects setting
            Tracker.Client.reconnect_max = 50;

            Tracker.Client.bUserRespondedAutoChat = false;

            Tracker.Client.initWndFocus();

            Tracker.Client.cancelEsc();

        }
        catch (e) { }
    }
}

Tracker.Client.hideInitMsgDiv = function()
{
    try
    {
        var initMsgDiv = document.getElementById('gp_initMsgDiv');
        var MsgsDiv = document.getElementById('gp_msgDiv');
        
        if (initMsgDiv == null || MsgsDiv == null ||
            initMsgDiv == undefined || MsgsDiv == null)
            return;
        
        initMsgDiv.style.display = 'none';
        MsgsDiv.style.display = 'block';

    }
    catch(e)
    {
    
    }
}

Tracker.Client.showInitMsgDiv = function()
{
    try
    {
        var initMsgDiv = document.getElementById('gp_initMsgDiv');
        var MsgsDiv = document.getElementById('gp_msgDiv');
        
        if (initMsgDiv == null || MsgsDiv == null ||
            initMsgDiv == undefined || MsgsDiv == null)
            return;
        
        initMsgDiv.style.display = 'block';
        MsgsDiv.style.display = 'none';

    }
    catch(e)
    {
    
    }
}

Tracker.Client.fixIEWdgtPos = function()
{
    return;
    
    
    if (!isMSIE)     // if internet explorer ...
        return;
    
    // get the chat widget
    var wgdt = document.getElementById('chat_w');
    if (wgdt == null)
        return;
 
    wgdt.style.right = "auto";
    wgdt.style.bottom = "auto";
    wgdt.style.left = ( -20 - chat_w.offsetWidth + ( document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth ) + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + 'px';
    wgdt.style.top =  ( -10 - chat_w.offsetHeight + ( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px';
}

Tracker.Client.debugMsg = function(msg)
{
    if (Tracker.Client.isDebug)
        alert(msg);
}

Tracker.Client.EnterPage = function()
{
    try
    {
        // check if we have a visitor id cookie
        Tracker.Client.visitorId = Tracker.Client.getVIdCookie();
    
        var strReq = Tracker.Client.baseUrl + '/Handlers/Controller.ashx?jsonp=Tracker.Client.EnterPageCallback&Url=' + 
        escape(document.location) + '&key=' + Tracker.Client.appKey + '&ref=' + escape(document.referrer) + '&a=enter';

        if (Tracker.Client.visitorId > 0)
            strReq += "&vid=" + Tracker.Client.visitorId;

        var obj = new JSONscriptRequest(strReq);
      
        obj.buildScriptTag(); // Build the script tag     
      
        obj.addScriptTag(); // Execute (add) the script tag
      
        theObj = obj;
    }
    catch(e) { }
}

Tracker.Client.EnterPageCallback = function(visitorId,
                                            widget /*, cForm*/,
                                            state,
                                            lst_msg,
                                            miliSecReconnect,
                                            chatIcon,
                                            isRtl,
                                            autoAdTxt,
                                            autoAdDelay,
                                            autoAdNav,
                                            autoAdId,
                                            isAutoChat,
                                            ACSeconds) {
    try {
        Tracker.Client.debugMsg('EnterPageCallback. visitorId: ' + visitorId);

        // set variables
        Tracker.Client.visitorId = visitorId;
        Tracker.Client.widget = widget;
        Tracker.Client.vstate = state;
        Tracker.Client.lastMsgId = lst_msg;
        Tracker.Client.cForm = null;  //cForm;
        Tracker.Client.cFormVisible = false;
        Tracker.Client.isRtl = isRtl;
        Tracker.Client.isUserOnline = false;
        Tracker.Client.isAutoChat = isAutoChat;

        // keep session alive
        Tracker.Client.milisecTimeout = miliSecReconnect;

        // Restore the chat widget state - client side (min/max/hide/collapse)
        Tracker.Client.restoreChatState();

        // set the poll interval by visitor state
        Tracker.Client.ChangeVState(Tracker.Client.vstate);

        // Set the automatic ad timeout
        if (autoAdDelay != undefined && autoAdDelay != null && autoAdDelay > 0 &&
            autoAdTxt != undefined && autoAdTxt != null &&
            autoAdTxt.c != undefined && autoAdTxt.c != null &&
            autoAdTxt.c.trim() != '') {
            try {
                autoAdTxt.navUrl = autoAdNav;
                setTimeout(
                    function() {
                        if (!Tracker.Client.getAdCookie(autoAdId)) {
                            Tracker.Client.showAd(autoAdTxt, false);
                            Tracker.Client.setAdCookie(autoAdId);
                        }
                    }, autoAdDelay * 1000);
            }
            catch (e) {
                Tracker.Client.debugMsg('set auto ad: ' + e.message);
            }
        }

        try {
            Tracker.Client.setVIdCookie();
        }
        catch (ex)
        { }

        // Set chat Icon
        if (chatIcon != null && chatIcon != undefined && document.getElementById('chatIcon') != null)
            document.getElementById('gp_chatIcon').innerHTML = chatIcon;

        if (Tracker.Client.isAutoChat && Tracker.Client.getAgentCookie() == null)
            Tracker.Client.initAutoChat(ACSeconds);

        Tracker.Client.get_contact_form();

        // start listening for new messages from the server
        Tracker.Client.CheckMsgs();


        ///setTimeout(Tracker.Client.contact_form, 1000);

        //Tracker.Client.JQInject();
    }
    catch (e) { }
}

Tracker.Client.initAutoChat = function(ACSeconds) {


    var delayMs = ACSeconds * 1000;
    
    setTimeout(Tracker.Client.setAgentCookie, delayMs);

    // send a _startup message three times
    setTimeout(Tracker.Client.sendAutoChatInitMsg, delayMs);
    setTimeout(Tracker.Client.sendAutoChatInitMsg, delayMs + 8000);
    setTimeout(Tracker.Client.sendAutoChatInitMsg, delayMs + 14000);
}

Tracker.Client.sendAutoChatInitMsg = function() {
    if (Tracker.Client.bUserRespondedAutoChat == false)
        Tracker.Client.sendMsg("_startup"); 
}

// Check if enter was pressed. If it was - send the message
Tracker.Client.CheckSend = function(control, e) {
    try {
        if (window.event) {
            keynum = e.keyCode;
        }
        else if (e.which) {
            keynum = e.which;
        }
        if (keynum == 13) {
            if (control.value.trim().length > 0) {
                
                Tracker.Client.bUserRespondedAutoChat = true;
                Tracker.Client.sendMsg(control.value);

                control.value = "";
                control.focus();
                return (false);
            }
        }
    }
    catch (e) { }
}



Tracker.Client.sendMsg = function(msgText) {

    var strReq = Tracker.Client.baseUrl + '/Handlers/Controller.ashx?jsonp=Tracker.Client.sendMsgClbck&key=' +
       Tracker.Client.appKey + '&msg=' + encodeURI(msgText) + '&a=send' + '&vid=' + Tracker.Client.visitorId;

    // Visitor sends a messages
    var obj = new JSONscriptRequest(strReq);

    obj.buildScriptTag(); // Build the script tag     

    obj.addScriptTag(); // Execute (add) the script tag

    theObj = obj;
}

Tracker.Client.sendMsgClbck = function(msg)
{
    try
    {
        var arr = new Array();
        arr[0] = msg;
        
        Tracker.Client.parseMsgs(arr);
        
        var oldVState = Tracker.Client.vstate;
        
        if (Tracker.Client.vstate != 'c')
        {
            if (Tracker.Client.vstate == 'Chatting:u_close' || Tracker.Client.vstate == 'u:u_close')
                Tracker.Client.vstate = Tracker.Client.vstate + '_msg';
            else
                if (Tracker.Client.vstate == 'u')
                    Tracker.Client.vstate = 'c';
                else
                    if (Tracker.Client.vstate != 'v' &&
                        Tracker.Client.vstate != 'VisitorLeft')    // don't update the visitor state if the visitor requested to chat and sent another message
                        // Change visitor state to 'c' if it is not already
                        Tracker.Client.vstate = 'v';

            if (Tracker.Client.vstate != oldVState)
            {
                Tracker.Client.debugMsg('Tracker.Client.updVState - 4. from: ' + oldVState + ' to: ' + Tracker.Client.vstate);

                // Update the visitor state on the server
                Tracker.Client.updVState();
            }
        }
    }
    catch(e) { }
}

// change visitor state on server by client visitor state
Tracker.Client.updVState = function()
{
//alert('Tracker.Client.updVState(' + Tracker.Client.vstate + ')');

    try
    {
	    // update the visitor state on server
	    var obj = new JSONscriptRequest(Tracker.Client.baseUrl + '/Handlers/Controller.ashx?jsonp=Tracker.Client.updVStateClbk&key=' +
                      Tracker.Client.appKey + '&a=u_vstate' + '&vstate=' + Tracker.Client.vstate + '&vid=' + Tracker.Client.visitorId);  

        obj.buildScriptTag(); // Build the script tag     

        obj.addScriptTag(); // Execute (add) the script tag

        theObj = obj;
    }
    catch(e) { }
}

Tracker.Client.updVStateClbk = function(response)
{
    try
    {
        // set the poll interval by visitor state
        Tracker.Client.ChangeVState(Tracker.Client.vstate);
    }
    catch(e)
    {
    
    }
}

// Restore the chat widget state - client side
Tracker.Client.restoreChatState = function() {
    Tracker.Client.showChatWidget();

    try {
        switch (Tracker.Client.vstate) {
            case "c":
            case "u":
            case "v":
            case "e":
                Tracker.Client.hideInitMsgDiv();
                break;
            case "b":
                break;
            default:
                break;
        }
    }
    catch (e) { }

    try {
        var wcookie = Tracker.Client.getWStateCookie();

        if (wcookie == null) {
            // minimize the chat widget
            //Tracker.Client.onToggleChat(null);
            
            Tracker.Client.collapseWdgt();
            //Tracker.Client.setWStateCookie('min');
        }
        else {
            if (wcookie == 'min')
                Tracker.Client.collapseWdgt();
            else
                Tracker.Client.expandWdgt();
            //Tracker.Client.onToggleChat(null);
        }
    }
    catch (e) {

    }
}

Tracker.Client.CheckMsgs = function()
{
    try
    {
        Tracker.Client.debugMsg("CheckMsgs");
    
        var obj = new JSONscriptRequest(Tracker.Client.baseUrl + '/CometAsync/CometAsync/CometAsyncHandler.ashx?jsonp=Tracker.Client.handleMsgs&key=' +
        Tracker.Client.appKey + '&lmsg=' + Tracker.Client.lastMsgId + '&vid=' + Tracker.Client.visitorId);     

        // Debug
        //Tracker.Client.debugMsg(Tracker.Client.baseUrl + '/CometAsync/CometAsync/CometAsyncHandler.ashx?jsonp=Tracker.Client.handleMsgs&key=' +
        //Tracker.Client.appKey + '&lmsg=' + Tracker.Client.lastMsgId + '&vid=' + Tracker.Client.visitorId);

        obj.buildScriptTag(); // Build the script tag     

        obj.addScriptTag(); // Execute (add) the script tag

        theObj = obj;
      
        Tracker.Client.setVIdCookie();
        
        //setInterval('window.status=" "' ,200);
        window.status = ' ';
      
    }
    catch(e) 
    { 
        //setTimeout(Tracker.Client.CheckMsgs, Tracker.Client.interval);
        Tracker.Client.debugMsg("CheckMsgs: " + e);
    }
}
 
Tracker.Client.removeScript = function()
{
    try
    {
        theObj.removeScriptTag();
    }
    catch(e) { }
}

Tracker.Client.handleMsgs = function(msgs)
{
    try
    {  
        Tracker.Client.debugMsg('handleMsgs');
    
        Tracker.Client.parseMsgs(msgs);
        
        if (Tracker.Client.bFirst == true)
            // fix scroll to bottom when moving from page to page
            setTimeout(Tracker.Client.fixFirstScroll, 500);
        
        Tracker.Client.bFirst = false;

        Tracker.Client.removeScript();
        
        // set the poll interval by visitor state
        Tracker.Client.ChangeVState(Tracker.Client.vstate);

        try {
//            if (Tracker.Client.isFocused) 
//                document.getElementById('gp_txtMessage').focus(); 
        } 
        catch(e) 
        { }

        Tracker.Client.CheckMsgs();
    }
    catch(e) 
    { 
        Tracker.Client.debugMsg("handleMsgs: " + e);
    }
}

Tracker.Client.scrollBottom = function() {
    try {
        var msgDiv = document.getElementById('gp_msgDiv');
        if (msgDiv != null)
            if (msgDiv.scrollHeight > 0)
                msgDiv.scrollTop = msgDiv.scrollHeight;
            else if (msgDiv.offsetHeight > 0)
                msgDiv.scrollTop = msgDiv.offsetHeight;
    }
    catch (e) {

    }
}


Tracker.Client.fixFirstScroll = function() {
    // fix scroll to bottom when moving from page to page
    try {
        if (document.getElementById('gp_msgDiv') != null)
            if (document.getElementById('gp_msgDiv').scrollHeight > 0)
            document.getElementById('gp_msgDiv').scrollTop = document.getElementById('gp_msgDiv').scrollHeight;
        else if (document.getElementById('gp_msgDiv').offsetHeight > 0)
            document.getElementById('gp_msgDiv').scrollTop = document.getElementById('gp_msgDiv').offsetHeight;
    }
    catch (e) {

    }
}

Tracker.Client.parseMsgs = function(msgs) {

    // no messages
    if (msgs == null || msgs == undefined)
        return;

    try {
        Tracker.Client.debugMsg('parseMsgs: length: ' + msgs.length);

        // iterate all messages recieved
        for (var i = 0; i < msgs.length; i++) {

            // if we didn't parse it yet
            if (msgs[i].id > Tracker.Client.lastMsgId) {
                // a new text message
                if (msgs[i].type == 'txt') {

                    // show the messages div
                    Tracker.Client.hideInitMsgDiv();

                    if (Tracker.Client.getWStateCookie() == 'min' && Tracker.Client.bFirst != true) {

                        // exapnd the chat widget when:
                        //   1. the visitor did not minimized the widget
                        // the widget is minimized at the start, by default

                        if (Tracker.Client.bFirstMsgRecieved == false) {
                            Tracker.Client.expandWdgt();
                            Tracker.Client.bFirstMsgRecieved = true;
                        }
                        else
                        // expand the chat widget when recieving a new message
                        //Tracker.Client.onToggleChat();
                            Tracker.Client.blinkTitle();
                    }
                    // first time (when entering the page)
                    if (Tracker.Client.bFirst == true && Tracker.Client.vstate == "e")
                    { }
                    else {
                        // not the first time we read message (when entering the page)
                        // or - chat state is not "chat ended"

                        if (msgs[i].from.left(1) == "u") {

                            Tracker.Client.showChatWidget();

                            switch (Tracker.Client.vstate) {
                                case "b":
                                case "e":
                                    Tracker.Client.vstate = "u";

                                    Tracker.Client.debugMsg('Tracker.Client.updVState - 5');

                                    Tracker.Client.updVState();
                                    break;
                                case "v":
                                    if (Tracker.Client.bFirst == false) {
                                        Tracker.Client.debugMsg('Tracker.Client.updVState - 6');

                                        Tracker.Client.vstate = "c";
                                        Tracker.Client.updVState();
                                    }
                                    break;
                                case "c":
                                case "u":
                                default:
                                    break;
                            }

                            // set the poll interval by visitor state
                            Tracker.Client.ChangeVState(Tracker.Client.vstate);
                        }
                    }

                    // add the text message to the list
                    Tracker.Client.addMsg(msgs[i]);
                }

                // new ad from server
                if (msgs[i].type == 'ad') {
                    if (Tracker.Client.bFirst != true)  // first time do nothing
                    {
                        Tracker.Client.showAd(msgs[i],false);
                    }
                }

                // new chat request from server
                if (msgs[i].type == 'v') {
                    if (Tracker.Client.bFirst != true)  // first time do nothing
                    {
                        Tracker.Client.showChatWidget();
                    }
                }

                // new popup request from server
                if (msgs[i].type == 'pop') {
                    if (Tracker.Client.bFirst != true)  // first time do nothing
                    {
                        window.open(msgs[i].u, 'ad');
                    }
                }

                // presence notification
                if (msgs[i].type.left(2) == 'pr') {
                    Tracker.Client.onPrMsg(msgs[i]);
                }
            }
            // save last message id
            if (msgs[i].id > Tracker.Client.lastMsgId)
                Tracker.Client.lastMsgId = msgs[i].id;

        }
    }
    catch (e) {
        Tracker.Client.debugMsg("parseMsgs: " + e);
    }
}

// parse the nick name of a message sender
Tracker.Client.parseNick = function(SentBy)
{
    try
    {
        switch(SentBy)
        {
            case 'v':
                if (Tracker.Client.isRtl)
                    return ('אני');
                return ('me');
                break;
            case 's':
                if (Tracker.Client.isRtl)
                    return ('הודעת מערכת');
                else
                    return ('system');
                break;
            default:    // supposed to be a user
                var nick = SentBy;
                var snt_by_arr = SentBy.split(":");
                if (snt_by_arr.length > 1)
                    nick = snt_by_arr[1];
                if (nick.length == 0)
                    nick = 'נציג';
                return (nick);
                break;
        }
    }
    catch(e) { }

}

// Change the visitor state (browsing/chatting/waitingToChat/ChatReq)
Tracker.Client.ChangeVState = function(newState)
{
    var bPrevInterval = Tracker.Client.interval;
    
    try
    { 
        switch (newState)
        {
            case "c":
            case "u":
            case "v":
                Tracker.Client.interval = 2000;
                break;
            case "b":
                Tracker.Client.interval = 7000;
                break;
            default:
                Tracker.Client.interval = 7000;
                break;
        }
        
        // re-set timer interval
        if (bPrevInterval != Tracker.Client.interval)
        {
            if (Tracker.Client.intervalId != null)
            {
                clearInterval (Tracker.Client.intervalId);
            }
        }
        
    }
    catch(e) { }
}

Tracker.Client.addMsg = function(msg) {
    try {

        if (msg.txt.trim().length <= 0)
            return;

        var d = new Date();
        var curr_hour = d.getHours() + '';
        if (curr_hour.length == 1)
            curr_hour = '0' + curr_hour;
        var curr_min = d.getMinutes() + '';
        if (curr_min.length == 1)
            curr_min = '0' + curr_min;

        var timStr = curr_hour + ":" + curr_min;

        // new
        if (msg.msgTime != undefined && msg.msgTime != null)
            timStr = msg.msgTime;

        var msgNick = Tracker.Client.parseNick(msg.from);
        var imgUrl = "http://cp.getpoint.co.il/images/bubble_blue.png";
        if (msg.from == 'v')
            imgUrl = "http://cp.getpoint.co.il/images/bubble_green.png";

        var msgUL = document.getElementById("gp_msgList");

        if (msgUL != null && msgUL != undefined) {

            var msgHdr = "<div style=\"font-weight:bold;color:#5C5B59; padding-bottom:3px;\"> \
									<img src=\"" + imgUrl + "\" width=\"17\" height=\"15\" alt=\"\" />  \
									" + msgNick + ": <div style=\"float:" + (Tracker.Client.isRtl?"left":"right") + "; color:#c4c2be;\">" + timStr + "</div></div>";

            if (Tracker.Client.lstMsgNick != msgNick) {

                Tracker.Client.lstMsgNick = msgNick;

                var Msg = "<div style=\"border-top:1px #71a040 solid; padding-top:5px; padding-bottom:3px;\"> \
								" + msgHdr + decodeURI(msg.txt) + " \
							</div>";

            }
            else {
                var Msg = "<div style=\"padding-top:5px; padding-bottom:3px;\"> \
								" + decodeURI(msg.txt) + " \
							</div>";

            }
            msgUL.innerHTML += '<li style="' + Tracker.Client.getMsgStyle(msg.from) + '">' + Msg + '</li>';

            // active scrolls message list
            if (Tracker.Client.divScroll != null)
                Tracker.Client.divScroll.activeScroll();
        }
    }
    catch (e) { }

    // external customer function
    try {
        if (Tracker.Client.OnMsgEx != null && Tracker.Client.OnMsgEx != undefined)
            Tracker.Client.OnMsgEx(msg, Tracker.Client.bFirst);
    }
    catch (e) {

    }
}

Tracker.Client.getMsgStyle = function(sentBy)
{
    var msgStyle = 'padding:0;';
    switch (sentBy)
    {
        case 's':
            msgStyle += 'color: #aaaaaa';
            break;
        default:
            break;
    }
    return (msgStyle);
}

Tracker.Client.onPrMsg = function(msg)
{
    Tracker.Client.debugMsg('onPrMsg: ' + msg.txt)

    // if pr:user_online or pr:user_offline
    // change the chat icon text
    // we can:
    // - get the two texts in the EnterPageCallback function, or
    // - send a message to the server to get the new html for the chat icon
    
    var arr_cmd = msg.type.split(":");
    
    if (arr_cmd.length > 1)
        cmd = arr_cmd[1];    // the pr command
    else    
        return;
    
    if (cmd == 'vstate')
    {
        if (Tracker.Client.bFirst != true)
        {
            Tracker.Client.debugMsg('new state = ' + msg.txt);
        
            if (msg.txt != "VisitorLeft")
                Tracker.Client.vstate = msg.txt;
            
            try
            {
                if (Tracker.Client.vstate == "e")
                {
                    msg.txt = "השיחה הסתיימה";
                    msg.from = "s";
                    Tracker.Client.addMsg(msg);
                
                    if (Tracker.Client.bFirst == false)
                    {
                        setTimeout(Tracker.Client.collapseWdgt, 2000);
                    }
                }
            }
            catch(e)
            {
            
            }
        }
    }
    else
        if (cmd == "ustate")
        {
            if (Tracker.Client.bFirst != true)
            {
                // User state (online or offline)
                if (msg.txt == "off")
                {
                    Tracker.Client.isUserOnline = false;
                    document.getElementById('gp_onMsgDiv').style.display = "none";
                    document.getElementById('gp_offMsgDiv').style.display = "block";
                }
                else
                    if (msg.txt == "on")
                    {
                        Tracker.Client.isUserOnline = true;
                        document.getElementById('gp_onMsgDiv').style.display = "block";
                        document.getElementById('gp_offMsgDiv').style.display = "none";
                    }
            }
        }
}

Tracker.Client.setWidgetPos = function(wgdt)
{
    if (wgdt == null || wgdt == undefined)
        return;

    wgdt.style.margin = '0';
    wgdt.style.padding = '0';
    wgdt.style.direction = 'ltr';   // TODO: ltr

    wgdt.style.position = 'fixed';
    wgdt.style.zIndex = '1000';
    wgdt.style._position = 'absolute';

    switch(Tracker.Client.widget.p)
    {
        case 'lt':
            wgdt.style.left = "10px";
            wgdt.style.top = "10px";
            break;
        case 'lb':
            wgdt.style.left = "10px";
            wgdt.style.bottom = "10px";
            // wgdt.style.direction = 'rtl';
            break;
        case 'rt':
            wgdt.style.right = "10px";
            wgdt.style.top = "10px";
            break;
        case 'rb':
            wgdt.style.right = "10px";
            wgdt.style.bottom = "10px";
            break;
        default:
            wgdt.style.right = "10px";
            wgdt.style.bottom = "10px";
            break;
    }

}

Tracker.Client.showChatWidget = function() {
    try {
        var bAnimate = false;

        Tracker.Client.debugMsg('showChatWidget');

        var wgdt = document.getElementById('chat_w');

        // create the chat widget
        if (wgdt == null || wgdt == undefined) {
            bAnimate = true;

            wgdt = document.createElement('div');
            wgdt.id = 'chat_w';
            try {
                wgdt.style.borderWidth = '1px';
                wgdt.style.borderStyle = 'none';
                wgdt.style.width = '270px';
                wgdt.style.borderColor = 'black';
            }
            catch (e) {
            }

            wgdt.style.display = 'none';

            wgdt.innerHTML = Tracker.Client.widget.c;
            document.body.appendChild(wgdt);
            
            
            //Tracker.Client.collapseWdgt();

            // for auto-scrolling messages
            Tracker.Client.divScroll = new chatscroll.Pane('gp_msgDiv');
        }
        else {
            if (wgdt.style.display == 'none')
                bAnimate = true;
        }

        if (wgdt == null || wgdt == undefined)
            return;


        Tracker.Client.setWidgetPos(wgdt);

        // THIS ANIMATION IS WORKING
        // animate only when showing the widget for the first time on a page
        if (bAnimate) {
            if (isMSIE)
                wgdt.style.display = 'block';
            else
                opacity('chat_w', 0, 100, 500);
        }
    }
    catch (e) {
        Tracker.Client.debugMsg('showChatWidget: ' + e.message);
    }
}

Tracker.Client.addCss = function(cssCode) {
    
    var styleElement = document.createElement("style");
    
    styleElement.type = "text/css";

    if (styleElement.styleSheet) {
        styleElement.styleSheet.cssText = cssCode;
    } 
    else 
    {
        styleElement.appendChild(document.createTextNode(cssCode));
    }
    document.getElementsByTagName("head")[0].appendChild(styleElement);
}

Tracker.Client.collapseWdgt = function() {
    
    Tracker.Client.onToggleChat('min');

    /*var wcookie = Tracker.Client.getWStateCookie();

    // If no widget-state cookie - minimize the widget
    if (wcookie == null)
    {
        // minimize the chat widget
        Tracker.Client.onToggleChat('min');
        Tracker.Client.setWStateCookie('min');
    }
    else // if there is a widget-state cookie
    {
        // if the widget state is maximized - collpase it
        if (wcookie == 'max')
            Tracker.Client.onToggleChat(null);
    }*/
}

Tracker.Client.expandWdgt = function() {

    Tracker.Client.onToggleChat('max');

    Tracker.Client.scrollBottom();
    
    /*var wcookie = Tracker.Client.getWStateCookie();

    if (wcookie == null)
    {
    // minimize the chat widget
    Tracker.Client.setWStateCookie('max');
    }
    else
    {
    if (wcookie == 'min')
    Tracker.Client.onToggleChat(null);
    }*/
}

Tracker.Client.onToggleChat = function(newState) {

    var gOpened = document.getElementById('gp_opened');
    var gClosed = document.getElementById('gp_closed');
    var imgAnt = document.getElementById('gp_imgAnt');

    if (gOpened == null || gClosed == null || imgAnt == null)
        return;

    switch (newState) {
        case 'min': // minimize the widget
            gOpened.style.display = 'none';
            gClosed.style.display = 'block';
            imgAnt.style.display = 'block';
            Tracker.Client.setWStateCookie('min');
            break;
        case 'max': // maximize the widget
            gOpened.style.display = 'block';
            gClosed.style.display = 'none';
            imgAnt.style.display = 'none';
            Tracker.Client.setWStateCookie('max');
            break;
        default:    // toggle the widget state
            // Expand the widget
            if (gOpened.style.display == 'none') {
                gOpened.style.display = 'block';
                gClosed.style.display = 'none';
                imgAnt.style.display = 'none';
                newState = 'max';
                Tracker.Client.setWStateCookie('max');
                Tracker.Client.scrollBottom();
            }
            else {
                // Collapse the widget
                gOpened.style.display = 'none';
                gClosed.style.display = 'block';
                imgAnt.style.display = 'block';
                newState = 'min';
                Tracker.Client.setWStateCookie('min');
            }
            break;
    }

    // call external event handler
    try {
        if (Tracker.Client.onToggleChatEx != undefined && Tracker.Client.onToggleChatEx != null)
            Tracker.Client.onToggleChatEx(newState);

    }
    catch (e)
    { }

    return;

    var cbody = document.getElementById('ChatBody');
    var cfootr = document.getElementById('chatFooter');
    var toggleBtn = document.getElementById('gpToggle');
    var imgAnt = document.getElementById('gp_imgAnt');

    if (cbody == null || cfootr == null || toggleBtn == null || imgAnt == null)
        return;

    // expand
    if (cbody.style.display == 'none') {
        toggleBtn.innerHTML = "_";
        cbody.style.display = 'block';
        imgAnt.style.display = 'none';

        Tracker.Client.setWStateCookie('max');
    }
    else    // collapse
    {
        toggleBtn.innerHTML = "^";
        cbody.style.display = 'none';
        imgAnt.style.display = 'block';

        Tracker.Client.setWStateCookie('min');
    }

    if (cfootr.style.display == 'none')
        cfootr.style.display = 'block';
    else
        cfootr.style.display = 'none';

    toggleBtn.blur();
}
onToggleChat = Tracker.Client.onToggleChat;


// visitor closes the chat widget (presses the x sign)
Tracker.Client.onCloseChat = function() {
    try {
        Tracker.Client.debugMsg('onCloseChat');

        // hide the chat widget
        Tracker.Client.hideChatWidget();

        if (Tracker.Client.vstate != "e") {

            Tracker.Client.vstate = "e";
            // set the poll interval by visitor state
            Tracker.Client.ChangeVState(Tracker.Client.vstate);

            // send a system message
            var obj = new JSONscriptRequest(Tracker.Client.baseUrl + '/Handlers/Controller.ashx?jsonp=Tracker.Client.closeChatClbck&key=' +
                  Tracker.Client.appKey + '&a=close_chat' + '&vid=' + Tracker.Client.visitorId);

            obj.buildScriptTag(); // Build the script tag     

            obj.addScriptTag(); // Execute (add) the script tag

            theObj = obj;
        }

        try {
            if (Tracker.Client.onCloseChatEx != undefined && Tracker.Client.onCloseChatEx != null)
                Tracker.Client.onCloseChatEx();

        }
        catch (e)
        { }
    }
    catch (e) { }
}

Tracker.Client.closeChatClbck = function()
{
    try
    {
        // do nothing, only remove the script tag
        Tracker.Client.removeScript();
    }
    catch(e) { }
}

Tracker.Client.hideChatWidget = function() {
    try {
        var wgdt = document.getElementById('chat_w');

        // create the chat widget
        if (wgdt != null && wgdt != undefined) {
            if (wgdt.style.opacity != '0') {
                //opacity('chat_w', 100, 0, 500);
                wgdt.style.opacity = '0';
                wgdt.style.display = 'none';
            }
        }
    }
    catch (e) { }
}

//Tracker.Client.showcForm = function()
//{
//    try
//    {    
//        var cFormUrl = Tracker.Client.baseUrl + '/UI/ControlPanel/Visitor/ContactForm.aspx?app=' + Tracker.Client.appKey;
//    
//        var w = window.open(cFormUrl, "ContactFor","location=1,alwaysRaised=1,menubar=0,toolbar=0,status=0,resizable=1,scrollbars=0,width=780,height=548");
//    }
//    catch(e)
//    {
//    
//    }
//}

Tracker.Client.getvStateBase = function()
{
    var st_arr = Tracker.Client.vstate.split(":");
    if (st_arr.length > 1)
        return(st_arr[0]);
    else
        return (Tracker.Client.vstate);
}

Tracker.Client.onChatIconClick = function()
{
    Tracker.Client.showChatWidget();
    
    var vStateBase = Tracker.Client.getvStateBase();
    
    if (vStateBase != 'c' && 
        vStateBase != 'v' && 
        vStateBase!= 'u')
    {
        Tracker.Client.debugMsg('Tracker.Client.updVState - 3');
    
        Tracker.Client.vstate = 'v';
        Tracker.Client.updVState();
        
        // set the poll interval by visitor state
        Tracker.Client.ChangeVState(Tracker.Client.vstate);

    }
}

//Tracker.Client.cancelCForm = function()
//{
//    try
//    {
//        // TODO: Change
//        Tracker.Client.removeAd();
//    }
//    catch(e) { }
//}

Tracker.Client.submitCForm = function(name,company,cellphone,email,phone,comments) {
//cform_submit
    try {
        Tracker.Client.collapseWdgt();

        // get cform
        var obj = new JSONscriptRequest(Tracker.Client.baseUrl + '/Handlers/Controller.ashx?jsonp=Tracker.Client.handlCForm&key=' +
                              Tracker.Client.appKey + '&a=cform_submit&vid=' + Tracker.Client.visitorId +
                              '&name=' + name + '&company=' + company + '&cellphone=' + cellphone +
                              '&email=' + email + '&phone=' + phone + '&comments=' + comments);

        obj.buildScriptTag(); // Build the script tag     

        obj.addScriptTag(); // Execute (add) the script tag

        theObj = obj;
    }
    catch (e) { }

    // external event handler
    try {
        if (Tracker.Client.onSubmitCFormEx != undefined && Tracker.Client.onSubmitCFormEx != null)
            Tracker.Client.onSubmitCFormEx();

    }
    catch (e)
        { }

}
Tracker.Client.sendCForm = function() {

    var name = '';
    var company = '';
    var cellphone = '';
    var email = '';
    var phone = '';
    var comments = '';

    try {
        name = document.getElementById('gp_cform_name').value;
    }
    catch (e)
    { }
    try {
        company = document.getElementById('gp_cform_company').value;
    }
    catch (e)
    { }
    try {
        cellphone = document.getElementById('gp_cform_cellphone').value;
    }
    catch (e)
    { }
    try {
        email = document.getElementById('gp_cform_email').value;
    }
    catch (e)
    { }
    try {
        phone = document.getElementById('gp_cform_phone').value;
    }
    catch (e)
    { }
    try {
        comments = document.getElementById('gp_cform_comments').value;
    }
    catch (e)
    { }

    if (name == null || name.trim() == '') {
        alert('נא הקלד את שם מלא');
        try { document.getElementById('gp_cform_name').focus(); } catch (e) { }
        return;
    }
    if (comments == null || comments.trim() == '') {
        alert('נא הקלד את הודעתך בשדה: הערות');
        try { document.getElementById('gp_cform_comments').focus(); } catch (e) { }
        return;
    }

    if (email != null && email.trim().length > 0) {
        if (!Tracker.Client.isEmailValid(email)) {
            alert('כתובת האימייל שהוקלדה אינה תקינה');
            try { document.getElementById('gp_cform_email').focus(); } catch (e) { }
            return;
        }
    }

    if ((email != null && email != '') || (phone != null && phone != '') || (cellphone != null && cellphone != '')) {

        Tracker.Client.removeAd();

        // send the message to the server
        Tracker.Client.submitCForm(name, company, cellphone, email, phone, comments);

        alert('הודעתך נשלחה');
    }
    else {
        try { document.getElementById('gp_cform_phone').focus(); } catch (e) { }
        alert('נא מלא אחד מפרטי ההתקשרות: טלפון, אימייל או טלפון נייד');
    }

    Tracker.Client.collapseWdgt();
    //    alert('send: ' + name + ',' + company + ',' + cellphone + ',' + email +
    //     ',' + phone + ',' + comments);

}

Tracker.Client.isEmailValid = function(str) {

    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    if (str.indexOf(at) == -1) {
        //alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
        //alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        //alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(at, (lat + 1)) != -1) {
        //alert("Invalid E-mail ID")
        return false
    }

    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        //alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(dot, (lat + 2)) == -1) {
        //alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(" ") != -1) {
        //alert("Invalid E-mail ID")
        return false
    }

    return true
}

Tracker.Client.contact_form = function() {
    try {
        Tracker.Client.collapseWdgt();

        Tracker.Client.createOverlay();

        if (Tracker.Client.cForm == null) {
            // get cform
            var obj = new JSONscriptRequest(Tracker.Client.baseUrl + '/Handlers/Controller.ashx?jsonp=Tracker.Client.handlCForm&key=' +
                              Tracker.Client.appKey + '&a=cform&vid=' + Tracker.Client.visitorId);

            obj.buildScriptTag(); // Build the script tag     

            obj.addScriptTag(); // Execute (add) the script tag

            theObj = obj;
        }
        else
            Tracker.Client.handlCForm(Tracker.Client.cForm);
    }
    catch (e) { }
}


Tracker.Client.get_contact_form = function() {
    try {
        if (Tracker.Client.cForm == null) {
            // get cform
            var obj = new JSONscriptRequest(Tracker.Client.baseUrl + '/Handlers/Controller.ashx?jsonp=Tracker.Client.getCFormClbk&key=' +
                              Tracker.Client.appKey + '&a=cform&vid=' + Tracker.Client.visitorId);

            obj.buildScriptTag(); // Build the script tag     

            obj.addScriptTag(); // Execute (add) the script tag

            theObj = obj;
        }
    }
    catch (e) { }
}

Tracker.Client.getCFormClbk = function(cform) {
    Tracker.Client.cForm = cform;

    // check if the script reference exists. if it's not - add it
    try {
        var cform_script = document.getElementById('gp_form_scr');
        if (cform_script == null) {
            // add the cform script
            if (cform.scr.length > 0) {
                var scrObj = document.createElement("script");
                scrObj.setAttribute("type", "text/javascript");
                scrObj.setAttribute("charset", "utf-8");
                scrObj.setAttribute("src", cform.scr);
                scrObj.setAttribute("id", "gp_form_scr");
                // Create the script tag
                document.getElementsByTagName("head").item(0).appendChild(scrObj);
            }
        }
    }
    catch (e)
    { }
}

Tracker.Client.handlCForm = function(cform) {

    Tracker.Client.cForm = cform;
    Tracker.Client.cFormVisible = true;

    //alert(cform.scr);
    
    Tracker.Client.showAd(cform, true);

}

Tracker.Client.showAd = function(ad, isCForm) {

    //alert('isCFormform = ' + isCForm + ' Tracker.Client.cFormVisible = ' + Tracker.Client.cFormVisible);

    // do not display ads while contact form is visible
    if (!isCForm && Tracker.Client.cFormVisible)
        return;

    Tracker.Client.debugMsg('showAd');

    if (ad == null || ad == undefined)
        return;

    try {
        try {
            Tracker.Client.removeAd(null);
            if (isCForm)
                Tracker.Client.cFormVisible = true;
        }
        catch (e) {
        }

        var pX = 15;
        var pY = 15;
        var startX = 0;
        var startY = 0;
        var xAlgn = 'center';
        var yAlign = 'middle';

        // create the div which wraps the ad (in order to position it)
        Tracker.Client.debugMsg('createElement');

        var newdiv = document.createElement('div');
        newdiv.setAttribute("id", "gp_ad");
        newdiv.setAttribute("style", "zoom:1;filter:alpha(opacity=0);opacity:0;position: absolute;float:none;border-collapse: collapse;");

        // get the top, left, right, bottom attributes
        // by the ad position attribute (ad.p)

        switch (ad.p) {
            case ('lt'):
                pX = 15; pY = 15;
                //xAlgn = 'left'; yAlign = 'top';
                newdiv.style.top = '15px';
                newdiv.style.left = '15px';
                break;
            case ('lb'):
                pX = 20; pY = -10;
                //xAlgn = 'left'; yAlign = 'bottom';
                newdiv.style.bottom = '15px';
                newdiv.style.left = '15px';
                break;
            case ('rt'):
                pX = -15; pY = 15;
                //xAlgn = 'right'; yAlign = 'top';
                newdiv.style.top = '15px';
                newdiv.style.right = '15px';
                break;
            case ('rb'):
                pX = -15; pY = -15;
                //xAlgn = 'right'; yAlign = 'bottom';
                newdiv.style.bottom = '15px';
                newdiv.style.right = '15px';
                break;
            case ('cc'):
                var cWidth = f_clientWidth();
                var cHeight = f_clientHeight();
                pX = cWidth / 2 - 150;
                pY = cHeight / 2 - 150;

                newdiv.style.left = pX + 'px';
                newdiv.style.top = pY + 'px';

                //xAlgn = 'none'; yAlign = 'middle';
                // calculate the ad position by the screen dimensions
                //newdiv.style.bottom = '15px';
                //newdiv.style.right = '15px';
                break;
            default:
                pX = 15; pY = -15;
                //xAlgn = 'none'; yAlign = 'middle';
                newdiv.style.bottom = '15px';
                newdiv.style.left = '15px';
                break;
        }

        // set the ad content
        //newdiv.innerHTML = '<table style="margin:10px;overflow:hidden;position: absolute;width:' + (f_clientWidth() - 20) + 'px;height:' + (f_clientHeight() - 20) + 'px;float:none;left:0;top:0;border-collapse: collapse;"><tr><td style="padding:0;vertical-align:' + yAlign + '"><table style="margin:auto;float:' + xAlgn + ';border-collapse:collapse"><tr><td id="gp_adWrap" style="padding:0;position:relative">' + Tracker.Client.getAdWrap(ad) + '</td></tr></table></td></tr>';
        newdiv.innerHTML = Tracker.Client.getAdWrap(ad);

        document.body.appendChild(newdiv);

        try {
            if (isCForm) {
                if (Tracker.Client.preShowCFormEx)
                    Tracker.Client.preShowCFormEx();
            }
        } catch (e)
        { }

        opacity('gp_ad', 0, 100, 3500);

        //addFloatLayer("gp_ad", 0, 0, 0, pY, 7);
        addFloatLayer("gp_ad", 0, 0, pX, pY, 7);

        getFloatLayer("gp_ad").initialize();
        alignFloatLayers();

        window.onscroll = alignFloatLayers;
        window.onresize = alignFloatLayers;

        try {
            if (isCForm) {
                if (Tracker.Client.postShowCFormEx)
                    Tracker.Client.postShowCFormEx();
            }
        } catch (e)
        { }


        // Log the AdShown event
        Tracker.Client.LogAdShown(ad.adId);
    }
    catch (e) {

    }
}

Tracker.Client.adCloseClicked = function() {
    try {
        // get the gp_ad top,left,right,bottom attributes
        // animate the ad position and decrease the top value

        if (document.getElementById('gp_ad') == null)
            return;

        removeFloatLayer('gp_ad');

        //var t = 15;
        var adStyle = document.getElementById('gp_ad').style;


        //adStyle.filter = "alpha(opacity=30)";

        // get ad top value
        var adTop = parseInt(adStyle.top);
        if (adTop == 0 || adTop == NaN || adTop == null)
            adTop = 0;

        for (var i = 1; i <= 20; i++) {

            setTimeout(function() {
                document.getElementById('gp_ad').style.top = adTop + 'px';
                adTop -= 5;
            }, i * 40);
        }

        opacity('gp_ad', 100, 0, 1000);
        Tracker.Client.removeOverlay();
        setTimeout(function() { Tracker.Client.removeAd();  }, 1000);
    }
    catch (e)
{ }
}

Tracker.Client.getAdWrap = function(ad) {
    var navUrl = (ad.navUrl != undefined && ad.navUrl != null ? ad.navUrl : '#');

    var imgClose = 'url(' + Tracker.Client.baseUrl + '/Images/close_r.png)';
    var imgCloseStyle = 'margin:-16px 0 0 0;top:40px;right:0;height:26px;width:30px;';
    if (ad.p) {
        if (ad.p == 'rt' || ad.p == 'rb') {
            imgClose = 'url(' + Tracker.Client.baseUrl + '/Images/close_l.png)';
            imgCloseStyle = 'margin:-16px 0 0 0;top:40px;left:0;height:26px;width:30px;';
        }
    }
    else {
        imgCloseStyle = 'margin:-16px 0 0 0;top:40px;right:0;height:26px;width:30px;';
    }

    var strWrap = '<div id="ad" style="background:transparent;filter:inherit;visibility: visible; position: relative;';
    strWrap += 'z-index: 10501;">';
    strWrap += '<div id="adWrap" style="padding-right:19px;padding-left:30px;position:relative;cursor: pointer;">';
    //    strWrap += '<div id="adClose" style="z-index: 10504;position:relative;margin:-16px 0 0 0;float:right;height:31px;width:34px; background: transparent url(' + Tracker.Client.baseUrl + '/Images/BUTTON2.png) no-repeat scroll right top;"';


    strWrap += '<div id="adClose" style="z-index: 10504;position:absolute;' + imgCloseStyle + ' background: transparent ' + imgClose + ' no-repeat scroll right top;"';

    //position:absolute;right:-8px;top:40px;width:30px;z-index:10504;
    strWrap += 'onclick="Tracker.Client.adCloseClicked()">&nbsp;</div>';
    strWrap += '<div id="adBody" onclick="Tracker.Client.redirectAd(' + ad.adId + ',\'' + navUrl + '\');" style="position: relative;border: none;z-index: 10501">';
    strWrap += ad.c;
    strWrap += '</div>';
    strWrap += '</div></div>';

    return (strWrap);
}

Tracker.Client.removeAd = function(content) {
    try {

        //alert('Tracker.Client.removeAd');
        Tracker.Client.cFormVisible = false;
        var adDiv = document.getElementById("gp_ad");
        if (adDiv)
            document.body.removeChild(adDiv);
    }
    catch (e) { }

}
Tracker.Client.createOverlay = function() {
    try {
        Tracker.Client.removeOverlay();
        // add overlay
        var overlay = document.createElement('div');
        overlay.id = 'gp_overlay';
        overlay.setAttribute('style', 'position:absolute;left:0;top:0;width:100%;height:' + f_scrollHeight() + 'px;filter:alpha(opacity=50);opacity: 0.5;-moz-opacity:0.5;background-color:#333333;');
        document.body.appendChild(overlay);
    }
    catch (e) { }
}

Tracker.Client.removeOverlay = function() {
    try {
        var overlay = document.getElementById("gp_overlay");
        if (overlay)
            document.body.removeChild(overlay);
    }
    catch (e) { }
}

Tracker.Client.redirectAd = function(adId, adUrl) {
    try {
        if (adUrl != undefined && adUrl != null && adUrl.trim() != '') {

            // Log the AdClick event in the server
            if (adId > 0)
                Tracker.Client.LogAdClick(adId);
            
            if ( adUrl != '#' && adUrl != '')
                // Open the url
                window.open(adUrl, "ad");
        }
    }
    catch (e) { }
}

Tracker.Client.LogAdClick = function(adId) {

var strReq = Tracker.Client.baseUrl + '/Handlers/Controller.ashx?jsonp=Tracker.Client.emptyClbk&key=' +
       Tracker.Client.appKey + '&a=ad_clicked' + '&adid=' + adId + '&vid=' + Tracker.Client.visitorId;

// Visitor sends a messages
var obj = new JSONscriptRequest(strReq);

obj.buildScriptTag(); // Build the script tag     

obj.addScriptTag(); // Execute (add) the script tag

theObj = obj;

}

Tracker.Client.LogAdShown = function(adId) {

    if (adId == undefined || adId == null)
        return;

    var strReq = Tracker.Client.baseUrl + '/Handlers/Controller.ashx?jsonp=Tracker.Client.emptyClbk&key=' +
       Tracker.Client.appKey + '&a=ad_shown' + '&adid=' + adId + '&vid=' + Tracker.Client.visitorId;

    // Visitor sends a messages
    var obj = new JSONscriptRequest(strReq);

    obj.buildScriptTag(); // Build the script tag     

    obj.addScriptTag(); // Execute (add) the script tag

    theObj = obj;
}

Tracker.Client.emptyClbk = function() { 

}

Tracker.Client.animateDiv = function(iDiv)
{
    try
    {
        if (!iDiv.currentPos) iDiv.currentPos = [520,15]; //if no mem is set, set it first;
            doPosChangeMem(iDiv,iDiv.currentPos,[520,100],50,10,0.5);
    }
    catch(e) 
    { 
        try
        {
            iDiv.style.left = "520";
            iDiv.style.top = "15";
        }
        catch(e)
        {
        
        }
    }
}

/**************** animations & effects *********************************/

Tracker.Client.blinkTitle = function() {

    var closed = document.getElementById('gp_hdrClosed');
    var opened = document.getElementById('gp_hdr');

    if (closed == null || opened == null)
        return;

    Tracker.Client.titleBackColor = opened.style.backgroundColor;

    var x = 0;
    setTimeout(function() { closed.style.backgroundColor = '#f55a5a'; }, x); x += 500;
    setTimeout(function() { closed.style.backgroundColor = Tracker.Client.titleBackColor; }, x); x += 500;
    setTimeout(function() { closed.style.backgroundColor = '#f55a5a'; }, x); x += 500;
    setTimeout(function() { closed.style.backgroundColor = Tracker.Client.titleBackColor; }, x); x += 500;
    setTimeout(function() { closed.style.backgroundColor = '#f55a5a'; }, x); x += 1000;
    setTimeout(function() { closed.style.backgroundColor = Tracker.Client.titleBackColor; }, x);
}

Tracker.Client.startMove = function(elmId, fromY, toY, jump)
{
   var elm = document.getElementById(elmId);
   elm.currY = fromY;
   elm.timerId = setInterval(function() { Tracker.Client.doMove(elmId, toY, jump); },40);
}

Tracker.Client.doMove = function(elmId, toY, jump) 
{
    var elm = document.getElementById(elmId);
    elm.currY = elm.currY + jump;
    elm.style.left = (elm.currY) + 'px';
    
    if (elm.currY >= toY)
        Tracker.Client.endMove(elmId ,toY, jump);
}

Tracker.Client.endMove = function(elmId, toY, jump)
{
    var elm = document.getElementById(elmId);
    clearInterval(elm.timerId);
    elm.style.left = (toY) + 'px';
}



function opacity(id, opacStart, opacEnd, millisec) {
    try {
        //speed for each frame
        var speed = Math.round(millisec / 500);
        var timer = 0;

        //determine the direction for the blending, if start and end are the same nothing happens
        if (opacStart > opacEnd) {
            for (i = opacStart; i >= opacEnd; i--) {
                setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));

                if (i <= opacEnd)   // My addition
                {
                    var hide_fnc = function() {
                        document.getElementById(id).style.display = 'none';
                    };
                    setTimeout(hide_fnc, (timer * speed + 100));
                }
                timer++;
            }
        } else if (opacStart < opacEnd) {
            for (i = opacStart; i <= opacEnd; i++) {
                setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));

                if (i >= opacEnd)   // My addition
                {
                    var show_fnc = function() {
                        document.getElementById(id).style.display = 'block';
                    };
                    setTimeout(show_fnc, (timer * speed + 100));
                }
                timer++;
            }
        }
    }
    catch (e)
    { }
}
//change the opacity for different browsers
function changeOpac(opacity, id) {
    try {
        var object = document.getElementById(id).style;
        object.opacity = (opacity / 100);
        object.MozOpacity = (opacity / 100);
        object.KhtmlOpacity = (opacity / 100);
        object.filter = "alpha(opacity=" + opacity + ");";
    }
    catch (e)
    { }
}

var TimeToFade = 1000.0;

function fade(eid)
{
  var element = document.getElementById(eid);
  if(element == null)
    return;
   
  if(element.FadeState == null)
  {
    if(element.style.opacity == null 
        || element.style.opacity == '' 
        || element.style.opacity == '1')
    {
      element.FadeState = 2;
    }
    else
    {
      element.FadeState = -2;
    }
  }
    
  if(element.FadeState == 1 || element.FadeState == -1)
  {
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
  }  
}

function animateFade(lastTick, eid)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = ' 
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
  
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}

function doBGFadeMem(elem,startRGB,endRGB,steps,intervals,powr) {
    //BG Fader with Memory by www.hesido.com
	if (elem.bgFadeMemInt) window.clearInterval(elem.bgFadeMemInt);
	var actStep = 0;
	elem.bgFadeMemInt = window.setInterval(
		function() {
			elem.currentbgRGB = [
				easeInOut(startRGB[0],endRGB[0],steps,actStep,powr),
				easeInOut(startRGB[1],endRGB[1],steps,actStep,powr),
				easeInOut(startRGB[2],endRGB[2],steps,actStep,powr)
				];
			elem.style.backgroundColor = "rgb("+
				elem.currentbgRGB[0]+","+
				elem.currentbgRGB[1]+","+
				elem.currentbgRGB[2]+")";
			actStep++;
			if (actStep > steps) window.clearInterval(elem.bgFadeMemInt);
		}
		,intervals);
}


function doPosChangeMem(elem,startPos,endPos,steps,intervals,powr) 
{
    try
    {
        //Position changer with Memory by www.hesido.com
	    if (elem.posChangeMemInt) window.clearInterval(elem.posChangeMemInt);
	    var actStep = 0;
	    elem.posChangeMemInt = window.setInterval(
		    function() {
			    elem.currentPos = [
				    easeInOut(startPos[0],endPos[0],steps,actStep,powr),
				    easeInOut(startPos[1],endPos[1],steps,actStep,powr)
				    ];
			    elem.style.left = elem.currentPos[0]+"px";
			    elem.style.top = elem.currentPos[1]+"px";
			    actStep++;
			    if (actStep > steps) window.clearInterval(elem.posChangeMemInt);
		    }
		    ,intervals);
    }
    catch(e) { }
}

function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) 
{
    try
    {
    //Generic Animation Step Value Generator By www.hesido.com
	    var delta = maxValue - minValue;
	    var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
	    return Math.ceil(stepp)
    }
    catch(e) { }
}

/* ----------- JsonP functions ---------- */



function JSONscriptRequest(fullUrl) 
{
    try
    {
        // REST request path
        this.fullUrl = fullUrl; 
        // Keep IE from caching requests
        this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
        // Get the DOM location to put the script tag
        this.headLoc = document.getElementsByTagName("head").item(0);
        // Generate a unique script tag id
        this.scriptId = 'YJscriptId' + JSONscriptRequest.scriptCounter++;
    }
    catch(e) { }
}

// Static script ID counter
JSONscriptRequest.scriptCounter = 1;

// buildScriptTag method
//
JSONscriptRequest.prototype.buildScriptTag = function () 
{
    try
    {
        // Create the script tag
        this.scriptObj = document.createElement("script");
        
        // Add script object attributes
        this.scriptObj.setAttribute("type", "text/javascript");
        this.scriptObj.setAttribute("charset", "utf-8");
        this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
        this.scriptObj.setAttribute("id", this.scriptId);
    }
    catch(e) { }
}
 
// removeScriptTag method
JSONscriptRequest.prototype.removeScriptTag = function () {
    try
    {
        // Destroy the script tag
        this.headLoc.removeChild(this.scriptObj);  
    }
    catch(e)
    {
        Tracker.Client.debugMsg(e.name + ' : ' + e.message);
    }
}

// addScriptTag method
// This is where the script is added to the document and is executed
// when it is returned from the server
//
JSONscriptRequest.prototype.addScriptTag = function () 
{
    try
    {
        // Create the script tag
        this.headLoc.appendChild(this.scriptObj);
    }
    catch(e) { }
}

/* --------End of JsonP functions--------- */


/************* scrolling *********************/

var chatscroll = new Object();

  chatscroll.Pane = function(scrollContainerId){
    this.bottomThreshold = 100;     // was 20
    this.scrollContainerId = scrollContainerId;
    this._lastScrollPosition = 100000000;
  }

  chatscroll.Pane.prototype.activeScroll = function()
  {
//alert('scrol');

    var _ref = this;
    var scrollDiv = document.getElementById(this.scrollContainerId);
    
//alert(scrollDiv.id);

    var currentHeight = 0;
    
    var _getElementHeight = function(){
      var intHt = 0;
      if(scrollDiv.style.pixelHeight)intHt = scrollDiv.style.pixelHeight;
      else intHt = scrollDiv.offsetHeight;
      return parseInt(intHt);
    }

    var _hasUserScrolled = function(){
      if(_ref._lastScrollPosition == scrollDiv.scrollTop || _ref._lastScrollPosition == null){
        //alert("_hasUserScrolled = false");
        return false;
      }
      //alert("_hasUserScrolled = true");
      return true;
    }

    var _scrollIfInZone = function() {
      if( !_hasUserScrolled() || isMSIE || 
          (currentHeight - scrollDiv.scrollTop - _getElementHeight() <= _ref.bottomThreshold)){
          scrollDiv.scrollTop = currentHeight;
          _ref._isUserActive = false;
      }
    }


    if (scrollDiv.scrollHeight > 0)currentHeight = scrollDiv.scrollHeight;
    else if(scrollDiv.offsetHeight > 0)currentHeight = scrollDiv.offsetHeight;

    _scrollIfInZone();

    _ref = null;
    scrollDiv = null;

  }

/************* end of scrolling **************/


/************* strings helper functions ***********************/

/* String trim funtions */

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

String.prototype.left = function(len){
    return (len > this.length) ? this : this.substring(0, len);
}

String.prototype.right = function(len){
    return (len > this.length) ? this : this.substring(this.length - len);
}

/************* end of strings helper functions ***********************/

/************* keep visitor session alive ****************************/

Tracker.Client.SessionReconnect = function()
{
    return;

    try
    {
        Tracker.Client.reconnect_count++;
        if (Tracker.Client.reconnect_count < Tracker.Client.reconnect_max)
        {
            //Tracker.Client.debugMsg('session reconnect');
        
            window.status = 'Link to Server Refreshed ' + Tracker.Client.reconnect_count.toString()+' time(s)' ;
            var img = new Image(1,1);
            img.src = Tracker.Client.baseUrl + '/UI/Visitor/Reconnect.aspx';
        }
    }
    catch(e) { }
}

/************* keep visitor session alive ****************************/


/************* get url param for checking if we are in preview mode **/

Tracker.Client.getUrlParam = function( name )
{
    try
    {
      name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
      var regexS = "[\\?&]"+name+"=([^&#]*)";
      var regex = new RegExp( regexS );
      var results = regex.exec( window.location.href );
      if( results == null )
        return "";
      else
        return results[1];
    }
    catch(e) { }
}

/******* end of get url param for checking if we are in preview mode **/


/************************** cookies **********************************/

// returns the visitor id from the cookie
Tracker.Client.getVIdCookie = function()
{
    try
    {
        var c = Tracker.Client.readCookie("mychat_vid");
        
        return (parseInt(c));
    }
    catch(e) 
    {
        //alert(e.description);
        return (0);
    }
}

// set the visitor id cookie
Tracker.Client.setVIdCookie = function() {
    try {
        // Create a visitor cookie and keep it for 2 minutes
        Tracker.Client.createCookie("mychat_vid", Tracker.Client.visitorId, 240);
    }
    catch (e) {
        //alert(e.description);
    }

}

// returns the visitor id from the cookie
Tracker.Client.getWStateCookie = function()
{
    try
    {
        var c = Tracker.Client.readCookie("mychat_wdgt");
        return (c);
    }
    catch(e) 
    {
        //alert(e.description);
        return (0);
    }
}

// set the visitor id cookie
Tracker.Client.setWStateCookie = function(c_value)
{
    try
    {
        // Create a visitor cookie and keep it for 2 minutes
        Tracker.Client.createCookie("mychat_wdgt", c_value, 240);
    }
    catch(e) 
    { 
        //alert(e.description);
    }

}

// returns the Agent flag from the cookie
Tracker.Client.getAgentCookie = function() {
    try {
        var c = Tracker.Client.readCookie("gp_agent");
        return (c);
    }
    catch (e) {
        return (0);
    }
}

// set the Agent flag cookie
Tracker.Client.setAgentCookie = function() {
    try {
        // Create an Agent flag cookie and keep it for 2 hours
        Tracker.Client.createCookie("gp_agent", 1, 7200);
    }
    catch (e) {
        //alert(e.description);
    }

}

Tracker.Client.getAdCookie = function(adId)
{
    try
    {
        var c = Tracker.Client.readCookie("gp_ad" + adId);
        return (c);
    }
    catch(e) 
    {
        return (0);
    }
}

Tracker.Client.setAdCookie = function(adId) {
    try {
        // Create an ad cookie and keep it for 60 minutes
        Tracker.Client.createCookie("gp_ad" + adId, adId, 3600);
    }
    catch (e) {
    }
}


Tracker.Client.createCookie = function(name, value, seconds /*days*/) {


var wwwIndex = document.domain.indexOf('.', 0)
var cookieDomain = document.domain;
if (wwwIndex > 0)
    if (document.domain.substring(0, wwwIndex) == 'www')
        cookieDomain = '.' + document.domain.substring(wwwIndex+1, document.domain.length);

//alert(document.domain + ' => ' + cookieDomain);

    try
    {
        if (seconds /*days*/) {
            var date = new Date();
            // date.setTime(date.getTime()+(days*24*60*60*1000));
            date.setTime(date.getTime()+(seconds*1000));
            var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
    }
    catch(e) 
    { 
        
    }
}

Tracker.Client.readCookie = function(name) {
    try
    {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }
    catch(e) 
    { 
        return null;
    }
}

Tracker.Client.eraseCookie = function(name) {
    createCookie(name,"",-1);
}

/************************** end of cookies **********************************/

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

/***************************** Floater *****************************/
/////////////////////////////////////////////////////////////////////

var FloatLayers       = new Array();
var FloatLayersByName = new Array();

function addFloatLayer(n, startX, startY, offX, offY, spd) { new FloatLayer(n, startX, startY, offX, offY, spd); }
function getFloatLayer(n){return FloatLayersByName[n];}
function alignFloatLayers(){for(var i=0;i<FloatLayers.length;i++)FloatLayers[i].align();}

function getXCoord(el) {
	x=0;
	while(el){
		x+=el.offsetLeft;
		el=el.offsetParent;
	}
	return x;
}
function getYCoord(el) {
	y=0;
	while(el){
		y+=el.offsetTop;
		el=el.offsetParent;
	}
	return y;
}

/////////////////////////////////////////////////////////////////////

FloatLayer.prototype.setFloatToTop=setTopFloater;
FloatLayer.prototype.setFloatToBottom=setBottomFloater;
FloatLayer.prototype.setFloatToLeft=setLeftFloater;
FloatLayer.prototype.setFloatToRight=setRightFloater;
FloatLayer.prototype.initialize=defineFloater;
FloatLayer.prototype.adjust=adjustFloater;
FloatLayer.prototype.align=alignFloater;

function FloatLayer(n,startX, startY, offX, offY, spd) {
	this.index=FloatLayers.length;

	FloatLayers.push(this);
	FloatLayersByName[n] = this;

	this.name    = n;
	this.floatX = startX;
	this.floatY = startY;
	this.tm      = null;
	this.steps   = spd;
	this.alignHorizontal=(offX>=0) ? leftFloater : rightFloater;
	this.alignVertical  =(offY>=0) ? topFloater : bottomFloater;
	this.ifloatX = Math.abs(offX);
	this.ifloatY = Math.abs(offY);

	this.isFloating = true;
}

function removeFloatLayer(n) {

    var lyr = FloatLayersByName[n];
    if (lyr != null)
        lyr.isFloating = false;
/*        if (lyr.index != undefined)
            if (lyr.index = FloatLayers.length - 1)
            FloatLayers.pop();
        else
            FloatLayers[lyr.index] = null;
    }
    FloatLayersByName[n] = null;*/
}

/////////////////////////////////////////////////////////////////////

function defineFloater(){
	this.layer  = document.getElementById(this.name);
	this.width  = this.layer.offsetWidth;
	this.height = this.layer.offsetHeight;
	this.prevX  = this.layer.offsetLeft;
	this.prevY  = this.layer.offsetTop;
}

function adjustFloater() {
    this.tm = null;

    if (!this.isFloating)
        return;
	
	if(this.layer.style.position!='absolute')return;

//	if (this.prevY > this.floatY + 100)
//	    this.prevY = this.floatY + 100;
//	if (this.prevY < this.floatY - 100)
//	    this.prevY = this.floatY - 100;

	var dx = Math.abs(this.floatX-this.prevX);
	var dy = Math.abs(this.floatY-this.prevY);

	if (dx < this.steps/2)
		cx = (dx>=1) ? 1 : 0;
	else
		cx = Math.round(dx/this.steps);

    if (dy < this.steps / 2)
        cy = (dy >= 1) ? 1 : 0;
    else {
        if (dy > 150) {
            cy = Math.round(dy / this.steps);
        }
        else {
            //
            if (dy < 10)
                cy = dy;
                //cy = Math.round(dy / this.steps);
            else
                cy = 10;
        }
    }

	if (this.floatX > this.prevX)
		this.prevX += cx;
	else if (this.floatX < this.prevX)
		this.prevX -= cx;

	if (this.floatY > this.prevY)
		this.prevY += cy;
	else if (this.floatY < this.prevY)
		this.prevY -= cy;

	this.layer.style.left = this.prevX + 'px';
	this.layer.style.top  = this.prevY + 'px';

	if (cx!=0||cy!=0){
		if(this.tm==null)this.tm=setTimeout('FloatLayers['+this.index+'].adjust()',50);
	}else
		alignFloatLayers();
}

function setLeftFloater(){this.alignHorizontal=leftFloater;}
function setRightFloater(){this.alignHorizontal=rightFloater;}
function setTopFloater(){this.alignVertical=topFloater;}
function setBottomFloater(){this.alignVertical=bottomFloater;}

function getScrollWidth()
{
   var w = window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft;    	   
   return w ? w : 0;
} 

function getScrollHeight()
{
   var h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
   return h ? h : 0;
}

function leftFloater(){this.floatX = f_scrollLeft() + this.ifloatX;}
function topFloater(){this.floatY = f_scrollTop() + this.ifloatY;}
function rightFloater(){this.floatX = f_scrollLeft() + f_clientWidth() - this.ifloatX - this.width;}
function bottomFloater(){this.floatY = f_scrollTop() + f_clientHeight() - this.ifloatY - this.height;}

function alignFloater(){
	if(this.layer==null)this.initialize();
	this.alignHorizontal();
	this.alignVertical();
	if(this.prevX!=this.floatX || this.prevY!=this.floatY){
		if(this.tm==null)this.tm=setTimeout('FloatLayers['+this.index+'].adjust()',50);
	}
}

// Dimensions
// ----------

function f_ElementWidth(Elem) {
    if (ns4) {
        var elem = getObjNN4(document, Elem);
        return elem.clip.width;
    } else {
        if (document.getElementById) {
            var elem = document.getElementById(Elem);
        } else if (document.all) {
            var elem = document.all[Elem];
        }
        if (op5) {
            xPos = elem.style.pixelWidth;
        } else {
            xPos = elem.offsetWidth;
        }
        return xPos;
    }
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}

function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_scrollHeight() {
    return f_filterResults(
		window.scrollHeight ? window.scrollHeight : 0,
		document.documentElement ? document.documentElement.scrollHeight : 0,
		document.body ? document.body.scrollHeight : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

Tracker.Client.onWndBlur = function() {
	Tracker.Client.isFocused = false;
}

Tracker.Client.onWndFocus = function() {
	Tracker.Client.isFocused = true;
}

Tracker.Client.initWndFocus = function() {
    if (isMSIE) { // Internet Explorer
	    document.onfocusin = Tracker.Client.onWndFocus;
	    document.onfocusout = Tracker.Client.onWndBlur;
    } else {
	    window.onfocus = Tracker.Client.onWndFocus;
	    window.onblur = Tracker.Client.onWndBlur;
    }
}

Tracker.Client.cancelEsc = function() {
    document.onkeypress = function(e) {
        try {
            var key = e.keyCode || e.charCode;
            if (key == 27) {
                return false;
            }
        } catch (e)
        { }
    }
}


/******************************** NEW VERSION **********************/

Tracker.Client.JQInject = function() {
    var script = document.createElement("script");
    script.src = Tracker.Client.baseUrl + "/JQuery/jquery-1.3.2.min.js";
    script.onload = script.onreadystatechange = function() {

        // on jquery script loaded
        var mywidget_jQuery = $.noConflict(true);

        //alert('hi');

        //alert(jQuery('#chat_w').html());

//        var script_clrbx = document.createElement("script");
//        script_clrbx.src = Tracker.Client.baseUrl + "/JQuery/plugins/colorbox/colorbox/jquery.colorbox-min.js";
//        script_clrbx.onload = script_clrbx.onreadystatechange = function() {

//            alert('1');

//            var newdiv = document.createElement('div')
//            newdiv.setAttribute("id", "gp_clrbx");
//            newdiv.setAttribute("style", "border: solid 1px blue;display:block;");

//            newdiv.innerHTML = "<span>hello</span>";
//            document.body.appendChild(newdiv);

//            jQuery('#gp_clrbx').colorbox({ transition: 'fade', speed: 500 });

//        };
//        document.body.appendChild(script_clrbx);
    };
    document.body.appendChild(script);
}

/*******************************************************************/
