var div,hin,huit,hin2, hsmilies, hinfo, hdelete, hnr; var config = new Array(); var post_info = timer_in = last = null; var display_shoutbox = false; var start = first = true; var smilies = false; var count = 0; function err_msg(title) { var err = new Error(title); if (!err.message) { err.message = title; } err.name = "E_USER_ERROR";//Php error?!? :D return err; } function handle(e) { switch (e.name) { //Is it our error? :) case "E_USER_ERROR": case "E_CORE_ERROR": message(e.message, true); return; break; default: { tmp = 'Es ist ein Javascript-Fehler aufgetreten. \nFehler: '; tmp += e.message; if (e.lineNumber) { tmp += '\nZeile: '; tmp += e.lineNumber; } if (e.fileName) { tmp += '\nDatei: '; tmp += e.fileName; } message(tmp, true); return; } } } function load_shout() { try { if (display_shoutbox == false) { return; } if (document.getElementById('shoutbox') == null) { var ev = err_msg('DIV-Code nicht gefunden'); ev.name = "E_CORE_ERROR"; throw ev; return; } else { div = document.getElementById('shoutbox'); // Display message ;) message('Shoutbox wird geladen...'); // HTTP vars, required to relead/post things. hin = http(); if (!hin) { return; } hin2 = http(); huit = http(); hsmilies = http(); hnr = http(); //Element bestaat. write_main(); } } catch (e) { handle(e); return; } } function write_main() { try { // Write the base. var basis = ce('ul'); basis.className = 'topiclist forums'; // basis.style.height = '210px'; var li = ce('li'); var dl = ce('dl'); dl.style.width = '100%'; var inh = ce('dt'); inh.style.width = '100%'; inh.id = 'post_message'; inh.className = 'row'; inh.width = '100%'; inh.style.display = 'none'; inh.height = '20px'; inh.appendChild(tn('Nachricht: ')); el = null; var el = ce('input'); el.className = 'inputbox'; el.name = el.id = 'bericht'; el.style.width = '350px'; el.onkeypress = function(evt) { try { evt = (evt) ? evt : event; var c = (evt.wich) ? evt.wich : evt.keyCode; if (c == 13) { document.getElementById('user').click(); evt.returnValue = false; this.returnValue = false; return false; } return true; } catch (e) { handle(e); return; } } inh.appendChild(el); inh.appendChild(tn(' ')); // inh.appendChild(ce('br')); var el = ce('input'); el.name = el.id = 'user'; el.value = el.defaultValue = 'Absenden'; el.type = 'button'; el.className = 'button1 btnmain'; el.onclick = function() { try { if (smilies == true) { smilies = false; document.getElementById('smilies').innerHTML = ''; document.getElementById('smilies').style.display = 'none'; } bbstyle(-1); // Here we send later the message ;) this.disabled = true; document.getElementById('post_message').style.display = 'none'; this.disabled = false; document.getElementById('msg_txt').innerHTML = ''; document.getElementById('msg_txt').appendChild(tn('Sende Nachricht...')); if (document.getElementById('bericht').value == '') { document.getElementById('msg_txt').innerHTML = ''; throw err_msg('Es wurde kein Text in die Nachricht eingegeben.'); } if (huit.readyState == 4 || huit.readyState == 0) { // Lets got some nice things :D huit.open('POST','shoutbox.php?m=add&1&sid=13a4926a44726c042404f4b2cfdec28f&rand='+Math.floor(Math.random() * 1000000),true); huit.onreadystatechange = function() { try { if (huit.readyState == 4) { xml = huit.responseXML; if (xml.getElementsByTagName("error") && xml.getElementsByTagName("error").length != 0) { err = xml.getElementsByTagName("error")[0].childNodes[0].nodeValue; document.getElementById('msg_txt').innerHTML = ''; document.getElementById('post_message').style.display = 'block'; last = 0; message(err, true); } else { document.getElementById('msg_txt').innerHTML = ''; document.getElementById('msg_txt').appendChild(tn('Die Nachricht wurde erfolgreich gesendet.')); setTimeout("document.getElementById('msg_txt').innerHTML = ''",3000); document.getElementById('post_message').style.display = 'block'; count = 0;// Set count to 0, because otherwise user willn't see his message clearTimeout(timer_in); timer_in = setTimeout('reload_post();reload_page();', 300); setTimeout('last = 0;', 500); } document.getElementById('bericht').focus(); } } catch (e) { handle(e); return; } } post = 'message='; post += encodeURIComponent(document.getElementById('bericht').value); document.getElementById('bericht').value = ''; if (smilies == true) { smilies = false; document.getElementById('smilies').innerHTML = ''; document.getElementById('smilies').style.display = 'none'; } huit.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); huit.send(post); } else { throw err_msg('This should not happen, double request found!'); } } catch (e) { document.getElementById('post_message').style.display = 'inline'; setTimeout("document.getElementById('msg_txt').innerHTML = ''",5000); handle(e); return; } } inh.appendChild(el); inh.appendChild(tn(' ')); el = ce('input') el.value = el.defaultValue = 'Smilies'; el.type = 'button'; el.className = 'button2 btnmain'; el.onclick = function() { try { if (smilies == true) { smilies = false; document.getElementById('smilies').innerHTML = ''; document.getElementById('smilies').style.display = 'none'; } else { smilies = true; document.getElementById('smilies').style.display = 'block'; document.getElementById('smilies').appendChild(tn('Shoutbox wird geladen...')); if (hsmilies.readyState == 4 || hsmilies.readyState == 0) { // Lets got some nice things :D hsmilies.open('GET','shoutbox.php?m=smilie&1&sid=13a4926a44726c042404f4b2cfdec28f&rand='+Math.floor(Math.random() * 1000000),true); hsmilies.onreadystatechange = function() { try { if (hsmilies.readyState == 4) { xml = hsmilies.responseXML; if (xml.getElementsByTagName("error") && xml.getElementsByTagName("error").length != 0) { err = xml.getElementsByTagName("error")[0].childNodes[0].nodeValue; document.getElementById('smilies').innerHTML = ''; message(err, true); } else { document.getElementById('smilies').innerHTML = ''; var tmp = xml.getElementsByTagName('smilie'); for (var i = (tmp.length - 1); i >= 0 ; i--) { var inh = tmp[i]; var a = ce('a'); // a.href = "#"; a.code = inh.getElementsByTagName('code')[0].childNodes[0].nodeValue; a.onclick = function() { document.getElementById('bericht').value += " " + this.code + " "; } var img = ce('img'); img.src = inh.getElementsByTagName('img')[0].childNodes[0].nodeValue; img.border = 0; a.appendChild(img); document.getElementById('smilies').appendChild(a); document.getElementById('smilies').appendChild(tn(' ')); } } } } catch (e) { handle(e); return; } } hsmilies.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); hsmilies.send(null); } } } catch (e) { handle(e); return; } } inh.appendChild(el); inh.appendChild(tn(' ')); // BBcode buttons ;) var bbcode = ce('input'); bbcode.type = 'button'; bbcode.className = 'button2 btnmain'; bbcode.accesskey = 'b'; bbcode.name = bbcode.id = 'addbbcode0'; bbcode.value = bbcode.defaultValue = ' B '; bbcode.style.fontWeight = 'bold'; bbcode.style.width = '33px'; bbcode.onclick = function() { bbstyle(0); } inh.appendChild(bbcode); inh.appendChild(tn(' ')); var bbcode = ce('input'); bbcode.type = 'button'; bbcode.className = 'button2 btnmain'; bbcode.accesskey = 'i'; bbcode.name = bbcode.id = 'addbbcode2'; bbcode.value = bbcode.defaultValue = ' I '; bbcode.style.fontStyle = 'italic'; bbcode.style.width = '33px'; bbcode.onclick = function() { bbstyle(2); } inh.appendChild(bbcode); inh.appendChild(tn(' ')); var bbcode = ce('input'); bbcode.type = 'button'; bbcode.className = 'button2 btnmain'; bbcode.accesskey = 'u'; bbcode.name = bbcode.id = 'addbbcode4'; bbcode.value = bbcode.defaultValue = 'U'; bbcode.style.textDecoration = 'underline'; bbcode.style.width = '33px'; bbcode.onclick = function() { bbstyle(4); } inh.appendChild(bbcode); inh.appendChild(tn(' ')); var bbcode = ce('input'); bbcode.type = 'button'; bbcode.className = 'button2 btnmain'; bbcode.accesskey = 'p'; bbcode.name = bbcode.id = 'addbbcode6'; bbcode.value = bbcode.defaultValue = ' IMG '; bbcode.style.width = '43px'; bbcode.onclick = function() { bbstyle(6); } inh.appendChild(bbcode); inh.appendChild(tn(' ')); var bbcode = ce('input'); bbcode.type = 'button'; bbcode.className = 'button2 btnmain'; bbcode.accesskey = 'w'; bbcode.name = bbcode.id = 'addbbcode8'; bbcode.value = bbcode.defaultValue = ' URL '; bbcode.style.width = '43px'; bbcode.onclick = function() { bbstyle(8); } inh.appendChild(bbcode); inh.appendChild(tn(' ')); // inh.appendChild(ce('br')); var smilie = ce('div'); smilie.style.display = 'none'; smilie.name = smilie.id = 'smilies'; inh.appendChild(smilie); dl.appendChild(inh); li.appendChild(dl); basis.appendChild(li); var msg_txt = ce('div'); msg_txt.id = 'msg_txt'; msg_txt.height = '180px'; msg_txt.appendChild(tn(' ')); basis.appendChild(msg_txt); var post = ce('div');//In this div, the chats will be placed ;) post.style.display = 'block'; post.id = 'msg'; post.style.width = '100%'; post.style.height = '160px'; post.style.overflow = 'auto'; post.appendChild(tn('Shoutbox wird geladen...')); basis.appendChild(post); // Nr div var nr_d = ce('div'); nr_d.id = 'nr'; basis.appendChild(nr_d); div.innerHTML = ''; div.appendChild(basis); // Everyting loaded, lets select posts :) reload_post(); reload_page(); } catch (e) { handle(e); return; } } function validate_overige(xml) { try { if (xml.childNodes.length == 0) { return tn(""); } else if (xml.childNodes.length == 1 && xml.childNodes[0].nodeValue != null) { // With a tag in it, its bigger as 1? return tn(xml.childNodes[0].nodeValue); } else { var div = ce("span"); loop: for (var i = 0; i < xml.childNodes.length; i++) { switch (xml.childNodes[i].nodeType) { case 3: div.appendChild(document.createTextNode(xml.childNodes[i].nodeValue)); break; case 9: case 8: case 10: case 11: // continue; break; case 1: if (xml.childNodes[i].childNodes.length == 0 && xml.childNodes[i].nodeName != 'br' && xml.childNodes[i].nodeName != 'img' && xml.childNodes[i].nodeName != 'hr') { break; } // This is a difficult one :) switch (xml.childNodes[i].nodeName) { case "br": div.appendChild(ce("br")); break; case "blockquote": var q = ce("blockquote"); q.className = "quote"; q.appendChild(validate_overige(xml.childNodes[i])); add_style(xml.childNodes[i], q); div.appendChild(q); break; case "a": var a = ce("a"); a.href = xml.childNodes[i].getAttribute("href"); a.appendChild(validate_overige(xml.childNodes[i])); add_style(xml.childNodes[i], a); div.appendChild(a); break; case "img": var img = ce("img"); img.alt = xml.childNodes[i].getAttribute("alt"); img.src = xml.childNodes[i].getAttribute("src"); img.border = 0; add_style(xml.childNodes[i], img); div.appendChild(img); break; case "strong": case "b": var b = ce("strong"); b.appendChild(validate_overige(xml.childNodes[i])); add_style(xml.childNodes[i], b); div.appendChild(b); break; case "hr": var hr = ce("hr"); div.appendChild(hr); break; case "h1": case "h2": case "h3": case "h4": case "h5": case "h6": var h = ce(xml.childNodes[i].nodeName); h.appendChild(validate_overige(xml.childNodes[i])); add_style(xml.childNodes[i], h); div.appendChild(h); break; case 'span': var s = ce('span'); s.appendChild(validate_overige(xml.childNodes[i])); add_style(xml.childNodes[i], s); div.appendChild(s); break; default: { throw err_msg("Ungültiges Element: "+xml.childNodes[i].nodeName); } } break; } } } return div; } catch (e) { handle(e); return div; } } function add_style(el, s) { var c = el.getAttribute('class'); if (c != null) { s.className = c; } f = el.getAttribute("style"); if (f == null) { return; } if (f.indexOf(";") == -1) { f += ";"; } f = f.split(";"); for (var j = 0; j < f.length; j++) { f2 = f[j].split(":"); if (f2[0]) { f2[0] = trim(f2[0]); } if (f2[1]) { f2[1] = trim(f2[1]); } switch (f2[0]) { case 'font-style': s.style.fontStyle = f2[1]; break; case 'font-weight': s.style.fontWeight = f2[1]; break; case 'font-size': try { s.style.fontSize = f2[1]; } catch (e){} break; case 'line-height': s.style.lineHeigt = f2[1]; break; case 'color': s.style.color = f2[1]; break; case 'text-decoration': s.style.textDecoration = f2[1]; break; } } } function trim(value) { value = value.replace(/^\s+/,''); value = value.replace(/\s+$/,''); return value; } function reload_page() { if (hnr.readyState == 4 || hnr.readyState == 0) { // Lets got some nice things :D hnr.open('GET','shoutbox.php?m=nr&1&sid=13a4926a44726c042404f4b2cfdec28f&rand='+Math.floor(Math.random() * 1000000),true); hnr.onreadystatechange = function() { try { if (hnr.readyState == 4) { xml = hnr.responseXML; if (xml.getElementsByTagName("error") && xml.getElementsByTagName("error").length != 0) { err = xml.getElementsByTagName("error")[0].childNodes[0].nodeValue; message(err, true); clearTimeout(timer_in); setTimeout("reload_post();",500); } else { var nr = xml.getElementsByTagName("nr")[0].childNodes[0].nodeValue; var f = document.getElementById('nr'); f.innerHTML = ''; var d = ce('div'); if (nr < 10) { return; } var per_page = 10; var total_pages = Math.ceil(nr / per_page); if (total_pages == 1 || !nr) { return; } on_page = Math.floor(count / per_page) + 1; var p = ce('span'); var a = ce('a'); var b = ce('strong'); if (on_page == 1) { b.appendChild(tn('1')); p.appendChild(b); b = ce('strong'); } else { a.c = ((on_page - 2) * per_page); a.href = "javascript:;"; a.onclick = function() { count = this.c; last = 0; // Reset last, otherwise it will not be loaded. clearTimeout(timer_in); reload_post(); reload_page(); } a.appendChild(tn('Vorherige')); p.appendChild(a); p.appendChild(tn(' ')); a = ce('a'); a.c = 0; a.href = "javascript:;"; a.onclick = function() { count = this.c; last = 0; // Reset last, otherwise it will not be loaded. clearTimeout(timer_in); reload_post(); reload_page(); } a.appendChild(tn('1')); p.appendChild(a); a = ce('a'); } if (total_pages > 5) { var start_cnt = Math.min(Math.max(1, on_page - 4), total_pages - 5); var end_cnt = Math.max(Math.min(total_pages, on_page + 4), 6); p.appendChild((start_cnt > 1) ? tn(' ... ') : cp()); for (var i = start_cnt + 1; i < end_cnt; i++) { if (i == on_page) { b.appendChild(tn(i)); p.appendChild(b); b = ce('strong'); } else { a.c = (i - 1) * per_page; a.href = "javascript:;"; a.onclick = function() { count = this.c; last = 0; // Reset last, otherwise it will not be loaded. clearTimeout(timer_in); reload_post(); reload_page(); } a.appendChild(tn(i)); p.appendChild(a); a = ce('a'); } if (i < end_cnt - 1) { p.appendChild(cp()); } } p.appendChild((end_cnt < total_pages) ? tn(' ... ') : cp()); } else { p.appendChild(cp()); for (var i = 2; i < total_pages; i++) { if (i == on_page) { b.appendChild(tn(i)); p.appendChild(b); b = ce('strong'); } else { a.c = (i - 1) * per_page; a.href = "javascript:;"; a.onclick = function() { count = this.c; last = 0; // Reset last, otherwise it will not be loaded. clearTimeout(timer_in); reload_post(); reload_page(); } a.appendChild(tn(i)); p.appendChild(a); a = ce('a'); } if (i < total_pages) { p.appendChild(cp()); } } } if (on_page == total_pages) { b.appendChild(tn(total_pages)); p.appendChild(b); b = ce('strong'); } else { a = ce('a'); a.c = ((total_pages - 1) * per_page); a.href = "javascript:;"; a.onclick = function() { count = this.c; last = 0; // Reset last, otherwise it will not be loaded. clearTimeout(timer_in); reload_post(); reload_page(); } a.appendChild(tn(total_pages)); p.appendChild(a); a = ce('a'); a.c = ((on_page) * per_page); a.href = "javascript:;"; a.onclick = function() { count = this.c; last = 0; // Reset last, otherwise it will not be loaded. clearTimeout(timer_in); reload_post(); reload_page(); } a.appendChild(tn('Nächste')); p.appendChild(tn(' ')); p.appendChild(a); a = ce('a'); } f.appendChild(p); } } } catch (e) { handle(e); return; } } hnr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); hnr.send(null); } } function reload_post() { // First check if there new posts. if (hin2.readyState == 4 || hin2.readyState == 0) { hin2.open('GET','shoutbox.php?m=check&1&sid=13a4926a44726c042404f4b2cfdec28f&last=' + last + '&rand='+Math.floor(Math.random() * 1000000),true); hin2.onreadystatechange = function() { try { if (hin2.readyState == 4) { if (!hin2.responseXML) { throw err_msg('XML-Fehler.'); } var xml = hin2.responseXML; if (xml.getElementsByTagName("error") && xml.getElementsByTagName("error").length != 0) { err = xml.getElementsByTagName('error')[0].childNodes[0].nodeValue; throw err_msg(err); return; } var t = xml.getElementsByTagName('tijd')[0].childNodes[0].nodeValue; if (t == "0") { // If start is true, we let notice that there are no messages if (start == true) { if (first) { document.getElementById('post_message').style.display = 'inline'; first = false; } var posts = document.getElementById('msg'); posts.innerHTML = ''; posts.appendChild(tn('Es sind keine Einträge in der Shoutbox vorhanden.')); } } else { if (hin.readyState == 4 || hin.readyState == 0) { last = xml.getElementsByTagName('last')[0].childNodes[0].nodeValue; // Lets got some nice things :D hin.open('GET','shoutbox.php?m=view&1&sid=13a4926a44726c042404f4b2cfdec28f&start=' + count + '&rand='+Math.floor(Math.random() * 1000000),true); hin.onreadystatechange = function() { try { if (hin.readyState == 4) { if (!hin.responseXML) { throw err_msg('XML-Fehler.'); return; } var xml = hin.responseXML; if (xml.getElementsByTagName("error") && xml.getElementsByTagName("error").length != 0) { var msg = xml.getElementsByTagName('error')[0].childNodes[0].nodeValue; throw err_msg(msg); return; } else { start = false; var tmp = xml.getElementsByTagName('posts'); if (tmp.length == 0) { if (first) { document.getElementById('post_message').style.display = 'inline'; first = false; } var posts = document.getElementById('msg'); posts.innerHTML = ''; posts.appendChild(tn('Es sind keine Einträge in der Shoutbox vorhanden.')); setTimeout('reload_post();',5000); return; } var posts = document.getElementById('msg'); posts.innerHTML = ''; var row = false; for (var i = (tmp.length - 1); i >= 0 ; i--) { var li = ce('li'); li.className = (!row) ? 'row row1' : 'row row2'; row = !row; var dl = ce('dl'); var dd = ce('dd'); var dt = ce('dt'); var inh = tmp[i]; dt.style.width = '13%'; dt.style.styleFloat = dt.style.cssFloat = 'left'; dd.style.styleFloat = dd.style.cssFloat = 'left'; dd.style.paddingLeft = '3px'; var s = ce('span'); dt.appendChild(validate_overige(inh.getElementsByTagName('shout_time')[0])); dt.appendChild(tn(' ')); dt.appendChild(validate_overige(inh.getElementsByTagName('username')[0])); dt.appendChild(tn(': ')); dl.appendChild(dt); var msg = validate_overige(inh.getElementsByTagName('shout_text')[0]); dd.appendChild(msg); dl.appendChild(dd); li.appendChild(dl); posts.appendChild(li); } //basis = row = null; if (first) { document.getElementById('post_message').style.display = 'inline'; first = false; } } } } catch (e) { timer_in = setTimeout('reload_post();',5000); handle(e); return; } } hin.send(null); } } timer_in = setTimeout('reload_post();',300000); } } catch (e) { handle(e); return; } } hin2.send(null); } } function http() { try { var http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { } } } if (!http_request) { throw err_msg('Kein Ajax verfügbar'); } return http_request; } catch (e) { handle(e); return false; } } function message(msg, color) { try { if (document.getElementById('msg_txt') != null) { document.getElementById('msg_txt').innerHTML = ''; var tmp = ce('div'); tmp.appendChild(tn(msg)); if (color) { tmp.style.color = '5B5F7A'; } document.getElementById('msg_txt').appendChild(tmp); } else { div.innerHTML = ''; var tmp = ce('div'); tmp.appendChild(tn(msg)); if (color) { tmp.style.color = '5B5F7A'; } div.appendChild(tmp); } } catch (e) { handle(e); return false; } } function ce(e) { return document.createElement(e); } function tn(e) { return document.createTextNode(e); } function cp() { var sep = ce('span'); sep.className = 'page-sep'; sep.appendChild(tn(', ')); return sep; }