//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;
        }
    }
    
    //set the invitation content into the lpCustomInnerInvitationHtml variable(WITHOUT THE WRAPPING DIV)
    lpCustomInnerInvitationHtml = '';
    lpCustomInnerInvitationHtml += '<div id="popcontent"><h3 class="bbg">Chat with an IBM representative</h3><h4 class="smtit">IBM Systems</h4>';
	lpCustomInnerInvitationHtml += '<p><strong>Welcome!</strong></p>';
	lpCustomInnerInvitationHtml += '<p>Let us help you with selecting the product or solution that best suits your needs.</p>';
	lpCustomInnerInvitationHtml += '<p>Click "Chat now" for live text chat with an IBM Systems representative.</p>';
	lpCustomInnerInvitationHtml += '<p><a class="fbox okchat" name="needRef" id="needRef" href="#" onclick="return hcAcceptCall();"><strong>Chat now</strong></a>';
	lpCustomInnerInvitationHtml += '<a class="fbox cancelchat" href="#" onclick="return hcRejectCall();"><strong>No, thanks</strong></a></p>';
	lpCustomInnerInvitationHtml += '<p>Chat service provided by IBM in conjunction with&nbsp;LIVEperson.</p></div>';
	lpCustomInnerInvitationHtml += '<div class="popupfooter"><a href="#" class="mainlink" onClick="return hcRejectCall();">Close [x]</a></div>';




    //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 = "315px";
    document.getElementById("mylayer").style.backgroundColor = "#fff";
    document.getElementById("mylayer").style.border = "solid 1px #000";
	document.getElementById("mylayer").style.textAlign = "left";
	document.getElementById("mylayer").style.fontSize = "12px";	
    //document.getElementById("mylayer").top = "90px";
    //document.getElementById("mylayer").left = "170px";
    
}

//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);
    }
}

