var newWin = null;

function popWinSize (url, x,y,scroll, tool, menu) {
	var winWidth = 'width=' + x;
	var winHeight = 'height=' + y;
	var winFeatures=winHeight + ',' + winWidth + ',' + 'scrollbars=yes, toolbar=yes';
	var xPos = 5; var yPos = 5;
	newWin=window.open(url, "popup", winFeatures);
	newWin.moveTo(xPos, yPos);
	newWin.focus();
}

function popWindow(url, windowType) {
	var xPos, yPos;
	switch (windowType) {
		case 'require':
			winFeatures='height=500,width=600,scrollbars=yes'; xPos = 20; yPos = 20;
		break;
		case 'criteria':
			winFeatures='height=450,width=668,menubar=yes,scrollbars=yes'; xPos = 20; yPos = 20;
		break;
		case 'resource':
			if (screen.width > 810)
				winFeatures='height=580,width=800, resizable=yes';
			else
				winFeatures='height=497,width=720, resizable=yes';
			xPos = 20; yPos = 20;
		break;
		case 'resource2':
			if (screen.width > 810)
				winFeatures='height=580,width=800, resizable=yes,scrollbars=yes';
			else
				winFeatures='height=497,width=720, resizable=yes,scrollbars=yes';
			xPos = 20; yPos = 20;
		break;
		case 'glossary':
			winFeatures='height=400,width=585,scrollbars=yes,resizable=no'; xPos = 20; yPos = 20;
		break;	
		case 'tour':
			winFeatures='height=450,width=650,scrollbars=yes,resizable=yes'; xPos = 10; yPos = 10;
		break;
		case 'document':
			winFeatures='height=480,width=680,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes';
			xPos = 20; yPos = 20;
		break;
		case 'textalt':
			winFeatures='height=480,width=680,menubar=yes,resizable=yes,scrollbars=yes';
			xPos = 20; yPos = 20;
		break;
		case 'max800':
			winFeatures='height=480,width=680,menubar=no,toolbar=no,resizable=yes,scrollbars=yes';
			xPos = 30; yPos = 30;
		break;	
		case 'magazine':
			winFeatures='height=480,width=680,menubar=no,toolbar=no,resizable=yes,scrollbars=yes';
			xPos = 20; yPos = 20;
		break;						
		default:
			winFeatures='height=400,width=500,scrollbars=yes'; xPos = 50; yPos = 50;
		break;
	}
	newWin=window.open(url, windowType, winFeatures);
	newWin.moveTo(xPos, yPos);
	newWin.focus();
}
// winfteFa
function closeWin() {
	if (parent.opener.newWin) {
		var pWin = parent.opener;
		pWin.focus();
		pWin.newWin = null;
	}
	parent.close();
}

// pop glossary
function glossaryTerm(termID, folderLevel) {
	var url = "";
	if (folderLevel) {
		for (var i=0; i < folderLevel; i++) { url += "../";	}
	}
	url += 'resources/glossary/glossary_fs.htm?' + termID;
	popWindow(url, 'glossary');
}

// preload images
function preloadImgs() { 
  var args = preloadImgs.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

// swap an image
function swapImg(imgID, imgSrc) {
  if (document.getElementById) {
    document.getElementById(imgID).src = imgSrc;
  }
}

// rollover image
function imgOver (imgID) {
	var iSrc = document.getElementById(imgID).src.split('.');
	if (iSrc.length) {
		var l = iSrc.length;
		iSrc[l-2] += '_over';
		var newSrc = iSrc.join(".");
		swapImg(imgID, newSrc);
	}
}

// rolloff image
function imgOff (imgID) {
	var iSrc = document.getElementById(imgID).src;
	if (iSrc.indexOf('_over.') != -1) {
		iSrc = iSrc.replace(/_over\./i, '.');
		swapImg (imgID, iSrc);
	}
}

// embed flash
function embedFlash(id, url, width, height, bgColour) {
	if (!id || !url || !width || !height || !bgColour) return;
	document.write("<div id=\""+id+"\">\n");
	document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\""+width+"\" height=\""+height+"\">\n");
	document.write("<param name=\"movie\" value=\""+url+"\" />\n");
	document.write("<param name=\"quality\" value=\"high\" />\n");
	document.write("<param name=\"bgcolor\" value=\""+bgColour+"\" />\n");
	document.write("<embed src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" autostart=\"true\" quality=\"high\" bgcolor=\""+bgColour+"\" type=\"application/x-shockwave-flash\" pluginspace=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></embed>\n");
	document.write("</object>\n");
	document.write("</div>\n");
}

// print a frame
function printFrame(fRef) {
	var agent = navigator.userAgent.toLowerCase();
	var isMAC = ( agent.indexOf("mac") != -1 );
	if (!fRef)
		fRef = self;
	if (isMAC) {
		alert("Sorry, your browser doesn't support this feature. Please use the Print option from the browser's File menu");
	} else {
		fRef.focus();
		fRef.print();
	}
}

// javascript skip link functions
function skipTo(elID) {
	if (document.getElementById) {
		//location.hash = elID;
		document.getElementById(elID).focus();
	}
}

// print individual element
function printElement(eleID) {
	nodesDisplay('none');
	if (document.getElementById)
		document.getElementById(eleID).style.display='block';
	printFrame(self);
	nodesDisplay('block');
}

// hide or display all children of the body element
function nodesDisplay(str) {
	if (document.firstChild) {
		var bodyNode = document.getElementsByTagName('body')[0];
		for (var i =0; i < bodyNode.childNodes.length; i++) {
			var node = bodyNode.childNodes[i].style.display = str;
		}
	}
}

function openDoc(thisTag) {
	var name = navigator.appName;
	var agent = navigator.userAgent.toLowerCase();
	var isMAC = ( agent.indexOf("mac") != -1 )
	var isIE = ( name.indexOf("Microsoft") != -1  );
	if (isIE && !isMAC) {
		popWindow(thisTag.href, "document");
		return false;
	}
	else {
	    location.href=thisTag.href;
		return false;
	}
}