// seperate .js for hospitals area


var hospital_map_has_been_created=0;

// hack for profiles
var has_item_one = 0;
var has_item_two = 0;

var added_row = 0;
$(document).ready(function(){	
hospital_cateogories = Array(); // keep all the measure categories in an omnipresent variable
// Navigation Features
	if(($("#page").val() == 'hospital_reports' && $('#sf').val() == 'hospital') || ($("#page").val() == 'hospital_search' && $('#sf').val() == 'hospital') || ($("#page").val() == 'hospital_profile' && $('#sf').val() == 'hospital')){
		getHospitalCategoryList();
	}

if($("#page").val() == 'home' && $('#sf').val() == 'hospital'){
		getHospitalMeasureList(); // there's only hospitals for this :(

	}	

function getHospitalMeasureList() {
		$.ajax({
			type: "POST", url: "actions/get_xml.php",
			data: 'feed=hospital_measure_list/',
			success: 	function(xml){ populateHospitalDropdown(xml);  },
			error: 		function(){ }	
		});
}

function populateHospitalDropdown(xml) {
	$('#measure_list_dropdown').empty();
	$('#measure_list_dropdown').append("<option value='all'>All</option>");


	// Parse XML and append data to the dropdown
	$('hospital-measure',xml).each(function(i){		
		// Find top level (non component) data
		id = $(this).find('id:first').text();			
		name = $(this).find('public-name:first').text();
		$('#measure_list_dropdown').append("<option value='"+id+"'>"+name+"</option>");
	});
}
// Ajax Get Data
function getHospitalCategoryList(){
		$.ajax({
			type: "POST", url: "actions/get_xml.php",
			data: 'feed=hospital_measure_list/',
			success: 	function(xml){ populateHospitalCategorySidebar(xml);  },
			error: 		function(){ $('#error_feedback').append(""); }	
		});

}
function getHospitalData() {

 	$('#data_table_loading').html("<div id='data_table_loading_inner' style='margin:auto;'><img alt='Loading...' src='assets/loading.gif' /></div>");
	var category = $('#category').val();
	if(category != "all") { 
		data_feed = 'feed=hospital_measure_data_current/' + category;
	} else { 
		data_feed = 'feed=hospital/';
		//data_feed = 'feed=hospital_measure_data_current/1';
	}
	
	if($("#page").val() == 'hospital_search' && $("#search_phrase").val() != "") { 
		thesearchphrase = $("#search_phrase").val();
		data_feed = 'feed=hospital_search/' + thesearchphrase + "";
		$.ajax({
			type: "POST", url: "actions/get_xml.php",
			data: data_feed,
			success: 	function(xml){ populateHospitalDataList(xml, 0);  },
			error: 		function(){ populateHospitalDataList(0, 1); }	
		});	
	
	} else if($("#page").val() == 'hospital_profile'){
	var hospital_id = $('#hospital_id').val();
	data_feed = 'feed=hospital/' + hospital_id + "";
			$.ajax({
			type: "POST", url: "actions/get_xml.php",
			data: data_feed,
			success: 	function(xml){ populate_hospital_profile(xml, 0);  },
			error: 		function(xml){ populate_hospital_profile(0, 1); }	
		});	
			
	
	} else {
		data_feed = data_feed;
		$.ajax({
			type: "POST", url: "actions/get_xml.php",
			data: data_feed,
			success: 	function(xml){ populateHospitalDataList(xml);  },
			error: 		function(){ populateHospitalDataList(xml, 1); }	
		});
	}

}
// Populate data list functions
function populateHospitalCategorySidebar(xml) {
		var page = $('#page').val();
		var sf = $('#sf').val();
		var category = $('#category').val();
		var sub_category = $('#sub_category').val();
		var name_id = $('#name_id').val();
		var compare = $('#compare').val();
		var search_phrase = $('#search_phrase').val();
		var hospital_id = $('#hospital_id').val();
		$('hospital-measure',xml).each(function(i){
			id = $(this).find('id:first').text();			
			name = $(this).find('public-name:first').text();
			hospital_cateogories.push(id);
		
			selected = (category == id)? " id='cat_"+id+"' class='selected' " : "";
		
		$('#sb_nav').append("<li "+selected+"><a class='sb_link' id='sb_nav_"+id+"' href='?p="+page+"&amp;sf="+sf+"&amp;search_phrase="+search_phrase+"&amp;category="+id+"&amp;name_id="+name_id+"&compare="+compare+"&hospital_id="+hospital_id+"&detail=" + $('#detail').val() +"'>"+name+"</a></li>");

		
	});
	
	// get data function goes here
	getHospitalData();

	}
function populateHospitalDataList(xml, error) {
	//doin thangs with the data list
	$('#data_table_loading').empty();
	if(error) {
		$('#data_table_tbody').append(
			"<tr class='colbody_top'>"+
				"<td colspan='6' class='no_results'>"+
					"<b>We're sorry, there were no results found for your search.</b><br />"+
					"Here are a few ideas that will hopefully improve your search results:<br /><br />"+
					"1. Double check the spelling of your search.<br />"+
					"2. Try using fewer words.<br />"+
					"3. Try using just part of the word that you are looking for.<br />"+
				"</td>"+
			"</tr>"
		);

	} else {

	if($('#category').val() == 'all' || $('#page').val() == 'hospital_search' && $('#search_phrase').val() != "") { 
	
	
		// general listing for all hospitals		

			$('hospital',xml).each(function(i){
			

				hospital_name 		 = $(this).find('name:first').text();
				city     			 = $(this).find('city:first').text();
				state				 = $(this).find('state:first').text();			
				zip					 = $(this).find('zip-five:first').text();			
				hospital_identifier  = $(this).find('mncm-identifier:first').text();
				profile_link1 = '<a href="?p=hospital_profile&hospital_id=' + hospital_identifier + '&sf=hospital">' + hospital_name + '</a>';
				profile_link2 = '<a href="?p=hospital_profile&hospital_id=' + hospital_identifier + '&sf=hospital">view profile > </a>';
				
				$('#data_table_tbody').append("<tr class='hospital_row'>" + 
				"<td class='name'><span style='display:none'>" + hospital_name + "</span>" + profile_link1 + "</td>" +
				"<td>" + city + "</td>" + 
				"<td>" + zip + "</td>" + 
				"<td></td>" + 
				"<td></td>" + 
				"<td>" + profile_link2 +"</td></tr>");
			});
$("#entry_table").tablesorter();

	} else {
		
	if($('#detail').val() == '1') { // show the table with full detail six columns
		$('public-measure-summary',xml).each(function(i){
			hospital_name 		 = $(this).find('hospital-name:first').text();
			city_zip 			 = $(this).find('hospital-city:first').text() + " " + $(this).find('hospital-zip:first').text();
			observed_numerator   = $(this).find('observed-numerator:first').text();
			observed_denominator = $(this).find('observed-denominator:first').text();
			mortality_rate       = parseFloat($(this).find('observed-rate:first').text()).toFixed(3);
			confidence_interval  = "(" + parseFloat($(this).find('ci-lower:first').text()).toFixed(3) +
			" - " + parseFloat($(this).find('ci-upper:first').text()).toFixed(3) + ")";
			expected_rate        = parseFloat($(this).find('expected-rate:first').text()).toFixed(3);
			compared_to_expected = $(this).find('rating:first').text();
			hospital_identifier  = $(this).find('hospital-identifier:first').text();
			if(compared_to_expected == 'Better') { 
				compared_image = '<img src="assets/hospital_icons/better.gif" alt="Better"/>';
			}
			if(compared_to_expected == 'Same') { 
				compared_image = '<img src="assets/hospital_icons/same.gif" alt="Same"/>';
			}
			if(compared_to_expected == 'Worse') { 
				compared_image = '<img src="assets/hospital_icons/worse.gif" alt="Worse"/>';
			}
			
			profile_link = '<a href="?p=hospital_profile&hospital_id=' + hospital_identifier + '&sf=hospital">' + hospital_name + '</a>';
			$('#data_table_tbody').append("<tr class='hospital_row'>" + 
			"<td class='hospital_cell hospital_cell_first'><span style='display:none'>"+ hospital_name + "</span><span class='name'>" + profile_link + "</span><br/><span class='address'>" + city_zip + "</span></td>" + 
			"<td class='hospital_cell'>" + observed_numerator + "</td>" + 
			"<td class='hospital_cell'>" + observed_denominator + "</td>" + 
			"<td class='hospital_cell'>" + mortality_rate + " " + confidence_interval  + "</td>" + 
			"<td class='hospital_cell'>" + expected_rate + "</td>" + 
			"<td class='hospital_cell'>" +compared_image + "<br/> " + compared_to_expected + "</td>" + 
			"</tr>");

			
		
		});//end XML loop
		$("#entry_table").tablesorter({
			sortList: [[5,0]]		
		});  
	}
	if($('#detail').val() == 'default') { // simplified display, two columns
	
	var column_to_sort;
		$('public-measure-summary',xml).each(function(i){
			id = $(this).find('code:first').text();			
			hospital_name = $(this).find('hospital-name:first').text();
			city_zip = $(this).find('hospital-city:first').text() + " " + $(this).find('zip-five:first').text();
			observed_numerator = $(this).find('observed-numerator:first').text();			
			observed_denominator = $(this).find('observed-denominator:first').text();
			rating = $(this).find('rating:first').text();
			measure_id = $(this).find('measure-id:first').text();
			hospital_identifier  = $(this).find('hospital-identifier:first').text();
			volume_threshold = $(this).find('volume-threshold:first').text();
			the_category = $('#category').val();
			profile_link = '<a href="?p=hospital_profile&hospital_id=' + hospital_identifier + '&sf=hospital">' + hospital_name + '</a>';
			
		if(rating == 'Better') {
			classScale = 'full';
			rating_number = 3;
		} else if(rating == 'Same') {
			classScale = 'half';
			rating_number = 2;
		} else if(rating == 'Worse') {
			classScale = 'empty';
			rating_number = 1;
		}
		var proficiency_graphic;
		if(volume_threshold == 'Met') { 
			proficiency_graphic = "<img src='assets/hospital_icons/check_greenbg.jpg' alt='Proficient' />";
		} else { 
			proficiency_graphic = "";
		}
		var good_id = parseInt(measure_id);

		if(measure_id >= parseInt('4')) {

			var thestring1 = "<tr class='hospital_row'>" + // no procedure number
					"<td class='hospital_cell hospital_cell_first'><span style='display:none'>"+ hospital_name + "</span><span class='name'>" + profile_link + "</span><br/><span class='address'>" + city_zip + "</span></td>" + 			
			"<td class='hospital_cell line_background2'><div style='display:none'>" + rating_number + "</div><div class='rating_text_default'>" + rating + "</div><div class='scale2 " + classScale + "'></div></td>" + 
			"</tr>";
			$('#data_table_tbody').append(thestring1);
			column_to_sort = 1;
		} else {
			var thestring2 = "<tr class='hospital_row'>" + // procedure number
			"<td class='hospital_cell hospital_cell_first'><span style='display:none'>"+ hospital_name + "</span><span class='name'>" + profile_link + "</span><br/><span class='address'>" + city_zip + "</span></td>" + 
			"<td class='hospital_cell procedures'>" + observed_denominator + " " + proficiency_graphic + "</td>" + 
			"<td class='hospital_cell line_background'><div style='display:none'>" + rating_number + "</div><div class='rating_text_default'>" + rating + "</div><div class='scale " + classScale + "'></div></td>" + 
			"</tr>";
			$('#data_table_tbody').append(thestring2);
			column_to_sort = 2;
		}
		

		
		
		});
		//end XML loop
			$("#entry_table").tablesorter({
			
				sortList: [[column_to_sort,0]]

			});   
		}
	}
	}

}
function populate_hospital_profile(xml, hospital_categories) {
	$('#data_table_tbody').empty();
	$('#data_table_loading').empty();
		
		
			$('#show_overview').click(function(){
			$('#profile_affiliations').hide(); 	$('#show_affiliations').removeClass('selected');	
			$('#profile_location').hide();		$('#show_location').removeClass('selected');
			$('#profile_overview').show();		$('#show_overview').addClass('selected');
			$('#profile_data_area').show();
			
			$('#profile_category_data').show();

			return false;
		});

		$('#show_location').click(function(){
			$('#profile_overview').hide();		$('#show_overview').removeClass('selected');
			$('#profile_affiliations').hide();	$('#show_affiliations').removeClass('selected');
			$('#profile_location').show();		$('#show_location').addClass('selected');
			$('#profile_data_area').hide();

			$('#profile_category_data').hide();

			if(!hospital_map_has_been_created){
				showHospitalMap(xml);
			}
			return false;
		});		
		var this_counter = 0;
		
		$('hospitals',xml).each(function(i){
			address1 		= $(this).find('address-line1:first').text();
			address2 		= $(this).find('address-line2:first').text();
			bed_size 		= $(this).find('bed-size:first').text();
			city 			= $(this).find('city:first').text();
			id 				= $(this).find('mncm-identifier:first').text();
			hospital_name 	= $(this).find('name:first').text();
			main_phone	= $(this).find('phone:first').text();
			state  			= $(this).find('state:first').text();
			zip_code 		= $(this).find('zip-code:first').text();
			region			= $(this).find('region:first').text();
			website 		= $(this).find('website:first').text();

		

		
		
		main_phone = main_phone.replace(/-/g,'');
		main_phone = main_phone.split('');
		main_phone = (main_phone!='')? "Main Phone: "+main_phone[0]+main_phone[1]+main_phone[2]+"-"+main_phone[3]+main_phone[4]+main_phone[5]+"-"+main_phone[6]+main_phone[7]+main_phone[8]+main_phone[9] : "";	
		
			$('#profile_name').append("" + hospital_name + "");
			$('#profile_overview').append(
				"<table>"+
					"<tr>"+
						"<td><a href='"+website+"'>" + website + "</a><br/><br/>" + main_phone + "</td>" + "<td></td>"+
					"</tr>"+
				"</table>"	
			);
			if($('#detail').val() == '1') { // complex
				$('#profile_data_area').append(
				"<div class='no_data'>No Measures Available</div>" +
				"<div class='detail_simple'><a href='?p=hospital_profile&amp;hospital_id=" + id + "&amp;sf=hospital&amp;detail=default&amp;category=" + $('#category').val() + "'><img src='assets/hospital_icons/summary_view.gif' /> Simple Display</a><br/></div><br/>");
				$('#profile_data_area').append(
				"<table id='data_table'>"+
				"<thead>"+
									
				"<tr style='border-bottom: solid 3px #BECAC7;'>" + 
				"<th class='greybox_colheader toggler' style='vertical-align: middle'><span class='condition_header'>Condition</span></th>" +
				"<th class='greybox_colheader' style='width: 65px;'><a href='#' title='The number of patients who had a negative event. Click on a specific condition below for more detailed information.' class='with-tooltip'>Numerator</a></th>"+
				"<th class='greybox_colheader' style='width: 65px;'><a href='#' title='The total number of patients considered. Click on a specific condition below for more detailed information.' class='with-tooltip'>Denominator</a></th>"+
				"<th class='greybox_colheader' style='width: 110px;'><a href='#' title=\"A hospital's numerator over its denominator adjusted for the severity of illness among patients (and a range of possible rates). Click on a condition below for more detailed information.\" class='with-tooltip'>Risk&nbsp;Adjusted&nbsp;Rate (Risk&nbsp;Adjusted&nbsp;Confidence&nbsp;Interval)</a></th>"+
				"<th class='greybox_colheader' style='width: 110px;'><a href='#' title=\"The rate expected for a hospital with a similar mix of patients. Click on a specific condition below for more detailed information.\" class='with-tooltip'>Expected</a></th>"+
				"<th class='greybox_colheader'><a href='#' title=\"A rating of how a hospital’s risk adjusted rate compared to its expected rate. Click on a specific condition below for more detailed information.\"  class='with-tooltip'>Compared<br/>To Expected</a></th>" +
				"</tr></thead>" +
				"<tbody id='data_table_tbody'>");
				$(hospital_cateogories).each(function(i){
					appendHospitalProfileData(this, id);
				});
				$('#profile_data_area').append(
				"</tbody>" +
				"</table>");
						$('.detail_simple').hide();
					$('#data_table').hide();
		
				
			} else { // simple
				
				$('#profile_data_area').append(
				"<div class='no_data'>No Measures Reported.</div>" +
				"<div class='detail_simple'><a href='?p=hospital_profile&amp;hospital_id=" + id + "&amp;sf=hospital&amp;detail=1&amp;category=" + $('#category').val() + "'><img src='assets/hospital_icons/detail_view.gif' /> Detail View</a><br/></div><br/><br/>" + 
				"<div id='data_info_one'>A Rating-better, same, or worse than expected—applies to all categories or conditions. A Proficiency score only applies to the measures listed below</div>"+				
				"<table id='data_table_one' style='width: 670px;'>"+
				"<thead>"+
				"<tr class='colhead_hospital'>" +
				"<th class='toggler' style='border-bottom: solid 3px #ccc;'><br/>Click column headers to sort<br/><br/><span class='condition_header'>Condition</span></th>" + 
				"<th class='greybox_colheader_sort' style='border-bottom: solid #becac7 3px; width: 120px;font-size: 12px;'>Number of Procedures<br/><img src='assets/hospital_icons/check_greybg.jpg' alt='Checkmark' /> = <a title='If a hospital has a green checkmark, they have met or exceeded the minimum recommended number of procedures.' class='with-tooltip' href=#>Proficient</a></th>"+
												
				"<th class='greybox_colheader_sort' style='border-bottom: solid #becac7 3px; width: 240px;font-size: 12px;'><?=$detail_text_cat?><br/>Compared to <a href='#' title='This rating indicates how the hospital performed compared to what would be expected for that hospital. Hospitals may have performed better, the same, or worse than expected.' class='with-tooltip'>Expected Rate</a></th>" +
				"</tr>" + 
				"</thead>" +
				"<tbody id='data_table_tbody_one'>");

				$(hospital_cateogories).each(function(i){
				if(this == 3 || this == 2 || this == 1) {
					appendHospitalProfileData(this, id, 1);
						this_counter++;						
									
					}
				});
			
				$('#profile_data_area').append(
				"</tbody>" +
				"</table>");
				// add a second table
				$('#profile_data_area').append(
				"<br/><br/>" +
				"<div id='data_info_two'>Only a rating is reported for the following surgical procedures or conditions.</div>" +
				"<br/>" +
				
				"<table id='data_table_two' style='width: 670px;'>"+
				"<thead>"+
				"<tr class='colhead_hospital'>" +
				"<th class='toggler' style='border-bottom: solid 3px #ccc;'>Click column headers to sort<br/><br/><span class='condition_header'>Condition</span></th>" + 
				"<th class='greybox_colheader_sort' style='border-bottom: solid #becac7 3px; width: 240px;font-size: 12px;'><?=$detail_text_cat?><br/>Compared to <a href='#' title='This rating indicates how the hospital performed compared to what would be expected for that hospital. Hospitals may have performed better, the same, or worse than expected.' class='with-tooltip'>Expected Rate</a></th>" +
				"</tr>" + 
				"</thead>" +
				"<tbody id='data_table_tbody_two'>");
					
				$(hospital_cateogories).each(function(i){
					if(this != 3 && this != 2 && this != 1) {
						appendHospitalProfileData(this, id, 0)
						
					}
				});
			
				$('#profile_data_area').append(
				"</tbody>" +
				"</table><br/><br/>");
				
			}
			
	
	
		$('.detail_simple').hide();
		$('#data_table_one').hide();
		$('#data_table_two').hide();
		$('#data_info_two').hide();
		$('#data_info_one').hide();
		

	/*if($('#category').val() == '1' || $('#category').val() == '2' || $('#category').val() == '3') {
		$('#data_table_one').show();
	}*/
	
	});
	
	$(".with-tooltip").simpletooltip();
	

	
	
}
function getHospitalSearchResults(search_phrase){

		feed = 'feed=hospital_search /'+search_phrase+'';
		$('#data_table_loading').html("<div id='data_table_loading_inner'><img alt='Loading...' src='assets/loading.gif' /></div>");
			
			$.ajax({
				type: "POST", url: "actions/get_xml.php",
				data: feed,
				success: 	function(xml){ populateHospitalDataList(xml); },		
				error: 		function(xml){ $('#error_feedback').append(""); populateHospitalDataList(xml); },
				complete: 	function(){ $('#data_table_loading').remove(); }
			});		

		
		}	

function appendHospitalProfileData(category_id, hospital_id, two_column) { 


		feed = 'feed=hospital_measure_data/'+ category_id +'/' + hospital_id + '/';
		$('#data_table_loading').html("<div id='data_table_loading_inner'><img alt='Loading...' src='assets/loading.gif' /></div>");
					if($('#category').val() == 'all') { 
						var is_added = $.ajax({
							type: "POST", url: "actions/get_xml.php",
							data: feed,
							success: 	function(xml, added_row){ 
												add_data_row_profile(category_id, xml, 0, two_column);
																																														
							},		
							error: 		function(xml){  
							
							},
							// async: false,
							complete: 	function(xml, status){ 
								$('#data_table_loading').remove();
								

								
								
							
							}
						});		
					} else { 
						if(category_id == $('#category').val()) { //only append row if you're in the correct category
						var is_added = $.ajax({
							type: "POST", url: "actions/get_xml.php",
							data: feed,
							success: 	function(xml, added_row){ 
														add_data_row_profile(category_id, xml, 0, two_column);
														
														
							},		
							error: 		function(xml){ 
							
							 },
							complete: 	function(xml, status){ 
							$('#data_table_loading').remove(); 																						
								
							}
						});		

						
						}
				
					}	

			 

}
function add_data_row_profile(category_id, xml, error, two_column) { 
$('.no_data').hide();
		if($('#detail').val() == '1') {
			$('public-measure-summary', xml).each(function(i) {
				
				hospital_name 		 = $(this).find('hospital-name:first').text();
				measure_name		 = $(this).find('measure-name:first').text();
				city_zip 			 = $(this).find('hospital-city:first').text() + " " + $(this).find('hospital-zip:first').text();
				observed_numerator   = $(this).find('observed-numerator:first').text();
				observed_denominator = $(this).find('observed-denominator:first').text();
				mortality_rate       = parseFloat($(this).find('observed-rate:first').text()).toFixed(3);
				confidence_interval  = "(" + parseFloat($(this).find('ci-lower:first').text()).toFixed(3) +
				" - " + parseFloat($(this).find('ci-upper:first').text()).toFixed(3) + ")";
				expected_rate        = parseFloat($(this).find('expected-rate:first').text()).toFixed(3);
				compared_to_expected = $(this).find('rating:first').text();
				hospital_identifier  = $(this).find('hospital-identifier:first').text();
				if(compared_to_expected == 'Better') { 
					compared_image = '<img src="assets/hospital_icons/better.gif" alt="Better"/>';
				}
				if(compared_to_expected == 'Same') { 
					compared_image = '<img src="assets/hospital_icons/same.gif" alt="Same"/>';
				}
				if(compared_to_expected == 'Worse') { 
					compared_image = '<img src="assets/hospital_icons/worse.gif" alt="Worse"/>';
				}
				
				
				var measure_link = "?p=hospital_profile&hospital_id=" + $('#hospital_id').val() + "&detail=0&sf=" + $('#sf').val() + "&category=" + category_id;
				$('#data_table_tbody').append("<tr class='hospital_row'>" + 
				"<td class='hospital_cell hospital_cell_first'  style='padding-left: 10px;'><b><a href='"+ measure_link +"'>" + measure_name + "</a></b></td>" + 
				"<td class='hospital_cell'>" + observed_numerator + "</td>" + 
				"<td class='hospital_cell'>" + observed_denominator + "</td>" + 
				"<td class='hospital_cell'>" + mortality_rate + " " + confidence_interval  + "</td>" + 
				"<td class='hospital_cell'>" + expected_rate + "</td>" + 
				"<td class='hospital_cell'>" +compared_image + "<br/> " + compared_to_expected + "</td>" + 
				"</tr>");

			$('#data_table').show();
			$('.detail_simple').show();
			
			});
			} else { 
			//<volume-proficiency type="NilClass">1</volume-proficiency>
			$('public-measure-summaries public-measure-summary', xml).each(function(i) {
			
			id = $(this).find('code:first').text();			
			measure_name		 = $(this).find('measure-name:first').text();
			city_zip = $(this).find('hospital-city:first').text() + " " + $(this).find('hospital-zip:first').text();
			observed_numerator = $(this).find('observed-numerator:first').text();			
			observed_denominator = $(this).find('observed-denominator:first').text();			
			rating = $(this).find('rating:first').text();
			measure_id = $(this).find('measure-id:first').text();
			hospital_identifier  = $(this).find('hospital-identifier:first').text(); 
			proficient = $(this).find('volume-proficiency').text();


			var measure_link = "?p=hospital_profile&hospital_id=" + $('#hospital_id').val() + "&detail=1&sf=" + $('#sf').val() + "&category=" + category_id;
		if(rating == 'Better') {
			classScale = 'full';
		} else if(rating == 'Same') {
			classScale = 'half';
		} else if(rating == 'Worse') {
			classScale = 'empty';
		}
		
		var good_id = parseInt(measure_id);

		
			if(proficient) { 
				checkmark_image = '<img src="assets/hospital_icons/check_greenbg.jpg" />';
			} else { 
				checkmark_image = '';
			}
			var string2 = "<tr class='hospital_row'>" + // procedure number
			"<td class='hospital_cell hospital_cell_first'  style='padding-left: 10px;'><b><a href='"+ measure_link +"'>" + measure_name + "</a></b></td>";
			if(measure_id >= parseInt('4')) {
				// string2 = string2 + "<td class='hospital_cell procedures' style='width: 150px'>N/A</td>";
		
			} else {
				string2 = string2 +  "<td class='hospital_cell procedures' style='width: 150px'>" + observed_denominator + " " + checkmark_image +"</td>";
			}
			string2 = string2 + "<td class='hospital_cell line_background' style='width: 300px;padding-left: 5px;'><div class='rating_text_default'>" + rating + "</div><div class='scale " + classScale + "'></div></td>";
			
			string2 = string2 + "</tr>";
			
			if(two_column) { 
				$('.no_data').hide();
				$('#data_table_one').show();
				$('#data_info_one').show();
				$('.detail_simple').show();
				$('#data_table_tbody_one').append(string2);
	
			} else {
				$('.no_data').hide();
				$('#data_table_two').show();			
				$('#data_info_two').show();
				$('.detail_simple').show();
				$('#data_table_tbody_two').append(string2);
				

			}
		


			});
			
			}
			

			
$('#data_table_one').tablesorter({
			

				
			});  
$('#data_table_two').tablesorter({
			

				
			});  
			
			

}


function showHospitalMap(xml){
	
	map_has_been_created=1;
	
	

	// Parse XML and append data to the dropdown
	$('hospitals', xml).each(function(i){				
		
			address1 		= $(this).find('address-line1:first').text();
			address2 		= $(this).find('address-line2:first').text();
			bed_size 		= $(this).find('bed-size:first').text();
			city 			= $(this).find('city:first').text();
			id 				= $(this).find('mncm-identifier:first').text();
			hospital_name 	= $(this).find('name:first').text();
			main_phone	= $(this).find('phone:first').text();
			state  			= $(this).find('state:first').text();
			zip_code 		= $(this).find('zip-code:first').text();
			region			= $(this).find('region:first').text();


		// 
		// Create Map
		// -------------------------------------------------------
		//alert(addressline1+' '+addressline2+' '+city+' '+state+' '+zipcode);
		
		showAddress(address1+' '+address2+' '+city+' '+state+' '+zip_code);
		$('#map_link').append("<br /><a target='_blank' href='http://maps.google.com/maps?q="+address1+" "+address2+" "+city+" "+state+" "+zip_code+"'>Find this Location on Google Maps >> </a><br /><br />");
		
	});
}

}); // end document ready