// JavaScript Document
function getHTTPObject() //{{{
{
  var xmlhttp = false;
  /*@cc_on @*/
  /*@if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && window.createRequest) {
      try {
          xmlhttp = window.createRequest();
      } catch (e) {
          xmlhttp=false;
      }
  }
  return xmlhttp;
} //}}}

var http = getHTTPObject();
 
function updateLocations(){
document.getElementById("location").length = 0;
document.getElementById("CosmeticSurgeon").innerHTML='<input type="hidden" name="docCount" id="docCount" value="0">';
var url = "ajaxForm.php?";
  if(http) {
    var action = "getLocation";
    var pp=document.getElementById("procedure").value;
	var pp1=document.getElementById("procedure_o").value;
    var post = "action=" + escape(action) + "&pp=" + escape(pp)+ "&pp1=" + escape(pp1);

	http.open("GET", url+post, true);

	http.onreadystatechange = handleHttpResponse;
    http.send(null);
  }
} 

function updateDoctors(select){
document.getElementById("CosmeticSurgeon").innerHTML='<input type="hidden" name="docCount" id="docCount" value="0">';
var url = "ajaxForm.php?";
  if(http) {
    var action = "getDoctors";
    var id = select.value;
	var pp=document.getElementById("procedure").value;
	var pp1=document.getElementById("procedure_o").value;
    var post = "action=" + escape(action) + "&id=" + escape(id)+ "&pp=" + escape(pp)+"&pp1=" + escape(pp1);
	
	http.open("GET", url+post, true);
    http.onreadystatechange = handleHttpResponse;
    http.send(null);
  }
} 
 
 
 
function handleHttpResponse(http_request)
{
  if (http.readyState != 4) {
    
  } else if (http.readyState == 4) {
    if (http.status == 200) {
      if (http.responseText == 1) {
      } else {
        
		var s = http.responseText;

if(s.substr(0,4) == "gLoc") {
          /* Sub Category */
          fixLocations(s.substring(4));
        } else if(s.substr(0,4) == "gDoc") {
          /* Sub Category */
          fixDoctors(s.substring(4));
        } 
        
      }
    }
  }
}

function fixLocations(s)
{
  if (s=="0,0") {
	alert("Sorry combination not available");  
  }
  var method = document.getElementById("location");
  method.length = 1;
  var a = s.split(',');
  var b = a.length;
  for(i=0; i<b; i=i+2) {
	selectedRow = false;
	selectedRowSelected = false;
    if(a[i+1]!=0) method.options[method.options.length] = new Option(a[i+1], a[i], selectedRow, selectedRowSelected);
  }
}

function fixDoctors(s)
{
  if (s=="0,0") {
	alert("Procedure not available yet");  
  }
  var method = document.getElementById("CosmeticSurgeon");
  method.length = 0;
  var a = s.split(',');
  var b = a.length;
  resp=' <p>Choose a Cosmetic Surgeon<br />';
  for(i=0; i<b; i=i+2) {
    if(a[i]!=0) resp+='<input type="checkbox" name="doctor[]" id="doc'+i+'" value="'+a[i]+'" /> '+a[i+1]+" <br>";
  }
  resp+='<input type="hidden" name="docCount" id="docCount" value="'+i+'"></p>';
  method.innerHTML=resp;
}


