// x_core.js
// X v3.15.1, Cross-Browser DHTML Library from Cross-Browser.com
// Copyright (c) 2002,2003,2004 Michael Foster (mike@cross-browser.com)
// This library is distributed under the terms of the LGPL (gnu.org)

// Variables:
var xVersion='3.15.1',xNN4=false,xOp7=false,xOp5or6=false,xIE4Up=false,xIE4=false,xIE5=false,xUA=navigator.userAgent.toLowerCase();
if(window.opera){
  xOp7=(xUA.indexOf('opera 7')!=-1 || xUA.indexOf('opera/7')!=-1);
  if (!xOp7) xOp5or6=(xUA.indexOf('opera 5')!=-1 || xUA.indexOf('opera/5')!=-1 || xUA.indexOf('opera 6')!=-1 || xUA.indexOf('opera/6')!=-1);
}
else if (document.all) {
  xIE4Up=xUA.indexOf('msie')!=-1 && parseInt(navigator.appVersion)>=4;
  xIE4=xUA.indexOf('msie 4')!=-1;
  xIE5=xUA.indexOf('msie 5')!=-1;
}
// Object:
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 xDef() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

function xPageX(e) {
  if (!(e=xGetElementById(e))) return 0;
  var x = 0;
  while (e) {
    if (xDef(e.offsetLeft)) x += e.offsetLeft;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
  return x;
}
function xPageY(e) {
  if (!(e=xGetElementById(e))) return 0;
  var y = 0;
  while (e) {
    if (xDef(e.offsetTop)) y += e.offsetTop;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
//  if (xOp7) return y - document.body.offsetTop; // v3.14, temporary hack for opera bug 130324
  return y;
}
/* ************** End X functions ************** */



/* dock navigation panel functions */
function collapseSidebarPreference() {
	var hidenav = readCookie("hidenav");
		if (hidenav == 1 && xGetElementById('maintab'))
	{
		hideMe();
}
}
function toggle() {
	var expiry = new Date();
	expiry.setFullYear(expiry.getFullYear()+1);
	var xmt = xPageX('maintab');
	var cookieString;
	if (xmt > 50) {
		hideMe();
		cookieString = "hidenav=1; expires= " + expiry.toGMTString() + "; path=/";
	}
	else {
	 	showMe();
		cookieString = "hidenav=0; expires= " + expiry.toGMTString() + "; path=/";
	}
	
	document.cookie = cookieString;
}
function hideMe(){
	var col1o = xGetElementById('col1o');
	col1o.style.display = "none";
	var col2o = xGetElementById('col2o');
	col2o.style.width = "80%";
	col2o.style.left = "0px";
	var col2 = xGetElementById('col2');	
	col2.className = "close";
	col2.style.backgroundPosition = "0 0";
}

function showMe(){
	var col1o = xGetElementById('col1o');
	col1o.style.display = "block";
	var col2o = xGetElementById('col2o');
	col2o.style.width = "60%";
	col2o.style.left = "20%";
	var col2 = xGetElementById('col2');	
	//col2.style.background = "url(/images/layout/tab.gif) repeat-y";
	col2.className = "open";
	col2.style.backgroundPosition = "0 0";
}

function cancelbubble(evt) {
evt = (evt) ? evt : ((event) ? event : null);
if (evt) {evt.cancelBubble = true;
}
}

/* Highlighter - Toggle functionality Highlight - Alex at Sitepoint.com */

function highlighton() {
	document.styleSheets[0].disabled=false;
	var hiliteoff = xGetElementById('hiliteoff');
	hiliteoff.style.display = "inline";
	var hiliteon = xGetElementById('hiliteon');
	hiliteon.style.display = "none";
}

function highlightoff() {
	document.styleSheets[0].disabled=true;
	var hiliteoff = xGetElementById('hiliteoff');
	hiliteoff.style.display = "none";
	var hiliteon = xGetElementById('hiliteon');
	hiliteon.style.display = "inline";
}

/* http://www.kryogenix.org/code/browser/searchhi/ */

function highlightWord(node,word) {
	// Iterate into this nodes childNodes
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			highlightWord(node.childNodes[hi_cn],word);
		}
	}
	
	// And do this node itself
	if (node.nodeType == 3) { // text node
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			if (pn.className != "searchword") {
				// word has not already been highlighted!
				nv = node.nodeValue;
				ni = tempNodeVal.indexOf(tempWordVal);
				// Create a load of replacement nodes
				before = document.createTextNode(nv.substr(0,ni));
				docWordVal = nv.substr(ni,word.length);
				after = document.createTextNode(nv.substr(ni+word.length));
				hiwordtext = document.createTextNode(docWordVal);
				hiword = document.createElement("span");
				hiword.className = "searchword";
				hiword.appendChild(hiwordtext);
				pn.insertBefore(before,node);
				pn.insertBefore(hiword,node);
				pn.insertBefore(after,node);
				pn.removeChild(node);
			}
		}
	}
}

function googleSearchHighlight() {
	if (!document.createElement) return;
	ref = document.referrer;
	if (ref.indexOf('?') == -1) return;
	qs = ref.substr(ref.indexOf('?')+1);
	qsa = qs.split('&');
	for (i=0;i<qsa.length;i++) {
		qsip = qsa[i].split('=');
	        if (qsip.length == 1) continue;
        	if (qsip[0] == 'q' || qsip[0] == 'p') { // q= for Google, p= for Yahoo
			words = unescape(qsip[1].replace(/\+/g,' ')).split(/\s+/);
	                for (w=0;w<words.length;w++) {
				highlightWord(document.getElementsByTagName("body")[0],words[w]);
                	}
	        }
	}
	highlighton();
}

