this.VisitorValue = "bc45cc9c1719412dbfd8b25c3b187a80";
this.LastCallbackImageHeight = 0;
this.LastCallbackAction = 0;
this.IntervalID = 0;
this.ImgHeightActions = 
{
    None: 1,
    DisableAsyncCallback: 2,
    EnableAsyncCallback: 3,
    RemoveFromListPerm: 4,
    RemoveFromList: 5,
    ForceChat: 6, 
    InviteChat: 7,
    SendClientLocation: 8,
    NavigateUrl: 9,
    PopupUrl: 10,
    Biggest_Image: 11
}
var MovableInvite = null;
var IsInviteMoving = false;
var WindowPosX = 0;
var WindowPosY = 0;

function SmarterTrackAction()
{
    this.OnNormalCheck = function()
    {
        // does nothing
    }
    this.EnableAsyncCallback = function()
    {
        // does nothing
    }
    this.DisableAsyncCallback = function()
    {
        try
        {
            clearInterval(IntervalID);
        }
        catch (err) { }
    }
    this.RemoveFromListPerm = function()
    {
        set_cookiePerm("StopTracking", "true");
        try
        {
            clearInterval(IntervalID);
        }
        catch (err) { }
    }
    this.RemoveFromList = function()
    {
        var paramCook = get_cookie("OutputParameter");
        if (paramCook != "")
        {
            set_cookieTime("StopTracking", "true", ";expires=" + paramCook);
        }
        try
        {
            clearInterval(IntervalID);
        }
        catch (err) { }
        //";expires=Fri, 1 Jan 2038 10:00:00 UTC"
    }
    this.ForceChat = function()
    {
        STInjectScript("&forcechat=true", "");
    }
    this.InviteChat = function(interactId)
    {
        STInjectScript("&sendinvite=true", interactId);
    }
    this.SendClientLocation = function()
    {
        // feature is not allowed
    }
    this.NavigateUrl = function()
    {
        // feature is only allowed from an initiated chat
    }
    this.PopupUrl = function()
    {
        // feature is not allowed
    }
}
function SmarterTrackObject(portal)
{      
    this.TrackingUrl = portal + "App_Themes/Horizon/Javascript/ST.ashx";
    this.TrackPage = function()
    {
        //var firstTimeUrl = this.TrackingUrl + "?firstrun=true";
        this.GetTrackingCode("");
    }
    this.TrackVirtualPage = function(pagename)
    {
        //var firstTimeUrl = this.TrackingUrl + "?firstrun=true&vp="+pagename;
        this.GetTrackingCode(pagename);
    }
    this.GetTrackingCode = function(virtualpage)
    {
        try
        {
            // check and see if this is a tracked session or co-browsing session
            var stopCookie = get_cookie("StopTracking");
            if (stopCookie == null || (stopCookie != null && stopCookie != "true"))
            {
                set_cookiePerm("PortalUrl", portal);
                var rid = Math.round(Math.random()*2147483647);
                var trackingDivName = "SmarterTrackingArea"+rid;
                var interactDivName = "SmarterInteractiveArea"+rid;                        
                
                var isInjectCapable = false;
                try
                {
                    STInjectScript("&firstrun=true&sendactionscript=true&dt="+EscapeTitle()+"&ref="+document.referrer+"&pp="+window.location.href, interactDivName);
                    isInjectCapable = true;
                }
                catch (err)
                {
                    // browser was not capable for the script injection... revert to use the image
                    var firstTimeUrl = this.TrackingUrl + "&firstrun=true&sendactionimage=true&dt="+EscapeTitle()+"&ref="+document.referrer+"&pp="+window.location.href;
                    document.write("<div style='z-index:150;position:absolute;left:0px;top:0px;"+GetVisibilityFalse()+"' id='"+trackingDivName+"'><img id='SmarterTrack_ActionDetection' src='"+firstTimeUrl+"' /></div>");            
                }
                document.write("<div style='z-index:151;position:absolute;left:0px;top:0px;"+GetVisibilityFalse()+"' id='"+interactDivName+"'></div>");
                
                if (isInjectCapable)
                    IntervalID = setInterval("RetrackScript('"+interactDivName+"', '"+virtualpage+"');", 4000);
                else
                    IntervalID = setInterval("RetrackImage('"+interactDivName+"', '"+trackingDivName+"', '"+virtualpage+"', '"+this.TrackingUrl+"');", 4000);
                
                setTimeout("clearInterval(IntervalID);", 900000);
            }
        }
        catch (err) { }
    }
}
function get_cookie(Name) 
{
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}
function set_cookieTemp(Name, Value)
{
    document.cookie =  this.Encode(Name) +'='+ this.Encode(Value) + "; path=/";
}
function set_cookiePerm(Name, Value)
{
    document.cookie =  this.Encode(Name) +'='+ this.Encode(Value) + ';expires=Fri, 1 Jan 2038 10:00:00 GMT; path=/';
}
function set_cookieTime(Name, Value, Expires)
{
    document.cookie =  this.Encode(Name) +'='+ this.Encode(Value) + Expires + "; path=/";
}
function del_cookie(Name)
{
    document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/";
}
function GetVisitorCookie()
{
    var visitCookie = get_cookie("siteuidut");
    if (visitCookie == null || visitCookie == "")
    {
        set_cookiePerm("siteuidut", this.VisitorValue);
        return this.VisitorValue;
    }
    else
    {
        return visitCookie;
    }
}
function Encode(text)
{
    try
    {
        return encodeURIComponent(text);
    }
    catch(ex)
    {
        return escape(text);
    }
}
function CloseMessage(interactId)
{
    var interactArea = document.getElementById(interactId);
    SetVisibility(interactId, false);
    interactArea.innerHTML = "";
}
function AcceptForcedMessage(responseUrl)
{
    window.open(responseUrl, "LiveChat", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=480");
}
function AcceptMessage(responseUrl, interactId, txtNameID, txtEmailID)
{
    var cName = document.getElementById(txtNameID).value;
    if (cName != "")
        cName = "&cName="+cName;
        
    var cEmail = document.getElementById(txtEmailID).value;
    if (cEmail != "")
        cEmail = "&cEmail="+cEmail;
    
    var respUrl = responseUrl+cName+cEmail;
    window.open(respUrl, "LiveChat", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=480");
    
    CloseMessage(interactId);
    STInjectScript('&inputparameter=ChatInviteState%3DAccepted"', "");
}
function RetrackScript(interactId, virtualpage)
{
    try
    {
        var vpQS = "";
        if (virtualpage != "")
        {
            vpQS = "&vp="+virtualpage;
        }
        STInjectScript("&sendactionscript=true&ref="+document.referrer+"&dt="+EscapeTitle()+"&pp="+window.location.href+vpQS, interactId);
    }
    catch (err) { }
}
function RetrackImage(interactId, trackingId, virtualpage, callerUrl)
{
    try
    {
        var vpQS = "";
        if (virtualpage != "")
        {
            vpQS = "&vp="+virtualpage;
        }
        var callerUrlID = callerUrl + "?postId="+Math.round(Math.random()*2147483647)+"&sendactionimage=true&visitorId="+GetVisitorCookie()+"&ref="+document.referrer+"&dt="+EscapeTitle()+"&pp="+window.location.href+vpQS;
        document.getElementById(""+trackingId+"").innerHTML = "<img id='SmarterTrack_ActionDetection' src='"+callerUrlID+"' />";
        DetectSTAction(interactId);
    }
    catch (err) { }
}
function DetectSTAction(interactId)
{
    var actionObj = document.getElementById("SmarterTrack_ActionDetection");
    if (actionObj != null)
    {
        if (actionObj.width != 1 || actionObj.height >= this.ImgHeightActions.Biggest_Image || actionObj.height == 0)
            setTimeout("DetectSTAction('"+interactId+"');", 300);
        else
            this.HandleCallbackCommand(interactId, actionObj.height);
    }
}
function HandleCallbackCommand(interactId, height)
{
    if (height == this.LastCallbackImageHeight) 
        return;
    this.LastCallbackImageHeight = height;
    if (height > 1)
        this.LastCallbackAction = height;
    
    var STAction = new SmarterTrackAction();
    switch (height)
    {
        case this.ImgHeightActions.None: STAction.OnNormalCheck(); break; // currently does nothing
        case this.ImgHeightActions.EnableAsyncCallback: STAction.EnableAsyncCallback(); break; // currently does nothing
        case this.ImgHeightActions.DisableAsyncCallback: STAction.DisableAsyncCallback(); break; // currently does nothing
        case this.ImgHeightActions.RemoveFromListPerm: STAction.RemoveFromListPerm(); break;
        case this.ImgHeightActions.ForceChat: STAction.ForceChat(interactId); break;
        case this.ImgHeightActions.InviteChat: STAction.InviteChat(interactId); break;
        case this.ImgHeightActions.SendClientLocation: STAction.SendClientLocation(); break; // currently does nothing
        case this.ImgHeightActions.NavigateUrl: STAction.NavigateUrl(); break; // currently does nothing
        case this.ImgHeightActions.PopupUrl: STAction.PopupUrl(); break; // currently does nothing
        default: break;
    }
}
function STSendAction(visitorId, action, interactId)
{
    try
    {
        if (GetVisitorCookie() != visitorId)
            return;
            
        this.LastCallbackImageHeight = action;
        if (action > 1)
            this.LastCallbackAction = action;
        
        var STAction = new SmarterTrackAction();
        switch (action)
        {
            case this.ImgHeightActions.None: STAction.OnNormalCheck(); break; // currently does nothing
            case this.ImgHeightActions.EnableAsyncCallback: STAction.EnableAsyncCallback(); break; // currently does nothing
            case this.ImgHeightActions.DisableAsyncCallback: STAction.DisableAsyncCallback(); break; // currently does nothing
            case this.ImgHeightActions.RemoveFromListPerm: STAction.RemoveFromListPerm(); break;
            case this.ImgHeightActions.ForceChat: STAction.ForceChat(interactId); break;
            case this.ImgHeightActions.InviteChat: STAction.InviteChat(interactId); break;
            case this.ImgHeightActions.SendClientLocation: STAction.SendClientLocation(); break; // currently does nothing
            case this.ImgHeightActions.NavigateUrl: STAction.NavigateUrl(); break; // currently does nothing
            case this.ImgHeightActions.PopupUrl: STAction.PopupUrl(); break; // currently does nothing
            default: break;
        }
    }
    catch (err) { }
}
function SetVisibility(id, isVisible)
{
    var objToSet = document.getElementById(id);
    if (navigator.appName.indexOf("Microsoft")!=-1)
    {
        objToSet.style.visibility = isVisible == true ? "visible" : "hidden";
    }
    else
    {
        objToSet.style.display = isVisible == true ? "" : "none";
    }
}
function GetVisibilityFalse()
{
    if (navigator.appName.indexOf("Microsoft")!=-1)
    {
        return "visibility: hidden;";
    }
    else
    {
        return "display: none;";
    }
}
function STHrefNull()
{
}
function STForceChat(visitorId, parameters)
{
    if (GetVisitorCookie() != visitorId)
        return;
        
    var portalUrlCook = get_cookie("PortalUrl");
	if (parameters != "" && portalUrlCook != "")
    {
        var params = parameters.split("|");
        var pInviteFrom = "";
        var pMessage = "";
        var pDept = "";
        var pGrp = "";
        var pUsr = "";
        var pTrackingId = "";
        for (var i = 0; i < params.length; i++)
        {
            var values = params[i].split("=");
            if (values.length == 2)
            {
                switch (values[0])
                {
                    case "Message": pMessage = values[1]; break;
                    case "InviteFrom": pInviteFrom = values[1]; break;
                    case "Department": pDept = "&departmentId=" + values[1]; break;
                    case "Group": pGrp = "&groupId=" + values[1]; break;
                    case "User": pUsr = "&userId=" + values[1]; break;
                    case "TrackingId": pTrackingId = "&trackingId=" + values[1]; break;
                }
            }
        }

		AcceptForcedMessage(portalUrlCook+"Chat/frmClientChatWait.aspx?fromInvite=true&forcedChat=true&message="+pMessage+pDept+pGrp+pUsr+pTrackingId);
		STInjectScript("&inputparameter=ChatInviteState%3DAccepted", "");
    }
}
function STBuildInvitation(visitorId, parameters, interactId)
{
    if (GetVisitorCookie() != visitorId)
        return;
    
    var interactArea = document.getElementById(interactId);
    
    //var paramCook = get_cookie("OutputParameter");
    var portalUrlCook = get_cookie("PortalUrl");
    if (parameters != "" && portalUrlCook != "" && interactArea != null)
    {
        var conWidth = 314;
        var conHeight = 196;
        
        var winWidth = 0;
        var winOuterWidth = 0;
        var winHeight = 0;
        var winOuterHeight = 0;
        if (parseInt(navigator.appVersion)>3) 
        {
            if (navigator.appName=="Netscape") 
            {
                if (document.body.offsetHeight && document.body.offsetWidth)
                {
                    winWidth = document.body.offsetWidth;
                    winHeight = document.body.offsetHeight;
                }
                else
                {
                    winWidth = window.innerWidth;
                    winHeight = window.innerHeight;
                }
            }
            if (navigator.appName.indexOf("Microsoft")!=-1)
            {
                winWidth = document.body.offsetWidth;
                winHeight = document.body.offsetHeight;
            }
        }
        
        if (window.innerWidth)
        {
            winOuterWidth = window.innerWidth;
            winOuterHeight = window.innerHeight;
        }
        else if (document.documentElement && 
            document.documentElement.clientWidth &&
            document.documentElement.clientWidth != 0)
        {
            winOuterWidth = document.documentElement.clientWidth;
            winOuterHeight = document.documentElement.clientHeight;
        }
        else
        {
            winOuterWidth = document.getElementsByTagName("body")[0].clientWidth;
            winOuterHeight = document.getElementsByTagName("body")[0].clientHeight;
        }
                
        var params = parameters.split("|");
        var pInviteFrom = "";
        var pMessage = "";
        var pDept = "";
        var pGrp = "";
        var pUsr = "";
        var pUsrID = "";
        var pTrackingId = "";
        var pTimeTillAbandon = 120000;
        var pShowFromName = "false";
        var pThemeName = "Horizon";
        var pHAlign = "";
        var pVAlign = "";
        var pHOffset = "";
        var pVOffset = "";
        var pAbsolutePosition = "false";
        var pGSChatInvitation = "";
        var pGSName = "";
        var pGSAccept = "";
        var pGSReject = "";
        var pGSEmail = "";
        
        for (var i = 0; i < params.length; i++)
        {
            var values = params[i].split("=");
            if (values.length == 2)
            {
                switch (values[0])
                {
                    case "Message": pMessage = TrackingMessageDecoder(values[1]); break;
                    case "InviteFrom": pInviteFrom = values[1]; break;
                    case "Department": pDept = "&departmentId=" + values[1]; break;
                    case "Group": pGrp = "&groupId=" + values[1]; break;
                    case "User": pUsr = "&userId=" + values[1]; pUsrID = values[1]; break;
                    case "TrackingId": pTrackingId = "&trackingId=" + values[1]; break;
                    case "AbandonTime": pTimeTillAbandon = parseInt(values[1]); break;
                    case "ShowFromName": pShowFromName = values[1]; break;
                    case "ThemeName": pThemeName = values[1]; break;
                    case "HAlign": pHAlign = values[1]; break;
                    case "VAlign": pVAlign = values[1]; break;
                    case "HOffset": pHOffset = values[1]; break;
                    case "VOffset": pVOffset = values[1]; break;
                    case "AbsolutePosition": pAbsolutePosition = values[1]; break;
                    case "GSChatInvitation": pGSChatInvitation = values[1]; break;
                    case "GSName": pGSName = values[1]; break;
                    case "GSAccept": pGSAccept = values[1]; break;
                    case "GSReject": pGSReject = values[1]; break;
                    case "GSEmail": pGSEmail = values[1]; break;
                }
            }
        }
        
        var adjLeft = 0;
        var adjTop = 0;
        
        if (parseFloat(pHOffset) > screen.width)
            pHOffset = "0";
        if (parseFloat(pVOffset) > screen.height)
            pVOffset = "0";
        
        var bufferSpacer = 0;
        switch (pHAlign)
        {
            case "Left": adjLeft = 0 + parseFloat(pHOffset); break;
            case "Center": adjLeft = Math.round((winWidth - conWidth) / 2) + parseFloat(pHOffset); break;
            case "Right": 
                if (navigator.appName == "Netscape")
                    bufferSpacer = 20;
                else
                    bufferSpacer = 0;
                
                adjLeft = Math.round(winWidth - conWidth - bufferSpacer) - parseFloat(pHOffset);
                break;
        }
        
        var posAbs = pAbsolutePosition == "True" || pAbsolutePosition == "true" ? true : false;
        var scrollTopPx = 0;
        
        if (document.body.scrollTop)
            scrollTopPx = document.body.scrollTop;
        else if (document.documentElement.scrollTop)
            scrollTopPx = document.documentElement.scrollTop;
        else if (window.pageYOffset)
            scrollTopPx = window.pageYOffset;
         
        switch (pVAlign)
        {
            case "Top": 
                if (posAbs)
                {
                    adjTop = 0 + parseFloat(pVOffset);
                }
                else
                {
                    adjTop = scrollTopPx + parseFloat(pVOffset);
                }
                break;
            case "Center": 
                if (posAbs)
                {
                    adjTop = Math.round((winHeight - conHeight) / 2) + parseFloat(pVOffset);
                }
                else
                {
                    adjTop = Math.round((winOuterHeight - conHeight) / 2) + scrollTopPx + parseFloat(pVOffset);
                }
                break;
            case "Bottom":
                if (posAbs)
                {
                    adjTop = Math.round(winHeight - conHeight) - parseFloat(pVOffset);
                }
                else
                {
                    if (navigator.appName == "Netscape")
                        bufferSpacer = 0;
                    else
                        bufferSpacer = 63;
                        
                    adjTop = ((Math.round(winOuterHeight - conHeight) - bufferSpacer) + scrollTopPx) - parseFloat(pVOffset);
                }
                break;
        }
        
        interactArea.style.left = adjLeft+"px";
        interactArea.style.top = adjTop+"px";
        
        SetVisibility(interactId, true);
        
        var randomIdentifier = "ST_"+Math.round(Math.random()*2147483647);
        var txtNameID = randomIdentifier+"_txtName";
        var txtEmailID = randomIdentifier+"_txtEmail";
        
        var leftTileID = randomIdentifier+"_leftChatTile";
        var centerTileID = randomIdentifier+"_centerChatTile";
        var rightTileID = randomIdentifier+"_rightChatTile";
        
        var leftRejectTileID = randomIdentifier+"_leftRejectTile";
        var centerRejectTileID = randomIdentifier+"_centerRejectTile";
        var rightRejectTileID = randomIdentifier+"_rightRejectTile";
        
        var closeAction = "CloseMessage('"+interactId+"');STInjectScript('&inputparameter=ChatInviteState%3DRejected%5E"+pUsrID+"', '');";
        var acceptResponseUrl = portalUrlCook+"Chat/frmClientChatWait.aspx?fromInvite=true&message="+pMessage+pDept+pGrp+pUsr+pTrackingId;

        // styles
        var invitationDir = portalUrlCook+"App_Themes/"+pThemeName+"/Images/Invitations/";
        var windowDir = portalUrlCook+"App_Themes/"+pThemeName+"/Controls/Window/";
        
        var blueTextColor = "#335771";
        var blueColor = "#436985";
        var greenColor = "#3F621B";
        
        var conStyle = "width: "+conWidth+"px;height: "+conHeight+"px;padding: 0px;margin: 0px;";
    //            var tblMain = "width: "+(conWidth-6)+"px;height: "+conHeight+"px;";
    //            var tblSide = "width: 6px;height: "+conHeight+"px;";
        
        var windowTopTile = "width: 304px;height: 27px;border-left: solid 1px "+blueColor+";border-top: solid 1px "+blueColor+";border-right: solid 1px "+blueColor+";background-image: url("+windowDir+"CssImg/PopIn_UpperTile.png);background-repeat: repeat-x;";
        var windowTopTitleText = "width: 276px;padding-left: 5px;font: 9pt Arial,Verdana;font-weight: bold;color: #ffffff;vertical-align: middle;text-align: left;";
        var windowBodyText = "font: 8pt Arial,Verdana;color: #444444;text-align: left;";
        var windowTopClose = "width: 26px;text-align: right;";
        var windowWM = "background-color: #ffffff;width: 184px;height: 150px;border-right: solid 1px "+blueColor+";border-bottom: solid 1px "+blueColor+";background-image: url("+invitationDir+"Watermark.gif);background-repeat:no-repeat;background-position: bottom right;";
        var windowMessageArea = "vertical-align: top;padding-left: 3px;padding-top: 8px;padding-right: 3px;";
        var windowEntryArea = "text-align: left;vertical-align: bottom;padding-left: 3px;padding-bottom: 13px; padding-right: 3px;";
        var windowTextBox = "width: 145px";
        var windowAgent = "background-color: #ffffff;border-left: solid 1px "+blueColor+";border-bottom: solid 1px "+blueColor+";width: 120px;height: 150px;";
        var windowAgentFromText = "text-align: center;font: 8pt Arial,Verdana;color: #444444;padding-bottom: 3px;";
        var centerContext = "text-align: center;vertical-align: middle;";
        var windowAgentSpan = "background-color: #ffffff;padding-left: 10px;";
        
        var windowFarRight = "width: 6px;";
        var btmButtonAreaLeft = "width: 124px;height: 32px;";
        var btmButtonAreaTile = "width: 180px;height: 32px;border-left: solid 1px "+blueColor+";background-image: url("+invitationDir+"BlueBtn/BlueBtn_Tile.gif);background-repeat: repeat-x;background-position: top right;";
        var btmButtonAreaRight = windowFarRight+"height: 88px;background-image: url("+invitationDir+"BlueBtn/BlueBtn_RightCap.gif);background-repeat: no-repeat;background-position: bottom left;";
        
        var btmButtonArea = "width: 132px;height: 100%;text-align: right;vertical-align: middle;";
        var btmButtonArrow = "width: 48px;height: 100%;text-align: center;vertical-align: middle;";
        
        var buttonLeftTile = "width: 2px;height: 21px;background-image: url("+invitationDir+"BlueBtn/StartBtn_LeftCap.gif);background-repeat: no-repeat;";
        var buttonRightTile = "width: 2px;height: 21px;background-image: url("+invitationDir+"BlueBtn/StartBtn_RightCap.gif);background-repeat: no-repeat;";
        var buttonCenterTile = "width: 60px;height: 21px;text-align: center;background-image: url("+invitationDir+"BlueBtn/StartBtn_Tile.gif);background-repeat: repeat-x;";
        var buttonBlueText = centerContext+"color: "+blueTextColor+";font: 9pt Arial;";
        var buttonSpacer = "width: 3px;";
        
        var cursorStyle = "cursor: pointer;";
        var anchorStyle = "text-decoration: none;border: none;";
        var tableMax = "height: 100%;";
        
        if (pInviteFrom == "")
            pInviteFrom = "Agent";
        
        var fromText = "";
        if (pShowFromName == "true")
        {
            fromText = "<div style='"+windowAgentFromText+"'>"+pInviteFrom+"</div>";
        }
        var s = "";
        
        // build invitation HTML with the styles above
        s += "<table style='"+conStyle+"' cellpadding='0' cellspacing='0'>";
        
        var MovableBarAreaID = "SmarterBar"+Math.round(Math.random()*2147483647);
        // top row (where header and close are)
        s += "<tr><td colspan='2' style='"+windowTopTile+"'>";
        s += "<table cellpadding='0' cellspacing='0'><tr>";
        s += "<td id='"+MovableBarAreaID+"' onmousedown=\"OnMouseInviteDown(e);\" onmouseup=\"OnMouseInviteUp(e);\" style='"+windowTopTitleText+"'>"+pGSChatInvitation+"</td>";
        s += "<td style='"+windowTopClose+"'>";
        s += "<img style='"+cursorStyle+"' src='"+windowDir+"Img/close.gif' onClick=\""+closeAction+"\" /></td>";
        s += "</tr></table></td><td style='"+windowFarRight+"'></td></tr>";
        
        // middle row (where body of invitation is)
        s += "<tr><td style='"+windowAgent+"'>";
        s += "<span style='"+windowAgentSpan+"'>";
        s += "<img src='"+invitationDir+"AgentIcon.gif' />"+fromText+"</span>";
        s += "</td><td style='"+windowWM+"'><table style='"+tableMax+"' cellpadding='0' cellspacing='0'><tr>";
        s += "<td style='"+windowMessageArea+"'><div style='"+windowBodyText+"'>"+pMessage+"</div></td></tr>";
        s += "<tr><td style='"+windowEntryArea+"'><div style='"+windowBodyText+"'>"+pGSName+"</div>";
        s += "<div><input type='text' id='"+txtNameID+"' width='120' style='"+windowTextBox+"' /></div>";
        s += "<div style='"+windowBodyText+"'>"+pGSEmail+"</div>";
        s += "<div><input type='text' id='"+txtEmailID+"' width='120' style='"+windowTextBox+"' /></div>";
        s += "</td></tr></table></td><td rowspan='2' style='"+btmButtonAreaRight+"'></td></tr>";
       
        // bottom row (where chat invite button is)
        s += "<tr><td colspan='2'><table style='width: 100%;' cellpadding='0' cellspacing='0'><tr>";
        s += "<td style='"+btmButtonAreaLeft+"'></td>";
        s += "<td style='"+btmButtonAreaTile+"'>";
        s += "<table style='"+tableMax+"' cellpadding='0' cellspacing='0'><tr>";
        s += "<td style='"+btmButtonArrow+"'><img src='"+invitationDir+"BlueBtn/Arrow.gif' /></td>";
        s += "<td style='"+btmButtonArea+"'><table cellpadding='0' cellspacing='0'<tr><td>";
        
        // Accept button
        s += "<a style='"+anchorStyle+cursorStyle+"' onmouseover=\"OnButton1Over('"+randomIdentifier+"', '"+invitationDir+"');\" ";
        s += "onmouseout=\"OnButton1Out('"+randomIdentifier+"', '"+invitationDir+"');\" href='javascript:STHrefNull();' ";
        s += "onClick=\"AcceptMessage('"+acceptResponseUrl+"', '"+interactId+"', '"+txtNameID+"', '"+txtEmailID+"');\"><table cellpadding='0' cellspacing='0'><tr>";
        s += "<td id='"+leftTileID+"' style='"+buttonLeftTile+"'></td>";
        s += "<td id='"+centerTileID+"' style='"+buttonCenterTile+"'><span style='"+buttonBlueText+"'>"+pGSAccept+"</span></td>";
        s += "<td id='"+rightTileID+"' style='"+buttonRightTile+"'></td></tr></table></a></td>";
        
        // Spacer
        s += "<td style='"+buttonSpacer+"'></td><td>";
        
        // Reject button
        s += "<a style='"+anchorStyle+cursorStyle+"' onmouseover=\"OnButton2Over('"+randomIdentifier+"', '"+invitationDir+"');\" ";
        s += "onmouseout=\"OnButton2Out('"+randomIdentifier+"', '"+invitationDir+"');\" href='javascript:STHrefNull();' ";
        s += "onClick=\""+closeAction+"\">";
        s += "<table cellpadding='0' cellspacing='0'><tr>";
        s += "<td id='"+leftRejectTileID+"' style='"+buttonLeftTile+"'></td>";
        s += "<td id='"+centerRejectTileID+"' style='"+buttonCenterTile+"'><span style='"+buttonBlueText+"'>"+pGSReject+"</span></td>";
        s += "<td id='"+rightRejectTileID+"' style='"+buttonRightTile+"'></td></tr></table></a></td></tr></table></td>";
        s += "</tr></table></td></tr></table></td></tr>";
        
        // ends table container
        s += "</table>";
        
        interactArea.innerHTML = s;
        
        var MovableBar = document.getElementById(MovableBarAreaID);
        if (MovableBar)
        {
            MovableBar.onmousedown = OnMouseInviteDown;
            MovableBar.onmouseup = OnMouseInviteUp;
            MovableInvite = interactArea;
        }
        setTimeout("CloseMessage('"+interactId+"');STInjectScript('&inputparameter=ChatInviteState%3DIgnored%5E"+pUsrID+"', '');", pTimeTillAbandon);
    }
}
function TrackingMessageDecoder(message)
{    
    var retVal = message.replace("+", " ");
    while (retVal.indexOf("+") > -1)
        retVal = retVal.replace("+", " ");
        
    retVal = unescape(retVal);
    
    while (retVal.indexOf("%@SQUOTE@%") > -1)
        retVal = retVal.replace("%@SQUOTE@%", "\'");
        
    while (retVal.indexOf("%@DQUOTE@%") > -1)    
        retVal = retVal.replace("%@DQUOTE@%", "\"");
        
    return retVal;
}
function EscapeTitle()
{
    var retVal = document.title;
    
    var numQuotes = 0;
    for (var i = 0; i < retVal.length; i++)
    {
        if (retVal[i] == "'")
            numQuotes += 1;
    }
    for (var i = 0; i <= numQuotes; i++)
        retVal = retVal.replace("'", "%SQUOTE%");
   
    return retVal;
}
function STInjectScript(inputQS, outputID)
{
    var portalUrlCook = get_cookie("PortalUrl");
    if (portalUrlCook != "")
    {
       var rid = Math.round(Math.random()*2147483647);
       var head = document.getElementsByTagName("head")[0];
       var script = document.createElement("script");
       script.type = "text/javascript";
       
       var interactAreaId = "";
       if (outputID != "")
       {
           interactAreaId = "&interactId="+outputID;
       }
       
       script.src = portalUrlCook + "ST.ashx?PostID="+rid+inputQS+"&visitorId="+GetVisitorCookie()+interactAreaId;
       head.appendChild(script);
   }
}
function OnButton1Over(idPrefix, imageDir)
{
    var leftTileID = idPrefix+"_leftChatTile";
    var centerTileID = idPrefix+"_centerChatTile";
    var rightTileID = idPrefix+"_rightChatTile";
    
    document.getElementById(leftTileID).style.backgroundImage = "url("+imageDir+"BlueBtn/StartBtn_LeftCap_Over.gif)";
    document.getElementById(centerTileID).style.backgroundImage = "url("+imageDir+"BlueBtn/StartBtn_Tile_Over.gif)";
    document.getElementById(rightTileID).style.backgroundImage = "url("+imageDir+"BlueBtn/StartBtn_RightCap_Over.gif)";
}
function OnButton1Out(idPrefix, imageDir)
{
    var leftTileID = idPrefix+"_leftChatTile";
    var centerTileID = idPrefix+"_centerChatTile";
    var rightTileID = idPrefix+"_rightChatTile";
    
    document.getElementById(leftTileID).style.backgroundImage = "url("+imageDir+"BlueBtn/StartBtn_LeftCap.gif)";
    document.getElementById(centerTileID).style.backgroundImage = "url("+imageDir+"BlueBtn/StartBtn_Tile.gif)";
    document.getElementById(rightTileID).style.backgroundImage = "url("+imageDir+"BlueBtn/StartBtn_RightCap.gif)";
}
function OnButton2Over(idPrefix, imageDir)
{
    var leftTileID = idPrefix+"_leftRejectTile";
    var centerTileID = idPrefix+"_centerRejectTile";
    var rightTileID = idPrefix+"_rightRejectTile";
    
    document.getElementById(leftTileID).style.backgroundImage = "url("+imageDir+"BlueBtn/StartBtn_LeftCap_Over.gif)";
    document.getElementById(centerTileID).style.backgroundImage = "url("+imageDir+"BlueBtn/StartBtn_Tile_Over.gif)";
    document.getElementById(rightTileID).style.backgroundImage = "url("+imageDir+"BlueBtn/StartBtn_RightCap_Over.gif)";
}
function OnButton2Out(idPrefix, imageDir)
{
    var leftTileID = idPrefix+"_leftRejectTile";
    var centerTileID = idPrefix+"_centerRejectTile";
    var rightTileID = idPrefix+"_rightRejectTile";
    
    document.getElementById(leftTileID).style.backgroundImage = "url("+imageDir+"BlueBtn/StartBtn_LeftCap.gif)";
    document.getElementById(centerTileID).style.backgroundImage = "url("+imageDir+"BlueBtn/StartBtn_Tile.gif)";
    document.getElementById(rightTileID).style.backgroundImage = "url("+imageDir+"BlueBtn/StartBtn_RightCap.gif)";
}

var OnMouseInviteDown = function(e)
{
    try
    {
        if (MovableInvite)
        {
            IsInviteMoving = true;
        }
        if (navigator.appName == "Netscape")
        {
            WindowPosX = e.layerX;
            WindowPosY = e.layerY;
        }
        else
        {
            WindowPosX = event.offsetX;
            WindowPosY = event.offsetY;
        }  
    }  
    catch (err) { }
}
var OnMouseInviteUp = function(e)
{
    IsInviteMoving = false;
}
document.OnMouseUpInviteListener = function(evt)
{
    IsInviteMoving = false;
}
document.OnMouseMoveInviteListener = function(evt)
{
    try
    {
        var winWidth = 0;
        var winHeight = 0;
        if (parseInt(navigator.appVersion)>3) 
        {
            if (navigator.appName=="Netscape") 
            {
                if (document.body.offsetHeight && document.body.offsetWidth)
                {
                    winWidth = document.body.offsetWidth;
                    winHeight = document.body.offsetHeight;
                }
                else
                {
                    winWidth = window.innerWidth;
                    winHeight = window.innerHeight;
                }
            }
            if (navigator.appName.indexOf("Microsoft")!=-1)
            {
                winWidth = document.body.offsetWidth;
                winHeight = document.body.offsetHeight;
            }
        }
        
        
        if (IsInviteMoving && MovableInvite != null)
        {
            if (navigator.appName == "Netscape")
            {
                if (evt.pageX < winWidth)
                    MovableInvite.style.left = (evt.pageX - WindowPosX) + 'px';
                if (evt.pageY < winHeight)
                    MovableInvite.style.top = (evt.pageY - WindowPosY) + 'px';
            }
            else
            {
                if (event.clientX < winWidth)
                    MovableInvite.style.left = event.clientX-WindowPosX + document.body.scrollLeft + 'px';
                if (event.clientY < winHeight)
                    MovableInvite.style.top = event.clientY-WindowPosY + document.body.scrollTop + 'px';
            }
            return false;
        }
    }
    catch (err) { }
}
AddHandler(document, "mousemove", "OnMouseMoveInviteListener");
AddHandler(document, "mouseup", "OnMouseUpInviteListener");
function AddHandler(target,eventName,handlerName) 
{
	if (target.addEventListener)
	{
		target[eventName + handlerName] = function(e){return target[handlerName](e)};
		target.addEventListener(eventName, target[eventName + handlerName], false);
	}
	else if (target.attachEvent)
	{
		target[eventName + handlerName] = function(e){return target[handlerName](e)};
		target.attachEvent("on" + eventName, target[eventName + handlerName]);
	}
	else 
	{ 
		var originalHandler = target["on" + eventName]; 
		if (originalHandler)
		{
			target[eventName + handlerName] = function(e){originalHandler(e); return target[handlerName](e);};
			target["on" + eventName] = target[eventName + handlerName]; 
		}
		else 
		{
			target["on" + eventName] = target[handlerName]; 
		}
    } 
}