var xmlHttp;






function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


function loadTree(type,search_term) {

    if(!search_term && document.getElementById(type + '_ajax_tree').innerHTML != ""){
	return;
    }

    function ajaxBindCallback() {
        // progressive transitions are from 0 .. 4
        if (ajaxRequest.readyState == 4) {
            // 200 is the successful response code
            if (ajaxRequest.status == 200) {
                ajaxCallback ( ajaxRequest.responseText, type );
            } else {
                // error handling here
                alert("There was a problem retrieving this ontology: " + ajaxRequest.status  );
		alert(ajaxRequest.responseText);
            }
        }else{
		document.getElementById(type + '_ajax_tree').innerHTML = "Loading ... <img src = '/gemina/images/loading.gif'>";
	      
	}	
    }

    var ajaxRequest = null;
    var ajaxCallback = set_tree_handler;
 
    //set the URL    
    var url="MakeFrontPages.cgi";

    var form_string = "page=mrs_ajax_get_tree&tree_type="+type+"&sid="+Math.random()+"&tree_search="+search_term;

    // bind the call back, then do the request
    if (window.XMLHttpRequest) {
        // mozilla, firefox, etc will get here
        ajaxRequest = new XMLHttpRequest();
        ajaxRequest.onreadystatechange = ajaxBindCallback;
        ajaxRequest.open("POST", url , true);
        ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        ajaxRequest.setRequestHeader("Connection", "close");
        ajaxRequest.send( form_string );
        
    } else if (window.ActiveXObject) {
        // IE, of course, has its own way
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");

        if (ajaxRequest) {
            ajaxRequest.onreadystatechange = ajaxBindCallback;
            ajaxRequest.open("POST", url , true);
            ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            ajaxRequest.setRequestHeader("Connection", "close");
            ajaxRequest.send( form_string );
        }
    }
}

function set_tree_handler (responseText, type){
	var arry = responseText.split("</script>");
	document.getElementById(type + '_ajax_tree').innerHTML=arry[1];
	
	eval(arry[0]);
	// display the search box
	document.getElementById(type + '_tree_search_bar').style.display = "";

}


function loadChildren(type, id, cell_id) {
    if(document.getElementById(cell_id).innerHTML.match("li")){ // has stuff
		hideShow(cell_id, id);
		return;
    }

	max_tree_id = max_tree_id + 1;

	document.getElementById('box_' + cell_id).className = 'has_children_loading';

    function ajaxBindCallback() {
        // progressive transitions are from 0 .. 4
        if (ajaxRequest.readyState == 4) {
            // 200 is the successful response code
            if (ajaxRequest.status == 200) {
                ajaxCallback ( ajaxRequest.responseText, id, cell_id );
            } else {
                // error handling here
                alert("There was a problem retrieving this ontology: " + ajaxRequest.status  );
		alert(ajaxRequest.responseText);
            }
        }else{
	      
	}	
    }
    var ajaxRequest = null;
    var ajaxCallback = set_tree_children_handler;
 
    //set the URL    
    var url="MakeFrontPages.cgi";

    var form_string = "page=mrs_ajax_get_tree&tree_type="+type+"&sid="+Math.random()+"&root="+id+"&tree_id="+max_tree_id;


    // bind the call back, then do the request
    if (window.XMLHttpRequest) {
        // mozilla, firefox, etc will get here
        ajaxRequest = new XMLHttpRequest();
        ajaxRequest.onreadystatechange = ajaxBindCallback;
        ajaxRequest.open("POST", url , true);
        ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        ajaxRequest.setRequestHeader("Connection", "close");
        ajaxRequest.send( form_string );
        
    } else if (window.ActiveXObject) {
        // IE, of course, has its own way
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");

        if (ajaxRequest) {
            ajaxRequest.onreadystatechange = ajaxBindCallback;
            ajaxRequest.open("POST", url , true);
            ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            ajaxRequest.setRequestHeader("Connection", "close");
            ajaxRequest.send( form_string );
        }
    }
}

function set_tree_children_handler (responseText, id, ident){

	document.getElementById(ident).innerHTML=responseText;
	hideShow(ident, id);

}




function loadTermDescription(term_id) {


    function ajaxBindCallback() {
        // progressive transitions are from 0 .. 4
        if (ajaxRequest.readyState == 4) {
            // 200 is the successful response code
            if (ajaxRequest.status == 200) {
                ajaxCallback ( ajaxRequest.responseText );
            } else {
                // error handling here
                alert("There was a problem retrieving this term information: " + ajaxRequest.status  );
		alert(ajaxRequest.responseText);
            }
        }else{
		document.getElementById('cvterm_description').innerHTML = "Loading ... <img src = '/gemina/images/loading.gif'>";
	      
	}	
    }

    var ajaxRequest = null;
    var ajaxCallback = set_term_description_handler;
 
    //set the URL    
    var url="get_cvterm_info.cgi";

    var form_string = "dbxref_acc="+term_id;

    // bind the call back, then do the request
    if (window.XMLHttpRequest) {
        // mozilla, firefox, etc will get here
        ajaxRequest = new XMLHttpRequest();
        ajaxRequest.onreadystatechange = ajaxBindCallback;
        ajaxRequest.open("POST", url , true);
        ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        ajaxRequest.setRequestHeader("Connection", "close");
        ajaxRequest.send( form_string );
        
    } else if (window.ActiveXObject) {
        // IE, of course, has its own way
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");

        if (ajaxRequest) {
            ajaxRequest.onreadystatechange = ajaxBindCallback;
            ajaxRequest.open("POST", url , true);
            ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            ajaxRequest.setRequestHeader("Connection", "close");
            ajaxRequest.send( form_string );
        }
    }
}

function set_term_description_handler (responseText, type){
	document.getElementById('cvterm_description').innerHTML=responseText;
	document.getElementById('cvterm_description').style.display = "";
}

