/*
 * Fluster2 0.1.1
 * Copyright (C) 2009 Fusonic GmbH
 *
 * This file is part of Fluster2.
 *
 * Fluster2 is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Fluster2 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Creates a new Fluster to manage masses of markers in a Google Maps v3.
 *
 * @constructor
 * @param {google.maps.Map} the Google Map v3
 * @param {bool} run in debug mode or not
 */
function Fluster2(_map, _debug)
{
	// Private variables
	var map = _map;
	var projection = new Fluster2ProjectionOverlay(map);
	var me = this;
	var clusters = new Object();
	var markersLeft = new Object();
	
	// Properties
	this.debugEnabled = _debug;
	this.gridSize = 60;
	this.markers = new Array();
	this.currentZoomLevel = -1;
	this.styles = {
		0: {
			image: 'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m1.png',
			textColor: '#FFFFFF',
			width: 53,
			height: 52
		},
		10: {
			image: 'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m2.png',
			textColor: '#FFFFFF',
			width: 56,
			height: 55
		},
		20: {
			image: 'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/images/m3.png',
			textColor: '#FFFFFF',
			width: 66,
			height: 65
		}
	};
	
	// Timeouts
	var zoomChangedTimeout = null;
	
	/**
	 * Create clusters for the current zoom level and assign markers.
	 */
	function createClusters()
	{
		var zoom = map.getZoom();
		
		if(clusters[zoom])
		{
			me.debug('Clusters for zoom level ' + zoom + ' already initialized.');
		}
		else
		{
			// Create clusters array
			var clustersThisZoomLevel = new Array();
			
			// Set cluster count
			var clusterCount = 0;
			
			// Get marker count
			var markerCount = me.markers.length;
			
			// Walk all markers
			for(var i = 0; i < markerCount; i++)
			{
				var marker = me.markers[i];
				var markerPosition = marker.getPosition();
				var done = false;
				
				// Find a cluster which contains the marker
				for(var j = clusterCount - 1; j >= 0; j--)
				{
					var cluster = clustersThisZoomLevel[j];
					if(cluster.contains(markerPosition))
					{
						cluster.addMarker(marker);
						done = true;
						break;
					}
				}
				
				if(!done)
				{
					// No cluster found, create a new one
					var cluster = new Fluster2Cluster(me, marker);
					clustersThisZoomLevel.push(cluster);
					
					// Increase cluster count
					clusterCount++;
				}
			}
			
			clusters[zoom] = clustersThisZoomLevel;
			
			me.debug('Initialized ' + clusters[zoom].length + ' clusters for zoom level ' + zoom + '.');
		}
		
		// Hide markers of previous zoom level
		if(clusters[me.currentZoomLevel])
		{
			for(var i = 0; i < clusters[me.currentZoomLevel].length; i++)
			{
				clusters[me.currentZoomLevel][i].hide();
			}
		}
		
		// Set current zoom level
		me.currentZoomLevel = zoom;
		
		// Show clusters
		showClustersInBounds();
	}
	
	/**
	 * Displays all clusters inside the current map bounds.
	 */
	function showClustersInBounds()
	{
		var mapBounds = map.getBounds();
		
		for(var i = 0; i < clusters[me.currentZoomLevel].length; i++)
		{
			var cluster = clusters[me.currentZoomLevel][i];
			if(mapBounds.contains(cluster.getPosition()))
			{
				cluster.show();
			}
		}
	}
	
	/**
	 * Callback which is executed 500ms after the map's zoom level has changed.
	 */
	this.zoomChanged = function()
	{
		window.clearInterval(zoomChangedTimeout);
		zoomChangedTimeout = window.setTimeout(createClusters, 500);
	};
	
	/**
	 * Returns the map assigned to this Fluster.
	 */
	this.getMap = function()
	{
		return map;
	};
	
	/**
	 * Returns the map projection.
	 */
	this.getProjection = function()
	{
		return projection.getP();
	};
	
	/**
	 * Prints debug messages to console if debugging is enabled.
	 */
	this.debug = function(message)
	{
		if(me.debugEnabled)
		{
			console.log('Fluster2: ' + message);
		}
	};
	
	/**
	 * Adds a marker to the Fluster.
	 */
	this.addMarker = function(_marker)
	{
		me.markers.push(_marker);
	};
	
	/**
	 * Returns the currently assigned styles.
	 */
	this.getStyles = function()
	{
		return me.styles;
	};
	
	/**
	 * Sets map event handlers and setup's the markers for the current
	 * map state.
	 */
	this.initialize = function()
	{		
		// Add event listeners
		google.maps.event.addListener(map, 'zoom_changed', this.zoomChanged);
		google.maps.event.addListener(map, 'dragend', showClustersInBounds);

		// Setup markers for the current state
		window.setTimeout(createClusters, 1000);
	};
	
// Modification	
function clearAll()
{
//me.debug('Clearing markers…, zoomlevel = '+me.currentZoomLevel);
for(var i = 0; i<15; i++)
{
for (var j=0; clusters[i] && j<clusters[i].length; j++)
{
//me.debug(‘Clearing markers…, i=’+i+’, j=’+j);
//if (clusters[i][j].marker)
//clusters[i][j].marker.setMap(null);
clusters[i][j].hide();
clusters[i][j] = null;
}
clusters[i]= null;
}

for (i = 0; i < me.markers.length; i++) {
me.markers[i].setMap(null);
}
me.markers = new Array();
clusters = new Object();
}

/**
* Remove all markers
*/
this.clearMarkers = function()
{
clearAll();
};	

// End Modification
	
}

