// 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_lLineCounter = 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_strImageDir = "images/Smilies/";var g_CtrlChatter = null;var g_CtrlConnectStatusDisplay = null;var g_CtrlChatCharCounter = null;function InitChatter(lCId, iMinLen, iMaxLen) { g_CtrlChatter = document.getElementById("ISSBChatter"); g_CtrlConnectStatusDisplay = document.getElementById("ConnectStatusDisplay"); g_CtrlChatCharCounter = document.getElementById("ISSBChatCharCounter");  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) { if (g_CtrlChatCharCounter != null)  { var strText = theElement.value; if (strText > "")  { var iDif = g_iMaxMsgLen - strText.length; if (iDif > 0) g_CtrlChatCharCounter.innerHTML = "noch " + iDif; else g_CtrlChatCharCounter.innerHTML = "Maximum erreicht."; } else g_CtrlChatCharCounter.innerHTML = ""; }}function SetTColor(theValue){ if (g_CtrlChatter != null) g_CtrlChatter.style.color = theValue;}function SetBGColor(theValue){ if (g_CtrlChatter != null) g_CtrlChatter.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 (g_CtrlConnectStatusDisplay != null) g_CtrlConnectStatusDisplay.style.backgroundColor = g_strColorConnectOk;  iTO = 500; } } else { if (g_CtrlConnectStatusDisplay != null) g_CtrlConnectStatusDisplay.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); if (strText > "" && strText.length > g_iMaxMsgLen) strText = strText.substr(0, g_iMaxMsgLen); strText = escape(strText); var bOk = false; if (strText > "" && strText.length >= g_iMinMsgLen) { if (g_CtrlConnectStatusDisplay != null) g_CtrlConnectStatusDisplay.style.backgroundColor = g_strColorConnectInit; bOk = SendRequest("SendChatText.asp?Msg=" + strText, ReadResponseSendCmd) != null; }  if (bOk != true) { if (g_CtrlConnectStatusDisplay != null) g_CtrlConnectStatusDisplay.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='" + g_strImageDir + "smilie1.gif' alt='$1'>"); strText = strText.replace(/(\:\-D)/g, "<img src='" + g_strImageDir + "biggrin.gif' alt='$1'>"); strText = strText.replace(/(\;\-\))/g, "<img src='" + g_strImageDir + "smilie3.gif' alt='$1'>"); strText = strText.replace(/(\;\-D)/g, "<img src='" + g_strImageDir + "zwinkern2.gif' alt='$1'>"); strText = strText.replace(/(\;\-\})/g, "<img src='" + g_strImageDir + "zwinkern3.gif' alt='$1'>"); strText = strText.replace(/(\:\-k)/g, "<img src='" + g_strImageDir + "010.gif' alt='$1'>"); strText = strText.replace(/(\:\-P)/g, "<img src='" + g_strImageDir + "003.gif' alt='$1'>"); strText = strText.replace(/(\:\-j)/g, "<img src='" + g_strImageDir + "aetsch.gif' alt='$1'>"); strText = strText.replace(/(\:\-l)/g, "<img src='" + g_strImageDir + "smilie7.gif' alt='$1'>"); strText = strText.replace(/(\:\-H)/g, "<img src='" + g_strImageDir + "help.gif' alt='$1'>"); strText = strText.replace(/(\:\-\?)/g, "<img src='" + g_strImageDir + "gruebel.gif' alt='$1'>"); strText = strText.replace(/(\:\-\|)/g, "<img src='" + g_strImageDir + "ablehnung4.gif' alt='$1'>"); strText = strText.replace(/(\:\-\()/g, "<img src='" + g_strImageDir + "1.gif' alt='$1'>"); strText = strText.replace(/(\:\-\[)/g, "<img src='" + g_strImageDir + "ablehnung2.gif' alt='$1'>"); strText = strText.replace(/(\:\-O)/g, "<img src='" + g_strImageDir + "122.gif' alt='$1'>"); strText = strText.replace(/(\;\-\()/g, "<img src='" + g_strImageDir + "frown.gif' alt='$1'>"); strText = strText.replace(/(\:\-\])/g, "<img src='" + g_strImageDir + "grinser010.gif' alt='$1'>"); strText = strText.replace(/(\:\-b)/g, "<img src='" + g_strImageDir + "bier.gif' alt='$1'>"); strText = strText.replace(/(\:\-\{)/g, "<img src='" + g_strImageDir + "077.gif' alt='$1'>"); strText = strText.replace(/(\:\-s)/g, "<img src='" + g_strImageDir + "stress2.gif' alt='$1'>"); strText = strText.replace(/(\:\-\})/g, "<img src='" + g_strImageDir + "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();   g_CtrlChatter.innerHTML += strLine;   FocusToEntry(); g_iTI = 5000; }}function FocusToEntry(){ g_CtrlChatter.focus();     g_CtrlChatter.scrollTop = g_CtrlChatter.scrollHeight - g_CtrlChatter.offsetHeight + 10;  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 (g_CtrlConnectStatusDisplay != null) { g_CtrlConnectStatusDisplay.style.backgroundColor = g_strColorConnectOk; g_CtrlConnectStatusDisplay.innerHTML = g_lLineCounter; } } else { if (g_CtrlConnectStatusDisplay != null) g_CtrlConnectStatusDisplay.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 (g_CtrlConnectStatusDisplay != null) g_CtrlConnectStatusDisplay.style.backgroundColor = g_strColorConnectInit; if (SendRequest("GetResponse.asp?FID=" + g_lLID, ReadResponseGetLines) == null) { if (g_CtrlConnectStatusDisplay != null) g_CtrlConnectStatusDisplay.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;}
