//
// popwin.js
//
// (c)2005 Iteris, Inc.
//
//	jsl  (original)
//	ghsu (new CV-I views, tabs, IE5/IE6/NS7/Firefox1 compatibilities)
//	cdg  (dual screen resolution mods)
//
//-----------------------------------------------------------------------------
var DEBUG_MODE = false;
window.onerror = ignoreError;

var m_defaultViewNumber = 7;
var m_onlinePath = "../";
var m_onlinePathHTML = "";
var m_random = Math.round(10000 * Math.random());
var isInternetExplorer = (navigator.appName.indexOf("Microsoft") != -1);
var isNetscape = (navigator.appName.indexOf("Netscape") != -1);
var isMacPPC = (navigator.appVersion.indexOf("PPC") != -1);
//-----------------------------------------------------------------------------


//
// Function is an error handler which simply ignores all the errors.
//
function ignoreError() { return true; }


//
// Function is called from es?mainMap.html, when the page is loaded - Call stack:
//	- es?mainmap.html <BODY onLoad> event calls showRightPaneNavTab(page)
//	- showRightPaneNavTab(page) brings up the XXXTABXXX.html, its <BODY onLoad> event then calls showRightPaneNavBody(page)
//	- showRightPaneNavBodyXXX(page) brings up the appropriate page to fill the tab body 
//
function showRightPane(returnRoutePage, ttlID)
{
	if (DEBUG_MODE) alert("In showRightPane("+returnRoutePage+","+ttlID+")");
	var prevReturnRoutePage = getReturnRoutePage();
	
	if (returnRoutePage != prevReturnRoutePage) 
	{
		saveReturnTTLID(""); //Clear last TTL ID if we've switched to a different view
		saveReturnRoutePage(returnRoutePage);
	}

	if (ttlID=="" || typeof ttlID=="undefined")
	{
		showRightPaneNavBodyAbout(); //Default tab
		setRightUpperFramePage("A");
	}
	else
	{
		showRightPaneNavBodyLinkTravelTimes(ttlID, "T"); //User clicked on a map link to show link TT
		setRightUpperFramePage("T"); //User clicked on a map segment 
	}
}


//
// Changes the current map view to the speified number.
// Function is called from the nav combo box.
//
function changeMapView(viewNumber)
{
	if (DEBUG_MODE) alert("In changeMapView("+viewNumber+")");
	top.IsSwitchingMapView=true; 
	top.location.href = 'http://' + document.domain + '/communityview/html/es_main.html?' + viewNumber 
}


//
// This event should fire every time:  (1) user switches CV-I map view, or 
// (2) navigates to a different website, or (3) shuts down the browser window.
// Note: Customer doesn't want the satellite window to reset its window 
// position every time a new map view is selected.
//
function closeSatelliteWindow()
{
	if (DEBUG_MODE) alert("In closeSatelliteWindow()");
	
	//Don't specify the URL to get reference to existing window		
	if (top.window_handle == null) 
		top.window_handle = top.window.open('', 'LowResSatWin', 'resizable, scrollable');  

	//If closing browser window or navigating to a different web site then close satellite window
	if (! top.IsSwitchingMapView) 
		top.window_handle.close();
}


//
// Make sure the hidden data frame is loaded when this script begins; wait upto 30 seconds
//
function waitForHiddenDataFrameToLoad()
{
	if (DEBUG_MODE) alert("In waitForHiddenDataFrameToLoad()");
	var waitCount = 0;

	while(! top.hiddenDataFrame.loaded && waitCount<30)
	{
		setTimeout("void(0)",1000);
		waitCount++;
	}
	if (! top.hiddenDataFrame.loaded)
		alert('Page has not loaded, please wait a moment and try your action again.');
}


function waitForLowresHiddenDataFrameToLoad()
{
	if (DEBUG_MODE) alert("In waitForLowresHiddenDataFrameToLoad()");
	var waitCount = 0;

	while(! top.window_handle.hiddenDataFrame.loaded && waitCount<30)
	{
		setTimeout("void(0)",1000);
		waitCount++;
	}
	if (! top.window_handle.hiddenDataFrame.loaded)
		alert('Popup window has not loaded, please wait a moment and try your action again. (Code: HDF)');
}


function waitForSatelliteRightUpperFrameToLoad()
{
	for (var waitCount=0; top.window_handle.rightUpperFrame==null && waitCount<60; waitCount++) 
		setTimeout("void(0)",1000);
	if (top.window_handle.rightUpperFrame==null) //Still didn't load; msgbox should do it.
		alert("Popup window has not loaded, please wait a moment and try your action again. (Code: RUF)");
}


