// for xLib
var xOp7Up,xOp6Dn,xIE4Up,xIE4,xIE5,xNN4,xUA = navigator.userAgent.toLowerCase();
if(window.opera){ var i=xUA.indexOf('opera'); if(i!=-1){var v=parseInt(xUA.charAt(i+6));xOp7Up=v>=7;xOp6Dn=v<7;	}
}else if(navigator.vendor!='KDE' && document.all && xUA.indexOf('msie')!=-1){xIE4Up=parseFloat(navigator.appVersion)>=4;xIE4=xUA.indexOf('msie 4')!=-1;xIE5=xUA.indexOf('msie 5')!=-1;
}else if(document.layers){ xNN4=true;}
xMac=xUA.indexOf('mac')!=-1;

//////////////////////////////////////////////
function _absLeft(obj) {
	return (obj.offsetParent)? obj.offsetLeft+_absLeft(obj.offsetParent) : obj.offsetLeft;
}
//////////////////////////////////////////////
function _absTop(obj) {
	return (obj.offsetParent)? obj.offsetTop+_absTop(obj.offsetParent) : obj.offsetTop;
}

/////////////////////////////////////////////////////
function _pagePosX(e){ // incl pagescroll
  if (document.all){
 	var off = (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : 0;
	off += (document.body.scrollLeft) ? document.body.scrollLeft : 0;
   	return window.event.clientX + off;
  }else
    return e.clientX + window.scrollX;
}
/////////////////////////////////////////////////////
function _pagePosY(e){ // incl pagescroll
	if (document.all){
		var off = (document.documentElement.scrollTop) ? document.documentElement.scrollTop : 0;
		off += (document.body.scrollTop) ? document.body.scrollTop : 0;
	   	return window.event.clientY + off;
	}else
		return e.clientY + window.scrollY;
}

/////////////////////////////////////////////////////
//----- might be a better version but this is pretty solid
//----- (c)GPL, apv
function getRefQuery () {
  var Refer = document.referrer
  if ( ! Refer ) return false
  q = Refer.match(/(q(([^=]*)|kw)?|p)=([^"&;]+)/)
  if ( ! q ) return false

//----- no cross-script hacking, please
  var qry = unescape( q[ ( q.length - 1 ) ] )
  qry = qry.replace(/</g, '&lt;')
  qry = qry.replace(/>/g, '&gt;')
  qry = qry.replace(/\+/g, ' ')
  if ( ! qry.match(/\w/) ) return false
  return qry
}
//----- I like javascript now
/////////////////////////////////////////////////////


/////////////////////////////////////////////////////
// onload patch for macIE5 from Simon Willison ::: http://simon.incutio.com/archive/2004/05/26/ 
/////////////////////////////////////////////////////
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


/////////////////////////////////////////////////////
// xAddEventListener, Copyright 2001-2005 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
/////////////////////////////////////////////////////
function xGetElementById(e){
	if(typeof(e)!='string')
		return e;
	if(document.getElementById)
		e=document.getElementById(e);
	else if(document.all)
		e=document.all[e];
	else e=null;
		return e;
}

/////////////////////////////////////////////////////
function xAddEventListener(e,eT,eL,cap){
  if(!(e=xGetElementById(e))) return;
  eT=eT.toLowerCase();
  if((!xIE4Up && !xOp7Up) && e==window) {
    if(eT=='resize') { window.xPCW=xClientWidth(); window.xPCH=xClientHeight(); window.xREL=eL; xResizeEvent(); return; }
    if(eT=='scroll') { window.xPSL=xScrollLeft(); window.xPST=xScrollTop(); window.xSEL=eL; xScrollEvent(); return; }
  }
  var eh='e.on'+eT+'=eL';
  if(e.addEventListener) e.addEventListener(eT,eL,cap);
  else if(e.attachEvent) e.attachEvent('on'+eT,eL);
  else eval(eh);
}
// called only from the above
/////////////////////////////////////////////////////
function xResizeEvent(){
  if (window.xREL) setTimeout('xResizeEvent()', 250);
  var cw = xClientWidth(), ch = xClientHeight();
  if (window.xPCW != cw || window.xPCH != ch) { window.xPCW = cw; window.xPCH = ch; if (window.xREL) window.xREL(); }
}
/////////////////////////////////////////////////////
function xScrollEvent(){
  if (window.xSEL) setTimeout('xScrollEvent()', 250);
  var sl = xScrollLeft(), st = xScrollTop();
  if (window.xPSL != sl || window.xPST != st) { window.xPSL = sl; window.xPST = st; if (window.xSEL) window.xSEL(); }
}

/////////////////////////////////////////////////////
function xClientWidth(){
	var w=0;
	if(xOp6Dn) 	w=window.innerWidth;
	else if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientWidth)
		w=document.documentElement.clientWidth;
	else if(document.body && document.body.clientWidth)	w=document.body.clientWidth;
	else if(xDef(window.innerWidth,window.innerHeight,document.height)) {
		w=window.innerWidth;
		if(document.height>window.innerHeight) w-=16;
	}
	return w;
}
/////////////////////////////////////////////////////
function xClientHeight(){
	var h=0;
	if(xOp6Dn) h=window.innerHeight;
	else if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientHeight)
		h=document.documentElement.clientHeight;
	else if(document.body && document.body.clientHeight)	h=document.body.clientHeight;
	else if(xDef(window.innerWidth,window.innerHeight,document.width)) {
		h=window.innerHeight;
		if(document.width>window.innerWidth) h-=16;
	}
	return h;
}


// xRemoveEventListener, Copyright 2001-2005 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

/////////////////////////////////////////////////////
function xRemoveEventListener(e,eT,eL,cap){
  if(!(e=xGetElementById(e))) return;
  eT=eT.toLowerCase();
  if((!xIE4Up && !xOp7Up) && e==window) {
    if(eT=='resize') { window.xREL=null; return; }
    if(eT=='scroll') { window.xSEL=null; return; }
  }
  var eh='e.on'+eT+'=null';
  if(e.removeEventListener) e.removeEventListener(eT,eL,cap);
  else if(e.detachEvent) e.detachEvent('on'+eT,eL);
  else eval(eh);
}
// xPreventDefault, Copyright 2004,2005 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

/////////////////////////////////////////////////////
function xPreventDefault(e){
  if (e && e.preventDefault) e.preventDefault();
  else if (window.event) window.event.returnValue = false;
}


/////////////////////////////////////////////////////
//http://xmlrpc-epi.sourceforge.net/main.php?t=php_api#output_options
//http://jibbering.com/2002/4/httprequest.html
//http://www.devx.com/webdev/Article/22338/0/page/4
//http://www.zend.com/php5/articles/php5-SOAP.php?article=php5-SOAP&kind=php5&id=5085&open=1&anc=0&view=1 (kommentare)

/////////////////////////////////////////////////////
function asyncGetData(target, url, post, callBack, headers){
	var xmlhttp = _XMLHttpRequest_init();
	var typ = (typeof(post)=="undefined") ? "GET" : post; 
	xmlhttp.open(typ, url, true);
	_sendHeaders(xmlhttp, headers)
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState != 4)
			return;
		callBack(target, xmlhttp.responseText, xmlhttp );
	}
	xmlhttp.send(post);
}

