﻿// Copyright (C) 2007 InstantService, Inc. All rights reserved. 
// All content is protected under U.S. copyright laws. Any unauthorized duplication, modification, 
// or reverse-engineering of this code without express written permission of InstantService, Inc. 
// is a violation of copyright law and is subject to penalty and prosecution.  
// This comment and the 4 lines above may not be removed from this file.
function ISVT_onInviteNotOffered(isvt_rid,isvt_iid){
var nv='?ai='+ISVT_ai+'&evt=20&ri='+isvt_rid+'&ii='+isvt_iid;
ISVT_callTS(ISVT_scr,nv);}
function ISVT_onInviteOffered(isvt_rid,isvt_iid){
var nv='?ai='+ISVT_ai+'&evt=21&ri='+isvt_rid+'&ii='+isvt_iid;
ISVT_callTS(ISVT_scr,nv);}
function ISVT_onInviteAccepted(isvt_iid,isvt_di){
var nv='?ai='+ISVT_ai+'&evt=22&ii='+isvt_iid+'&di='+isvt_di;
ISVT_callTS(ISVT_scr,nv);}
function ISVT_onInviteDeclined(isvt_iid,isvt_di){
var nv='?ai='+ISVT_ai+'&evt=23&ii='+isvt_iid+'&di='+isvt_di;
ISVT_callTS(ISVT_scr,nv);}
function ISVT_onQueueUnavailable(isvt_di){
var nv='?ai='+ISVT_ai+'&evt=30&di='+isvt_di;
ISVT_callTS(ISVT_scr,nv);}
function ISVT_onEnteredQueue(isvt_cui,isvt_di){
var nv='?ai='+ISVT_ai+'&evt=31&cui='+isvt_cui+'&di='+isvt_di;
ISVT_callTS(ISVT_scr,nv);}
function ISVT_onChatWithAgent(isvt_cui,isvt_ci,isvt_di,isvt_sq){
var nv='?ai='+ISVT_ai+'&evt='+((isvt_sq==0)?'32':'33')+'&cui='+isvt_cui+'&ci='+isvt_ci+'&di='+isvt_di;
ISVT_callTS(ISVT_scr,nv);}
function ISVT_onMailMessagePosted(isvt_di){
if(ISVT_mmp==1)return;
var nv='?ai='+ISVT_ai+'&evt=40&di='+isvt_di;
ISVT_callTS(ISVT_scr,nv);ISVT_mmp=1;}
function ISVT_onConversion(isvt_cvi,isvt_cv,isvt_type,isvt_cd1){
var argv = ISVT_onConversion.arguments;  
var argc = ISVT_onConversion.arguments.length;  
var isvt_cd2 = (argc > 4) ? argv[4] : null;  
var isvt_cd3 = (argc > 5) ? argv[5] : null;  
var isvt_cd4 = (argc > 6) ? argv[6] : null;  
var isvt_cd5 = (argc > 7) ? argv[7] : null;  
var evt=((isvt_type == 0) ? 50 : 51);
var nv='?ai='+ISVT_ai+'&evt='+evt+'&cvi='+isvt_cvi+'&cv='+isvt_cv;
if (isvt_cd1.length > 0) nv+='&cd1='+ISVT_encode(isvt_cd1);
if (isvt_cd2 != null && isvt_cd2.length > 0) nv+='&cd2='+ISVT_encode(isvt_cd2);
if (isvt_cd3 != null && isvt_cd3.length > 0) nv+='&cd3='+ISVT_encode(isvt_cd3);
if (isvt_cd4 != null && isvt_cd4.length > 0) nv+='&cd4='+ISVT_encode(isvt_cd4);
if (isvt_cd5 != null && isvt_cd5.length > 0) nv+='&cd5='+ISVT_encode(isvt_cd5);
ISVT_callTS(ISVT_scr,nv);}
  
function ISVT_callTS(isvt_scr, isvt_nv){
var vtid = ISVT_getVTID();
if (vtid != null && vtid != "") isvt_nv += '&vti=' + vtid;
if (isvt_scr.length > 0 && document.getElementById) {
  var head = document.getElementsByTagName('head').item(0);
  var old  = document.getElementById('vtscript');
  if (old) head.removeChild(old);
  vtscr = document.createElement('script');
  vtscr.src = isvt_scr + isvt_nv;
  vtscr.type = 'text/javascript';
  vtscr.defer = true;
  vtscr.id = 'vtscript';
  void(head.appendChild(vtscr));
}}

