﻿//Ensure that this page always loads in the frame,unless it's being printed
setOnload=true
if(top.location.href==document.location.href){
	if(location.search.length>1 && (/(?:&|\?)print(?:&|$)/i.test(location.search))){
		onload=function(){window.print();self.close()}
		setOnload=false
		}
	else top.location.replace('/#url='+document.location.pathname+document.location.search)
	}
	
function setMailto(){
	var x,a=document.getElementsByTagName('a')
	for(x in a){
		if(/^mailto:/i.test(a[x].href))a[x].className+=' mailto'
		}
	}
	
hash={
	raw:function(){
		if(arguments.length>0){
			top.location.hash=arguments[0]
			}
		return top.location.hash
		},
	serialize:function(o){
		var re='#'
		for(x in o){re+=x+'='+o[x]+'&'}
		return re.substring(0,re.length-1)
		},
	extract:function(str){
		if(arguments.length<1){str=top.location.hash}
		var re={},m,m2,x=0
		m=str.match(/(?:^|#|&)(\w[\w\d]+)=([^&]*?)(?=&|$)/ig)
		for(x=0;x<m.length;x++){
			m2=/(?:#|&)(\w[\w\d]+)=(.*)$/.exec(m[x])
			re[m2[1]]=m2[2]
			}
		return re
		},	
	set:function(name,val,write){//broken on IE
		if(write==undefined){write=true}
		var l=top.location.hash
		if(l && l!='#'){
			lo=this.extract()//ex tract is broken, not anything else
			lo[name]=val
			for(x in lo){if(!lo[x]){delete lo[x--]}};
			if(write){
				top.location.hash=this.serialize(lo)
				return top.location.hash
				}
			return this.serialize(lo)
			}
		else{
			return top.location.hash=name+'='+val
			}
		}
	}

var baseTitle=top.document.title
if(setOnload)onload=function(){
	newtitle=document.title
	if(newtitle!=''){
		top.document.title=baseTitle+" : "+newtitle
		}
	hash.set('url',document.location.pathname+document.location.search)
	setMailto()
	writePrint()
	}

onunload=function(){
	top.document.title=baseTitle
	}

function writePrint(){
	var b=document.getElementsByTagName('body')[0]
	a=document.createElement('a')
	a.id='print'
	//a.href=""+location.pathname
	a.href="?print"
	a.target='_blank'
	a.innerHTML='[Printer Friendly]'
	b.appendChild(a)
	}

