var WebchatFolder = '/visitor'; var http; //Used for polling var httpSend; //Used for sending client messages to server function createRequestObject() { var request = null; try { request = new XMLHttpRequest(); } catch (trymicrosoft) { try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (othermicrosoft) { try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) { request = null; } } } if (request == null) alert("Error creating request object! Browser not supported"); return request; } http = createRequestObject(); httpSend = createRequestObject(); function XML_GetTag(strXMLBlock, strXMLTag) { var lTagStart; var lTagEnd; var strReturnString = ''; // Look for the tag given lTagStart = strXMLBlock.indexOf('<' + strXMLTag + '>'); if (lTagStart != -1) { // found it lTagStart = lTagStart + strXMLTag.length + 2; lTagEnd = strXMLBlock.indexOf('', lTagStart); if (lTagEnd != -1) { strReturnString = strXMLBlock.substr(lTagStart, lTagEnd - lTagStart); } } return strReturnString; } function XML_GetTags(strXMLBlock, strXMLTag) { var lTagStart; var lTagEnd; var arrArray = []; var strContents; // Look for the tag given lTagStart = strXMLBlock.indexOf('<' + strXMLTag + '>'); while (lTagStart != -1) { // found it lTagStart = lTagStart + strXMLTag.length + 2; lTagEnd = strXMLBlock.indexOf('', lTagStart); if (lTagEnd != -1) { strContents = strXMLBlock.substr(lTagStart, lTagEnd - lTagStart); arrArray.push(strContents); lTagStart = strXMLBlock.indexOf('<' + strXMLTag + '>', lTagEnd + strXMLTag.length + 3); } else { lTagStart = -1; } } return arrArray; } function RequestInProgress() { return (http.readyState != 0 && http.readyState != 4) } function sndMsg(action, param) { //Used for client sending messages //create a new request object, because we can't reset the readystate //property of the object once it's been used, and we are using that //property to determine whether a request is in progress. httpSend = createRequestObject(); var params = 'action='+ escape(action) + '&arg='+ escape(param); if (httpSend != null) { httpSend.open('POST', WebchatFolder + '/MsgHandler.aspx' ); //Send the proper header information along with the request httpSend.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); httpSend.setRequestHeader("Content-length", params.length); httpSend.setRequestHeader("Connection", "close"); httpSend.onreadystatechange = handleResponse; try { httpSend.send(params); } catch(e) { alert('Failed to contact server. Please try again'); } } } function sndReq(action, param) { //Used for polling based on timers //create a new request object, because we can't reset the readystate //property of the object once it's been used, and we are using that //property to determine whether a request is in progress. http = createRequestObject(); if (http != null) { http.open('get', WebchatFolder + '/MsgHandler.aspx?action='+ action + '&arg='+ param ); http.onreadystatechange = handleResponse; try { http.send(null); } catch(e) { //alert('Failed to contact server. Please try again'); var ChatStatus = document.getElementById('ChatStatus'); if ( ChatStatus != null ) { ChatStatus.innerHTML = '

Error!

'; txtMsg.disabled=true; txtMsg.value = str_NoAgentText; imgSend.src = 'senddisabled.gif'; imgSend.className = "Disabled"; } } } } function sndReqEx(page, action, param) { //Used for polling based on timers //create a new request object, because we can't reset the readystate //property of the object once it's been used, and we are using that //property to determine whether a request is in progress. http = createRequestObject(); if (http != null) { http.open('get', WebchatFolder + '/' + page + '?action='+ action + '&arg='+ param ); http.onreadystatechange = handleResponse; try { http.send(null); } catch(e) { alert('Failed to contact server. Please try again'); } } }// JScript File function handleTopics(XML) { var TopicID; var TopicName; var comboHTML = ''; var count = 1; var cboTopics; var selectedItem = -1; var strCurrentTopic; var bFound = false; var Data = XML_GetTag(XML, 'DATA'); var ConnStatus = XML_GetTag(XML, 'CONN_STATUS'); var divOnline = document.getElementById('ChatOnline'); var divOffline = document.getElementById('ChatOffline'); var divInitialising = document.getElementById('ChatInitialising'); if (divInitialising != null) { divInitialising.style.display = 'none'; } if ( divOnline != null && divOffline != null ) { if (ConnStatus == 'False') { divOffline.style.display = 'inline'; divOnline.style.display = 'none'; } else { TopicID = XML_GetTag(Data, 'ID' + count); strCurrentTopic = document.getElementById('ChatTopic').innerHTML; if (strCurrentTopic != '') { bFound = false; while(TopicID != '') { TopicName = XML_GetTag(Data, 'N' + count); if (TopicName.toUpperCase() == strCurrentTopic.toUpperCase() ) { bFound = true; } count += 1; TopicID = XML_GetTag(Data, 'ID' + count); } if (bFound) { divOffline.style.display = 'none'; divOnline.style.display = 'inline'; } else { divOffline.style.display = 'inline'; divOnline.style.display = 'none'; } } } /*END IF (ConnStatus == "False")*/ } /*END IF ( myCombo != null && divOnline != null && divOffline != null )*/ } function handleResponse() { if(http.readyState == 4) { if (http.status == 200) { var response = http.responseText; switch(XML_GetTag(response,'CMD')) { case 'RT': handleTopics(response); break; case "CONN_STATUS": var myStatus = document.getElementById('Conn_Status'); if (myStatus != null) { Data = XML_GetTag(response, 'DATA'); myStatus.innerHTML = 'Connection Status: ' + Data; } default: } } else { //Oops. Error with request. var message = http.getResponseHeader("Status"); if ((message.length == null) || (message.length <= 0)) { AddErrorMessage("Problem contacting server! Request status is " + http.status); } else { AddErrorMessage(message); } } } } function PollTopics(Interval) { //Check for any what topics are available every now and then sndReq('RT', 0); setTimeout( 'PollTopics(' + Interval + ')', Interval); } function InitTopics() { setTimeout( "sndReq('RT', 0)", 1000); }