/*  This is a part of the Hull and East Yorkshire CAMRA Website, maintained by Dominic Bell */
/*    Last updated 16th August 2005                                                         */

function loadFrames(doc1,doc2){
    parent.Left.location.href=(doc1);
    parent.Main.location.href=(doc2);
   }

function checkStillInFrame(){
	if (parent.location.href == self.location.href) {
    if (window.location.href.replace)
        window.location.replace('index.htm');
    else
        // causes problems with back button, but works
        window.location.href = 'index.htm';
	}
}

/* Function setFrames(navFrameName, defaultFrameName)
Sets up initial frameset, with default navigation and content pages passed into it. If it has been called by another page it will check if that page has passed a link to it. To get around the IE explorer bug that stops this working on local hard disks under Internet Explorer it will, if the passing page is a file, check to see if that page set a cookie from which it can get the link. It will then use this link for the content page. 
*/
//Modified from Negrino and Smith, p.92

function setFrames(navFrameName, defaultFrameName)
{
	linkURL = defaultFrameName;
	navURL = navFrameName;

	if (parent.document.URL)
	{
		callingURL = parent.document.URL;
		if (callingURL.indexOf('?') != -1)
		{
			linkURL = callingURL.substring(callingURL.indexOf('?')+1, callingURL.length);
		}
		else 
		{
			// Looks for cookie if on hard disk to get around IE bug
			if (cookieVal("frame"))
			{
				home = document.URL.split(":")[0];
				if (home == "file")
				{
					// Reads cookie
					linkURL = cookieVal("frame");
					// Resets cookie with home pages	
					setFrameCookie(defaultFrameName);
				}
			}
		}
	}

	document.writeln('<frameset cols = "140,500" frameborder = "no" frameborder = "0">');
	//document.writeln('<frame src = "hidden.html" name = "hidden">');
	document.writeln('<frame src = "' + navURL + '"name = "Left">');
	document.writeln('<frameset rows = "160,*" frameborder = "no" frameborder = "0">');
	document.writeln('<frame name = "Top" src = "header.htm" scrolling = "yes">');
	document.writeln('<frame src = "' + linkURL + '" name = "Main">');
	document.writeln('<\/frameset>');
}


/* Function getFrames(fsetName,pageName)
If a page intended to be part of a frameset has been called by itself, calls a named frameset and passes its own name to it. Its parameters are the name of the frameset page and the name of the page itself. If it finds that the page is one from a local hard disk, it will set a cookie to get around the IE Explorer bug which stops the passing of the frames name.
*/

// Modified from Negrino and Smith, p.93

function getFrames(fsetName,pageName)
{
	if (top.location == self.location)
	{
		// Set cookie if on hard disk to get around IE bug
		home = document.URL.split(":")[0];
		if (home == "file")
		{
			setFrameCookie(pageName);	
		}
		self.location.replace(fsetName + '?' + pageName);
	}
}

/* Function getFramesNav(fsetName)
If navigation frame has been called by itself, this calls the frameset that should be around it. This is a cutdown version of getFrames(fsetName,pageName).
*/

// Modified from Negrino and Smith, p.93
function getFramesNav(fsetName)
{
	if (top.location == self.location)
	{
		self.location.replace(fsetName);
	}
}

/* function setFrameCookie(string)
Sets a cookie to hold the frame name, which it takes as a parameter.
*/

//Modified from Negrino and Smith, p.224
function setFrameCookie(string)
{
	expireDate = new Date;	
	expireDate.setMinutes(expireDate.getMinutes()+10);
	document.cookie = "frame=" + string + ";expires=" + expireDate.toGMTString() + ";path=/";
}

/*function cookieVal(cookieName)
Gets the value from a cookie of a given name, which is passed in as a parameter.
*/

// Taken from Negrino and Smith, p.233
function cookieVal(cookieName)
{
	thisCookie = document.cookie.split("; ");
	for (i = 0; i < thisCookie.length; i++)
	{
		if (cookieName == thisCookie[i].split("=")[0])
		{
			return thisCookie[i].split("=")[1];
		}
	}
	return 0;  
} 

// Adapted from Study Guide week 8 and other function
function crypCookieVal(cookieName)
{
	thisCookie = document.cookie.split("; ");
	for (i = 0; i < thisCookie.length; i++)
	{
		if (cookieName == thisCookie[i].split("=")[0])
		{
			return unescape(thisCookie[i].split("=")[1]);
		}
	}
	return 0;  
} 