function ISVT_getVTID(){  
if (typeof window.ISVT_tid != 'undefined') return ISVT_tid;
var arg = "isvt_visitor=";  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {    
  var j = i + arg.length;    
  if (document.cookie.substring(i, j) == arg) {   
    var endstr = document.cookie.indexOf (";", j);  
    if (endstr == -1) endstr = document.cookie.length;  
    return unescape(document.cookie.substring(j, endstr));
  }
  i = document.cookie.indexOf(" ", i)+1;    
  if (i == 0) break;   
}return null;}

function ISVT_encode(s){
if (ISVT_hex == null){
  ISVT_hex = new Array(256);
  for (var i=0;i<256;i++){
    if (i < 16) ISVT_hex[i] = "%0" + i.toString(16);
    else ISVT_hex[i] = "%" + i.toString(16);
  }
}
if (s == null) return;
var sbuf = "";
for (i = 0; i < s.length; i++){
  var ch = s.charAt(i);
  var chCode = s.charCodeAt(i);
  if ("A"<=ch && ch<="Z") sbuf = sbuf.concat(ch);
  else if ("a"<=ch && ch<="z") sbuf = sbuf.concat(ch);
  else if ("0"<=ch && ch<="9") sbuf = sbuf.concat(ch);
  else if (ch==" ") sbuf = sbuf.concat("+");
  else if (ch=="-" || ch=="_" || ch=="." || ch=="!" || ch=="~" || ch=="*" || ch=="(" || ch==")") sbuf = sbuf.concat(ch);
  else if (chCode <= parseInt("007f",16)) sbuf = sbuf.concat(ISVT_hex[chCode]);
  else if (chCode <= parseInt("07ff")){              
    var idxCode0 = parseInt("c0",16) | (chCode >> 6);
    var idxCode1 = parseInt("80",16) | (chCode & parseInt("3f",16));
    sbuf = sbuf.concat(ISVT_hex[idxCode0]);
    sbuf = sbuf.concat(ISVT_hex[idxCode1]);
  } 
  else{              
    var idxCode0 = parseInt("e0",16) | (chCode >> 12);
    var idxCode1 = parseInt("80",16) | ((chCode >> 6) & parseInt("3f",16));
    var idxCode2 = parseInt("80",16) | (chCode & parseInt("3f",16));
    sbuf = sbuf.concat(ISVT_hex[idxCode0]);
    sbuf = sbuf.concat(ISVT_hex[idxCode1]);
    sbuf = sbuf.concat(ISVT_hex[idxCode2]);
  }
}return sbuf;}

function ISVT_setCookie(isvt_name, isvt_value){
if (typeof window.ISVT_tid != 'undefined') return;
var expires = new Date();
if (30 == 0) expires = null;
else expires.setTime(expires.getTime() + (30*24*60*60*1000));
var domain=ISVT_getDomain();
document.cookie=isvt_name+"="+escape(isvt_value)+
((expires==null)?"":(";expires="+expires.toGMTString()))+
";path=/"+((domain == null||domain=="")?"":(";domain="+ domain));}

function ISVT_getDomain(){ 
var dom = document.domain;
var arr = dom.split('.');
if (arr.length == 3) dom = arr[1] + '.' + arr[2];
else if (arr.length > 3) dom = arr[arr.length-3] + '.' + arr[arr.length-2] + '.' + arr[arr.length-1];
return(dom);}

var ISVT_hex=null;
var ISVT_mmp=0;
var ISVT_prtcl=document.location.protocol.indexOf("https")!=-1?"https://":"http://";
var ISVT_scr=ISVT_prtcl+'ts.istrack.com/trackingAPI.js';
var ISVT_ai='qq58S2mEuHNcyMUndnIpK+NoJdfVOT1z';
if(document.all && !document.getElementById) document.getElementById = function(id) { return document.all[id]; }
if (ISVT_getVTID() == null) ISVT_callTS(ISVT_scr, '?ai='+ISVT_ai);

//Click-to-chat

