//script to open a new window of given size and attributes
function openNew(newPage, newName, newAttributes) {
newWindow = window.open(newPage,newName,newAttributes);
newWindow.focus();
return false
}

//function to read cookie; split cookie into number of sales for each pan type
//Then produce a table of sales as a bar graph
function loadChart() {

//see if the right cookie exists, if not alert the user 
if (document.cookie.indexOf('sales') == -1) {
document.write("<p>There is no data to construct a bar graph! This page requires your browser to accept cookies.  ")
document.write("If you have cookies enabled and still cannot see the graph, visit the home page ")
document.write("where the cookie will automatically be set and then return to this page.</p>")
}
else {

//otherwise pick the correct cookie out of the string of cookies and save into variable 'cookieString'
//by first making substring starting at with the name of the chosen cookie
var cookieString = document.cookie.substr(document.cookie.indexOf('sales'));

//and then reducing this substring to one cookie if there is a ';' indicating another cookie follows.
if (cookieString.indexOf(';') != -1) {
cookieString = cookieString.substring(0,cookieString.indexOf(';'));
}

//declare some arrays

//the longest length a bar can be (ie 100%)
var barLength = 300;
//initial value of pan totals
var intPanTotals = 0;
var arrPans = new Array();
var arrPanValue = new Array();
var arrFigures = new Array();

//Get cookie and split it into name and value
arrPanValue = cookieString.split("=");
//Unescape the the value to allow for splitting
arrPanValue[1]=unescape(arrPanValue[1]);
//populate an array with the results of spliting the cookie value at","
arrFigures = arrPanValue[1].split(",");

//Create the table holding the headings

document.write("<h2>"+arrPanValue[0]+"<\/h2>");
document.write("<table><tr><td width='70'><h4>Product<\/h4><\/td><td><h4>Total Sales<\/h4><\/td><\/tr><\/table>")

//populate arrays with pan name (arrPans) and sales (arrFigures)
	for (i=0; i<arrFigures.length; i++) {
		var snippet = arrFigures[i].indexOf("=");
		arrPans[i] = arrFigures[i].substring(0,snippet);
		arrFigures[i] = arrFigures[i].substr(snippet+1);
		arrFigures[i] = parseInt(arrFigures[i]);
	  intPanTotals += arrFigures[i];
	 }
//Create the table using a for loop to loop around the instances of the value split		 
//and divide each pan by the total of pans to get a percentage, then multiply by a constant barLength figure	
	 for (i=0; i<arrFigures.length; i++) {
		 imgWidth = arrFigures[i]/intPanTotals*barLength;
		 //get percent of total pans and multiply by constant
		 document.write("<table><tr><td width='70'>"+arrPans[i]+"<\/td>");
		 document.write("<td bgcolor='#6699cc'><img src='images\/clear_dot.gif' ");
		 document.write("width='"+imgWidth+"' height='30' alt='bar graph'><\/td><td>"+arrFigures[i]+"<\/td><\/tr><\/table>");
		 }
document.close();
}
}


// Open a new Image widow with the passed perameters
function newImageWindow(newRef, newName,newPerams, newDescription) {
newWindow = window.open("", newName,newPerams)
newWindow.document.write("<html><head><title>"+newName+"<\/title><\/head>")
newWindow.document.write("<body><img src='"+newRef+"' alt='largepan'><br>")
newWindow.document.write("<strong>" + newDescription + "<br><br>")
newWindow.document.write("<a href='javascript:window.close()'>Close window<\/a>")
newWindow.document.write("<\/body><\/html>")
newWindow.document.close();
}
//preloads a number of images to use later in roll overs
function preLoad() {
if(document.images) {
panImage = new Array();

		for (var i = 0; i < arguments.length; i++) {
		panImage[i] = new Image();
    panImage[i].src = arguments[i];
		}
}
}
//function to detect browser and set certain browser variables for use in conditional
// statements later on and return true if it is a supported browser
function browserDetect() {

if (agent.indexOf("Opera") != -1) {
		starter = agent.indexOf("Opera");
		browserName = "Opera";
		versionString = agent.substr(starter+6);
		arrVersion = versionString.split(" ");
		browserVersion = arrVersion[0];
		return true;
		}

else 	if (agent.indexOf("Netscape") != -1) {
			starter = agent.indexOf("Netscape");
			browserName = "Netscape";
			versionString = agent.substr(starter+9);
			arrVersion = versionString.split(" ");
			browserVersion = arrVersion[0];
			return true;
			}
		
else 	if (agent.indexOf("Firefox") != -1) {
			starter = agent.indexOf("Firefox");
			browserName = "Firefox";
			versionString = agent.substr(starter+8);
			arrVersion = versionString.split(" ");
			browserVersion = arrVersion[0];
			return true;
			}
		
else if (agent.indexOf("compatible") != -1) {
			versionSplit = agent.split(";")
			browserVersion = versionSplit[1]
			browserName = browserappName;
			return true;
			}
			
else if (browserappName == "Netscape") {
			versionSplit = version.split(" ")
			browserVersion = versionSplit[0]
			browserName = browserappName;
			return true;
			}
		
else {
			return false;
			}
			
}	

//This function loads a new page with a value from an option selected in a form
function jumpPage(newLoc) {
	newPage = newLoc.options[newLoc.selectedIndex].value
	
			if (newPage != "") {
				window.location = newPage
			}
}
	
function SetCookie(name, value) {
expDate = new Date;
expDate.setMonth(expDate.getMonth()+1);
document.cookie = name + "=" + escape(value)+";expires="+expDate.toGMTString();
}

function expandIt(nowMenu, lastMenu, nextMenu) {
if (document.getElementById) {
				atMenu = document.getElementById(nowMenu).style
				thatMenu = document.getElementById(lastMenu).style
				theotherMenu = document.getElementById(nextMenu).style
				atMenu.display = "block";
				thatMenu.display = "none";
				theotherMenu.display = "none";
			}
}

function downSmall(menuName, num) {
for (i=1; i<=num; i++) {
		document.getElementById(menuName+i).style.display	= "none"
		}
}


		function toggleMenuOver(currMenu) {
			if (document.getElementById) {
				thisMenu = document.getElementById(currMenu).style
				thisMenu.visibility = "visible"
			}
}

	function toggleMenuOut(currMenu) {
			if (document.getElementById) {
				thisMenu = document.getElementById(currMenu).style
				thisMenu.visibility = "hidden"
			}
}

// -->