
var newPushPin=false;var hideDisabled=false;var clickedPushpin=null;var clickedPushpinEntityChangeLastLocation=null;var pushpinIDCounter=0;var userRatings=new Array(false,false,false,false,false);var InfoBoxOriginalHide=null;var ratedPushpin=null;var ratedStation=null;var infoboxTestHTML='<div id="infoboxText" style="background-color:White; border-style:solid;border-width:medium; border-color:Black; min-height:100px; position:absolute;top:0px; left:0px; width:200px;"><b id="infoboxTitle" style="position:absolute; top:10px; left:10px; width:180px;">Testbox!</b><p id="infoboxDescription" style="position:absolute; top:30px; left:10px; width:220px;">Additional information here!<br /><input type="button" name="Test me!" value="Test me!" onclick="alert("hello!");" /></p></div>';function RemovePushPins(){for(var i=0;i<pushpins.length;i++){deleteCookie("pushpin"+i);pushpinLayer.remove(pushpins[i]);}
pushpins=new Array();}
function DragNewPushPin(event){var x=10000;var y=10000;pixel=new Microsoft.Maps.Point(x,y);var LL=map.tryPixelToLocation(pixel);var pushpinOptions={icon:'./AspNetVisualAssets/PushPinIcons/PP_rolledFlag_Shadow_pointing_transparent.png',width:70,height:70,draggable:true};var shape=new Microsoft.Maps.Pushpin(LL,pushpinOptions);pushpinLayer.push(shape);shownPushpinsLayer.push(shape);dragShape=shape;dragShape.setLocation(LL);AddPushPinHandlers(dragShape);newPushPin=true;if(event.preventDefault){event.preventDefault();}}
function GiveNewPushpinBack(event){if(dragShape!=null){if(pushpinLayer.indexOf(dragShape)!=-1){pushpinLayer.remove(dragShape);}
if(shownPushpinsLayer.indexOf(dragShape)!=-1){shownPushpinsLayer.remove(dragShape);}
dragShape=null;newPushPin=false;}}
function AddPushPinHandlers(pushpin){Microsoft.Maps.Events.addHandler(pushpin,"mouseover",PushPinMouseOverHandler);Microsoft.Maps.Events.addHandler(pushpin,"mouseout",PushPinMouseOutHandler);Microsoft.Maps.Events.addHandler(pushpin,"entitychanged",PushPinEntityChangedHandler);Microsoft.Maps.Events.addHandler(pushpin,"mousedown",PushPinMouseDownHandler);}
function PushPinMouseOverHandler(e){if(e.target.getIcon()=='./AspNetVisualAssets/PushPinIcons/PP_rolledFlag_Shadow_pointing_transparent.png'){return;}
else if(e.target!=clickedPushpin){}
var filename=e.target.getIcon();var index=filename.indexOf("noEffect");if(index==-1){return;}
var newFilename=filename.substring(0,index);newFilename=newFilename.concat("hover.png");e.target.setOptions({icon:newFilename});}
function PushPinMouseOutHandler(e){if(!hideDisabled){}
var filename=e.target.getIcon();var index=filename.indexOf("hover");if(index==-1){return;}
var newFilename=filename.substring(0,index);newFilename=newFilename.concat("noEffect.png");e.target.setOptions({icon:newFilename});}
function PushPinEntityChangedHandler(e){if(newPushPin){return;}
var pushpin=e.entity;var typeName=pushpin.getTypeName().split(",");var pushPinID=typeName[0];if(pushPinID!=null){deleteCookie("pushpin"+pushPinID);var latitude=pushpin.getLocation().latitude;var longitude=pushpin.getLocation().longitude;setCookie("pushpin"+pushPinID,latitude+","+longitude+","+typeName[1],365);}
hideDisabled=false;if(typeName[1]!=undefined&&typeName[1]!=null){if(clickedPushpin!=undefined&&clickedPushpin!=null&&clickedPushpin==pushpin){if(clickedPushpinEntityChangeLastLocation==null){clickedPushpinEntityChangeLastLocation=e.entity.getLocation();}
if(e.entity.getLocation().latitude==clickedPushpinEntityChangeLastLocation.latitude&&e.entity.getLocation().longitude==clickedPushpinEntityChangeLastLocation.longitude){}
else{document.getElementById(""+typeName[1]+"Infobox").style.visibility="hidden";}
clickedPushpinEntityChangeLastLocation=e.entity.getLocation();}}}
function PushPinMouseDownHandler(e){if((e.target!=clickedPushpin)&&(clickedPushpin!=null)){var oldTypeName=clickedPushpin.getTypeName().split(",");var newTypeName=e.target.getTypeName().split(",");if((oldTypeName[1]!=undefined)&&(newTypeName[1]!=undefined)){if(oldTypeName[1]!=newTypeName[1]){hideInfobox(""+oldTypeName[1]+"Infobox");enableInfoBoxHide();}}}
hideDisabled=true;showInfobox(e);clickedPushpin=e.target;clickedPushpinEntityChangeLastLocation=null;}
function PushPinMouseUpHandler(e){if((e.target!=clickedPushpin)&&(clickedPushpin!=null)){var oldTypeName=clickedPushpin.getTypeName().split(",");var newTypeName=e.target.getTypeName().split(",");if((oldTypeName[1]!=undefined)&&(newTypeName[1]!=undefined)){if(oldTypeName[1]!=newTypeName[1]){hideInfobox(""+oldTypeName[1]+"Infobox");enableInfoBoxHide();}}}
hideDisabled=true;showInfobox(e);clickedPushpin=e.target;}
function showInfobox(e){if(e.targetType=="pushpin"){var offsetTop=0;var offsetLeft=20;var pixel=map.tryLocationToPixel(e.target.getLocation(),Microsoft.Maps.PixelReference.control);var typeName=e.target.getTypeName().split(",");if(typeName[1]==undefined||typeName[1]==null||typeName[1]==""){return;}
var infobox=document.getElementById(''+typeName[1]+'Infobox');var mapdivWidth=parseInt(document.getElementById('myMap').style.width);var mapdivHeight=parseInt(document.getElementById('myMap').style.height);var infoboxWidth=$('#'+typeName[1]+'Infobox').width();var infoboxHeight=$('#'+typeName[1]+'Infobox').height();if((pixel.x+infoboxWidth)>mapdivWidth){infobox.style.left=(pixel.x-infoboxWidth)+"px";}
else{infobox.style.left=(pixel.x+offsetLeft)+"px";}
if((pixel.y+infoboxHeight)>mapdivHeight){infobox.style.top=(pixel.y-infoboxHeight)+"px";}
else{infobox.style.top=(pixel.y+offsetTop)+"px";}
var pushpinId=pushpinIDCounter++;$('#'+typeName[1]+'InfoboxPushpinID').text(""+pushpinId);var pushpinCookieId=typeName[0];var js="RemoveActualPushpin("+pushpinCookieId+");";var newclick=new Function(js);$('#'+typeName[1]+'InfoboxDeleteIcon').unbind('click');$('#'+typeName[1]+'InfoboxDeleteIcon').click(newclick);infobox.style.visibility="visible";$('#'+typeName[1]+'Infobox').fadeIn('slow');var selectedWatch=$('#selectedWatchName').text();if(selectedWatch!=undefined){selectedWatch=selectedWatch.substring(0,selectedWatch.length-watchNameSuffix.length);}
else{selectedWatch="";}
$('#'+typeName[1]+'InfoboxLatitude').text(""+e.target.getLocation().latitude);$('#'+typeName[1]+'InfoboxLongitude').text(""+e.target.getLocation().longitude);var shareString=""+e.target.getLocation().latitude+"|"+e.target.getLocation().longitude+"|"+map.getZoom()+"|"+selectedWatch+"|";shareString=escape(shareString);$("#"+typeName[1]+"InfoboxShareString").text("http://"+currentHostname+"/?share="+shareString);var functionname=typeName[1]+"InfoboxLoadData";window[functionname](pushpinId);}}
function CloseInfobox(name){hideDisabled=false;hideInfobox(name);clickedPushpin=null;}
function CloseAllInfoboxes(){CloseInfobox("AirUserPushpinInfobox");CloseInfobox("AirStationsInfobox");CloseInfobox("YearlyWaterInfobox");CloseInfobox("NoiseUserPushpinInfobox");CloseInfobox("NoiseStationsInfobox");}
function hideInfobox(infoboxName){$('#'+infoboxName).fadeOut('slow',function(){var infobox=document.getElementById(infoboxName);infobox.style.visibility="hidden";});}
function hideAllInfoboxes(){var category="";for(var i=0;i<tileLayerPropertyBagArray.length;i++){category=tileLayerPropertyBagArray[i].getCategory1();if(document.getElementById(''+category+'UserPushpinInfobox')!=null){document.getElementById(''+category+'UserPushpinInfobox').style.visibility="hidden";}}}
function mouseOverInfobox(infoboxName){}
function mouseOutInfobox(infoboxName){}
function disableInfoBoxHide(){if(!hideDisabled){hideDisabled=true;}}
function enableInfoBoxHide(){if(hideDisabled){hideDisabled=false;}}
function placePushPin(current,latitude,longitude,category){var LL=new Microsoft.Maps.Location(latitude,longitude);var pushPinID;var actualCategory=category;if(current){return;}
else if(newPushPin){var watch=document.getElementById("selectedWatchName").innerHTML;actualCategory=watch.substring(0,watch.length-watchNameSuffix.length);var iconName='./AspNetVisualAssets/PushPinIcons/'+actualCategory+'Watch_PP_watchcolour_Shadow_noEffect.png';pushPinID=pushpins.length;var pushPinTypeName=""+pushPinID.toString()+","+actualCategory+"UserPushpin";dragShape.setLocation(LL);dragShape.setOptions({typeName:pushPinTypeName,icon:iconName,width:65,height:42});pushpins[pushPinID]=dragShape;setCookie("pushpin"+pushPinID,latitude+","+longitude+","+actualCategory+"UserPushpin",365);}
else{pushPinID=pushpins.length;var pushPinTypeName=""+pushPinID.toString()+","+category+"UserPushpin";var shape=new Microsoft.Maps.Pushpin();var iconName='./AspNetVisualAssets/PushPinIcons/'+category+'Watch_PP_watchcolour_Shadow_noEffect.png';shape.setOptions({icon:iconName,typeName:pushPinTypeName,draggable:true,width:65,height:42});AddPushPinHandlers(shape);var stationShape=shape;stationShape.setLocation(LL);pushpinLayer.push(shape);pushpins[pushPinID]=stationShape;}}
function RemoveActualPushpin(pushpinCookieId){var typeName="";for(var i=0;i<pushpinLayer.getLength();i++){typeName=pushpinLayer.get(i).getTypeName().split(",");if(typeName[0]==pushpinCookieId){RemovePushpin(pushpinLayer.get(i).getTypeName());break;}}}
function ClosePushpinControl(){}
function RemovePushpin(pushpinTypeName){typeName=pushpinTypeName.split(",");pushpinId=typeName[0];hideInfobox(''+typeName[1]+'Infobox');setCookie("pushpin"+pushpinId,"deleted",365);pushpinLayer.remove(pushpins[pushpinId]);shownPushpinsLayer.remove(pushpins[pushpinId]);}
function checkBoxes(){var words=new Array();$("#wordList input:checked").each(function(i){words[i]=$(this).attr("id").match(/\d$/)[0];});return words;}
function PushPinOnMouseUp(e){if(newPushPin){var x=e.getX();var y=e.getY();var pixel=new Microsoft.Maps.Point(x,y);var LL=map.tryPixelToLocation(pixel);placePushPin(false,LL.latitude,LL.longitude);newPushPin=false;}
dragShape=null;}
function GetStationTrueOnMouseUp(){dragShape=null;GetStations();}
function handlePushPinOnMouseMove(e){if(newPushPin){var x=e.getX();var y=e.getY();var pixel=new Microsoft.Maps.Point(x,y);var LL=map.tryPixelToLocation(pixel);dragShape.setLocation(LL);}}
function GetPushpin(id,latitude,longitude){ScriptablePushpinService.GetPushpinHtml(id,latitude,longitude,userCulture,GetPushpin_OnSuccess,GetPushpin_OnFailed);return true;}
function GetCurrentPushpin(id,latitude,longitude){ScriptablePushpinService.GetPushpinHtml(id,latitude,longitude,userCulture,GetCurrentPushpin_OnSuccess,GetPushpin_OnFailed);return true;}
function GetCurrentPushpin_OnSuccess(result){if(pushpins[result.Id]!=null){if(result.HasData==true){pushpins[result.Id].setOptions({icon:'./AspNetVisualAssets/PushPin1.png'});}
var loadingDiv=$("#loading").parent().parent();if(loadingDiv.html()!=null){loadingDiv.html(result.Html);}
else{}}}
function GetPushpin_OnSuccess(result){if(pushpins[result.Id]!=null){if(result.HasData==true){pushpins[result.Id].setOptions({icon:'./AspNetVisualAssets/PushPin1.png'});}}}
function GetPushpin_OnFailed(result){}
