function MM_findObj(n, d) { //v4.01
	var p,i,x;
	if(!d)
		d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length){
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all)
		x=d.all[n];
		for(i=0;!x&&i<d.forms.length;i++)
			x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++)
			x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById)
		x=d.getElementById(n);
	return x;
}

function MM_showHideLayers() { //v6.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for(i=0;i<(args.length-2);i+=3)
		if((obj=MM_findObj(args[i]))!=null){
			v=args[i+2];
			if(obj.style){
				obj=obj.style;
				v=(v=='show')?'visible':(v=='hide')?'hidden':v;
			}
			obj.visibility=v;
		}
}
//Each cookie holds every selected item on a certain page.
//There will only be a maximum of 5 cookies
//at any one time for this domain (one for each page's list).

//Return the value of a cookie given its name.
//Searches through the list of current cookies.
function readCookie(name){
	var nameEQ=name+"=";
	//Get array of all cookies
	var ca=document.cookie.split(';');
	//Look through each cookie to match its name
	//with the one we want.
	for(var i=0;i<ca.length;i++) {
		var c=ca[i];
		//Get rid of the leading spaces for the cookie
		while(c.charAt(0)==' ')
			c=c.substring(1,c.length);
		//If this is the cookie we want, return its value
		if(c.indexOf(nameEQ)==0)
			return c.substring(nameEQ.length,c.length);
	}
	//Return null if the cookie isn't found
	return null;
}
//Returns the value we're looking for if it is in the
//cookie's list of items, or null if the value wasn't found.
function readValue(name,value){
	//See if the cookie exists.
	var cookieValue=readCookie(name);
	//If there cookie didn't exist, there's no point in continuing.
	if(cookieValue!=null){
		//Get list of items in cookie's value
		var itemArray=cookieValue.split(",");
		//Go through each item to see if the value we're looking for is there
		for(var i=0;i<itemArray.length;i++){
			var ci=itemArray[i];
			while(ci.charAt(0)==' ')
				ci=ci.substring(1,ci.length);
			//Return the value when we've found it
			if(ci.indexOf(value)==0)
				return ci;
		}
	}
	//Return null if what we're looking for isn't found
	return null;
}
//Make a cookie with the supplied name and value.
//This cookie will last 7 days. If the cookie already
//exists, it will append the value of the 'value' parameter to the
//existing value of the cookie (as opposed to making a new cookie).
function makeCookie(name,value){
	//Get the value of the cookie if it exists already
	var curCookieValue=readCookie(name);
	//Make a date 7 days in the future
	var date=new Date();
	date.setTime(date.getTime()+(7*24*60*60*1000));
	//If the cookie wasn't found, we need to make a new one.
	//If the cookie was found, we'll add our value to its list of values.
	if(curCookieValue==null)
		document.cookie=name+"="+value+"; expires="+date.toGMTString()+"; path=/";
	else
		document.cookie=name+"="+curCookieValue+","+value+"; expires="+date.toGMTString()+"; path=/";
}
//Puts the names and values of all cookies into a
//nicely-formatted string, and returns that string.
function readAllCookies(){
	var cookieInfo="";
	//Get the cookie array
	var ca=document.cookie.split(";");
	//Go through each cookie.
	for(var i=0;i<ca.length;i++){
		var c=ca[i];
		//Remove leading white space for cookie
		while(c.charAt(0)==' ')
			c=c.substring(1,c.length);
		//Get the value of the cookie.
		var ta=c.split("=");
		cookieInfo+=ta[0]+":\n";
		//Separate the value of the cookie into its list items.
		var sa=ta[1].split(",");
		//Add each item to the final string, adding format characters
		//as needed.
		for(var j=0;j<sa.length;j++){
			cookieInfo+=sa[j]+'\n';
		}
		cookieInfo+='\n';
	}
	//Return the formatted string
	return cookieInfo;
}
function isTripPlannerCookie(name){
	if(name.indexOf("Spas")==0)
		return true;
	else if(name.indexOf("Hotels")==0)
		return true;
	else if(name.indexOf("Attractions")==0)
		return true;
	else if(name.indexOf("Gay Bars")==0)
		return true;
	else if(name.indexOf("Comedy")==0)
		return true;
	else if(name.indexOf("Dance Clubs")==0)
		return true;
	else if(name.indexOf("Lounge Bars")==0)
		return true;
	else if(name.indexOf("Bars")==0)
		return true;
	else if(name.indexOf("Alternative - Rock Music")==0)
		return true;
	else if(name.indexOf("Steak House Restaurants")==0)
		return true;
	else if(name.indexOf("Japanese Restaurants")==0)
		return true;
	else if(name.indexOf("French Restaurants")==0)
		return true;
	else if(name.indexOf("Disney Restaurants")==0)
		return true;
	else if(name.indexOf("American Dining")==0)
		return true;
	else if(name.indexOf("Clothing Stores")==0)
		return true;
	else if(name.indexOf("Designer Outlets")==0)
		return true;
	else if(name.indexOf("Shopping Malls")==0)
		return true;
	else
		return false;
}
//Generate the trip planner page (through items in the cookies)
function outputCookies(toElement){
	//Make header for the page
	//Make a div for each item on the list
	//For each item:
	//   Make a border on top
	//   Make space (line break)
	//   Make the title bold
	//   Show address and telephone number
	var headDiv=document.createElement("div");
	var headerElement=document.createElement("img");
	headerElement.setAttribute("src","../images/print_header.jpg");
	headDiv.appendChild(headerElement);
	var pageDiv=document.getElementById(toElement);
	var breakElement=document.createElement("br");
	pageDiv.appendChild(breakElement);
	breakElement=document.createElement("br");
	pageDiv.appendChild(breakElement);
	pageDiv.appendChild(headDiv);
	breakElement=document.createElement("br");
	pageDiv.appendChild(breakElement);
	//Get all the pages to display
	if(document.cookie.length==0)
		return;
	var cookies=document.cookie.split(";");
	//Get all the items in each page
	for(var i=0;i<cookies.length;i++){
		var curCookieString=cookies[i];
		var curCookie=curCookieString.split("=");
		var itemString=curCookie[1];
		var cookieName=curCookie[0];
		while(cookieName.charAt(0)==' ')
			cookieName=cookieName.substring(1,cookieName.length);
		if(isTripPlannerCookie(cookieName)){
			var items=itemString.split(",");
			var newDiv=document.createElement("div");
			newDiv.setAttribute("id","tripplanner");
			var boldText=document.createElement("b");
			newDiv.appendChild(boldText);
			var newTNode=document.createTextNode(curCookie[0]);
			boldText.appendChild(newTNode);
			pageDiv.appendChild(newDiv);
			//Put each item into its own formatted div
			for(var j=0;j<items.length;j++){
				var itemDiv=document.createElement("div");
				itemDiv.setAttribute("id","tripplanner");
				var boldItemDiv=document.createElement("strong");
				breakElement=document.createElement("br");
				itemDiv.appendChild(breakElement);
				itemDiv.appendChild(boldItemDiv);
				var itemText=document.createTextNode(items[j]);
				boldItemDiv.appendChild(itemText);
				breakElement=document.createElement("br");
				var breakElement2=document.createElement("br");
				var addressItem=addressArray[cookieName+" "+items[j]];
				var addressLines=addressItem.split('|');
				for(var k=0;k<addressLines.length;k++){
					var addressText=document.createTextNode(addressLines[k]);
					var breakElem=document.createElement("br");
					itemDiv.appendChild(breakElem);
					itemDiv.appendChild(addressText);
				}
				itemDiv.appendChild(breakElement);
				itemDiv.appendChild(breakElement2);
				pageDiv.appendChild(itemDiv);
			}
		}
	}
}
//Removes a cookie from the domain.
function removeCookie(name){
	var date=new Date();
	date.setTime(date.getTime()-(24*60*60*1000));
	document.cookie=name+"=; expires="+date.toGMTString()+"; path=/";
}
//Removes a value from a list of values for a cookie.
function removeValue(name,value){
	var items=readCookie(name);
	var itemList=items.split(",");
	removeCookie(name);
	for(var i=0;i<itemList.length;i++){
		var curItem=itemList[i];
		while(curItem.charAt(0)==' ')
			curItem=curItem.substring(1,curItem.length);
		if(curItem.indexOf(value)!=0)
			makeCookie(name,curItem);
	}
}
//Removes all the cookies for this domain.
function clearCookies(){
	//Get the array of cookies.
	var ca=document.cookie.split(';');
	//Get the date for yesterday.
	var date=new Date();
	date.setTime(date.getTime()-(24*60*60*1000));
	//Set all cookies to yesterday's date to delete them.
	for(var i=0;i<ca.length;i++){
		var valpair=ca[i].split('=');
		var name=valpair[0];
		while(name.charAt(0)==' ')
			name=name.substring(1,name.length);
		if(isTripPlannerCookie(name))
			document.cookie=name+"=; expires="+date.toGMTString()+"; path=/";
	}
}
//Marks buttons of selected items to selected if their items are found
//in the cookie's list of values (for page 'pageName'). Necessary for the
//persistance of item selection status when the page is refreshed.
function showSelectedItems(pageName){
	//Get the cookie's value for the page we're going to update
	var cookieValue=readCookie(pageName);
	var curElement;
	//If a cookie for the page exists, proceed.
	if(cookieValue!=null){
		//Get list of items in the cookie's value.
		cookieAr=cookieValue.split(',');
		//Set list items to selected when found in cookie's matching value list
		for(var i=0;i<cookieAr.length;i++){
			var val=cookieAr[i];
			while(val.charAt(0)==' ')
				val=val.substring(1,val.length);
			curElement=document.getElementById(pageName+" "+val);
			curElement.setAttribute("src","../images/tripplan_button_green.gif");
		}
	}
}
//Swaps the image of the button to make it appear selected.
//Also removes or adds the value of the selected item to the page's
//cookie as needed.
function swapImages(pageName,value){
	//Get reference to the item to swap the image for.
	var imageToSwap=document.getElementById(pageName+" "+value);
	//If the item in question is already in the list, remove it and set the
	//button to unselected. If the item is not in the list, add it, and set the
	//button to selected.
	if(readValue(pageName,value)==null){
		makeCookie(pageName,value);
		imageToSwap.setAttribute("src","../images/tripplan_button_green.gif");
	}
	else{
		removeValue(pageName,value);
		imageToSwap.setAttribute("src","../images/tripplan_button.gif");
	}
}
//Displays the planner in another window, giving the user the option to print it.
function printPlanner(){
	//Make a new window
}

