
//max number of times to create custom invite before aborting
var LP_CUSTOM_INVITE_MAX_LOOPS = 5;

function lpCreateCustomInvitation() 
{

    var lpCustomInnerInvitationHtml = "";
    var lpForceInviteCreate = false;
    
    //Wait for the Monitor tag to create the original "mylayer" DIV (that's where the standard invitation is created)
    if (!document.getElementById("mylayer")) 
     {
     
        //Loop no more than LP_CUSTOM_INVITE_MAX_LOOPS times, to avoid endless loop in case
        //the DIV is not found
        if(LP_CUSTOM_INVITE_MAX_LOOPS > 0)
        {
            LP_CUSTOM_INVITE_MAX_LOOPS--;
            setTimeout('lpCreateCustomInvitation()', 1000);
            return;
        }
        else
        {
            //Max loops has passed, so mark we need to create the invitation
            lpForceInviteCreate = true;
        }
    }

// invite contents begin here

    lpCustomInnerInvitationHtml = '';
    lpCustomInnerInvitationHtml += '<div id="ibm-dialog">';
    lpCustomInnerInvitationHtml += '<div id="ibm-com">';
    lpCustomInnerInvitationHtml += '<div id="ibm-top">';
    lpCustomInnerInvitationHtml += '<div id="ibm-masthead">';
    lpCustomInnerInvitationHtml += '<div id="ibm-logo"><a href="http://www.ibm.com/us/en/"><img alt="IBM®" src="//www.ibm.com/i/v16/t/ibm-logo-small.gif" height="26" width="54" /></a></div>';
    lpCustomInnerInvitationHtml += '<h1>Chat now with an IBM representative</h1>';
    lpCustomInnerInvitationHtml += '</div>';
    lpCustomInnerInvitationHtml += '<div id="ibm-pcon">';
    lpCustomInnerInvitationHtml += '<div id="ibm-content">';
    lpCustomInnerInvitationHtml += '<!-- TITLE_BEGIN -->';
    lpCustomInnerInvitationHtml += '<div id="ibm-content-head">';
    lpCustomInnerInvitationHtml += '</div>';
    lpCustomInnerInvitationHtml += '<!-- TITLE_END -->';
    lpCustomInnerInvitationHtml += '<div id="ibm-content-body">';
    lpCustomInnerInvitationHtml += '<div id="ibm-content-main">';
    lpCustomInnerInvitationHtml += '<div class="ibm-container ibm-alternate">';
    lpCustomInnerInvitationHtml += '<div class="ibm-container-body">';
    lpCustomInnerInvitationHtml += '<img src="http://www.ibm.com/software/main/img/com/lp-lot-invite-350x100.gif" alt="" width="350" height="100" border="0" />';
    lpCustomInnerInvitationHtml += '<h2>Welcome to IBM Lotus!</h2>';
    lpCustomInnerInvitationHtml += '<p>An IBM Lotus representative can assist you with selecting the product that best suits your needs.';
    lpCustomInnerInvitationHtml += ' Click "Chat now" for a live text chat with an IBM Lotus representative.</p>';
    lpCustomInnerInvitationHtml += '<form><div class="ibm-buttons-row">';
    lpCustomInnerInvitationHtml += '<p class="ibm-first"><input value=" Chat now" type="submit" onclick="return hcAcceptCall();" name="ibm-submit" class="ibm-btn-arrow-pri" /></p>';
    lpCustomInnerInvitationHtml += '<p class="ibm-second"><input value=" No, thanks" type="reset" onclick="return hcRejectCall();" name="ibm-cancel" class="ibm-btn-cancel-sec" /></p>';
    lpCustomInnerInvitationHtml += '</div>';
    lpCustomInnerInvitationHtml += '</form>';
    lpCustomInnerInvitationHtml += '<p>Chat service provided by IBM in conjunction with LIVEperson.</p>';
    lpCustomInnerInvitationHtml += '</div>';
    lpCustomInnerInvitationHtml += '</div>';
    lpCustomInnerInvitationHtml += '</div>';
    lpCustomInnerInvitationHtml += '</div>';
    lpCustomInnerInvitationHtml += '</div>';
    lpCustomInnerInvitationHtml += '</div>';



    lpCustomInnerInvitationHtml += '<div id="ibm-footer-d">';
    lpCustomInnerInvitationHtml += '<ul>';
    lpCustomInnerInvitationHtml += '<li class="ibm-first"><a href="http://www.ibm.com/legal/us/en/">Terms of use</a></li>';
    lpCustomInnerInvitationHtml += '<li><a href="http://www.ibm.com/privacy/us/en/">Privacy</a></li>';
    lpCustomInnerInvitationHtml += '<li class="ibm-close-link"><a href="" onClick="return hcRejectCall();">Close [ x ]</a></li>';
    lpCustomInnerInvitationHtml += '</ul>';
    lpCustomInnerInvitationHtml += '</div>';

    lpCustomInnerInvitationHtml += '</div>';
    lpCustomInnerInvitationHtml += '</div>';
    lpCustomInnerInvitationHtml += '</div>';

// invite contents end here

//if need to create the DIV
    if(lpForceInviteCreate)
    {
        //call a method of the Monitor tag to create the div with our own content
        lpCreateGenericDiv('mylayer', 200, 170, 90, lpInnerInvitationHtml, null, null, false);
    }
    else
    {
         //replace current invitation content with custom one
         document.getElementById("mylayer").innerHTML = lpCustomInnerInvitationHtml;
    }
    
    //mark the invitation has loaded
     hcFloatIconLoaded();
    
    //If needed, modify any styling details of the invitation DIV now (e.g, change width and height)
    //document.getElementById("mylayer").style.width = "311px";
    document.getElementById("mylayer").style.backgroundColor = "#fff";
    document.getElementById("mylayer").style.border = "solid 1px #000";
    document.getElementById("mylayer").top = "215px";
    document.getElementById("mylayer").left = "240px";
    
}

//call method to create custom invite
lpCreateCustomInvitation();

function openChat(param, openVars, isAuto)
{
    if (typeof(isAuto) == "undefined")
        isAuto = false;

	visitorStatus = "CHAT_STATUS";
	var s = document.location;
	if (param != null)
		s = "(" + param + ") " + s;
	s = escape(s);

    var oparms = "";
    if (openVars != null)
        oparms = oparms + "&" + openVars;

    var url;
    var name;
    if (lpVoiceEngageFlag)
    {
        url = hcBase + '?cmd=file&file=visitorWantsToCallback' + oparms + '&site='+lpNumber+'&d=' + hcDate()+'&referrer='+s;
        name = 'call'+lpNumber;
    } else
    {
        url = hcBase + '?cmd=file&file=visitorWantsToChat' + oparms + '&site='+lpNumber+'&channel=web'+'&d=' + hcDate()+'&referrer='+s;
        name = 'chat'+lpNumber;
    }

    var params = 'top=90,left=170,width=365,height=470,menubar=no,scrollbars=0';
    if (lpVoiceEngageFlag && (typeof(lpOpenVoice) == "function")) {
        lpOpenVoice(url, name, params);
    } else
    if ((! lpVoiceEngageFlag) && (typeof(lpOpenChat) == "function")) {
        lpOpenChat(url, name, params);
    } else {
        var ow = window.open(url, name, params);
        if ((ow == null) && isAuto)
            openEngageChat("engage", null);
    }
}
