// Flip it on
function roll(imgName) {
	document[imgName].src = "i/" + imgName + "-on.gif";
}
// Flip it off
function out(imgName) {
document[imgName].src = "i/" + imgName + ".gif";
}

//use the following var to remember an image's original src value
//the imageRoll function will constantly update this value, allowing the imageOut function to use its current value
var imageSourceValue = '';
function imageRoll(imageObject)
{
	//store the current src value
	imageSourceValue = imageObject.src;
	//grab the directory from the src attribute
	var folderIndex = imageObject.src.lastIndexOf("/");
	var theDirectory = imageObject.src.substring(0,folderIndex+1);//returns the DIR in the form http://domain.com/folder
	//test for image file type, jpg v. gif
	var theFileType = imageObject.src.substring(imageObject.src.length-3);//grab the last 3 characters, they represent the file type

	imageObject.src=theDirectory+imageObject.name+'-on.'+theFileType;
}
function imageOut(imageObject)
{
	//retrieve the original image src attribute
	imageObject.src = imageSourceValue;
}
//nextPage is used by the google map display pages to show the next block of listings
function nextPage(pageNum)
{
	var theLocation = new String(document.location)
	var varCheck = theLocation.indexOf("?");
	var placeholder = theLocation.indexOf("currentPage=");
	if(varCheck == -1)//there were no URL vars, so append currentpage and load new url
	{
		document.location = document.location+"?currentPage="+pageNum;
	}
	else if(placeholder != -1)//there was already a currentPage var , get rid of it and reload w/ new page num.
	{
		var tmpLocation = theLocation.slice(0,placeholder);
		document.location = tmpLocation+"currentPage="+pageNum;
	}
	else
	{
		document.location = document.location+"&currentPage="+pageNum;
	}
}
// google pop up window
var theWindow = 0;
var theWindow2 = 0;
var googleWindow = 0;
function addToTripPlanner(theID,theCAT)
{
	/*if(theWindow)
	{
		if(!theWindow.closed)
		{
			theWindow.close();
		}
	}
	theWindow=window.open("http://thisiscooperstown.com/tripPlannerPortal-addToTP.cfm?id="+theID+"&category="+theCAT,"w","width=250,height=125,top=150,left=150"); 
	theWindow.focus();*/
	
	var xmlHttp;
  try
	{    
		// Firefox, Opera 8.0+, Safari    
		xmlHttp=new XMLHttpRequest();   
	}
  	catch (e)
	{    // Internet Explorer    
		try
	  	{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
	  	{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				document.location = "tripPlannerPortal-addToTP.cfm?id="+theID+"&category="+theCAT;
			}  
		}
	}
	
	//now we have the com object, send out request
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			//window.refresh();
			document.location = document.location;
		}
	}
	var queryURL = "tripPlannerPortal-addToTP.cfm?id="+theID+"&category="+theCAT;
	xmlHttp.open("GET",queryURL,true);
	xmlHttp.send(null); 

}

function removeFromTripPlanner(theID,theCAT)
{
	if(confirm('Are you sure you want to delete this listing from your trip planner?'))
	{
		/*if(theWindow)
		{
			if(!theWindow.closed)
			{
				theWindow.close();
			}
		}
		theWindow=window.open("http://thisiscooperstown.com/tripPlannerPortal-removeItem.cfm?id="+theID+"&cat="+theCAT,"w","width=250,height=125,top=150,left=150"); 
		theWindow.focus();*/
		var xmlHttp;
  try
	{    
		// Firefox, Opera 8.0+, Safari    
		xmlHttp=new XMLHttpRequest();   
	}
  	catch (e)
	{    // Internet Explorer    
		try
	  	{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
	  	{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				document.location = "tripPlannerPortal-removeItem.cfm?id="+theID+"&cat="+theCAT;
			}  
		}
	}
	
	//now we have the com object, send out request
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			//window.refresh();
			document.location = document.location;
		}
	}
	var queryURL = "tripPlannerPortal-removeItem.cfm?id="+theID+"&cat="+theCAT;
	xmlHttp.open("GET",queryURL,true);
	xmlHttp.send(null); 
	}
}


function popListingDetails(id,cat)
{
  if(theWindow2)
  {
    if(!theWindow2.closed) theWindow2.close();
  }
  if(cat == 'photos')
  {
	  theWindow2 = open('popPhoto.cfm?id='+id, 'theWindow2', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=yes,copyhistory=yes,width=900,height=600,left=10,top=10,screenX=10,screenY=10');
  }
  else
  { 
  	theWindow2 = open('tripPlannerPortal-popListingDetails.cfm?id='+id+'&category='+cat, 'theWindow2', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=yes,copyhistory=yes,width=900,height=600,left=10,top=10,screenX=10,screenY=10');
  }

}

function directionsSubmit(){
	if(document.forms[0].saddr.value != ""){document.forms[0].submit();}else{alert("Please enter your starting address!");}
}


function zoomToStreet(longitude,latitude)
{
	   var point = new GPoint(longitude, latitude);
	 	map.centerAndZoom(point,2);
}



/* DHTML FUNCTIONS */

function showSearching()
{
	document.getElementById("searchingAlertBox").style.visibility = "visible";
}

function showHints(vis)
{
	document.getElementById("hints").style.visibility = (vis) ? "visible" : "hidden";
}
