
 function hf_finder() {
     
    if(document.F1.facility_type.value != "-1")       
       document.F1.submit();
    else   
       document.F1.facility_type.focus();

 } // end


 function getDistrictDataList(ftype, cid, dregion, n, sby, sas) {

   data = "ftype=" + ftype + "&cid=" + cid + "&dregion=" + dregion + "&n=" + n;
   data += "&sby=" + sby + "&sas=" + sas;

   $.ajax({type: "POST", url: "facilities_data.php", data: data, cache: true,
     success: function(html){
       html_arr = html.split("##DATA##");
       $("#" + ftype + "_sorting").html(html_arr[2]);
       $("#" + ftype + "_area").html(html_arr[1]);
     }
    });
  
 } // end function


 function submitSortOptions(ftype, cid, dregion, n) {

   sby = RadioValue(ftype+'_sort_by');
   sas = RadioValue(ftype+'_sort_as');

   SortingList(ftype);
   getDistrictDataList(ftype, cid, dregion, n, sby, sas);
  
 } // end function


 function SortingList(ftype) {
 
   if(ftype == "hospitals") {
      $('#hospitals_sorting_list').toggle();
      $('#clinics_sorting_list').hide();
   }
   else {
      $('#clinics_sorting_list').toggle();
      $('#hospitals_sorting_list').hide();
   }
 
 } // end function
 

 function RegionDistrictsList(v) {

    if(v == "-1") {
       $("#district").html("<option value='0'>All Districts</option>");
    }
    else{
    
       v = v.replace("_hospitals","");
       v = v.replace("_clinics","");

       $("#district").html($("#"+v+"_region").html());

    } // end if

 } // end function


 function search_nav(n) {
 
    document.F1.action = "index.php?page=9&np=" + n;
    document.F1.submit();
 
 } // end function


 function RadioValue(vname) {

  var vObj = $('input[name='+vname+']:checked');
  var vVal = vObj.val();
  
  return vVal;
  
 } // end function