/*
 * Fluster2 0.1.1
 * Copyright (C) 2009 Fusonic GmbH
 *
 * This file is part of Fluster2.
 *
 * Fluster2 is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Fluster2 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Cluster which holds one or more markers of the map.
 *
 * @constructor
 * @private
 * @param {Fluster2} the Fluster2 itself
 * @param {google.maps.Marker} the first marker
 */
function Fluster2Cluster(_fluster, _marker)
{	
	// Get properties from marker
	var markerPosition = _marker.getPosition();
	
	// Properties
	this.fluster = _fluster;
	this.markers = [];
	this.bounds = null;
	this.marker = null;
	this.lngSum = 0;
	this.latSum = 0;
	this.center = markerPosition;
	this.map = this.fluster.getMap();
	
	var me = this;
	
	// Get properties from fluster
	var projection = _fluster.getProjection();
	var gridSize = _fluster.gridSize;
	
	// Calculate bounds
	var position = projection.fromLatLngToDivPixel(markerPosition);
	var positionSW = new google.maps.Point(
		position.x - gridSize,
		position.y + gridSize
	);
	var positionNE = new google.maps.Point(
		position.x + gridSize,
		position.y - gridSize
	);
	this.bounds = new google.maps.LatLngBounds(
		projection.fromDivPixelToLatLng(positionSW),
		projection.fromDivPixelToLatLng(positionNE)
	);
	
	/**
	 * Adds a marker to the cluster.
	 */
	this.addMarker = function(_marker)
	{
		this.markers.push(_marker);
	};

	/**
	 * Shows either the only marker or a cluster marker instead.
	 */
	this.show = function()
	{
		// Show marker if there is only 1
		if(this.markers.length == 1)
		{
			this.markers[0].setMap(me.map);
		}
		else if(this.markers.length > 1)
		{
			// Hide all markers
			for(var i = 0; i < this.markers.length; i++)
			{
				this.markers[i].setMap(null);
			}
			
			// Create marker
			if(this.marker == null)
			{
				this.marker = new Fluster2ClusterMarker(this.fluster, this);
				
				if(this.fluster.debugEnabled)
				{
					google.maps.event.addListener(this.marker, 'mouseover', me.debugShowMarkers);
					google.maps.event.addListener(this.marker, 'mouseout', me.debugHideMarkers);
				}
			}
			
			// Show marker
			this.marker.show();
		}
	};
	
	/**
	 * Hides the cluster
	 */
	this.hide = function()
	{
		if(this.marker != null)
		{
			this.marker.hide();
		}
	};
	
	/**
	 * Shows all markers included by this cluster (debugging only).
	 */
	this.debugShowMarkers = function()
	{
		for(var i = 0; i < me.markers.length; i++)
		{
			me.markers[i].setVisible(true);
		}
	};
	
	/**
	 * Hides all markers included by this cluster (debugging only).
	 */
	this.debugHideMarkers = function()
	{
		for(var i = 0; i < me.markers.length; i++)
		{
			me.markers[i].setVisible(false);
		}
	};
	
	/**
	 * Returns the number of markers in this cluster.
	 */
	this.getMarkerCount = function()
	{
		return this.markers.length;
	};
	
	/**
	 * Checks if the cluster bounds contains the given position.
	 */
	this.contains = function(_position)
	{
		return me.bounds.contains(_position);
	};
	
	/**
	 * Returns the central point of this cluster's bounds.
	 */
	this.getPosition = function()
	{
		return this.center;
	};

	/**
	 * Returns this cluster's bounds.
	 */
	this.getBounds = function()
	{
		return this.bounds;
	};

	/**
	 * Return the bounds calculated on the markers in this cluster.
	 */
	this.getMarkerBounds = function()
	{
		var bounds = new google.maps.LatLngBounds(
			me.markers[0].getPosition(),
			me.markers[0].getPosition()
		);
		for(var i = 1; i < me.markers.length; i++)
		{
			bounds.extend(me.markers[i].getPosition());
		}
		return bounds;
	};
	
	// Add the first marker
	this.addMarker(_marker);
}

