var xmlhttp

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
	 try {
	   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch(e) {
	   try {
	     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	   } catch(e) {
	     xmlhttp = false;
	   }
	 }
  @else
     xmlhttp = false;
  @end @*/
  
if (!xmlhttp && typeof(XMLHttpRequest) != 'undefined') {
  try {
	xmlhttp = new XMLHttpRequest();
  } catch (e) {
	xmlhttp = false;
  }
}

function myXMLHttpRequest() {
  var xmlhttplocal;
  
  try {
	xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
  } catch (e) {
    try {
	  xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
	} catch (E) {
	  xmlhttplocal=false;
	}
  }

  if (!xmlhttplocal && typeof(XMLHttpRequest) != 'undefined') {
	try {
	  var xmlhttplocal = new XMLHttpRequest();
    } catch (e) {
	  var xmlhttplocal=false;
	  alert('couldn\'t create xmlhttp object');
    }
  }
  return(xmlhttplocal);
}

function sendRequestCB(id,action) {
  if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
	str = 'clipboard_process.php?action='+action+'&cb_id='+id;
	xmlhttp.open("GET",str,true);
	xmlhttp.onreadystatechange = handleResponseCB; 
	xmlhttp.send(null);
  }
  return false;
}

function handleResponseCB() {
  if (xmlhttp.readyState == 4) {
	input = xmlhttp.responseText.split(',');
	id = input[0];
	action = input[1];
	btn = document.getElementById('cb'+id+'_btn');
    
	if (input[2] == 1)
	  result = true;
	else
	  result = false;

	switch (action) {
	  case 'add':
	    if (result) btn.innerHTML = "<a class=\"action\" href=\"javascript:void(0);\" onClick=\"sendRequestCB('" + id + "','remove')\">- Clip</a>";
	    break;
	  
	  case 'remove':
	    if (result) btn.innerHTML = "<a class=\"action\" href=\"javascript:void(0);\" onClick=\"sendRequestCB('" + id + "','add')\">+ Clip</a>";
	    break;
	}
    document.getElementById('cb_size').innerHTML = input[3];
  }
}

function sendRequestCP(form_name,fld_name,file_name,type) {
  if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
	var set_num;

    switch (type) {
      case "Drug Discrimination":
	    set_num = 1;
	    break;

	  case "Drug Self-Administration":
	    set_num = 2;
	    break;

	  default:
	    set_num = 0;
    }

	str = 'pulldown_process.php?form_name='+form_name+'&fld_name='+fld_name+'&file_name='+file_name+'&set_num='+set_num;
	
	xmlhttp.open("GET",str,true);
	xmlhttp.onreadystatechange = handleResponseCP; 
	xmlhttp.send(null);

	document.getElementById(fld_name+"_display").innerHTML = "--- Loading ... ---";
  }
  return false;
}

function handleResponseCP() {
  if (xmlhttp.readyState == 4) {
	input = xmlhttp.responseText.split('|');
	fld_name = input[0];
    pulldown = input[1];

	if (pulldown.length > 0)
	  document.getElementById(fld_name+"_display").innerHTML = pulldown;
  }
}
