var newwin;

function openWindow(Link, Width, Height, Name, Slides){
	
	if (Width == null)
		Width = 770;
		
	if (Height == null)
		Height = 560;
	
	if (Name == null)
		Name = "WindowName";
		
		Resize = "yes";
		Scroll = "yes";
	
	winfeatures = "width=" + Width;
	winfeatures += ",height=" + Height;
	winfeatures += ",scrollbars=" + Scroll;
	winfeatures += ",resizable=" + Resize;
//	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,"width=430,height=450" + 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=350");
			newwin.focus();
		}
	} // close swf OR flv if statement
	else if(Link == 'http://www.nfstc.org/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 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));
}// close findFolder

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 openGlossary(Link) {

	fullLink = "../glossary.htm#" + Link;

	Width = 790;
	Height = 150;
	
	openWindow(fullLink, Width, Height, "glossaryName");
}// close openGlossary
