2 // Custom project scripts
\r
5 var elements = new Array();
\r
6 for (var i = 0; i < arguments.length; i++) {
\r
7 var element = arguments[i];
\r
8 if (typeof element == 'string')
\r
9 element = document.getElementById(element);
\r
10 if (arguments.length == 1)
\r
12 elements.push(element);
\r
17 function getElementsByClass(searchClass,node,tag)
\r
19 var classElements = new Array();
\r
24 var els = node.getElementsByTagName(tag);
\r
25 var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
\r
26 for (i = 0; i < els.length; i++)
\r
27 if ( pattern.test(els[i].className) )
\r
28 classElements.push(els[i]);
\r
29 return classElements;
\r
33 return document.body||document.documentElement||(document.getElementsByTagName ? document.getElementsByTagName("body")[0] : null);
\r
36 function getPageRect(){
\r
37 var b = document.body || document.documentElement,
\r
38 sTop = window.pageYOffset || b.scrollTop,
\r
39 sLeft = window.pageXOffset || b.scrollLeft,
\r
40 sWidth= b.clientWidth || window.innerWidth,
\r
41 sHeight= b.clientHeight || window.innerHeight,
\r
42 oWidth= b.scrollWidth || b.offsetWidth,
\r
43 oHeight= b.scrollHeight || b.offsetHeight;
\r
44 return {top: sTop, left: sLeft, width: sWidth, height: sHeight, scrollX: oWidth, scrollY: oHeight};
\r
47 function getBounds(e)
\r
49 var left = e.offsetLeft, top = e.offsetTop, width = e.offsetWidth, height = e.offsetHeight;
\r
50 while (e = e.offsetParent){
\r
51 left += e.offsetLeft;
\r
54 return {left: left, top: top, width: width, height: height};
\r
57 function insertElement(parent, tag, id)
\r
59 if(parent.insertAdjacentHTML)
\r
61 parent.insertAdjacentHTML("afterBegin", '<'+tag+ ' id="'+id+'"></'+tag+'>');
\r
62 return document.getElementById(id);
\r
64 else if(document.createElement && parent.appendChild)
\r
66 var el = document.createElement(tag);
\r
68 parent.appendChild(el);
\r
73 function addEvent(el, sEvt, PFnc)
\r
77 if(el.addEventListener)
\r
78 el.addEventListener(sEvt, PFnc, false);
\r
80 el.attachEvent("on" + sEvt, PFnc);
\r
83 function addLoadEvent(func)
\r
85 var oldonload = window.onload;
\r
86 if (typeof window.onload != 'function')
\r
87 window.onload = func;
\r
89 window.onload = function(){oldonload();func();}
\r
91 function removeEvent(el, sEvt, PFnc)
\r
95 if(el.removeEventListener)
\r
96 el.removeEventListener(sEvt, PFnc, false);
\r
98 el.detachEvent("on" + sEvt, PFnc);
\r
101 function ChangeCssProperty(myclass, element, value)
\r
103 var CSSRules = document.styleSheets[0].rules || document.styleSheets[0].cssRules;
\r
104 for (var i = 0; i < CSSRules.length; i++)
\r
105 if (CSSRules[i].selectorText.toLowerCase() == myclass.toLowerCase())
\r
106 CSSRules[i].style[element] = value;
\r
108 function getOpaSettings()
\r
111 var s = document.body.style;
\r
112 if (typeof s.opacity == 'string') p = 'opacity';
\r
113 else if (typeof s.MozOpacity == 'string') p = 'MozOpacity';
\r
114 else if (typeof s.KhtmlOpacity == 'string') p = 'KhtmlOpacity';
\r
115 else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) p='filter';
\r
118 function setOpacity(oElem, nOpacity)
\r
120 var p = getOpaSettings();
\r
122 setOpacity = new Function('oElem', 'nOpacity', 'if (nOpacity >= 100) {oElem.style.filter = ""; return;} var oAlpha = oElem.filters["DXImageTransform.Microsoft.alpha"] || oElem.filters.alpha; if (oAlpha) oAlpha.opacity = nOpacity;else {oElem.style.zoom = 1;oElem.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";}');
\r
124 setOpacity = new Function('oElem', 'nOpacity', 'oElem.style.'+p+' = nOpacity/100;');
\r
126 setOpacity = new Function(oElem, nOpacity);
\r
127 return setOpacity(oElem, nOpacity);
\r
129 function getOpacity(oElem)
\r
131 var p = getOpaSettings();
\r
133 getOpacity = new Function('oElem', 'var m = oElem.style.filter.match(/alpha\(opacity=(.+)\)/i); return m ? parseFloat(m[1]) : 1;');
\r
135 getOpacity = new Function('oElem', 'var v = oElem.style.'+p+'; return v*100;');
\r
137 getOpacity = new Function(oElem);
\r
138 return getOpacity(oElem);
\r
140 Number.prototype.Timer = function(s, iT, bUrge){
\r
142 if(!this.value || bUrge)
\r
143 this.value = window.setTimeout(s, iT);
\r
145 Number.prototype.EndTimer = function(){
\r
147 window.clearTimeout(this.value);
\r
151 function parseURL(url)
\r
153 // Example "https://www.example.com:8080/some/path/index.html?p=1&q=2&r=3#some-hash"
\r
157 // #1 PROTOCOL, "https"
\r
158 "(?:([^:/\\?#]*):)?" +
\r
159 // #2 HOST, "www.example.com",
\r
160 "(?://([^:/\\?#]*))" +
\r
162 "(?::([^/\\?#]*))?" +
\r
163 // #4 PATH, "/some/path/index.html"
\r
165 // #5 QUERY, "p=1&q=2&r=3"
\r
166 "(?:\\?([^#]*))?" +
\r
167 // #6 FRAGMENT, "some-hash"
\r
168 "(?:#(.*))?" + "$";
\r
169 return RegExp(patern).exec(url);
\r
173 // Link event add function
\r
175 function parseHref(element)
\r
177 var tip={'item':'i', 'spell':'s', 'enchant':'e', 'npc':'c', 'faction':'f'};
\r
178 var ext={'jpg':1, 'jpeg':1, 'png':1};
\r
179 var c = element.getElementsByTagName("a");
\r
180 for (var i = 0; i < c.length; i++)
\r
183 var url = parseURL(a.href);
\r
184 if (!url) continue;
\r
186 if (!url[4]) continue;
\r
187 var e = url[4].split('.');
\r
188 if (e.length > 1 && ext[e[e.length-1]]) a.onclick = showLightbox;
\r
190 if (!url[5]) continue;
\r
191 var p=url[5].split('&');
\r
192 var r=p[0].split('=');
\r
193 // Add tooltip event
\r
194 if (p.length==1&&tip[r[0]]&&r[1]&&!a.id) {a.id=tip[r[0]]+r[1]; a.onmouseover = tt_hrefTip;}
\r
195 // Add light box event
\r
196 else if(r[0]=='map' && !a.onclick) a.onclick = showAjaxBox;
\r
200 // Upload data as HTML in obj.innerHTML via ajax functions
\r
202 function ajaxCacheHtml(element, url) {
\r
203 my_AJAX.addCache(element.innerHTML, 'ajax.php'+url);
\r
206 function ajaxCacheHtmlId(elementId, url) {
\r
207 ajaxCacheHtml(document.getElementById(elementId), url);
\r
209 function uploadFromHref(link, elementId) {
\r
210 var url = link.href.substring(link.href.indexOf('?'), link.href.length);
\r
211 uploadHtmlToId(url, elementId);
\r
214 function uploadHtmlToId(url, elementId) {
\r
215 uploadHtml(url, $(elementId));
\r
217 function uploadHtml(url, element)
\r
220 function callback(text) {
\r
221 obj.innerHTML = text;
\r
222 execHTMLScripts(obj);
\r
225 my_AJAX.GETupload('ajax.php'+url, callback);
\r
228 // Report tabs support functions
\r
230 function report_setSelect(tab, selected)
\r
232 var l = tab.id.split(':');
\r
233 var element = $(l[1]);
\r
234 if (!element) return;
\r
235 element.style.display = selected ? "block" : "none";
\r
236 tab.className = selected ? 'selected' : '';
\r
238 function report_selectTab(page)
\r
240 var tab = $('report_tabs');
\r
242 var els = tab.getElementsByTagName('li');
\r
243 for (i = 0; i < els.length; i++)
\r
244 report_setSelect(els[i], els[i].id == page.id)
\r
246 function report_hideHeaders()
\r
248 ChangeCssProperty('TABLE.report TR.head', 'display', 'none');
\r
250 function report_addTab(name, elementId, selected)
\r
252 var tab = $('report_tabs');
\r
254 tab.innerHTML += '<li id="t:' + elementId + '" onClick="report_selectTab(this);"><a>' + name + '</a></li>';
\r
255 report_setSelect($('t:' + elementId), selected);
\r
261 document.write('<div id=debug></div>');
\r
262 function outDebug(text)
\r
264 var debugDiv = $('debug');
\r
267 debugDiv = document.createElement('div');
\r
268 document.body.appendChild(debugDiv);
\r
269 debugDiv.style.position = 'fixed';
\r
270 debugDiv.style.border = '1px solid';
\r
271 debugDiv.style.background = '#EEE';
\r
272 debugDiv.style.top = 0;
\r
273 debugDiv.style.left = 0;
\r
274 debugDiv.style.width = '800px';
\r
276 debugDiv.innerHTML=text + '<br>';
\r