 	/* station object and related functions */
    function station(cnt,id,code,lat,_long, glat, glong, name, address, city_state,alert_status, alert_x,alert_y,alert_msg,lines)
    {	
	var cnt;
	var id;
	var code;
	var name;
	var lat;
	var _long;
	var glat;
	var glong;
	var popup_html;
	var ph;
	var pm;
	var pf;
	var ld;
	var alert_status;
	var alert_x;
	var alert_y;
	var last_updated;
	var alert_popup_html;
	var addr;
	var city_st;
	var al_mes;
	var lines;
	var st_mk_ar_pos;
	var al_mk_ar_pos;
	var dist;

	this.cnt = cnt;
	this.id = id;
	this.code = code;
	this.name = name;
	this.lat = lat;
	this._long= _long;
	this.glat = glat;
	this.glong = glong;	
	this.lines = lines;
	this.ph = st_popup_header(id);
	this.pm = st_info(id,name, address, city_state,alert_msg);
	this.alert_status = alert_status;
	this.alert_x = alert_x;
	this.alert_y = alert_y;
	this.addr = address;
	this.city_st = city_state;	
	//this.last_updated = _time;
	
	this.st_mk_ar_pos = -1;
	this.al_mk_ar_pos = -1;
	this.alert_popup_html = "";	
	if (alert_status ==1)
	{
		this.alert_popup_html = alertPopup(id,name, alert_msg);
	} 

}   
	// due to logic change popup is broken into sections, cause next train data has to be loading into popup via ajax;
	/* st_popup_header */
    function st_popup_header(id)
    {
	var str_html;	
	
	str_html = "<div id='station_popup"+id+"' class='infoWin'>";
	str_html += "<table border='0' cellspacing='0' cellpadding='0'>";
	str_html += "<tr><td>";
	str_html += "<table border='0' class='col2'>";
	str_html += "<tr><td class='dots' valign='top'>";

	return str_html;
    }    
     /* st_lines - line circlel images */
  function st_lines(lns)
  {
    
	//lns string seperates by -
	var ar = [];
	if (lns.indexOf("-") ==-1)
	{
		ar.push(lns);
	}else
	{
		ar = lns.split('-');
	}
	
	var str_html ="";

	for (var x=0; x < ar.length ; x++)
	{	
		str_html += setLineImg(ar[x].toLowerCase(),"b");				
	}
	return str_html;

  }
	/* station alerts - disruptions, elevator and escalator alerts  */
  function st_alerts(d_al,el_al,ecs_al,st_obj)
   {
	var str_html = "";		
	str_html += "</td><td align='right' valign='top' class='el_esc_info'>";	
	str_html += "<table border='0' class='alerts'><tr><td class='alert_tag'><img src='img/alerts_tag.gif' alt='ALERTS' title='Alerts are shown in color. Mouse over icons for the alerts'/></td>";	
	/*
	if (d_al > 0)
	{	
		// different alert link based on map type
		if (mt == "rail") 
		{
			str_html += "<td width='20'><a href='#'  onclick='closePopOpnAlrt(\""+st_obj.st_mk_ar_pos+"\",\""+st_obj.al_mk_ar_pos+"\")' ><img src='img/alert_on.gif' alt='Rail Alerts' title='Rail Alert !' /></a></a></td>";
		}
		else
		{
			str_html += "<td width='20'><a href='/rail/station_detail.cfm?station_id="+st_obj.id+"'><img src='img/alert_on.gif' alt='Rail Alerts' title='Rail Alert !' /></a></a></td>";
		}
		
	}
	else
	{
		str_html += "<td width='20'><img src='img/alert_off.gif' alt='No Rail Alert' title='No Rail Alert' /></td>";
	}	
	*/

	if (el_al > 0)
	{
		str_html += "<td width='20'><a href='/rail/station_detail.cfm?station_id="+st_obj.id+"'><img src='img/elevator_on.gif' alt='Elevator Alert' title='Elevator Alert !' /></a></td>";

	}
	else
	{
		str_html += "<td width='20'><img src='img/elevator_off.gif' alt='No Elevator Alert' title='No Elevator Alert' /></td>";

	}
	
	if (ecs_al > 0)
	{
		str_html += "<td width='20'><a href='/rail/station_detail.cfm?station_id="+st_obj.id+"'><img src='img/escalator_on.gif' alt='Escalator Alert' title='Escalator Alert !' /></a></td>";

	}
	else
	{
		str_html += "<td width='20'><img src='img/escalator_off.gif' alt='No Escalator Alert' title='No Escalator Alert' /></td>";

	}
	str_html += "</tr></table></td></tr>";
	str_html += "</table>";
	return str_html;
   }
   /* -- end popup-up header --*/
   
   	/* st_info - station address info */
    function st_info(id,name, address, city_state,alrt_msg)
    {
	var str_html;

	str_html ="</td></tr>";
	str_html += "<tr><td>";
	str_html += "<span id='station_link'><a style='color:#0A94d6;' href='/rail/station_detail.cfm?station_id="+id+"'>"+name+"</a></span>";
	str_html +="</td></tr>";
	str_html += "<tr><td class='header2'>";
	str_html += address +"<br>";
	str_html += city_state;
	str_html +="</td></tr>";
	str_html += "<tr><td>";

	return str_html;
    }

	/* st_train_data - display train data */
	//train/destination must be unique, group tains by color
       /*st_train_data   */
  function st_train_data(ntda,_time, stlc, stid)
   {
	var str_html;
	var str_tmp;
	var exists;	
	var tt = []; 
	var tr_d = []; 
	var ar = [];
	var ntd = [];
	var tc = [];	
	
	if (stlc.indexOf("-") ==-1)
	{
		tc.push(stlc);
	}else
	{
		tc = stlc.split("-");
	}
	
	str_html = "<span class='header3'>NEXT TRAIN ARRIVALS (UPDATED "+_time+") <a href='/rider_tools/pids/showpid.cfm?station_id="+stid+"' onclick='javascript:window.open(this.href,\"pidsWindow\",\"width=350,height=600\"); return false;'><img title='Load Station Pop-up window' alt='Load Station Pop-up window' src='img/cascade.jpg'></a></span>";
	str_html +="</td></tr>";
	str_html += "<tr><td class='line_info'>";
	//get data into better usable array ,loop through next train info 
	ar = ntdata_ar2(ntda);	
	if (ar.length > 0)
	{
	str_html += "<ul>";
	for (var x=0; x < ar.length ; x++)
	{
		str_tmp = "";						
		
		if (ar[x][1] !="" && ar[x][2] !="")
		{
			exists = false;
			for (var y=0; y < tr_d.length ; y++)
			{
				if (ar[x][1]==tr_d[y])
				{
					exists = true;
				}
			}

			if (! exists)
			{
		
			tt = []; 
			var imgstr;
			exists = false;			
			imgstr = setLineImg(ar[x][0].toLowerCase().substring(0,1),"s");
			str_tmp = "<li>"+imgstr+"  "+ar[x][1]+" - ";
			var cntr =0;

				for (var i=0; i < ar.length ; i++)
				{	
					if (ar[x][1]==ar[i][1])
					{
						if (ar[i][2].length >0)
						{
							if (cntr >0)
							{
								//str_tmp += " - ";
								//str_html += " - ";
							}
																				
							// add train data to array
							//str_tmp += formatTraiTime(ar[i][2]); //traim times
							tt.push(ar[i][2]);							
							cntr ++;					
						}				
					}																		

				}
			
			str_tmp += formatTraiTime2(tt);
			str_tmp += "</li>";
			tr_d.push(ar[x][1]);
			//train color , html data			
			ntd.push([ar[x][0],str_tmp])
			}
		}
	}	
	//group trains by color	
		for (var i=0; i < tc.length ; i++)
		{
			for(var n=0; n < ntd.length ; n++)
			{
				if (tc[i].substring(0,1) == ntd[n][0].substring(0,1))
				{
				str_html += ntd[n][1];
				}
			}
	
		}	
		str_html +="</ul>";
	}
	else
	{
	str_html +="<p>No arrival data currently available<p>";
	}
	str_html += "</td></tr>";	
	return str_html;
   }
   
	/* st_popup_footer - popup footer */
   function st_popup_footer(station_obj)
   {
	var str_html;	
	str_html = "<tr><td id='popup_links' align='center'>";
	//check map type for links (var- mt )
	if (mt == "rail")
	{
		
		str_html += "<a href='#' onclick='load2(\""+station_obj.glat+"\",\""+station_obj.glong+"\",\"15\",\"st\",\""+station_obj.cnt+"\")';>Google Map</a>";

	}
	else
	{
		str_html += "<a href='#' onclick='load(\""+station_obj.cnt+"\")';>Rail Map</a>";
		//str_html += "<a href='#' >Rail Map</a>";

	}
	str_html += " | <a href='#' onclick='openNBSearch("+station_obj.cnt+")'>Search Nearby</a>";
	//str_html += " | <a href='#' onclick='showSndToPhone("+station_obj.cnt+")' >Send to Phone</a>";
	str_html +="</td></tr>";
	str_html += "<tr><td class='empty_height'></tr><td>";
	str_html += "</table>";
	str_html += "<br><br><br>";
	str_html += "</div>"
			
	return str_html;
   }

	/* alertPopup - station alert/disruption popup */
   function alertPopup(id,name, alert_msg,line)
    {
	var str_html;
	var imgstr = "img/alert_medium.gif";

	str_html = "<div id='station_alert"+id+"' class='infoWin'>";
	str_html += "<table border='0' cellspacing='0' cellpadding='0'>";
	str_html += "<tr><td class='empty_height'></tr><td>";
	str_html += "<tr><td>";
	str_html += "<span class='header1'>";
 	str_html += "<img src='"+imgstr+"' border='0' align='top' alt='Station Alert'>  ";
	str_html += "<span id='station_link'><a href=''>"+name+"</a></span>";
	str_html += "</span>";
	str_html += "</td></tr>";
	str_html += "<tr><td >";
	str_html += "<ul class='header2' style='width: 300px'>";	
	//loop through array of messages
	for (var x=0; x < alert_msg.length; x++)
	{
		if (alert_msg[x] != "ESC" && alert_msg[x] != "ESC") 
		{
			str_html += "<li>";
			str_html += alert_msg[x];
			str_html += "</li>";
		}

	}
	str_html += "</ul>";
	str_html += "</td></tr>";
	str_html += "</table>";
	str_html += "<br>";
	str_html += "</div>";

	return str_html;
    }
   
     /* openNBSearch - search near by info window */
   function createNBSearchPopup(station_obj,i)
   {
	var str_html;

	str_html =  station_obj.ph;	
	str_html += st_lines(station_obj.lines);
	str_html += st_alerts(station_obj);
	str_html += station_obj.pm;
	str_html += "<input type='text' maxlength='30' id='snby"+i+"' name='nsby"+i+"' onblur='saveSNBY(this.value)' style='border: 1px solid rgb(0,0,0);'><br>";
	str_html += "<input type='button' value='Search Nearby' onclick='load2(\" "+station_obj.glat+"\",\""+station_obj.glong+"\",\"15\",\"snby\",\""+i+"\")'id='btnsby"+i+"' name='btnsby"+i+"' style='height:24px; border: 1px solid rgb(0,0,0); font-size:15px; margin-left:0px; margin-top:2px;'>";
	str_html += st_popup_footer(station_obj);

	return str_html;
   }