function waitForSatelliteRightLowerFrameToLoad()
{
	for (var waitCount=0; top.window_handle.rightLowerFrame==null && waitCount<60; waitCount++) 
		setTimeout("void(0)",1000);
	if (top.window_handle.rightLowerFrame==null) //Still didn't load; msgbox should do it.
		alert("Popup window has not loaded, please wait a moment and try your action again. (Code: RLF)");
}


function openAnyWindow(url, name, w, h)
{
	if (DEBUG_MODE) alert("In openAnyWindow");
	openAWindow(url, name, w, h);
}


function reloadGIF()
{
	if (DEBUG_MODE) alert("In reloadGIF");
	
	// test to see if there is an object to reference 
	if (document.EStrafficmap)
	{
		// make sure there is a src field and that it is not empty (I would be surprised if this fails)
		if (document.EStrafficmap.src != null && document.EStrafficmap.src != "")
		{
		// get the src and reload it
		var trafficMapLocation = document.EStrafficmap.src;
		document.EStrafficmap.src = trafficMapLocation;
		}
		else
		{
		// reload document if the above fails
		window.location.reload();
		}
	}
	else
	{
		// reload document if the above fails
		window.location.reload();
	}
}


//
// Function is called when RightPaneNavX.html "About" tab is clicked on.
// Note: under Apache web server, the URI is case sensitive; i.e. "/CommunityView/" won't work!!!
//
function showRightPaneNavBodyAbout(activeTabCode)
{ 
	if (DEBUG_MODE) alert("In showRightPaneNavBodyAbout("+activeTabCode+")");
	
	if (typeof activeTabCode!="undefined" && activeTabCode.length>0) //activeTabCode when provided (invoked when user clicks on the tab), sets the current tab as the active tab
	{
		loadFrame('/communityview/assets/html/Tabs_' + activeTabCode + '.html', 'rightUpperFrame'); //Make tab active
	}
	//setRightLowerFramepage("/communityview/html/TabContent_About.html"); 
	loadFrame('/communityview/html/TabContent_About.html', 'rightLowerFrame'); //Change the right pane to show corresponding body page
}


//
// Function is called when RightPaneNavX.html "Weather" tab is clicked on.
// Note: under Apache web server, the URI is case sensitive; i.e. "/CommunityView/" won't work!!!
//
function showRightPaneNavBodyWeather(activeTabCode)
{ 
	if (DEBUG_MODE) alert("In showRightPaneNavBodyWeather("+activeTabCode+")");
	
	if (typeof activeTabCode!="undefined" && activeTabCode.length>0) //activeTabCode when provided (invoked when user clicks on the tab), sets the current tab as the active tab
	{
		loadFrame('/communityview/assets/html/Tabs_' + activeTabCode + '.html', 'rightUpperFrame'); //Make tab active
	}
	//setRightLowerFramepage("/communityview/html/TabContent_Weather.html"); 
	var viewNumber;
	if (typeof top.hiddenDataFrame!="undefined")  viewNumber = parseMapQSViewNumber(top.location.search); //Standard res mode
	else  viewNumber = parseMapQSViewNumber(top.opener.top.location.search); //Low res mode
	loadFrame('/communityview/html/TabContent_Weather_' + viewNumber + '.html', 'rightLowerFrame'); //Change the right pane to show corresponding body page  	
}


//
// Function is called when RightPaneNavX.html "Construction Info" tab is clicked on.
// Note: under Apache web server, the URI is case sensitive; i.e. "/CommunityView/" won't work!!!
//
function showRightPaneNavBodyConstruction(activeTabCode)
{
	if (DEBUG_MODE) alert("In showRightPaneNavBodyConstruction("+activeTabCode+")");
	
	if (typeof activeTabCode!="undefined" && activeTabCode.length>0) //activeTabCode when provided (invoked when user clicks on the tab), sets the current tab as the active tab
	{
		loadFrame('/communityview/assets/html/Tabs_' + activeTabCode + '.html', 'rightUpperFrame'); //Make tab active
	}
	//setRightLowerFramepage("/communityview/html/TabContent_Construction.html"); 
	loadFrame('/communityview/html/TabContent_Construction.html', 'rightLowerFrame'); // Change the right pane to show corresponding body page
    	
}