/////////////////////////////////////////////////////
function _sendHeaders(xmlhttp, headers){
	if(headers){
		for(var header in headers){
			xmlhttp.setRequestHeader(header, headers[header] );
		}
	}
}
/////////////////////////////////////////////////////
function _XMLHttpRequest_init() {
	var A = null;
	var success = false;
	var MS_PROGIDS = ['MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP'];
	for (var i=0;i < MS_PROGIDS.length && !success; i++) {
	    try {
		A = new ActiveXObject(MS_PROGIDS[i]);
		success = true;
	    } catch (e) { A=null;}
	}
	if(!A && typeof XMLHttpRequest != "undefined")
		A = new XMLHttpRequest();
	if (!A)
		alert("Could not create connection object.");
	return A;
}


/////////////////////////////////////////////////////
/*
HTMLElement Prototyping in KHTML and WebCore
Copyright (C) 2005  Jason Davis, http://www.jasonkarldavis.com
Additional thanks to Brothercake, http://www.brothercake.com

This code is licensed under the LGPL:
	http://www.gnu.org/licenses/lgpl.html
*/

if (navigator.vendor == "Apple Computer, Inc." || navigator.vendor == "KDE") { // WebCore/KHTML
	(function(c) {
		for (var i in c)
			window["HTML" + i + "Element"] = document.createElement(c[i]).constructor;
	})({
		Html: "html", Head: "head", Link: "link", Title: "title", Meta: "meta",
		Base: "base", IsIndex: "isindex", Style: "style", Body: "body", Form: "form",
		Select: "select", OptGroup: "optgroup", Option: "option", Input: "input",
		TextArea: "textarea", Button: "button", Label: "label", FieldSet: "fieldset",
		Legend: "legend", UList: "ul", OList: "ol", DList: "dl", Directory: "dir",
		Menu: "menu", LI: "li", Div: "div", Paragraph: "p", Heading: "h1", Quote: "q",
		Pre: "pre", BR: "br", BaseFont: "basefont", Font: "font", HR: "hr", Mod: "ins",
		Anchor: "a", Image: "img", Object: "object", Param: "param", Applet: "applet",
		Map: "map", Area: "area", Script: "script", Table: "table", TableCaption: "caption",
		TableCol: "col", TableSection: "tbody", TableRow: "tr", TableCell: "td",
		FrameSet: "frameset", Frame: "frame", IFrame: "iframe"
	});

	function HTMLElement() {}
	HTMLElement.prototype     = HTMLHtmlElement.__proto__.__proto__;	
	var HTMLDocument          = document.constructor;
	var HTMLCollection        = document.links.constructor;
	var HTMLOptionsCollection = document.createElement("select").options.constructor;
	var Text                  = document.createTextNode("").constructor;
	var Node                  = Text;
}
/////////////////////////////////////////////////////
if(typeof HTMLElement!="undefined" && ! HTMLElement.prototype.insertAdjacentElement){
	HTMLElement.prototype.insertAdjacentHTML = function (sWhere, sHTML) {
	   var df;   // : DocumentFragment
	   var r = this.ownerDocument.createRange();

	   switch (String(sWhere).toLowerCase()) {  // convert to string and unify case
	      case "beforebegin":
		 r.setStartBefore(this);
		 df = r.createContextualFragment(sHTML);
		 this.parentNode.insertBefore(df, this);
		 break;
	      case "afterbegin":
		 r.selectNodeContents(this);
		 r.collapse(true);
		 df = r.createContextualFragment(sHTML);
		 this.insertBefore(df, this.firstChild);
		 break;
	      case "beforeend":
		 r.selectNodeContents(this);
		 r.collapse(false);
		 df = r.createContextualFragment(sHTML);
		 this.appendChild(df);
		 break;
	      case "afterend":
		 r.setStartAfter(this);
		 df = r.createContextualFragment(sHTML);
		 this.parentNode.insertBefore(df, this.nextSibling);
		 break;
	   }   
	};
}
/////////////////////////////////////////////////////
