<!-- Copyright (c) 1998 - 2004 Jaytu Technologies.  All rights reserved. -->

function
ste(strRamp, x, y, iRoadBeginIndex, iSpeed, iHovSpeed, strRoad)
{
	this.Ramp= strRamp;
	this.X= x;
	this.Y= y;
	this.RoadBeginIndex= iRoadBeginIndex;
	this.Speed= iSpeed;
	this.HovSpeed= (null == iHovSpeed) ? -1 : iHovSpeed;
	this.Road= (null == strRoad) ? '' : strRoad;
}

function
v(strRamp, x, y, iSpeed, iHovSpeed, strRoad)
{
	if (null != strRoad)
		iCurrentRoadBeginIndex= iCurrentRamp;

	as[iCurrentRamp++]= new ste(strRamp, x, y, iCurrentRoadBeginIndex, iSpeed, iHovSpeed, strRoad);
}

function
SpeedPopup(iRamp)
{
	var iRoad= as[iRamp].RoadBeginIndex;
	var strRoad= as[iRoad].Road;
	var bReverse= (strRoad.search("North") >= 0) || (strRoad.search("West") >= 0);

	var strRows= "";
	var i= iRamp - 2;

	if (i < iRoad)
		i= iRoad;

	var j= i;
	var bHasHov= false;

	do
	{
		if (as[j].HovSpeed > 0)
		{
			bHasHov= true;
			break;
		}

		j++;
	} while ((j <= iRamp + 2) && ('' == as[j].Road));
	
	var iRowCounter = 0;
	do
	{
		if (null != as[i])
		{
			var strRowStyle = "StdListRow" + (0 == iRowCounter++ % 2? "1":"2");
			var strThisRow= "<tr>";
			
			var strExtraStyle = "padding: 1px;";
			if (i== iRamp)
				strExtraStyle += "border-top: 1px dashed #000000; border-bottom: 1px dashed #000000;";
			
			var iSpeed= as[i].Speed;
			var strSpeedTier= SpeedTier(iSpeed);

			strThisRow += "<td nowrap class=" + strRowStyle + " style='" + strExtraStyle + "'>";
			strThisRow += ((i == iRamp) ? as[i].Ramp.bold() : as[i].Ramp) + "&nbsp;</td>";

			var strSpeedCellClass = ("Fast" == strSpeedTier || iSpeed < 0? strRowStyle: "Speed" + strSpeedTier);
			strThisRow += "<td class=" + strSpeedCellClass + " nowrap align=right style='" + strExtraStyle + "'>&nbsp;";
			var strSpeed= (iSpeed > 0) ? (iSpeed + " mph") : "N/A";
			strThisRow += strSpeed;
			strThisRow += "&nbsp;</td>";

			if (bHasHov)
			{
				iSpeed= as[i].HovSpeed;
				strSpeed= iSpeed + " mph";
				strSpeedTier= SpeedTier(iSpeed);

				if (iSpeed > 0)
				{
					strSpeedCellClass = ("Fast" == strSpeedTier || iSpeed < 0? strRowStyle: "Speed" + strSpeedTier);
					strThisRow += "<td class='" + strSpeedCellClass + "' nowrap align='right' style='" + strExtraStyle + "'>&nbsp;" + strSpeed + "&nbsp;</td>";
				}
				else
					strThisRow += "<td class=" + strRowStyle + " style='" + strExtraStyle + "'>&nbsp;</td>";
			}

			strThisRow += "</tr>\r\n";

			if (bReverse)
				strRows= strThisRow + strRows;
			else
				strRows += strThisRow;
		}

		i++;
	} while ((i <= iRamp + 2) && ('' == as[i].Road));

	strRows +=	"</table><div class=DetailsLink>Click a dot for more speeds</div>";

	var strBody =	"<table class='StdList' width=100% cellpadding=0 cellspacing=0 style='border: 0px;'>" + 
						(bHasHov ? "<tr><td colspan=2 class=StdListHeader2>&nbsp;</td><td align=center class=StdListHeader2><img src='" + strImageDir + "/CarPool.gif'></td></tr>" : "") +
						strRows;

	ShowMapPopup(strRoad, strBody, -1)
}

function ite(id, strTime, strType, strLocation, x, y)
{
	this.Id= id;
	this.Time= strTime;
	this.Type= strType;
	this.Location= strLocation;
	this.X= x;
	this.Y= y;
}

function
a(id, strTime, strType, strArea, strLocation, x, y)
{
	ai[iCurrentIncident++]= new ite(id, strTime, strType, strArea, strLocation, x, y);
}