//
// Function is called from showRightPaneNavTab() when user clicks on a road segment on the map to show link travel times (TTL ID).
// Note: under Apache web server, the URI is case sensitive; i.e. "/CommunityView/" won't work!!!
//
function showRightPaneNavBodyLinkTravelTimes(ttlID, activeTabCode) 
{
	if (DEBUG_MODE) alert("In showRightPaneNavBodyLinkTravelTimes("+ttlID+")");

	if (typeof activeTabCode!="undefined" && activeTabCode.length>0) //activeTabCode when provided (invoked when user clicks on the tab), sets the current tab as the active tab
	{
		loadFrame('/communityview/assets/html/Tabs_' + activeTabCode + '.html', 'rightUpperFrame');  //Make tab active
	}

	if (typeof ttlID=="undefined" || ttlID=="") 
	{
		ttlID = getReturnTTLID(); //Retrieve last/saved TTL ID if user click on other tabs and then returned to "Travel Time" tab
		if (typeof ttlID=="undefined" || ttlID=="")
		{
			//setRightLowerFramepage("/communityview/html/TabContent_BlankTTL.html"); 
			loadFrame('/communityview/html/TabContent_BlankTTL.html', 'rightLowerFrame'); //Show a blank TTL page; since user has never clicked on a road segment on this view
		}
		else
		{
			setRightLowerFramepage("/communityview/html/es_tt" + ttlID + ".html"); //e.g. returnRoutePage='es4'
		}
	}
	else
	{
		saveReturnTTLID(ttlID); //Save TTL ID if user clicked on map link
		setRightLowerFramepage("/communityview/html/es_tt" + ttlID + ".html"); //e.g. returnRoutePage='es4'
	}
}


//
// Use the text box inside the hidden text frame to store the return route page name; e.g. "es", "es4"
//
function getReturnRoutePage()
{
	var page;
	if (typeof top.hiddenDataFrame!="undefined")
	{
		if (! top.hiddenDataFrame.loaded) waitForHiddenDataFrameToLoad();

		if (typeof top.hiddenDataFrame.document.getElementById('txtReturnRoutePage')=="undefined" 
				|| top.hiddenDataFrame.document.getElementById('txtReturnRoutePage').value=="") 
			page = "es"+m_defaultViewNumber; 
		else
			page = top.hiddenDataFrame.document.getElementById('txtReturnRoutePage').value;
	}
	else 
	{
		if (! top.opener.top.hiddenDataFrame.loaded) waitForLowresHiddenDataFrameToLoad();

		if (typeof top.opener.top.hiddenDataFrame.document.getElementById('txtReturnRoutePage')=="undefined" 
				|| top.opener.top.hiddenDataFrame.document.getElementById('txtReturnRoutePage').value=="") 
			page = "es"+m_defaultViewNumber; 
		else
			page = top.opener.top.hiddenDataFrame.document.getElementById('txtReturnRoutePage').value;
	}

	if (DEBUG_MODE) alert("In getReturnRoutePage()="+page);
	return page;
}


function saveReturnRoutePage(returnRoutePage)
{
	if (DEBUG_MODE) alert("In saveReturnRoutePage("+returnRoutePage+")");

	if (typeof top.hiddenDataFrame!="undefined")
	{
		if (! top.hiddenDataFrame.loaded) waitForHiddenDataFrameToLoad();
		top.hiddenDataFrame.document.getElementById('txtReturnRoutePage').value = returnRoutePage;
	}
	else 
	{
		if (! top.opener.top.hiddenDataFrame.loaded) waitForLowresHiddenDataFrameToLoad();
		top.opener.top.hiddenDataFrame.document.getElementById('txtReturnRoutePage').value = returnRoutePage;
	}
}


//
// Use the text box inside the hidden text frame to store the return link travel time page/TTL ID; e.g. "10020", "10030"
//
function getReturnTTLID()
{
	var ttlID;
	if (typeof top.hiddenDataFrame!="undefined")
	{
		if (! top.hiddenDataFrame.loaded) waitForHiddenDataFrameToLoad();
		

		if (typeof top.hiddenDataFrame.document.getElementById('txtReturnTTLID')=="undefined" 
				|| top.hiddenDataFrame.document.getElementById('txtReturnTTLID').value=="") 
			ttlID = "";
		else
			ttlID = top.hiddenDataFrame.document.getElementById('txtReturnTTLID').value;	
	}
	else 
	{
		if (! top.opener.top.hiddenDataFrame.loaded) waitForLowresHiddenDataFrameToLoad();

		if (typeof top.opener.top.hiddenDataFrame.document.getElementById('txtReturnTTLID')=="undefined" 
				|| top.opener.top.hiddenDataFrame.document.getElementById('txtReturnTTLID').value=="") 
			ttlID = "";
		else
			ttlID = top.opener.top.hiddenDataFrame.document.getElementById('txtReturnTTLID').value;	
	}

	if (DEBUG_MODE) alert("In getReturnTTLID("+ttlID+")");
	return ttlID;
}


