﻿           /*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 © 2008
 ~@BBB@R(       BB~   /tC/  %@/		http://www.challenger.se
 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];};

/*	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;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) {var i = (!x)? n : x-n ;var p = (!x)? 0 : n ;return p + parseInt(Math.random()*i);};

/*	EXTENDS OBJECT	*/
Object.prototype._clone_	= function() {var t = {}; for (n in this) {t[n] = (typeof(this[n]) == 'object' && !this[n].nodeType)? ((this[n].length)? this[n].clone() : this[n]._clone_()) : this[n];} return t;};
Object.prototype._length_	= function() {var l=0; for (var n in this) {if (n.slice(0,1) == '_' && n.slice(-1) == '_') continue; l++;} return l;};

/*	ENVIRONMENT	*/
var _env = {
	ie : /msie/i.test(navigator.userAgent),		//	Internet Explorer
	gk : /gecko/i.test(navigator.userAgent),	//	Gecko based browsers
	ff : /firefox/i.test(navigator.userAgent),	//	Firefox browsers
	sf : /safari/i.test(navigator.userAgent),	//	Safari
	ax : typeof(ActiveXObject) == 'function',	//	Is ActiveXObject supported
	xhr : typeof(XMLHttpRequest) == 'function',	//	Is XMLHttpRequest supported
	cancelEvent : function() {event.cancelBubble = true; event.returnValue = null;}
};

/*	FIREBUG CONSOLE	(MIMICS) */
if (typeof(console) == 'undefined') {
	var console = {
		log : function(s) {
			alert(s);
		}
	};
}

/*	EXTENDS GECKO	*/
if (!_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 - getDim(this.srcElement).t;});
	Event.prototype.__defineGetter__('offsetX',		function()		{return window.pageXOffset + this.pageX - getDim(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);
}

/*	DOM EXPLORERS	*/
function $(s) {
	return (typeof(s) == 'string')? document.getElementById(s) : s ;
};
function getScope(el, s) {
	while (el && el.scopeName != s) {
		el = el.parentNode;
	}
	return el;
};
function getEl(el, p) {
	if (!el) return;
	var o = p || {};
	var e = getChildren(el, '_id');
	for (var i=0; i<e.length; i++) {
		o[e[i].getAttribute('_id')] = e[i];
		if (e[i].getAttribute('_id') == '_toolbar') {
			o[e[i].getAttribute('_id')].tool = getChildren(e[i], 'nodeName', 'tool');
		}
	}
	if (!p) return o;
};
function getSrcIndex($el) {
	var i=0;
	while ($el.previousSibling) {
		$el=$el.previousSibling;
		if ($el.nodeType != 3) i++;
	}
	return i;
};
function getChildren(el, a, v) {
	var ar = new Array();
	var ac = $(el).getElementsByTagName('*');
	for (c=0; c<ac.length; c++) {
		if (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;
};
function getChild(el, a, v) {
	var ar = new Array();
	var ac = $(el).getElementsByTagName('*');
	for (var c=0; c<ac.length; c++) {
		if (a=='nodeName' && 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];
		}
	}
};
function getParent(el, a, v) {
	var el = $(el);
	while ((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;
	}
	return el;
};
/*
		while (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;
		}
*/
function getNext(el, a, v) {
	var el = $(el);
	while (el.nextSibling) {
		el = el.nextSibling;
		if (el.nodeType == 1) {
			if (v? (el[a] == v || el.getAttribute(a) == v) : (el[a] || el.getAttribute(a))) return el;
		}
	}
};
function getPrevious(el, a, v) {
	var el = $(el);
	while (el.previousSibling) {
		el = el.previousSibling;
		if (el.nodeType == 1) {
			if (v? (el[a] == v || el.getAttribute(a) == v) : (el[a] || el.getAttribute(a))) return el;
		}
	}
};
function getSheet(id) {
	if (_env.ie) return document.styleSheets(id);
	for (var s=0; s<document.styleSheets.length; s++) {
		if (document.styleSheets[s].ownerNode.id == id) return document.styleSheets[s];
	}
};
function getDim(el, a, v) {
	var a = a || 'nodeName';
	var v = v || 'BODY';
	var point = {w:el.offsetWidth, h:el.offsetHeight, t:0, l:0}
	while (el && el[a] != v && el.getAttribute(a) != v) {
		if (el == document.firstChild) return null;
		point.t += el.offsetTop;
		point.l += el.offsetLeft;
		el = el.offsetParent;
	}
	point.obj = el;
	return point;
};

/*	COCKIE HANDLER	*/
var Cookie = {
	Delete : 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 (j=0; j<aCookie.length; j++) {
			bCookie = aCookie[j].split('=');
			if (bCookie[0] == cName) return unescape(bCookie[1]);
		}
	},
	Set : function(cName, cValue) {
		if (!cValue) Cookie.Delete(cName);
		var date = new Date();
		date.setYear(date.getFullYear() + 1);
		document.cookie = cName + '=' + escape(cValue) + '; expires=' + date.toGMTString();
	}
};

/*	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;}
};
