
/*******************************************************************************************
 * initPrintMe (call after document load)
 *******************************************************************************************/

	function initPrintMe () {
		if(!document.getElementById)return false;

		var elem = document.getElementById("printLink");
		if(elem){
			elem.style.visibility = "visible";
		}
	}

	addLoadEvent(initPrintMe);

/*******************************************************************************************
 * printMe
 * Try to run the "print" function, otherwise tell the user how to print correctly.
 * Example:	printMe();
 *******************************************************************************************/


	function printMe () {
		try {
			print();
		} catch(exception){
			alert("To print this page, click file and\n select 'Print' or 'Print Preview'");
		}
	}



/*******************************************************************************************
 * blurCheck & focusCheck
 * Focuses the text within the site search and telephone numer search input fields
 *******************************************************************************************/

	function blurCheck (frm,str) {
		if((frm.value=='')&&(frm.value!=str))frm.value=str;
	}

	function focusCheck (frm) {
		frm.value='';
	}


/*******************************************************************************************
 * nicely add an onload event
 * http://simon.incutio.com/archive/2004/05/26/addLoadEvent
 *******************************************************************************************/
	function addLoadEvent(func) {
  		var oldonload = window.onload;
  		if (typeof window.onload != 'function') {
    		window.onload = func;
  		} else {
    		window.onload = function() {
      		if (oldonload) {
       			oldonload();
      		}
    	  	func();
    		}
  		}
	}


/*******************************************************************************************
 * cssjs
 * Written by Christian Heilmann (http://icant.co.uk)
 * Eases the dynamic application of CSS classes via DOM
 * Parameters: action a, object o and class names c1 and c2 (c2 optional)
 * Actions: swap exchanges c1 and c2 in object o
 *			add adds class c1 to object o
 *			remove removes class c1 from object o
 *			check tests if class c1 is applied to object o
 * Example:	cssjs('swap',document.getElementById('foo'),'bar','baz');
 *******************************************************************************************/

function cssjs (a, o, c1, c2) {
	switch (a) {
		case 'swap':
			o.className = !cssjs('check', o, c1) ? o.className.replace(c2, c1) : o.className.replace(c1, c2);
			break;
		case 'add':
			if (!o.className)
				o.className = '';
			if (!cssjs('check', o, c1)) {
				o.className += o.className ? ' '+c1 : c1;
			}
			break;
		case 'remove':
			var rep = o.className.match(' '+c1) ? ' '+c1 : c1;
			o.className = o.className.replace(rep, '');
			break;
		case 'check':
			if (!o.className)
				return(false);
			return(new RegExp('\\b'+c1+'\\b').test(o.className));
			break;
	}
	return(true);
}

/*******************************************************************************************
 * Take a link reference and bind a function to the onclick/onkeypress events
 *******************************************************************************************/

function addLinkEvent(link, func) {

	try {
		link.style.cursor = 'pointer';
	} catch (e) {
		try {
			link.style.cursor = 'hand';
		} catch (e) {
		}
	}

	link.tabIndex = 0;

	link.onclick = func;

	link.onkeypress = function (e) {
			var keyCode = e ? e.which : window.event.keyCode;
			if (keyCode != 13 && keyCode != 32) return true;
			this.onclick();
			return false;
		};

}

/*******************************************************************************************
 * addCssRule
 * Originally written by Craig Francis (http://craigfrancis.co.uk)
 * Add a CSS rule to the document - includes support for xhtml+xml
 * Example:	addCssRule('#itemId { position: absolute; left: -5000px; }');
 *******************************************************************************************/

	function addCssRule(cssRule) {

		var styleElement;
		var headRef;

		this.useXmlMethods = (document.contentType && document.contentType.indexOf('xml') > -1);
		if (this.useXmlMethods) {

			styleElement = createElement('style');
			styleElement.setAttribute('type', 'text/css');
			styleElement.appendChild(document.createTextNode(cssRule));

			headRef = document.getElementsByTagName('head');
			if (headRef[0]) {
				headRef[0].appendChild(styleElement);
			}

		} else {

			document.write ('<style type="text\/css"> ' + cssRule + ' <\/style>');

		}

	}
	
	
 /*******************************************************************************************
  * externalLinks
  * Fix for new window link - just replace target="_blank" with rel="external"
 *******************************************************************************************/
	
	function externalLinks() {
        if (!document.getElementsByTagName) return;
        var anchors = document.getElementsByTagName("a");
        for (var i=0; i<anchors.length; i++) {
            var anchor = anchors[i];
            if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
                anchor.target = "_blank";
         }
    }
    
    addLoadEvent(externalLinks);