// JavaScript Document

function init(){
	var req = new Ajax.Request(
			'server.php',
			{method: 'post', onComplete: ajax_response_menu}
	)
}
function ajax_response_menu(originalResponse){
	var jscript = originalResponse.responseText;
	eval(jscript);
	for (var k =0; k < hospitals.length; k++){
		//var thisHospital = document.createElement('option');
		//thisHospital.value = hospitals[k].value;
		//thisHospital.text = hospitals[k].text;
		//$('name').appendChild(thisHospital);
		var thisHospital = document.createElement('option');
		$('name').appendChild(thisHospital);
		thisHospital.value = hospitals[k].value;
		thisHospital.text = hospitals[k].text;
	}
}
function getHospital(){
//	alert($('name').value);
	var param = 'name=' + $('name').value;
	var req = new Ajax.Request(
				'serverA.php',
				{method:'post', parameters: param, onComplete: ajax_hospital_response}
	)
}


function getstatereport(){
//	alert($('name').value);
	var param = 'name=' + $('name').value;
	var req = new Ajax.Request(
				'serverAcategory.php',
				{method:'post', parameters: param, onComplete: ajax_state_response}
	)
}


function ajax_state_response(originalResponse){
	var jscript = originalResponse.responseText;
	eval(jscript);
	var html = '<a href="#" onclick="getHospital()"><p style="font-family:arial">Get Federal Report </p></a><br><center><u style="font-size:30px">State Report</u></center><br>This is information from 2005 reported by hospitals to the Florida Agency for Health Care Administration. The agency then rated hospitals in each category on their performance, taking into account how old, how sick and how complicated their patients were. The <font style="color:blue">rating</font> tells whether the hospital did better, worse or as well as would be expected based on their mix of patients. In some cases, hospitals had too few patients in a category for the state to reach a sound conclusion. <font style="color:blue">State average</font> tells the percentage of patients affected by the particular condition or procedure at the average hospital in Florida.<br><center><table  style="font-family:arial"><tr><td><b style="color:blue">Procedure/Condition</b></td><td><b style="color:blue">Rating</b></td><td><b style="color:blue">State Average</b></td></tr>';
	for (var k =0; k < hospitalstateinfo.length; k++){
		
		if ((k % 2) == 1) {
		html += '<tr bgcolor="#CCCCCC"><td style="padding-right:10px">' + hospitalstateinfo[k].procedure_or_condition + '</td><td style="padding-left:20px; padding-right:20px">' + hospitalstateinfo[k].rating + '</td><td style="padding-left:20px; padding-right:20px">' + hospitalstateinfo[k].state_avg + '</td></tr>';
		} else {
		html += '<tr><td style="padding-right:10px">' + hospitalstateinfo[k].procedure_or_condition + '</td><td style="padding-left:20px; padding-right:20px">' + hospitalstateinfo[k].rating + '</td><td style="padding-left:20px; padding-right:20px">' + hospitalstateinfo[k].state_avg + '</td></tr>';;
		}
	}
	
	
	html += '</table></center>';
	$('lblResult').innerHTML = html;
}

function ajax_hospital_response(originalResponse){
	var jscript = originalResponse.responseText;
	eval(jscript);
	var html = '<a href="#" onclick="getstatereport()"><u style="font-family:arial">Get State Report </u></a><br><center><u style="font-size:30px">Federal Report</u></center><br>This is information from 2005-06 reported by hospitals to the U.S. Department of Health and Human Services. The agency then rated hospitals in various type of best practices, which are methods proven to make medical care more effective or to lower the chances of complication. Hospitals use the methods to help patients admitted for heart attacks, heart failure or pneumonia, or to control infections, as listed in <font style="color:blue">category</font>. The <font style="color:blue">actual rate</font> tells how often the hospital used the method on a sampling of its patients. The <font style="color:blue">national rating</font> is based on how the hospital did compared to others. A hospital was rated <font style="color:blue">perfect</font> if it used the method 100 percent of the time, <font style="color:blue">above average</font> if it used the method significantly more than average and <font style="color:blue">below average</font> if it used the method significantly less than average.<br><center><table style="font-family:arial"><tr><td><b style="color:blue">Measure</b></td><td><b style="color:blue">Category</b></td><td><b style="color:blue">National Rating</b></td><td><b style="color:blue">Actual Rate</b></td></tr>';
	for (var k =0; k < hospitalDetails.length; k++){
		
		if ((k % 2) == 1) {
		html += '<tr bgcolor="#CCCCCC"><td style="padding-right:10px">' + hospitalDetails[k].measurename + '</td><td style="padding-left:20px; padding-right:20px">' + hospitalDetails[k].cat + '</td><td style="padding-left:20px; padding-right:20px">' + hospitalDetails[k].natgrade + '</td><td style="padding-left:20px; padding-right:20px">' + hospitalDetails[k].actrate + '</td></tr>';
		} else {
			html += '<tr><td style="padding-right:10px">' + hospitalDetails[k].measurename + '</td><td style="padding-left:20px; padding-right:20px">' + hospitalDetails[k].cat + '</td><td style="padding-left:20px; padding-right:20px">' + hospitalDetails[k].natgrade + '</td><td style="padding-left:20px; padding-right:20px">' + hospitalDetails[k].actrate + '</td></tr>';
		}
	}
	
	
	html += '</table></center>';
	$('lblResult').innerHTML = html;
}