function
IncidentPopup(i)
{
	var strRow = "<span style='white-space: nowrap'>";
	strRow +=	"<b>" + ai[i].Type + "</b><br>";
	strRow +=		ai[i].Location + "<br>";
	strRow +=		"Occurred at " + ai[i].Time + "</span>";

	var strSponsorPopupHTML = (bIsActiveUser? "":document.getElementById("divPopupInsert").innerHTML);

	var strBody =	"<table class='StdList' cellpadding=0 cellspacing=0 style='border: 0px;'>" + 
						("" == strSponsorPopupHTML ? "" : "<tr><td align=center nowrap class='StdListRow1'>" + strSponsorPopupHTML + "</td></tr>") +
						"<tr><td class='StdListRow1'>" + strRow + "</td></tr></table><div class=DetailsLink>Click the diamond for details</div>";

	ShowMapPopup("Traffic Accident", strBody, -1);
}

function
cte(id, strRoad, strDesc, strUrl, x, y)
{
	this.Id= id;
	this.Road= strRoad;
	this.Description= strDesc;
	this.Url= strUrl;
	this.X= x;
	this.Y= y;
}

function
c(id, strRoad, strDesc, strUrl, x, y)
{
	ac[iCurrentCamera++]= new cte(id, strRoad, strDesc, strUrl, x, y);
}

var dtNextImageLoadTime = new Date(1990,1,1);
function
GenerateImageTimeStamp()
{
	var dtNow = new Date();

	if (dtNow > dtNextImageLoadTime)
	{
		dtNextImageLoadTime = dtNow;
		dtNextImageLoadTime.setSeconds(dtNextImageLoadTime.getSeconds() + 60)
	}

	return	dtNextImageLoadTime.getFullYear().toString() +
				dtNextImageLoadTime.getMonth().toString() + 
				dtNextImageLoadTime.getDate().toString() +
				dtNextImageLoadTime.getHours().toString() +
				dtNextImageLoadTime.getMinutes().toString();
}

function
CameraPopup(i)
{
	var strLink;
	var strBody;
	var strCaption = "<b>" + ac[i].Road + " at " + ac[i].Description + "</b>";

	if (bIsActiveUser || bFreeCameras)
	{
		var strCamURL = ac[i].Url;
		if (-1 == strCamURL.indexOf("?"))
			strCamURL += "?" + GenerateImageTimeStamp();
		else
			strCamURL += "&" + GenerateImageTimeStamp();
		
		strLink=	"<img name='TheImage' src='" + strCamURL + "' border=0 width=352 height=258>";
		strBody=	"<div class='PopUpBody' style='text-align: center;'>" + strLink
					+ "<br>" + strCaption
					+ '<div class="CameraPopupDetails">Note:  The lanes at the bottom of the photo are on ' + ac[i].Road + '</div>';

		if (bFreeCameras && !bIsActiveUser)
			strBody += '<div style="background-color: #595994; color: #ffffff;padding-bottom: 2px;"><b>Camera Beta</b><br>' +
							'These cameras are available for a limited time only to visitors without a My Sigalert account. Please click on the Cameras link near the top of the page for details.</div>';
		
		strBody +=	'</div>';		// Close PopUpBody div
	}
	else
	{
		strLink=	'<img name="TheImage" src="' + strImageDir + '/CameraSample.jpg" border=0>';
		strBody=	"<div class='PopUpBody' style='text-align: center;'>" + strLink
					+ "<br>" + strCaption
					+ '<div class="CameraPopupDetails">Live photos for My Sigalert users only. <a href=\'javascript:GotoPage(\"AboutMySa.asp\")\'>Click here for details.</a></div></div>';
	}

	ShowMapPopup(strCaption, strBody, 352);
}

function
ShowMapPopup(strCaption, strBody, iWidth, iTimeoutMS)
{
	if (bSupportPopups)
	{
		if ("undefined" == typeof(iTimeoutMS))
			iTimeoutMS = 10000;

		var bSetWrap = false;

		if (iWidth < 0)
		{
			iWidth=500;
			bSetWrap = true;
		}

		var oRadios = document.PopupPositionForm.PopupPosition;
		var strPopupPositionSetting = "m";
		for (var i=0; i < oRadios.length; i++)
		{
			if (oRadios[i].checked)
				strPopupPositionSetting = oRadios[i].value;
		}
		
		var strCloseText = 	"<img 	src='" + strImageDir + "/Hide.gif?cb=1'";
		strCloseText +=		"			border=0 height=12 width=12 name='imgMapPopupHide'";
		strCloseText +=		"			onmouseover='document.imgMapPopupHide.src=\"" + strImageDir + "/HideHover.gif?cb=1\"'";
		strCloseText +=		"			onmouseout='document.imgMapPopupHide.src=\"" + strImageDir + "/Hide.gif?cb=1\"'>";

		switch(strPopupPositionSetting)
		{
			case "n":
				break;
			case "f":
				overlib(	strBody,
							CAPTION, strCaption,
							STICKY,
							TIMEOUT, iTimeoutMS,
							(bSetWrap? WRAP:DONOTHING),
							WIDTH, iWidth,
							RELX, -4,
							RELY, 4,
							CELLPAD, 0,
							FGCLASS, "MapPopupBackground",
							BGCOLOR, "#000000",
							CAPTIONFONTCLASS, "MapPopupCaption",
							CLOSEFONTCLASS, "MapPopupCaptionClose",
							CLOSECLICK,
							CLOSETEXT, strCloseText,
							SHADOW,
							SHADOWCOLOR, "#000000",
							SHADOWX, -3,
							SHADOWY, 3,
							SHADOWOPACITY, 50,
							TEXTSIZE, 2);
				break;
			default:
				overlib(	strBody,
							CAPTION, strCaption,
							STICKY,
							TIMEOUT, iTimeoutMS,
							(bSetWrap? WRAP:DONOTHING),
							WIDTH, iWidth,
							OFFSETX, 50,
							OFFSETY, 50,
							FOLLOWMOUSE,
							CELLPAD, 0,
							HAUTO, VAUTO,
							FGCLASS, "MapPopupBackground",
							BGCOLOR, "#000000",
							CAPTIONFONTCLASS, "MapPopupCaption",
							CLOSEFONTCLASS, "MapPopupCaptionClose",
							CLOSECLICK,
							CLOSETEXT, strCloseText,
							SHADOW,
							SHADOWCOLOR, "#000000",
							SHADOWX, -3,
							SHADOWY, 3,
							SHADOWOPACITY, 50,
							TEXTSIZE, 2);
		}
	}
}