function saveReturnTTLID(returnTTLID)
{
	if (DEBUG_MODE) alert("In saveReturnTTLID("+returnTTLID+")");
	
	if (typeof top.hiddenDataFrame!="undefined")
	{
		if (! top.hiddenDataFrame.loaded) waitForHiddenDataFrameToLoad();
		top.hiddenDataFrame.document.getElementById('txtReturnTTLID').value = returnTTLID;
	}
	else 
	{
		if (! top.opener.top.hiddenDataFrame.loaded) waitForLowresHiddenDataFrameToLoad();
		top.opener.top.hiddenDataFrame.document.getElementById('txtReturnTTLID').value = returnTTLID;
	}
}


//
// **********cdg*******
// This loads an HTML file at url into the target frame
//
function loadFrame(url, target)
{
	try { parent.frames[target].location.href = url; }
	catch(ex) {} 
}


//
// activeTabCode:  the tab to set as the active/selected tab.
//		"R"=Route, "W"=Weather, "C"=Contr, "T"=TraveTime
// Note: under Apache web server, the URI is case sensitive; i.e. "/CommunityView/" won't work!!!
//
function setRightUpperFramePage(activeTabCode)
{
	if (DEBUG_MODE) alert("In setRightUpperFramePage()");

	try
	{
		if (typeof top.rightUpperFrame != "undefined")
			top.rightUpperFrame.location.href = "/communityview/assets/html/Tabs_" + activeTabCode + ".html";
		else
		{
			if (top.window_handle.rightUpperFrame == null) waitForSatelliteRightUpperFrameToLoad()
			top.window_handle.rightUpperFrame.location.href = "/communityview/assets/html/Tabs_" + activeTabCode + ".html";
		}
	}
	catch(ex) {} //For now just ingore the exception, we only get error while in 800x600 mode if user clicks fwy link before satellite window is fully loaded 
}


function setRightLowerFramepage(uri)
{
	if (DEBUG_MODE) alert("In setRightLowerFramepage("+uri+")");

	try
	{	
		if (typeof top.rightUpperFrame != "undefined")
		{
			top.rightLowerFrame.location.href = uri;
		}
		else
		{
			if (top.window_handle==null || top.window_handle.closed)
				top.window_handle = window.open('es_lowressatellite.html', 'LowResSatWin', 'width=275, height=400, resizable, scrollable');

			//if (top.window_handle.rightLowerFrame == null) waitForSatelliteRightLowerFrameToLoad()

			// For some reason this uri was not getting set unless it was done multiple times.  
			// This only occured when I was testing remotely and not on the machine running 
			// the webserver.  This is a real hack but it is working
			for (var i=0; top.window_handle.rightLowerFrame.location.pathname!=uri && i<100; i++) 
				top.window_handle.rightLowerFrame.location.href = 'http://' + document.domain + uri;

			top.window_handle.focus();
		}
	}
	catch(ex) {} //For now just ingore the exception, we only get error while in 800x600 mode if user clicks fwy link before satellite window is fully loaded 
}


function openAWindow(url, name, w, h)
{
  reloadGIF();
  // open new window
  popupWin = window.open(url, name, 'status,resizable,scrollbars,width=' + w + ',height=' + h + '');
  // Bring focus to window -- doesn't work with Netscape ;(
  popupWin.focus();
  return popupWin;
}