/*
 * Fluster2 0.1.1
 * Copyright (C) 2009 Fusonic GmbH
 *
 * This file is part of Fluster2.
 *
 * Fluster2 is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Fluster2 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * A cluster marker which shows a background image and the marker count 
 * of the assigned cluster.
 *
 * @constructor
 * @private
 * @param {Fluster2} the Fluster2 itself
 * @param {Fluster2Cluster} the Fluster2Cluster assigned to this marker
 */
function Fluster2ClusterMarker(_fluster, _cluster)
{
	this.fluster = _fluster;
	this.cluster = _cluster;
	this.position = this.cluster.getPosition();
	this.markerCount = this.cluster.getMarkerCount();
	this.map = this.fluster.getMap();
	this.style = null;
	this.div = null;
	
	// Assign style
	var styles = this.fluster.getStyles();
	for(var i in styles)
	{
		if(this.markerCount > i)
		{
			this.style = styles[i];
		}
		else
		{
			break;
		}
	}
	
	// Basics
	google.maps.OverlayView.call(this);
	this.setMap(this.map);
	
	// Draw
	this.draw();
};

Fluster2ClusterMarker.prototype = new google.maps.OverlayView();

Fluster2ClusterMarker.prototype.draw = function()
{
	if(this.div == null)
	{
		var me = this;
		
		// Create div
		this.div = document.createElement('div');
		
		// Set styles
		this.div.style.position = 'absolute';
		this.div.style.width = this.style.width + 'px';
		this.div.style.height = this.style.height + 'px';
		this.div.style.lineHeight = this.style.height + 'px';
		this.div.style.background = 'transparent url("' + this.style.image + '") 50% 50% no-repeat';
		this.div.style.color = this.style.textColor;
		
		// Marker count
		this.div.style.textAlign = 'center';
		this.div.style.fontFamily = 'Arial, Helvetica';
		this.div.style.fontSize = '11px';
		this.div.style.fontWeight = 'bold';
		this.div.innerHTML = this.markerCount;
		
		// Cursor and onlick
		this.div.style.cursor = 'pointer';
		google.maps.event.addDomListener(this.div, 'click', function() {
			me.map.fitBounds(me.cluster.getMarkerBounds());
		});
		
		this.getPanes().overlayLayer.appendChild(this.div);
	}
	
	// Position
	var position = this.getProjection().fromLatLngToDivPixel(this.position);
	this.div.style.left = (position.x - parseInt(this.style.width / 2)) + 'px';
	this.div.style.top = (position.y - parseInt(this.style.height / 2)) + 'px';
};

