function createMarkerForMarkerManager(){
	//alert(facilityArray);
	//mgr = new MarkerManager(map);
	mgr.clearMarkers();
	createFacilityMarkerForMarkerManager();
	createContinentMarkerForMarkerManager();
	mgr.refresh();

}

function createContinentMarkerForMarkerManager(){
	
	if(continentArray != ''){
		for(var continentIndex=0 ; continentIndex < continentArray.length ; continentIndex++){
			var mark = createContinentMarker(continentIndex);
			mgr.addMarker(mark, 0, 2);
		}
	}
	
}

function createFacilityMarkerForMarkerManager(){

	if(searchCriteriaSpec == '' && (searchCriteriaProType == '')){
		createMarkerForAllFacilities();
	
	}else{
		createMarkerForSearchResult();

	}

}


function createMarkerForAllFacilities(){
	if(facilityArray != ''){
		for(var facilityIndex=0 ; facilityIndex < facilityArray.length ; facilityIndex++){
									
			var mark = createNewFacilityMarker(facilityIndex, true);
			mgr.addMarker(mark, 3);

		}
	}
}


function createMarkerForSearchResult(){
	
	var markers = new Array(facilityArray.length);
	for(var facilityIndex=0 ; facilityIndex < facilityArray.length ; facilityIndex++){

		var specialityPresent = false;
		var facilityPresent = false;
		var markerSelected = false;
		if(facilityArray[facilityIndex][1] != '' && searchCriteriaSpec != '')
		{
			var arrayLength = facilityArray[facilityIndex][1].length;
			var specialityIndex;
			for(specialityIndex=0; specialityIndex < arrayLength ; specialityIndex++){
				
				if(facilityArray[facilityIndex][1][specialityIndex] == searchCriteriaSpec){
					specialityPresent = true;
					break;
				}
			}//for end
		}//if end
		
		if(searchCriteriaProType != '' && facilityArray[facilityIndex][4] == searchCriteriaProType){
			facilityPresent = true;	
		}//if end

		if(facilityPresent == true && specialityPresent == true){
				markerSelected = true;
		}else if(facilityPresent == true && searchCriteriaSpec == ''){
				markerSelected = true;
		}else if(specialityPresent == true && searchCriteriaProType == ''){
				markerSelected = true;
		}//if end
		
	   markers[facilityIndex] = createNewFacilityMarker(facilityIndex, markerSelected);
	 
	}//for end
	
	mgr.addMarkers(markers, 3);

}//function end


