/*
	GO TO URL
	Implement the following function with tag written as so:
	<a href="#" onclick="backToTop(); return false">Back to Top</a>
*/

function goToUrl(url) {
	if (url != "") {
		location = url;
	}
}

/*
	RELOAD
*/
function reload() {
	document.location.reload()
}

/*
	WINDOW POP UP CODE
	Implement the following function with tag written as so:
	<a href="http://www.example.com" onclick="linkPopUp(this);  return false;">
	Code courtesy of K (http://v2studio.com/k/code/lib/).
*/

var _POPUP_FEATURES = 'location=0, statusbar=0, menubar=0, resizable=1, scrollbars=1, width=800, height=600';

function isUndefined(a) { return typeof a == 'undefined' }

function rawPopUp(url, target, features) {
	if (isUndefined(features)) {
		features = _POPUP_FEATURES;
	}
	if (isUndefined(target)) {
		target = '_blank';
	}
	var theWindow =
	window.open(url, target, features);
	theWindow.focus();
	return theWindow;
}

function linkPopUp(src, features) {
	return rawPopUp(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}

/*
	BACK TO TOP
	Implement the following function with tag written as so:
	<a href="#" onclick="backToTop(); return false">Back to Top</a>
*/

function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;
    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }
    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }
    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;
    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));
    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));
    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 100);
    }
}

/*
	TOGGLE EXPANDABLE/COLLAPSIBLE TEXT
	Used for expandable/collapsible content items used in site.
	For the following to work the html code needs to be as follows:
	
	<dl id="expandable_content">
		<dt>
			<a href="#">title of content1</a>
		</dt>
		<dd style="display:none;" id="a1">
			<p>content1 content1 content1</p>
		</dd>
		<dt>
			<a href="#">title of content2</a>
		</dt>
		<dd style="display:none;" id="a2">
			<p>content2 content2 content2</p>
		</dd>
	</dl>
*/

function addOnloadEvent(event) {
    var init = window.onload;
    window.onload = (typeof init != 'function') ? event : function() { init(); event(); };
}

function toggleContent(title,content) {
    if (content.style['display'] == 'block') {
        content.style['display'] = 'none';
        title.className = null;
    } else {
        content.style['display'] = 'block';
        title.className = 'on';
    }
}

function initExpContent() {
    if ( document.getElementById('expandable_content') ) {
        var ddELs = document.getElementById('expandable_content').getElementsByTagName('dd');
        for (var i=0; i<ddELs.length; i++) {
            ddELs[i].style['display'] = 'none';
            var aELs = document.getElementById('expandable_content').getElementsByTagName('dt')[i].getElementsByTagName('A');
            aELs[0].href = aELs[0].href.replace(/#(.)*/g,'');
            aELs[0].content = ddELs[i];
            aELs[0].onclick = function() {
                toggleContent(this, this.content);
                return false;
            }
        }
     }
}

addOnloadEvent(initExpContent);

/*
	FOCUSING ON ITEMS
	Implement the following function with tag written as so:
	<a href="#" onclick="setFocus('itemId');"></a>
*/

function setFocus(focusItem) {
	document.getElementById(focusItem).focus()
}

function loseFocus(focusItem) {
	document.getElementById(focusItem).blur()
}
  
  