Fluster2ClusterMarker.prototype.hide = function()
{
	// Hide div
	this.div.style.display = 'none';
};

Fluster2ClusterMarker.prototype.show = function()
{
	// Show div
	this.div.style.display = 'block';
};

/*
 * Fluster2 0.1.1
 * Copyright (C) 2009 Fusonic GmbH
 *
 * This file is part of Fluster2.
 *
 * Fluster2 is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Fluster2 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * An empty overlay which is used to retrieve the map projection panes.
 *
 * @constructor
 * @private
 * @param {google.maps.Map} the Google Maps v3
 */
function Fluster2ProjectionOverlay(map)
{
	google.maps.OverlayView.call(this);
	this.setMap(map);
	
	this.getP = function()
	{
		return this.getProjection();
	};
}

Fluster2ProjectionOverlay.prototype = new google.maps.OverlayView();

Fluster2ProjectionOverlay.prototype.draw = function()
{
};

/*
Fluster loader
*/

function loadGMapWithFluster() {

	var mapTypes = new Array();
	mapTypes.push(google.maps.MapTypeId.ROADMAP);
	mapTypes.push(google.maps.MapTypeId.TERRAIN);
    
	map = new google.maps.Map(document.getElementById("map"), {
    center: initPosZoom.pos,
    zoom: initPosZoom.zoom,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    mapTypeControlOptions: {mapTypeIds: mapTypes}
    });
  pl = new progressLoader();
	map.controls[google.maps.ControlPosition.RIGHT].push(pl.getBar());

	// Initialize Fluster and give it a existing map
	fluster = new Fluster2(map);
	fluster.gridSize = 50;
			
  infoWindow = new google.maps.InfoWindow( {maxWidth: 300} );
			

  google.maps.event.addListener(map, 'zoom_changed', function() {
	    currentZoom=map.getZoom();
	    if(currentZoom<= 6){
	    	fluster.gridSize=50;
	    }else if(currentZoom<=9){
	    	fluster.gridSize=40;
	    }else if(currentZoom<=12){
	    	fluster.gridSize=20;
	    }else{
	    	fluster.gridSize=0;
	    	if(currentZoom>13){
	    		map.setZoom(13); 
	    	}
	    }
  	});
	

  loadXMLLocations(wsUrl+wsQS);
	
	fluster.styles = {
		// This style will be used for clusters with more than 0 markers
		0: {
			image: '/images/stories/gmap/small.png',
			textColor: '#ffffff',
			width: 45,
			height: 45
		},
		// This style will be used for clusters with more than 10 markers
		10: {
			image: '/images/stories/gmap/medium.png',
			textColor: '#ffffff',
			width: 55,
			height: 55
		},
		20: {
			image: '/images/stories/gmap/big.png',
			textColor: '#ffffff',
			width: 65,
			height: 65
		}
	};

}

