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