//**********************************************************
//*   VIRTUAL EARTH MAP                                    *
//*    TRIP PROFILE PAGE                                   *
//*     Bartlomiej Obecny                                  *
//**********************************************************
var map=null;
var mapE=null;
var timerError;
var Quantity=0;
var ListOfLon= new Array();
var ListOfLat= new Array();
var ListOfCountriesCode= new Array();
var ListOfLocationName= new Array();
var ListOfDetails= new Array();
var ListOfCountriesName= new Array();
var ListOfKeys= new Array();
var ListOfCategories= new Array();
var TimerInfoBox;
var tick=0;
var InfoBoxMaxHeight=50;
var InfoBoxWidth=200;
var InfoBoxOverValue=0;
var ManyPoints=0;
var MainLink="";
var citykey=0;
var townkey=0;
var countrycode="";
//--     Function for initiating api for map
function LoadTravelDestinationMap(){
try{citykey=$('city_key').value}catch(e){}
try{townkey=$('town_key').value}catch(e){}
try{countrycode=$('country_code').value}catch(e){}
try{continentcode=$('continent_code').value}catch(e){}
try{
if((citykey==0) && (townkey==0) && (countrycode=="") &&(continentcode!="")){
return;
}
}catch(e){}
var head = document.getElementsByTagName("head")[0];
var s = document.createElement('script');
s.id = 'VEScript';
s.type = 'text/javascript';
s.src = "http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6";
try {
head.appendChild(s);
}
catch(e){
alert("The service is temporarily unavailable. Try again later.");
}
DelayTravelDestinationMap();
}
//--     Function for loading the map asynchronusly with page
function DelayTravelDestinationMap(){
window.clearTimeout(timerError);
try{
var ffv = 0;
var ffn = "Firefox/"
var ffp = navigator.userAgent.indexOf(ffn);
if (ffp != -1) ffv = parseFloat(navigator.userAgent.substring(ffp + ffn.length));
if ((ffv >= 1.5)||(typeof(window.innerWidth)=='number')){
try {
Msn.Drawing.Graphic.CreateGraphic=function(f,b) { return new Msn.Drawing.SVGGraphic(f,b) }
}
catch(e){
timerError=setTimeout("DelayTravelDestinationMap()",1500);
return;
}
}
try {
map = new VEMap("myMap");
}
catch(e){
timerError=setTimeout("DelayTravelDestinationMap()",1500);
return;
}
}
catch(e){
timerError=setTimeout("DelayTravelDestinationMap()",1500);
return;
}
WhichPage=11;
try{
map.LoadMap();
}
catch(e){
timerError=setTimeout("DelayTravelDestinationMap()",1500);
return;
}
LoadMapAddons();
}
function LoadMapAddons(){
map.SetCenterAndZoom(new VELatLong(0,0), 1);
map.vemapcontrol.EnableGeoCommunity(false);
map.HideDashboard();
map.ShowDisambiguationDialog(false);
map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
if (ManyPoints==0){
Quantity=1;
ListOfLon[1]=$("geo_lon").value;
ListOfLat[1]=$("geo_lat").value;
ListOfCountriesCode[1]=$("country_code").value;
try{
ListOfLocationName[1]=$("OverviewName").value;
ListOfDetails[1]=$("OverviewName").value;
}catch(err){}
ListOfCountriesName[1]=$("country_name").value;
MainLink=$("mainlink").value;
}
else{
}
//	map.AttachEvent("onclick",MouseHandler);
AddLocalizationsOnMap();
ManyPoints=0;
var obj=$("ExpandButton");
if (obj!=null){
obj.style.display="";
}
}
function MouseHandler(e){
var msg;
if (e.eventName == "onclick"){
if (e.rightMouseButton){
var x = e.mapX;
var y = e.mapY;
pixel = new VEPixel(x, y);
varCoord = map.PixelToLatLong(pixel);
var geo_lat=varCoord.Latitude;
var geo_lon=varCoord.Longitude;
msg=geo_lat+" "+geo_lon;
//			GetInfo(geo_lat,geo_lon);
var url = "http://ws.geonames.org/findNearbyPlaceName?lat="+geo_lat+"&lng="+geo_lon;
new Ajax.Updater("resultDiv", url, { method: 'get' });
}
}
}
/*
function GetInfo(geo_lat,geo_lon) {
try {
var xmlhttp = newXMLobject();
var strQuery="http://ws.geonames.org/findNearbyPlaceName?lat="+geo_lat+"&lng="+geo_lon;
xmlhttp.open("GET",strQuery, "true");
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4){
var MapPoints = xmlhttp.responseXML.getElementsByTagName('geonames');
Quantity=0;
if (MapPoints.length > 0 ) {
var countryName=MapPoints[0].getAttribute('countryCode');
var locationName=MapPoints[0].getAttribute('name');
alert(countryName+"\n"+locationName);
}
}
};
xmlhttp.send('');
}
catch (e) {
alert("Server is not available at this time to process your request.");
}
}
*/
function getMapPoints() {
try {
var 	xmlRequest = null;
var strQuery;
var country_code = $("country_code").value;
var city_key = $("city_key").value;
var town_key = $("town_key").value;
var directory_key = $("directory_key").value;
var addons="";
addons+="&country_code="+country_code;
addons+="&city_key="+city_key;
addons+="&town_key="+town_key;
addons+="&place_key="+directory_key;
strQuery="/wayntravels.html?wci=home&wce=mapdetails"+addons;
xmlRequest = new Ajax.Request ( strQuery,
{
method : 'GET',
onSuccess : function ( xmlhttp ) {
var MapPoints = xmlhttp.responseXML.getElementsByTagName('mappoint');
Quantity=0;
if (MapPoints.length > 0 ) {
for(var i=0;MapPoints[i];i++){
var geo_lon=MapPoints[i].getAttribute('geo_lon');
var geo_lat=MapPoints[i].getAttribute('geo_lat');
var countryCode=MapPoints[i].getAttribute('CountryCode');
var countryName=MapPoints[i].getAttribute('CountryName');
var placeName=MapPoints[i].getAttribute('PlaceName');
var placeKey=MapPoints[i].getAttribute('PlaceKey');
var categoryKey=MapPoints[i].getAttribute('CategoryKey');
var address=MapPoints[i].getAttribute('Address');
var details=placeName+"<br>"+address;
Quantity++;
ListOfLon[Quantity]=geo_lon;
ListOfLat[Quantity]=geo_lat;
ListOfCountriesCode[Quantity]=countryCode;
ListOfCountriesName[Quantity]=countryName;
ListOfLocationName[Quantity]=placeName;
ListOfDetails[Quantity]=details;
ListOfKeys[Quantity]=placeKey;
ListOfCategories[Quantity]=categoryKey;
}
AddLocalizationsOnMap(mapE);
}
},
onFailure : function ( xmlhttp ) {
},
onException: function ( xmlhttp ) {
}
}
);
/*
var xmlhttp = newXMLobject();
xmlhttp.open("GET",strQuery, "true");
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4){
var MapPoints = xmlhttp.responseXML.getElementsByTagName('mappoint');
Quantity=0;
if (MapPoints.length > 0 ) {
for(var i=0;MapPoints[i];i++){
var geo_lon=MapPoints[i].getAttribute('geo_lon');
var geo_lat=MapPoints[i].getAttribute('geo_lat');
var countryCode=MapPoints[i].getAttribute('CountryCode');
var countryName=MapPoints[i].getAttribute('CountryName');
var placeName=MapPoints[i].getAttribute('PlaceName');
var placeKey=MapPoints[i].getAttribute('PlaceKey');
var categoryKey=MapPoints[i].getAttribute('CategoryKey');
var address=MapPoints[i].getAttribute('Address');
var details=placeName+"<br>"+address;
Quantity++;
ListOfLon[Quantity]=geo_lon;
ListOfLat[Quantity]=geo_lat;
ListOfCountriesCode[Quantity]=countryCode;
ListOfCountriesName[Quantity]=countryName;
ListOfLocationName[Quantity]=placeName;
ListOfDetails[Quantity]=details;
ListOfKeys[Quantity]=placeKey;
ListOfCategories[Quantity]=categoryKey;
}
AddLocalizationsOnMap(mapE);
}
}
else{
//loading
}
};
xmlhttp.send(null);
*/
}
catch (e) {
alert("Server is not available at this time to process your request.");
}
}
function AddLocalizationsOnMap(MapObj){
if (MapObj==null){
MapObj=map;
}
var OldCountryCode=" ";var NewCountryCode="";
var OldLocationName=" ";var NewLocationName="";
var PinID=0;
var HtmlBody="";
var HtmlTitle="";
var pins=new Array();
MapObj.DeleteAllPushpins();
MapObj.DeleteAllPolylines();
MapObj.DeleteAllPolygons();
CloseInfoBoxOver();
var tmpStr="";
try
{
var ShowPins=1;
var tmpObj=$("no_geo");
if (tmpObj!=null){
if (tmpObj.value=="1"){
if ((Quantity==1)&&(MapObj==map)){
ShowPins=0;
}
}
}
for (var i=1;i<=Quantity;i++){
NewCountryCode=ListOfCountriesCode[i];
NewLocationName=ListOfLat[i]+"$"+ListOfLon[i];
//			if (NewCountryCode!=OldCountryCode){
OldCountryCode=NewCountryCode;
OldLocationName=NewLocationName;
if ((ListOfCountriesName[i]!="")&&(ListOfCountriesName[i]!=null)){
if (NewCountryCode!=''){
HtmlTitle="<img border='0' src=\""+appproxypath+"maps/flags/"+NewCountryCode+".gif\" border=\"0\" >&nbsp;&nbsp;"+ListOfCountriesName[i];
}
else{
HtmlTitle=ListOfCountriesName[i];
}
}
else{
HtmlTitle="";
}
HtmlBody="";
//			}
if (NewLocationName!=OldLocationName){
OldLocationName=NewLocationName;
HtmlBody="";
}
if (MainLink!=""){
if (ListOfKeys[i]>0){
tmpStr=ListOfKeys[i];
}
else{
tmpStr="";
}
tmpStr=AHrefOnDiv(MainLink + tmpStr,unescape(ListOfDetails[i]),"");
}
else{
tmpStr=ListOfDetails[i];
}
HtmlBody+=tmpStr+"<br>";
var AddPin=(i==Quantity);
if (AddPin==false){
AddPin=(OldCountryCode!=ListOfCountriesCode[i+1]);
if (AddPin==false){
AddPin=(OldLocationName!=ListOfLat[i+1]+"$"+ListOfLon[i+1]);
}
}
if (AddPin==true){
PinID++;
lat=ListOfLat[i];
lon=ListOfLon[i];
var PinImage="";
if (ListOfCategories[i]>0){
PinImage="travels/pins/pins_cat_"+ListOfCategories[i]+".png";
}
else{
PinImage="travels/pins/pins_s_"+i+".png";
}
if (Quantity==1){
PinImage="travels/pins/pins_s_0.png";
}
var pinLatLong = new VELatLong(lat, lon);
var pin = new VEPushpin(PinID,
pinLatLong,
appproxypath+PinImage,
HtmlTitle,
HtmlBody
);
pins.push(pinLatLong);
if (ShowPins==1){
MapObj.AddPushpin(pin);
var element=document.getElementById(PinID);
element.onclick=MapEventHandlerOnClick;
VEPushpin.ShowDetailOnMouseOver = false;
VEPushpin.OnMouseOverCallback = function(x, y, title, details){
window.parent.document.getElementById('InfoBox').display="none";
tick=80;
document.getElementById("myobject").innerHTML=details;
var strTitle=unescape(title);
if (strTitle.length>0){strTitle="<strong>"+strTitle+"</strong><br>"}
window.parent.document.getElementById('InfoBox').style.height=InfoBoxMaxHeight;
window.parent.document.getElementById('InfoBox').style.width=InfoBoxWidth;
window.parent.document.getElementById('InfoBox').style.overflow="auto";
window.parent.document.getElementById('InfoBox').innerHTML=strTitle+details;
var valHeight=parseFloat(window.parent.document.getElementById('InfoBox').style.height);
if (valHeight>InfoBoxMaxHeight){
valHeight=InfoBoxMaxHeight;
}
var parentX=0;
var parentY=0;
var obj=window.parent.document.getElementById('myMapExpanded');
if (obj!=null){
if (obj.style.display!="none"){
parentX=parseInt(obj.style.left);
parentY=parseInt(obj.style.top);
}
}
window.parent.document.getElementById('InfoBox').style.top=y-(valHeight/2)-10;
window.parent.document.getElementById('InfoBox').style.left=x+15;
InfoBoxOver(1);
}
}
}
}
try{
var tmpZoom=$("geo_zoom").value;
}
catch (e){var tmpZoom=0;}
MapObj.SetMapView(pins);
if (tmpZoom>0){
if (Quantity<2){
MapObj.SetZoomLevel(tmpZoom);
MapObj.PanToLatLong(pinLatLong);
}
else{
MapObj.SetMapView(pins);
}
}
else{
if (Quantity<2){
var obj=$("town_key");
if (obj==null){
zoom=20;
}
else{
try{
if ($("town_key").value>0){
zoom=9;
}
else{
if($("city_key").value>0){
zoom=7;
}
else{
if($("directory_key").value>0){
zoom=20;
}
else{
zoom=4;
}
}
}
}
catch (e){zoom=20;}
}
MapObj.SetZoomLevel(zoom);
MapObj.PanToLatLong(pinLatLong);
}
else{
MapObj.SetZoomLevel(0);
MapObj.SetMapView(pins);
}
}
var tmpZoom=MapObj.GetZoomLevel();
if (tmpZoom>16){
tmpZoom=16;
MapObj.SetZoomLevel(tmpZoom);
}
}
catch(e){}
}
function AHrefOnDiv(href_link,strText,addons){
var arr = new Array();
arr = strText.split("<br>");
if (arr.length>0){
var line1=arr[0];
if (arr.length>1){
var line2="<br>"+arr[1];
}
else{
line2="";
}
}
else{
var line1=strText;
var line2="";
}
return "<a href=\""+unescape(href_link)+"\" " +unescape(addons)+" onmouseover=\"javascript:InfoBoxOver(1);return false;\" onmouseout=\"javascript:InfoBoxOver(0);return false;\" >"+unescape(line1)+"</a>"+unescape(line2);
}
function InfoBoxOver(ValVisible){
if (ValVisible==1){
InfoBoxOverValue=1;
window.clearTimeout(TimerInfoBox);
TimerInfoBox=window.setTimeout("OpenInfoBoxOver()",1);
}
else{
InfoBoxOverValue=0;
window.clearTimeout(TimerInfoBox);
TimerInfoBox=window.setTimeout("CloseInfoBoxOver()",1);
}
}
function OpenInfoBoxOver(){
window.clearTimeout(TimerInfoBox);
if (InfoBoxOverValue==0){
TimerInfoBox=window.setTimeout("AppearInfoBoxOver(0)",1);
}
else{
TimerInfoBox=window.setTimeout("AppearInfoBoxOver("+tick+")",1);
}
}
function CloseInfoBoxOver(){
window.clearTimeout(TimerInfoBox);
if (InfoBoxOverValue==0){
TimerInfoBox=window.setTimeout("DissaperInfoBoxOver(88)",1);
}
else{
TimerInfoBox=window.setTimeout("DissaperInfoBoxOver("+tick+")",1);
}
}
function AppearInfoBoxOver(tick2){
window.clearTimeout(TimerInfoBox);
tick=tick2;
var x=parseFloat(window.parent.document.getElementById('InfoBox').style.left)+parseFloat(window.parent.document.getElementById('InfoBox').style.width);
var y=parseFloat(window.parent.document.getElementById('InfoBox').style.top);
window.parent.document.getElementById('InfoBoxClose').innerHTML="x";
window.parent.document.getElementById('InfoBoxClose').style.top=y-4;
if (ie5!==true){
window.parent.document.getElementById('InfoBoxClose').style.left=x+12;
}
else{
window.parent.document.getElementById('InfoBoxClose').style.left=x-3;
}
var ValueHeight=window.parent.document.getElementById('InfoBox').offsetHeight;
var ValueHeight2=parseFloat(window.parent.document.getElementById('InfoBox').style.height);
if (ns6==true){
if (WhichPage==2){
window.parent.document.getElementById('InfoBox').style.overflow="auto";
window.parent.document.getElementById('InfoBox').style.height=InfoBoxMaxHeight;
}
}
else{
if (ValueHeight>InfoBoxMaxHeight){
window.parent.document.getElementById('InfoBox').style.overflow="auto";
window.parent.document.getElementById('InfoBox').style.height=InfoBoxMaxHeight;
}
else{
if (ValueHeight>ValueHeight2){
window.parent.document.getElementById('InfoBox').style.overflow="visible";
window.parent.document.getElementById('InfoBox').style.height=ValueHeight;
}
}
}
window.parent.document.getElementById('InfoBox').style.display="inline";
window.parent.document.getElementById('InfoBoxClose').style.display="inline";
x=parseFloat(window.parent.document.getElementById('InfoBoxClose').style.left);
window.parent.document.getElementById('InfoBoxClose').style.left=x-14;
tick=tick+6;
if (tick>88){
tick=88;
}
if (ie5){
window.parent.document.getElementById('InfoBox').filters.alpha.opacity=tick;
}
else if(ns6) {
window.parent.document.getElementById('InfoBox').style.opacity=tick/100;
}
if (tick<88){
TimerInfoBox=window.setTimeout("AppearInfoBoxOver("+tick+")",20);
}
else{
TimerInfoBox=window.setTimeout("CloseInfoBoxOver()",8000);
}
}
//--     Function for closing the information box on a map using the opacity property
function DissaperInfoBoxOver(tick2){
tick=tick2;
tick=tick-3;
if (tick<0){tick=0;}
window.clearTimeout(TimerInfoBox);
if (tick>0){
if (ie5){
window.parent.document.getElementById('InfoBox').filters.alpha.opacity=tick;
}
else if(ns6) {
window.parent.document.getElementById('InfoBox').style.opacity=tick/100;
}
TimerInfoBox=window.setTimeout("DissaperInfoBoxOver("+tick+")",20);
}
else{
window.parent.document.getElementById('InfoBox').style.display="none";
window.parent.document.getElementById('InfoBoxClose').style.display="none";
}
}
function ShowExpandedMap(){
obj=$("myMapExpanded");
if (obj!=null){
var screenW = window.innerWidth != null ? window.innerWidth : document.documentElement &&  document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null ? document.body.clientWidth : null;
var screenH = window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight:null;
var posX=(screenW-parseInt(obj.style.width)-23)/2;
var posY=130;
obj.style.left=posX;
obj.style.top=posY;
$("myMapExpanded").style.display="";
//mapE.Resize();
if (ManyPoints==0){
var obj=$("myMapE");
if (obj!=null){
mapE = new VEMap("myMapE");
mapE.LoadMap();
mapE.SetCenterAndZoom(new VELatLong(0,0), 1);
mapE.vemapcontrol.EnableGeoCommunity(false);
mapE.HideDashboard();
mapE.ShowDisambiguationDialog(false);
mapE.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
}
ManyPoints=1;
MainLink="wayntravels.html?wci=place&place_key=";
var obj=$("ExpandMapLegend");
if (obj!=null){
if (obj.style.display=="none"){
AddLocalizationsOnMap(mapE);
ShowAlternativeLegend();
}
else{
if (countrycode==""){
//for reviews
AddLocalizationsOnMap(mapE);
}
else{
getMapPoints();
}
}
}
}
}
}
function MoveExpandedMap(){
obj=$("myMapExpanded");
if (obj!=null){
if (obj.style.display!="none"){
var screenW = window.innerWidth != null ? window.innerWidth : document.documentElement &&  document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null ? document.body.clientWidth : null;
var screenH = window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight:null;
var posX=(screenW-parseInt(obj.style.width)-23)/2;
var posY=130;
if (screenW<900){
posX=(900-parseInt(obj.style.width)-23)/2;
}
obj.style.left=posX;
obj.style.top=posY;
}
}
}
function HideExpandedMap(){
obj=$("myMapExpanded");
if (obj!=null){
InfoBoxOverValue=0;
CloseInfoBoxOver();
$("myMapExpanded").style.display="none";
}
}
function MapEventHandlerOnClick(e){
var strLocation=unescape(document.getElementById("myobject").innerHTML);
var strTemp=strLocation.substr(strLocation.indexOf("href=\"")+6,strLocation.length);
strLocation=strTemp;
strTemp=strLocation.substr(0,strLocation.indexOf("\""));
strTemp=strTemp.replace(/&amp;/gi, "&");
if (strTemp.indexOf("wayntravels.htm")>=0){
document.location=strTemp;
}
else if (strTemp.indexOf("javascript:")==0){
strLocation=strTemp;
strTemp=strLocation.substr(11,strLocation.length);
eval(strTemp);
}
}
function ShowAlternativeLegend(){
var PinImage;
var LegendContent="";
var tmpStr="";
var tmpObj=$("no_geo");
if (tmpObj==null){
for (var i=1;i<=Quantity;i++){
PinImage="travels/pins/pins_"+i+".png";
if (Quantity==1){
PinImage="travels/pins/pins_0.png";
}
PinImage=appproxypath+PinImage;
tmpStr="<tr><td>";
tmpStr+="<img style='width:25px;' align='absmiddle' border='0' src=\""+PinImage+"\" border=\"0\" >&nbsp;&nbsp;";
tmpStr+="</td><td style='padding-right:2px;'>";
//		tmpStr+="<img width='12' align='absmiddle' border='0' src=\""+appproxypath+"maps/flags/"+ListOfCountriesCode[i]+".gif\" border=\"0\" >&nbsp;&nbsp;";
if (ListOfKeys[i]>0){
tmpStr+="<a href='"+MainLink+ListOfKeys[i]+"' class='linkMiddleBlue'>"+ListOfDetails[i]+"</a>";
}
else{
tmpStr+=ListOfDetails[i];
}
tmpStr+="</td></tr>";
LegendContent+=tmpStr;
}
}
tmpStr=LegendContent;
LegendContent='<table class="tabBoxClean" cellpadding="2" cellspacing="0">';
LegendContent+='<tr><td colspan="2" class="headingBlueMiddle">&nbsp;</td></tr>';
LegendContent+='<tr><td colspan="2" class="headingBlueMiddle" align="center">Legend</td></tr>';
LegendContent+='<tr><td colspan="2" class="headingBlueMiddle">&nbsp;</td></tr>'+tmpStr;
LegendContent+="</table>";
$("ExpandMapLegend2").innerHTML=LegendContent;
$("ExpandMapLegend2").style.display="";
}
function MoveMapTo(moveto_lat, moveto_long, zoom_level){
if(map){
var latlong = new VELatLong(moveto_lat, moveto_long);
map.SetCenterAndZoom(latlong, zoom_level);
}
}