// A function to create the marker for continents and set up the event window
function createNewFacilityMarker(index, searchResultIcon) {

	var html = "";

	var lat = parseFloat(facilityArray[index][2]);
	var lng = parseFloat(facilityArray[index][3]);
	var point = new GLatLng(lat,lng);
	var marker;	

	if(searchResultIcon){
		marker = new GMarker(point, { icon: getSearchResultIcon() });

	}else{
		marker = new GMarker(point, { icon: getGeneralIcon() });

	}
	
	
	var popupHeight = 150;
	var popupWidth = 270;

	

	if(facilityArray[index][0] != ''){
		
		if(facilityArray[index][5] != ''){
			
			html = html + '<h3><a href="'+facilityArray[index][5]+'" target="_blank">'+facilityArray[index][0]+'</a></h3>';

		}else{
			html = html + '<h3>'+facilityArray[index][0]+'</h3>';
		}

	}

	if(facilityArray[index][9] != ''){
		popupHeight = popupHeight + 6;
		html = html + facilityArray[index][9] + '<br />';
	}else{
		popupHeight = popupHeight - 6;
	}
	
	if(facilityArray[index][10] != ''){
		popupHeight = popupHeight + 6;
		html = html + facilityArray[index][10] + '<br />';
	}else{
		popupHeight = popupHeight - 6;
	}
	
	if(facilityArray[index][11] != ''){
		popupHeight = popupHeight + 6;
		html = html + facilityArray[index][11] + '<br />';
	}else{
		popupHeight = popupHeight - 6;
	}

	if(facilityArray[index][12] != ''){
		popupHeight = popupHeight + 6;
		html = html + facilityArray[index][12] + '<br />';
	}else{
		popupHeight = popupHeight - 6;
	}
	
	if(facilityArray[index][13] != ''){
		popupHeight = popupHeight + 6;
		html = html + facilityArray[index][13] + '<br />';
	}else{
		popupHeight = popupHeight - 6;
	}
	
	
	if(facilityArray[index][14] != ''){
		popupHeight = popupHeight + 6;
		html = html + '<strong>Tel: </strong> ' +facilityArray[index][14] + '<br />';
	}else{
		popupHeight = popupHeight - 6;
	}

	if(facilityArray[index][15] != ''){
		popupHeight = popupHeight + 10;
		html = html + '<strong>Email: </strong><a href="mailto:' + facilityArray[index][15] + '">' + facilityArray[index][15] +'</a> <br />';
	}else{
		popupHeight = popupHeight - 10;
	}
	
	if(facilityArray[index][16] != ''){
		popupHeight = popupHeight + 6;
		html = html + '<strong>Fax: </strong> ' +facilityArray[index][16] + '<br />';
	}else{
		popupHeight = popupHeight - 6;
	}

	if(facilityArray[index][17] != ''){
		popupHeight = popupHeight + 10;
		html = html + '<strong>Web Site: </strong><a href="' + facilityArray[index][17] + '" target="_blank">' + facilityArray[index][17] +'</a><br />';
	}else{
		popupHeight = popupHeight - 10;
	}

	
	if(facilityArray[index][1] != '')
	{
		popupHeight = popupHeight + 6;
		var arrayLength = facilityArray[index][1].length;
		var specialityArrayJsp = contextRoot + '/specialityPopupJs.do' + '?specialities='; 

		var flag = false;
		for(var specialityIndex=0; specialityIndex < arrayLength ; specialityIndex++){
			
			if(speciality != '')
			{
				specialityArrayJsp = specialityArrayJsp + facilityArray[index][1][specialityIndex]+ ',';
			
			}
		}	
		
		html = html + '<a href="javascript:specialityPopUp(\''+specialityArrayJsp+'\');">See full list of specialties...</a>';				

	}else {
		popupHeight = popupHeight - 10;
	}		
	
	html = html + '</div>';

	if(facilityArray[index][6] != ''){
		
		popupWidth = popupWidth + 70;
		var height = 66;//facilityArray[index][7];
		var width = 66;//facilityArray[index][8];
		if(height == ''){
			height = 66;	
		}
		if(width == ''){
			width = 66;	
		}

		html = html + '<div id="imgDivIntl" style="float:left;margin-left:10px;margin-right:10px;"><img src="'+ facilityArray[index][6] +'" width="'+ width +'" height="'+ height +'" /></div>';
	}
	
	//var myStyle = '<style type="text/css">#facilitypopupIntl{height:' + popupHeight + 'px !important;border:1px solid green;width:' + popupWidth + 'px;float:left;}</style>';
	
	var dynamicHeight = '<div id="facilitypopupIntl" style="height:' + popupHeight + 'px;width:' + popupWidth + 'px;float:left;">';
	
	html = dynamicHeight + html;

	GEvent.addListener(marker, "click", function() {
	  marker.openInfoWindowHtml(html);
	});

	// add a line to the side_bar html
	side_bar_html += '<a href="javascript:myclick(' + index + ')">' + facilityArray[index][0] + '<\/a><br>';
	return marker;

}



function getSearchResultIcon() {

	  //var i = Math.floor(IMAGES.length*Math.random());
	  //alert("dhappa");
	  if (!searchResultIcon) {
		searchResultIcon = new GIcon();
		searchResultIcon.image = "/bupastatic/images/gmap/red_marker.gif"; 
		searchResultIcon.iconAnchor = new GPoint(16, 16);
		searchResultIcon.infoWindowAnchor = new GPoint(16, 0);
		//searchResultIcon.iconSize = new GSize(32, 32);
		//icon.shadow = "images/" 
		//	+ IMAGES[i] + "-shadow.png";
		//icon.shadowSize = new GSize(59, 32);
	  }
	  return searchResultIcon;

}

function getGeneralIcon() {

	  //var i = Math.floor(IMAGES.length*Math.random());
	  if (!generalIcon) {
		generalIcon = new GIcon();
		generalIcon.image = "/bupastatic/images/gmap/grey_marker.gif";
		generalIcon.iconAnchor = new GPoint(16, 16);
		generalIcon.infoWindowAnchor = new GPoint(16, 0);
		//generalIcon.iconSize = new GSize(32, 32);
		//icon.shadow = "images/" 
		//	+ IMAGES[i] + "-shadow.png";
		//icon.shadowSize = new GSize(59, 32);
	  }
	  return generalIcon;

}


function addOption(selectbox,text,value, defaultSelection)
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	if(defaultSelection){
		optn.defaultSelected = true;
	}
	var theDropDown = document.getElementById(selectbox);
	theDropDown.options.add(optn);
}

function clearDropDown(dropdownId){
	var theDropDown = document.getElementById(dropdownId);  
	var numberOfOptions = theDropDown.options.length;
	for (i=0; i<numberOfOptions; i++) {  
		//Note: Always remove(0) and NOT remove(i)  
		theDropDown.remove(0);  
	} 

}


function specialityPopUp(urlspecialityPopUp) 
{
	var win = window.open(urlspecialityPopUp,'_blank','location=no,width=617,height=400,toolbar=no,menubar=no,titlebar=no,scrollbars=no');
	win.focus();    
}