function
GetRelatedMapHTML(strRegionEncoded, strDisplayName)
{
	return "<br>&nbsp;&nbsp;<a class='MenuItem' href='/map.asp?Region=" + strRegionEncoded + strPartnerQS + "'>" + strDisplayName + "</a>"
}

function
PopupRelatedMaps(strMap)
{
	if (bSupportPopups)
	{
		var strBody = "<b>Choose another map:</b>";

		if(("" == strSponsorRegionList || strSponsorRegionList.indexOf("SoCal") >= 0) && "Bay Area Sacramento Phoenix".indexOf(strRegion) < 0)
		{
			strBody +=	("LA West" != strMap? GetRelatedMapHTML("LA+West", "West Los Angeles County"):"");
			strBody +=	("LA East" != strMap? GetRelatedMapHTML("LA+East", "East Los Angeles County"):"");
			strBody +=	("Orange County" != strMap? GetRelatedMapHTML("Orange+County", "Orange County"):"");
			strBody +=	("Greater Los Angeles" != strMap? GetRelatedMapHTML("Greater+Los+Angeles", "L.A. and Orange County"):"");
			strBody +=	("Ventura" != strMap? GetRelatedMapHTML("Ventura", "Ventura"):"");
			strBody +=	("Inland Empire" != strMap? GetRelatedMapHTML("Inland+Empire", "Inland Empire"):"");
			strBody +=	("San Diego" != strMap? GetRelatedMapHTML("San+Diego", "San Diego"):"");
		}

		if(("" == strSponsorRegionList || strSponsorRegionList.indexOf("NoCal") >= 0) && "Bay Area Sacramento Phoenix".indexOf(strRegion) >= 0)
		{
			strBody +=	("Bay Area" != strMap? GetRelatedMapHTML("Bay+Area", "San Francisco Bay Area"):"");
			strBody +=	("Sacramento" != strMap? GetRelatedMapHTML("Sacramento", "Sacramento"):"");
		}

		overlib(	strBody,
					STICKY,
					MOUSEOFF,
					WIDTH, 200,
					TIMEOUT, 10000,
					FGCLASS, "MenuPopupBackground",
					BGCOLOR, "",
					SHADOW,
					SHADOWCOLOR, "#000000",
					SHADOWX, -3,
					SHADOWY, 3,
					SHADOWOPACITY, 50,
					HAUTO, VAUTO,
					TEXTSIZE, 2)
	}
}

function
SigalertLogoPopup()
{
	if (bSupportPopups)
	{
		var strBody =	"<center><font size=+1><b>Try My Sigalert for FREE</b></font></center>";
		strBody +=		"<p><li>See how long it will take to get home"
		strBody +=		"<li>Get traffic alerts sent to your phone";
		strBody +=		"<li>No Web site advertisements";
		strBody +=		"<li>And more...";

		strBody +=		"<p><center><b><a href='javascript:GotoAboutMySa()'>Click here for more information</b>";

		if (!bIsActiveUser)
		{
			overlib(	strBody,
						STICKY,
						MOUSEOFF,
						WRAP,
						TIMEOUT, 40000,
						OFFSETX, -2,
						OFFSETY, -10,
						FGCLASS, "MenuPopupBackground",
						BGCOLOR, "",
						SHADOW,
						SHADOWCOLOR, "#000000",
						SHADOWX, -3,
						SHADOWY, 3,
						SHADOWOPACITY, 50,
						HAUTO, VAUTO,
						TEXTSIZE, 2)
		}
	}
}

function
SetPopupPositionDefault(str)
{
	if (bSupportPopups)
		WriteCookie("MPP", str, strCookieDomain, true);
}
