
var dom = document.getElementById;
var ie = document.all;

var alphaBase = '@.comukeairtn-slpdhgbyfvwxzqj_1234567890 ';
var encKey = 'c+pb$5UkX%1sZvy9m37ni^h0qr2f6xeN!CD*BVFQJPw=';


function addEvent(obj, evnt, func) {
	if (obj.addEventListener)	// w3c
		obj.addEventListener(evnt, eval(func), false);
	else if (window.attachEvent)	// ie
		obj.attachEvent('on' + evnt, eval(func));
}

function bookmarkPage() {
	if (window.external)
		window.external.AddFavorite(document.location, document.title);
	else
		alert('Sorry! Your browser doesn\'t support this function.');
}

function changeStyle(obj, attr, value) {
	if (obj != null)
		eval('obj.style.' + attr + ' = \'' + value + '\';');
}

function changeStyleById(id, attr, value) {
	var o;
	if ((o = findObj(id)) != null)
		eval('o.style.' + attr + ' = \'' + value + '\';');
}

function findObj(id) {
    var o;
    if (id != null)
        if (dom && (o = document.getElementById(id)) != null)
			return o;
		else
			return MM_findObj(id); //fall-back
}

function generateHash(seed) {
	var s;
	seed = seed.toLowerCase();
	s = textScramble(seed, alphaBase, encKey);
	//alert(s);
	document.write(s);
}

function generateMailer(hash, linkText, cssClass) {
	var s;
	if (linkText == null || linkText == '')
		linkText = textScramble(hash, encKey, alphaBase);
	s = '<a hr'+'ef="ma'+'ilto'+':' + textScramble(hash, encKey, alphaBase) + '"';
	if (cssClass != null && cssClass != '')
		s += ' class="' + cssClass + '"';
	s += '>' + linkText;
	s += '</a>';
	//alert(s);
	document.write(s);
}

function generateText(hash) {
	var s;
	s = textScramble(hash, encKey, alphaBase);
	//alert(s);
	document.write(s);
}

function mapWindow(pc, msg) {
	if (msg)
		alert('You are now being taken to the Ordnance Survey Get-a-map service.\nUse of this service is subject to the terms and conditions found on the website.')
	var w = 740;
	var h = 520;
	var l = Math.round(0.5 * (screen.availWidth - w));
	var t = Math.round(0.5 * (screen.availHeight - h)) - 20;
	pc = escape(pc).toUpperCase()
	var win = window.open('http://getamap.ordnancesurvey.co.uk/getamap/frames.htm?mapAction=gaz&gazName=pc&gazString=' + pc, 'gam', 'left='+l+',screenX='+l+',top='+t+',screenY='+t+',width='+w+',height='+h+',status,scrolling=no');
	win.focus();
	return false;
return false;
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function newWindow(tag) {
	var win;
	win = window.open(tag.href);
	win.focus();
	return false;
}

function printPage(close) {
	window.print();
	if (close)
		window.close();
	return false;
}

function printWindow(tag) {
	var win;
	win = window.open(tag.href, 'printPage', 'scrollbars=1,status=1,width=700,height=700');
	win.focus();
	return false;
}

function textScramble(seed, base, key) {
	var hash = '';
	var i;
	var idx;
	var s;
	for (i = 0; i < seed.length; i++) {
		s = seed.charAt(i);
		idx = base.indexOf(s);
		hash += ((idx == -1) ? s : key.charAt(idx));
	}
	return hash;
}
