requestedScripts = new Array();
cDiv="center-column-items";

try{
	if(documentContents){}
}catch(e){
	if(document.getElementById("print-tools")){
		document.getElementById("print-tools").innerHTML="<img src='/images/action_refresh_animated.gif' alt='loading' /> Show Printable Version";
		lci=setInterval("checkload()", 500);
	}
}
function getScript(p){
	for(i in requestedScripts){
		if (requestedScripts[i]==p){
			return true;
		}
	}
	var s,d=document;
	s=d.createElement('script');
	s.type='text/javascript';
	s.src=p;//+"?"+(Math.floor(Math.random()*1000)); //use for cache-busting during testing
	d.body.appendChild(s);
	requestedScripts.unshift(p);
	return true;
}

//load the appropriate scripts & elements
function checkload(){
	//if the print button is not live
	if(!document.getElementById("get-printable")){
		//check to see if this should be the printable page
		if(location.search.indexOf("printable=true")>=0){
			//if it's the printable page, keep loading scripts
			if (typeof($)=="function"){
				if(typeof(buildPrintVersion)=="function"){
					buildPrintVersion();
					clearInterval(lci);
				}else{
					getScript("/scripts/print-functions.js");
				}
			}else{
				getScript("/scripts/prototype.js");
			}
		} else {
			//if this is the normal page, just make the button
			createPrintButton(cDiv);
			clearInterval(lci);
		}
	} else {
		clearInterval(lci);
	}
}

//add the "Printable Version" button to the page
function createPrintButton(contentDiv){
	if(!document.getElementById("get-printable")){
		var s,q,d=document;
		q = getQuery();
		if(q.length>0){
			q+="&";
		}
		if(document.getElementById("print-tools")){
			document.getElementById("print-tools").innerHTML='<a id="get-printable" href="'+getPageURL()+'?'+q+'printable=true'+window.location.hash+'" target="_blank"><img alt="" src="/images/action_print.gif"/> Show Printable Version<a>';
			return true;
		}
	}
	return false;
}

function getQuery(){
	var qsParm=""; 
	var querystring = window.location.search.substring(1);
	var parms = querystring.split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			if(key != "printable"){
                  qsParm += parms[i];
            }
		}
	}
    return qsParm;
}

function getPageURL(){
	return window.location.protocol+"//"+window.location.host+window.location.pathname;
}