var newwin;

function openWindow(Link, Width, Height, Name, Slides){
	
	if (Width == null)
		Width = 345;

	if (Height == null)
		Height = 327;
	
	if (Name == null)
		Name = "WindowName";
		
	Resize = "yes";
	Scroll = "no";
	Status = "no";
	
	winfeatures = "width=" + Width;
	winfeatures += ",height=" + Height;
	winfeatures += ",scrollbars=" + Scroll;
	winfeatures += ",resizable=" + Resize;
	winfeatures += ",status=" + Status;
//	winfeatures += ",location=yes"; //use for adding the address bar for testing

	//Check to see if link is swf or flv
	linkType = Link.substring(Link.length - 3);

	if (linkType == 'swf' || linkType == 'flv')
	{
		// Check to see if cookie has been set; if it has, see if it is set to true
		cookie_name = "hasRightVersion";

		function getName()
		{
			if(document.cookie)
			{
				index = document.cookie.indexOf(cookie_name);
				if (index != -1)
				{
					namestart = (document.cookie.indexOf("=", index) + 1);
					nameend = document.cookie.indexOf(";", index);
				
					if (nameend == -1)
						nameend = document.cookie.length;
				
					hasRightVersion = document.cookie.substring(namestart, nameend);
					return hasRightVersion;
				}
			}
		}// close getName() function
		
		if (hasRightVersion=getName()) // check if cookie is set to true
		{
			if(linkType == 'swf') //If link IS swf, then check to see if it's the correct version
			{
				folderLink = findFolder();
				newwin = window.open("../embed_swf.htm?link="+folderLink+Link,Name,winfeatures);
				newwin.focus();
			}
			else if(linkType =='flv') //If link is an FLV, then we'll use a little different link
			{
				folderLink = findFolder();
				newwin = window.open("../embed_swf.htm?link=images/videos.swf&flvLink="+Link+"&slides="+Slides,Name,winfeatures);
				newwin.focus();
			}
		} //close hasRightVersion if statement
		else // if version of flash is not correct or cookie is not been set, then send them to the flash test page
		{
			folderLink = findFolder();
			newwin = window.open("../flashtest.htm?"+folderLink+Link + "&slides="+Slides,"flashTest","width=400,height=390");
			newwin.focus();
		}
	} // close swf OR flv if statement
	else if(Link == 'http://www.nfstc.org/review/review_form.php' || Link == '../review/review_form.php')
	{
		location = window.location; // find location of referring page
		Link = Link + '?referer=' + location; // used for finding referring page on review form
		newwin = window.open(Link,Name,winfeatures);
		newwin.focus();
	}
	else 
	{
		newwin = window.open(Link,Name,winfeatures);
		newwin.focus();
	}
} // close openWindow

function putCookie(value)
{
	if(document.cookie != document.cookie)
		index = document.cookie.indexOf("menu");
	else
		document.cookie="menu="+value+"; expires=Monday, 04-Apr-2100 05:00:00 GMT";
}// close putCookie() function

function getCookie()
		{
			if(document.cookie)
			{
				index = document.cookie.indexOf("menu");
				if (index != -1)
				{
					namestart = (document.cookie.indexOf("=", index) + 1);
					nameend = document.cookie.indexOf(";", index);
				
					if (nameend == -1)
						nameend = document.cookie.length;
				
					value = document.cookie.substring(namestart, nameend);
					return value;
				}
			}
		}// close getCookie() function

function openVideo(Link, Slides, Width, Height, Name) {
	if (Width == null)
		Width = 430;
		
	if (Height == null)
		Height = 450;
		
	if (Name == null)
		Name = 'video';

	if (Slides == null)
		Slides = 0;

	openWindow(Link, Width, Height, Name, Slides);
}// close openVideo

function findFolder()
{
	var locate = window.location;
	var text = new String(locate);

	function delineate(str)
	{
		theleft = 0;
		theright = str.lastIndexOf("/") - 1;
		
		for (i=0; str.charAt(theright - i) != "/" && str.charAt(theright - i) != "\\"; i++)
			theleft = theright -i;
		
		theright += 2;
		return(str.substring(theleft, theright));
	}

	return(delineate(text));
}

function openGlossary(Link) {

	fullLink = "../glossary.htm#" + Link;

	Width = 790;
	Height = 200;
	
	openWindow(fullLink, Width, Height, "glossaryName");
}// close openGlossary

function checkScreenSize() {
	//change width to 715px & hide menu by default
	if (screen.width < 800){
		document.write('<style>#Container {width:715px;}</style>');
	}
}

checkScreenSize(); // Changes CSS depending on screen size

function printPage(){
	window.print();
}

