//-------------------------------------------------------------------------------------
// Contains JavaScript specific to click-to-chat functionality using the Instant Service 
// chat vendor. This code has been cut and pasted from the Instant Service documentation 
// and modified extensively in order to integrate into the "Request Info Console" which 
// contains chat, call/talk, "ask a question", and "info request" features.
//-------------------------------------------------------------------------------------

mbInstantServiceCheckDone = false;

//-------------------------------------------------------------------------------------
// Displays the Instant Service vendor's chat window. Note: This function is not
// provided by Instant Service vendor and can be modified and used in the future 
// should another vendor be used in place of Instant Service.
//-------------------------------------------------------------------------------------
function ShowInstantServiceChatWindow() {

    //alert("Into ShowInstantServiceChatWindow...");

    var sUrl;
    
    sUrl = "https:";
    sUrl += "//admin.instantservice.com/links/6294/23898";
    //*** GoldRam Note: *** Replaced URL with the following to facilitate conversion tracking.
    //sUrl +='//admin.instantservice.com/Customer?ai=6294&di=23898&trackingid=' + encodeURIComponent(ISVT_getVTID());
    
    var sOptions = "width=600,height=400,scrollbars=0";
    
    window.open(sUrl,"custclient",sOptions);
    
}

//-------------------------------------------------------------------------------------
// Check to see if agents are available. This function is is specific to the 
// Instant Service vendor and has been modified from original function with same name 
// provided by Instant Service.
//-------------------------------------------------------------------------------------
function agents_available() 
{
    //TESTING ERROR HANDLER
    //agents_not_available();
    //return;

    if (mbInstantServiceCheckDone) return;
    
    //alert("Into agents_available...");

    var sUrl;

    sUrl = "http:"
    sUrl += "//admin.instantservice.com/resources/smartbutton/6294/23898/available.gif?";
    sUrl += Math.floor(Math.random() * 10001);

    $("InstSvcStatus").src = sUrl;

    $("Click2ChatLink1").href = "javascript:ShowInstantServiceChatWindow();";
    $("Click2ChatLink2").href = "javascript:ShowInstantServiceChatWindow();";
    $("Click2ChatTriggerImage").src = "reqinfo/images/ConsoleClick2ChatOnline.jpg";
    $("Click2ChatTriggerText3").innerHTML = "Live operators online now!";

    mbInstantServiceCheckDone = true;
    
    return true; 
}

//-------------------------------------------------------------------------------------
// Called via the error handler in the InstSvcStatus image object when agents are not 
// available. This function is is specific to the Instant Service vendor and has been 
// modified from original function with same name provided by Instant Service.
//-------------------------------------------------------------------------------------
function agents_not_available() 
{
    //alert("Error handler invoked");

    var sBody;
    var sSubject;
    sSubject = "LeTourneau University Information Request";
    sBody = "(Send this email to the email address above. A LeTourneau University representative ";
    sBody += "will contact you soon. Thank you for your interest!)"

    $("Click2ChatLink1").onclick = "";
    $("Click2ChatLink2").onclick = "";
    $("Click2ChatLink1").href = "mailto:LETU@etechinc.com?subject=" + sSubject + "&body=" + sBody
    $("Click2ChatLink2").href = "mailto:LETU@etechinc.com?subject=" + sSubject + "&body=" + sBody
    //$("Click2ChatTrigger").src ="images/ConsoleClick2ChatOffline.jpg";
    $("Click2ChatTriggerImage").src ="reqinfo/images/ConsoleClick2ChatOnline.jpg";
    $("Click2ChatTriggerText3").innerHTML = "No operators currently available. Please click to send an email.";
    
    return true;
}