function openPlaybackWindow(cameraName, cameraLocation)
{
   win = openAWindow("","EScamera", 0,0);
   win.resizeTo(460,550);
   win.document.writeln("<html><head>");
   win.document.writeln("<title>Traffic Cam: " + cameraLocation + "</title>");
   win.document.writeln("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=iso-8859-1\" />");
   win.document.writeln("<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\" />");

   win.document.writeln("<script language=\"javascript\">");
   win.document.writeln("<!-- ");
   win.document.writeln("var m_onlinePath = \"" + m_onlinePath + "\";");
   win.document.writeln("var m_random = Math.round(10000 * Math.random());");
   win.document.writeln("var m_imageURL;");
   win.document.writeln("window.onerror=null;");
   win.document.writeln("function badImageURL() {");
   win.document.writeln("   document.images[0].src = \"" + m_onlinePath + "images/cameras/Cam_NA.jpg\";");
   win.document.writeln("   return true;");
   win.document.writeln("}");
   win.document.writeln("function refreshImage() {");
   win.document.writeln("   document.images[0].src = m_imageURL + \"?" + m_random + "\";");
   win.document.writeln("   setTimeout(\"refreshImage()\",180000);");
   win.document.writeln("}");
   win.document.writeln("function startRefreshTimer(imageURL) {");
   win.document.writeln("   m_imageURL = imageURL;");
   win.document.writeln("   setTimeout(\"refreshImage()\",180000);");
   win.document.writeln("}");

   win.document.writeln("function beginSnapshotPlayback(cameraName, cameraLocation) {");
   win.document.writeln("   win = window.open('','EScamera', 'status,resizable,scrollbars,width=0,height=0');");
   win.document.writeln("   win.resizeTo(460,550);");
   win.document.writeln("   win.document.writeln('<html><head>');");
   win.document.writeln("   win.document.writeln('<title>Fontana Camera: ' + cameraLocation + '</title>');");
   win.document.writeln("   win.document.writeln('<meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;charset=iso-8859-1\\\" />');");
   win.document.writeln("   win.document.writeln('<meta http-equiv=\\\"Content-Script-Type\\\" content=\\\"text/javascript\\\" />');");

   win.document.writeln("   win.document.writeln('<script type=\\\"text/javascript\\\" language=\\\"javascript\\\">');");
   win.document.writeln("   win.document.writeln('var m_imageNdx;');");
   win.document.writeln("   win.document.writeln('var m_imageURL;');");
   win.document.writeln("   win.document.writeln('var m_refreshCtr;');");
   win.document.writeln("   win.document.writeln('var m_timerID;');");
   win.document.writeln("   win.document.writeln('window.onerror=null;');");
   win.document.writeln("   win.document.writeln('function badImageURL() {');");
   win.document.writeln("   win.document.writeln('   return true;');");
   win.document.writeln("   win.document.writeln('}');");
   win.document.writeln("   win.document.writeln('function nextImage() {');");
   win.document.writeln("   win.document.writeln('  if (++m_imageNdx > 10) {');");
   win.document.writeln("   win.document.writeln('     m_imageNdx=1;');");
   win.document.writeln("   win.document.writeln('     if (++m_refreshCtr > 36) return;');");
   win.document.writeln("   win.document.writeln('  }');");
   win.document.writeln("   win.document.writeln('  if (m_imageNdx == 1)');");
   win.document.writeln("   win.document.writeln('    document.images[10].border=0;');");
   win.document.writeln("   win.document.writeln('  else');");
   win.document.writeln("   win.document.writeln('    document.images[m_imageNdx-1].border=0;');");
   win.document.writeln("   win.document.writeln('  document.images[m_imageNdx].border=1;');");
   win.document.writeln("   win.document.writeln('  document.images[m_imageNdx].src = m_imageURL + \\\"_\\\" + m_imageNdx + \\\".jpg?' + m_random + '\\\";');");
   win.document.writeln("   win.document.writeln('  document.images[0].src = document.images[m_imageNdx].src;');");
   win.document.writeln("   win.document.writeln('  m_timerID = setTimeout(\\\"nextImage()\\\",500);');");
   win.document.writeln("   win.document.writeln('}');");
   win.document.writeln("   win.document.writeln('function startPlayback(cameraName) {');");
   win.document.writeln("   win.document.writeln('   m_imageURL = \\\"' + m_onlinePath + 'images/cameras/\\\" + cameraName;');");
   win.document.writeln("   win.document.writeln('   m_imageNdx=0; m_refreshCtr=0;');");
   win.document.writeln("   win.document.writeln('   document.snapshots.status.value=\\\"playing snapshots...\\\";');");
   win.document.writeln("   win.document.writeln('   nextImage();');");
   win.document.writeln("   win.document.writeln('}');");
   win.document.writeln("   win.document.writeln('function stopPlayback(imageNdx) {');");
   win.document.writeln("   win.document.writeln('  clearTimeout(m_timerID);');");
   win.document.writeln("   win.document.writeln('  if (imageNdx == m_imageNdx) {');");
   win.document.writeln("   win.document.writeln('    document.snapshots.status.value=\\\"playing snapshots...\\\";');");
   win.document.writeln("   win.document.writeln('     nextImage();');");
   win.document.writeln("   win.document.writeln('  } else {');");
   win.document.writeln("   win.document.writeln('    document.snapshots.status.value=\\\"pausing playback...(click outlined snapshot to restart playback)\\\";');");
   win.document.writeln("   win.document.writeln('    document.images[m_imageNdx].border=0;');");
   win.document.writeln("   win.document.writeln('    m_imageNdx = imageNdx;')");
   win.document.writeln("   win.document.writeln('    document.images[imageNdx].border=1;');");
   win.document.writeln("   win.document.writeln('    document.images[imageNdx].src = m_imageURL + \\\"_\\\" + imageNdx + \\\".jpg?' + m_random + '\\\";');");
   win.document.writeln("   win.document.writeln('    document.images[0].src = document.images[imageNdx].src;');");
   win.document.writeln("   win.document.writeln('  }');");
   win.document.writeln("   win.document.writeln('}');");
   win.document.writeln("   win.document.writeln('</script>');");

   win.document.writeln("   win.document.writeln('</head><body onload=\\\"startPlayback(\\\'' + cameraName + '\\\');\\\">');");
   win.document.writeln("   win.document.writeln('<form name=\\\"snapshots\\\"><table border=\\\"0\\\" cellspacing=\\\"0\\\" cellpadding=\\\"0\\\">');");
   win.document.writeln("   win.document.writeln('<tr><td background=\\\"' + m_onlinePath + 'images/cameras/Cam_NA400.jpg\\\"><center><img width=\\\"400\\\" height=\\\"300\\\" src=\\\"' + m_onlinePath + 'images/cameras/\" + cameraName + \"_1.jpg?\" + m_random + \"\\\" onError=\\\"javascript:return badImageURL();\\\" /></center></td></tr>');");
   win.document.writeln("   win.document.writeln('<tr><td><center><input name=\\\"status\\\" size=\\\"60\\\" value=\\\"loading snapshots...(may take a few minutes on slow connections)\\\" /></center></td></tr>');");
   win.document.writeln("   win.document.writeln('<tr><td><center><img width=\\\"30\\\" src=\\\"' + m_onlinePath + 'images/cameras/' + cameraName + '_1.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(1);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + m_onlinePath + 'images/cameras/' + cameraName + '_2.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(2);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + m_onlinePath + 'images/cameras/' + cameraName + '_3.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(3);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + m_onlinePath + 'images/cameras/' + cameraName + '_4.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(4);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + m_onlinePath + 'images/cameras/' + cameraName + '_5.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(5);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + m_onlinePath + 'images/cameras/' + cameraName + '_6.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(6);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + m_onlinePath + 'images/cameras/' + cameraName + '_7.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(7);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + m_onlinePath + 'images/cameras/' + cameraName + '_8.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(8);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + m_onlinePath + 'images/cameras/' + cameraName + '_9.jpg?'  + m_random + '\\\" onClick=\\\"javascript:stopPlayback(9);\\\" />');");
   win.document.writeln("   win.document.writeln('<img width=\\\"30\\\" src=\\\"' + m_onlinePath + 'images/cameras/' + cameraName + '_10.jpg?' + m_random + '\\\" onClick=\\\"javascript:stopPlayback(10);\\\" /></center></td></tr>');");
   win.document.writeln("   win.document.writeln('<tr><td><center>This snapshot series is regenerated every 5 minutes.</center></td></tr>');");
   win.document.writeln("   win.document.writeln('<tr><td><center><font face=\\\"arial, helvetica\\\" size=\\\"2\\\"><br />');");
   win.document.writeln("   win.document.writeln('The camera snapshots are provided courtesy of<br />');");
   win.document.writeln("   win.document.writeln('<a href=\\\"http://www.fontana.org/\\\" target=\\\"_blank\\\">City of Fontana, California, Traffic Operations</a><br /></font>');");
   win.document.writeln("   win.document.writeln('<font face=\\\"arial, helvetica\\\" size=\\\"1\\\">&copy;2002 Iteris, Inc</font></center></td></tr>');");
   win.document.writeln("   win.document.writeln('</table></form></body></html>');");
   win.document.writeln("   win.document.close();");
   win.document.writeln("   win.focus();");
   win.document.writeln("}");

   win.document.writeln("// -->");
   win.document.writeln("</script>");

   win.document.writeln("</head><body onload=\"javascript:startRefreshTimer('" + m_onlinePath + "images/cameras/" + cameraName + "_1.jpg');\">");
   win.document.writeln("<form><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
   win.document.writeln("<tr><td><center><img width=\"400\" height=\"300\" src=\"" + m_onlinePath + "images/cameras/" + cameraName + "_1.jpg?" + m_random + "\" onError=\"javascript:return badImageURL();\" /></center></td></tr>");
   win.document.writeln("<tr><td><center>This snapshot image is regenerated every 5 minutes.</center></td></tr>");
   win.document.writeln("<tr><td><br /><center><font face=\"arial, helvetica\">If you have a high-speed internet connection, you can<br />");
   win.document.writeln("try our new<input type=\"submit\" value=\"SnapShot Playback\" onclick=\"javascript:beginSnapshotPlayback('" + cameraName + "','" + cameraLocation + "');\">mode.<br />");
   win.document.writeln("<font color=#ff0000 size=\"1\"><b>[NOT RECOMMENDED FOR DIALUP INTERNET CONNECTIONS]</b></font></font></center></td></tr>");
   win.document.writeln("<tr><td><center><br /><font face=\"arial, helvetica\" size=\"2\">");
   win.document.writeln("The camera snapshots are provided courtesy of<br />");
   win.document.writeln("<a href=\"http://www.fontana.org/\" target=\"_blank\">City of Fontana, California, Traffic Operations</a><br /></font>");
   win.document.writeln("<font face=\"arial, helvetica\" size=\"1\">&copy;2002 Iteris, Inc</font></center></td></tr>");
   win.document.writeln("</table></form></body></html>");
   win.document.close();
}


function openCaltranCameraWindow(cameraName, cameraLocation, imageURL)
{
   win = openAWindow("","EScamera", 0,0);
   win.resizeTo(380,400);
   win.document.writeln("<html><head>");
   win.document.writeln("<title>Caltrans Camera</title>");
   win.document.writeln("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=iso-8859-1\" />");
   win.document.writeln("<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\" />");

   win.document.writeln("<script type=\"text/javascript\" language=\"javascript\">");
   win.document.writeln("<!-- ");
   win.document.writeln("var m_imageURL;");
   win.document.writeln("window.onerror=null;");
   win.document.writeln("function refreshImage() {");
   win.document.writeln("   document.images[0].src = m_imageURL + \"?\" + Math.random();");
   win.document.writeln("   setTimeout(\"refreshImage()\",120000);");
   win.document.writeln("}");
   win.document.writeln("function startRefreshTimer(imageURL) {");
   win.document.writeln("   m_imageURL = imageURL;");
   win.document.writeln("   setTimeout(\"refreshImage()\",120000);");
   win.document.writeln("}");
   win.document.writeln("// -->");
   win.document.writeln("</script>");

   win.document.writeln("</head><body onload=\"javascript:startRefreshTimer('" + imageURL + "');\">");
   win.document.writeln("<table border=0 cellspacing=0 cellpadding=0>");
   win.document.writeln("<tr><td background=\"" + m_onlinePath + "images/cameras/Cam_NA320.jpg\"><center><img width=\"320\" height=\"240\" src=\"" + imageURL + "?" + m_random + "\" /></center></td></tr>");
   win.document.writeln("<tr bgcolor=\"BLACK\"><td><center><font size=2 color=\"WHITE\">" + cameraLocation + "</font></center></td></tr>");
   win.document.writeln("<tr><td><center><font face=\"arial, helvetica\" size=\"2\"><br />");
   win.document.writeln("The snapshot image is provided courtesy of<br />");
   win.document.writeln("<a href=\"http://www.dot.ca.gov/dist8/\" target=\"_blank\">Caltrans District 8, San Bernadino</a><br /></font>");
   win.document.writeln("<font face=\"arial, helvetica\" size=\"1\">&copy;2004 Iteris, Inc</font></center></td></tr>");
   win.document.writeln("</table></body></html>");
   win.document.close();
   win.focus();
}


function openRealPlayerWindow(imageURL)
{
   win = openAWindow("","EScamera", 0,0);
   win.resizeTo(395,430);
   win.document.writeln("<html><head><title>Caltrans Camera</title></head>");

   win.document.writeln("<frameset rows=325,100 frameborder=\"NO\" border=\"0\" framespacing=\"0\">");
   win.document.writeln("  <frame name=\"video\" scrolling=\"NO\" noresize src=\"" + imageURL + "\">");
   win.document.writeln("  <frame name=\"player warning\" scrolling=\"NO\" noresize src=\"" + m_onlinePathHTML + "RealPlayerWarning.html\">");
   win.document.writeln("</frameset>");
   win.document.writeln("<noframes><body bgcolor=\"#FFFFFF\">");
   win.document.writeln("I'm sorry, Your browser does not support frames.<br />");
   win.document.writeln("<a href='" + imageURL + "'>Click here</a> to continue on to the Caltrans streaming video page.<br />");
   win.document.writeln("To view this streaming video, you will need the free RealPlayer plugin.");
   win.document.writeln("</body></noframes></html>");

   win.document.close();
   win.focus();
}


function openRealPlayerWindowStream(imageURL)
{
  win = openAWindow("","EScamera", 0,0);
  win.resizeTo(450,550);
  win.document.writeln("<html><head><title>Streaming Camera</title></head>");
  win.document.writeln("<body bgcolor='#FFFFFF'>");
   
   
  win.document.writeln('<object id="MediaPlayer1" width=400 height=350 classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"  standby="Loading Microsoft® Windows® Media Player components..." type="application/x-oleobject" align="middle">');
  win.document.writeln('<param name="FileName" value="'+ imageURL +'">');
  win.document.writeln('<param name="ShowStatusBar" value="true">');
  win.document.writeln('<param name="AutoStart" value="true">');
  win.document.writeln('<param name="DefaultFrame" value="mainFrame">');
  win.document.writeln('<embed type="application/x-mplayer2" pluginspage = "http://www.microsoft.com/Windows/MediaPlayer/" src="'+ imageURL +'" align="middle" width=400 height=350 defaultframe="rightFrame" showstatusbar="true"></embed>');
  win.document.writeln('</object>');
    win.document.writeln("<BR><BR><FONT SIZE='2' FACE='Tahoma' >To view this streaming video, you will need the free Windows Media Player plugin.  You can downoad it <A HREF='http://www.microsoft.com/windows/windowsmedia/download/AllDownloads.aspx?displang=en&qstechnology' target='_new'>here.</A>");

  win.document.writeln("</body></html>");

  win.document.close();
  win.focus();
}


function leavingSite(newSiteHREF, newSiteName)
{
   //reloadGIF();
   win = window.open('');
   win.document.writeln("<html><head>");
   win.document.writeln("<title>You Are Now Leaving the El Segundo Area ITS Traffic Web Site</title>");
   win.document.writeln("	<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>");
   win.document.writeln("	<meta name='Posted' contents='02/19/2003'>");
   win.document.writeln("</head><body bgcolor='#FFFFFF'>");
   win.document.writeln("<hr align='center' width='80%'>");
   win.document.writeln("<br clear=all />");
   win.document.writeln("<p align=center><font size=+2 color='navy'><b>You Are Now Leaving the<br />El Segundo Area ITS Traffic Information<br />Web Site</b></font></p>");
   win.document.writeln("<br clear=all />");
   win.document.writeln("<hr align='center' width='80%'>");
   win.document.writeln("<table width='70%' align='center'>");
   win.document.writeln("<tr><td>");
   win.document.writeln("<p align='center'><br><B>You are about to access <A href='"+newSiteHREF+"'>"+newSiteName+"</a></B><br><br></p>");
   win.document.writeln("</td></tr>");
   win.document.writeln("<tr><td><p align='justify'><font size='+1'><strong>Please note:</strong></font>");
   win.document.writeln("&nbsp;&nbsp; Links to web sites outside of this Traffic Information site are offered for your convenience");
   win.document.writeln(" in accessing related information. Please be aware that when you exit this web site,");
   win.document.writeln(" you are subject to the privacy policy of the new site. ");
   win.document.writeln("&nbsp;The El Segundo Area ITS does not attest to the accuracy of information provided by linked sites,");
   win.document.writeln(" and such information does not necessarily represent the viewpoint of the El Segundo Area ITS. </p>");
   win.document.writeln("</td></tr></table>");
   win.document.writeln("<p><div align='center'></div>");
   win.document.writeln("<P></P>");
   win.document.writeln("<br /><p align='center'>");
   win.document.writeln("<A href='"+newSiteHREF+"'>Continue</a>");
   win.document.writeln("&nbsp;&nbsp; <B>OR</B> &nbsp;&nbsp;");
   win.document.writeln("<a href='javascript:window.close()'>Close Window</a>");
   win.document.writeln("</p><br><center><p><b>Thank you for visiting.</b></p></center></td>");
   win.document.writeln("<td width='76'></td></tr></table></font>");
   win.document.writeln("</body></html>");
   win.document.close();
   win.focus();
}


//
// Parses the mapview number from the given URL string.
// e.g. Given "?7" returns 7.
//
function parseMapQSViewNumber(queryString)
{
	try
	{
		var viewNumber = unescape(queryString.substring(1,queryString.length));
		return (viewNumber==null || viewNumber=='' ? m_defaultViewNumber : viewNumber);
	}
	catch(ex) { return m_defaultViewNumber; } 
}


//
// This is a stub to allow the "hide" link to not generate an error on old es_ttXXX.html pages.
// This stub function can be removed once the data collector can be recompiled.
//
function loadTravelTime(param) {}



//-----------------------------------------------------------------------------