function loadGMapPoint() {

	var mapTypes = new Array();
	mapTypes.push(google.maps.MapTypeId.ROADMAP);
	mapTypes.push(google.maps.MapTypeId.TERRAIN);
    
	map = new google.maps.Map(document.getElementById("map"), {
    center: initPosZoom.pos,
    zoom: initPosZoom.zoom,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    mapTypeControlOptions: {mapTypeIds: mapTypes}
    });
		
  infoWindow = new google.maps.InfoWindow( {maxWidth: 300} );
	
	if(csPoints.length > 0){
		for(i=0; i<csPoints.length; i++){
       var shortdesc = csPoints[i].shortdesc;
       var Url = csPoints[i].Url;
       var ref = csPoints[i].ref;
       var imgUrl = csPoints[i].imgUrl;
       var nbCouchages = csPoints[i].nbCouchages;
       var infomsg = '<p><strong>'+csPoints[i].name+'</strong><p><p><center><a href="'+Url+'" target="_blank"><img src="'+imgUrl+'" border="0" width="160" height="120"></a></center></p><p>'+shortdesc+'</p><p><u>Ref :</u> '+ref+'<br /><u>'+csLibs.nbCouchages+' :</u> '+nbCouchages+'</p><p><a href="'+Url+'" target="_blank">'+csLibs.voirLaPage+'</a></p><p><i>'+csLibs.infoApprox+'</i></p>';
       var latlng = new google.maps.LatLng(
	              parseFloat(csPoints[i].lat),
	              parseFloat(csPoints[i].lng));
	     createMarker(latlng, csPoints[i].name, infomsg, false, (csPoints.length==(i+1)));
		}
		//infoWindow.open(map, markers[i]);
	}
	
  google.maps.event.addListener(map, 'zoom_changed', function() {
	    currentZoom=map.getZoom();
    	if(currentZoom>13){
    		map.setZoom(13); 
    	}
  	});

}

function elmToUri(aqs,name){
			var a = new Array();
			for (var i=0; elm=document.getElementById(name+"["+i+"]"); i++){
				if(elm.checked){
					a.push(elm.name);
				}
			}
			if(a.length>0){
				aqs.push(name+"="+encodeURIComponent(a.join(',')));
			}
			return aqs;
}

function searchLocations() {
      pl.showBar();

			var searchUrl = wsUrl+'?';
			var aqs = new Array();
			for (var i=0; elm=document.getElementById("filter["+i+"]"); i++){
				aqs.push(elm.name+"="+encodeURIComponent(elm.value));
			}
			aqs=elmToUri(aqs,'equip');
			aqs=elmToUri(aqs,'zone');
			if(document.getElementById("prm").checked){
				aqs.push("prm=1");
			}
			if(document.getElementById("gm_dispo").checked){
				var arr = document.getElementById("gm_arr").value;
				if(arr==''){
					alert(csLibs.chooseDate);
					return false;
				}
				var lst = document.getElementById("gm_stay");
				dur = lst.options[lst.selectedIndex].value;
				if(dur=='0'){
					alert(csLibs.chooseDuree);
					return false;
				}
				aqs.push("arr="+encodeURIComponent(arr));
				aqs.push("dur="+encodeURIComponent(dur));
			}
			loadXMLLocations(searchUrl+aqs.join('&'));
}
	
function clearLocations() {
     infoWindow.close();
     for (var i = 0; i < markers.length; i++) {
       markers[i].setMap(null);
     }
     markers.length = 0;
     
     fluster.clearMarkers();
}

function createMarker(latlng, titre, html, flusterize, showinfo) {
      var marker = new google.maps.Marker({
        map: map,
        position: latlng,
        icon: '/images/stories/gmap/marker.png'
      });

			if(flusterize){
			// Add the marker to the Fluster
				fluster.addMarker(marker);
			}
      if(showinfo){
        infoWindow.setContent(html);
        infoWindow.open(map, marker);
      }
      google.maps.event.addListener(marker, 'click', function() {
        infoWindow.setContent(html);
        infoWindow.open(map, marker);
      });
      markers.push(marker);
}

