//This document is used to extract a quertstring and then return av value indicating wheather a printer friendly version of the page is needed.
//Created on 9/24/04 by William Milligan.

var myURL = location.href;
var myArray = myURL.split("/");
var myFile = myArray[myArray.length - 2] + "/" + myArray[myArray.length - 1];
var myDir = myArray[myArray.length - 1];
var imgName = "skybluestripe.gif";
var imgUrl;

//creates the correct path for the background image
if(myArray[myArray.length - 3]=='spanish' || myArray[myArray.length - 2]=='spanish')
{
	if(myArray[myArray.length - 2]=='about' || myArray[myArray.length - 2]=='science' || myArray[myArray.length - 2]=='community' || myArray[myArray.length - 2]=='media')
	{
		imgUrl = "../../images/" + imgName;
	}
	else
	{
		imgUrl = "../images/" + imgName;
	}
}
else
{
	if(myArray[myArray.length - 2]=='about' || myArray[myArray.length - 2]=='science' || myArray[myArray.length - 2]=='community' || myArray[myArray.length - 2]=='media')
	{
		imgUrl = "../images/" + imgName;
	}
	else
	{
		imgUrl = "images/" + imgName;
	}
}
//parses the querystring and returns a boolean true if value of print is yes
function ckQS()
{
	var myAtts = new Array();
	var myVals = new Array();
	var myPairs = new Array();
	
	if(location.search) //if a querystring is present proceed, otherwise return false
	{
		var myQstr = location.search; //grabs the quesrstring, everything including the "?" to the end of the URL
		myQstr = myQstr.substr(1, myQstr.length);  //extracts everything but the "?"
		myPairs = myQstr.split("&");
		//myPairs = myQstr.split("%26"); //Splits the querystring on the "&", may change from "%26" to "&" when live on the server
		//loops through the querstring attribute value pairs and splits them into seperate arrays.
		for(var i = 0; i < myPairs.length; i+=1)
		{
			var myTempArr = new Array();
			myTempArr = myPairs[i].split("="); //splits on the "="
			myAtts[i] = myTempArr[0]; //attribute array
			myVals[i] = myTempArr[1]; //value array
			//all code above is generic code to parse a querysting, below is code specific to the querystring we are after
			if(myAtts[i] == "print") //if the attribute is print, look at the value
			{
				if(myVals[i] == "yes") //if the value is yes, return true
				{
					return true;
				}
				else //if the value is not yes, return false
				{
					return false;
				}
			}
		}
	}
	else //no querystring, so return false
	{
		return false;
	}
}

//creates a new window with the printer friendly version in it
function myPopWin(URL) 
{
	window.open(URL, "printMe", "width=640, height=600, menubar=yes, toolbar=yes, scrollbars=yes");
}

//writes a body tag without a background image for the printable version and a div tag to hide unprintable content
//or a body tag for display with the background image
function printBody(toPrint)
{
	if(toPrint)
	{
		document.write("<body leftmargin=0 marginwidth=0 topmargin=0 marginheight=0 onload='self.focus()'>");
		document.write("<div style='visibility:hidden;'>");
	}
	else
	{
		document.write("<body leftmargin=0 marginwidth=0 background='" + imgUrl + "' topmargin=0 marginheight=0>");
	}
	
}

//writes a div tag to make printable content visible
function printContent(toPrint)
{
	if(toPrint)
	{
		document.write("<div style='visibility:visible;z-order:100;position:absolute;left:0px;top:0px;width:612'>");
	}
}

//writes a close button to the page, and closes the div tags that make printable content visible
function closeContent(toPrint)
{
	if(toPrint)
	{
		document.write("<div align='center' style='visibility:visible;margin-top:20px'>");
		document.write("<a href='javascript:window.close();'>Close</a>");
		document.write("</div>");
		document.write("</div>");
	}
}

//writes a closing div tag just before the closing body tag
function closeBody(toPrint)
{
	if(myBool)
	{
		document.write("</div>");
	}
}