// IF AGENTS ARE AVAILABLE: 
function agents_available() {
    var availableHTML  = '<A HREF="" alt="'+strLiveChat+'" title="'+strLiveChat+'" onClick="dcsMultiTrack(\'DCS.dcsuri\', \'\', \'WT.ti\', \'Live Chat\' , \'WT.dl\', \'20\', \'WT.si_n\', \'Datasheet Download\', \'WT.si_x\', \'1\', \'WT.si_cs\', \'1\'); window.open(\'https://admin.instantservice.com/Customer?ai='+strLiveChatAccountId+'&di='+strLiveChatDepartmentId+'&optionaldata5='+window.location+'&optionaldata6='+document.referrer+'&trackingid='+ISVT_getVTID()+'\',\'custclient\',\'width=500,height=320,scrollbars=0\');return false;">'+strLiveChat+'</A>';
    var availableHTML1 = '<A HREF="" onClick="dcsMultiTrack(\'DCS.dcsuri\', \'\', \'WT.ti\', \'Live Chat\' , \'WT.dl\', \'20\', \'WT.si_n\', \'Datasheet Download\', \'WT.si_x\', \'1\', \'WT.si_cs\', \'1\'); window.open(\'https://admin.instantservice.com/Customer?ai='+strLiveChatAccountId+'&di='+strLiveChatDepartmentId+'&optionaldata5='+window.location+'&optionaldata6='+document.referrer+'&trackingid='+ISVT_getVTID()+'\',\'custclient\',\'width=500,height=320,scrollbars=0\');return false;">here</A>&nbsp;';
    if (document.getElementById('smartbutton'))
    {
        document.getElementById('smartbutton').innerHTML = "&nbsp;|&nbsp;&nbsp;" + availableHTML;
        if (document.getElementById('smartbuttonlist'))
        {
            document.getElementById('smartbuttonlist').style.display = "block";
        }
    }
    if (document.getElementById('smartbutton1'))
    {
        document.getElementById('smartbutton1').innerHTML = availableHTML;
        if (document.getElementById('smartbutton1list'))
        {
            document.getElementById('smartbutton1list').style.display = "block";
        }
    }
    if (document.getElementById('smartbutton2'))
    {
        document.getElementById('smartbutton2').innerHTML = availableHTML;
        if (document.getElementById('smartbutton2list'))
        {
            document.getElementById('smartbutton2list').style.display = "block";
        }
    }
    //Product Recommender
    if (document.getElementById('smartbutton3'))
    {
        document.getElementById('smartbutton3').innerHTML = availableHTML1;
        if (document.getElementById('smartbutton3list'))
        {
            document.getElementById('smartbutton3list').style.display = "block";
        }
    }
    if (document.getElementById('smartbutton4'))
    {
        document.getElementById('smartbutton4').innerHTML = availableHTML1;
        if (document.getElementById('smartbutton4list'))
        {
            document.getElementById('smartbutton4list').style.display = "block";
        }
    }
    return true; 
} 
  
// IF AGENTS ARE NOT AVAILABLE: 
function agents_not_available() {
    var unavailableHTML = '';
    if (document.getElementById('smartbutton'))
    {
        document.getElementById('smartbutton').innerHTML = unavailableHTML;
        if (document.getElementById('smartbuttonlist'))
        {
            document.getElementById('smartbuttonlist').style.display = "none";
        }
    }
    if (document.getElementById('smartbutton1'))
    {
        document.getElementById('smartbutton1').innerHTML = unavailableHTML;
        if (document.getElementById('smartbutton1list'))
        {
            document.getElementById('smartbutton1list').style.display = "none";
        }
    }
    if (document.getElementById('smartbutton2'))
    {
        document.getElementById('smartbutton2').innerHTML = unavailableHTML;
        if (document.getElementById('smartbutton2list'))
        {
            document.getElementById('smartbutton2list').style.display = "none";
        }
    }
    if (document.getElementById('smartbutton3'))
    {
        document.getElementById('smartbutton3').innerHTML = unavailableHTML;
        if (document.getElementById('smartbutton3list'))
        {
            document.getElementById('smartbutton3list').style.display = "none";
        }
    }
    if (document.getElementById('smartbutton4'))
    {
        document.getElementById('smartbutton4').innerHTML = unavailableHTML;
        if (document.getElementById('smartbutton4list'))
        {
            document.getElementById('smartbutton4list').style.display = "none";
        }
    }
    return true; 
}