function loadXMLLocations(searchUrl) {
     if(markers.length>0){
     	clearLocations(); 
     }
     downloadUrl(searchUrl, function(data) {
       var xml = parseXml(data);
       var markerNodes = xml.documentElement.getElementsByTagName("marker");
       var bounds;
       
       if(markerNodes.length>0){
       	 bounds = new google.maps.LatLngBounds();
	       for (var i = 0; i < markerNodes.length; i++) {
	         var name = markerNodes[i].getAttribute("name");
	         var shortdesc = markerNodes[i].getAttribute("shortdesc");
	         var Url = markerNodes[i].getAttribute("Url");
	         var ref = markerNodes[i].getAttribute("ref");
	         var imgUrl = markerNodes[i].getAttribute("imgUrl");
	         var nbCouchages = markerNodes[i].getAttribute("nbCouchages");
	         var infomsg = '<p><strong>'+name+'</strong><p><p><center><a href="'+Url+'" target="_blank"><img src="'+imgUrl+'" border="0" width="160" height="120"></a></center></p><p>'+shortdesc+'</p><p><u>Ref :</u> '+ref+'<br /><u>'+csLibs.nbCouchages+' :</u> '+nbCouchages+'</p><p><a href="'+Url+'" target="_blank">'+csLibs.voirLaPage+'</a></p><p><i>'+csLibs.infoApprox+'</i></p>';
	         var latlng = new google.maps.LatLng(
	              parseFloat(markerNodes[i].getAttribute("lat")),
	              parseFloat(markerNodes[i].getAttribute("lng")));
	         createMarker(latlng, name, infomsg, true, false);
	         bounds.extend(latlng);
	       }
					// Initialize Fluster
					// This will set event handlers on the map and calculate clusters the first time.
					if(!fluster.isInitialized){
						fluster.initialize();
					}
	        fluster.isInitialized=true;
	        map.fitBounds(bounds);
				}else{
					map.panTo(initPosZoom.pos);
					map.setZoom(initPosZoom.zoom);
				}
        if(map.getZoom()>10){
          map.setZoom(10);
        }
        pl.hideBar();
      });

}   
function downloadUrl(url, callback) {
      var request = window.ActiveXObject ?
          new ActiveXObject('Microsoft.XMLHTTP') :
          new XMLHttpRequest;

      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          callback(request.responseText, request.status);
        }
      };

      request.open('GET', url, true);
      request.send(null);
}

function parseXml(str) {
      if (window.ActiveXObject) {
        var doc = new ActiveXObject('Microsoft.XMLDOM');
        doc.loadXML(str);
        return doc;
      } else if (window.DOMParser) {
        return (new DOMParser).parseFromString(str, 'text/xml');
      }
}

function doNothing() {}
		
function reloadSearchElm(elm,name){
			var s="";
			var searchElms = eval(name+"List");
			var searchElm;
			var catTitle="";
			if(searchElms[elm.value].length > 0){
				for(i=0; i<searchElms[elm.value].length; i++){
					searchElm = searchElms[elm.value][i];
					if(catTitle!=searchElm.catTitle){
						if(catTitle!=""){
							s += '<div style="clear:left;"></div>';
						}
						s += '<div style="padding:3px 0 3px 0; width:100%;" class="csLabel1" id="'+searchElm.catTitle+'Lbl">'+searchElm.catTitle+'</div>';					
						catTitle=searchElm.catTitle;
					}
					s += '  <div style="float:left; padding:0 3px 0 0;">';
					s += '    <input id="'+name+'['+i+']" type="checkbox" name="'+searchElm.idtype+'" value="1" class="inputbox" >';
					s += '    <label class="csLabel2">'+searchElm.title+'</label>';
					s += '  </div>';
				}
				s += '<div style="clear:left;"></div>';
			}
			document.getElementById(name+'Block').innerHTML=s;
			
}

progressLoader = function() {
		  var div = document.createElement('div');
		  div.id  = 'loader_div';
		  div.style.display     = 'block';
		  div.style.width       = '220px';
		  div.style.height       = '30px';
			
		  var img = document.createElement('img');
		  img.id  = 'loader_img';
			img.src='/images/stories/gmap/ajax-loader.'+csLibs.lg+'.gif';
		  img.width       = '220';
		  img.height      = '30';
		  img.border			= '0';
		  div.appendChild(img);
			
		  var getBar = function() {
		    return div;
		  }
		  var showBar = function() {
		    div.style.display     = 'block';
		  }
		  var hideBar = function() {
		    div.style.display     = 'none';
		  }
		  return {
		    getBar: getBar,
		    showBar: showBar,
		    hideBar: hideBar
		  }
		  
		
}
