// JScript-Datei
// CopyRight (c) ISSB, 2008
// Anfragen an jens.boerner@issb.de
var g_tID = 0;var g_iMinMsgLen = 1;var g_iMaxMsgLen = 100;var g_iTI = 5000;var g_lLID = 0;var g_lCId = 0;var g_lActionOnNewMsg = 0;var g_oHttpReq = null;var g_strVer = "ISSB-ChatClient 2.1";var g_strColorConnectOk = "#00EE00";var g_strColorConnectFailed = "red";var g_strColorConnectBusy = "yellow";var g_strColorConnectInit = "gray";var g_lLineCounter = 0;function InitChatter(lCId, iMinLen, iMaxLen){ g_iMinMsgLen = iMinLen; g_iMaxMsgLen = iMaxLen; g_lCId = lCId; theForm = document.forms[0]; if (document.getElementById("ChatText") != null && theForm.ChatText != null) theForm.ChatText.focus(); g_tID = window.setTimeout("GetBroadcastReq();", 1000);}function OnChangeText(theElement){ var strText = theElement.value; if (strText > "") ISSBChatCharCounter.innerHTML = "Anzahl Zeichen: " + strText.length; else ISSBChatCharCounter.innerHTML = "";}function SetTColor(theValue){if (ISSBChatter != null)ISSBChatter.style.color = theValue;}function SetBGColor(theValue){if (ISSBChatter != null)ISSBChatter.style.backgroundColor = theValue;}function SetIcon(strIcon){ theForm = document.forms[0];if (document.getElementById("ChatText") != null && theForm.ChatText != null){ theForm.ChatText.value += strIcon + " "; theForm.ChatText.focus();}}function CreateRequestObject(){ var oReq = null; try  { oReq = new XMLHttpRequest(); }  catch(W3C)  { try  { oReq = new ActiveXObject("Msxml2.XMLHTTP"); }  catch(MSIE)  { try  { oReq = new ActiveXObject("Microsoft.XMLHTTP"); }  catch(MSIE_OLD)  { oReq = null; window.status = "Programm-Fehler. Chatter kann leider nicht ausgeführt werden."; } } } return oReq;}function SendRequest(strUrl, fnReadResponse){ if (g_oHttpReq != null) {  g_oHttpReq.abort(); } else g_oHttpReq = CreateRequestObject(); if (g_oHttpReq != null){  try { g_oHttpReq.onreadystatechange = fnReadResponse; g_oHttpReq.open("GET", strUrl, true); g_oHttpReq.setRequestHeader("ChatClient", g_strVer); g_oHttpReq.send(null);  g_iTI = 2000;  return g_oHttpReq; } catch (Req_Failed) { window.status = "Fehler beim Senden der Daten."; if (g_oHttpReq != null)  g_oHttpReq.abort(); } } return null;}function ReadResponseSendCmd(){ if (g_tID > 0) { window.clearTimeout(g_tID); g_tID = 0; }   var iTO = 10000;  if (g_oHttpReq.readyState == 4 && g_oHttpReq.status == 200) { var strResp = g_oHttpReq.responseText; var strCRID = g_oHttpReq.getResponseHeader("CRID"); var strLID = g_oHttpReq.getResponseHeader("LID"); if (parseInt(strCRID, 10) >= 0 && parseInt(strLID, 10) > 0) {  bOk = true; if (document.getElementById("ConnectStatusDisplay") != null && ConnectStatusDisplay != null) ConnectStatusDisplay.style.backgroundColor = g_strColorConnectOk;  iTO = 500; } } else { if (document.getElementById("ConnectStatusDisplay") != null && ConnectStatusDisplay != null) ConnectStatusDisplay.style.backgroundColor = g_strColorConnectBusy; } g_tID = window.setTimeout("GetBroadcastReq();", iTO);}function SendChatText(strText){ if (g_tID > 0) { window.clearTimeout(g_tID); g_tID = 0; }  while (strText > "" && strText.charAt(0) == " ") strText = strText.substr(1); strText = escape(strText); var bOk = false; if (strText > "" && strText.length >= g_iMinMsgLen) { if (strText.length > g_iMaxMsgLen) strText = strText.substr(0, g_iMaxMsgLen); if (document.getElementById("ConnectStatusDisplay") != null && ConnectStatusDisplay != null) ConnectStatusDisplay.style.backgroundColor = g_strColorConnectInit; bOk = SendRequest("SendChatText.asp?Msg=" + strText, ReadResponseSendCmd) != null; }  if (bOk != true) { if (document.getElementById("ConnectStatusDisplay") != null && ConnectStatusDisplay != null) ConnectStatusDisplay.style.backgroundColor = g_strColorConnectFailed; g_iTI = 10000; if (g_tID > 0) window.clearTimeout(g_tID); g_tID = window.setTimeout("GetBroadcastReq();", g_iTI); } return bOk;}function EncodeChar(cChar){ if (cChar != null) { var iChar = cChar.charCodeAt(0); return "&#" + iChar + ";"; } return null;}function ReplaceSmilies(strText){ if (strText != null && strText.length > 0) { strText = strText.replace(/(\:\-\))/g, "<img src='/Chatter/images/Smilies/smilie1.gif' alt='$1'>"); strText = strText.replace(/(\:\-D)/g, "<img src='/Chatter/images/Smilies/biggrin.gif' alt='$1'>"); strText = strText.replace(/(\;\-\))/g, "<img src='/Chatter/images/Smilies/smilie3.gif' alt='$1'>"); strText = strText.replace(/(\;\-D)/g, "<img src='/Chatter/images/Smilies/zwinkern2.gif' alt='$1'>"); strText = strText.replace(/(\;\-\})/g, "<img src='/Chatter/images/Smilies/zwinkern3.gif' alt='$1'>"); strText = strText.replace(/(\:\-k)/g, "<img src='/Chatter/images/Smilies/010.gif' alt='$1'>"); strText = strText.replace(/(\:\-P)/g, "<img src='/Chatter/images/Smilies/003.gif' alt='$1'>"); strText = strText.replace(/(\:\-j)/g, "<img src='/Chatter/images/Smilies/aetsch.gif' alt='$1'>"); strText = strText.replace(/(\:\-l)/g, "<img src='/Chatter/images/Smilies/smilie7.gif' alt='$1'>"); strText = strText.replace(/(\:\-H)/g, "<img src='/Chatter/images/Smilies/help.gif' alt='$1'>"); strText = strText.replace(/(\:\-\?)/g, "<img src='/Chatter/images/Smilies/gruebel.gif' alt='$1'>"); strText = strText.replace(/(\:\-\|)/g, "<img src='/Chatter/images/Smilies/ablehnung4.gif' alt='$1'>"); strText = strText.replace(/(\:\-\()/g, "<img src='/Chatter/images/Smilies/1.gif' alt='$1'>"); strText = strText.replace(/(\:\-\[)/g, "<img src='/Chatter/images/Smilies/ablehnung2.gif' alt='$1'>"); strText = strText.replace(/(\:\-O)/g, "<img src='/Chatter/images/Smilies/122.gif' alt='$1'>"); strText = strText.replace(/(\;\-\()/g, "<img src='/Chatter/images/Smilies/frown.gif' alt='$1'>"); strText = strText.replace(/(\:\-\])/g, "<img src='/Chatter/images/Smilies/grinser010.gif' alt='$1'>"); strText = strText.replace(/(\:\-b)/g, "<img src='/Chatter/images/Smilies/bier.gif' alt='$1'>"); strText = strText.replace(/(\:\-\{)/g, "<img src='/Chatter/images/Smilies/077.gif' alt='$1'>"); strText = strText.replace(/(\:\-s)/g, "<img src='/Chatter/images/Smilies/stress2.gif' alt='$1'>"); strText = strText.replace(/(\:\-\})/g, "<img src='/Chatter/images/Smilies/sport1.gif' alt='$1'>"); } return strText;}function HtmlEncode(strText){ if (strText != null && strText.length > 0) {/*  var cChar; var ix = 0; while (ix < strText.length) { cChar = strText.charAt(ix); if ((cChar >= 'a' && cChar <= 'z') || (cChar >= 'A' && cChar <= 'Z') || (cChar >= '0' && cChar <= '9')) { ix++; } else { var strHtml = "&#" + cChar.charCodeAt(0) + ";"; strText = strText.substr(0, ix) + strHtml + strText.substr(ix + 1); if (strHtml != null && strHtml.length > 0) { ix += strHtml.length; } else ix++; } }*/ /* strText = strText.replace("Ä", "&Auml;"); strText = strText.replace("ä", "&auml;"); strText = strText.replace("Ö", "&Ouml;"); strText = strText.replace("ö", "&ouml;"); strText = strText.replace("Ü", "&Uuml;"); strText = strText.replace("ü", "&uuml;"); strText = strText.replace("ß", "&szlig;");*/  } return strText;}function ApendTextline(strLine){ if (strLine != null && strLine.length > 0) {  if (g_lActionOnNewMsg & 1) window.focus();   ISSBChatter.innerHTML += strLine;  FocusToEntry(); g_iTI = 5000; }}function FocusToEntry(){ ISSBChatter.focus(); ISSBChatter.scrollTop = ISSBChatter.scrollHeight; try { ISSBChatter.scrollTo(0, 100); } catch(e) { window.status = "Fehler beim Darstellung der Ansicht."; }  if (document.getElementById("ChatText") != null && theForm.ChatText != null) theForm.ChatText.focus();}function SplitUserNameAndTime(strUsername){ if (strUsername != null && strUsername.length > 0) { var iIndex = strUsername.indexOf(" - "); if (iIndex >= 0) { var strTime = "<span class='ChatUserTime'>" +  strUsername.substr(0, iIndex) + "</span>"; var strUN = "<span class='ChatUserName'>" +  HtmlEncode(strUsername.substr(iIndex + 3)) + "</span>"; strUsername = "<br>\r\n" + strTime + " - " + strUN + ": "; } } return strUsername;}function ReadResponseGetLines(){ if (g_tID > 0) { window.clearTimeout(g_tID); g_tID = 0; }  g_iTI = 20000;  if (g_oHttpReq.readyState == 4 && g_oHttpReq.status == 200) { var strCRID = g_oHttpReq.getResponseHeader("CRID"); var strLID = g_oHttpReq.getResponseHeader("LID"); if (strCRID > "" && parseInt(strCRID, 10) == g_lCId && strLID > "") { var lLID = parseInt(strLID, 10); if (lLID > 0) { g_lLID = lLID + 1;  var strResp = "\r\n" + g_oHttpReq.responseText;  var iPos1 = strResp.indexOf("\r\n["); while (iPos1 >= 0) {  var iPos2 = strResp.substr(iPos1 + 3).indexOf("]"); if (iPos2 >= 0) { var strUN = strResp.substr(iPos1 + 3, iPos2);  var strMsg = strResp.substr(iPos1 + iPos2 + 4); strResp = strResp.substr(0, iPos1) +  SplitUserNameAndTime(strUN); iPos1 = strMsg.indexOf("\r\n"); if (iPos1 >= 0) strMsg = "<span class='ChatMsg'>" +  ReplaceSmilies(HtmlEncode(strMsg.substr(0, iPos1))) + "</span>" + strMsg.substr(iPos1); else strMsg = "<span class='ChatMsg'>" + ReplaceSmilies(HtmlEncode(strMsg)) + "</span>"; strResp += strMsg;   iPos1 = strResp.indexOf("\r\n["); } else break;   g_lLineCounter++; } g_iTI = 10000; if (strResp != "\r\n") ApendTextline(strResp); } } if (document.getElementById("ConnectStatusDisplay") != null && ConnectStatusDisplay != null) { ConnectStatusDisplay.style.backgroundColor = g_strColorConnectOk; ConnectStatusDisplay.innerHTML = g_lLineCounter; } } else { if (document.getElementById("ConnectStatusDisplay") != null && ConnectStatusDisplay != null) ConnectStatusDisplay.style.backgroundColor = g_strColorConnectBusy; } g_tID = window.setTimeout("GetBroadcastReq();", g_iTI);}function GetBroadcastReq(){ if (g_tID > 0) { window.clearTimeout(g_tID); g_tID = 0; } if (document.getElementById("ConnectStatusDisplay") != null && ConnectStatusDisplay != null) ConnectStatusDisplay.style.backgroundColor = g_strColorConnectInit; if (SendRequest("/Chatter/GetResponse.asp?FID=" + g_lLID, ReadResponseGetLines) == null) { if (document.getElementById("ConnectStatusDisplay") != null && ConnectStatusDisplay != null) ConnectStatusDisplay.style.backgroundColor = g_strColorConnectFailed; g_iTI = 10000; if (g_tID > 0) window.clearTimeout(g_tID); g_tID = window.setTimeout("GetBroadcastReq();", g_iTI); }}function ClearInput(theForm){ theForm.ChatText.value = ""; OnChangeText(theForm.ChatText); theForm.ChatText.focus();}function Send(){ theForm = document.forms[0]; if (SendChatText(theForm.ChatText.value)) ClearInput(theForm);}function FormValidator(theForm){ if (SendChatText(theForm.ChatText.value)) { ClearInput(theForm); return false; }  return true;}