
var site_root = '/';
var cursor_type = (document.all) ? 'hand' : 'pointer';
var content_div;
var banner_div;
var body_tag;

//	Browser detection
var w3c = (document.getElementById) ? true : false;
var ie = (document.all && !w3c) ? true : false;
var ns4 = (document.layers) ? true : false;





function init () {
	content_div = document.getElementById('content');
	banner_div = document.getElementById('banner');
	body_tag = document.getElementsByTagName('BODY')[0];
	
	createFontResizer();
	setPDFlinks();
	logoPress();

	var font_size = getFontCookie();
	if (font_size != null) {
		body_tag.className = font_size;
	}
}

if (w3c) { 	window.onload=init; }


function createFontResizer() {
	var h1_tag = document.getElementsByTagName('H1')[0];
	var size_imgs = new Array (3);
		
	if (h1_tag && banner_div) {
		//alert('Yeah mon!');
		fontResizer_div = document.createElement('DIV');
		fontResizer_div.id = 'fontResizer';
		
		fontsize_img = document.createElement('IMG');
		fontsize_img.src = site_root + 'images/font_size.gif';
		
		fontResizer_div.appendChild(fontsize_img);
		
		for (var aa=0; aa<size_imgs.length; aa++) {
			size_imgs[aa] = document.createElement('IMG');
			size_imgs[aa].src = site_root + 'images/font_size_' + (aa+1) + '.gif';
			size_imgs[aa].assoc_classname = 'larger' + (aa+1);
			size_imgs[aa].onclick = function () {
				body_tag.className = this.assoc_classname;
				setFontCookie(this.assoc_classname)
			}
			size_imgs[aa].onmouseover = function () {
				this.style.cursor = cursor_type;
			}
			fontResizer_div.appendChild(size_imgs[aa]);
		}
		banner_div.insertBefore(fontResizer_div,h1_tag);
	}
}

function setFontCookie(class_name) {
	
	//format expiry date
	font_date = new Date();
	font_date.setTime(font_date.getTime() + ( 365 *24*60*60*1000));

	if (class_name == 'larger1') {
		font_date.setTime(0); //	Deletes the cookie
	}
	document.cookie = 'fontSize=' + class_name
		+ '; expires=' + font_date.toGMTString() 
		+ '; path=/';
}


function getFontCookie() {
	font_cookie = null;	
	
	if (document.cookie && document.cookie.indexOf('fontSize')!=-1) {
		font_cookie = document.cookie.split('fontSize=');
		font_cookie = font_cookie[1].split(';');
	}
	// alert(font_cookie);
	
	return font_cookie;
}

function logoPress() {
	var logo_link = document.getElementById('logoLink');
	var logo_img = logo_link.getElementsByTagName('IMG')[0];
	
	if (logo_img) {
		logo_link.onmousedown = function() {
			logo_img.src = site_root + 'images/aapm_down.gif';
		}
		logo_link.onmouseup = function() {
			logo_img.src = site_root + 'images/aapm.gif';
		}
	}
}



function setPDFlinks() {
	var all_links = document.getElementsByTagName('A');
	var all_areas = document.getElementsByTagName('AREA');
	
	for (var aa=0; aa<all_areas.length; aa++) {		
		if (all_areas[aa].target.toLowerCase() == 'pdflink') {		
			all_areas[aa].onclick = function() {
				popPDF(this);
				return false;
			}
		}
	}
	
	for (var bb=0; bb<all_links.length; bb++) {		
		if (all_links[bb].target.toLowerCase() == 'pdflink') {		
			all_links[bb].onclick = function() {
				popPDF(this);
				return false;
			}
		}
	}
}

//	Popup window code
var page_position = (parseInt(navigator.appVersion) > 3) ? 'left=0,top=0,screenX=0,screenY=0,' : "";
var popup_features = 'menubar=yes,status=yes,scrollbars=yes,resizable=yes,width=785,height=550';

function popupWindow(url, target, features) {
	if (isUndefined(features)) {
		features = popup_features;
	}
	if (isUndefined(target)) {
		target = '_blank';
	}
	var the_window = window.open(url, target, page_position+features);
	the_window.focus();
	return the_window;
}

function linkPopup(src, features) {
	return popupWindow(src.getAttribute('href'),src.getAttribute('target') || '_blank',features);
}//	End Popup window code

//	Utility function [currently used in popupWindow()]
function isUndefined(v) { 
	//	Returns true if [v] is not defined, false otherwise
	//	IE 5.0 does not support the undefined keyword, so we cannot 
	//	do a direct comparison such as v===undefined.
	var undef;
	return v===undef;
}


//	Pop up a PDF!!!
var the_pdf;
function popPDF(src,features) {
	the_pdf = src;
	var pdf_target = src.getAttribute('target') || 'PDFlink';
	if (isUndefined(features)) {
		features = 'menubar=yes,status=yes,scrollbars=yes,resizable=yes,width=750,height=485';
	}
	//alert(the_target);
	return popupWindow(site_root + 'pdf/pdf_launcher.html',pdf_target,features);
}

function doPDF(win_ref) {
	win_ref.location.href = the_pdf;
	//location.href=location.search.substring(1);
}



function doPrint() {
	if (window.print) {
		window.print();
	} else {
		alert('To print this page, click on the File menu and choose Print \nor press Cntrl + P on your keyboard.');
	}
}











