
function backlinkxml (search,properties,max)
{
	var linkResolverURL = "/linkresolver/resolve";
	var query = linkResolverURL + "?search=" + escape(search) + "&properties=" + properties + "&maxresults=" + max;
	
	var xmlhttp=getxmlhttpobject();

	if (!xmlhttp) {
		return new Array (-1, "AJAX is not supported in your browser!");
	}
	xmlhttp.open('GET', query, false);
	xmlhttp.send(null);
	
	return new Array(xmlhttp.status, xmlhttp.responseXML);
}

function backlinkArray( search,title,max )
{
	var linkResolverURL = "/linkresolver/resolve";
	var query = linkResolverURL + "?search=" + escape(search) + "&title=" + title + "&maxresults=" + max;
	
	var xmlhttp=getxmlhttpobject();

	if (!xmlhttp) {
		return (false);
	}
	xmlhttp.open('GET', query, false);
	xmlhttp.send(null);
	if (xmlhttp.status != 200) {
		return new Array();
	}

	var newline = new RegExp("\r\n");
	var delim = new RegExp(":-:");
	var lines = xmlhttp.responseText.split(newline,max);
	var retVal = new Array();
	for (var i = 0; i < lines.length; i++) {
		var values = lines[i].split(delim,2);
		retVal[i] = values;
	}
	return retVal;
}

function resolvelink( uid )
{
	var linkResolverURL = "/linkresolver/resolve";
	var query = linkResolverURL + "?uid=" + uid;
	
	var xmlhttp=getxmlhttpobject();

	if (!xmlhttp) {
		return new Array (-1, "AJAX is not supported in your browser!");
	}
	xmlhttp.open('GET', query, false);
	xmlhttp.send(null);
	
	return new Array(xmlhttp.status, xmlhttp.responseText);
}

function getxmlhttpobject ()
{
	var xmlhttp=false;
	/*cc_on @*/
	///*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 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) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	return xmlhttp;
}

function _myonchange( sel ) {
	if (sel.selectedIndex != 0) {
		window.open(sel.options[sel.selectedIndex].value);
		sel.size = 1;
	}
}

function backlinkselect( id,search,title,max )
{
	var mySelect = document.getElementById(id);
	var arr = backlinkArray(search,title,max);
	for (var i = 0; i<arr.length; i++) {
		var option = document.createElement("option");
		var optionvalue = document.createAttribute("value");
		optionvalue.nodeValue = arr[i][0];
		var optiontext = document.createTextNode(arr[i][1]);
		option.setAttributeNode(optionvalue);
		option.appendChild(optiontext);
		mySelect.appendChild(option);
	}
	mySelect.removeAttribute('onFocus',0);
        mySelect.onfocus = null;
	mySelect.size=mySelect.options.length;
}

function notify_status ( call ) {
	switch (call[0]) {
		case 404:
		alert ("Page not found");
		break;
		case 500:
		alert ("Server error");
		break;
		case -1:
		alert ("Client error: " + call[1]);
		break;
		default:
		alert ("The link resolver returned an unhandled status:" + call[0]);
		break;
	}
}

function deeplink( app, uid )
{
	var apps = new Array ( 'ats','chti','cl','ecjd','eth','gi','giii','giv','gta','gth','gv','hold','igtt','la','ma','nats','natstt','sitl','supps','treaty','ttdl','vl','lawlink','wtl');
	var url = '/' + app + '/index.htm?where=';
	for ( var i = 0; i < apps.length; i++ )
	{
		if ( app == apps[i] ) 
		{
			url = '/' + app + '/index.jsp?where=';
			break;
		}
	}
	var call = resolvelink ( uid );
	if (call[0] == 200) {
		window.open ( url + call[1] + '#' + uid);
	} else {
		notify_status(call);
	}
}

function popuplink ( uid )
{
	var call = resolvelink ( uid );
	if (call[0] == 200) {
		window.open ( call[1] + '#' + uid );
	} else {
		notify_status(call);
	}
}

function openlink ( uid )
{
	var call = resolvelink ( uid );
	if (call[0] == 200) {
		location.href = call[1] + '#' + uid;
	} else {
		notify_status(call);
	}
}