/* Function jumpPage(newLoc)
*/
// Modified from Negrano and Smith, p.135
function jumpPage(newLoc)
{
	newPage = newLoc.options[newLoc.selectedIndex].value;
	
	if (newPage != "")
	{
		parent.content.document.location.href = newPage;
	}
} 

/* Function chgImg(imgField, newImg)
*/
// Taken from Negrano and Smith, p.62
function chgImg(imgField, newImg)
{
	if (document.images)
	{
		document[imgField].src = eval(newImg + ".src");
	}
}





/* Function getBrowser()
*/
// Modified from Negrano and Smith, p.24, with added information from Flanagan, p.102 and Kourbatov // (http://www.javascripter.net/faq/browserv.htm 4th July 2004)
function getBrowser()
{
	var browser = navigator.appName;
	//alert("browser is " + browser);

	var versionString = navigator.appVersion;
	//alert("version is " + versionString);
	var agentString = navigator.userAgent;
	//alert("agent is " + agentString);
	
	// For Netscape
	version = parseFloat(navigator.appVersion);
	
	// In Internet Explorer, the version number is after "MSIE" 
	if ((verOffset=agentString.indexOf("MSIE"))!=-1) 
	{
 		version = parseFloat(agentString.substring(verOffset+5,agentString.length));
 	}

	// In Opera, the version number is after "Opera"
	if ((verOffset=agentString.indexOf("Opera"))!=-1) 
	{
 		version = parseFloat(agentString.substring(verOffset+6,agentString.length));
	}

	// Stops removal of decimal places for 6.0, etc
	version = version.toString();
	//alert("version length is " + version.length);
	if (version.length == 1)
	{
		version = version + ".0";
	}

	//alert("version is " + version);
	document.write("You are running " + browser + " version " + version + "<br\/>");
	if (navigator.cookieEnabled)
	{
		document.write("Cookies are enabled.&nbsp;");
	}
	else
	{
		document.write("Cookies are disabled.&nbsp;");
	}
	if (navigator.javaEnabled())
	{
		document.write("Javascript is enabled.<br\/>");
	}
	else
	{
		document.write("Javascript is disabled.<br\/>");
	}	
}

/* openPicWindow(picture, description, width, height)
Takes picture file, description string for alt, and size parameters and generates a window with the name of the file minus the extension and directory, and with a button on it to close it. 
*/
// Heavily modified from Negrino and Smith, p.112 and p.122) 
function openPicWindow(picture, picDesc, picWidth, picHeight)	
{
	// Set window widths and height, allowing margins around picture and space for button
	winWidth = picWidth + 20;
	winHeight = picHeight + 70;
	//winOpenString = "\"\", \"newWin\", \"toolbar=no,location=no,scrollbars=no,width=" + winWidth + ",height=" + winHeight + "\"";
	// Build window configuration string
	winOpenString = "toolbar=no,location=no,scrollbars=no,width="+ winWidth + ",height=" + winHeight;
	//alert(winOpenString);
	// Set window name (picture file name - extension)
	if ((startName=picture.indexOf("/"))!=-1) 
	{	
		// if path has directory in go to remove directory and extension from name
		winName = picture.substring(startName + 1, picture.length-4);
	}
	else
	{
		// if does not have directory just remove extension
		winName = picture.substring(0, picture.length - 4); 
	}
	//alert(winName);
	//alert(picDesc);
	// Open new window
	newWindow = window.open("", winName, winOpenString);

	newWindow.document.write("<html><head><title>Big Picture<\/title>");
	newWindow.document.write("<link rel = stylesheet type='text\/css' href='eca.css'>");
	newWindow.document.write("<\/head><body>");
	newWindow.document.write("<p class = 'centerpara'>");
	newWindow.document.write("<img src = '" + picture + "' width = " + picWidth + " height = " + picHeight + " alt = '" + picDesc + "'></a>");
	newWindow.document.write("<form name = 'buttonForm' action = 'none'><input type = 'button' name = 'closebutton' onClick = 'self.close()' value = 'Close'></form>");
	newWindow.document.write("<\/p><\/body><\/html>");
}

/* toggleMenu(currMenu)
Takes menu name and toggles it on and off. 
*/
// From Negrino and Smith, p.290-291) 
	function toggleMenu(currMenu) {
		if (document.getElementById) 
		{
			thisMenu = document.getElementById(currMenu).style;
			if (thisMenu.display == "block") 
			{
				thisMenu.display = "none";
			}
			else 
			{
				thisMenu.display = "block";
			}
			return false;
		}
		else
		{
			return true;
		}
	}
