﻿           /*3OGGO3(^
       ~Q@@@BBBBB@#(B@@S/
     O@@BBBBBBBBBB@O R@B@@O
    O@BBB@@@@@@BBB@G S@@@@@O		Extends Browsers
  /B@BBB@t    /#@B@( //     /		Script controlled by Hakan Bilgin © 2009
 ~@BBB@R(       BB~   /tC/  %@/		For: http://www.cloudo.com
 O@BB@#CCQ##s  /R(  e#@@O  C@@s
/@BBBBBBBBB@O (@( /@#7 /6R@@BB@/
%@BBBBBBB@B~ KR    ^(CG3   t@B@%
3@BBBBBB@O (@R   Q@@@@Q^ /#@BB@%
%@BBBBB@#  K@e   K@@BC  tR@BBB@t
^B@B@SC3  »%   ^^ /sB@BBBBB@R^R
 %KC/      //(     C@@BBBBBBB@t
  QQQ#G    e@@/     C@BBBBBB@R
   K@@#   sRRB@%S@@@(C@BBBB@Q
    (B@K 7@BBBBBBBB@S6@BB@R/
     ~R@G e@BBBBBBB@GS@B@#/			This code is licensed under a Creative Commons License.
        (#@S#@BBBB@#Q@Q(			http://creativecommons.org/licenses/LGPL/2.1/
             ^/~~/*/

