// Core Ajax functions taken from AJAX Design Patterns


function createXMLHttpRequest() {
  try { return new ActiveXObject("Msxml2.XMLHTTP");    } catch(e) {}
  try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
  try { return new XMLHttpRequest();                   } catch(e) {}
  alert("XMLHttpRequest not supported");
  return null;
}


// custom functions specific to this page

function $(id) {return document.getElementById(id);}

function obdisplay() {// actual CSS values passed to make it flexible enough to support inline OR block
	var displaytype = obdisplay.arguments[0];
	var oblen = obdisplay.arguments.length;
	for (i=1; i<oblen; i++)  {$(obdisplay.arguments[i]).style.display = displaytype;}
}

function showresearch(subid) {
	var alldivs = document.getElementsByTagName('DIV');
	for (i in alldivs) {if (alldivs[i].className == 'tabtext') {alldivs[i].style.display = 'none';}}
	obdisplay('block',subid); // last one only needed first time, actually
}

function bluethis(linkobj) {
	liobj = linkobj.parentNode;
	ulobj = liobj.parentNode;
	for (i in ulobj.childNodes) {
		testobj = ulobj.childNodes[i];
		if (testobj.nodeName == 'LI') {
			ulobj.childNodes[i].style.backgroundColor = '#557565'; // faster than iterating
		}
	}
	liobj.style.backgroundColor = '#003366';
}

// AJAX routines

var restype = new Array("moresources","searchbox","recres","FTdatabase","ReferenceReso","internet_site","media_site","e_book","alphalist");


var url = "/cline-cgi-bin/researchdyn2.pl?"; // The server-side script
//<img src="../images/throb_blu036.gif" id="searchbox_throb" />
function harvestcontent(discipline) {
	var xwant = createXMLHttpRequest();
	myurl = url + escape(discipline);
	/*for (i in restype) {
		var tname = restype[i];
		if ($(tname)) {$(tname).innerHTML = '<img src="images/throb_blu036.gif" id="searchbox_throb" />';}
	}*/
	xwant.onreadystatechange = function() {
		if (xwant.readyState==4 && xwant.status==200) {
				var xmlString = xwant.responseText;
				for (i in restype) {
					var tname = restype[i];
					var tagnamelen = tname.length;
					var tagst = xmlString.indexOf("<" + tname + ">");
					var tagen = xmlString.indexOf("</" + tname + ">");
					if (tagst > 0) {
						var tagfill = xmlString.substr((tagst+tagnamelen+2),(tagen - tagst)-(tagnamelen+3));
						var wrappingDiv = document.createElement('div');
						wrappingDiv.setAttribute('id',tname);
						wrappingDiv.style.cssText = $(tname).style.cssText;
						wrappingDiv.className = $(tname).className;
						wrappingDiv.innerHTML = tagfill;
						$(tname).parentNode.replaceChild(wrappingDiv,$(tname));
					}
				}
		}
	}
	xwant.open("GET",myurl,true);
	xwant.send(null);
	hiliteDiscipline($('Databases'),discipline);
}



function onServerResponse(html, headers, elementID) {
	$(elementID).innerHTML = html;
}

function hiliteDiscipline(indexid,discipline) {
	for (var i=0; i < indexid.length; i++) {
		if (indexid[i].value == discipline) {
			indexid[i].selected = true;
		}
	}
}

/**/


function parse_uri_args()
{
   if ( document.location.href.indexOf('?') == -1 )
   {
       return false;
   }
   else
   {
        if (document.location.href.indexOf('&') != -1)
        {
             var arguments_list = document.location.href.split('?')[1].split('&');
             var arguments = new Array();
             for ( i = 0 ; i < arguments_list.length ; i++ )
             {
                  key = arguments_list[i].split('=')[0];
                  value = arguments_list[i].split('=')[1];
                  arguments[key] = value;
             }
             return arguments;
        }
        else
        {
             arguments = new Array();
             var arguments_list = document.location.href.split('?')[1];
             key = arguments_list.split('=')[0];
             value = arguments_list.split('=')[1];
             arguments[key] = value;
             return arguments;
        }
   }
}

var uri_array = parse_uri_args();
var defaultsub = unescape(uri_array['subject']) ;
defaultsub = defaultsub.replace(/_/g,' ');
if (defaultsub == "undefined") {defaultsub = 'General Research';}
