opera_nav = (navigator.userAgent.indexOf('Opera') != -1) ? true : false;
ie_nav = (navigator.userAgent.indexOf('MSIE') != -1 && !opera_nav) ? true : false;
ie6_nav = (navigator.userAgent.indexOf('MSIE 6') != -1 && !opera_nav) ? true : false;
mozilla_nav = (navigator.userAgent.indexOf('Gecko') != -1) ? true : false;
safari_nav = (navigator.userAgent.indexOf('Safari') != -1) ? true : false;
function preloadImg(imgEl, src) {
var img = document.createElement("img");
img.setAttribute("src", src);
img.onload = function() {
imgEl.setAttribute("src", img.src);
imgEl.onload = null;
};
imgEl.style.display = 'inline';
}
function loadImg(src) {
var img = new Image();
img.src = src;
}
function deleteEl(el) {
if(el && el.parentNode) {
el.parentNode.removeChild(el);
}
}
function clone(obj) {
if((typeof(obj) != 'object') || (obj == null)) {
return obj;
}
if(obj.length == undefined) {
var newObj = {}
for(var i in obj) {
newObj[i] = clone(obj[i]);
}
} else {
var newObj = []
for(var i=0; i<obj.length; i++) {
newObj[i] = clone(obj[i]);
}
}
return newObj;
}
function swap(a, b) {
var tmp = a;
a = b;
b = tmp;
}
function elById(id) {
return document.getElementById(id);
}
function showEl(el) {
el.style.display = 'block';
}
function hideEl(el) {
el.style.display = 'none';
}
function clearEl(el) {
el.innerHTML = '';
}
function info(txt) {
document.getElementById("info").innerHTML = txt;
}
function px2int(px) {
return parseInt(px.substring(0,px.length-2));
}
function getMousePos(e) {
var px;
var py;
if (mozilla_nav) {
px = e.pageX;
py = e.pageY;
} else {
px = event.clientX + document.body.scrollLeft;
py = event.clientY + document.body.scrollTop;
}
return {left:px, top:py};
}
function isPosInObj(pos, obj) {
var left = getLeft(obj);
var top = getTop(obj);
if((pos.left > left) &&
(pos.left < obj.offsetWidth + left) &&
(pos.top > top) &&
(pos.top < obj.offsetHeight + top)) {
return true;
}
return false;
}
function getLeft(obj) {
var curleft = 0;
if (obj.offsetParent) {
while (obj.offsetParent) {
curleft += obj.offsetLeft;
obj = obj.offsetParent;
}
} else if (obj.x) curleft += obj.x;
return curleft;
}
function getTop(obj) {
var curtop = 0;
if (obj.offsetParent) {
while (obj.offsetParent) {
curtop += obj.offsetTop;
obj = obj.offsetParent;
}
} else if (obj.y) curtop += obj.y;
return curtop;
}
function getElPos(el) {
var left = 0;
var top = 0;
if (el.offsetParent) {
while (el.offsetParent) {
left += el.offsetLeft;
top += el.offsetTop;
el = el.offsetParent;
}
} else
if (el.y) {
left += el.x;
top += el.y;
}
return {left:left, top:top};
}
function setElPos(el, pos) {
el.style.left = pos.left + "px";
el.style.top = pos.top + "px";
}
function trim(s) {
if(s && s.replace) {
return s.replace(/^\s*(.+?)\s*$/, "$1").replace(/'/g, "").replace(/"/g, "");
} else {
return "";
}
}
function arraySearch(needle, data) {
for(var i = 0; i<data.length; i++) {
if(data[i] == needle) {
return i;
}
}
return undefined;
}
function arrayFirstFree(data) {
var id = arraySearch(undefined, data);
if(id != undefined) {
return id;
} else {
return data.length;
}
}
function getDir(url) {
if(url) {
return url.substring(0, url.lastIndexOf("/"));
} else {
return "";
}
}
function getDomain(url) {
if(url) {
var tmp = url.split("//");
return (tmp[1] != undefined) ? tmp[1].split("/")[0] : tmp[0].split("/")[0];
} else {
return "";
}
}
function wordWrap(txt) {
var w = txt.split(" ");
var r = [];
for(var i=0; i<w.length; i++) {
if(w[i].length>40) {
var stops = Math.ceil(w[i].length / 40) + 1;
for(var j=0; j<stops; j++) {
r[i] += w[i].substr(stops, 40) + "&shy;";
}
} else {
r[i] = w[i];
}
}
return r.join(" ");
}
function loadIcon(v_img, v_urls) {
var el = new Image();
var img = v_img;
var urls = v_urls;
var f = function() {
if(urls.length > 0) {
el.urls = urls;
el.onload = function() {
this.onerror = null;
img.setAttribute("src", this.src);
}
el.onerror = function() {
if(this.urls.length > 0) {
var url = "";
while(!url && (this.urls.length > 0) && (trim(url) == "")) {
url = urls.shift();
}
if(url) {
if(url.indexOf("http://") == -1) {
url = "http://" + url;
}
this.setAttribute("src", url);
}
} else {
this.onerror = null;
}
}
el.onerror();
}
}
setTimeout(f, 100);
}
function fix_event(event) {
if (!event) {
event = window.event;
}
if (event.target) {
if (event.target.nodeType == 3) event.target = event.target.parentNode;
} else if (event.srcElement) {
event.target = event.srcElement;
}
var tg = event.target;
while(tg && (tg.entityInfo == undefined) && (tg != document.body)) {
tg = tg.parentNode;
}
event.target.entityInfo = tg.entityInfo;
return event;
}
function stopPropagation(anEvent) {
if(!anEvent) anEvent = window.event;
if(anEvent) {
if(anEvent.stopPropagation) anEvent.stopPropagation(); else anEvent.cancelBubble = true;
}
}
function preventDefault(anEvent) {
if(!anEvent) anEvent = window.event;
if(anEvent) {
if (anEvent.preventDefault) anEvent.preventDefault(); else anEvent.returnValue = false;
}
}
function killEvent(anEvent) {
if(anEvent) {
stopPropagation(anEvent);
preventDefault(anEvent);
}
return false;
}
/*********************************************
*
*   DEBUG
*
********************************************/
function varp(v) {
alert(Dump(v));
}
function varpw(v) {
win = open("", "varp", "width=900,toolbar=no,status=no,titlebar=no,scroollbars=yes");
win.document.write("<html><body><pre style='font-family: Tahoma, Verdana, Arial; font-size: 11px;'>"+Dump(v)+"</pre></body></html>");
}
function info(v) {
var s ='';
for(var i in v) {
s+=i + '; ';
}
alert(s);
}
function Dump(d,l) {
if (l == null) l = 1;
var s = '';
if (typeof(d) == "object") {
s += " {\n";
for (var k in d) {
for (var i=0; i<l; i++) s += "  ";
s += k+": " + Dump(d[k],l+1);
}
for (var i=0; i<l-1; i++) s += "  ";
s += "}\n"
} else if(typeof(d) != "function"){
s += "" + d + "\n";
}
return s;
}
function toCode(d,l) {
if (l == null) l = 1;
var s = '';
if (typeof(d) == "object") {
var items = [];
var i = 0;
if(d) {
var isList = d.length != undefined;
} else {
var isList = false;
}
for(var k in d) {
switch(typeof(d[k])) {
case "integet":
var v = parseInt(d[k]);
break;
case "string":
var v = "'" + d[k] + "'";
break;
case "function":
continue;
break;
default:
var v = toCode(d[k],l+1);
break;
}
items[i] = isList ? v : (k + ":" + v);
i++;
}
if(isList) {
s += "[" + items.join(",") + "]";
} else {
s += "{" + items.join(",") + "}";
}
} else if(typeof(d) != "function") {
s += "" + d;
}
return s;
}
function toValue(str) {
if(str) {
eval("var r = "+str);
return r;
} else {
return {}
}
}
/*********************************************
*
*   COOKIES
*
********************************************/
function getCookie(name) {
var cookie = " " + document.cookie;
var search = " " + name + "=";
var setStr = "";
var offset = 0;
var end = 0;
if (cookie.length > 0) {
offset = cookie.indexOf(search);
if (offset != -1) {
offset += search.length;
end = cookie.indexOf(";", offset)
if (end == -1) {
end = cookie.length;
}
setStr = unescape(cookie.substring(offset, end));
}
}
return(setStr);
}
function setCookie(name, value) {
var today = new Date();
today.setTime(today.getTime());
var expires_date = new Date(today.getTime() + 31536000000);
document.cookie = name + "=" + escape(value) + ";expires=" + expires_date.toGMTString();
}
function delCookie(name) {
if(getCookie(name)) {
document.cookie = name + "=;expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
}
/*********************************************
*
*   STRINGS
*
********************************************/
function text2html(txt) {
txt = txt.replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br>");
return txt;
}
function html2text(html) {
html = html.replace(/<br>/g,"\n").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">");
return html;
}
String.prototype.addSlashes = function() {
return this.replace(/\\/g,'\\\\').replace(/\"/g,"\\\"").replace(/\'/g,"\\\'");
}
String.prototype.stripSlashes = function() {
return this.replace(/\\'/g,'\'').replace(/\\"/g,'"').replace(/\\\\/g,'\\');
}
String.prototype.wordWrap = function(w) {
var i, j, s, r = this.split("\n");
if(w > 0) for(i in r){
for(s = r[i], r[i] = ""; s.length > w;
r[i] += s.substr(0, w) + ((s = s.substr(w)).length ? "&shy;" : "")
);
r[i] += s;
}
return r.join("\n");
}
String.prototype.jsEscape = function() {
return this.replace(/\%/g, "%jcp").replace(/\n/g, "%jcn").replace(/\r/g, "%jcr").replace(/"/g, "%jcqq").replace(/'/g, "%jcq").replace(/\\/g, "%jcbs").replace(/\u00E4/g, "a").replace(/\u00F6/g, "%ooo").replace(/\u00FC/g, "%uuu").replace(/\u00C4/g, "A").replace(/\u00D6/g, "%OOO").replace(/\u00DC/g, "%UUU").replace(/\u00DF/g, "%sss");
}
String.prototype.jsUnescape = function() {
return this.replace(/\%jcr/g, " ").replace(/\%jcn/g, "\n").replace(/\%jcqq/g, "\"").replace(/\%jcq/g, "'").replace(/\%jcbs/g, "\\").replace(/\%jcp/g, "%").replace(/%aaa/g, "a").replace(/%ooo/g, "\u00F6").replace(/%uuu/g, "\u00FC").replace(/%AAA/g, "A").replace(/%OOO/g, "\u00D6").replace(/%UUU/g, "\u00DC").replace(/%sss/g, "\u00DF");
}
String.prototype.parseUrl = function(){
var lines = this.split("<br>");
for(var z=0; z<lines.length; z++){
var tmp = lines[z].split(" ");
for(var i=0; i<tmp.length; i++){
if(tmp[i].indexOf("www.")!=-1 && tmp[i].indexOf("http://")==-1){
tmp[i] = "<a href='http://"+tmp[i]+"' target='_blank'>"+tmp[i]+"</a>";
} else if(tmp[i].indexOf("http://")!=-1 || tmp[i].indexOf("ftp://")!=-1 || tmp[i].indexOf("https://")!=-1){
tmp[i] = "<a href='"+tmp[i]+"' target='_blank'>"+tmp[i]+"</a>";
} else if (tmp[i].indexOf("@") != -1 && tmp[i].charAt(0) != "@" && tmp[i].charAt(tmp[i].length-1) != "@") {
tmp[i] = "<a href='mailto:"+tmp[i]+"'>"+tmp[i]+"</a>";
}
}
lines[z] = tmp.join(" ");
}
return lines.join("<br>");
}
requests_counter = 0;
function updateLoadingIcon(ofs) {
requests_counter += ofs;
if(requests_counter <= 0) {
hideEl(elById("loading_spinner"));
} else {
showEl(elById("loading_spinner"));
}
}
function Request() {
this.controllerURL = "controller.php";
this.convertParams = function(hash) {
var res = [];
for(k in hash) {
res.push(k + "=" + encodeURIComponent(hash[k]));
}
return res.join("&");
}
this.getNoCache = function() {
return ("" + Math.random()).slice(2, 8);
}
this.getTransportObj = function() {
var req;
if (window.XMLHttpRequest) {
try { req = new XMLHttpRequest() } catch(e) {}
} else if (window.ActiveXObject) {
try { req = new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}
if (!req) {
try { req = new ActiveXObject("Msxml2.XMLHTTP") } catch (e) {}
}
}
return req;
}
this.send = function(params, widget, method) {
var req = this.getTransportObj();
if(!req) {
return false;
}
var widgetId = widget.id;
params.module = widget.cfg.module;
var date = new Date();
params["_nc"] = this.getNoCache();
req.onreadystatechange = function() {
if (req.readyState == 4) {
if ((req.status < 400) && req.responseText) {
updateLoadingIcon(-1);
try {
eval("if(kernel.getWidget(widgetId)) { kernel.getWidget(widgetId).dispatchMsg("+req.responseText+")}");
} catch(e) { }
} else { }
}
}
if (method == "POST") {
req.open("POST", this.controllerURL, false);
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8;');
req.send(this.convertParams(params));
} else {
req.open("GET", this.controllerURL + "?" + this.convertParams(params), true);
req.send(null);
}
updateLoadingIcon(1);
return req;
}
this.getXML = function(url, obj, callback) {
var req = this.getTransportObj();
var o = obj
var cb = callback;
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status < 400) {
updateLoadingIcon(-1);
if(req.responseXML) {
o[cb](req.responseXML.documentElement);
}
} else {
o[cb](null);
}
}
}
if(url.indexOf("http:") != -1) {
req.open("GET", "xmlproxy.php?url=" + escape(url) + "&_nc=" + this.getNoCache(), true);
} else {
req.open("GET", url + "?_nc=" + this.getNoCache(), true);
}
updateLoadingIcon(1);
req.send(null);
return req;
}
this.getUWA = function(url, obj, callBack) {
var req = this.getTransportObj();
req.onreadystatechange = function() {
if(req.readyState == 4) {
if(req.status < 400) {
updateLoadingIcon(-1);
obj[callBack](req.responseXML);
} else {
callBack(null);
}
}
}
if(url.indexOf("http://") == -1) {
url = "http://" + url;
}
req.open("GET", "uwaproxy.php?url=" + encodeURIComponent(url) + "&_nc=" + this.getNoCache(), true);
req.send(null);
}
this.getFeed = function(url, widget, method) {
var req = this.getTransportObj();
var widgetId = widget.id;
req.onreadystatechange = function() {
if(req.readyState == 4) {
if(req.status < 400) {
updateLoadingIcon(-1);
if(kernel.getWidget(widgetId)) { kernel.getWidget(widgetId)[method](toValue(req.responseText)); }
}
}
}
if(url.indexOf("http://") == -1) {
url = "http://" + url;
}
req.open("GET", "xmlproxy.php?url=" + encodeURIComponent(url) + "&type=feed&_nc=" + this.getNoCache(), true);
req.send(null);
updateLoadingIcon(1);
}
this.commonRequest = function(url, callBack, type) {
var req = this.getTransportObj();
req.onreadystatechange = function() {
if(req.readyState == 4) {
if(req.status < 400) {
updateLoadingIcon(-1);
switch(type) {
case "xml":
callBack(req.responseXML);
break;
case "uwa":
callBack(req.responseXML);
break;
case "feed":
case "json":
callBack(toValue(req.responseText));
break;
default:
callBack(req.responseText);
break;
}
} else {
callBack(null);
}
}
}
if(url.indexOf("http://") == -1) {
url = "http://" + url;
}
req.open("GET", "xmlproxy.php?url=" + encodeURIComponent(url) + "&type=" + type + "&_nc=" + this.getNoCache(), true);
req.send(null);
updateLoadingIcon(1);
}
}
function XMLRequest() {
this.send = function(url, widget, callback, params, noProxy) {
var req;
if (window.XMLHttpRequest) {
try { req = new XMLHttpRequest() } catch(e) {}
} else if (window.ActiveXObject) {
try { req = new ActiveXObject("MSXML2.XMLHttp") } catch (e) {}
if (!req) {
try { req = new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}
}
}
if(!req) {
return false;
}
var date = new Date();
noCache = '&_nc='+ request.getNoCache();
var paramStr = "";
if(params) {
for(var i in params) {
paramStr += "&"+i+"="+escape(params[i]);
}
}
var widgetId = widget.id;
var cf = callback;
req.onreadystatechange = function() {
updateLoadingIcon(-1);
if (req.readyState == 4) {
if (req.status == 200) {
updateLoadingIcon(-1);
try {
if(kernel.getWidget(widgetId)) {
kernel.getWidget(widgetId)[cf](req);
}
} catch(e) {  }
} else {	}
}
}
if(noProxy == true) {
req.open("GET", url+"?"+noCache, true);
} else {
req.open("GET", "xmlproxy.php?url="+escape(url)+paramStr+noCache, true);
}
req.send(null);
updateLoadingIcon(1);
return req;
}
this.sendg = function(url, widget, callback, params, noProxy) {
var req;
if (window.XMLHttpRequest) {
try { req = new XMLHttpRequest() } catch(e) {}
} else if (window.ActiveXObject) {
try { req = new ActiveXObject("MSXML2.XMLHttp") } catch (e) {}
if (!req) {
try { req = new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}
}
}
if(!req) {
return false;
}
var date = new Date();
noCache = '&_nc='+ request.getNoCache();
var paramStr = "";
if(params) {
for(var i in params) {
paramStr += "&"+i+"="+escape(params[i]);
}
}
var widgetId = widget.id;
var cf = callback;
req.onreadystatechange = function() {
updateLoadingIcon(-1);
if (req.readyState == 4) {
if (req.status == 200) {
updateLoadingIcon(-1);
try {
if(kernel.getWidget(widgetId)) {
kernel.getWidget(widgetId)[cf](req);
}
} catch(e) {  }
} else {	}
}
}
req.open("GET", "xmlproxyg.php?url="+escape(url)+paramStr+noCache, true);
req.send(null);
updateLoadingIcon(1);
return req;
}
}
var XMLParser = {
xml2hash: function(xmlDocElem, tagItemName) {
var self = XMLParser;
var xmlElemArray = new Array;
var xmlElemRow;
var objArray = [];
if(!tagItemName) {
tagItemName = 'item';
}
if (xmlDocElem.hasChildNodes()) {
xmlElemArray = xmlDocElem.getElementsByTagName(tagItemName);
if(xmlElemArray && xmlElemArray.length == 0) {
xmlElemArray = xmlDocElem.getElementsByTagName('entry');
}
xmlElemRow = xmlElemArray[0];
for (var j = 0; j < xmlElemArray.length; j++) {
xmlElemRow = xmlElemArray[j];
objArray[j] = self.xmlElem2Obj(xmlElemArray[j]);
}
}
var linkEl = xmlDocElem.getElementsByTagName("link")[0];
if(linkEl) {
if(linkEl.firstChild) {
var siteUrl = linkEl.firstChild.nodeValue;
} else if(linkEl.attributes["href"]) {
var siteUrl = linkEl.attributes["href"].nodeValue;
}
}
var title = "";
if(xmlDocElem.getElementsByTagName("title")[0]) {
title = xmlDocElem.getElementsByTagName("title")[0].firstChild.nodeValue;
}
var updated = "";
if(xmlDocElem.getElementsByTagName("updated")[0]) {
updated = xmlDocElem.getElementsByTagName("updated")[0].firstChild.nodeValue;
} else if(xmlDocElem.getElementsByTagName("pubDate")[0]) {
updated = xmlDocElem.getElementsByTagName("pubDate")[0].firstChild.nodeValue;
}
return title ? { title: title, siteUrl: siteUrl, items: objArray, updated: updated} : null;
},
parseBookmarks: function(node) {
var self = XMLParser;
var res = [];
var tags = [];
self.parseBookmarksNode(res, tags, node.getElementsByTagName("DL")[0]);
return res ? res : null;
},
parseBookmarksNode: function(res, tags, node) {
var self = XMLParser;
switch(node.tagName) {
case "A":
var curTags = clone(tags);
res.push({ title: node.firstChild.nodeValue,
url: node.getAttribute("HREF"),
tags: curTags.length>0 ? curTags : null});
break;
case "H3":
tags.push(node.firstChild.nodeValue);
break;
case "DL":
for(var i=0; i<node.childNodes.length; i++) {
if(node.childNodes[i].nodeType == 1 && node.childNodes[i].firstChild) {
self.parseBookmarksNode(res, tags, node.childNodes[i]);
}
}
tags.pop();
break;
}
return res;
},
xmlElem2Obj: function(xmlElem) {
var self = XMLParser;
var ret = new Object();
self.setPropertiesRecursive(ret, xmlElem);
return ret;
},
setPropertiesRecursive: function(obj, node) {
var self = XMLParser;
if (node.childNodes.length > 0) {
for (var i = 0; i < node.childNodes.length; i++) {
if(node.childNodes[i].nodeName == "content") {
obj["content"] = self.toHTML(node.childNodes[i].firstChild.nodeValue);
} else if(node.childNodes[i].nodeName == "content:encoded") {
obj["content"] = node.childNodes[i].firstChild.nodeValue;
} else if(node.childNodes[i].nodeType == 1) {
if(node.childNodes[i].firstChild) {
if(node.childNodes[i].childNodes.length == 1) {
obj[node.childNodes[i].tagName] = node.childNodes[i].firstChild.nodeValue;
}
else {
obj[node.childNodes[i].tagName] = [];
self.setPropertiesRecursive(obj[node.childNodes[i].tagName], node.childNodes[i]);
}
} else if (node.childNodes[i].attributes.length>0) {
var attrs = {};
for(var a = 0; a < node.childNodes[i].attributes.length; a++) {
attrs[node.childNodes[i].attributes[a].nodeName] = node.childNodes[i].attributes[a].nodeValue;
}
obj[node.childNodes[i].tagName] = attrs;
}
}
}
}
},
cleanXMLObjText: function(xmlObj) {
var self = XMLParser;
var cleanObj = xmlObj;
for (var prop in cleanObj) {
cleanObj[prop] = cleanText(cleanObj[prop]);
}
return cleanObj;
},
cleanText: function(str) {
var self = XMLParser;
var ret = str;
ret = ret.replace(/\n/g, '');
ret = ret.replace(/\r/g, '');
ret = ret.replace(/\'/g, "\\'");
ret = ret.replace(/\[CDATA\[/g, '');
ret = ret.replace(/\]]/g, '');
return ret;
},
toHTML: function(str) {
var html = str;
html = html.replace(/\&lt\;/, '<');
html = html.replace(/\&gt\;/, '>');
return html;
},
rendered2Source: function(str) {
var self = XMLParser;
var proc = str;
proc = proc.replace(/</g, '&lt;');
proc = proc.replace(/>/g, '&gt;');
return '<pre>' + proc + '</pre>';
},
getXMLDocElem: function(xmlDivId, xmlNodeName) {
var self = XMLParser;
var xmlElemArray = [];
var xmlDocElem = null;
if (document.all) {
var xmlStr = document.getElementById(xmlDivId).innerHTML;
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.loadXML(xmlStr);
xmlDocElem = xmlDoc.documentElement;
}
else {
xmlElemArray = window.document.body.getElementsByTagName(xmlNodeName);
xmlDocElem = xmlElemArray[0]; ;
}
return xmlDocElem;
}
}
function plog(info) {
if(DEBUG) {
desktop.elements.debug_info.innerHTML = info + "<br>" + desktop.elements.debug_info.innerHTML;
}
}
colorsChart = [
["#FFEEEE", "#FFCCCC", "#FFAAAA", "#FF8888", "#FF6666", "#FF4444", "#FF2222", "#FF0000", "#EE0000", "#CC0000", "#AA0000", "#880000", "#770000", "#660000", "#550000", "#440000", "#330000"],
["#EEFFEE", "#CCFFCC", "#AAFFAA", "#88FF88", "#66FF66", "#44FF44", "#22FF22", "#00FF00", "#00EE00", "#00CC00", "#00AA00", "#008800", "#007700", "#006600", "#005500", "#004400", "#003300"],
["#EEEEFF", "#CCCCFF", "#AAAAFF", "#8888FF", "#6666FF", "#4444FF", "#2222FF", "#0000FF", "#0000EE", "#0000CC", "#0000AA", "#000088", "#000077", "#000066", "#000055", "#000044", "#000033"],
["#FFFFEE", "#FFFFCC", "#FFFFAA", "#FFFF88", "#FFFF66", "#FFFF44", "#FFFF22", "#FFFF00", "#EEEE00", "#CCCC00", "#AAAA00", "#888800", "#777700", "#666600", "#555500", "#444400", "#333300"],
["#FFEEFF", "#FFCCFF", "#FFAAFF", "#FF88FF", "#FF66FF", "#FF44FF", "#FF22FF", "#FF00FF", "#EE00EE", "#CC00CC", "#AA00AA", "#880088", "#770077", "#660066", "#550055", "#440044", "#330033"],
["#FFF0D0", "#FFEECC", "#FFEEBB", "#FFDDAA", "#FFCC99", "#FFC090", "#EEBB88", "#DDAA77", "#CC9966", "#BB8855", "#AA7744", "#886633", "#775522", "#664411", "#553300", "#442200", "#331100"],
["#EEFFFF", "#CCFFFF", "#AAFFFF", "#88FFFF", "#66FFFF", "#44FFFF", "#22FFFF", "#00FFFF", "#00EEEE", "#00CCCC", "#00AAAA", "#008888", "#007777", "#006666", "#005555", "#004444", "#003333"],
["#FFFFFF", "#EEEEEE", "#DDDDDD", "#CCCCCC", "#BBBBBB", "#AAAAAA", "#A0A0A0", "#999999", "#888888", "#777777", "#666666", "#555555", "#444444", "#333333", "#222222", "#111111", "#000000"]
];
// make interface
function createButtonDom(title, action, icon, id, img_id) {
if((icon != false) && (icon != null) && (icon != undefined)) {
if(title) {
var button = { tag: "span",
childs: [
{ tag: "img", id: img_id, src: icon, style: { margin: "0px 4px 0px 0px", verticalAlign: "middle"}},
{ tag: "a", href: "void", events: {onclick: action}, innerHTML: title }
]}
if(id) button.childs[1].id = id;
} else {
var button = { tag: "a", href: "void", events: {onclick: action}, childs: [ { tag: "img", id: img_id, src: icon} ]};
if(id) button.id = id;
}
} else {
var button = { tag: "a", href: "void", events: {onclick: action}, innerHTML: title};
if(id) button.id = id;
}
return button;
}
function createButtonMenu (title, action, icon, id, img_id) {
if((icon != false) && (icon != null) && (icon != undefined)) {
var button = { tag: "span",
childs: [
{ tag: "img", className: "menu_button", id: img_id, src: icon, events: {onclick: action}, style: { margin: "0px 4px 0px 0px", verticalAlign: "middle"}},
{ tag: "a", href: "void", className: "menu_button", events: {onclick: action}, innerHTML: title }
]}
if(id) button.childs[1].id = id;
} else {
var button = { tag: "a", href: "void", events: {onclick: action}, innerHTML: title};
if(id) button.id = id;
}
return button;
}
function createTableDom(tds, width) {
var table = { tag: "table", width: (width ? width : "95%"), childs: { tr: { tag: "tr", childs: {} } } };
for(var i=0; i<tds.length; i++) {
if(typeof(tds[i].content) == "string") {
table.childs.tr.childs[i] = { tag: "td", width: tds[i].width, innerHTML: tds[i].content };
} else {
table.childs.tr.childs[i] = { tag: "td", width: tds[i].width, childs: [tds[i].content] };
}
}
return table;
}
function createPanelDom(name, title, content) {
var m = { tag: "div", className: "panel", display: false, id: "panel_" + name,
childs: [
{ tag: "div", className: "panel_header",
childs: [
{ tag: "div", className: "panel_title", innerHTML: title },
{ tag: "div", className: "panel_close_icon", events: { onclick: "hideElement('panel_" + name + "')"} }
]}
]}
for(var i in content) {
m.childs.push({ tag: "div", className: "panel_section", childs: content[i] });
}
return m;
}
// CRC32
(function() {
var table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D";
/* Number */
crc32 = function( /* String */ str, /* Number */ crc ) {
if( crc == window.undefined ) crc = 0;
var n = 0; //a number between 0 and 255
var x = 0; //an hex number
crc = crc ^ (-1);
for( var i = 0, iTop = str.length; i < iTop; i++ ) {
n = ( crc ^ str.charCodeAt( i ) ) & 0xFF;
x = "0x" + table.substr( n * 9, 8 );
crc = ( crc >>> 8 ) ^ x;
}
return crc ^ (-1);
};
})();
function Widget() {
this.defaultProfile = {
title: ""
}
this.domModel =
{ tag: "div", className: "window", id: "window",
childs: [
{ tag: "div",
childs: [
{ tag: "table", className: "plan_table", style: { width: "100%"},
childs: [
{ tag: "tr",
childs: [
{ tag: "td", className: "window_caption_left" },
{ tag: "td", className: "window_caption_middle",
childs: [
{ tag: "div", className: "window_caption",
id: "caption" }
]},
{ tag: "td", className: "window_caption_right" }
]}
]}
]},
{ tag: "div", className: "window_setting", id: "settings"},
{ tag: "div", className: "window_content",
id: "content" },
{ tag: "div", className: "window_footer", id: "footer",
childs: [
{ tag: "table", className: "plan_table", style: {width: "100%"},
childs: [
{ tag: "tr",
childs: [
{ tag: "td", className: "window_footer_left" },
{ tag: "td", className: "window_footer_middle", innerHTML: "&nbsp;"},
{ tag: "td", className: "window_footer_right" }
]}
]}
]}
]
}
this.init = function() {
this.elements = {};
this.id = null;
this.isReduced = false;
this.isSettingsReduced = true;
this.profile = {};
this.isPreview = false;
}
this.init();
this.open = function(parent, id, profile, param) {
this.buildWindow(parent);
this.buildInterface();
if(this.elements.window) {
this.elements.window.wid = this.id;
}
this.onOpen(param);
}
this.setParent = function(parentEl) {
this.elements.window.parentNode.removeChild(this.elements.window);
parentEl.appendChild(this.elements.window);
}
this.buildWindow = function(parent) {
this.domModel.display = !this.cfg.isOpenHidden;
if(this.cfg.hasDrag) {
this.domModel.events = { onmouseover: "checkMouseInOut(1)", onmouseout: "checkMouseInOut(0)"}
}
this.buildDomModel(parent, this.domModel);
var m = [];
if(this.cfg.hasSizeBtn) {
m.push(
{ tag: "div", className: "caption_left_element", display: false, id: "showhide_div",
childs: [
{ tag: "div", id: "btn_hide", className: "btn_hide", title: loc.text("wbtn_hide"), events: {onclick: "switchSize()"} },
{ tag: "div", id: "btn_show", className: "btn_show", title: loc.text("wbtn_show"), events: {onclick: "switchSize()"}, display: false}
]}
);
}
if(this.cfg.hasIcon) {
m.push(
{ tag: "div", id: "icon_div", className: "caption_left_element",
childs: [
{ tag: "img", id: "icon", src: "widgets/"+this.cfg.module.toLowerCase()+"/ico.gif", style: { width: "16px", height: "16px", paddingTop:"4px"}}
]}
);
}
m.push( { tag: "div", id: "title", className: "caption_title" });
if(this.cfg.hasCloseBtn) {
m.push({ tag: "a", href: "void", title: loc.text("wbtn_close"), className: "btn_close", display: !this.cfg.hasDrag, events: {onclick: "close()"}, id: "btn_close" });
}
if(this.cfg.hasSettingsBtn) {
m.push({ tag: "a", href: "void", title: loc.text("wbtn_settings"), className: "btn_settings", display: !this.cfg.hasDrag, events: {onclick: "switchSettings()"}, id: "btn_settings" } );
}
if(this.cfg.hasRefreshBtn) {
m.push({ tag: "a", href: "void", title: loc.text("wbtn_refresh"), className: "btn_refresh", display: !this.cfg.hasDrag, events: {onclick: "refresh()"}, id: "btn_refresh" } );
}
this.buildDomModel(this.elements["caption"], m);
}
this.initDtagAndDrop = function() {
if(this.cfg.hasDrag) {
this.elements.caption.style.cursor = 'move';
this.elements.window.drag = new Drag(this.elements.window, this.elements.caption);
}
}
this.buildInterface = function() {
if(!this.isPreview) {
this.initDtagAndDrop();
}
this.buildDomModel(this.elements.settings,
{ tag: "div", className: "settings_section",
childs: [
{tag: "span", innerHTML: loc.text("inp_title"), className: "settings_label"},
{tag: "input", id: "input_title", type: "text", size: "15", className: "settings_control"},
{tag: "input", type: "button", value: loc.text("btn_set"), events: {onclick: "settingsSetTitle()"}, className: "settings_control"}
]}
);
this.onBuildInterface();
}
this.disableOnClosePrompt = false;
this.isForceClose = false;
this.forceClose = function() {
this.isForceClose = true;
this.disableOnClosePrompt = true;
this.close();
}
this.close = function() {
var flag = (this.cfg.hasOnCloseConfirm && !this.disableOnClosePrompt) ? confirm(loc.text("desktop_confirm_widget_remove")) : true;
if(flag) {
this.onClose();
kernel.freeWidget(this.id);
if(this.elements.window) {
deleteEl(this.elements.window);
this.elements.window.innerHTML = '';
this.elements.window = null;
}
this.profile = false;
this.save();
if(this.cfg.hasDrag && !this.isForceClose) {
desktop.savePanels();
}
}
}
this.setTitle = function(html) {
this.elements.title.innerHTML = html;
}
this.checkMouseInOut = function(mouse_in) {
if (mouse_in==1 || this.isSettingsReduced==false) {
if(this.cfg.hasCloseBtn && !this.isPreview)    this.elements.btn_close.style.display = 'block';
if(this.cfg.hasSettingsBtn) this.elements.btn_settings.style.display = 'block';
if(this.cfg.hasRefreshBtn)  this.elements.btn_refresh.style.display = 'block';
if(this.cfg.hasSizeBtn){
this.elements.showhide_div.style.display = 'block';
if(this.cfg.hasIcon) this.elements.icon_div.style.display = 'none';
}
}
else {
if(this.cfg.hasCloseBtn)    this.elements.btn_close.style.display = 'none';
if(this.cfg.hasSettingsBtn) this.elements.btn_settings.style.display = 'none';
if(this.cfg.hasRefreshBtn)  this.elements.btn_refresh.style.display = 'none';
if(this.cfg.hasSizeBtn){
this.elements.showhide_div.style.display = 'none';
if(this.cfg.hasIcon) this.elements.icon_div.style.display = 'block';
}
}
}
this.switchSize = function() {
if(this.isReduced) {
this.show();
} else {
this.hide();
}
}
this.show = function() {
hideEl(this.elements.btn_show);
showEl(this.elements.btn_hide);
if(this.elements.content) {
showEl(this.elements.content);
}
this.onShow();
this.isReduced = false;
}
this.hide = function() {
hideEl(this.elements.btn_hide);
showEl(this.elements.btn_show);
if(this.elements.content) {
hideEl(this.elements.content);
}
this.hideSettings();
this.onHide();
this.isReduced = true;
}
this.switchSettings = function() {
if(this.isSettingsReduced) {
this.showSettings();
} else {
this.hideSettings();
}
}
this.showSettings = function() {
this.onShowSettings();
showEl(this.elements.settings);
this.isSettingsReduced = !this.isSettingsReduced;
}
this.hideSettings = function() {
if(this.elements.settings) {
hideEl(this.elements.settings);
this.isSettingsReduced = !this.isSettingsReduced;
}
}
this.attachEvent = function(el, e, cmd) {
var wid = this.id;
if(mozilla_nav) {
el.setAttribute(e, "kernel.getWidget("+wid+")."+cmd+";");
} else {
el[e] = new Function("kernel.getWidget("+wid+")."+cmd+";");
}
}
this.attachClickEvent = function(el, e, cmd) {
var code = "kernel.getWidget(" + this.id + ")." + cmd + ";"
var f = function(e) {
this.blur();
eval(code);
return killEvent(e);
}
el[e] = f;
}
this.buildDomModel = function(parentEl, data) {
if(data["tag"]) {
var el = document.createElement(data.tag);
for (p in data) {
switch(p) {
case null, "tag", "childs": break;
case "cn":
el.className = data.cn;
break;
case "id":
this.elements[data.id] = el;
break;
case "style":
for(var s in data.style) {
el.style[s] = data.style[s];
}
break;
case "options":
if(data.options.start != undefined) {
var step = data.options.step || 1;
var options = [];
for(var i = data.options.start; i <=data.options.end; ) {
options.push( { text: i, value: i });
i += step;
}
} else {
var options = data.options;
}
if(options.length) {
for(var i=0; i<options.length; i++) {
el.options.add(new Option(options[i].text, options[i].value));
if(options[i].isBold) {
el.options[el.options.length - 1].style.fontWeight = "bold";
}
}
}
break;
case "src":
var src = data.src;
if(src.indexOf("http") == -1) {
src = "http://"+baseUrl+src;
}
if(ie_nav) {
var setSrc = function() { el.src = src }
setTimeout(setSrc, 200);
} else {
el.src = src;
}
break;
case "display":
if(!data[p]) {
el.style.display = 'none';
}
break;
case "href":
if(data.href == "void") {
el.href = "javascript:void(0);";
} else if(data.tag == "a") {
this.attachClickEvent(el, "onclick", data.href);
el.href = "javascript:void(0);";
} else {
el.href = data.href;
}
break;
case "html":
el.innerHTML = data.html;
break;
case "sysHref":
el.href = data.sysHref;
break;
case "events":
var wid = this.id;
if(typeof(data.events) == "object") {
for(var e in data.events) {
switch(e) {
case "onenter":
var wid = this.id;
el.onkeyup = function(event) {
event = fix_event(event);
if(event.keyCode == 13) {
eval("kernel.getWidget(wid)."+data.events[e]+";");
}
}
break;
default:
this.attachEvent(el, e, data.events[e]);
break;
}
}
}
break;
case "sysEvents":
if(typeof(data.sysEvents) == "object") {
for(var e in data.sysEvents) {
el.setAttribute(e, data.sysEvents[e]+";");
}
}
break;
default:
el[p] = data[p];
break;
}
}
parentEl.appendChild(el);
if(data.tag == "table") {
parentEl = el;
var el = document.createElement("tbody");
if(data.id) {
this.elements[data.id+"_tbody"] = el;
}
parentEl.appendChild(el);
}
if(data.childs) {
this.buildDomModel(el, data.childs);
}
} else if (typeof data == "object") {
for(var i in data) {
this.buildDomModel(parentEl, data[i]);
}
}
}
this.settingsSetTitle = function() {
var t = trim(this.elements.input_title.value);
t = t.replace(/\u00DF/g, "&szlig;").replace(/\u00E4/g, "&auml;").replace(/\u00F6/g, "&ouml;").replace(/\u00FC/g, "&uuml;").replace(/\u00C4/g, "&Auml;").replace(/\u00D6/g, "&Ouml;").replace(/\u00DC/g, "&Uuml;");
if(t != this.profile.title) {
this.profile.title = t;
this.setTitle(t);
this.save();
}
}
this.save = function() {
if(!this.isPreview) {
profiler.saveProfile(this);
}
}
this.onOpen = function() {}
this.onBuildInterface = function() {}
this.onClose = function() {}
this.onShow = function() {}
this.onHide = function() {}
this.onShowSettings = function() {}
this.onDrag = function() {}
this.timerHandler = function() {}
this.refresh = function() {}
this.dispatchMsg = function() {}
// SYS
this.hideElement = function(id) {
if(this.elements[id]) {
this.elements[id].style.display = 'none';
}
}
this.showElement = function(id, display) {
if(this.elements[id]) {
this.elements[id].style.display = display ? display : 'block';
}
}
this.deleteElement = function(id) {
if(this.elements[id].parentNode) {
this.elements[id].parentNode.removeChild(this.elements[id]);
}
this.elements[id] = null;
}
// Interface elements
this.ieIdCounter = 0;
this.getExpanderModel = function(title, content) {
this.ieIdCounter++;
var id = "_ie" + this.ieIdCounter;
var tid = id + "_title";
var cid = id + "_content";
var m =
{ tag: "div", className: "expander_box",
childs: [
{ tag: "div", className: "title_closed", id: tid, html: title, isExtended: false, events: { onclick: "switchExtender('" + id + "')" }},
{ tag: "div", className: "content", id: cid, display: false, childs: content }
]}
return m;
}
this.switchExtender = function(id) {
var tid = id + "_title";
var cid = id + "_content";
if(this.elements[tid].isExtended) {
this.hideElement(cid);
this.elements[tid].className = "title_closed";
} else {
this.showElement(cid);
this.elements[tid].className = "title_opened";
}
this.elements[tid].isExtended = !this.elements[tid].isExtended;
}
}
DRAG_NONE = 0;
DRAG_MOVE = 1;
DRAG_ANIM = 1;
Drag = function(win, caption) {
var div = win;
var action = DRAG_NONE;
var dragging = false;
var targetPos = {left: 0, top: 0};
var animSteps = 5;
var animFrame = 0;
var offset = {left: 0, top: 0};
var tid = null;
function calcOffset(event) {
event = fix_event(event);
var pos = getElPos(div);
offset.left = event.clientX - pos.left;
offset.top = event.clientY - pos.top;
}
function drag(event) {
event = fix_event(event);
if(action == DRAG_MOVE) {
var l = event.clientX - offset.left;
var h = event.clientY - offset.top;
div.style.left = l + "px";
div.style.top = h + "px";
desktop.processArea({left: l + Math.ceil(div.offsetWidth / 2), top: h + 16});
}
}
function processAnimation() {
var f = function() {
clearTimeout(tid);
animFrame ++;
if(animFrame < animSteps) {
var dPos = {
left: div.offsetLeft,
top: div.offsetTop
}
var newPos = {
left: Math.floor(dPos.left + (targetPos.left - dPos.left) / animSteps),
top: Math.floor(dPos.top + (targetPos.top - dPos.top) / animSteps)
}
div.style.left = newPos.left + "px";
div.style.top = newPos.top + "px";
tid = setTimeout(f, 50);
} else {
placeWindow();
}
}
tid = setTimeout(f, 50);
}
function stopDrag(event) {
event = fix_event(event);
document.onmousemove = null;
document.onmouseup = null;
document.ondrag = null;
document.body.onselectstart = null;
document.onselectstart = null;
targetPos = getElPos(desktop.elements.area);
targetPos.top -= 14;
animFrame = 0;
action = DRAG_ANIM;
processAnimation();
}
function placeWindow() {
clearTimeout(tid);
div.style.position = 'static';
desktop.elements.area.parentNode.insertBefore(div, desktop.elements.area);
div.style.width = 'auto';
desktop.stopArea();
desktop.savePanels();
action = DRAG_NONE;
}
function startDrag(event) {
event = fix_event(event);
if(action != DRAG_NONE) {
return false;
}
document.ondrag = function () { return false; }
document.body.ondrag = function () { return false; }
document.onselectstart = function () { return false; }
document.body.onselectstart = function () { return false; }
action = DRAG_MOVE;
calcOffset(event);
document.onmousemove = function(event) { drag(event) }
document.onmouseup = function(event) { stopDrag(event) }
putEl(div);
}
function putEl(el) {
var left = getLeft(el);
var top = getTop(el);
var width = el.offsetWidth;
desktop.startArea(el);
el.parentNode.removeChild(el);
document.body.appendChild(el);
el.style.position = 'absolute';
el.style.left = left + "px";
el.style.top = top + "px";
el.style.width = width + "px";
}
caption.onmousedown = function(event) {
event = fix_event(event);
if(action == DRAG_MOVE) {
stopDrag(event);
} else {
var e = event.target;
while(e.onclick == null && e != this) {
e = e.parentNode;
}
if(e == this) startDrag(event);
}
}
function fix_event(event) {
if (!event) {
event = window.event;
}
if (event.target) {
if (event.target.nodeType == 3) event.target = event.target.parentNode
} else if (event.srcElement) {
event.target = event.srcElement
}
return event
}
}
// events: onstart, onover, onstop
// mode: drag, menu, all
EntityHandler = function(el, mode, events) {
var div = el;
var divClone = null;
var dragging = false;
var offset = {left: 0, top: 0};
var startPos = {left: 0, top: 0};
var events = events ? events : {};
var belongElement = null;
function waitForDrag(event) {
event = fix_event(event);
if( (Math.abs(event.clientX - startPos.left) > 4) || (Math.abs(event.clientY - startPos.top) > 4)) {
dragging = true;
offset = {left: div.offsetWidth + 2,
top: div.offsetHeight + 2};
document.onmousemove = function(e) { drag(e) }
document.onmouseup = function(e) { stopDrag(e) }
divClone = div.cloneNode(true);
divClone.style.cssText = divClone.style.cssText + ";opacity: 0.75; -moz-opacity: 0.75; -khtml-opacity: 0.75; filter: alpha(opacity=75);";
document.body.appendChild(divClone);
divClone.style.position = 'absolute';
divClone.style.width = div.offsetWidth + "px";
divClone.style.height = div.offsetHeight + "px";
if(events.onDragStart) {
events.onDragStart(div.entityInfo);
}
if(event.target.entityInfo && events.onElementOver) {
events.onElementOver(event.target.entityInfo);
}
}
}
function drag(event) {
if(dragging) {
event = fix_event(event);
divClone.style.left = event.clientX + 2 + "px";
divClone.style.top = event.clientY + 2 + "px";
if(event.target.entityInfo && events.onElementOver) {
events.onElementOver(event.target.entityInfo);
}
}
}
function startDrag(event) {
event = fix_event(event);
document.ondrag = function () { return false; }
document.body.ondrag = function () { return false; }
document.onselectstart = function () { return false; }
document.body.onselectstart = function () { return false; }
document.onmousemove = function(e) { waitForDrag(event) }
document.onmouseup = function(e) { stopDrag(event) }
startPos = {left: event.clientX, top: event.clientY};
return false;
}
function stopDrag(event) {
event = fix_event(event);
document.onmousemove = null;
document.onmouseup = null;
document.ondrag = null;
document.body.onselectstart = null;
document.onselectstart = null;
desktop.isFileDrag = false;
if(div.onmouseout) {
div.onmouseout();
}
if(divClone) {
deleteEl(divClone);
}
if(events.onDragStop && dragging) {
events.onDragStop(div.entityInfo);
}
dragging = false;
}
switch(mode) {
case "tabs_drag":
div.onmousedown = function(event) {
desktop.hideTabOptions();
event = fix_event(event);
if(dragging) {
stopDrag(event);
} else {
startDrag(event);
}
if (event.stopPropagation) {
event.stopPropagation();
event.preventDefault();
} else if(window.event) {
window.event.cancelBubble = true;
window.event.returnValue = false;
}
return false;
}
}
}
// Tracker
Tracker = function(gripper, params) {
var dragging = false;
var offset;
var gripperOffset = - 3;
var gripperPos = Math.round(params.width * params.value / (params.end - params.start));
gripper.parentNode.style.width = params.width + "px";
setGripperPos();
function setGripperPos() {
gripper.style.marginLeft = gripperPos + gripperOffset + "px";
}
function getValue() {
return params.start + Math.round( (gripperPos / params.width) * (params.end - params.start));
}
function calcOffset(event) {
event = fix_event(event);
offset = event.clientX - gripperPos;
}
function drag(event) {
event = fix_event(event);
gripperPos = event.clientX - offset;
if(gripperPos < 0) {
gripperPos = 0;
} else if(gripperPos > params.width) {
gripperPos = params.width;
}
setGripperPos();
if(params.onchange) {
params.onchange(getValue());
}
}
function stopDrag(event) {
event = fix_event(event);
document.onmousemove = null;
document.onmouseup = null;
document.ondrag = null;
document.body.onselectstart = null;
document.onselectstart = null;
if(params.onstop) {
params.onstop(getValue());
}
dragging = false;
}
function startDrag(event) {
event = fix_event(event);
if(dragging) {
return false;
}
document.ondrag = function () { return false; }
document.body.ondrag = function () { return false; }
document.onselectstart = function () { return false; }
document.body.onselectstart = function () { return false; }
calcOffset(event);
document.onmousemove = function(event) { drag(event) }
document.onmouseup = function(event) { stopDrag(event) }
dragging = true;
}
gripper.onmousedown = function(event) {
event = fix_event(event);
if(dragging) {
stopDrag(event);
} else {
var e = event.target;
while(e.onclick == null && e != this) {
e = e.parentNode;
}
if(e == this) startDrag(event);
}
}
function fix_event(event) {
if (!event) {
event = window.event;
}
if (event.target) {
if (event.target.nodeType == 3) event.target = event.target.parentNode
} else if (event.srcElement) {
event.target = event.srcElement
}
return event
}
}
function startPage() {
request = new Request();
xmlRequest = new XMLRequest();
kernel = new Kernel();
loc = new Loc();
loc.onLoad = function() {
auth = new Auth();
auth.id = kernel.getUniqueId(auth);
kernel.addWidget(auth);
auth.onLoad = function() {
profiler = new Profiler();
profiler.id = kernel.getUniqueId(profiler);
kernel.addWidget(profiler);
profiler.onLoad = function(param) {
desktop = kernel.runDesktopWidget("Desktop", elById("desktop_body"), param);
window.onresize = desktop.onWindowResize;
auth.open(desktop.addPopup("auth"));
menu = kernel.runWidget("Menu", document.body);
feedback = kernel.runWidget("Feedback", desktop.addPopup("feedback"));
sendtofriend = kernel.runWidget("SendToFriend", desktop.addPopup("sendtofriend"));
rssreader = kernel.runWidget("RssReader", desktop.addPopup("rssreader"));
if(auth.isLogged()) konto = kernel.runWidget("Konto", desktop.addPopup("konto"));
desktop.wakeUp();
}
profiler.loadProfile();
}
auth.start();
}
loc.start();
}
SYS_WIDGETS_ID = 1;
USER_WIDGETS_ID = 100;
cfgWidget = {
hasIcon: true,
hasSizeBtn: true,
hasCloseBtn: true,
hasRefreshBtn: true,
hasSettingsBtn: true,
hasDrag: true,
hasOnCloseConfirm: true,
hasProfile: true,
isOpenHidden: false,
isSystem: false,
title: "",
module: "base",
uniqueId: false,
saveMethod: "GET"
}
function Kernel() {
this.widgets = [];
this.getUniqueId = function(w) {
if(w.cfg.uniqueId) {
return w.cfg.uniqueId;
} else {
var newId = USER_WIDGETS_ID;
while(this.widgets[newId]) newId++;
return newId;
}
}
this.getWidget = function(id) {
return this.widgets[id];
}
this.addWidget = function(widget) {
this.widgets[widget.id] = widget;
}
this.freeWidget = function(id) {
this.widgets[id] = null;
}
this.runWidget = function(className, parent, id, profile, objvars) {
var code = 'var w = new ' + className + '();';
try { eval(code); } catch(e) { }
if(w) {
profile = profile || false;
w.id = id || w.cfg.uniqueId || this.getUniqueId(w);
if(typeof(objvars) == "object") {
for(var i in objvars) {
w[i] = objvars[i];
}
}
kernel.addWidget(w);
for(var c in cfgWidget) {
if(typeof(w.cfg[c]) == "undefined") {
w.cfg[c] = cfgWidget[c];
}
}
if(w.cfg.hasProfile) {
profiler.registerWidget(w);
if(profile) {
for(var p in profile) {
w.profile[p] = profile[p];
}
}
}
w.open(parent, false, profile);
return w;
}
}
this.runDesktopWidget = function(className, parent, param) {
var w = new Desktop();
if(w) {
w.id = w.cfg.uniqueId;
kernel.addWidget(w);
for(var c in cfgWidget) {
if(typeof(w.cfg[c]) == "undefined") {
w.cfg[c] = cfgWidget[c];
}
}
if(w.cfg.hasProfile) {
profiler.registerWidget(w);
}
w.open(parent, false, false, param);
return w;
}
}
this.timers = [];
this.processTimer = function(widgetId, period, noAction) {
if(kernel.widgets[widgetId]) {
if(noAction != true) {
kernel.getWidget(widgetId).timerHandler();
}
kernel.timers[widgetId] = setTimeout("kernel.processTimer("+widgetId+","+period+")", period);
}
}
this.stopTimer = function(widgetId) {
if(this.timers[widgetId] != undefined) {
clearTimeout(this.timers[widgetId]);
this.timers[widgetId] = undefined;
}
}
}
/* Languages data */
function Loc() {
this.data = {};
this.start = function() {
request.getXML("lang/de.xml", this, "parseLangXML");
}
this.parseLangXML = function(xml) {
this.data = this.getHashList(xml, "string", "id");
this.onLoad();
}
this.text = function(id, param) {
var text = this.data[id] ? this.data[id] : "loc:" + id;
if(param && text != '') {
if(typeof(param) == "object") {
for(var i in param) {
var mask = new RegExp("%"+i+"%", "ig");
text = text.replace(mask, param[i]);
}
return text;
} else {
return text.replace(/(%\w*%)/ig, param);
}
}
return text;
}
this.getHashList = function(node, tagName, key) {
var hash = {};
if(node) {
var nodes = node.getElementsByTagName(tagName);
for(var i=0; i<nodes.length; i++) {
hash[nodes[i].getAttribute(key)] = nodes[i].firstChild ? nodes[i].firstChild.nodeValue : "";
}
}
return hash;
}
this.onLoad = function() {}
}
function Desktop() {
this.init();
this.cfg = {
hasSizeBtn: false,
hasCloseBtn: false,
hasRefreshBtn: false,
hasSettingsBtn: false,
hasDrag: false,
hasOnCloseConfirm: false,
isSystem: true,
title: "",
module: "desktop",
uniqueId: SYS_WIDGETS_ID + 1,
saveMethod: "POST"
}
this.defaultProfile["title"] = "";
this.defaultProfile["theme"] = "default";
this.defaultProfile["background"] = { top: false, bottom: false };
this.defaultProfile["header_size"] = 0;
this.defaultProfile["tabs"] = []; // [ {t: title, c: columner_id, i }, ...]
this.defaultProfile["order"] = []; // array of tab indexes
this.getTopDate = function () {
var d = new Date ();
var dateStr = "";
switch (d.getDay()) {
case 0: dateStr = loc.text('weather_sun')+", "+d.getDate()+". ";break;
case 1: dateStr = loc.text('weather_mon')+", "+d.getDate()+". ";break;
case 2: dateStr = loc.text('weather_tue')+", "+d.getDate()+". ";break;
case 3: dateStr = loc.text('weather_wed')+", "+d.getDate()+". ";break;
case 4: dateStr = loc.text('weather_thu')+", "+d.getDate()+". ";break;
case 5: dateStr = loc.text('weather_fri')+", "+d.getDate()+". ";break;
case 6: dateStr = loc.text('weather_sat')+", "+d.getDate()+". ";break;
default: dateStr = "";break;
}
if (dateStr != "") {
switch (d.getMonth()) {
case 0: dateStr += loc.text('month_jan')+" "+d.getFullYear();break;
case 1: dateStr += loc.text('month_feb')+" "+d.getFullYear();break;
case 2: dateStr += loc.text('month_mar')+" "+d.getFullYear();break;
case 3: dateStr += loc.text('month_apr')+" "+d.getFullYear();break;
case 4: dateStr += loc.text('month_may')+" "+d.getFullYear();break;
case 5: dateStr += loc.text('month_jun')+" "+d.getFullYear();break;
case 6: dateStr += loc.text('month_jul')+" "+d.getFullYear();break;
case 7: dateStr += loc.text('month_aug')+" "+d.getFullYear();break;
case 8: dateStr += loc.text('month_sep')+" "+d.getFullYear();break;
case 9: dateStr += loc.text('month_oct')+" "+d.getFullYear();break;
case 10: dateStr += loc.text('month_nov')+" "+d.getFullYear();break;
case 11: dateStr += loc.text('month_dec')+" "+d.getFullYear();break;
default: dateStr = "";break;
}
}
return dateStr;
}
this.domModel = [
{ tag: "div", display: false, id: "tmp" },
{ tag: "div", cn: "desktop_header",
id: "header",
childs: [
{ tag: "div", id: "top_line",
cn: "top_line",
childs: [
{ tag: "div", cn: "float_left",
childs: [
{ tag: "span", className: "top_date", innerHTML: this.getTopDate() }
]},
{ tag: "div", cn: "float_right",
childs: [
{ tag: "span", innerHTML: auth.user.email, cn: "listItemVisited" },
{ tag: "span", innerHTML: "&nbsp;&nbsp;&nbsp;&nbsp;" },
{ tag: "span", childs: [createButtonDom(loc.text("menu_title"), "switchMenu()", "widgets/menu/ico.gif")]},
{ tag: "span", innerHTML: "&nbsp;&nbsp;|&nbsp;&nbsp;" },
{ tag: "img", id: "hilfe", src: "static/client/hilfe.gif", style: { margin: "0px 4px 0px 0px", verticalAlign: "middle" }},
{ tag: "span", innerHTML: "<a onclick='window.open(this.href); return false;' href='hilfe.html'>Hilfe</a>" },
{ tag: "span", innerHTML: "&nbsp;&nbsp;|&nbsp;&nbsp;" },
{ tag: "span", id: "kontoButton" },
{ tag: "span", id: "authButton" }
]}
]},
{ tag: "div", cn: "title_section",
id: "title_section",
childs: [
{ tag: "div", className: "title",
childs:[
{ tag: "span", innerHTML: "<img src='static/logo/logo_top_new.gif'>"},
]
}
]
},
{ tag: "div", className: "tabs_panel",
id: "tabs",
childs: [
{ tag: "div", id: "add_page_button",
className: "tab_box",
events: {onclick: "addNewTab()"},
childs: [
{ tag: "div", className: "tab_left" },
{ tag: "div", className: "tab_middle",
childs: [
{ tag: "div", className: "tab_add_icon" }
]},
{ tag: "div", className: "tab_right" }
]}
]},
{ tag: "div", className: "header_hr" }
]},
// widgets
{ tag: "div", cn: "desktop_columns",
id: "desktop_columns" },
// footer
{ tag: "div", cn: "desktop_footer",
childs: [
{ tag: "span", className: "sp_footer", align: "center"},
{ tag: "span", id: "bottom_links_0", align: "center",
childs: [
{ tag: "a", href: "addToFavorites()", display: (mozilla_nav || ie_nav || opera_nav), html: loc.text('desktop_lnk_favorites') },
{ tag: "span", html: "<!--[if IE]>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='#' onClick='this.style.behavior=\"url(#default#homepage)\"; this.setHomePage(\"http://www.elch24.de\");'>Elch24 als Startseite</A><![endif]-->"},
{ tag: "span", html: "&nbsp;&nbsp;|&nbsp;&nbsp;" },
{ tag: "a", href: "showPopup('feedback')",
html: loc.text('desktop_lnk_user_feedback') },
{ tag: "span", html: "&nbsp;&nbsp;|&nbsp;&nbsp;" },
{ tag: "a", href: "showPopup('sendtofriend')",
html: loc.text('desktop_lnk_sendtofriend') },
{ tag: "span", html: "&nbsp;&nbsp;|&nbsp;&nbsp;" },
{ tag: "span", innerHTML: "<a onclick='window.open(this.href); return false;' href='impressum.html'>"+loc.text('desktop_lnk_impressum')+"</a>" },
{ tag: "span", html: "&nbsp;&nbsp;|&nbsp;&nbsp;" },
{ tag: "span", innerHTML: "<a onclick='window.open(this.href); return false;' href='nutzung.html'>"+loc.text('desktop_lnk_nutzung')+"</a>" },
{ tag: "span", html: "&nbsp;&nbsp;|&nbsp;&nbsp;" },
{ tag: "span", innerHTML: "<a onclick='window.open(this.href); return false;' href='datenschutz.html'>"+loc.text('desktop_lnk_datenschutz')+"</a>" },
]}
]},
{ tag: "div", id: "area", className: "area", name: "area", display: false},
{ tag: "div", id: "tab_area", className: "tab_area", name: "area", display: false},
// Tabs menu
createPanelDom("tab", loc.text("desktop_tab_options"), [
[ { tag: "span", innerHTML: "Title: "},
{ tag: "input", type: "text", id: "input_tab_title" },
{ tag: "input", type: "button", value: loc.text("btn_set"),
events: { onclick: "renameTab()" }} ],
[ { tag: "div", innerHTML: loc.text("desktop_select_tab_icon")},
{ tag: "div", id: "tab_icons_box" },
{ tag: "div",
childs: [
{ tag: "a", href: "void",
innerHTML: loc.text("desktop_delete_tab_icon"),
events: { onclick: "deleteTabIcon()"}}
]}]
])
]
this.newFeedUrl = null;
this.it = false;
this.onOpen = function(param) {
this.buildDomModel(document.body, { tag: "link", id: "themes_loader", rel: "stylesheet", media: "screen"});
this.recentWidgetsStorage = kernel.runWidget("RecentWidgetsStorage", document.body);
this.applyTheme();
this.applyHeaderSize();
this.elements["panel_tab"].style.position = "absolute";
this.elements["panel_tab"].style.width = "250px";
this.buildDomModel(document.body, [
{ tag: "div", id: "popups", display: false, cn: "popups_box" },
{ tag: "div", id: "overlay", events:
{ onclick: "hideActivePopup()"},
display: false, cn: "page_overlay" }
]);
if (param == 1)
this.it = true;
if (this.it){
var ns6=document.getElementById&&!document.all;
crossobj=ns6? document.getElementById("postit") : document.all.postit;
crossobj2=ns6? document.getElementById("postit2") : document.all.postit2;
crossobj3=ns6? document.getElementById("postit3") : document.all.postit3;
crossobj.style.left="640px";
crossobj.style.top="71px";
crossobj2.style.left="820px";
crossobj2.style.top="698px";
crossobj3.style.left="820px";
crossobj3.style.top="263px";
pointerobj=ns6? document.getElementById("dhtmlpointer") : document.all.dhtmlpointer;
pointerobj2=ns6? document.getElementById("dhtmlpointer2") : document.all.dhtmlpointer2;
pointerobj3=ns6? document.getElementById("dhtmlpointer3") : document.all.dhtmlpointer3;
pointerobj.src="static/client/arrow_med.gif";
pointerobj2.src="static/client/arrow.gif";
pointerobj3.src="static/client/arrow.gif";
pointerobj.style.left="650px";
pointerobj.style.top="24px";
pointerobj2.style.left="830px";
pointerobj2.style.top="635px";
pointerobj3.style.left="950px";
pointerobj3.style.top="200px";
this.showBubbles();
}
}
this.showBubbles = function () {
crossobj.style.visibility="visible";
crossobj2.style.visibility="visible";
crossobj3.style.visibility="visible";
pointerobj.style.visibility="visible";
pointerobj2.style.visibility="visible";
pointerobj3.style.visibility="visible";
}
this.closeit = function(){
crossobj.style.visibility="hidden";
pointerobj.style.visibility="hidden";
}
this.closeit2 = function(){
crossobj2.style.visibility="hidden";
pointerobj2.style.visibility="hidden";
}
this.closeit3 = function(){
crossobj3.style.visibility="hidden";
pointerobj3.style.visibility="hidden";
}
this.applyHeaderSize = function() {
var s = this.profile["header_size"];
this.elements["title_section"].style.margin = "0" + s + "px 0 " + s + "px";
}
this.applyTheme = function() {
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
var ieversion=new Number(RegExp.$1)
if (ieversion<7)
this.elements["themes_loader"].href = "themes/" + this.profile["theme"] + "/theme_ie6.css?v=" + (Math.random() * 1000000);
else
this.elements["themes_loader"].href = "themes/" + this.profile["theme"] + "/theme.css?v=" + (Math.random() * 1000000);
}
else {
if (safari_nav)
window.location = "safariredirect.html";
else
this.elements["themes_loader"].href = "themes/" + this.profile["theme"] + "/theme.css?v=" + (Math.random() * 1000000);
}
}
//--------------------------------------------
// Recent UWA widgets
//--------------------------------------------
this.getRecentWidgetsList = function() {
return this.recentWidgetsStorage.profile["list"];
}
this.addRecentWidget = function(info) {
var rw = this.recentWidgetsStorage;
for(var i=0; i<rw.profile["list"].length; i++) {
if(rw.profile["list"][i].url == info.url) {
rw.profile["list"].splice(i, 1);
break;
}
}
if(rw.profile["list"].length > 15) {
rw.profile["list"].pop();
}
rw.profile["list"].unshift(info);
rw.save();
}
//--------------------------------------------
// Main menu
//--------------------------------------------
this.isMenuShow = false;
this.switchMenu = function() {
if(this.isMenuShow) {
menu.hide();
this.showWebsearch();
} else {
this.hideWebsearch();
menu.show();
}
}
//--------------------------------------------
// Popups
//--------------------------------------------
this.popupsHistory = [];
this.showPopup = function(name) {
var l = this.popupsHistory.length;
if(this.popupsHistory[l-1] == name) return;
if(l) {
this.hideElement("popup_" + this.popupsHistory[l-1]);
} else {
this.hideWebsearch();
this.showElement("overlay");
this.showElement("popups");
}
this.popupsHistory.push(name);
this.showElement("popup_" + name);
var height = document.body.clientHeight || document.documentElement.clientHeight;
this.elements["overlay"].style.height = height + "px";
var top = document.documentElement.scrollTop || document.body.scrollTop;
this.elements["popups"].style.top = 50 + top + "px";
this.updatePopupPosition();
}
this.hideActivePopup = function() {
if(!this.popupsHistory.length) return;
var name = this.popupsHistory.pop();
this.hideElement("popup_" + name);
if(!this.popupsHistory.length) {
this.showWebsearch();
this.hideElement("popups");
this.hideElement("overlay");
}
}
this.addPopup = function(name) {
this.buildDomModel(this.elements["popups"],
{ tag: "div", id: "popup_" + name, display: false });
return this.elements["popup_" + name];
}
this.updatePopupPosition = function() {
var dw = document.body.clientWidth || document.documentElement.clientWidth;
var pw = this.elements["popups"].offsetWidth;
this.elements["popups"].style.left = Math.ceil(0.5 * (dw - pw)) + "px";
}
this.onWindowResize = function() {
if(!desktop.popupsHistory.length) return;
desktop.updatePopupPosition();
}
//--------------------------------------------
// System
//--------------------------------------------
this.buildWindow = function(parent) {
this.buildDomModel(parent, this.domModel);
}
this.buildInterface = function() {
this.profile["title"] = "";
with(this.elements) {
document.title = "Elch24 - Die pers\u00F6nliche Zeitung";
}
}
//--------------------------------------------
// TABS
//--------------------------------------------
this.columners = [];
this.tabOptionsShown = false;
this.getNewTabNumber = function() {
return this.profile["order"].length + 1;
}
this.addNewTab = function() {
var title = loc.text("desktop_tab_title") + this.getNewTabNumber();
var idx = arrayFirstFree(this.profile.tabs);
this.columners[idx] = kernel.runWidget("Columner", document.body);
this.columners[idx].profile["pcount"] = this.defaultPanelsCount;
this.columners[idx].save();
this.profile.tabs[idx] = {
t: title,
i: "",
cid: this.columners[idx].id
}
this.profile["order"][idx] = idx;
this.save();
this.buildDomModel(this.elements["desktop_columns"],
this.getPanelsDom(idx, this.defaultPanelsCount));
this.renderTab(idx, title);
this.showTab(idx);
}
this.getTabIconSrc = function(icon) {
return "static/tab_icons/" + icon + ".gif";
}
this.renderTab = function(n, title, icon) {
var icon_src = icon ? this.getTabIconSrc(icon) : "";
this.buildDomModel(this.elements.tmp,
{ tag: "div", id: "tab_"+n,
className: "tab_box",
entityInfo: { type: "tab", idx: n},
events: {onclick: "showTab('"+n+"')"},
childs: [
{ tag: "div", className: "tab_left" },
{ tag: "div", className: "tab_middle",
childs: [
{ tag: "div", className: "tab_icon",
childs: [
{ tag: "img", id: "tab_icon_" + n,
src: icon_src,
display: (icon_src != "") }
]},
{ tag: "div", className: "tab_title",
id: "tab_title_" + n,
innerHTML: title },
{ tag: "div", className: "tab_controls",
childs: [
{ tag: "div", className: "tab_close_btn",
events: { onclick: "closeTab('" + n + "')" }},
{ tag: "div", className: "tab_options_btn",
events: { onclick: "showTabOptions('" + n + "')" }}
]}
]},
{ tag: "div", className: "tab_right" }
]});
this.elements["tabs"].insertBefore(this.elements["tab_"+n], this.elements["add_page_button"]);
var eh = new EntityHandler(this.elements["tab_"+n], "tabs_drag",
{ onDragStart: desktop.onTabDragStart, onElementOver: desktop.onTabDragOver, onDragStop: desktop.onTabDragStop});
}
//--------------------------------------------
// Drag&drop tabs
//--------------------------------------------
this.belongTabInfo = null;
this.onTabDragStart = function(info) { }
this.onTabDragOver = function(info) {
if(info.type == "tab") {
desktop.belongTabInfo = info;
desktop.showElement("tab_area");
desktop.elements["tab_" + info.idx].parentNode.insertBefore(desktop.elements["tab_area"], desktop.elements["tab_" + info.idx]);
}
}
this.onTabDragStop = function(info) {
if((desktop.belongTabInfo != null) && (desktop.belongTabInfo.type == "tab") && (desktop.belongTabInfo.idx != info.idx)) {
desktop.elements["tab_" + info.idx].parentNode.insertBefore(desktop.elements["tab_" + info.idx], desktop.elements["tab_area"]);
for(var i=0; i< desktop.profile["order"].length; i++) {
if(desktop.profile["order"][i] == desktop.belongTabInfo.idx) {
var belongIdx = i;
}
if(desktop.profile["order"][i] == info.idx) {
var dragIdx = i;
}
}
desktop.profile["order"].splice(belongIdx - (belongIdx > dragIdx ? 1 : 0), 0, desktop.profile["order"].splice(dragIdx, 1)[0]);
desktop.save();
}
this.belongTabInfo = null;
desktop.hideElement("tab_area");
}
// show/hide tabs
this.activeTab = null;
this.hideTab = function(idx) {
this.hideTabOptions();
this.elements["tab_" + idx].className = "tab_box";
}
this.showTab = function(idx) {
if(this.activeTab != null && this.activeTab != idx) {
this.hideTab(this.activeTab);
this.hideElement("tab_container_" + this.activeTab);
}
this.activeTab = idx;
if(this.elements["tab_" + idx]) {
this.elements["tab_" + idx].className = "tab_box_selected";
this.showElement("tab_container_" + idx);
}
}
// tab options
this.showTabOptions = function(idx) {
var t = this.profile.tabs[idx].t;
t = t.replace(/&szlig;/g, "\u00DF").replace(/&auml;/g, "\u00E4").replace(/&ouml;/g, "\u00F6").replace(/&uuml;/g, "\u00FC").replace(/&Auml;/g, "\u00C4").replace(/&Ouml;/g, "\u00D6").replace(/&Uuml;/g, "\u00DC");
this.elements["input_tab_title"].value = t;
var pos = getElPos(this.elements["tab_" + idx]);
this.showElement("panel_tab");
this.elements["panel_tab"].style.left = Math.min(pos.left, (document.body.clientWidth - 255)) + "px";
this.elements["panel_tab"].style.top = (pos.top + this.elements["tab_" + idx].offsetHeight + 4) + "px";
this.elements["panel_tab"].style.zIndex = 5000;
if(!this.tabOptionsShown) {
this.tabOptionsShown = true;
for(var i=0; i< this.tabIcons.length; i++) {
this.buildDomModel(this.elements["tab_icons_box"],
{ tag: "a", href: "void",
events: { onclick: "setTabIcon('" + this.tabIcons[i] + "')"},
innerHTML: "<img src='" + this.getTabIconSrc(this.tabIcons[i]) + "' style='margin: 1px;'>"});
}
}
}
this.hideTabOptions = function() {
this.hideElement("panel_tab");
}
// tab managment
this.renameTab = function() {
var t = trim(this.elements["input_tab_title"].value);
t = t.replace(/\u00DF/g, "&szlig;").replace(/\u00E4/g, "&auml;").replace(/\u00F6/g, "&ouml;").replace(/\u00FC/g, "&uuml;").replace(/\u00C4/g, "&Auml;").replace(/\u00D6/g, "&Ouml;").replace(/\u00DC/g, "&Uuml;");
this.profile.tabs[this.activeTab].t = t;
this.elements["tab_title_" + this.activeTab].innerHTML = t;
this.save();
}
this.setTabIcon = function(icon) {
this.showElement("tab_icon_" + this.activeTab);
this.elements["tab_icon_" + this.activeTab].src = this.getTabIconSrc(icon);
this.profile.tabs[this.activeTab].i = icon;
this.save();
}
this.deleteTabIcon = function() {
this.hideElement("tab_icon_" + this.activeTab);
this.profile.tabs[this.activeTab].i = "";
this.save();
}
this.closeTab = function() {
if(confirm(loc.text("desktop_close_page_prompt"))) {
this.hideTabOptions();
var widgets = this.columners[this.activeTab].profile["widgets"];
for(var i in widgets) {
var w = kernel.getWidget(widgets[i].id);
if(w) {
w.forceClose();
}
}
this.columners[this.activeTab].close();
deleteEl(this.elements["tab_" + this.activeTab]);
deleteEl(this.elements["tab_container_" + this.activeTab]);
delete this.profile["tabs"][this.activeTab];
for(var o in this.profile["order"]) {
if(this.profile["order"][o] > this.activeTab) {
this.profile["order"][o] --;
}
}
for(var o in this.profile["order"]) {
if(this.profile["order"][o] == this.activeTab) {
this.profile["order"].splice(o, 1);
break;
}
}
this.save();
this.activeTab = null;
for(var i=0; i<this.profile.tabs.length; i++) {
if(this.profile.tabs[i] != undefined) {
this.activeTab = i;
continue;
}
}
if(this.activeTab != null) {
this.showTab(this.activeTab);
}
}
}
//--------------------------------------------
// PANELS
//--------------------------------------------
this.defaultPanelsCount = 3;
this.setPanelsCount = function(n) {
if(n == this.columners[this.activeTab].profile["pcount"]) {
return;
}
for(var p=0; p<this.getPanelsCount(); p++) {
var panel = this.getPanel(p);
for(; panel.childNodes.length>0; ) {
var wid = panel.childNodes[0].wid;
this.elements["tmp"].appendChild(kernel.getWidget(wid).elements.window);
}
}
for(var i=0; i<this.getPanelsCount(); i++) {
deleteEl(this.elements["panel_" + this.activeTab + "_" + i]);
}
deleteEl(this.elements["tab_container_" + this.activeTab]);
this.buildDomModel(this.elements["desktop_columns"], this.getPanelsDom(this.activeTab, n));
this.columners[this.activeTab].profile["pcount"] = n;
this.columners[this.activeTab].save();
for(;this.elements["tmp"].childNodes.length > 0;) {
this.getTinyPanel().appendChild(this.elements["tmp"].childNodes[0]);
}
this.savePanels();
}
this.getPanelsDom = function(tab_idx, count) {
var p = [];
var pwidth = Math.round(100 / count) + "%";
for(var i=0; i<count; i++) {
p.push({ tag: "td", width: pwidth,
style: { paddingBottom: "50px", width: pwidth, verticalAlign: "top"},
id: "panel_" + tab_idx + "_" + i });
}
var m = { tag: "div", id: "tab_container_" + tab_idx,
childs: [
{ tag: "table", className: "panels_table", width: "100%", childs: [ { tag: "tr", childs: p } ]}
]}
return m;
}
// Panels managment
this.getPanel = function(n) {
if(n > this.getPanelsCount()-1) {
n = this.getPanelsCount()-1;
}
return this.elements["panel_" + this.activeTab + "_" + n];
}
this.getPanelsCount = function() {
return this.columners[this.activeTab] ? this.columners[this.activeTab].profile["pcount"] : -1;
}
this.getTinyPanel = function() {
if(this.activeTab == null) {
this.addNewTab();
}
var p = 0;
var minh = 100000;
for(var i = this.getPanelsCount()-1; i>=0; i--) {
var h = 0;
panel = this.getPanel(i);
for(var j=0; j<panel.childNodes.length; j++) {
h += panel.childNodes[j].offsetHeight;
}
if(h <= minh) {
minh = h;
p = i;
}
}
return this.getPanel(p);
}
//--------------------------------------------
// Drag and drop
//--------------------------------------------
this.getBelongPanel = function(pos) {
for(var i=0; i<this.getPanelsCount(); i++) {
if(isPosInObj(pos, this.getPanel(i))) {
return this.getPanel(i);
}
}
return null;
}
this.getWindowAtPos = function(panel, pos) {
for(var i=0; i<panel.childNodes.length; i++) {
if(isPosInObj(pos, panel.childNodes[i])) {
return panel.childNodes[i];
}
}
return null;
}
this.startArea = function(el) {
with(this.elements) {
area.style.position = 'relative';
el.parentNode.insertBefore(area, el);
area.style.height = el.offsetHeight + "px";
area.style.display = 'block';
}
}
this.stopArea = function() {
with(this.elements) {
area.style.height = 0;
area.style.display = 'none';
area.parentNode.removeChild(area);
}
}
this.processArea = function(pos) {
p = this.getBelongPanel(pos);
if(p) {
if(p.hasChildNodes()) {
w = this.getWindowAtPos(p, pos);
if(w) {
if(w.name != 'area') {
w = this.getWindowAtPos(p, pos);
p.insertBefore(this.elements.area, w);
}
}
else {
this.elements.area.parentNode.removeChild(this.elements.area);
p.appendChild(this.elements.area);
}
}
else {
this.elements.area.parentNode.removeChild(this.elements.area);
p.appendChild(this.elements.area);
}
}
}
this.putWindow = function(pos) {
if(this.activeTab == null) {
this.addNewTab();
}
panel = this.getBelongPanel(mpos);
if(panel) {
drag.el.parentNode.removeChild(drag.el);
panel.insertBefore(drag.el, this.elements.area);
}
}
this.hideWebsearch = function() {
for(var p=0; p<this.getPanelsCount(); p++) {
for(var i=0; i<this.getPanel(p).childNodes.length; i++) {
var wid = this.getPanel(p).childNodes[i].wid;
if(wid) {
if (kernel.getWidget(wid).cfg.module == "Websearch")
kernel.getWidget(wid).hide();
}
}
}
}
this.showWebsearch = function() {
for(var p=0; p<this.getPanelsCount(); p++) {
for(var i=0; i<this.getPanel(p).childNodes.length; i++) {
var wid = this.getPanel(p).childNodes[i].wid;
if(wid) {
if (kernel.getWidget(wid).cfg.module == "Websearch")
kernel.getWidget(wid).show();
}
}
}
}
//--------------------------------------------
// SAVE/LOAD DESKTOP
//--------------------------------------------
this.savePanels = function() {
var n = 0;
var panelsCount = this.getPanelsCount();
if(this.columners[this.activeTab]) {
this.columners[this.activeTab].profile["widgets"] = [];
for(var p=0; p<panelsCount; p++) {
for(var i=0; i<this.getPanel(p).childNodes.length; i++) {
var wid = this.getPanel(p).childNodes[i].wid;
if(wid) {
this.columners[this.activeTab].profile["widgets"].push(
{ m: kernel.getWidget(wid).cfg.module, id:wid, p: p});
}
}
}
this.columners[this.activeTab].save();
}
}
this.wakeUp = function() {
hideEl(elById("loading_note"));
for(var o=0; o<this.profile["order"].length; o++) {
var i = this.profile["order"][o];
if(this.profile.tabs[i] == undefined) {
continue;
}
this.renderTab(i, this.profile.tabs[i].t, this.profile.tabs[i].i);
this.columners[i] = kernel.runWidget("Columner", document.body, this.profile.tabs[i].cid);
this.buildDomModel(this.elements["desktop_columns"],
this.getPanelsDom(i, this.columners[i].profile["pcount"]));
this.showTab(i);
var widgets = this.columners[i].profile["widgets"];
for(var j=0; j<widgets.length; j++) {
kernel.runWidget(widgets[j].m, this.getPanel(widgets[j].p), widgets[j].id);
}
}
for(var o in this.profile["order"]) {
var i = this.profile["order"][o];
if(this.profile.tabs[i] != undefined) {
this.showTab(i);
break;
}
}
if(_GET["add_url"]) {
url = _GET["add_url"];
if(url.indexOf("http://") == -1) {
url = "http://"+url;
}
this.newFeedUrl = url;
xmlRequest.send(url, this, "addFeedDispatch");
}
this.showElement("content");
showEl(elById("page_header"));
showEl(elById("page_footer"));
window.scrollTo(0,0);
}
this.addFeedDispatch = function(response) {
if(response.responseXML.documentElement) {
var channel = XMLParser.xml2hash(response.responseXML.documentElement);
if(channel) {
menu.registerFeed(channel.title, this.newFeedUrl);
var w = kernel.runWidget("Rss", this.getTinyPanel(), false, {url: this.newFeedUrl});
w.save();
this.savePanels();
return;
}
}
}
this.addToFavorites = function() {
var url = "http://" + baseUrl;
if(mozilla_nav) {
window.sidebar.addPanel("Elch24", url, "");
} else if(ie_nav) {
window.external.AddFavorite(url, "Elch24");
} else if(opera_nav) {  
alert("Mit der Tastenkombination Strg + D k\u00F6nnen Sie Elch24.de zu Ihren Favoriten hinzuf\u00FCgen."); 
}
}
}
Desktop.prototype = new Widget();
//--------------------------------------------
// Columner
//--------------------------------------------
function Columner() {
this.init();
this.cfg = {
hasSizeBtn: false,
hasCloseBtn: false,
hasRefreshBtn: false,
hasSettingsBtn: false,
hasDrag: false,
hasOnCloseConfirm: false,
isSystem: true,
title: "",
module: "columner"
}
this.defaultProfile["widgets"] = [];
this.defaultProfile["pcount"] = 3;
this.defaultProfile["config"] = "";
this.buildWindow = function(parent) {}
this.buildInterface = function() {}
}
Columner.prototype = new Widget();
//--------------------------------------------
// Recent widgets
//--------------------------------------------
function RecentWidgetsStorage() {
this.init();
this.cfg = {
hasSizeBtn: false,
hasCloseBtn: false,
hasRefreshBtn: false,
hasSettingsBtn: false,
hasDrag: false,
hasOnCloseConfirm: false,
isSystem: true,
title: "",
module: "RecentWidgetsStorage",
uniqueId: SYS_WIDGETS_ID + 10
}
this.defaultProfile["list"] = [];
this.buildWindow = function(parent) {}
this.buildInterface = function() {}
}
RecentWidgetsStorage.prototype = new Widget();
Desktop.prototype.tabIcons = [
"user",
"user_female",
"user_green",
"user_red",
"tux",
"new",
"feed",
"chart_bar",
"music",
"television",
"sport_football",
"sport_raquet",
"sport_soccer",
"flag_blue",
"flag_green",
"flag_red",
"flag_yellow",
"car",
"clock",
"clock_red",
"exclamation",
"information",
"emoticon_grin",
"emoticon_smile",
"money_dollar",
"money_euro"
]
function Auth() {
this.init();
this.cfg = {
hasIcon: true,
hasSizeBtn: false,
hasCloseBtn: true,
hasRefreshBtn: false,
hasSettingsBtn: false,
hasDrag: false,
hasOnCloseConfirm: false,
isOpenHidden: false,
isSystem: true,
title: loc.text("auth_title"),
module: "Auth",
uniqueId: SYS_WIDGETS_ID + 2
}
this.user = { id: null, email: null, password: null}
var leftm = "36px";
if(ie6_nav) 
leftm = "8px";

this.domContent = [
{ tag: "div", className: "float_panel",
id: "login_form",
childs: [
{ tag: "div", className: "float_left",
style: { width: "45%", padding: "8px", marginLeft: leftm},
childs: [
// login exist user
{ tag: "h1", html: loc.text("auth_exist_user") },
{ tag: "div", html: loc.text("inp_email") },
{ tag: "div",
childs: [
{ tag: "input", id: "login_email", size: "30", type: "text", style: { marginBottom: "8px"} }
]},
{ tag: "div", html: loc.text("inp_pwd") },
{ tag: "div",
childs: [
{ tag: "input", id: "login_pwd", size: "30", type: "password" }
]},
{ tag: "div", style: { marginTop: "12px"},
childs: [
{ tag: "input", id: "login_btn", events: { onclick: "tryLogin()"},
type: "button", value: loc.text("auth_load_my_page") }
]},
{ tag: "div", id: "login_msg", style: { marginTop: "12px", textAlign: "justify"}},
// pwd remind
{ tag: "div",
style: { marginTop: "12px"},
childs: [
{ tag: "div",
id: "pwd_remind_link",
childs: [
{ tag: "a", href: "showRemindForm()", html: loc.text("auth_lnk_forget_pwd") }
]},
{ tag: "div",
display: false,
id: "pwd_remind_form",
childs: [
{ tag: "h1", html: loc.text("auth_remind_title")},
{ tag: "div", html: loc.text("inp_email") },
{ tag: "div",
childs: [
{ tag: "input", size: "30", id: "inp_reminder_email", type: "text" },
{ tag: "input", type: "button", value: loc.text("btn_send"), events: { onclick: "remindPwd()"} }
]}
]},
{ tag: "div", id: "pwd_remind_msg", html: loc.text("msg_sending"), display: false }
]}
]},
// new user explanation
{ tag: "div", className: "float_right",
style: { width: "45%", padding: "8px" },
childs: [
{ tag: "h1", html: loc.text("auth_new_user") },
{ tag: "div", style: { textAlign: "left"},
html: loc.text("auth_reg_msg") },
{ tag: "div", style: { marginTop: "12px"},
childs: [
{ tag: "input", id: "goreg_btn", events: { onclick: "showRegform()"}, type: "button", value: loc.text("auth_registration") }
]}
]}
]},
{ tag: "div", id: "reg_form", className: "float_panel",
display: false,
childs: [
{ tag: "div", className: "float_left", style: { width: "45%", padding: "8px" , marginLeft: leftm},
childs: [{ tag: "h1", html: loc.text("auth_new_user") }, 
{ tag: "div", html: loc.text("inp_email") },
                { tag: "div", childs: [
{ tag: "input", id: "reg_email", size: "30", type: "text" , style: { marginBottom: "8px"}}]},
                { tag: "div", html: loc.text("inp_email2") },
                { tag: "div", childs: [
{ tag: "input", id: "reg_email2", size: "30",type: "text", style: { marginBottom: "8px"}}]},
                { tag: "div", html: loc.text("inp_pwd") },
                { tag: "div", childs: [
{ tag: "input", id: "reg_pwd", size: "30", type: "password", style: { marginBottom: "8px"} }]},
                { tag: "div", html: loc.text("inp_pwd2") },
                { tag: "div", childs: [{ tag: "input", id: "reg_pwd2", size: "30", type: "password" }]},
{ tag: "div", style: { marginTop: "12px"},
                  childs: [{ tag: "input", id: "reg_btn", events: { onclick: "tryRegister()"},type: "button", value: loc.text("auth_process_reg_btn") }]},
                { tag: "div", id: "reg_msg",style: { marginTop: "12px", textAlign: "justify"}}
]}
]},
{ tag: "div", id: "reg_ok", className: "float_panel",
display: false,
childs: [
{ tag: "div", className: "float_left",
style: { width: "45%", padding: "8px" , marginLeft: leftm},
childs: [
{ tag: "h1", html: loc.text("auth_new_user") },
{ tag: "div", style: { textAlign: "left"},
html: loc.text("auth_registration_ok") },
{ tag: "div", style: {  marginTop: "12px"},
childs: [
{ tag: "input", type: "button", events: { onclick: "regFinish()"}, value: loc.text("btn_ok")}
]}
]}
]}
]
this.onBuildInterface = function() {
if(ie_nav)
  this.elements["content"].style.height = "250px";
this.buildDomModel(this.elements.content, this.domContent);
this.buildDomModel(desktop.elements.kontoButton, 
[{ tag: "span", id:"kontoBtn",
childs: [createButtonDom(loc.text("settings_konto"), "launchKonto()", "widgets/auth/img/sign_in.gif")]},
{ tag: "span", id:"kontoNbsp", innerHTML: "&nbsp;&nbsp;|&nbsp;&nbsp;"}]);
this.buildDomModel(desktop.elements.authButton,
[{ tag: "span", id:"signinBtn",
childs: [createButtonDom(loc.text("auth_lnk_sign_in"), "signIn()", "widgets/auth/img/sign_in.gif")]  },
{ tag: "span", id:"signoutBtn",
childs: [createButtonDom(loc.text("auth_lnk_sign_out"), "logout()", "widgets/auth/img/sign_out.gif")]  }]);
if(this.isLogged()) {
hideEl(this.elements.signinBtn);
} else {
hideEl(this.elements.kontoBtn);
hideEl(this.elements.kontoNbsp);
hideEl(this.elements.signoutBtn);
}
this.setTitle("<b>"+loc.text("auth_title")+"</b>");
widget = this;
this.elements["login_pwd"]["onkeyup"] = function(event) {if (!event) {event = window.event;} if(event.keyCode == 13) {widget.tryLogin();} };
this.elements["inp_reminder_email"]["onkeyup"] = function(event) {if (!event) {event = window.event;} if(event.keyCode == 13) {widget.remindPwd();} };
this.elements["reg_pwd2"]["onkeyup"] = function(event) {if (!event) {event = window.event;} if(event.keyCode == 13) {widget.tryRegister();} };
}
this.showRemindForm = function() {
this.showElement("pwd_remind_form");
this.hideElement("pwd_remind_link");
this.hideElement("pwd_remind_msg");
this.elements["inp_reminder_email"].value = "";
this.elements["inp_reminder_email"].focus();
}
this.regFinish = function() {
this.close();
}
this.launchKonto = function() {
desktop.showPopup('konto');
}
this.remindPwd = function() {
var email = trim(this.elements["inp_reminder_email"].value);
if(this.checkEmail(email)) {
request.send( { act: "remind_pwd", email: email }, this);
this.hideElement("pwd_remind_form");
this.showElement("pwd_remind_msg");
}
}
this.showRegform = function() {
this.showElement("reg_form");
this.hideElement("login_form");
}
this.hideRegform = function() {
this.hideElement("reg_form");
this.showElement("login_form");
}
this.tryLogin = function() {
var e = trim(this.elements["login_email"].value);
var pwd = trim(this.elements["login_pwd"].value);
if(e != "" && pwd != "") {
request.send({ act: "login_user", email: e, password: pwd }, this);
this.hideElement("login_btn");
this.hideElement("goreg_btn");
this.elements["login_msg"].innerHTML = loc.text("msg_processing");
}
}
this.tryRegister = function() {
var e = trim(this.elements["reg_email"].value);
var e2 = trim(this.elements["reg_email2"].value);
var pwd = trim(this.elements["reg_pwd"].value);
var pwd2 = trim(this.elements["reg_pwd2"].value);
if(e != e2 || !this.checkEmail(e)) {
this.elements["reg_msg"].innerHTML = loc.text("auth_email_error");
} else if(pwd != pwd2 || !this.checkPassword(pwd)) {
this.elements["reg_msg"].innerHTML = loc.text("auth_pwd_error");
} else if(e != "" && pwd !="") {
request.send({ act: "register_user", email: e, password: pwd }, this);
this.hideElement("reg_btn");
this.elements["reg_msg"].innerHTML = loc.text("msg_processing");
}
}
this.close = function() {
this.hideRegform();
desktop.hideActivePopup();
}
this.signIn = function() {
desktop.showPopup('auth');
}
this.isLogged = function() {
return this.user.email != '';
}
this.logout = function() {
request.send({act: "logout"}, this);
}
this.loadUser = function() {
this.anonymusId = getCookie("anonymusid");
this.user.id = getCookie("userid");
this.user.email = getCookie("useremail");
this.user.password = getCookie("userpassword");
}
this.saveUser = function() {
setCookie("userid", this.user.id);
setCookie("useremail", this.user.email);
setCookie("userpassword", this.user.password);
}
this.start = function() {
if(session_user) {
this.user = session_user;
this.onLoad();
} else {
this.loadUser();
if(this.user.email && this.user.password) {
request.send({act: "start_user", user_id: this.user.id, email: this.user.email, password: this.user.password}, this);
} else {
request.send({act: "start_anonymus", user_id: this.user.id}, this);
}
}
}
this.dispatchMsg = function(msg) {
switch(msg.status) {
case "":
break;
case "start_result":
this.user = msg.user;
this.saveUser();
this.onLoad();
break;
case "register_ok":
this.showElement("reg_ok");
this.hideElement("reg_form");
this.elements["signinBtn"].style.display = "none";
this.elements["signoutBtn"].style.display = "inline";
this.user = msg.user;
this.saveUser();
break;
case "register_error":
this.elements["reg_msg"].innerHTML = loc.text("auth_msg_reg_error");
this.elements["reg_email"].value = "";
this.elements["reg_email2"].value = "";
this.showElement("reg_btn");
break;
case "login_ok":
setCookie("anonymusid", this.user.id);
this.user = msg.user;
this.saveUser();
location.reload();
break;
case "login_error":
this.elements["login_msg"].innerHTML = loc.text("auth_login_error");
this.showElement("login_btn");
this.showElement("goreg_btn");
break;
case "logout_ok":
var anonymusId = getCookie("anonymusid");
if(anonymusId) {
this.user = {id: anonymusId, email: "", password: ""};
this.saveUser();
delCookie("anonymusid");
} else {
delCookie("userid");
delCookie("useremail");
delCookie("userpassword");
}
location.reload();
break;
case 'user_ok':
if(!this.user.email) {
setCookie("anonymusid", this.user.id);
}
this.user = msg.user;
this.saveUser();
location.reload();
break;
case "pwd_sent":
this.elements["inp_reminder_email"].value = "";
this.hideElement("pwd_remind_form");
this.showElement("pwd_remind_link");
this.hideElement("pwd_remind_msg");
break;
}
}
this.onLoad = function() {}
this.registerUser = function() {
var errors = [];
email = trim(this.elements.selectEmail.value);
password = trim(this.elements.selectPassword.value);
if(!this.checkEmail(email)) {
errors[errors.length] = "<b>" + loc.text("auth_msg_email_invalid") + "</b>";
}
if(!this.checkPassword(password)) {
errors[errors.length]= "<b>" + loc.text("auth_msg_pwd_invalid") + "</b>";
}
if(errors.length > 0) {
this.elements.messages.innerHTML = errors.join("<BR>");
} else {
hideEl(this.elements.submitButton);
this.elements.messages.innerHTML = loc.text("msg_processing");
request.send({act: "register_user", email: email, password: password}, this);
}
}
this.checkEmail = function(str) {
return /^[a-zA-Z][a-z0-9\-\_\.]{1,20}@[a-z0-9\-\_\.]{5,30}$/.test(str);
}
this.checkPassword = function(str) {
return (str.length > 5);
}
}
Auth.prototype = new Widget();
function Konto() {

    this.init();

    this.cfg = {
        hasIcon: true,
        hasSizeBtn: false,
        hasCloseBtn: true,
        hasRefreshBtn: false,
        hasSettingsBtn: false,
        hasDrag: false,
        title: loc.text("settings_konto"),
        module: "Konto",
        uniqueId: SYS_WIDGETS_ID + 4
    }     

    this.domContent = [
        {tag: "table", width: "100%",  className: "float_panel", id: "login_form",
          childs: [ {tag: "tr",  childs: [
            {tag: "td", style: { width: "320px", padding: "8px", paddingLeft: "50px"},
              childs: [
                // Passwort change
                { tag: "h1", html: loc.text("settings_change_pwd") },
                { tag: "div", html: loc.text("settings_inp_old_pwd")},
                { tag: "div", childs: [{ tag: "input", id: "inp_old_pwd", size: "30", type: "password" , style: { marginBottom: "8px"}}]},
                { tag: "div", html: loc.text("settings_inp_new_pwd")},
                { tag: "div", childs: [{ tag: "input", id: "inp_new_pwd", size: "30",type: "password"  , style: { marginBottom: "8px"}}]},
                { tag: "div", html: loc.text("settings_inp_new_pwd2")},
                { tag: "div", childs: [{ tag: "input", id: "inp_new_pwd2", size: "30",type: "password"  , style: { marginBottom: "4px"}}]},
                { tag: "div", style: { marginTop: "6px", height: "25px"},
                  childs: [{ tag: "input", id: "btn_change_pwd",
                  events: { onclick: "changePwd()"}, type: "button", value: loc.text("settings_btn_change_pwd") }]},
                { tag: "div", id: "change_pwd_msg", style: { marginTop: "12px"}}
              ]},
            {tag: "td", style: { width: "320px", padding: "8px", paddingLeft: "50px" },
              childs: [
                // username change
                { tag: "h1", html: loc.text("settings_inp_uid") },
                { tag: "div", html: loc.text("settings_inp_old_pwd")},
                { tag: "div", childs: [{ tag: "input", id: "inp_old_pwd2", size: "30", type: "password"  , style: { marginBottom: "8px"}}]},
                { tag: "div", html: loc.text("settings_inp_new_uid") },
                { tag: "div", childs: [{ tag: "input", id: "inp_new_uid", size: "30",type: "text"  , style: { marginBottom: "8px"}}]},
                { tag: "div", html: loc.text("settings_inp_new_uid2") },
                { tag: "div", childs: [{ tag: "input", id: "inp_new_uid2", size: "30",type: "text"  , style: { marginBottom: "4px"}}]},
                { tag: "div", style: { marginTop: "6px", height: "25px"},
                  childs: [{ tag: "input", id: "btn_change_uid",
                    events: { onclick: "changeUid()"}, type: "button", value: loc.text("settings_btn_change_pwd") }]},
                { tag: "div", id: "change_uid_msg", style: { marginTop: "12px"}}
              ]}
          ]}
       ]}
    ]


    this.onBuildInterface = function() {
        this.setTitle("<b>"+this.cfg.title+"</b>");
        this.buildDomModel(this.elements.content, this.domContent);
        var widget = this;
        this.elements["inp_new_pwd2"]["onkeyup"] = function(event) {if (!event) {event = window.event;} if(event.keyCode == 13) {widget.changePwd();} };
        this.elements["inp_new_uid2"]["onkeyup"] = function(event) {if (!event) {event = window.event;} if(event.keyCode == 13) {widget.changeUid();} };
    }

    this.changePwd = function() {
      var p1 = trim(this.elements["inp_new_pwd"].value);
      var p2 = trim(this.elements["inp_new_pwd2"].value);
      var opwd = trim(this.elements["inp_old_pwd"].value);
      if(opwd == auth.user.password) {
        if((p1 == p2) && (p1 != "")) {
          var opwd = trim(this.elements["inp_old_pwd"].value);
          request.send({ act: "change_pwd", npwd: p1}, this);
          this.elements["change_pwd_msg"].innerHTML = loc.text("msg_processing");
          this.elements["btn_change_pwd"].disabled = true;
        } 
        else {
          this.elements["change_pwd_msg"].innerHTML = loc.text("settings_new_pwd_wrong");
        }
      } 
      else {
        this.elements["change_pwd_msg"].innerHTML = loc.text("settings_old_pwd_wrong");
      }
    }

    this.changeUid = function() {
      var u1 = trim(this.elements["inp_new_uid"].value);
      var u2 = trim(this.elements["inp_new_uid2"].value);
      var opwd = trim(this.elements["inp_old_pwd2"].value);
      if(opwd == auth.user.password) {
        if((u1 == u2) && (u1 != "") && (this.checkEmail(u1))) {
          var opwd = trim(this.elements["inp_old_pwd"].value);
          request.send({ act: "change_uid", nuid: u1}, this);
          this.elements["change_uid_msg"].innerHTML = loc.text("msg_processing");
          this.elements["btn_change_uid"].disabled = true;
        } 
        else {
          this.elements["change_uid_msg"].innerHTML = loc.text("settings_uid_wrong") ;
        }
      } 
      else {
        this.elements["change_uid_msg"].innerHTML = loc.text("settings_old_pwd_wrong");
      }
    }

    this.onOpen = function() {
        this.setTitle(this.cfg.title);
    }

    this.close = function() {
        desktop.hideActivePopup();
    }

    this.dispatchMsg = function(msg) {
        switch(msg.status) {
            case "":
                break;
            case "pwd_changed":
                this.elements["change_pwd_msg"].innerHTML = loc.text("settings_pwd_changed");
                this.elements["btn_change_pwd"].disabled = false;
                this.elements["inp_old_pwd"].value = "";
                this.elements["inp_new_pwd"].value = "";
                this.elements["inp_new_pwd2"].value = "";
                auth.user.password = msg.npwd;
                auth.saveUser();
                break;
            case "uid_changed":
                this.elements["change_uid_msg"].innerHTML = loc.text("settings_uid_changed");
                this.elements["btn_change_uid"].disabled = false;
                this.elements["inp_old_pwd2"].value = "";
                this.elements["inp_new_uid"].value = "";
                this.elements["inp_new_uid2"].value = "";
                auth.user.email = msg.nuid;
                auth.saveUser();
                break;
            case "register_error":
                this.elements["change_uid_msg"].innerHTML = loc.text("settings_uid_occupied") ;
                this.elements["btn_change_uid"].disabled = false;
                break;
        }
    }

    this.checkEmail = function(str) {
        return /^[a-zA-Z][a-z0-9\-\_\.]{1,20}@[a-z0-9\-\_\.]{5,30}$/.test(str);
    }

    this.checkPassword = function(str) {
        return (str.length > 5);
    }

}
Konto.prototype = new Widget();
function Profiler() {
this.data = {};
this.cfg = {
module: "Profiler",
hasProfile: false
}
this.registerWidget = function(widget) {
var profile = clone(widget.defaultProfile);
if(this.data[widget.id]) {
for(var i in this.data[widget.id]) {
if(profile[i] != undefined) {
profile[i] = this.data[widget.id][i];
}
}
}
widget.profile = profile;
}
this.saveProfile = function(widget) {
var wkey = widget.id;//getSignature();
if(widget.profile) {
act = this.data[wkey] ? "update" : "create";
request.send({w: widget.cfg.module, act: act, wkey: wkey, data: escape(toCode(widget.profile))}, this, widget.cfg.saveMethod);
} else {
request.send({act: "delete", wkey: wkey}, this);
}
this.data[wkey] = widget.profile;
}
this.loadProfile = function() {
request.send({act: "load_data"}, this);
}
this.onLoad = function() {}
this.dispatchMsg = function(msg) {
if(msg.status == "loaded") {
profiler.data = {};
for(var i in msg.data) {
try {
profiler.data[i] = toValue(unescape(msg.data[i]));
} catch(e) {
profiler.data[i] = {}
}
}
profiler.onLoad(msg.bubbles);
}
}
}
CCIDS = 10000;
function Menu() {
this.init();
this.cfg = {
hasSizeBtn: false,
hasRefreshBtn: false,
hasSettingsBtn: false,
hasDrag: false,
isOpenHidden: true,
isSystem: true,
title: loc.text("menu_title"),
module: "Menu",
uniqueId: SYS_WIDGETS_ID + 3
}
this.defaultProfile["catalog"] = [];
this.defaultProfile["recentw"] = [];
this.widget = null;
this.catalog = [];
this.catalog[CCIDS] = {categories: [{id: CCIDS+1, name: loc.text("menu_cutom_channels")}], items: []};
this.catalog[CCIDS+1] = {categories: [], items: []};
this.folder_o = new Image();
this.folder_o.src = "static/client/folder-o.gif";
this.folder_oa = new Image();
this.folder_oa.src = "static/client/folder-oa.gif";
this.folder_ol = new Image();
this.folder_ol.src = "static/client/folder-ol.gif";
this.folder_ob = new Image();
this.folder_ob.src = "static/client/folder-ob.gif";
this.folder_os = new Image();
this.folder_os.src = "static/client/folder-os.gif";
this.folder_s = new Image();
this.folder_s.src = "static/client/folder-s.gif";
this.domModelContent = [
{ tag: "div", className: "menu_panel", id: "cat_content0", display: false }
]
this.domModelContent2 = [
{ tag: "div", className: "menu_hr"},
{ tag: "div", className: "menu_panel", id: "addFeedMenuItem",
childs: [createButtonMenu("&nbsp;&nbsp;&nbsp;"+loc.text("menu_add_feed"), "showAddFeedPanel()", "widgets/menu/img/add.gif")] },
{ tag: "div", className: "menu_panel", id: "cat_content"+CCIDS, display: false }, { tag: "div", className: "menu_hr"}
]
this.domModelAdditional = [
{ tag: "div", className: "panel", id: "preview", display: false, style: {position: "absolute", left: "0px", top: "0px", width: "325px"},
childs: [ { tag: "div", className: "panel_section",
childs: [ createTableDom([
/*
{content: createButtonDom("<b>" + loc.text("menu_add2desktop") + "</b>", "addToDesktop()", "widgets/menu/img/plus.gif"), width: "99%"},
*/
{content: {tag: "a", href: "void", events: {onclick: "addToDesktop()"}, innerHTML: "<img src='widgets/menu/img/plus.gif' style='margin: 0px 4px 0px 0px; vertical-align: middle;'><b>" + loc.text("menu_add2desktop") + "</b>"}, width: "99%"},
{content: {tag: "a", href: "void", events: {onclick: "closePreview()"}, innerHTML: "<img src='static/client/close.gif'>"}, width: "1%"}
]),
{ tag: "div", id: "preview_panel", style: {width: "100%", height: "auto", padding: "0", margin: "0"} }
]
}]
},
{ tag: "div", className: "panel", id: "addFeedPanel", display: false, style: {position: "absolute", left: "0px", top: "0px", width: "360px"},
childs: [ { tag: "div", className: "caption",
childs: [ createTableDom([
{content: "<img src='widgets/menu/img/item.gif' style='vertical-align: middle'> &nbsp;<b>" + loc.text("menu_add_feed") + "</b>", width: "99%"},
{content: createButtonDom(false, "closeAddFeedPanel()", "static/client/close.gif"), width: "1%"}
]),
createTableDom([
{content: { tag: "div", innerHTML: loc.text("menu_inp_url"), style: {paddingTop: "15px", paddingBottom: "15px"}}, width: "1%"},
{content: { tag: "input", type: "text", size: "40", id: "selectFeedUrl"}, width: "100%"},
{content: { tag: "input", type: "button", id: "addFeedButton", events: {onclick: "addFeed()"}, value: loc.text("btn_add")}, width: "1%"}
]),
{ tag: "div", display: false, id: "addFeedStatus", className: "menu_panel", style: {paddingBottom: "15px"}, align: "center"}
]
}]
},
{ tag: "div", className: "panel", id: "item_menu", display: false, style: {padding: "6px", position: "absolute", left: "0px", top: "0px", verticalAlign: "middle"},
childs: [ { tag: "span", id: "item_menu_actions",
childs: [
createButtonDom("<b>"+loc.text("menu_rename")+"</b>", "showRenameItemSection()", "static/client/edit.gif"), { tag: "br"},
createButtonDom("<b>"+loc.text("menu_delete")+"</b>", "showDeleteItemSection()", "static/client/delete_link.gif")
]
},
{ tag: "span", id: "item_menu_rename", display: false,
innerHTML: "<b>" +loc.text("menu_rename_to")+"</b> &nbsp;",
childs: [
{ tag: "input", type: "text", id: "new_item_title", style: {width: "190px"}},
{ tag: "input", type: "button", value: loc.text("btn_ok"), events: {onclick: "renameItem()"}},
{ tag: "input", type: "button", value: loc.text("btn_cancel"), events: {onclick: "hideItemMenu()"} }
]
},
{ tag: "span", id: "item_menu_delete", display: false,
innerHTML: "<b>"+loc.text("menu_delete_prompt")+"</b> &nbsp;",
childs: [
{ tag: "input", type: "button", value: loc.text("btn_yes"), events: {onclick: "deleteItem()"} },
{ tag: "input", type: "button", value: loc.text("btn_no"), events: {onclick: "hideItemMenu()"} }
]
}
]
}
]
this.menuItemId = 0;
this.getMenuItemId = function(id) {
var res = "menu_item_";
if(id) {
res = res + id;
}
else {
this.menuItemId ++;
res = res + this.menuItemId;
}
return res;
}
this.onBuildInterface = function() {
this.elements.window.style.position = "absolute";
this.elements.window.style.margin = "2px";
this.elements.window.style.top = "128px";
this.elements.window.style.left = "13px";
this.elements.window.style.width = "500px";
this.elements.window.style.border = "solid 3px #000000";
this.elements.window.style.background = "#F0F0F0";
this.buildDomModel(this.elements.content, this.domModelContent);
for(var w=0; w<2; w++) {
var mid = this.getMenuItemId();
var wname = menuWidgets[w].className.toLowerCase();
this.buildDomModel(document.body,
{ tag: "div", className: "hint", id: "hint_"+wname, display: false, style: {position: "absolute", left: "0px", top: "0px", width: "260px", padding: "8px"},
innerHTML: loc.text(wname + "_hint").replace(/\n/g, "<br>") } );
var m = { tag: "div", className: "menu_panel", style: { paddingLeft: "8px"}, events: { onmouseover: "showHint('" + wname + "', '"+mid+"')", onmouseout: "hideHint('" + wname + "')"},
childs: [ createButtonMenu("&nbsp;&nbsp;&nbsp;"+loc.text(wname + "_title"), "openWidget('" + menuWidgets[w].className + "', '"+mid+"')", "widgets/" + wname + "/ico2.gif", mid) ]
}
this.buildDomModel(this.elements["content"], m);
}
this.buildDomModel(this.elements.content, this.domModelContent2);
this.buildDomModel(document.body, this.domModelAdditional);
this.setTitle("<b>"+this.cfg.title + "</b><br>&nbsp;");
for(var w=2; w<menuWidgets.length; w++) {
var mid = this.getMenuItemId();
var wname = menuWidgets[w].className.toLowerCase();
this.buildDomModel(document.body,
{ tag: "div", className: "hint", id: "hint_"+wname, display: false, style: {position: "absolute", left: "0px", top: "0px", width: "260px", padding: "8px"},
innerHTML: loc.text(wname + "_hint").replace(/\n/g, "<br>") } );
var m = { tag: "div", className: "menu_panel", style: { paddingLeft: "8px"}, events: { onmouseover: "showHint('" + wname + "', '"+mid+"')", onmouseout: "hideHint('" + wname + "')"},
childs: [ createButtonMenu("&nbsp;&nbsp;&nbsp;"+loc.text(wname + "_title"), "openWidget('" + menuWidgets[w].className + "', '"+mid+"')", "widgets/" + wname + "/ico2.gif", mid) ]
}
this.buildDomModel(this.elements["content"], m);
}
// Load feeds catalog
this.switchCategory(0);
// Custom feeds
var tmp = [];
for(var i=0; i<this.profile.catalog.length; i++) {
if(this.profile.catalog[i]["title"]) {
tmp.push(this.profile.catalog[i]);
}
}
this.profile.catalog = null;
this.profile.catalog = tmp;
for(var i=0; i<this.profile.catalog.length; i++) {
this.catalog[CCIDS+1].items[i] = clone(this.profile.catalog[i]);
this.catalog[CCIDS+1].items[i].id = CCIDS + 2 + parseInt(i);
}
this.renderCategory(CCIDS);
}
// open/close sub menus
this.switchPanel = function(name) {
with (this.elements[name].style) {
display = (display == 'none' ? 'block' : 'none');
}
}
this.show = function() {
if(!desktop.isMenuShow) {
showEl(this.elements.window);
desktop.isMenuShow = true;
}
}
this.hide = function() {
if(desktop.isMenuShow) {
hideEl(this.elements.window);
desktop.isMenuShow = false;
}
}
this.close = function() {
this.hideItemMenu();
this.closePreview();
this.closeAddFeedPanel();
this.hide();
var elOld = "";
for (var i=5; i< 10002; i++) {
elOld = this.elements["cat_content"+i];
if(this.catalog[i]) {
if(this.catalog[i].rendered) {
hideEl(elOld);
this.elements["fico_" + i].setAttribute("src",this.folder_s.src);
}
}
/*                if(i==25 || i==42 || i==158) i++; */
if (i==175) i = 10000;
}
desktop.showWebsearch();
}
//---------------------------------------------
// PREVIEW
//---------------------------------------------
this.openWidget = function(widgetClass, mid, params) {
this.hideItemMenu();
this.hideHint();
this.closePreview();
this.closeAddFeedPanel();
showEl(this.elements.preview);
var pos = {left: getLeft(this.elements.window) + this.elements.window.offsetWidth + 12, top:  getTop(this.elements[mid])};
setElPos(this.elements.preview, pos);
this.widget = kernel.runWidget(widgetClass, this.elements["preview_panel"], false, params, { isPreview: true});
this.oldDisableOnClosePrompt = this.widget.disableOnClosePrompt;
this.widget.disableOnClosePrompt = true;
pos.top = pos.top - Math.round(this.elements.preview.offsetHeight / 2);
setElPos(this.elements.preview, pos);
}
this.closePreview = function() {
if(this.widget) {
this.widget.close();
}
this.widget = null;
hideEl(this.elements.preview);
this.elements.preview_panel.innerHTML = '';
}
this.addToDesktop = function() {
var w = this.widget;
if(w) {
w.setParent(desktop.getTinyPanel());
w.isPreview = false;
w.initDtagAndDrop();
w.disableOnClosePrompt = this.oldDisableOnClosePrompt;
w.save();
this.widget = null;
this.closePreview();
desktop.savePanels();
/*
menu.hide();
desktop.showWebsearch();
*/
}
}
//---------------------------------------------
// HINTS
//---------------------------------------------
this.currentHint = null;
this.showHint = function(wname, mid) {
if(!this.widget) {
var pos = {left: getLeft(this.elements.window) + this.elements.window.offsetWidth - 286,
top:  getTop(this.elements[mid])};
setElPos(this.elements["hint_"+wname], pos);
showEl(this.elements["hint_"+wname]);
this.currentHint = wname;
this.hideItemMenu();
}
}
this.hideHint = function(wname) {
if(wname) {
hideEl(this.elements["hint_"+wname]);
} else if (this.currentHint) {
hideEl(this.elements["hint_"+this.currentHint]);
}
}
//---------------------------------------------
// ADD CHANNELS
//---------------------------------------------
this.setAddFeedStatus = function(html) {
if(html) {
showEl(this.elements.addFeedStatus);
this.elements.addFeedStatus.innerHTML = html;
} else {
clearEl(this.elements.addFeedStatus);
hideEl(this.elements.addFeedStatus);
}
}
this.addFeedPanelVisible = false;
this.showAddFeedPanel = function() {
this.hideItemMenu();
this.closePreview();
if(!this.addFeedPanelVisible) {
this.setAddFeedStatus(null);
showEl(this.elements.addFeedPanel);
showEl(this.elements.addFeedButton);
var pos = {left: getLeft(this.elements.window) + this.elements.window.offsetWidth + 12,
top:  getTop(this.elements.addFeedMenuItem)};
setElPos(this.elements.addFeedPanel, pos);
this.elements.selectFeedUrl.focus();
this.addFeedPanelVisible = true;
}
}
this.closeAddFeedPanel = function() {
if(this.addFeedPanelVisible) {
hideEl(this.elements.addFeedPanel);
this.addFeedPanelVisible = false;
}
}
this.addFeed = function() {
var url = trim(this.elements.selectFeedUrl.value);
if(url!="") {
hideEl(this.elements.addFeedButton);
this.setAddFeedStatus("<b>"+loc.text("menu_msg_cc")+"</b>");
if(url.indexOf("http://") == -1) {
url = "http://"+url;
}
this.newFeedUrl = url;
xmlRequest.send(url, this, "addFeedDispatch");
}
}
this.registerFeed = function(title, url) {
  var bb = '';
  for(i=0; i<title.length; i++)
  {
    if(title.charCodeAt(i)>0)
    {
      bb += '&#' + title.charCodeAt(i) + ';';
    }
    else
    {
      bb += title.charAt(i);
    }
  }
 title = bb;
var cn = this.catalog[CCIDS+1].items.length;
this.profile.catalog[cn] = {title: title, url: url};
var newItem = {id: CCIDS+cn+2, title: title.substr(0,34), url: url, icon: ''};
this.catalog[CCIDS+1].items[cn] = newItem;
this.renderCategory(CCIDS+1, true);
this.save();
}
this.addFeedDispatch = function(response) {
if(response.responseXML.documentElement) {
var channel = XMLParser.xml2hash(response.responseXML.documentElement);
if(channel) {
this.setAddFeedStatus("<b>"+loc.text("menu_msg_added", channel.title)+"</b>");
this.elements.selectFeedUrl.value = '';
this.registerFeed(channel.title, this.newFeedUrl);
showEl(this.elements.addFeedButton);
var w = kernel.runWidget("Rss", desktop.getTinyPanel(), false, {url: this.newFeedUrl});
w.save();
desktop.savePanels();
this.closeAddFeedPanel();
/*
menu.hide();
desktop.showWebsearch();
*/
return;
}
}
this.setAddFeedStatus("<b>"+loc.text("menu_msg_no_responce")+ "</b>");
showEl(this.elements.addFeedButton);
}
//---------------------------------------------
// ITEM MENU
//---------------------------------------------
this.activeItemId = null;
this.showItemControl = function(id) {
this.hideItemControl();
showEl(this.elements["item_control"+id]);
this.activeItemId = id;
}
this.hideItemControl = function() {
if(this.activeItemId != null) {
hideEl(this.elements["item_control"+this.activeItemId]);
}
}
this.showItemMenu = function(mid) {
if(!this.widget && !this.addFeedPanelVisible) {
hideEl(this.elements.item_menu_rename);
hideEl(this.elements.item_menu_delete);
showEl(this.elements.item_menu_actions);
showEl(this.elements.item_menu);
var pos = {left: getLeft(this.elements.window) + this.elements.window.offsetWidth + 2,
top:  getTop(this.elements[mid]) - 10};
setElPos(this.elements.item_menu, pos);
}
}
this.hideItemMenu = function() {
hideEl(this.elements.item_menu);
}
this.showRenameItemSection = function() {
var n = this.getItemNum(this.activeItemId);
this.elements.new_item_title.value = this.profile.catalog[n].title;
hideEl(this.elements.item_menu_actions);
showEl(this.elements.item_menu_rename);
}
this.showDeleteItemSection = function() {
hideEl(this.elements.item_menu_actions);
showEl(this.elements.item_menu_delete);
}
this.getItemNum = function(itemId) {
for(var i=0; i<this.catalog[CCIDS+1].items.length; i++) {
if(this.catalog[CCIDS+1].items[i] != -1 && this.catalog[CCIDS+1].items[i].id == itemId) {
return i;
}
}
}
this.renameItem = function() {
var title = trim(this.elements.new_item_title.value);
if(title != "") {
var n = this.getItemNum(this.activeItemId);
this.profile.catalog[n].title = title;
this.catalog[CCIDS+1].items[n].title = title;
this.elements["cat_item_title"+this.activeItemId].innerHTML = title;
this.save();
this.hideItemMenu();
}
}
this.deleteItem = function() {
var n = this.getItemNum(this.activeItemId);
this.profile.catalog[n] = -1;
this.catalog[CCIDS+1].items[n] = -1;
this.elements["cat_item"+this.activeItemId].parentNode.removeChild(this.elements["cat_item"+this.activeItemId]);
this.elements["cat_item"+this.activeItemId] = null;
this.save();
this.hideItemMenu();
}
//---------------------------------------------
// CATALOGS
//---------------------------------------------
this.getParentFolder = function(catId) {
if(catId > 42 && catId < 63) return 36;
if(catId > 62 && catId < 76) return 28;
if(catId > 75 && catId < 89) return 33;
if(catId > 88 && catId < 93) return 42;
if(catId > 92 && catId < 110) return 35;
if(catId > 109 && catId < 123) return 27;
if(catId > 122 && catId < 126) return 30;
if(catId > 125 && catId < 142) return 41;
if(catId == 142 || catId == 145 || catId == 149 || catId == 159) return 148;
if(catId == 164 || catId == 175) return 163;
if(catId == 174) return 165;
return 1;
}
this.switchCategory = function(catId) {
this.closePreview();
window.scrollTo(0,125);
this.closeAddFeedPanel();
this.hideItemMenu();
var el = this.elements["cat_content"+catId];
if(el.style.display == 'none') {
var elOld = "";
if (catId > 0 && catId < 9) {
for (var i=5; i< 9; i++) {
if (i != catId){
elOld = this.elements["cat_content"+i];
if(this.catalog[i]) {
if(this.catalog[i].rendered) {
hideEl(elOld);
this.elements["fico_" + i].setAttribute("src",this.folder_s.src);
}
}
}
}
}
if (catId == 10001) {
for (var i=5; i< 9; i++) {
elOld = this.elements["cat_content"+i];
if(this.catalog[i]) {
if(this.catalog[i].rendered) {
hideEl(elOld);
this.elements["fico_" + i].setAttribute("src",this.folder_s.src);
}
}
}
}
if(catId != "0") {
for (var i=9; i< 176; i++) {
if (i != catId && i != this.getParentFolder(catId)){
elOld = this.elements["cat_content"+i];
if(this.catalog[i]) {
if(this.catalog[i].rendered) {
hideEl(elOld);
this.elements["fico_" + i].setAttribute("src",this.folder_s.src);
}
}
}
/*                    if(i==25 || i==42 || i==158) i++;*/
}
if(catId != 10001) {
elOld = this.elements["cat_content10001"];
if(this.catalog[10001]) {
if(this.catalog[10001].rendered) {
hideEl(elOld);
this.elements["fico_10001"].setAttribute("src",this.folder_s.src);
}
}
}
}
if(this.catalog[catId]) {
if(this.catalog[catId].rendered) {
showEl(el);
}
else {
this.renderCategory(catId);
}
}
else {
if(catId < CCIDS) {
el.innerHTML = loc.text("msg_loading");
showEl(el);
request.send({act: "get_category", cat_id: catId}, this);
}
}
if(catId != "0") {
var bildo ="";
switch (catId) {
case 5: bildo = this.folder_oa.src; break;
case 6: bildo = this.folder_ol.src; break;
case 7: bildo = this.folder_ob.src; break;
case 8: bildo = this.folder_os.src; break;
default: bildo = this.folder_o.src; break;
}
this.elements["fico_" + catId].setAttribute("src", bildo);
}
}
else {
if(catId != "0") {
this.elements["fico_" + catId].setAttribute("src",this.folder_s.src);
}
hideEl(el);
}
}
this.tmpIcons = {};
this.renderCategory = function(catId, silent) {
el = this.elements["cat_content"+catId];
el.innerHTML = '';
with(this.catalog[catId]) {
if(categories) {
for(var i=0; i<categories.length; i++) {
this.buildDomModel(el,
{ tag: "div", className: "menu_panel", id: "cat"+categories[i].id,
childs: [
createButtonMenu("&nbsp;&nbsp;&nbsp;"+categories[i].name, "switchCategory("+categories[i].id+")", this.folder_s.src, false, "fico_" + categories[i].id ),
{ tag: "div", id: "cat_content"+categories[i].id, className: "menu_sub_panel", display: false }
]
});
}
}
if(items) {
var m = null;
for(var i=0; i<items.length; i++) {
if(items[i] == -1) {
continue;
}
var ico_id = "item_icon_"+items[i].id;
m = { tag: "div", id: "cat_item"+items[i].id, style: {width: "100%", padding: "0px"}, childs: []}
var cells = [
{content: createButtonMenu("&nbsp;&nbsp;"+items[i].title,
"openWidget('Rss', 'cat_item"+items[i].id+"', {title: '"+items[i].title+"', url: '"+items[i].url+"'"+(items[i].icon ? ", icon: '"+items[i].icon+"'" : "") + "})",
"widgets/menu/img/item.gif", "cat_item_title"+items[i].id, ico_id), width: "99%"}];
if(items[i].id > CCIDS) {
m.events = {onmouseover: "showItemControl('"+items[i].id+"')", onmouseout: "hideItemControl()"};
cells.push({content:
{ tag: "img", src: "static/client/right_arrow.gif", id: "item_control"+items[i].id, style: {verticalAlign: "middle", cursor: "pointer"}, display: false,
events: {onmouseover: "showItemMenu('cat_item"+items[i].id+"')"} }, width: "99%"});
}
m.childs.push(createTableDom(cells));
this.buildDomModel(el, m);
var icons = [items[i].icon, getDomain(items[i].url) + "/favicon.ico", getDir(items[i].url) + "/favicon.ico"];
with(this.elements[ico_id].style) {
width = "16px";
heigth = "16px";
}
loadIcon(this.elements[ico_id], icons);
}
}
if(!items  &&  !categories) {
el.innerHTML = loc.text("msg_empty");
}
rendered = true;
}
if(!silent) {
el.style.display = 'block';
}
this.catalog[catId].rendered = true;
}
//---------------------------------------------
// DISPATCHER
//---------------------------------------------
this.dispatchMsg = function(msg) {
switch (msg.status) {
case "category_data":
this.catalog[msg.cat_id] = { categories: msg.categories, items: msg.items};
this.renderCategory(msg.cat_id);
break;
case "html_widgets":
this.renderHTMLWidgetsList(msg.data);
break;
}
}
}
Menu.prototype = new Widget();
function Feedback() {
this.init();
this.cfg = {
hasSizeBtn: false,
hasRefreshBtn: false,
hasSettingsBtn: false,
hasDrag: false,
hasProfile: false,
title: loc.text('feedback_user_feedback'),
module: "Feedback",
uniqueId: SYS_WIDGETS_ID + 7
}
this.onBuildInterface = function() {
this.setTitle("<b>"+this.cfg.title+"</b>");
this.buildDomModel(this.elements.content, [
{ tag: "div", align: "center", id: "feedback_status",
html: "<B>" + loc.text("feedback_status") + "</B>"} ,
{ tag: "hr"},
{ tag: "div", className: "menu_panel",
id: "feedback_sending",
display: false,
innerHTML: "<p><b>"+loc.text('feedback_sending')+"</b></p>" },
{ tag: "table", width: "95%",
id: "feedback_input",
childs: [
{ tag: "tr",
childs: [
{ tag: "td", width: "30%", align: "right",
childs: [{ tag: "div", innerHTML: loc.text('sendtofriend_your_email')}]},
{ tag: "td",
childs: [{ tag: "input", type: "text", id: "inp_email", size: "30"}]}
]
},
{ tag: "tr",
childs: [
{ tag: "td", width: "30%", align: "right", valign: "top",
childs: [{ tag: "div", innerHTML: loc.text('feedback_feedback_text')}]},
{ tag: "td",
childs: [{ tag: "textarea", id: "inp_message", rows: 16, cols: 50, style: {width: "90%"} }]}
]},
{ tag: "tr",
childs: [
{ tag: "td"},
{ tag: "td",
childs: [
{ tag: "input", type: "button", align: "center",
value: loc.text('btn_send'),
events: {onclick: "sendFeedback()"}}
]}
]}
]}
]);
this.elements["content"].style.height = "300px";
this.elements["inp_email"].value = auth.user.email;
}
this.close = function() {
desktop.hideActivePopup();
}
this.showText = function() {}
this.applyText = function() {}
//-------------------------------------
// SEND
//-------------------------------------
this.sendFeedback = function() {
var str = this.elements["inp_message"].value;
if(str!="") {
hideEl(this.elements.feedback_input);
showEl(this.elements.feedback_sending);
request.send({ act: "feedback",
text: str,
email: this.elements["inp_email"].value},
this, "POST");
}
else {
alert(loc.text('feedback_text_empty'));
}
}
this.dispatchMsg = function(msg) {
switch (msg.status) {
case "feedback_saved":
this.elements.feedback_status.innerHTML = "<b>"+loc.text('feedback_msg_saved')+"</b>";
this.elements["inp_message"].value = "";
showEl(this.elements.feedback_input);
hideEl(this.elements.feedback_sending);
break;
case "empty_text":
this.elements.feedback_status.innerHTML = loc.text('feedback_msg_empty');
showEl(this.elements.feedback_input);
hideEl(this.elements.feedback_sending);
break;
}
}
}
Feedback.prototype = new Widget();
function SendToFriend() {
this.init();
this.domSendToFriend = {
tag: "div", className: "menu_panel",
childs: [
{ tag: "div", align: "center", id: "send_status",
style: { fontWeight: "bold" },
html: loc.text("sendtofriend_status") },
{tag: "hr"},
{tag: "table", width: "95%",
childs: [
{ tag: "tr",
childs: [
{ tag: "td", width: "30%", align: "right",
childs: [{ tag: "div", innerHTML: loc.text('sendtofriend_your_name')}]
},
{ tag: "td",
childs: [{ tag: "input", type: "text", id: "ed_name", size: "30"}]
}
]
},
{ tag: "tr", childs: [{ tag: "td"},{ tag: "td"}]},
{ tag: "tr",
childs: [
{ tag: "td", width: "30%", align: "right",
childs: [{ tag: "div", innerHTML: loc.text('sendtofriend_your_email')}]
},
{ tag: "td",
childs: [{ tag: "input", type: "text", id: "ed_email", size: "30" }]
}
]
},
{ tag: "tr", childs: [{ tag: "td"},{ tag: "td"}]},
{ tag: "tr",
childs: [
{ tag: "td", width: "30%", align: "right",
childs: [{ tag: "div", innerHTML: loc.text('sendtofriend_friend_email')}]
},
{ tag: "td",
childs: [{ tag: "input", type: "text", id: "ed_friend_email", size: "30" }]
}
]
},
{ tag: "tr", childs: [{ tag: "td"},{ tag: "td"}]},
{ tag: "tr",
childs: [
{ tag: "td", width: "30%", align: "right", valign: "top",
childs: [{ tag: "div", innerHTML: loc.text('sendtofriend_message')}]
},
{ tag: "td",
childs: [{ tag: "textarea", id: "ed_message", rows: "9", cols: "50", style: {width: "90%"} }]
}
]
},
{ tag: "tr", childs: [{ tag: "td", innerHTML: "&nbsp;"},{ tag: "td"}]},
]
},
{ tag: "div", align: "center", id: "btn_send",
childs: [
{ tag: "input",
type: "button", value: loc.text('sendtofriend_send'),
events: {onclick: "doSend()"}}
]}
]}
this.cfg = {
hasSizeBtn: false,
hasRefreshBtn: false,
hasSettingsBtn: false,
hasDrag: false,
hasProfile: false,
title: "",
module: "SendToFriend",
uniqueId: SYS_WIDGETS_ID + 9
}
this.onBuildInterface = function() {
this.setTitle("<b>"+loc.text('sendtofriend_title')+"</b>");
this.elements["content"].style.height = "300px";
this.buildDomModel(this.elements.content, this.domSendToFriend);
this.elements["ed_email"].value = auth.user.email;
this.elements["ed_message"].value = "http://" + baseUrl;
}
this.close = function() {
desktop.hideActivePopup();
}
this.dispatchMsg = function(msg) {
//alert(msg.status);
switch(msg.status) {
case 'ok':
this.showElement("btn_send");
this.elements.send_status.innerHTML = '<font color=green>'+loc.text('sendtofriend_send_ok')+'</font>';
break;
case 'failed':
this.elements.send_status.innerHTML = '<font color=red>'+loc.text('sendtofriend_send_failed')+'</font>';
this.showElement("btn_send");
break;
}
}
this.doSend = function() {
var name_val   = this.elements.ed_name.value;
var email_val  = this.elements.ed_email.value;
var femail_val = this.elements.ed_friend_email.value;
var msg_val    = this.elements.ed_message.value;
//todo: e-mail check
if (email_val=="") {
alert(loc.text('sendtofriend_email_empty'));
this.elements.ed_email.focus();
return;
}
if (checkEmailAddress(email_val)==false) {
alert(loc.text('sendtofriend_email_invalid'));
this.elements.ed_email.focus();
return;
}
if (femail_val=="") {
alert(loc.text('sendtofriend_femail_empty'));
this.elements.ed_friend_email.focus();
return;
}
if (checkEmailAddress(femail_val)==false) {
alert(loc.text('sendtofriend_femail_invalid'));
this.elements.ed_friend_email.focus();
return;
}
this.elements["send_status"].innerHTML = loc.text("msg_processing");
this.hideElement("btn_send");
request.send({
act    : "send_to_friend",
name   : name_val,
email  : email_val,
femail : femail_val,
msg    : msg_val
},
this);
}
}
SendToFriend.prototype = new Widget();
// E-MAIL
function checkEmailAddress(value)
{
//trim(field);
var goodEmail = value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
if (goodEmail)
return true;
else
return false;
}
function Rss() {
this.init();
this.cfg = {
title: loc.text("rss_title"),
module: "Rss"
}
this.defaultProfile["cnt"] = 4;
this.defaultProfile["opend"] = 0;
this.defaultProfile["url"] = "";
this.defaultProfile["icon"] = "";
this.defaultProfile["period"] = 600;
this.defaultProfile["md5"] = [];
this.domSettings = [
{ tag: "div", className: "settings_section",
childs: [
{ tag: "span", className: "settings_label", innerHTML: loc.text("rss_inp_refresh")},
{ tag: "select", id: "period", className: "settings_control",
options: [
{ value:"600", text: loc.text("rss_p600")},
{ value:"1800", text: loc.text("rss_p1800")},
{ value:"3600", text: loc.text("rss_p3600")}
]
},
{ tag: "input", type: "button", value: loc.text("btn_set"), events: {onclick: "setPeriod()"}}
]},
{ tag: "div", className: "settings_section",
childs: [
{ tag: "span", className: "settings_label", innerHTML: loc.text("rss_inp_open_to")},
{ tag: "input", type: "checkbox", id: "opend", events: { onclick: "setOpenDirectly()"}
}
]}
]
this.lastRefresh = null
this.isLoading = false;
this.isInReader = false;
this.onBuildInterface = function() {
this.elements["settings"].innerHTML = "";
this.buildDomModel(this.elements.settings, this.domSettings);
this.elements.period.value = this.profile.period;
this.elements.opend.checked = this.profile.opend == 1;
this.elements.content.style.padding = "6px";
}
this.onOpen = function() {
this.setTitle(loc.text("rss_title"));
this.elements["content"].innerHTML = loc.text("msg_loading");
kernel.processTimer(this.id, this.profile.period * 1000);
}
this.setOpenDirectly = function() {
this.profile.opend = this.elements.opend.checked ? 1 : 0;
this.save();
this.hideSettings();
}
this.setPeriod = function() {
this.profile.period = this.elements.period.value;
kernel.stopTimer(this.id);
kernel.processTimer(this.id, this.profile.period * 1000, true);
this.save();
this.hideSettings();
}
this.timerHandler = function() {
if(!this.isInReader) {
this.refresh();
}
}
this.refresh = function() {
if(this.profile.url != "") {
var date = new Date();
this.lastRefresh = date.getSeconds();
this.setTitle(loc.text("msg_loading"));
var wid = this.id;
var iconEl = this.elements.icon;
xmlRequest.send(this.profile.url, this, "showChannel");
this.isLoading == true;
} else {
this.elements["content"].innerHTML = loc.text("msg_empty");
}
}
this.openChannel = function(wid, feedId, readeri, count) {
if(this.profile.opend == 1) {
window.open(this.data.items[feedId]["link"]);
} else {
if(!this.isPreview) {
this.isInReader = true;
rssreader.channelLastRefresh = this.lastRefresh;
rssreader.elements["icon"].src = this.elements["icon"].src;
rssreader.openChannel(wid, feedId, readeri, count);
}
}
}
this.getItemsCount = function() {
return Math.min(this.data.items.length, this.profile.cnt);
}
this.getItemsCountAll = function() {
return this.data.items.length;
}
this.getProfileTitle = function() {
if (this.profile.title == '') {
return "<b>"+this.data.title+"</b><br>&nbsp;";
}
else {
var titleUpEnd = this.profile.title.search(/\s-/i);
if (titleUpEnd == -1) {
return "<b>"+this.profile.title+"</b><br>&nbsp;";
}
else {
return "<b>"+this.profile.title.substr(0,titleUpEnd)+"</b><br>"+this.profile.title.substr(titleUpEnd+2);
}
}
}
this.showChannelTitle = function() {
if(this.data) {
this.elements.title.innerHTML = '';
if (this.profile.title == '') {
this.buildDomModel(this.elements.title,
{ tag: "a", href: "void", innerHTML: "<b>"+this.data.title.substr(0,34)+"</b><br>&nbsp;", events: { onclick: "openSite()" } });
}
else {
var titleUpEnd = this.profile.title.search(/\s-/i);
if (titleUpEnd == -1 || titleUpEnd > 34) titleCut = 34;
else titleCut = titleUpEnd;
if (titleUpEnd == -1) {
this.buildDomModel(this.elements.title,
{ tag: "a", href: "void", innerHTML: "<b>"+this.profile.title.substr(0,titleCut)+"</b><br>&nbsp;", events: { onclick: "openSite()" } });
}
else {
var startup = titleUpEnd+3;
var stopup = startup+42;
this.buildDomModel(this.elements.title,
{ tag: "a", href: "void", innerHTML: "<b>"+this.profile.title.substr(0,titleCut)+"</b><br>"+this.profile.title.substr(startup, 43),
events: { onclick: "openSite()" } });
}
}
}
}
this.lastFeed = {
url: null,
time: null
}
this.getItemMd5 = function(idx) {
var content = this.data.items[idx]["content"] ? this.data.items[idx]["content"] : this.data.items[idx]["description"];
var str = this.data.items[idx].title + content;
return crc32(str);
}
this.showChannel = function(response) {
this.isLoading == false;
if(response.responseXML && response.responseXML.documentElement) {
this.data = XMLParser.xml2hash(response.responseXML.documentElement);
var newMd5 = [];
if(this.data) {
var count = this.data.items.length;
var l = this.profile["md5"].length;
for(var i=0; i<count; i++) {
var md5 = this.data.items[i]["md5"] = this.getItemMd5(i);
var j = this.isReaded(md5);
if(j != null) {
this.data.items[i].isRead = 1;
newMd5.push(md5);
l--;
}
}
this.profile["md5"] = newMd5;
if(l != 0) {
this.save();
}
}
this.renderChannel();
this.showChannelTitle();
} else {
this.showError();
}
}
this.iconLoaded = false;
this.wordwrap = function (str, int_width, str_break, cut ) {
var i, j, s, r = str.split("\n");
if(int_width > 0)
for(i in r){
for(s = r[i], r[i] = ""; s.length > int_width;
j = cut ? int_width : (j = s.substr(0, int_width).match(/\S*$/)).input.length - j[0].length || int_width,
r[i] += s.substr(0, j) + ((s = s.substr(j)).length ? str_break : "")
);
r[i] += s;
}
return r.join("\n");
}
this.renderChannel = function(weiter) {
if(this.data) {
if (weiter > 0) {
i = weiter*4;
count = Math.min(this.data.items.length, (i+4));
}
else {
i = 0;
count = Math.min(this.data.items.length, 4);
}
readeri = i;
if(!this.iconLoaded) {
var icons = [
this.profile.icon,
getDir(this.data.siteUrl) + "/favicon.ico",
getDomain(this.data.siteUrl) + "/favicon.ico",
getDir(this.profile.url) + "/favicon.ico",
getDomain(this.profile.url) + "/favicon.ico"
];
loadIcon(this.elements["icon"], icons);
this.iconLoaded = true;
}
var content = "";
var url = "";
var enclosure = "";
var bildEnd = "-1";
var bildStart = bildJpeg = bildPng = bildGif = bild = "";
var width = height = 70;
var sizeParam="width";
var imageObj = new Image();
var c = "";
this.elements.content.innerHTML = '';
if(i == 0) {
var date = this.data.items[0]["pubDate"] ? this.data.items[0]["pubDate"] : "";
var dateStr = "";
if(date != "") {
date = date.substr(5,17);
var month = date.substr(3,3);
var monthNbr= 0;
switch(month.toLowerCase()) {
case "jan": month = loc.text('month_jan'); monthNbr= 1; break;
case "feb": month = loc.text('month_feb'); monthNbr= 2; break;
case "mar": month = loc.text('month_mar'); monthNbr= 3; break;
case "apr": month = loc.text('month_apr'); monthNbr= 4; break;
case "may": month = loc.text('month_may'); monthNbr= 5; break;
case "jun": month = loc.text('month_jun'); monthNbr= 6; break;
case "jul": month = loc.text('month_jul'); monthNbr= 7; break;
case "aug": month = loc.text('month_aug'); monthNbr= 8; break;
case "sep": month = loc.text('month_sep'); monthNbr= 9; break;
case "oct": month = loc.text('month_oct'); monthNbr= 10; break;
case "nov": month = loc.text('month_nov'); monthNbr= 11; break;
case "dec": month = loc.text('month_dec'); monthNbr= 12; break;
default: month = ""; monthNbr= 0; break;
}
var d = new Date ();
var thisMonth = d.getMonth() +1;
if(d.getDate() == Number(date.substr(0,2)) && thisMonth == monthNbr) {
dateStr="Heute "+date.substr(12,5);
}
else {
if (d.getDate()-1 == Number(date.substr(0,2)) && (d.getMonth()+1) == monthNbr) {
dateStr="Gestern "+date.substr(12,5);
}
else {
if (month != "")
dateStr=date.substr(0,2)+". "+month+" "+date.substr(12,5);
else
dateStr = "";
}
}
}
this.buildDomModel(this.elements.content, { tag: "div", className: "rss_box_top0"} );
this.buildDomModel(this.elements.content, { tag: "div", className: "rss_box_top1b"} );
this.buildDomModel(this.elements.content,
{ tag: "div", className: "rss_box_top2b", childs: [ {tag:"span", className: "rss_box_top_txt", innerHTML: "<b>TOP MELDUNG</b>" },
{tag:"span", className: "rss_box_top_txt_right", innerHTML: dateStr } ]} );
}
for(i; i<count; i++) {
content = this.data.items[i]["content"] ? this.data.items[i]["content"] : this.data.items[i]["description"];
url = this.data.items[i]["link"]["href"] ? this.data.items[i]["link"]["href"] : this.data.items[i]["link"];
enclosure = this.data.items[i]["enclosure"] ? this.data.items[i]["enclosure"]["url"] : "";
if (enclosure != "")
if (enclosure.search(/\.jpg/i) == -1 && enclosure.search(/\.jpeg/i) == -1 && enclosure.search(/\.png/i) == -1 && enclosure.search(/\.gif/i) == -1)
enclosure = "";
if (i==0) {
this.buildDomModel(this.elements.content,
{ tag: "div", className: "rss_box_headline",
innerHTML: this.data.items[i].title,
events: { onclick: "openChannel("+this.id+","+i+", "+readeri+", "+count+")" }, id: "item_" + i });
this.buildDomModel(this.elements.content, { tag: "div", className: "rss_box_hrb"});
}
else {
if (content && content != "" && enclosure == "") {
bildStart = content.search(/src/i);
bildEnd = content.search(/\.jpg/i);
bildJpeg = content.search(/\.jpeg/i);
bildPng = content.search(/\.png/i);
if(content.search(/\mf.gif/i) == -1)
bildGif = content.search(/\.gif/i);
if (bildJpeg > bildStart)
if (bildEnd == -1 || bildJpeg < bildEnd)
bildEnd = bildJpeg+1;
if (bildPng > bildStart)
if (bildEnd == -1 || bildPng < bildEnd)
bildEnd = bildPng;
if (bildGif > bildStart)
if (bildEnd == -1 || bildGif < bildEnd)
bildEnd = bildGif;
}
if (enclosure != "")
bildEnd = 1;
if(bildEnd > 0)  {
if (enclosure != "") {
bild = enclosure;
}
else {
if(content){
if (content.substring(bildStart, bildEnd).search(/\"/) == -1 && content.substring(bildStart, bildEnd).search(/\'/) == -1)
bild = content.substring(bildStart+4, bildEnd+4);
else
bild = content.substring(bildStart+5, bildEnd+4);
}
}
if (bild.search(/http/i) == -1)
bild = this.data.siteUrl + bild;
imageObj.src=bild;
width = imageObj.width;
height = imageObj.height;
if (width < height)
sizeParam = "height";
else
sizeParam = "width";
/*
if (height <2) {
c = "<table width=100%><tr><td valign=center style='padding: 0px;'>"
}
else{
*/
c = "<table width=100%><tr><td valign=center width='80' style='padding: 0px;'>"+
"<img src='"+bild+"' "+sizeParam+"='70'/>"+"</td><td valign=center style='padding: 0px;'>"
/*
}
*/
/*
if (i==0) {
c += this.data.items[i].title+"</td></tr></table>";
this.buildDomModel(this.elements.content,
{ tag: "div", className: "rss_box_headline",
innerHTML: c, events: { onclick: "openChannel("+this.id+","+i+", "+readeri+", "+count+")" }, id: "item_" + i });
this.buildDomModel(this.elements.content, { tag: "div", className: "rss_box_hrb"});
}
else {
*/
c += this.data.items[i].title+"</td></tr></table><hr color='#AAAAAA'/>";
this.buildDomModel(this.elements.content,
{ tag: "div", className: "rss_box_item" + ( (this.data.items[i].isRead == 1) ? "_visited" : ""),
innerHTML: c, events: { onclick: "openChannel("+this.id+","+i+", "+readeri+", "+count+")" }, id: "item_" + i });
/*
}
*/
}
else {
this.buildDomModel(this.elements.content,
{ tag: "div", className: "rss_box_item" + ( (this.data.items[i].isRead == 1) ? "_visited" : ""),
innerHTML: this.data.items[i].title+"<hr color='#AAAAAA'/>",
events: { onclick: "openChannel("+this.id+","+i+", "+readeri+", "+count+")" }, id: "item_" + i });
}
}
}
/* Seite etc */
this.buildDomModel(this.elements.content,
{ tag: "a", className: "rss_box_item_seite", innerHTML: loc.text("rss_page")});
var j = (this.data.items.length - (this.data.items.length % 4)) / 4;
if (this.data.items.length % 4 == 0)
j--;
if (j>9)
j=9;
var x = 1;
var current;
if (weiter > 0)
current = weiter;
else
current = 0;
for (x; x < j+2; x++) {
if (x-1 == current) {
this.buildDomModel(this.elements.content,
{ tag: "a", className: "rss_box_item_currseite", innerHTML: ""+x});
}
else {
this.buildDomModel(this.elements.content,
{ tag: "a", href:"void", title: loc.text("rss_page")+" "+x, className: "rss_box_item_weiter",
innerHTML: x, events: { onclick: "renderChannel("+(x-1)+")" }, id: "weiter" });
}
}
}
else if (!this.isLoading) {
this.showError();
}
}
this.showError = function() {
var titel = '';
if (this.profile.title == '')
titel = this.data.title.substr(0,34);
else
titel = this.profile.title;
this.elements["title"].innerHTML = "<b>"+titel+"</b><br>"+loc.text("rss_msg_error");
this.elements["content"].innerHTML = loc.text("rss_error");
}
this.openSite = function() {
if(this.data) {
window.open(this.data.siteUrl);
}
}
this.onClose = function() {
if(!this.isPreview && rssreader.widgetId && rssreader.widgetId == this.id) {
rssreader.close();
}
}
this.isReaded = function(md5) {
for(var i=0; i<this.profile["md5"].length; i++) {
if(this.profile["md5"][i] == md5) {
return i;
}
}
return null;
}
this.setReaded = function(idx) {
var md5 = this.data.items[idx].md5;
var i = this.isReaded(md5);
if(i == null) {
this.profile["md5"].push(md5);
}
}
this.processItemRead = function(itemIdx) {
this.data.items[itemIdx].isRead = 1;
this.setReaded(itemIdx);
this.showChannelTitle();
if (this.elements["item_" + itemIdx] && itemIdx != 0)
this.elements["item_" + itemIdx].className = "rss_box_item_visited";
}
}
Rss.prototype = new Widget();

function RssReader() {
this.init();
this.cfg = {
hasSizeBtn: false,
hasRefreshBtn: false,
hasSettingsBtn: false,
hasDrag: false,
hasProfile: false,
title: loc.text("rssreader_title"),
module: "RssReader",
uniqueId: SYS_WIDGETS_ID + 5
}
var totCount="";
this.domContent = {
tag: "table",
style: { width: "100%" },
childs: [
{ tag: "tr", childs: [ { tag: "td", width: "35%", childs: [ ]}, { tag: "td", childs: [{ tag: "div", id: "channelTitle"}] } ] },
{ tag: "tr",
childs: [ { tag: "td", width: "35%", childs: [ { tag: "div", id: "menu", className: "listBox", style: {width: "auto", height: "405px"}} ]},
{ tag: "td", childs: [ { tag: "div", id: "view", className: "listBoxContent", style: {width: "auto", height: "405px"}} ]}
]}
]}
this.channelLastRefresh = null;
this.onBuildInterface = function() {
this.elements["content"].style.height = "425px";
this.buildDomModel(this.elements.content, this.domContent);
this.setTitle(this.cfg.title);
}
this.buildChannel = function(readeri, count) {
var i = readeri;
totCount = count;
this.elements.channelTitle.innerHTML = "";
this.elements.menu.innerHTML = "";
this.elements.view.innerHTML = "";
for(i; i< count; i++) {
this.buildDomModel(this.elements.menu,
[{ tag: "div", className: "menu_panel",
childs: [
{ tag: "a", innerHTML: this.data.items[i].title, id: "menuItem"+i, href: "void", events: {onclick: "readFeed("+i+")"},
className: "listItem" + (this.data.items[i].isRead == 1 ? "Visited" : "") }
]
},
{ tag: "hr", width: "100%"}
]);
}
}
this.readFeed = function(feedId) {
this.elements.view.scrollTop = 0;
this.elements.view.innerHTML = "";
var content = this.data.items[feedId]["content"] ? this.data.items[feedId]["content"] : this.data.items[feedId]["description"];
if(content && content != "")
content = content.replace(/<a /g, "<a target='_blank' ");
var url = this.data.items[feedId]["link"]["href"] ? this.data.items[feedId]["link"]["href"] : this.data.items[feedId]["link"];
var date = this.data.items[feedId]["pubDate"] ? this.data.items[feedId]["pubDate"] : "";
var dateStr = "";
if(date != "") {
date = date.substr(5,17);
var month = date.substr(3,3);
var monthNbr= 0;
switch(month.toLowerCase()) {
case "jan": month = loc.text('month_jan'); monthNbr= 1; break;
case "feb": month = loc.text('month_feb'); monthNbr= 2; break;
case "mar": month = loc.text('month_mar'); monthNbr= 3; break;
case "apr": month = loc.text('month_apr'); monthNbr= 4; break;
case "may": month = loc.text('month_may'); monthNbr= 5; break;
case "jun": month = loc.text('month_jun'); monthNbr= 6; break;
case "jul": month = loc.text('month_jul'); monthNbr= 7; break;
case "aug": month = loc.text('month_aug'); monthNbr= 8; break;
case "sep": month = loc.text('month_sep'); monthNbr= 9; break;
case "oct": month = loc.text('month_oct'); monthNbr= 10; break;
case "nov": month = loc.text('month_nov'); monthNbr= 11; break;
case "dec": month = loc.text('month_dec'); monthNbr= 12; break;
default: month = ""; monthNbr= 0; break;
}
var d = new Date ();
var thisMonth = d.getMonth() +1;
if(d.getDate() == Number(date.substr(0,2)) && thisMonth == monthNbr) {
dateStr="Heute "+date.substr(12,5);
}
else {
if (d.getDate()-1 == Number(date.substr(0,2)) && (d.getMonth()+1) == monthNbr) {
dateStr="Gestern "+date.substr(12,5);
}
else {
if (month != "")
dateStr=date.substr(0,2)+". "+month+" "+date.substr(12,5);
else
dateStr = "";
}
}
}
this.buildDomModel(this.elements.view, [

/*--table--*/
{tag: "table",
childs: [
{ tag: "tr", childs: [ { tag: "td", childs:[

{ tag: "div", style: { padding:"16px", height: "320px" },className: "listBoxContent",
innerHTML: "<div><a href='" + url + "' class='rssreader_item_title' target=_blank>" + this.data.items[feedId].title +
"</a></div><p class='rssreader_date'>"+dateStr+"</p><p>"+(content ? content : "")+"</p>"
}

/*,*/

/*--table--*/
]}]},
{ tag: "tr", childs: [ { tag: "td", childs:[

{ tag: "div", style: { paddingLeft:"16px",paddingRight:"16px" }, className: "float_panel",
childs: [

{ tag: "hr", width: "100%"},
{tag: "div" , style: {paddingTop: "4px"}, childs:[
{tag: "a", className: "rssreader_item_link", target: "_blank", sysHref: url ,innerHTML: loc.text("rssreader_link")},
{tag: "a", display: (feedId > 0), className: "rssreader_prev", href: "void", events: {onclick: "readFeed("+(feedId-1)+")"}, innerHTML: "<< Vorherige"},
{tag: "a", display:(feedId == 0), className: "rssreader_prevempty",  innerHTML: ""},
{tag: "a", display:(feedId > 0 && feedId < totCount - 1), className: "rssreader_item_link",  innerHTML: " | "},
{tag: "a", display: (feedId < totCount - 1), className: "rssreader_item_link", href: "void", events: {onclick: "readFeed("+(feedId+1)+")"}, innerHTML: "Nächste >>"}
]}

]}
/*--table--*/
]}]}]}

]);

this.elements.view.scrollTop = 0;
if(kernel.getWidget(this.widgetId)) {
kernel.getWidget(this.widgetId).processItemRead(feedId);
kernel.getWidget(this.widgetId).save();
}
this.elements['menuItem'+feedId].className = "listItemVisited";
}
this.openChannel = function(widgetId, feedId, readeri, count) {
menu.hide();
this.data = kernel.getWidget(widgetId).data;
this.widgetId = widgetId;
var countAll = kernel.getWidget(this.widgetId).getItemsCountAll();
this.buildChannel(0, countAll);
this.elements.icon.src = kernel.getWidget(widgetId).elements.icon.src;
desktop.showPopup('rssreader');
this.setTitle(kernel.getWidget(this.widgetId).getProfileTitle());
this.readFeed(feedId);
}
this.close = function() {
if(this.widgetId && kernel.getWidget(this.widgetId)) {
if(this.channelLastRefresh == kernel.getWidget(this.widgetId).lastRefresh) {
kernel.getWidget(this.widgetId).isInReader = false;
}
}
desktop.hideActivePopup();
}
}
RssReader.prototype = new Widget();


function Googlenews() {
this.init();
this.cfg = {
title: loc.text("googlenews_title"),
module: "Googlenews"
}
this.defaultProfile["cnt"] = 4;
this.defaultProfile["opend"] = 0;
this.defaultProfile["url"] = "http://news.google.com/news?ned=de&hl=de&ned=de&q=Elch&ie=UTF-8&output=rss";
this.defaultProfile["icon"] = "widgets/googlenews/ico.gif";
this.defaultProfile["period"] = 600;
this.defaultProfile["md5"] = [];
this.domSettings = [
{ tag: "div", className: "settings_section",
childs: [
{ tag: "span", className: "settings_label", innerHTML: loc.text("rss_inp_refresh")},
{ tag: "select", id: "period", className: "settings_control",
options: [
{ value:"600", text: loc.text("rss_p600")},
{ value:"1800", text: loc.text("rss_p1800")},
{ value:"3600", text: loc.text("rss_p3600")}
]
},
{ tag: "input", type: "button", value: loc.text("btn_set"), events: {onclick: "setPeriod()"}}
]},
{ tag: "div", className: "settings_section",
childs: [
{ tag: "span", className: "settings_label", innerHTML: loc.text("rss_inp_open_to")},
{ tag: "input", type: "checkbox", id: "opend", events: { onclick: "setOpenDirectly()"}
}
]}
]
this.domContent = [
{ tag: "div", className: "menu_panel", style: {background: "#F0F0F0", padding: "0px", marginTop: "4px"},
childs: [
createTableDom([{content: { tag: "img", id: "server_logo", border: "0", display: false, style: {marginRight: "10px"} }, width: "1%"},
{content: { tag: "input", id: "search_text", type: "text", style: {width: "95%", align: "center"}}, width: "98%"},
{content: { tag: "input", type: "button", value: loc.text("btn_go"), events: {onclick: "goSearch()"}}, width: "1%"}
], "100%")
]
}
]
this.lastRefresh = null
this.isLoading = false;
this.isInReader = false;
this.onBuildInterface = function() {
this.elements["settings"].innerHTML = "";
this.buildDomModel(this.elements.settings, this.domSettings);
this.buildDomModel(this.elements.content, this.domContent);
this.elements.period.value = this.profile.period;
this.elements.opend.checked = this.profile.opend == 1;
this.elements.content.style.padding = "6px";
var widget = this;
this.elements["search_text"]["onkeyup"] = function(event) {
if (!event) {
event = window.event
}
if(event.keyCode == 13) {
widget.goSearch()
}
};
}
this.onOpen = function() {
this.setTitle(loc.text("rss_title"));
this.elements["content"].innerHTML = loc.text("msg_loading");
kernel.processTimer(this.id, this.profile.period * 1000);
}
this.setOpenDirectly = function() {
this.profile.opend = this.elements.opend.checked ? 1 : 0;
this.save();
this.hideSettings();
}
this.setUrl = function(new_url) {
var url = new_url;
if(url != "") {
if(this.profile["url"] != url) {
this.profile["url"] = url;
this.save();
kernel.stopTimer(this.id);
kernel.processTimer(this.id, this.profile.period * 1000, true);
this.refresh();
}
}
}
this.setPeriod = function() {
this.profile.period = this.elements.period.value;
kernel.stopTimer(this.id);
kernel.processTimer(this.id, this.profile.period * 1000, true);
this.save();
this.hideSettings();
}
this.timerHandler = function() {
if(!this.isInReader) {
this.refresh();
}
}
this.refresh = function() {
if(this.profile.url != "") {
var date = new Date();
this.lastRefresh = date.getSeconds();
this.setTitle(loc.text("msg_loading"));
var wid = this.id;
var iconEl = this.elements.icon;
var url = this.profile.url;
url = url.replace(/ooo/g, "\u00F6").replace(/uuu/g, "\u00FC").replace(/aaa/g, "\u00E4").replace(/sss/g, "\u00DF").replace(/AAA/g, "\u00C4").replace(/OOO/g, "\u00D6").replace(/UUU/g, "\u00DC");
xmlRequest.sendg(encodeURI(url), this, "showChannel");
this.isLoading == true;
} else {
this.elements["content"].innerHTML = loc.text("msg_empty");
}
}
this.openChannel = function(wid, feedId, readeri, count) {
if(this.profile.opend == 1) {
window.open(this.data.items[feedId]["link"]);
} else {
if(!this.isPreview) {
this.isInReader = true;
rssreader.channelLastRefresh = this.lastRefresh;
rssreader.elements["icon"].src = this.elements["icon"].src;
rssreader.openChannel(wid, feedId, readeri, count);
}
}
}
this.getItemsCount = function() {
return Math.min(this.data.items.length, this.profile.cnt);
}
this.getItemsCountAll = function() {
return this.data.items.length;
}

this.getProfileTitle = function() {
var titleUpEnd = this.data.title.search(/\s-/i);
var titleUpStop = Math.min(titleUpEnd, 32);
if (titleUpEnd == -1) {
return "<b>"+this.data.title+"</b><br>&nbsp;";
}
else {
return "<b>"+this.data.title.substr(0,titleUpStop)+"</b><br>"+this.data.title.substr(titleUpEnd+2,12)+"-Suche";
}
}

this.showChannelTitle = function() {
if(this.data) {
this.elements.title.innerHTML = '';
this.buildDomModel(this.elements.title,
{ tag: "a", href: "void", innerHTML: this.getProfileTitle(),
events: { onclick: "openSite()" } });
}
}

this.lastFeed = {
url: null,
time: null
}
this.getItemMd5 = function(idx) {
var content = this.data.items[idx]["content"] ? this.data.items[idx]["content"] : this.data.items[idx]["description"];
var str = this.data.items[idx].title + content;
return crc32(str);
}
this.showChannel = function(response) {
this.isLoading == false;
if(response.responseXML && response.responseXML.documentElement) {
this.data = XMLParser.xml2hash(response.responseXML.documentElement);
var newMd5 = [];
if(this.data) {
var count = this.data.items.length;
var l = this.profile["md5"].length;
for(var i=0; i<count; i++) {
var md5 = this.data.items[i]["md5"] = this.getItemMd5(i);
var j = this.isReaded(md5);
if(j != null) {
this.data.items[i].isRead = 1;
newMd5.push(md5);
l--;
}
}
this.profile["md5"] = newMd5;
if(l != 0) {
this.save();
}
}
this.renderChannel();
this.showChannelTitle();
} else {
this.showError();
}
}
this.wordwrap = function (str, int_width, str_break, cut ) {
var i, j, s, r = str.split("\n");
if(int_width > 0)
for(i in r){
for(s = r[i], r[i] = ""; s.length > int_width;
j = cut ? int_width : (j = s.substr(0, int_width).match(/\S*$/)).input.length - j[0].length || int_width,
r[i] += s.substr(0, j) + ((s = s.substr(j)).length ? str_break : "")
);
r[i] += s;
}
return r.join("\n");
}
this.renderChannel = function(weiter) {
if(this.data) {
if (weiter > 0) {
i = weiter*4;
count = Math.min(this.data.items.length, (i+4));
}
else {
i = 0;
count = Math.min(this.data.items.length, 4);
}
readeri = i;
var icons = [this.profile.icon];
loadIcon(this.elements["icon"], icons);
var content = "";
var url = "";
var bildEnd = "-1";
var bildStart = bildJpeg = bildPng = bildGif = bild = "";
var width = height = 70;
var sizeParam="width";
var imageObj = new Image();
var c = "";
this.elements.content.innerHTML = '';
this.buildDomModel(this.elements.content,
{ tag: "div", className: "menu_panel", style: {marginTop: "4px", padding: "0px"},
childs: [
createTableDom([
{content: { tag: "span", innerHTML: "Suchbegriff", className: "googlenews_stich", title: loc.text("googlenews_hint_search"), style: {marginRight: "10px"} }, width: "1%"},
{content: { tag: "input", id: "search_text", type: "text", style: {width: "95%", align: "center"}}, width: "98%"},
{content: { tag: "input", type: "button", value: loc.text("btn_go"), events: {onclick: "goSearch()"}}, width: "1%"}
], "100%")
]
}
);
var widget = this;
this.elements["search_text"]["onkeyup"] = function(event) {
if (!event) {
event = window.event
}
if(event.keyCode == 13) {
widget.goSearch()
}
};
if(count == 0) {
this.buildDomModel(this.elements.content,
{ tag: "div", className: "googlenews_zerohits", innerHTML: loc.text("googlenews_nohit")+"<br><hr color='#AAAAAA'/>" }
);
}
else {
if(i == (weiter*4) && i != 0) {
this.buildDomModel(this.elements.content,
{ tag: "div", className: "rss_box_item", innerHTML: "<hr color='#AAAAAA'/>" }
);
}
if(i == 0) {
var date = this.data.items[0]["pubDate"] ? this.data.items[0]["pubDate"] : "";
var dateStr = "";
if(date != "") {
date = date.substr(5,17);
var month = date.substr(3,3);
var monthNbr= 0;
switch(month.toLowerCase()) {
case "jan": month = loc.text('month_jan'); monthNbr= 1; break;
case "feb": month = loc.text('month_feb'); monthNbr= 2; break;
case "mar": month = loc.text('month_mar'); monthNbr= 3; break;
case "apr": month = loc.text('month_apr'); monthNbr= 4; break;
case "may": month = loc.text('month_may'); monthNbr= 5; break;
case "jun": month = loc.text('month_jun'); monthNbr= 6; break;
case "jul": month = loc.text('month_jul'); monthNbr= 7; break;
case "aug": month = loc.text('month_aug'); monthNbr= 8; break;
case "sep": month = loc.text('month_sep'); monthNbr= 9; break;
case "oct": month = loc.text('month_oct'); monthNbr= 10; break;
case "nov": month = loc.text('month_nov'); monthNbr= 11; break;
case "dec": month = loc.text('month_dec'); monthNbr= 12; break;
default: month = ""; monthNbr= 0; break;
}
var d = new Date ();
var thisMonth = d.getMonth() +1;
if(d.getDate() == Number(date.substr(0,2)) && thisMonth == monthNbr) {
dateStr="Heute "+date.substr(12,5);
}
else {
if (d.getDate()-1 == Number(date.substr(0,2)) && (d.getMonth()+1) == monthNbr) {
dateStr="Gestern "+date.substr(12,5);
}
else {
if (month != "")
dateStr=date.substr(0,2)+". "+month+" "+date.substr(12,5);
else
dateStr = "";
}
}
}
this.buildDomModel(this.elements.content, { tag: "div", className: "google_top0"} );
this.buildDomModel(this.elements.content, { tag: "div", className: "google_top1"} );
this.buildDomModel(this.elements.content,
{ tag: "div", className: "google_top2",
childs: [ {tag:"span", className: "google_top_txt", innerHTML: "<b>NEUSTE NACHRICHT</b>"},
{tag:"span", className: "rss_box_top_txt_right", innerHTML: dateStr }]} );
}
}
for(i; i<count; i++) {
content = this.data.items[i]["content"] ? this.data.items[i]["content"] : this.data.items[i]["description"];
url = this.data.items[i]["link"]["href"] ? this.data.items[i]["link"]["href"] : this.data.items[i]["link"];
if (content) {
bildStart = content.search(/src/i);
bildEnd = content.search(/\.jpg/i);
bildJpeg = content.search(/\.jpeg/i);
bildPng = content.search(/\.png/i);
bildGif = content.search(/\.gif/i);
if (bildJpeg > bildStart)
if (bildEnd == -1 || bildJpeg < bildEnd)
bildEnd = bildJpeg+1;
if (bildPng > bildStart)
if (bildEnd == -1 || bildPng < bildEnd)
bildEnd = bildPng;
if (bildGif > bildStart)
if (bildEnd == -1 || bildGif < bildEnd)
bildEnd = bildGif;
}
if(bildEnd > 0) {
bild = content.substring(bildStart+5, bildEnd+4);
imageObj.src=bild;
width = imageObj.width;
height = imageObj.height;
if (width < height)
sizeParam = "height";
else
sizeParam = "width";
if (i==0) {
c = "<table width=100%><tr><td valign=center width='80' style='padding: 0px;'>"+
"<img src='"+bild+"' "+sizeParam+"='70'/>"+"</td><td valign=center style='padding: 0px;'>"+
this.data.items[i].title+"</td></tr></table>";
this.buildDomModel(this.elements.content,
{ tag: "div", className: "google_headline",
innerHTML: c, events: { onclick: "openChannel("+this.id+","+i+", "+readeri+", "+count+")" }, id: "item_" + i });
this.buildDomModel(this.elements.content,
{ tag: "div", className: "google_hr"});
}
else {
c = "<table width=100%><tr><td valign=top width='80' style='padding: 0px;'>"+
"<img src='"+bild+"' "+sizeParam+"='70'/>"+"</td><td valign=center style='padding: 0px;'>"+
this.data.items[i].title+"</td></tr></table>";
c = c + "<hr color='#AAAAAA'/>";
this.buildDomModel(this.elements.content,
{ tag: "div", className: "rss_box_item" + ( (this.data.items[i].isRead == 1) ? "_visited" : ""),
innerHTML: c, events: { onclick: "openChannel("+this.id+","+i+", "+readeri+", "+count+")" }, id: "item_" + i });
}
}
else {
if (i==0) {
this.buildDomModel(this.elements.content,
{ tag: "div", className: "google_headline",
innerHTML: this.data.items[i].title,
events: { onclick: "openChannel("+this.id+","+i+", "+readeri+", "+count+")" }, id: "item_" + i });
this.buildDomModel(this.elements.content,
{ tag: "div", className: "google_hr"});
}
else {
this.buildDomModel(this.elements.content,
{ tag: "div", className: "rss_box_item" + ( (this.data.items[i].isRead == 1) ? "_visited" : ""),
innerHTML: "" + this.data.items[i].title+"<hr color='#AAAAAA'/>",
events: { onclick: "openChannel("+this.id+","+i+", "+readeri+", "+count+")" }, id: "item_" + i });
}
}
}
/* Seite etc */
this.buildDomModel(this.elements.content,
{ tag: "a", className: "rss_box_item_seite", innerHTML: loc.text("rss_page")});
var j = (this.data.items.length - (this.data.items.length % 4)) / 4;
if (this.data.items.length % 4 == 0)
j--;
if (j>9)
j=9;
var x = 1;
var current;
if (weiter > 0)
current = weiter;
else
current = 0;
for (x; x < j+2; x++) {
if (x-1 == current) {
this.buildDomModel(this.elements.content,
{ tag: "a", className: "rss_box_item_currseite", innerHTML: ""+x});
}
else {
this.buildDomModel(this.elements.content,
{ tag: "a", href:"void", title: loc.text("rss_page")+" "+x, className: "rss_box_item_weiter",
innerHTML: x, events: { onclick: "renderChannel("+(x-1)+")" }, id: "weiter" });
}
}
}
else if (!this.isLoading) {
this.showError();
}
}
this.showError = function() {
this.elements["title"].innerHTML = loc.text("rss_msg_error");
this.elements["content"].innerHTML = "";
}
this.openSite = function() {
if(this.data) {
window.open(this.data.siteUrl);
}
}
this.onClose = function() {
if(!this.isPreview && rssreader.widgetId && rssreader.widgetId == this.id) {
rssreader.close();
}
}
this.isReaded = function(md5) {
for(var i=0; i<this.profile["md5"].length; i++) {
if(this.profile["md5"][i] == md5) {
return i;
}
}
return null;
}
this.setReaded = function(idx) {
var md5 = this.data.items[idx].md5;
var i = this.isReaded(md5);
if(i == null) {
this.profile["md5"].push(md5);
}
}
this.processItemRead = function(itemIdx) {
this.data.items[itemIdx].isRead = 1;
this.setReaded(itemIdx);
this.showChannelTitle();
if (this.elements["item_" + itemIdx] && itemIdx != 0)
this.elements["item_" + itemIdx].className = "rss_box_item_visited";
}
this.goSearch = function() {
var str = this.elements.search_text.value;
str = str.replace(/\u002B/g, "").replace(/\u00F6/g, "ooo").replace(/\u00FC/g, "uuu").replace(/\u00E4/g, "aaa").replace(/\u00DF/g, "sss").replace(/\u00C4/g, "AAA").replace(/\u00D6/g, "OOO").replace(/\u00DC/g, "UUU");
if(str == "") {
return;
}
var url = "http://news.google.com/news?ned=de&hl=de&ned=de&q="+str+"&ie=UTF-8&scoring=n&output=rss";
this.setUrl(url);
}
}
Googlenews.prototype = new Widget();
function Bookmarks() {
this.init();
this.cfg = {
hasRefreshBtn: false,
title: loc.text("bookmarks_title"),
module: "Bookmarks",
saveMethod: "POST"
}
this.domSettings = [
{ tag: "div", className: "bevel_section", innerHTML: loc.text("bookmarks_sec_delete"),
style: {cursor: "pointer"}, events: {onclick: "switchSection('section_delete')"}
},
{ tag: "div", className: "menu_panel", id: "section_delete", display: false, align: "center",
childs: [ { tag: "input", type: "button", value: loc.text("bookmarks_btn_delete_all"), events: {onclick: "deleteBookmarks()"}} ]
},
{ tag: "div", className: "bevel_section", innerHTML: loc.text("bookmarks_sec_add"), id: "add_bookmark",
style: {cursor: "pointer"}, events: {onclick: "switchSection('section_add')"}
},
{ tag: "div", className: "menu_panel", id: "section_add", display: false,
childs: [ { tag: "table", width: "95%", id: "bookmarks_table", align: "center",
childs: [
{ tag: "tr",
childs: [
{ tag: "td", width: "25%", childs: [ { tag: "span", className: "menu_panel", innerHTML: loc.text("bookmarks_inp_title")}] },
{ tag: "td", childs: [ { tag: "input", type: "text", id: "select_title"}] }
]
},
{ tag: "tr",
childs: [
{ tag: "td", width: "25%", childs: [ { tag: "div", className: "menu_panel", innerHTML: loc.text("bookmarks_inp_url")}] },
{ tag: "td", childs: [ { tag: "input", type: "text", id: "select_url"}] }
]
},
{ tag: "tr",
childs: [
{ tag: "td", width: "25%", childs: [ { tag: "div", className: "menu_panel", innerHTML: loc.text("bookmarks_inp_tags")}] },
{ tag: "td", childs: [ { tag: "input", type: "text", id: "select_tags"}] }
]
},
{ tag: "tr",
childs: [
{ tag: "td", width: "25%", childs: [ { tag: "span", className: "menu_panel", innerHTML: "&nbsp;"}] },
{ tag: "td", childs: [ { tag: "input", type: "button", value: loc.text("btn_save"), events: {onclick: "processAdd()"}}] }
]
}
]
}]
}
];
this.domContent = [
{ tag: "div", className: "bevel_section", innerHTML: loc.text("bookmarks_sec_edit"), id: "edit_bookmark", display: false,
style: {cursor: "pointer"}, events: {onclick: "switchSection('section_edit')"}
},
{ tag: "div", className: "menu_panel", id: "section_edit", display: false,
childs: [ { tag: "table", width: "95%", id: "bookmarks_table", align: "center",
childs: [
{ tag: "tr",
childs: [
{ tag: "td", width: "25%", childs: [ { tag: "span", className: "menu_panel", innerHTML: loc.text("bookmarks_inp_title")}] },
{ tag: "td", childs: [ { tag: "input", type: "text", id: "edit_title"}] }
]
},
{ tag: "tr",
childs: [
{ tag: "td", width: "25%", childs: [ { tag: "div", className: "menu_panel", innerHTML: loc.text("bookmarks_inp_url")}] },
{ tag: "td", childs: [ { tag: "input", type: "text", id: "edit_url"}] }
]
},
{ tag: "tr",
childs: [
{ tag: "td", width: "25%", childs: [ { tag: "div", className: "menu_panel", innerHTML: loc.text("bookmarks_inp_tags")}] },
{ tag: "td", childs: [ { tag: "input", type: "text", id: "edit_tags"}] }
]
},
{ tag: "tr",
childs: [
{ tag: "td", width: "25%", childs: [ { tag: "span", className: "menu_panel", innerHTML: "&nbsp;"}] },
{ tag: "td", childs: [ { tag: "input", type: "button", value: loc.text("btn_save"), events: {onclick: "processUpdate()"}}] }
]
}
]
}]
},
{ tag: "div", className: "bevel_section", innerHTML: loc.text("bookmark_sec_tags"),
style: {cursor: "pointer"}, events: {onclick: "switchSection('section_tags')"}},
{ tag: "div", className: "menu_panel", id: "section_tags", display: "inline", align: "left"},
{ tag: "hr", width: "100%"},
{ tag: "div", className: "menu_panel", id: "bookmarks", align: "left"}
]
this.defaultProfile["title"] = loc.text("bookmarks_title");
this.defaultProfile["tags"] = ['Unkategorisiert'];
this.defaultProfile["bookmarks"] = [];
this.activeTag = 0;
this.onBuildInterface = function() {
this.elements["settings"].innerHTML = "";
this.buildDomModel(this.elements.settings, this.domSettings);
this.buildDomModel(this.elements.content, this.domContent);
this.applyTag(0);
}
this.onShowSettings = function() {
this.closeEdit();
}
this.switchSection = function(sid) {
if(this.elements[sid].style.display == 'none') {
showEl(this.elements[sid]);
} else {
hideEl(this.elements[sid]);
}
}
this.editBookmarkId = null;
this.closeEdit = function() {
if(this.editBookmarkId != null) {
hideEl(this.elements.section_edit);
hideEl(this.elements.edit_bookmark);
this.isEditOpen = null;
}
}
this.openEdit = function(id) {
this.editBookmarkId = id;
var tags = [];
for(var i = 0; i < this.profile.bookmarks[id].tags.length; i++) {
tags.push(this.profile.tags[this.profile.bookmarks[id].tags[i]])
}
this.elements.edit_title.value = this.profile.bookmarks[id].title;
this.elements.edit_url.value = this.profile.bookmarks[id].url;
this.elements.edit_tags.value = tags.join(", ");
showEl(this.elements.section_edit);
showEl(this.elements.edit_bookmark);
hideEl(this.elements.settings);
}
this.processUpdate = function() {
if(this.editBookmarkId != null) {
var title = trim(this.elements.edit_title.value);
var url = trim(this.elements.edit_url.value);
if(title != "" && url != "") {
this.updateBookmark(this.editBookmarkId, title, url, trim(this.elements.edit_tags.value));
this.applyTag(this.activeTag);
this.save();
}
}
this.closeEdit();
}
this.deleteBookmarks = function() {
this.profile.bookmarks = this.defaultProfile["bookmarks"];
this.profile.tags = this.defaultProfile["tags"];
this.applyTag(0);
}
this.processAdd = function() {
var title = trim(this.elements.select_title.value);
var url = trim(this.elements.select_url.value);
if(title != "" && url != "") {
if(url.indexOf("http://") == -1) {
url = "http://" + url;
}
this.closeEdit();
this.addBookmark(title, url, trim(this.elements.select_tags.value));
this.save();
this.applyTag(this.activeTag);
this.elements.select_title.value = '';
this.elements.select_url.value = '';
this.elements.select_tags.value = '';
}
}
this.renderTags = function() {
this.elements.section_tags.innerHTML = '';
for(var t=0; t<this.profile.tags.length; t++) {
if(this.profile.tags[t] != undefined) {
if(this.activeTag != t) {
this.buildDomModel(this.elements.section_tags,  { tag: "a", href: "void", events: { onclick: "applyTag("+t+")"},
innerHTML: this.profile.tags[t], style: { margin: "4px"} });
} else {
this.buildDomModel(this.elements.section_tags, { tag: "span", innerHTML: this.profile.tags[t], style: { margin: "4px"} });
}
}
}
}
this.applyTag = function(tagId) {
this.closeEdit();
this.activeTag = tagId;
this.setTitle("<b>"+loc.text("bookmarks_title")+"</b><br>"+this.profile.tags[tagId]);
var list = this.getBookmarksByTagId(tagId);
this.elements.bookmarks.innerHTML = '';
for(var i = 0; i<list.length; i++) {
var itemDom = { tag: "div", className: "menu_panel", id: "item"+list[i],
childs: [
createTableDom([
{content: {tag: "a", id: "item_title"+list[i], sysHref: this.profile.bookmarks[list[i]].url, target: "_blank", innerHTML: this.profile.bookmarks[list[i]].title}, width: "95%"},
{content: createButtonDom(false, "openEdit("+list[i]+")", "static/client/edit.gif"), width: "1%"},
{content: createButtonDom(false, "deleteItem("+list[i]+")", "static/client/delete_link.gif"), width: "1%"}
], "95%")
]
}
this.buildDomModel(this.elements.bookmarks, itemDom);
}
this.renderTags();
}
this.deleteItem = function(id) {
if(confirm(loc.text("bookmarks_delete_prompt", this.profile.bookmarks[id].title))) {
this.closeEdit();
this.deleteBookmark(id);
if(this.profile.tags[this.activeTag]) {
this.applyTag(this.activeTag);
} else {
this.applyTag(0);
}
this.save();
}
}
this.updateBookmark = function(id, title, url, tags) {
this.deleteBookmark(id);
if(url.indexOf("http://") == -1) {
url = "http://" + url;
}
this.addBookmark(title, url, tags);
}
this.addBookmark = function(title, url, tagsData) {
var newBookmark = { title: title, url: url, tags: [] };
if(typeof(tagsData) == "string") {
var tags = tagsData!= "" ? tagsData.split(",") : false;
} else {
var tags = tagsData;
}
if(tags) {
for(var i = 0; i<tags.length; i++) {
tags[i] = trim(tags[i]);
var tn = arraySearch(tags[i], this.profile.tags)
if(tn != undefined) {
newBookmark.tags.push(tn);
} else {
var idx = arrayFirstFree(this.profile.tags);
this.profile.tags[idx] = tags[i];
newBookmark.tags.push(idx);
}
}
} else {
newBookmark.tags = [0];
}
this.activeTag = newBookmark.tags[0];
this.profile.bookmarks[arrayFirstFree(this.profile.bookmarks)] = newBookmark;
}
this.deleteBookmark = function(id) {
var tags = this.profile.bookmarks[id].tags;
for(var i=0; i<tags.length; i++) {
if(tags[i] != 0) {
var count = 0;
for(var j=0; j<this.profile.bookmarks.length; j++) {
if(this.profile.bookmarks[j] && arraySearch(tags[i], this.profile.bookmarks[j].tags) != undefined) {
count++;
}
}
if(count<2) {
this.profile.tags[tags[i]] = undefined;
}
}
}
this.profile.bookmarks[id] = undefined;
}
this.getBookmarksByTagId = function(tagId) {
var res = [];
for(var i=0; i<this.profile.bookmarks.length; i++) {
if(this.profile.bookmarks[i] &&
this.profile.bookmarks[i].tags != undefined &&
arraySearch(tagId, this.profile.bookmarks[i].tags) != undefined) {
res.push(i);
}
}
return res;
}
}
Bookmarks.prototype = new Widget();
function ToDoList() {
this.init();
this.cfg = {
hasRefreshBtn: false,
title_prefix: loc.text("todolist_title_prefix"),
title: "",
module: "ToDoList"
}
this.defaultProfile["items"] = [];
this.defaultProfile["title"] = "";
this.domSettings = [
{ tag: "div", className: "settings_section",
childs: [
{ tag: "span", innerHTML: loc.text("todolist_inp_todo"), className: "settings_label"},
{tag: "input", id: "todo_title", type: "text", size: "15", className: "settings_control"},
{tag: "input", type: "button", value: loc.text("btn_add"), events: {onclick: "addItem()"}, className: "settings_control"}
]}
]
this.domContent = { tag: "table", className: "sys_table", id: "items_table", width: "100%", childs: [] }
this.onBuildInterface = function() {
this.buildDomModel(this.elements.settings, this.domSettings);
this.renderItems();
widget = this;
this.elements["todo_title"]["onkeyup"] = function(event) {if (!event) {event = window.event;} if(event.keyCode == 13) {widget.addItem();} };
this.elements["input_title"]["onkeyup"] = function(event) {if (!event) {event = window.event;} if(event.keyCode == 13) {widget.settingsSetTitle();} };
}
this.onOpen = function() {
this.setTitle(this.profile.title);
}
this.setTitle = function(html) {
this.elements.title.innerHTML = "<b>"+this.cfg.title_prefix+"</b><br>"+html;
this.hideSettings();
}
this.renderItems = function() {
this.elements.content.innerHTML = "";
this.buildDomModel(this.elements.content, this.domContent);
for(var i=0; i<this.profile.items.length; i++) {
this.renderItem(i);
}
}
this.renderItem = function(n) {
this.buildDomModel(this.elements.items_table_tbody,
{ tag: "tr", id: "item"+n,
childs: [
{ tag: "td", width: "1%",
childs: [
{ tag: "input", id: "item_checkbox"+n, type: "checkbox", events: {onclick: "switchItem("+n+")"}, checked: this.profile.items[n].completed}
]},
{ tag: "td", width: "95%",
childs: [
{ tag: "div", style: {textDecoration: this.profile.items[n].completed ? "line-through" : "", overflow: "hidden"},
id: "item_title"+n, innerHTML: this.profile.items[n].title.wordWrap(10).jsUnescape() }
]},
{ tag: "td", width: "1%", childs: [ createButtonDom(false, "moveItemUp("+n+")", "static/client/move_up.gif") ]},
{ tag: "td", width: "1%", childs: [ createButtonDom(false, "moveItemDown("+n+")", "static/client/move_down.gif") ]},
{ tag: "td", width: "1%", childs: [ createButtonDom(false, "editItem("+n+")", "static/client/edit.gif") ]},
{ tag: "td", width: "1%", childs: [ createButtonDom(false, "deleteItem("+n+")", "static/client/delete_link.gif") ]}
]
});
}
this.addItem = function() {
var title = trim(this.elements.todo_title.value.jsEscape());
if(!title) {
return;
}
var newId = this.profile.items.length;
var newItem = {title: title, completed: false};
this.profile.items[newId] = newItem;
this.renderItem(newId);
this.save();
this.elements.todo_title.value = '';
}
this.switchItem = function(id) {
this.profile.items[id].completed = !this.profile.items[id].completed;
this.elements['item_title'+id].style.textDecoration = this.profile.items[id].completed ? "line-through" : "" ;
this.save();
}
this.moveItemUp = function(id) {
if(id > 0) {
this.swapItems(id, id-1);
this.renderItems();
this.save();
}
}
this.moveItemDown = function(id) {
if(id < this.profile.items.length - 1) {
this.swapItems(id, id+1);
this.renderItems();
this.save();
}
}
this.editItem = function(id) {
var res = trim(prompt(loc.text("todolist_todo_edit"), this.profile.items[id].title));
if(res) {
this.profile.items[id].title = res;
this.elements['item_title'+id].innerHTML = res.wordWrap(10);
}
this.save();
}
this.deleteItem = function(id) {
if(confirm(  loc.text("todolist_delete_confirm", this.profile.items[id].title)  )) {
var tmp = [];
for(var i=0; i<this.profile.items.length; i++) {
if(i != id) {
tmp.push(this.profile.items[i]);
}
}
this.profile.items = tmp;
tmp = null;
this.renderItems();
this.save();
}
}
this.swapItems = function(a,b) {
var tmp = this.profile.items[a];
this.profile.items[a] = this.profile.items[b];
this.profile.items[b] = tmp;
}
}
ToDoList.prototype = new Widget();
function Webnote() {
this.init();
this.cfg = {
hasRefreshBtn: false,
title: loc.text("webnote_title"),
module: "Webnote"
}
this.defaultProfile["title"] = this.cfg.title;
this.defaultProfile["text"] = loc.text("webnote_text");
this.contentDomWebnote = [
{ tag: "div", id: "text_show", className: "webnote_text"},
{ tag: "textarea", id: "text_edit", display: false, className: "webnote_textarea",
events: {onclick: "applyText()", onblur: "showText()"}}
]
this.onBuildInterface = function() {
this.buildDomModel(this.elements.content, this.contentDomWebnote);
var text_show = this.elements.text_show;
var text_edit = this.elements.text_edit;
var widget = this;
this.elements.text_show["onclick"] = function() { widget.editText(widget, text_show, text_edit); };
var t = this.profile.text.jsUnescape();
this.elements.text_show.innerHTML = text2html(t).parseUrl();
this.elements.text_edit.value = t;
this.elements.text_show.style.backgroundColor = "#FFFFEE";
this.elements.text_show.style.padding = "4px";
this.elements.text_edit.style.backgroundColor = "#FFFFEE";
this.elements.text_edit.style.padding = "4px";
this.elements.title.innerHTML = "<b>"+loc.text("webnote_title")+"</b><br>"+this.profile.title;

this.elements["input_title"]["onkeyup"] = function(event) {if (!event) {event = window.event;} if(event.keyCode == 13) {widget.settingsSetTitle();} };

}
this.setTitle = function(html) {
this.elements.title.innerHTML = "<b>"+loc.text("webnote_title")+"</b><br>"+html;
this.hideSettings();
}
this.editText = function(widget, text_show, text_edit) {
var h = text_show.offsetHeight;
hideEl(text_show);
showEl(text_edit);
text_edit.style.height = (h+16)+"px";
text_edit.focus();
text_edit.onkeyup = function() {
text_show.innerHTML = text2html(this.value);
showEl(text_show);
this.style.height = (text_show.offsetHeight+16) + "px";
hideEl(text_show);
}
text_edit.onblur = function() {
text = this.value.replace(/\\/g, "");
this.onblur = null;
hideEl(this);
htmlText = text2html(text);
text_show.innerHTML = htmlText.jsUnescape().parseUrl();
text_show.style.display = "block";
text_show.onclick =  function() { widget.editText(widget, text_show, text_edit); };
widget.profile.text = text.jsEscape();
widget.save();
}
}
this.showText = function() {}
this.applyText = function() {}
}
Webnote.prototype = new Widget();

/*Weather-----------------------*/
function Weather() {
this.init();
this.cfg = {
title: loc.text("weather_title"),
module: "Weather"
};
this.defaultProfile["city"] = "GMXX0007";
this.defaultProfile["unit"] = "c";
this.domSettings = [
{ tag: "div", className: "settings_section",
childs: [
{ tag: "span", innerHTML: loc.text("weather_inp_unit"), className: "settings_label"},
{ tag: "select", id: "setUnit", events: {onchange: "setUnit()"}, className: "settings_control",
options: [ { value:"c", text: loc.text("weather_celsius")}, { value:"f", text: loc.text("weather_fahrenheit")}
]}
]},
{ tag: "div", className: "settings_section",
childs: [
{ tag: "span", innerHTML: loc.text("weather_inp_town"), className: "settings_label"},
{ tag: "input", type: "text", size: 15, id: "setCity", className: "settings_control"},
{ tag: "input", type: "button", id: "btn_setCity", events: {onclick: "loadCities()"}, value: loc.text("btn_set"), className: "settings_control"},
]},
{ tag: "div", className: "settings_section", id: "citiesList", display: false}
]
this.onBuildInterface = function() {
this.elements["settings"].innerHTML = "";
this.buildDomModel(this.elements.settings, this.domSettings);
this.elements.setUnit.value = this.profile.unit;
var widget = this;
this.elements["setCity"]["onkeyup"] = function(event) {
if (!event) { event = window.event; }
if(event.keyCode == 13) { widget.loadCities(); }
};
}
this.onOpen = function() {
this.refresh();
}
var loading = false;
this.refresh = function() {
if(!loading) {
loading = true;
this.setTitle(loc.text("msg_loading"));
xmlRequest.send("http://xoap.weather.com/weather/local/"+this.profile.city+"?cc=*&dayf=4&link=xoap&prod=xoap&par=1127109597&key=f775e0583f016824", this, "showWeather");
}
}
this.setUnit = function() {
this.profile.unit = this.elements.setUnit.value;
this.renderWeather();
this.hideSettings();
this.save();
}
this.loadCities = function() {
this.elements.citiesList.innerHTML = loc.text("msg_loading");
showEl(this.elements.citiesList);
this.elements["btn_setCity"].disabled = true;
var cityStr = this.elements.setCity.value;
cityStr = cityStr.replace(/\u00DF/g, "ss").replace(/\u00E4/g, "a").replace(/\u00F6/g, "o").replace(/\u00FC/g, "u").replace(/\u00C4/g, "a").replace(/\u00D6/g, "o").replace(/\u00DC/g, "u");
cityStr = cityStr.toLowerCase();
switch (cityStr) {
case 'cologne': case 'koln': cityStr = 'cologne, germany'; break;
case 'berlin': cityStr = 'berlin, germany'; break;
case 'dresden': cityStr = 'dresden, germany'; break;
case 'oldenburg': cityStr = 'oldenburg, germany'; break;
case 'bremen': cityStr = 'bremen, germany'; break;
case 'frankfurt am main': cityStr = 'frankfurt main'; break;
case 'munich': case 'munchen': cityStr = 'munich, germany'; break;
case 'hamburg': cityStr = 'hamburg, germany'; break;
case 'gorlitz': cityStr = 'goerlitz, germany'; break;
case 'zurich': cityStr = 'zurich, switzerland'; break;
case 'bern': cityStr = 'bern, switzerland'; break;
case 'basel': cityStr = 'basel, switzerland'; break;
case 'vienna': case 'wien': cityStr = 'vienna, austria'; break;
deafault: cityStr = cityStr; break;
}
xmlRequest.send(encodeURI("http://xoap.weather.com/search/search?where="+cityStr), this, "showCities");
}
this.showCities = function(response) {
this.elements["btn_setCity"].disabled = false;
this.elements.citiesList.innerHTML = '';
showEl(this.elements.citiesList);
var doc = response.responseXML.documentElement;
var r = doc.getElementsByTagName("loc");
if(r.length == 1) {
this.hideSettings();
this.setCity(r[0].getAttribute("id"));
} else if (r.length == 0) {
this.elements.citiesList.innerHTML = "<b>" + loc.text("weather_no_cities") + "</b>";
} else {
var clistDom = [];
var cityString = "";
for(var i=0; i<r.length; i++) {
cityString = r[i].firstChild.nodeValue.replace(/Germany/g, "Deutschland").replace(/Switzerland/i, "Schweiz").replace(/Austria/i, "&Ouml;sterreich");
clistDom[i]={tag:"li", childs: [{ tag: "a", href: "void", events: {onclick: "setCity('"+r[i].getAttribute("id")+"')"},innerHTML: cityString}]}
}
this.buildDomModel(this.elements.citiesList, { tag: "ul", childs: clistDom });
}
}
this.setCity = function(id) {
this.profile.city = id;
hideEl(this.elements.citiesList);
this.hideSettings();
this.save();
this.refresh();
}
this.toCelcius = function(n) {
var calc = Math.round((n-32)*5/9);
return (isNaN(calc)) ? loc.text("weather_na") : calc + "&#176;";
}
this.getTemp = function(node) {
var hi = node.getElementsByTagName("hi")[0].firstChild.nodeValue;
var low = node.getElementsByTagName("low")[0].firstChild.nodeValue;
if(this.profile.unit == "c") {
hi = this.toCelcius(hi);
low = this.toCelcius(low);
}
if (hi == loc.text("weather_na"))
return "&nbsp;<br>&nbsp;<br>"+loc.text("weather_lo")+" "+low;
else
return "&nbsp;<br>"+loc.text("weather_hi")+" "+hi+"<br>"+loc.text("weather_lo")+" "+low+"";
}
this.renderWeather = function() {
if(!this.data) {
return false;
}
var days = this.data.getElementsByTagName("day");
var tag = [];
var mDays = [];
var pic;
for(var i=0; i<days.length; i++) {
switch (days[i].getAttribute("t")) {
case "Monday": tag.push(loc.text("weather_mon")); break;
case "Tuesday": tag.push(loc.text("weather_tue")); break;
case "Wednesday": tag.push(loc.text("weather_wed")); break;
case "Thursday": tag.push(loc.text("weather_thu")); break;
case "Friday": tag.push(loc.text("weather_fri")); break;
case "Saturday": tag.push(loc.text("weather_sat")); break;
case "Sunday": tag.push(loc.text("weather_sun")); break;
default: tag.push(loc.text("weather_na")); break;
}
}
for(var i=0; i<days.length; i++) {
pic = parseInt(days[i].getElementsByTagName("icon")[0].firstChild.nodeValue);
pic = ((pic < 10) ? "0" : "") + pic + ".gif";
mDays.push({ tag: "td", style: {textAlign: "center"},
childs: [
{ tag: "div", innerHTML: tag[i]+"<br>&nbsp;" },
{ tag: "img", src: 'static/weather/' + pic },
{ tag: "div", innerHTML: this.getTemp(days[i]) }
]});
}
var m = { tag: "table", className: "sys_table", style: {width: "100%"}, childs: [ { tag: "tr", childs: mDays } ]};
this.elements["content"].innerHTML = '';
this.buildDomModel(this.elements["content"], m);

/*---TWC-links------*/
var mLinks = [];
mLinks.push(
{ tag: "td", style: {textAlign: "left", width: "36px"},
childs: [
{ tag: "div", innerHTML: "<a onclick='window.open(this.href); return false;' href='http://www.weather.com/?par=xoap&site=wx_logo&cm_ven=bd_oap&cm_cat=1127109597&cm_pla=HomePage&cm_ite=Logo'><img src='static/weather/TWClogo_31px.png' alt='TWCi' style='margin:6px;' /></a>" }
]});
mLinks.push(
{ tag: "td", style: {textAlign: "left"},
childs: [
{ tag: "div", innerHTML: "<a class='twcLink' onclick='window.open(this.href); return false;' href='http://de.weather.com/weather/local/"+this.profile.city+"'>10 Tage Vorhersage</a>" },
{ tag: "div", innerHTML: "<a class='twcLink' onclick='window.open(this.href); return false;' href='http://de.weather.com/weather/hourbyhour/"+this.profile.city+"'>Rund um die Uhr</a>" }
]});
mLinks.push(
{ tag: "td", style: {textAlign: "left"},
childs: [
{ tag: "div", innerHTML: "<a class='twcLink' onclick='window.open(this.href); return false;' href='http://de.weather.com/maps/activities/intlformula1/index_large.html'>Deutschland Vorhersage</a>" },
{ tag: "div", innerHTML: "<a class='twcLink' onclick='window.open(this.href); return false;' href='http://de.weather.com/maps/activities/intlformula1/eur24stvorhersminmax_large.html'>Europa Vorhersage</a>" }
]});
var m2 = { tag: "table", className: "sys_table", style: {width: "100%"}, childs: [ { tag: "tr", childs: mLinks } ]};
this.buildDomModel(this.elements["content"], m2);

if(this.data.getElementsByTagName("dnam").length>0) {
var cityCap = this.data.getElementsByTagName("dnam")[0].firstChild.nodeValue;
cityCap = cityCap.replace(/Germany/i, "Deutschland").replace(/Munich/i, "M&uuml;nchen").replace(/Cologne/i, "K&ouml;ln").replace(/Goerlitz/i, "G&ouml;rlitz").replace(/Giessen/i, "Gie&szlig;en").replace(/Switzerland/i, "Schweiz").replace(/Austria/i, "&Ouml;sterreich").replace(/Zurich/i, "Z&uuml;rich").replace(/Vienna/i, "Wien");
cityCap = cityCap.replace(/Nurnberg/i, "N&uuml;rnberg").replace(/Osnabruck/i, "Osnabr&uuml;ck").replace(/Neumunster/i, "Neum&uuml;nster").replace(/Lubeck/i, "L&uuml;beck").replace(/Luneburg/i, "L&uuml;neburg").replace(/Munster/i, "M&uuml;nster").replace(/Dusseldorf/i, "D&uuml;sseldorf").replace(/Saarbrucken/i, "Saarbr&uuml;cken").replace(/Tubingen/i, "T&uuml;bingen").replace(/Furth/i, "F&uuml;rth").replace(/Wurtzburg/i, "W&uuml;rtzburg").replace(/Gottingen/i, "G&ouml;ttingen");
this.setTitle("<b>"+this.cfg.title + "</b><br>" + cityCap);
}
}
this.showWeather = function(response) {
this.data = response.responseXML.documentElement;
this.renderWeather();
loading = false;
}
}
Weather.prototype = new Widget();
/*Weather-----------------------*/

function Websearch() {
this.init();
this.cfg = {
hasRefreshBtn: false,
title: loc.text("websearch_title"),
module: "Websearch"
}
this.defaultProfile["openHere"] = "0";
this.defaultProfile["serverId"] = 1;
this.domSettings = [
{ tag: "div", className: "settings_section",
childs: [
{ tag: "span", innerHTML: loc.text("websearch_results_target"), className: "settings_label"},
{ tag: "input", id: "set_target", type: "checkbox", events: {onclick: "setTarget()"}, className: "settings_control"}
]}
]
this.domContent = [
{ tag: "div", className: "menu_panel", style: {margin: "0px", backgroundColor: "#F0F0F0", padding: "0px"},
childs: [
createTableDom([{content: { tag: "img", title: loc.text("websearch_hint_google"), id: "search_logoG", border: "0", display: false, style: {marginLeft:"4px", marginRight: "8px"} }, width: "1%"},
{content: { tag: "input", id: "search_textG", type: "text", style: {width: "160px", align: "center"}}, width: "98%"},
{content: { tag: "input", type: "button", value: loc.text("btn_go"), events: {onclick: "goSearchG()"}, style: { marginRight: "4px"}}, width: "1%"}
], "100%"),
createTableDom([{content: { tag: "img", title: loc.text("websearch_hint_wiki"), id: "search_logoW", border: "0", display: false, style: {marginLeft:"4px", marginRight: "8px"} }, width: "1%"},
{content: { tag: "input", id: "search_textW", type: "text", style: {width: "160px", align: "center"}}, width: "98%"},
{content: { tag: "input", type: "button", value: loc.text("btn_go"), events: {onclick: "goSearchW()"}, style: { marginRight: "4px"}}, width: "1%"}
], "100%"),
createTableDom([{content: { tag: "img", title: loc.text("websearch_hint_canoo"), id: "search_logoC", border: "0", display: false, style: {marginLeft:"4px", marginRight: "8px"} }, width: "1%"},
{content: { tag: "input", id: "search_textC", type: "text", style: {width: "160px", align: "center"}}, width: "98%"},
{content: { tag: "input", type: "button", value: loc.text("btn_go"), events: {onclick: "goSearchC()"}, style: { marginRight: "4px"}}, width: "1%"}
], "100%"),
createTableDom([
{content: { tag: "img", title: loc.text("websearch_hint_leo"), id: "search_logoL", border: "0", display: false, style: {marginLeft:"4px", marginRight: "8px"} }, width: "1%"},
{content: { tag: "select", id: "inp_location", style: {width: "60px"},options: [
{ text: "DE-EN", value: "1" }, { text: "DE-FR", value: "3" }, { text: "DE-ES", value: "5" }, { text: "DE-IT", value: "7" }, { text: "DE-CN", value: "9" },
{ text: "EN-DE", value: "2" }, { text: "FR-DE", value: "4" }, { text: "ES-DE", value: "6" }, { text: "IT-DE", value: "8" }, { text: "CN-DE", value: "10" }
] }, width: "20%"},
{content: { tag: "input", id: "search_textL", type: "text", style: {width: "97px"}}, width: "78%"},
{content: { tag: "input", type: "button", value: loc.text("btn_go"), events: {onclick: "goSearchL()"}, style: { marginRight: "4px"}}, width: "1%"}
], "100%")
]
}
]
this.onBuildInterface = function() {
this.elements["settings"].innerHTML = "";
this.buildDomModel(this.elements.settings, this.domSettings);
this.buildDomModel(this.elements.content, this.domContent);
showEl(this.elements.search_logoG);
this.elements.search_logoG.src = 'widgets/websearch/google_logo.gif';
showEl(this.elements.search_logoW);
this.elements.search_logoW.src = 'widgets/websearch/wiki_fav.gif';
showEl(this.elements.search_logoC);
this.elements.search_logoC.src = 'widgets/websearch/canoo_logo.gif';
showEl(this.elements.search_logoL);
this.elements.search_logoL.src = 'widgets/websearch/leo_logo.gif';
this.setTitle("<b>"+this.cfg.title + "</b><br>&nbsp;");
this.elements.set_target.checked = (this.profile.openHere == 1);
var widget = this;
this.elements["search_textG"]["onkeyup"] = function(event) { if (!event) { event = window.event } if(event.keyCode == 13) { widget.goSearchG() } };
this.elements["search_textW"]["onkeyup"] = function(event) { if (!event) { event = window.event } if(event.keyCode == 13) { widget.goSearchW() } };
this.elements["search_textC"]["onkeyup"] = function(event) { if (!event) { event = window.event } if(event.keyCode == 13) { widget.goSearchC() } };
this.elements["search_textL"]["onkeyup"] = function(event) { if (!event) { event = window.event } if(event.keyCode == 13) { widget.goSearchL() } };
}
this.setTarget = function() {
this.profile.openHere = (this.elements.set_target.checked ? "1" : "0");
this.save();
}
this.goSearchG = function() {
var str = this.elements.search_textG.value;
if(str == "") {
return;
}
var url = "http://www.google.de/search?q="+escape(str);
if(this.profile.openHere == 1) {
document.location = url;
} else {
window.open(url);
}
}
this.goSearchW = function() {
var str = this.elements.search_textW.value;
if(str == "") {
return;
}
var url = "http://de.wikipedia.org/wiki/"+escape(str);
if(this.profile.openHere == 1) {
document.location = url;
} else {
window.open(url);
}
}
this.goSearchC = function() {
var str = this.elements.search_textC.value;
if(str == "") {
return;
}
var url = "http://www.canoo.net/services/Controller?input="+escape(str)+"&MenuId=Search&service=canooNet&lang=de";
if(this.profile.openHere == 1) {
document.location = url;
} else {
window.open(url);
}
}
this.goSearchL = function() {
var str = this.elements.search_textL.value;
var location = "1";
var langPair = "ende";
switch (this.elements["inp_location"].value) {
case "1": langPair = "ende"; location = "1"; break;
case "2": langPair = "ende"; location = "-1"; break;
case "3": langPair = "frde"; location = "1"; break;
case "4": langPair = "frde"; location = "-1"; break;
case "5": langPair = "esde"; location = "1"; break;
case "6": langPair = "esde"; location = "-1"; break;
case "7": langPair = "itde"; location = "1"; break;
case "8": langPair = "itde"; location = "-1"; break;
case "9": langPair = "chde"; location = "1"; break;
case "10": langPair = "chde"; location = "-1"; break;
default: langPair = "ende"; location = "1"; break;
}
if(str == "") {
return;
}
var url = "http://dict.leo.org/"+langPair+"?lp="+langPair+"&lang=de&searchLoc="+
location+"&cmpType=relaxed&sectHdr=on&spellToler=on&search="+escape(str)+"&relink=on";
if(this.profile.openHere == 1) {
document.location = url;
} else {
window.open(url);
}
}
}
Websearch.prototype = new Widget();
function Calculator() {
this.init();
this.cfg = {
hasProfile: false,
title: "",
hasSettingsBtn: false,
hasRefreshBtn: false,
module: "Calculator"
}
this.numpadButtons = [
[ {type: "sys1", numkey: "sys", action: "memoryClear()", text: "MC"},
{type: "sys1", numkey: "sys", action: "memoryRestore()", text: "MR"},
{type: "sys1", numkey: "sys", action: "memoryStore()", text: "MS"},
{type: "sys1", numkey: "sys", action: "memoryAdd()", text: "M+"},
{type: "sys2", numkey: "sys", action: "clear()", text: "C"},
{type: "sys2", numkey: "sys", action: "clearE()", text: "CE"} ],
[ {type: "std", numkey: "num", action: "addNumber(7)", text: "7"},
{type: "std", numkey: "num", action: "addNumber(8)", text: "8"},
{type: "std", numkey: "num", action: "addNumber(9)", text: "9"},
{type: "std", numkey: "op", action: "setOperation('/')", text: "/"},
{type: "std", numkey: "op", action: "evalSqrt()", text: "sqrt"} ],
[ {type: "std", numkey: "num", action: "addNumber(4)", text: "4"},
{type: "std", numkey: "num", action: "addNumber(5)", text: "5"},
{type: "std", numkey: "num", action: "addNumber(6)", text: "6"},
{type: "std", numkey: "op", action: "setOperation('*')", text: "*"},
{type: "std", numkey: "op", action: "evalPercent()", text: "%"} ],
[ {type: "std", numkey: "num", action: "addNumber(1)", text: "1"},
{type: "std", numkey: "num", action: "addNumber(2)", text: "2"},
{type: "std", numkey: "num", action: "addNumber(3)", text: "3"},
{type: "std", numkey: "op", action: "setOperation('-')", text: "-"},
{type: "std", numkey: "op", action: "eval1x()", text: "1/x"} ],
[ {type: "std", numkey: "op", action: "changeSign()", text: "+/-"},
{type: "std", numkey: "num", action: "addNumber(0)", text: "0"},
{type: "std", numkey: "num", action: "addPoint()", text: ","},
{type: "std", numkey: "op", action: "setOperation('+')", text: "+"},
{type: "std", numkey: "op", action: "evalute()", text: "="} ]
]
this.onBuildInterface = function() {
var numpadModel = [];
for(var r=0; r<this.numpadButtons.length; r++) {
var rowModel = [];
for(var b=0; b<this.numpadButtons[r].length; b++) {
rowModel.push(
{ tag: "div", className: "calc_btn_" + this.numpadButtons[r][b].type,
childs: [
{ tag: "button", innerHTML: this.numpadButtons[r][b].text, className: "calc_padkey_"+ this.numpadButtons[r][b].numkey,
events: { onclick: this.numpadButtons[r][b].action }}
]});
}
numpadModel.push(
{ tag: "div", className: "calc_numpad_row",
childs: rowModel });
}
this.buildDomModel(this.elements["content"], [
{ tag: "div", className: "calc_display", innerHTML: "0",
id: "display"},
{ tag: "div", className: "calc_numpad",
childs: numpadModel }
]);
}
this.onOpen = function() {
this.setTitle("<b>"+loc.text("calculator_title")+"</b><br>&nbsp;");
}
this.addPointFlag = false;
this.memory = null;
this.operation = null;
this.activeNumber = 0;
this.needClear = false;
this.isError = false;
this.getValue = function() {
var v = trim(this.elements["display"].innerHTML);
if(v == "E") {
this.setValue(0);
v = "0";
}
return v;
}
this.setValue = function(v) {
this.elements["display"].innerHTML = v;
}
this.addNumber = function(n) {
if(this.isError) {
this.setValue(0);
this.isError = false;
}
if(this.needClear) {
this.setValue(0);
this.needClear = false;
}
if((this.getValue() == "0") && !this.addPointFlag) {
this.setValue(n);
}
else {
if(this.addPointFlag) {
this.elements["display"].innerHTML += ".";
}
this.elements["display"].innerHTML += n;
}
this.addPointFlag = false;
}
this.addPoint = function() {
if(this.needClear) {
this.setValue(0);
this.needClear = false;
}
if(this.getValue().indexOf(".") == -1) {
this.addPointFlag = true;
}
}
this.setOperation = function(op) {
if(this.operation != null) {
this.evalute();
}
this.addPointFlag = false;
this.activeNumber = parseFloat(this.getValue());
this.operation = op;
this.needClear = true;
}
this.evalute = function() {
if(this.operation != null) {
var v = parseFloat(this.getValue());
switch(this.operation) {
case "*":
this.setValue(v * this.activeNumber);
break;
case "+":
this.setValue(v + this.activeNumber);
break;
case "-":
this.setValue(this.activeNumber - v);
break;
case "/":
if(v != 0) {
this.setValue(this.activeNumber / v);
}
else {
this.setValue("E");
}
break;
}
this.operation = false;
this.addPointFlag = false;
this.needClear = true;
}
}
this.evalPercent = function() {
if(this.activeNumber != null && this.operation != null) {
this.addPointFlag = false;
var v = parseFloat(this.getValue());
this.setValue(v*this.activeNumber/100);
}
}
this.evalSqrt = function() {
this.addPointFlag = false;
var v = parseFloat(this.getValue());
this.setValue(Math.sqrt(v));
}
this.eval1x = function() {
this.addPointFlag = false;
var v = parseFloat(this.getValue());
if(v != 0) {
this.setValue(1/v);
}
else {
this.setValue("E");
}
}
this.changeSign = function() {
var v = parseFloat(this.getValue());
if(v != 0) {
this.setValue(-v);
}
}
this.memoryClear = function() {
this.memory = null;
}
this.memoryRestore = function() {
if(this.memory != null) {
this.setValue(this.memory);
this.needClear = true;
}
}
this.memoryStore = function() {
this.memory = parseFloat(this.getValue());
}
this.memoryAdd = function() {
if(this.memory == null) {
this.memory = 0;
}
this.memory += parseFloat(this.getValue());
}
this.clear = function() {
this.addPointFlag = false;
this.operation = null;
this.activeNumber = 0;
this.setValue(0);
}
this.clearE = function() {
this.addPointFlag = false;
this.setValue(0);
}
}
Calculator.prototype = new Widget();