/*	EXTENDS STRING	*/
String.prototype.trim		= function() {return this.replace(/(^\s*)|(\s*$)/g,'');};
String.prototype.fill		= function(i,c) {var str = this; c = c || ' '; for (; str.length<i; str+=c){}; return str;};
String.prototype.friendlyHTML = function() {return this.replace(/<scrip.*?>|<\/script>|<applet.*?>|<\/applett>|<embe.*?>|<objec.*?>.*?<\/object>/ig, '').replace(/ on.+?=.+?>/ig, '>').replace(/ href=.javascript:.+?.>/ig, '>');};
String.prototype.stripHTML	= function() {return this.replace(/<.*?>/g, '');};
String.prototype.stripNS	= function() {return this.replace(/<hbi:.*?>|<\/hbi:.*?>/g, '');};
String.prototype.sha1		= function() {return sha1.binb2hex(sha1.core_sha1(sha1.str2binb(this),this.length * sha1.chrsz));};
String.prototype.toHex		= function() {var a = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F']; var i = parseInt(parseInt(this)/16); return a[i] + a[parseInt(this)-i*16];};
String.prototype.encrypt	= function(k) {k=k||9999;var r='';for(i=0;i<this.length;++i){r+=String.fromCharCode(k^this.charCodeAt(i));}return r;};
String.prototype.decrypt	= function(k) {k=k||9999;var r='';for(i=0;i<this.length;i++){r+=String.fromCharCode(k^this.charCodeAt(i));}return r;};

/*	EXTENDS ARRAY	*/
Array.prototype.sort_int	= function(d) {var d = d || -1;return this.sort(function(a,b) {var a = a || new Number(a);var b = b || new Number(b);if (a>b) return 1*d;if (a<b) return -1*d;if (isNaN(a)) return -1*d;if (isNaN(b)) return 1*d;return 0;});};
Array.prototype.indexOf		= function(e) {for (var i=0; i<this.length; i++) {if (this[i] == e) return i;}return -1;};
Array.prototype.subtract	= function(a) {if (!a) return this; if (!a.length) a = [a]; var ra = new Array();for (var i=0; i<this.length; i++) {if (a.indexOf(this[i]) == -1) ra.push(this[i]);}return ra;};
Array.prototype.remove		= function(e) {if (!e) return this;return this.subtract([e]);};
Array.prototype.sum			= function() {var r = 0;for (var i=0; i<this.length; i++) {if (typeof(this[i]) != 'number') continue;r += this[i];}return r;};
Array.prototype.foreach		= function(f) {for (var i=0; i<this.length; i++) {f(this[i], i);}};
Array.prototype.clone		= function() {var n = new Array(this.length); for (var i=0; i<this.length; i++) {if (this[i].length) {n[i] = this[i].clone(); continue;} n[i] = this[i];} return n;};

/*	EXTENDS DATE	*/
Date.prototype.getWeek		= function() {var nYear = new Date(this.getFullYear(), 0, 1);var offset = 7 + 1 - nYear.getDay();if (offset == 8) offset = 1;var dNum = ((Date.UTC(this.getFullYear(), this.getMonth(), this.getDate(),0,0,0) - Date.UTC(this.getFullYear(),0,1,0,0,0)) /1000/60/60/24) + 1;var wNum = Math.floor((dNum-offset+7)/7);if (wNum == 0) {this.getFullYear()--;var pnYear = new Date(this.getFullYear(),0,1);var pOffset = 7 + 1 - pnYear.getDay();wNum = (pOffset == 2 || pOffset == 8)? 53 : 52;}return wNum+1;};

/*	EXTENDS MATH	*/
Math.rnd					= function(n,x) {n=n||10; var i=(!x)?n:x-n;var p=(!x)?0:n;return p+parseInt(Math.random()*i);};
Math.tween = {
	linear : function(t,b,c,d) {return c*t/d+b;},
	bounce : function(t,b,c,d) {return c*Math.sin(t/d*(Math.PI))+b;},
	easeIn : function(t,b,c,d) {return c*(t/=d)*t*t+b;},
	easeOut : function(t,b,c,d) {return c*((t=t/d-1)*t*t+1)+b;},
	easeInOut : function(t,b,c,d) {return ((t/=d/2)<1)? c/2*t*t*t+b : c/2*((t-=2)*t*t+2)+b;},
	gb2 : function (t,b,c,d) {return c-Math.tween.gb1(d-t,0,c,d)+b;},
	gb3 : function (t,b,c,d) {return (t<d/2)? Math.tween.gb2(t*2,0,c,d)*.5+b : Math.tween.gb1(t*2-d,0,c,d)*.5+c*.5+b;},
	gb1 : function (t,b,c,d) {
		if ((t/=d)<(1/2.75)) return c*(7.5625*t*t)+b;
		else if (t<(2/2.75)) return c*(7.5625*(t-=(1.5/2.75))*t+.75)+b;
		else if (t<(2.5/2.75)) return c*(7.5625*(t-=(2.25/2.75))*t+.9375)+b;
		else return c*(7.5625*(t-=(2.625/2.75))*t+.984375)+b;
	}
};

/*	GET (URL) PARAMETERS	*/
window.GET = {};
var srch = window.location.href.split('?');
if (srch.length > 1) {
	var r = srch[1].split('&');
	for (var i=0, il=r.length; i<il; i++) {
		var pair = r[i].split('=');
		if (pair.length == 2) window.GET[pair[0]] = pair[1].split('#')[0];
	}
}

/*	WORD COMPLETE	*/
var woco = {
    rgx: new RegExp('[\\wäåöæø]', 'ig'),
    init: function(oEl) {
        woco.oEl = oEl;
        woco.oEl.value = '';
        woco.rgx = new RegExp('[\\wäåöæø]', 'ig');
        if (/msie/i.test(navigator.userAgent)) {
            oEl.onkeypress = woco.ie.doKey;
            oEl.onkeyup = woco.ie.doSysKey;
        } else {
            oEl.addEventListener('keyup', woco.moz.doSysKey, false);
            oEl.addEventListener('keypress', woco.moz.doKey, false);
        }
    },
    ie: {
        doKey: function() {
            if (event.ctrlKey) return;
            var tKey = String.fromCharCode(event.keyCode);
            if (!event.shiftKey) tKey = tKey.toLowerCase();
            if (!tKey.match(woco.rgx)) return;
            woco.ie.doMatch(tKey);
        },
        doMatch: function(tKey) {
            var tKey = tKey || '';
            rng = document.selection.createRange();
            crng = rng.duplicate();
            crng.moveEnd('character');
            if (document.selection.type == 'Text') document.selection.clear();
            if (crng.text.match(woco.rgx)) return;
            rng.text = tKey;
            rng.moveStart('word', -1);
            rgx = new RegExp(' ' + rng.text.trim() + '[\\wäåöæø_]+', 'ig');
            woco.ie.match = woco.db.match(rgx);
            if (woco.ie.match == null) woco.ie.match = woco.db.match(new RegExp(' ' + rng.text.trim(), 'ig'));
            if (woco.ie.match && woco.ie.match != 'null') {
                woco.ie.mInt = 0;
                woco.ie.complete(tKey);
            } else {
                $('.src_matches')[0].innerHTML = 'Ingen träff.';
            }
            if (tKey != '') woco.ie.cancelEvent();
        },
        complete: function(tKey) {
            jc.maps.render.city(woco.ie.match);
            if (!woco.ie.match || tKey == '') return;
            var suggestedWord = woco.ie.match[woco.ie.mInt].trim().substr(rng.text.length);
            woco.ie.rng = document.selection.createRange();
            /*
            $('.'+ suggestedWord).addClass('bg_color');
            */
            woco.ie.rng.text = suggestedWord;
            woco.ie.rng.moveStart('character', -suggestedWord.length);
            woco.ie.rng.select();
            woco.ie.cancelEvent();
        },
        cancelEvent: function() {
            event.returnValue = null;
            event.cancelBubble = true;
        },
        doSysKey: function() {
            switch (event.keyCode) {
                case 8:
                    if (event.type == 'keyup') woco.ie.doMatch('');
                    break;
                case 9:
                    if (woco.ie.rng && woco.ie.match) {
                        woco.ie.cancelEvent();
                        if (woco.ie.charCase) {
                            woco.ie.rng.moveStart('word', -1);
                            woco.ie.rng.expand('word');
                            woco.ie.rng.text = woco.ie.match[woco.ie.mInt].trim();
                        } else woco.ie.rng.text = woco.ie.rng.text + ' ';
                        woco.ie.rng.select();
                    }
                    break;
                case 13:
                    woco.ie.cancelEvent();
                    break;
            }
            woco.ie.match = null;
        }
    },
    moz: {
        doKey: function(e) {
            var oEl = e.target;
            var tKey = String.fromCharCode(e.charCode);
            if (!tKey.match(woco.rgx)) return woco.moz.doSysKey(e);
            woco.moz.doMatch(e, tKey);
        },
        doMatch: function(e, tKey) {
            var tKey = tKey || '';
            var oEl = e.target;
            rngStart = oEl.selectionStart;
            rngEnd = oEl.selectionEnd;
            selEnd = (rngStart != rngEnd) ? rngEnd : null;
            if (!selEnd && oEl.value.substring(rngStart, rngStart + 1).match(woco.rgx)) return;

            frgStart = rngStart;
            while (frgStart > 0 && oEl.value.substring(frgStart - 1, frgStart).match(woco.rgx)) frgStart--;
            wordFragment = oEl.value.substring(frgStart, rngStart) + tKey;
            rgx = new RegExp(' ' + wordFragment + '[\\wåäööæø_////]+', 'ig');
            woco.moz.match = woco.db.match(rgx);

            if (tKey == '') woco.moz.match = woco.moz.match.sort();
            if (woco.moz.match == null) woco.moz.match = woco.db.match(new RegExp(' ' + wordFragment, 'ig'));

            if (woco.moz.match && woco.moz.match != 'null') {
                woco.moz.mInt = 0;
                woco.moz.complete(e, tKey);
            } else {
                $('.src_matches')[0].innerHTML = 'Ingen träff.';
            }
        },
        doSysKey: function(e) {
            oEl = e.target;
            switch (e.keyCode) {
                case 8:
                    if (e.type == 'keyup') woco.moz.doMatch(e, '');
                    break;
                case 9:
                    if (!woco.moz.match) return;
                    if (woco.moz.charCase) {
                        frgStart = oEl.selectionStart;
                        while (frgStart > 0 && oEl.value.substring(frgStart - 1, frgStart).match(woco.rgx)) frgStart--;
                        nValue = oEl.value.substring(0, frgStart);
                        nValue += woco.moz.match[woco.moz.mInt].trim();
                        nValue += oEl.value.substring(oEl.selectionEnd, oEl.value.length);
                        oEl.value = nValue;
                        cPos = frgStart + woco.moz.match[woco.moz.mInt].trim().length;
                        oEl.setSelectionRange(cPos, cPos);
                    } else oEl.setSelectionRange(oEl.selectionEnd, oEl.selectionEnd);
                    woco.moz.cancelEvent(e);
                    break;
                case 13:
                    woco.moz.cancelEvent(e);
                    break;
            }
            if (e.type != 'keyup') woco.moz.match = null;
        },
        complete: function(e, tKey) {
            if (tKey == '') woco.moz.match = woco.moz.match.sort();

            jc.maps.render.city(woco.moz.match);
            if (!woco.moz.match || tKey == '') return;
            var oEl = e.target;
            var swFrag = woco.moz.match[woco.moz.mInt].trim().substr(rngStart - frgStart + tKey.length);
            selEnd = selEnd || rngStart;
            nValue = oEl.value.substring(0, rngStart);
            nValue += tKey + swFrag;
            nValue += oEl.value.substring(selEnd, oEl.value.length);
            oEl.value = nValue;
            /*
            $('.'+ nValue).addClass('bg_color');
            */
            var cPos = rngStart + tKey.length;
            oEl.setSelectionRange(cPos, cPos + swFrag.length);
            woco.moz.cancelEvent(e);
        },
        cancelEvent: function(e) {
            e.stopPropagation();
            e.preventDefault();
        }
    }
};

/*	XDBC	*/
var xdbc = {
	env : {
		/*	ENVIRONMENT	*/
		init : function() {
			xdbc.env.os = (xdbc.env.win)?'win':((xdbc.env.mac)?'mac':((xdbc.env.linux)? 'linux':'other'));
			xdbc.env.br = (xdbc.env.ie)?'ie':((xdbc.env.ff)?'ff':((xdbc.env.sf)? 'sf':'other'));
		},
		mac : /mac/i.test(navigator.userAgent),
		win : /win|windows/i.test(navigator.userAgent),
		linux : /inux/i.test(navigator.userAgent),
		ie : /msie/i.test(navigator.userAgent),
		gk : /gecko/i.test(navigator.userAgent),
		ff : /firefox/i.test(navigator.userAgent),
		sf : /safari/i.test(navigator.userAgent),
		ax : typeof(ActiveXObject) == 'function',
		xhr : typeof(XMLHttpRequest) == 'function',
		cancelEvent : function() {if (event == null) return; event.cancelBubble = true; event.returnValue = null;}
	},
	debug		: false,
	escStr		: ['"=$34;', '\'=$39;', '<=$60;', '>=$62;'],
	flushQue	: function()	{xdbc.que = xdbc.load('<data xmlns:sys="sys.cloudo.com"></data>').documentElement;},
	createNode	: function(name){return !xdbc.env.xhr && !xdbc.env.sf? xdbc.que.parentNode.createNode(1, name, '') : xdbc.que.parentNode.createElement(name);},
	$			: function(s)	{return (typeof(s) == 'string')? document.getElementById(s):s;},
	uniqId : function (l) {
		var l = l || 16;
		var a = 'abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ-1234567890';
		var s = a.charAt((Math.random()*50));
		var d = new Date().valueOf();
		var k = Math.random().toString().slice(2);
		for (r=0; r<l; r++) s += a.charAt((Math.random()*256)%a.length);
		return s.slice(0,l);
	},
	get : {
		origo : function(el) {
			var oEl = document.body;
			var pos = ['absolute', 'relative', 'fixed'];
			while (el.nodeName) {
				if (pos.indexOf(el.currentStyle.position) > 0) {
					oEl = el;
					break;
				}
				if (el == oEl) break;
				el = el.parentNode;
			}
			return xdbc.get.dim(oEl);
		},
		is_visible : function(el) {
			var visible = true;
			try {
				while (el.nodeName) {
					if (el.currentStyle.display == 'none') {
						visible = false;
						break;
					}
					if (el == document.body.parentNode) break;
					el = el.parentNode;
				}
			} catch (e) {}
			return visible;
		},
		is_parent : function(el, pEl) {
			var test;
			while (el.parentNode) {
				if (el == pEl) {
					test = true;
					break;
				}
				el = el.parentNode;
			}
			return test;
		},
		scope : function(el, s) {
			while (el && el.scopeName != s) {
				el = el.parentNode;
			}
			return el;
		},
		el : function(el, p) {
			if (!p) {
				return (typeof(el) == 'string')? document.getElementById(el) : el ;
			}
			if (!el) return {};
			var o = p || {};
			var e = xdbc.get.children(el, '_id');
			for (var i=0, il=e.length; i<il; i++) {
				o[e[i].getAttribute('_id')] = e[i];
				if (e[i].getAttribute('_id') == '_toolbar') {
					var s = (e[i].getAttribute('_tsize') == '16')? 'tool16' : 'tool' ;
					o[e[i].getAttribute('_id')].tool = xdbc.get.children(e[i], 'nodeName', s);
				}
			}
			if (!p) return o;
		},
		srcIndex : function(el) {
			var i=0;
			while (el.previousSibling) {
				el = el.previousSibling;
				if (el.nodeType != 3) i++;
			}
			return i;
		},
		children : function(el, a, v) {
			el = xdbc.get.el(el);
			if (!el) return;
			var ar = new Array();
			var ac = el.getElementsByTagName('*');
			for (c=0, cl=ac.length; c<cl; c++) {
				if (v && a=='nodeName' && ac[c].nodeName.indexOf(':') > -1 && ac[c].nodeName.split(':')[1].toLowerCase() == v.toLowerCase()) {
					ar.push(ac[c]);
					continue;
				}
				if (v? (ac[c][a] == v || ac[c].getAttribute(a) == v) : (ac[c][a] || ac[c].getAttribute(a))) {
					ar.push(ac[c]);
				}
			}
			return ar;
		},
		child : function(el, a, v) {
			el = xdbc.get.el(el);
			if (!el) return;
			var ar = new Array();
			var ac = xdbc.get.el(el).getElementsByTagName('*');
			for (var c=0, cl=ac.length; c<cl; c++) {
				if (v && a == 'nodeName' && v && ac[c].nodeName.indexOf(':') > -1 && ac[c].nodeName.split(':')[1].toLowerCase() == v.toLowerCase()) {
					return ac[c];
				}
				if (v? (ac[c][a] == v || ac[c].getAttribute(a) == v) : (ac[c][a] || ac[c].getAttribute(a))) {
					return ac[c];
				}
			}
		},
		parent : function(el, a, v) {
			el = xdbc.get.el(el);
			try {
				while ((v && a=='nodeName' && el.nodeName && el.nodeName.indexOf(':') > -1)?
					(el.nodeName.toLowerCase().indexOf(':'+ v.toLowerCase()) == -1) :
					(v? (el && el[a] != v && el.getAttribute(a) != v) : (el && !el[a] && !el.getAttribute(a)))) {
					if (el == document.body.parentNode) return null;
					el = el.parentNode;
				}
			} catch (e) {
				el = null;
			}
			return el;
		},
		next : function(el, a, v) {
			el = xdbc.get.el(el);
			while (el && el.nextSibling) {
				el = el.nextSibling;
				if (el.nodeType == 1) {
					if ((v && a=='nodeName' && el.nodeName && el.nodeName.indexOf(':') > -1)?
						(el.nodeName.toLowerCase().indexOf(':'+ v.toLowerCase()) > -1) :
						(v? (el[a] == v || el.getAttribute(a) == v) : (el[a] || el.getAttribute(a)))) return el;
				}
			}
		},
		prev : function(el, a, v) {
			el = xdbc.get.el(el);
			while (el.previousSibling) {
				el = el.previousSibling;
				if (el.nodeType == 1) {
					if ((v && a=='nodeName' && el.nodeName && el.nodeName.indexOf(':') > -1)?
						(el.nodeName.toLowerCase().indexOf(':'+ v.toLowerCase()) > -1) :
						(v? (el[a] == v || el.getAttribute(a) == v) : (el[a] || el.getAttribute(a)))) return el;
				}
			}
		},
		sheet : function(id) {
			if (xdbc.env.ie) return document.styleSheets(id);
			for (var s=0, sl=document.styleSheets.length; s<sl; s++) {
				if (document.styleSheets[s].ownerNode.id == id) return document.styleSheets[s];
			}
		},
		dim : function(el, a, v) {
			if (!el) return {w:0, h:0, t:0, l:0, obj:el};
			a = a || 'nodeName';
			v = v || 'BODY';
			var p = {w:el.offsetWidth, h:el.offsetHeight, t:0, l:0, obj:el};
			while (el && el[a] != v && el.getAttribute(a) != v) {
				if (el == document.firstChild) return null;
				p.t += el.offsetTop - el.scrollTop;
				p.l += el.offsetLeft - el.scrollLeft;
				if (el.scrollWidth > el.offsetWidth) {
					p.w = Math.min(p.w, p.w-(p.w + p.l - el.offsetWidth - el.scrollLeft));
				}
				el = el.offsetParent;
			}
			return p;
		}
	},
	cookie : {
		del : function(cName) {
			var date = new Date();
			date.setYear(date.getFullYear() - 10);
			document.cookie = cName + '=; expires=' + date.toGMTString();
		},
		get : function(cName) {
			var aCookie = document.cookie.split('; ');
			for (var j=0; j<aCookie.length; j++) {
				var bCookie = aCookie[j].split('=');
				if (bCookie[0] == cName) return unescape(bCookie[1]).decrypt();
			}
		},
		set : function(cName, cValue) {
			if (!cValue) _cookie.Del(cName);
			var cValue = cValue.toString().encrypt();
			var date = new Date();
			date.setYear(date.getFullYear() + 1);
			document.cookie = cName + '=' + escape(cValue) + '; expires=' + date.toGMTString();
		}
	},
	init : function() {
		xdbc.env.init();
		xdbc.prefix();
		xdbc.xslDoc = new Array();
		xdbc.flushQue();
	},
	load : function(xSrc, xCallback) {
		if (xSrc.indexOf('<') > -1) {
			if (xdbc.env.ax) {
				var xDom = new ActiveXObject(xdbc.otype['DomDocument']);
				if (xDom.loadXML(xSrc)) return xDom;
			} else if (xdbc.env.gk) {
				var xDom = new DOMParser().parseFromString(xSrc, 'text/xml');
				if (xDom.firstChild.nodeName != 'parsererror') return xDom;
			}
			xdbc.ctrlXml(false, xSrc);
		} else {
			var xhr = {
				src		 : xSrc,
				callback : (typeof(xCallback) == 'function')? xCallback : null,
				async	 : (typeof(xCallback) != 'undefined'),
				http	 : xdbc.env.ax? new ActiveXObject(xdbc.otype['XmlHttp']) : new XMLHttpRequest()
			};
			xSrc += (xSrc.indexOf("?") > 0) ? "&" : "?";
			xhr.http.open('GET', xSrc + xdbc.uniqId(), xhr.async);
			xhr.http.send('');
			if (xhr.async) {
				if (xhr.http.readyState == 4) {
					xhr.dom = xdbc.ctrlXml(xhr.http.responseXML, xhr.src);
					if (xhr.callback) xhr.callback(xhr.dom);
					return xhr;
				} else {
					xhr.http.onreadystatechange = function() {
						if (xhr.http.readyState != 4) return;
						var rsp = (xhr.http.responseXML && xhr.http.responseXML.xml)? xhr.http.responseXML : xhr.http.responseText;
						xhr.dom = xdbc.ctrlXml(rsp, xhr.src);
						if (xhr.callback) xhr.callback(xhr.dom);
					}
					return xhr;
				}
			} else return xdbc.ctrlXml(xhr.http.responseXML, xhr.src);
		}
	},
	ctrlXml : function(xObj, xSrc) {
		xSrc = xSrc || '';
		if (!xdbc.env.ie && xObj == null || xObj.xml.indexOf('<parsererror') > 0) xObj = false;
		return (typeof(xObj) == 'object' && xObj.xml != '')? xObj : xdbc.doError('Invalid XML structure:\n'+ xSrc);
	},
	prefix : function() {
		xdbc.otype = new Array();
		var t = ['DomDocument', 'XmlHttp'];
		var b = ['Microsoft', 'MSXML', 'MSXML2', 'MSXML3'];
		for (n=0; n<t.length; n++) {
			for (p=0; p<b.length; p++) {
				try {
					new ActiveXObject(b[p] +'.'+ t[0]);
					xdbc.otype[t[n]] = b[p] +'.'+ t[n];
				}
				catch (e) {}
			}
		}
	},
	xslRam : function($src, $callback) {
		if (xdbc.xslDoc[$src]) return xdbc.xslDoc[$src];
		else {
			var callback = $callback || true;
			xdbc.xslDoc[$src] = xdbc.load($src, callback);
			return xdbc.xslDoc[$src];
		}
	},
	htmlChar : function(sFrag) {
		sFrag = sFrag.replace(/<\?xml.+?\?>/i, '');
		sFrag = sFrag.replace(/&quot;/ig, '"');
		sFrag = sFrag.replace(/&amp;/ig, '&');
		sFrag = sFrag.replace(/&lt;/ig, '<');
		sFrag = sFrag.replace(/&gt;/ig, '>');
		return sFrag;
	},
	transform : function($xml, $xsl, $el, $callback) {
		if (typeof($xml) == 'string') $xml = xdbc.load($xml, true);
		if (typeof($xsl) == 'string') $xsl = xdbc.xslRam($xsl);
		if (!$xml.dom && $xml.documentElement || $xml.xml) $xml = {dom:$xml}
		if (!$xsl.dom && $xsl.documentElement) $xsl = {dom:$xsl}
		if (!$xml.dom || !$xsl.dom) {
			setTimeout(function() {
				xdbc.transform($xml, $xsl, $el, $callback);
			}, 500);
			return;
		}
		xdbc.transform.recentXML = $xml.dom;
		$el = xdbc.get.el($el);
		if (xdbc.env.ax) {
			var frg = $xml.dom.transformNode($xsl.dom.documentElement);
			if (typeof($el) == 'function') $el(xdbc.htmlChar(frg));
			else $el.innerHTML = xdbc.htmlChar(frg);
		} else {
			var xslPrc = new XSLTProcessor();
			xslPrc.importStylesheet($xsl.dom);
			var frg = xdbc.htmlChar(xslPrc.transformToFragment($xml.dom, document).xml);
			
			if (typeof($el) == 'function') $el(frg);
			else {
				var rng = $el.ownerDocument.createRange();
				rng.setStartBefore($el);
				$el.innerHTML = '';
				$el.appendChild(rng.createContextualFragment(frg));
			}
		}
		if ($callback) {
			var $cb_param = ($callback.indexOf('(') > -1)? '' : '(xdbc.transform.recentXML);';
			try {eval($callback + $cb_param);}
			catch (e) {/* REPORT TO DOERROR? */};
		}
		$xml = $xsl = null;
	},
	escape : function($iStr) {
		for ($e=0; $e<xdbc.escStr.length; $e++) 
			$iStr = $iStr.replace(new RegExp(xdbc.escStr[$e].slice(0,1), 'g'), xdbc.escStr[$e].slice(2));
		return $iStr;
	},
	unescape : function(xml) {
		var xAll = xml.selectNodes('//*');
		for (x=0; x<xAll.length; x++) {
			if (!xAll[x].attributes) continue;
			for (a=0; a<xAll[x].attributes.length; a++) {
				xVal = unescape(xAll[x].attributes.item(a).value);
				xAll[x].attributes.item(a).value = xVal;
			}
		}
	},
	prepQue : function() {
		var qAll = xdbc.que.selectNodes('//*');
		for (var x=0; x<qAll.length; x++) {
			for (var a=0; a<qAll[x].attributes.length; a++) {
				var qNodeVal = qAll[x].attributes.item(a).value;
				qAll[x].attributes.item(a).value = (qAll[x].attributes.item(a).name.slice(0,1) == '_')?
													xdbc.escape(qNodeVal) : xdbc.normalize(qNodeVal);
			}
		}
	},
	addQue : function($pNode) {
		if (typeof($pNode) != 'object') return;
		var $pNode = $pNode.cloneNode(false);
		var $nAttr = $pNode.getAttribute('_selby');
		if ($nAttr) {
			for (var $a=1; $a<arguments.length; $a++) $nAttr = $nAttr.replace(new RegExp('\\$prm'+ ($a), 'g'), arguments[$a]);
			$pNode.setAttribute('_selby', $nAttr);
		}
		if (xdbc.token) $pNode.setAttribute('_token', xdbc.token);
		return xdbc.que.appendChild($pNode);
	},
	doError : function(xhr) {
		if (typeof(xhr) == 'object') {
			if (xhr.xml) xhr = {dom:xhr}
			with (xhr.dom.firstChild) {
				var code = getAttribute('code');
				var desc = getAttribute('description');
				var text = text;
			}
			xdbc.recentError = 'ERROR ['+ code +']: ';
			xdbc.recentError += desc +'\n-------\n';
			xdbc.recentError += text +'\n-------';
		} else {
			xdbc.recentError = '\n-------\n'+ xhr.replace(/>/g, '>\n') 
			xdbc.recentError +='\n-------';
		}
		if (xdbc.debug) return;	// alert(xdbc.recentError);
		if (typeof(xhr.callback) == 'function') xhr.callback();
	},
	exec : function() {
		if (!xdbc.que.childNodes.length) return (typeof(arguments[0]) == 'function')? arguments[0]() : xdbc.doError('Nothing qued!');
		//xdbc.prepQue();
		var xhr = {
			src		 : xdbc.path,
			callback : (typeof(arguments[0]) == 'function')? arguments[0] : null,
			async	 : (typeof(arguments[0]) == 'function' || typeof(arguments[0]) == 'boolean'),
			http	 : (xdbc.env.ax? new ActiveXObject(xdbc.otype['XmlHttp']) : new XMLHttpRequest())
		};
		xhr.http.open('POST', xdbc.path, xhr.async);
		xhr.http.send(xdbc.que.parentNode);
		xdbc.flushQue();
		if (xhr.async) {
			xhr.http.onreadystatechange = function() {
				if (xhr.http.readyState != 4) return;
				try {
					xhr.dom = xdbc.ctrlXml(xhr.http.responseXML.documentElement, xhr.src);
				} catch (e) {return; /*alert('Error reply:'+xhr.http.responseText);*/}
				if (!xhr.dom) return xdbc.doError(xhr.http.responseText);
				else if (xhr.dom.hasChildNodes() && xhr.dom.firstChild.nodeName == 'error') return xdbc.doError(xhr);
				//xdbc.unescape(xhr.dom);
				if (xhr.callback) xhr.callback(xhr.dom);
			}
			return xhr;
		}
		try {
			xhr.dom = xdbc.ctrlXml(xhr.http.responseXML.documentElement, xhr.src);
		} catch (e) {return; /*alert(xhr.http.responseText);*/}
		
		if (!xhr.dom) return xdbc.doError(xhr.http.responseText);
		else if (xhr.dom.hasChildNodes && xhr.dom.firstChild.nodeName == 'error') return xdbc.doError(xhr.dom);
		else {
			//xdbc.unescape(xhr.dom);
			return xhr.dom;
		}
	}
}

/*	DOM EXPLORERS	*/
var getScope	= xdbc.get.scope;
var getEl		= xdbc.get.el;
var getSrcIndex = xdbc.get.srcIndex;
var getChildren	= xdbc.get.children;
var getChild	= xdbc.get.child;
var getParent	= xdbc.get.parent;
var getNext		= xdbc.get.next;
var getPrevious	= xdbc.get.prev;
var getSheet	= xdbc.get.sheet;
var getDim		= xdbc.get.dim;

/*	COCKIE HANDLER	*/
var _cookie = {
	Del : xdbc.cookie.del,
	Get : xdbc.cookie.get,
	Set : xdbc.cookie.set
};

var _env = {
	mac : xdbc.env.mac,
	win : xdbc.env.win,
	linux : xdbc.env.linux,
	ie : xdbc.env.ie,
	gk : xdbc.env.gk,
	ff : xdbc.env.ff,
	sf : xdbc.env.sf,
	ax : xdbc.env.ax,
	xhr : xdbc.env.xhr,
	cancelEvent : xdbc.env.cancelEvent
};

/*	EXTENDS GECKO	*/
if (!xdbc.env.ie) {
	Node.prototype.setCapture =				function()		{};
	Node.prototype.releaseCapture =			function()		{};
	Node.prototype.fireEvent =				function(eType) {var e = document.createEvent('MouseEvents'); e.initEvent(eType.slice(2), true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); this.dispatchEvent(e);};
	Node.prototype.attachEvent =			function(e, h)	{this.addEventListener(e.slice(2), h, false);};
	Node.prototype.detachEvent =			function(e, h)	{this.removeEventListener(e.slice(2), h, false);};
	Document.prototype.selectNodes =		function(XPath, XNode) {if(!XNode) XNode = this; this.ns = this.createNSResolver(this.documentElement); this.qI = this.evaluate(XPath, XNode, this.ns, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); aResult = []; for(i=0; i<this.qI.snapshotLength; i++) aResult[i] = this.qI.snapshotItem(i); return aResult;};
	Document.prototype.selectSingleNode =	function(XPath, XNode) {if(!XNode) XNode = this; this.xI = this.selectNodes(XPath, XNode); return (this.xI.length > 0)? this.xI[0] : null ;};
	Element.prototype.selectNodes =			function(XPath) {return this.ownerDocument.selectNodes(XPath, this);};
	Element.prototype.selectSingleNode =	function(XPath) {return this.ownerDocument.selectSingleNode(XPath, this);};
	
	Node.prototype.__defineGetter__('scopeName',	function()		{var n = this.nodeName.toString();return (n.indexOf(':') > -1)? n.split(':')[0].toLowerCase() : 'HTML' ;});
	Node.prototype.__defineGetter__('xml',			function()		{return (new XMLSerializer()).serializeToString(this);});
	Node.prototype.__defineGetter__('outerHTML',	function()		{return (new XMLSerializer()).serializeToString(this);});
	Node.prototype.__defineSetter__('outerHTML',	function(s)		{var rng = this.ownerDocument.createRange(); rng.setStartBefore(this); cFrag = rng.createContextualFragment(s); this.parentNode.replaceChild(cFrag, this);});
	Node.prototype.__defineGetter__('text',			function()		{return this.textContent;});
	Node.prototype.__defineSetter__('text',			function(c)		{this.textContent = c;});
	Node.prototype.__defineGetter__('innerText',	function()		{return this.textContent;});
	Node.prototype.__defineSetter__('innerText',	function(c)		{this.textContent = c;});
	Node.prototype.__defineGetter__('currentStyle', function()		{return getComputedStyle(this, null);});
	Node.prototype.__defineSetter__('onreadystatechange', function(b) {this.readyState = 'complete'; this.onload = b;});
	/* Event */
	Event.prototype.__defineGetter__('event',		function()		{return this;});
	Event.prototype.__defineGetter__('clientY',		function()		{return this.pageY;});
	Event.prototype.__defineGetter__('clientX',		function()		{return this.pageX;});
	Event.prototype.__defineGetter__('offsetY',		function()		{return window.pageYOffset + this.pageY - xdbc.get.dim(this.srcElement).t;});
	Event.prototype.__defineGetter__('offsetX',		function()		{return window.pageXOffset + this.pageX - xdbc.get.dim(this.srcElement).l;});
	Event.prototype.__defineGetter__('srcElement',	function()		{var node = this.target; while (node && node.nodeType != 1) node = node.parentNode; return node;});
	Event.prototype.__defineSetter__('cancelBubble',function(b)		{if (b) this.stopPropagation();});
	Event.prototype.__defineSetter__('returnValue',	function(b)		{if (!b) this.preventDefault();});
	
	var e = ['contextmenu', 'click', 'dblclick', 'mouseover', 'mouseout', 'mousedown', 'mouseup', 'mousemove', 'keydown', 'keypress', 'keyup', 'focus', 'blur'];
	for (i=0; i<e.length; i++) document.addEventListener(e[i], function(e) {window.event=e;}, true);
}

/*	SHA1	*/
var sha1 = {
	hexcase : 0,
	chrsz : 8,
	sha1_kt : function(t) {return (t<20)? 1518500249 : (t<40)? 1859775393 : (t<60)? -1894007588 : -899497514;},
	rol : function(num,cnt) {return (num<<cnt)|(num>>>(32-cnt));},
	core_sha1 : function(x,len) {x[len>>5]|=0x80<<(24-len%32);x[((len+64>>9)<<4)+15]=len;var w=Array(80),a=1732584193,b=-271733879,c=-1732584194,d=271733878,e=-1009589776;for(var i=0;i<x.length;i+=16){var olda=a,oldb=b,oldc=c,oldd=d,olde=e;for(var j=0;j<80;j++){if(j<16)w[j]=x[i+j];else w[j]=sha1.rol(w[j-3]^w[j-8]^w[j-14]^w[j-16],1);t=sha1.safe_add(sha1.safe_add(sha1.rol(a,5),sha1.sha1_ft(j,b,c,d)),sha1.safe_add(sha1.safe_add(e,w[j]),sha1.sha1_kt(j)));e=d;d=c;c=sha1.rol(b,30);b=a;a=t;}a=sha1.safe_add(a,olda);b=sha1.safe_add(b,oldb);c=sha1.safe_add(c,oldc);d=sha1.safe_add(d,oldd);e=sha1.safe_add(e,olde);}return Array(a, b, c, d, e);},
	sha1_ft : function(t,b,c,d) {if(t<20) return (b&c)|((~b)&d);if(t<40) return b^c^d;if(t<60) return (b&c)|(b&d)|(c&d);return b^c^d;},
	safe_add : function(x,y){var lsw=(x&0xFFFF)+(y&0xFFFF);var msw=(x>>16)+(y>>16)+(lsw>>16);return (msw<<16)|(lsw&0xFFFF);},
	str2binb : function(str){var bin=Array();var mask=(1<<sha1.chrsz)-1;for(var i=0;i<str.length*sha1.chrsz;i+=sha1.chrsz)bin[i>>5]|=(str.charCodeAt(i/sha1.chrsz)&mask)<<(24-i%32);return bin;},
	binb2hex : function(binarray){var hex_tab=sha1.hexcase?"0123456789ABCDEF":"0123456789abcdef";var str="";for(var i=0;i<binarray.length*4;i++)str+=hex_tab.charAt((binarray[i>>2]>>((3-i%4)*8+4))&0xF)+hex_tab.charAt((binarray[i>>2]>>((3-i%4)*8))&0xF);return str;}
};

xdbc.init();

