var map = null;$(document).ready(function() {	//Turn of Alpha-PNG transparency to cope with performance problems in IE6    //OpenLayers.Util.alphaHack();    Hydro.Map.setMap();    Hydro.Map.Tools();    Hydro.Application.setText();    Hydro.Application.getURLParam();    var ie6 = false;        //If the browser is IE6    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;		 var ieversion=new Number(RegExp.$1);		 		 if(ieversion == "6.0"){			 ie6 = true;		 }	}            //To force IE6 to show the loading image it is necessary to use a timeout    if(ie6)    {    	document.getElementById('loadingCircle').style.visibility = 'visible';    	setTimeout("Hydro.Map.showRssWrapper()", 500);    }    else    {    	Hydro.Map.showRss("true", "true", "true", "false", "false", "false", "false", "false");    }        Hydro.Application.Events();       return null;});//OpenLayers.Util.alphaHack = function() { return false; } Hydro.Application.setText = function(){	$("#btnDownload").val(Hydro.configPaths.Buttons.DownloadBtn);	$("#btnSearch").val(Hydro.configPaths.Buttons.SearchBtn);}Hydro.Map.showRssWrapper = function(){	Hydro.Map.showRss("true", "true", "true", "false", "false", "false", "false", "false");	$("#loadingCircle").hide();}//Called on startup to add google as map baselayer.Hydro.Map.setMap = function() {	if(map == null){            map = new OpenLayers.Map('map');            var bounds = new OpenLayers.Bounds(-2.6806640625,38.72203912287745, 32.9150390625,82.66735162287745);            //left-bottom=(-2.6806640625,38.72203912287745) right-top=(32.9150390625,82.66735162287745) left=-2.6806640625 bottom=38.72203912287745            map.setOptions({ restrictedExtent: bounds });            var gmap = new OpenLayers.Layer.Google(                    "Google Streets",                    {numZoomLevels: 12, 'minZoomLevel':4, 'maxZoomLevel':16}                );            map.addLayer(gmap);            Hydro.Map.setCenter();	}}Hydro.Map.Clear = function(){	document.getElementById("cityName").value = "";	Hydro.Map.showMarkers($("#cbxHydro").attr('checked'), $("#cbxUnoX").attr('checked'), $("#cbxBensin").attr('checked'), $("#cbxE85").attr('checked'), $("#cbxDiesel").attr('checked'),  $("#cbxB98").attr('checked'), $("#cbxBVP").attr('checked'), $("#cbxADB").attr('checked'), document.getElementById("cityName").value);}Hydro.Application.getURLParam = function(){	var strReturn = "";	  var strHref = window.location.href;	    var bounds = strHref.split('bounds=');	    if(bounds.length > 1)	    	Hydro.Map.zoomToBounds(bounds[1]);	  }//Called by setMap so the map is centered on Sweden, even called if the searchresult returns empty.Hydro.Map.setCenter = function(){	map.setCenter(new OpenLayers.LonLat(15.1171875, 60.69469537287745), 0);	}// Close the result list and popup on click anywhere.Hydro.Application.checkSearchVisibility = function(e) {    if(map.popups){        if(map.popups.length != 0) {            //map.popups[0].hide();        }    }}//Registers function to call on document.onclick.//Several functions can be added.Hydro.Application.addDocumentClickEvent = function(func) {   	 var oldonload = window.onload;   	 if (typeof document.onclick != 'function') {   	     document.onclick = func;   	 } 	 else {   	     document.onclick = function() {   	         if (oldonload) {   	             oldonload();   	         }   	         func();   	     }   	 }   }//Function that disables the enterkey so it isn\u00B4t fires "submit" form instead of search.Hydro.Application.disableEnterKey = function(e){     var key;     if(window.event)          key = window.event.keyCode;     //IE     else          key = e.which;     //firefox     if(key == 13)          return false;     else          return true;}Hydro.Map.Tools = function(){	var pZbar = new OpenLayers.Control.PanZoomBar();    pZbar.position = new OpenLayers.Pixel(10, 10);    map.addControl(pZbar);    var pZ = new OpenLayers.Control.PanZoom({ slideFactor: 100 });    //pZ.position = new OpenLayers.Pixel(750, 750);    map.addControl(pZ);}Hydro.Map.showMarkers = function(hydro, unoX, bensin, e85, diesel, b98, bvp, adb, searchString){	searchString = searchString.toLowerCase();	for(var i=0; i<map.layers.length;i++){		if(map.layers[i].CLASS_NAME == "OpenLayers.Layer.GeoRSS"){			for(var j=0;j < map.layers[i].features.length;j++){				var display = true;				var featureData = map.layers[i].features[j].data;				var featureMarker = map.layers[i].features[j].marker;								/*				if(searchString != "" && featureData.lan.indexOf(searchString) == -1 && featureData.kommun.indexOf(searchString) == -1 && featureData.city.indexOf(searchString) == -1 && featureData.name.indexOf(searchString) == -1)				{					display = false;				}				*/								if(!hydro && !unoX){					display = false;				}				else if(hydro && !unoX){					if(featureData.station != "hydro"){						display = false;					}						}				else if(!hydro && unoX){					if(featureData.station != "unox"){						display = false;					}				}				if(bensin){					if(featureData.bensin == "Nej"){						display = false;					}				}				if(e85){					if(featureData.e85 == "Nej"){						display = false;					}				}				if(diesel){					if(featureData.diesel == "Nej"){						display = false;					}				}				if(b98){					if(featureData.b98 == "Nej"){						display = false;					}				}				if(bvp){					if(featureData.bvp == "Nej"){						display = false;					}				}				if(adb){					if(featureData.adb == "Nej"){						display = false;					}				}				map.layers[i].features[j].marker.display(display);				}			}		}	}//All events that occurs is registered below. Ex. User clicks in a checkbox.Hydro.Application.Events = function(){	$("#noResultDiv").hide();	 //$("#loadingCircle").hide();	$("#cityName").click(function(){$("#noResultDiv").hide();});	$("#cbxHydro").click(function(){		Hydro.Map.showMarkers($("#cbxHydro").attr('checked'), $("#cbxUnoX").attr('checked'), $("#cbxBensin").attr('checked'), $("#cbxE85").attr('checked'), $("#cbxDiesel").attr('checked'), $("#cbxB98").attr('checked'), $("#cbxBVP").attr('checked'), $("#cbxADB").attr('checked'), document.getElementById("cityName").value);	});	$("#cbxUnoX").click(function(){		Hydro.Map.showMarkers($("#cbxHydro").attr('checked'), $("#cbxUnoX").attr('checked'), $("#cbxBensin").attr('checked'), $("#cbxE85").attr('checked'), $("#cbxDiesel").attr('checked'), $("#cbxB98").attr('checked'), $("#cbxBVP").attr('checked'), $("#cbxADB").attr('checked'), document.getElementById("cityName").value);	});	$("#cbxBensin").click(function(){		Hydro.Map.showMarkers($("#cbxHydro").attr('checked'), $("#cbxUnoX").attr('checked'), $("#cbxBensin").attr('checked'), $("#cbxE85").attr('checked'), $("#cbxDiesel").attr('checked'), $("#cbxB98").attr('checked'), $("#cbxBVP").attr('checked'), $("#cbxADB").attr('checked'), document.getElementById("cityName").value);	});	$("#cbxE85").click(function(){		Hydro.Map.showMarkers($("#cbxHydro").attr('checked'), $("#cbxUnoX").attr('checked'), $("#cbxBensin").attr('checked'), $("#cbxE85").attr('checked'), $("#cbxDiesel").attr('checked'), $("#cbxB98").attr('checked'), $("#cbxBVP").attr('checked'), $("#cbxADB").attr('checked'), document.getElementById("cityName").value);	});	$("#cbxDiesel").click(function(){		Hydro.Map.showMarkers($("#cbxHydro").attr('checked'), $("#cbxUnoX").attr('checked'), $("#cbxBensin").attr('checked'), $("#cbxE85").attr('checked'), $("#cbxDiesel").attr('checked'), $("#cbxB98").attr('checked'), $("#cbxBVP").attr('checked'), $("#cbxADB").attr('checked'), document.getElementById("cityName").value);	});	$("#cbxB98").click(function(){		Hydro.Map.showMarkers($("#cbxHydro").attr('checked'), $("#cbxUnoX").attr('checked'), $("#cbxBensin").attr('checked'), $("#cbxE85").attr('checked'), $("#cbxDiesel").attr('checked'), $("#cbxB98").attr('checked'), $("#cbxBVP").attr('checked'), $("#cbxADB").attr('checked'), document.getElementById("cityName").value);	});	$("#cbxBVP").click(function(){		Hydro.Map.showMarkers($("#cbxHydro").attr('checked'), $("#cbxUnoX").attr('checked'), $("#cbxBensin").attr('checked'), $("#cbxE85").attr('checked'), $("#cbxDiesel").attr('checked'), $("#cbxB98").attr('checked'), $("#cbxBVP").attr('checked'), $("#cbxADB").attr('checked'), document.getElementById("cityName").value);	});	$("#cbxADB").click(function(){		Hydro.Map.showMarkers($("#cbxHydro").attr('checked'), $("#cbxUnoX").attr('checked'), $("#cbxBensin").attr('checked'), $("#cbxE85").attr('checked'), $("#cbxDiesel").attr('checked'), $("#cbxB98").attr('checked'), $("#cbxBVP").attr('checked'), $("#cbxADB").attr('checked'), document.getElementById("cityName").value);	});	Hydro.Application.addDocumentClickEvent(Hydro.Application.checkSearchVisibility);	$("#cityName").keyup(function(event){        if (event.keyCode == 13) {        	Hydro.Map.getBounds();        }	});}function stopSubmit() {	return false;	}//Performs the ajax get for boundingbox upon search.Hydro.Map.getBounds = function(){	$("#loadingCircle").show();		if(document.getElementById("cityName").value.length > 0){				$cityName = encodeURIComponent(document.getElementById("cityName").value);			$businessArea = encodeURIComponent(document.getElementById("ba").value);			$.post(Hydro.configPaths.ServletPath.SearchServlet, {cityName: $cityName, businessArea: $businessArea}, Hydro.Map.handleSearchResult,'html');			//alert($businessArea);		}		else		{			Hydro.Map.showMarkers($("#cbxHydro").attr('checked'), $("#cbxUnoX").attr('checked'), $("#cbxBensin").attr('checked'), $("#cbxE85").attr('checked'), $("#cbxDiesel").attr('checked'), $("#cbxB98").attr('checked'), $("#cbxBVP").attr('checked'), $("#cbxADB").attr('checked'), document.getElementById("cityName").value);			Hydro.Map.setCenter();			 $("#loadingCircle").hide();		}}//This function handles the adding of GeoRSS, removes the old layer aswell if a new search is made.Hydro.Map.showRss = function(hydro, unoX, bensin, e85, diesel, b98, bvp, adb){//	hydro = true;//	unoX = true;			//Check if the browser is IE6	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;		 var ieversion=new Number(RegExp.$1);		 		 //alert('You are using IE' + ieversion);	}		if(map == null){		Hydro.Map.setMap();	}	var sPath;	for(var i=0; i<map.layers.length;i++){		if(map.layers[i].CLASS_NAME == "OpenLayers.Layer.GeoRSS"){			map.removeLayer(map.layers[i]);			//sPath = Hydro.configPaths.ServletPath.GeoRssServlet +'?' + 'hydro=' + hydro + '&unox=' + unoX + '&bensin=' + bensin + '&e85=' + e85 + '&diesel=' + diesel;		}	}	businessArea = encodeURIComponent(document.getElementById("ba").value);	//alert(businessArea);	sPath = Hydro.configPaths.ServletPath.GeoRssServlet +escape('?' + 'businessArea=' + businessArea + '&hydro=' + hydro + '&unox=' + unoX + '&bensin=' + bensin + '&e85=' + e85 + '&diesel=' + diesel + '&b98=' + b98 + '&bvp=' + bvp + '&adb=' + adb);	//var newIcon = new OpenLayers.Icon("img/logo_hydro.gif", new OpenLayers.Size(10,10));		var size = new OpenLayers.Size(12,12);	//31,43	var calculateOffset = function(size) {	return new OpenLayers.Pixel(-(size.w/2), -size.h); 	};	var newIcon = new OpenLayers.Icon("img/logo_hydro.gif",	size, null, calculateOffset);	//var tempMarker = new OpenLayers.Marker(new OpenLayers.LonLat(x, y), icon);		var newRSSLayer = new OpenLayers.Layer.GeoRSS('Stationer', sPath, { 'icon': newIcon, 'useFeedTitle': false });	map.addLayer(newRSSLayer);	$("#loadingCircle").hide();}//Called by getBounds upon searchanswer from serverside, also passes the coords into zoomToBounds function if ajax is successful.Hydro.Map.handleSearchResult = function(sText, sStatus) { 	if (sStatus == "success") {        Hydro.Map.zoomToBounds(sText);    } else {        alert('Error occured in ajaxrequest!');    }}//Zoomfunction that centers the map when user searches a city.Hydro.Map.zoomToBounds = function(bounds){	if(map == null){		Hydro.Map.setMap();	}	if(bounds.length > 0){		var boundsList = bounds.split('&'); 		if(boundsList[3] == "0.0"){			Hydro.Map.setCenter();			$("#noResultDiv").show();			 $("#loadingCircle").hide();					}		else if(boundsList[0] > 0){			$("#noResultDiv").hide();			var bounds = new OpenLayers.Bounds(boundsList[0], boundsList[1], boundsList[2], boundsList[3]);			map.zoomToExtent(bounds);						//Check if the bounding box really fits within the zoom level set by OpenLayers.			//If not, zoom out one level			var extent = map.getExtent();						if(bounds.getWidth() > extent.getWidth() || bounds.getHeight() > extent.getHeight())			{				map.zoomOut();			}						 $("#loadingCircle").hide();		}	}}//Performs submit when user clicks Download.Hydro.Application.formSubmit = function(val){	if(val == "Download"){		document.forms[0].action=Hydro.configPaths.ServletPath.PoiController;		document.forms[0].submit();	}}
