// (c) 2010 CodeGen International

var suggestedRoute=0;var suggestedRouteMarkers=[];var showPathAttrWithSugstddRoutes=false;var startAndEndMarkersHidden=[];var cityIdsOfClickedCities=[];function showHideRouteList(themeId){if(document.getElementById(themeId)){var theme_tr_obj=document.getElementById(themeId);var themeNumber=themeId.split("-");var themeImgName="theme_img-"+themeNumber[1];var routeId="route_id-"+themeNumber[1];if(document.getElementById(routeId)){var route_tr_obj=document.getElementById(routeId);var theme_img_td_obj=document.getElementById(themeImgName);if(route_tr_obj.style.display=='none'){route_tr_obj.style.display='table-row';if(theme_img_td_obj){document.getElementById(themeImgName).innerHTML="<img src='"+cg_pathfinder_path+"/images/minus.png' width='10px' height='10px' />";}}else{route_tr_obj.style.display='none';if(theme_img_td_obj){document.getElementById(themeImgName).innerHTML="<img src='"+cg_pathfinder_path+"/images/plus.png' width='10px' height='10px' />";}}}}}
function generateSuggestedRouteMarkers(cityId,cityName,cityTid){var name=cityName;var dwnld_url=base_path+"get_city_geocode_wl/"+cityId;GDownloadUrl(dwnld_url,function(data){if(!empty(data)){xml_doc=GXml.parse(data);var city_info_node=xml_doc.documentElement.getElementsByTagName("city_info");if(!empty(city_info_node)){var point=new GLatLng(parseFloat(city_info_node[0].getAttribute("city_pt_lat")),parseFloat(city_info_node[0].getAttribute("city_pt_lon")));var ico=viacityicon;ico.infoWindowAnchor=new GPoint(5,2);var marker;if(cityTid!="NULL"){marker=new GMarker(point,{icon:ico,title:name});map.addOverlay(marker);GEvent.addListener(marker,'click',function(){if(document.getElementById(cityTid)){document.getElementById(cityTid).checked=true;var tidInt=parseInt(cityTid,10);var cityIdInt=parseInt(cityId,10);getCity(tidInt,false,cityIdInt);var cityElemArr=cityMarkerList[tidInt];if(!empty(cityElemArr)){marker.hide();}}});var label=null;GEvent.addListener(marker,"mouseover",function(){label=new ELabel(new GLatLng(parseFloat(city_info_node[0].getAttribute("city_pt_lat")),parseFloat(city_info_node[0].getAttribute("city_pt_lon"))),cityName+": Click to see attractions","elableStyle");label.pixelOffset=new GSize(5,5);map.addOverlay(label);});GEvent.addListener(marker,"mouseout",function(){if(label!==null){map.removeOverlay(label);label=null;}});}else{marker=new GMarker(point,{icon:ico,title:cityName});map.addOverlay(marker);}
suggestedRouteMarkers[cityId]=marker;cityIdsOfClickedCities[cityId]=cityTid;}else{alert('Location data currently unavailable.');}}else{alert('Could not identify city location. Please select a different city!');}});}
function showSuggestedRouteOnMap(cityIdList,cityNamesList,showPathAttr,cityTidList){var cityIdsReceived=cityIdList.split(",");var cityNamesReceived=cityNamesList.split(",");var cityTidsReceived=cityTidList.split(",");var viaCityList="";var zoom_level=map.getZoom();for(var i=1;i<cityIdsReceived.length-1;i++){viaCityList=viaCityList+","+cityIdsReceived[i];}
viaCityList=viaCityList.substring(1);if(empty(viaCityList)){viaCityList=-1;}
var showAttractions=0;if(showPathAttr=='t'){showAttractions=1;showPathAttrWithSugstddRoutes=true;suggestedRouteAttrSet=true;}
var dwnld_url=base_path+"show_suggested_route_wl/"+cityIdsReceived[0]+"/"+cityIdsReceived[cityIdsReceived.length-1]+"/"+zoom_level+"/"+showAttractions+"/"+viaCityList;show_hide_path_load_img(true);viaCityRequestNotArrived=true;timerObj=window.setTimeout('checkViaCityTimeTaken()',30000);hideViaCitiesMarkers();GDownloadUrl(dwnld_url,function(data){if(viaCityRequestNotArrived){if(!empty(data)){viaCityRequestNotArrived=false;xml_doc=GXml.parse(data);var loct_node=xml_doc.documentElement.getElementsByTagName("locations");if(!empty(loct_node)){for(var i=1;i<cityIdsReceived.length-1;i++){generateSuggestedRouteMarkers(cityIdsReceived[i],cityNamesReceived[i],cityTidsReceived[i]);}
var start_pt_node=loct_node[0].getElementsByTagName("start_point");if(!empty(start_pt_node)){path_start_point=new GLatLng(parseFloat(start_pt_node[0].getAttribute("lat")),parseFloat(start_pt_node[0].getAttribute("lon")));if(!empty(path_start_marker)){map.removeOverlay(path_start_marker);}
if(document.getElementById(cityTidsReceived[0])){var startName=cityNamesReceived[0]+": Click to see attractions";path_start_marker=new GMarker(path_start_point,{icon:start_marker_ico,title:startName});}else{path_start_marker=new GMarker(path_start_point,{icon:start_marker_ico,title:cityNamesReceived[0]});}
GEvent.addListener(path_start_marker,'click',function(){if(document.getElementById(cityTidsReceived[0])){if(!(document.getElementById(cityTidsReceived[0]).checked)){document.getElementById(cityTidsReceived[0]).checked=true;startAndEndMarkersHidden[0]=(cityTidsReceived[0]);getCity(cityTidsReceived[0],true);var cityElementArr=cityMarkerList[cityTidsReceived[0]];if(!empty(cityElementArr)){for(var elem in cityElementArr){if(cityElementArr[elem]){if(empty(cityElementArr[elem].centerMarker)){break;}
cityElementArr[elem].centerMarker.hide();}}}}}});map.addOverlay(path_start_marker);start_pt_zoom=map.getZoom();}
var end_pt_node=loct_node[0].getElementsByTagName("end_point");if(!empty(end_pt_node)){path_end_point=new GLatLng(parseFloat(end_pt_node[0].getAttribute("lat")),parseFloat(end_pt_node[0].getAttribute("lon")));if(!empty(path_end_marker)){map.removeOverlay(path_end_marker);}
if(document.getElementById(cityTidsReceived[cityTidsReceived.length-1])){var endName=cityNamesReceived[cityNamesReceived.length-1]+": Click to see attractions";path_end_marker=new GMarker(path_end_point,{icon:end_marker_ico,title:endName});}else{path_end_marker=new GMarker(path_end_point,{icon:end_marker_ico,title:cityNamesReceived[cityNamesReceived.length-1]});}
GEvent.addListener(path_end_marker,'click',function(){if(document.getElementById(cityTidsReceived[cityTidsReceived.length-1])){if(!(document.getElementById(cityTidsReceived[cityTidsReceived.length-1]).checked)){document.getElementById(cityTidsReceived[cityTidsReceived.length-1]).checked=true;startAndEndMarkersHidden[1]=cityTidsReceived[cityTidsReceived.length-1];getCity(cityTidsReceived[cityTidsReceived.length-1],true);var cityElementArr=cityMarkerList[cityTidsReceived[cityTidsReceived.length-1]];if(!empty(cityElementArr)){for(var elem in cityElementArr){if(cityElementArr[elem]){if(empty(cityElementArr[elem].centerMarker)){break;}
cityElementArr[elem].centerMarker.hide();}}}}}});map.addOverlay(path_end_marker);end_pt_zoom=map.getZoom();}}
show_path(xml_doc,"",showPathAttrWithSugstddRoutes);clearViaCityTimer();show_hide_path_load_img(false);viaCityRequestNotArrived=true;}else{alert('Could not identify a path between two destinations. Please try again!');}}
clearViaCityTimer();show_hide_path_load_img(false);viaCityRequestNotArrived=true;});}
function setSuggestedRoutsInput(){if(document.getElementById('sug_routes_select')){var suggestedRouteObj=document.getElementById('sug_routes_select');var selectedRouteValue=suggestedRouteObj[suggestedRouteObj.selectedIndex].value;if(selectedRouteValue!=-1){suggestedRoute=selectedRouteValue;var subValues=selectedRouteValue.split(",");var zoom_level=map.getZoom();var city_ids_received=new Array(2);city_ids_received[0]=1957;city_ids_received[1]=1366;var cityNamesReceived=new Array(2);cityNamesReceived[0]="Gampaha";cityNamesReceived[1]="Kegalla";for(var i=0;i<city_ids_received.length;i++){generateSuggestedRouteMarkers(city_ids_received[i],cityNamesReceived[i]);}
var dwnld_url=base_path+"get_directions_wl/"+subValues[1]+"/"+subValues[2]+"/"+zoom_level+"/"+1+"/"+1+","+1957+","+1366+"/"+0;viaCityRequestNotArrived=true;timerObj=window.setTimeout('checkViaCityTimeTaken()',30000);GDownloadUrl(dwnld_url,function(data){if(viaCityRequestNotArrived){if(!empty(data)){viaCityRequestNotArrived=false;xml_doc=GXml.parse(data);var loct_node=xml_doc.documentElement.getElementsByTagName("locations");if(!empty(loct_node)){var start_pt_node=loct_node[0].getElementsByTagName("start_point");if(!empty(start_pt_node)){path_start_point=new GLatLng(parseFloat(start_pt_node[0].getAttribute("lat")),parseFloat(start_pt_node[0].getAttribute("lon")));if(!empty(path_start_marker)){map.removeOverlay(path_start_marker);}
path_start_marker=new GMarker(path_start_point,{icon:start_marker_ico,title:"Colombo"});map.addOverlay(path_start_marker);start_pt_zoom=map.getZoom();}
var end_pt_node=loct_node[0].getElementsByTagName("end_point");if(!empty(end_pt_node)){path_end_point=new GLatLng(parseFloat(end_pt_node[0].getAttribute("lat")),parseFloat(end_pt_node[0].getAttribute("lon")));if(!empty(path_end_marker)){map.removeOverlay(path_end_marker);}
path_end_marker=new GMarker(path_end_point,{icon:end_marker_ico,title:"Kandy"});map.addOverlay(path_end_marker);end_pt_zoom=map.getZoom();}}
show_path(xml_doc);clearViaCityTimer();show_hide_path_load_img(false);viaCityRequestNotArrived=true;}else{alert('Could not identify a path between two destinations. Please try again!');}}
clearViaCityTimer();show_hide_path_load_img(false);viaCityRequestNotArrived=true;});}}}
function clearSuggestedRouteMarkers(){for(var x=0;x<suggestedRouteMarkers.length;x++){if(!empty(suggestedRouteMarkers[x])){suggestedRouteMarkers[x].hide();}}
suggestedRouteMarkers=null;suggestedRouteMarkers=[];startAndEndMarkersHidden=null;startAndEndMarkersHidden=[];cityIdsOfClickedCities=null;cityIdsOfClickedCities=[];}
