//
// IASP 5.0 AJAX Layer
// October 2006-
//
// Copyright (C) IASP 2007.
// Unauthorised reproduction or use
// on external websites will 
// be subject to rigorous prosecution
//
var _state_id;
var _suburb_id;
var _postcode_id;
var _xh;

//
// Generic IFRAME background loader
//
var _iframe;
var _iframe_url;

CMS.Ajax = function() { };

function AJAX_bgloadIframe(iframe,url) {
	//
	// This function is temporarily disabled as it didn't help IE render things any better, and added a page state change to browser history
	//
	//_xh = GetXMLHTTP();
	//if (_xh) {
		//_iframe = iframe;
		//_iframe_url = url;
		
		//iframe.src = '/ui.aspx?f=if_blank';
		
		//
		// Initiate XMLHTTP callback
		//
		//_xh.onreadystatechange = AJAX_bgloadIframe_callback;
		//_xh.open("GET",url,true);
		//_xh.send(null);
	//} else {
		//
		// XMLHTTP doesn't work, just use .src
		//
		iframe.src = url;
	//}
}

function AJAX_bgloadIframe_callback() {
	if (_xh.readyState == 4) {
		if (_xh.status == 200) {
			//
			// Dump content into IFRAME
			//
			_iframe.contentWindow.document.open();
			_iframe.contentWindow.document.write(_xh.responseText);
			_iframe.contentWindow.document.close();
			
			//_iframe.contentWindow.document.innerHTML = _xh.responseText;
		} else {
			//
			// Status wasn't ok, do the old method and let the browser display the error
			//
			_iframe.src = _iframe_url;
		}
	}
}

var _vIF_obj;
//
// Load a URL into a DIV handling it as a virtual iframe
//
function AJAX_loadVirtualIFrameByID(id,url,completionCallback) {
	var obj = document.getElementById(id);
	
	return AJAX_loadVirtualIFrame(obj,url);
}

//
// Load a URL into a DIV handling it as a virtual iframe
//
function AJAX_loadVirtualIFrame(obj,url,completionCallback) {
	var xmlHttp = GetXMLHTTP();
	if (xmlHttp) {
		//
		// Load the URL
		//
		AJAX_loadStart();
		
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {
				if (xmlHttp.status == 200) {
					//
					// Dump content into object
					//
					obj.innerHTML = xmlHttp.responseText;
					if (completionCallback != null) completionCallback();
				} else {
					//
					// Status wasn't ok..
					//
					alert('AJAX callback failed:' + xmlHttp.responseText);
				}
				AJAX_loadEnd();
			}
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		
	} else {
		//
		// XMLHTTP doesn't work!
		//
		cms_NoAJAXAlert();
	}	
		
	return false; // block link following
}

// Standard 'AJAX Not working' alert
function cms_NoAJAXAlert() {
	window.alert('Sorry, this action requires functionality either not supported or disabled in your browser.\nPlease enable XMLHTTP (AJAX), or upgrade to a more recent or standards compliant browser such as Mozilla Firefox or Safari.');
}
CMS.noAjaxAlert = cms_NoAJAXAlert;

// Number of currently open AJAX threads
var _AJAX_threadCount = 0;

// make loading div visible
function AJAX_loadStart() {
	if (_AJAX_threadCount == 0) {
		var obj = document.getElementById('cms_ajax_loading');

		if (obj) {
			obj.style.visibility = 'visible';
		}
	}
	_AJAX_threadCount++;
}
CMS.Ajax.startLoad = AJAX_loadStart;

// hide loading div
function AJAX_loadEnd() {
	_AJAX_threadCount--;
	if (_AJAX_threadCount == 0) {
		var obj = document.getElementById('cms_ajax_loading');

		if (obj) {
			obj.style.visibility = 'hidden';
		}
	}
}
CMS.Ajax.endLoad = AJAX_loadEnd;

// repopulate a SELECT using a supplied array
function AJAX_RepopulateDropdown(id,values)
{
	var sel = $(id);
	
	sel._oldval = sel.value;
	
	for (x=sel.length; x >= 0; x--) {
		sel[x] = null;
	}

	//sel[0] = null;
	sel[0] = new Option("-","");

	for (i=0; i < values.length; i++) {
		sel[i + 1] = new Option(values[i],values[i]);
	}
	
	sel.value = sel._oldval;
}

// repopulate a SELECT using a supplied array
function AJAX_RepopulateDropdownWithValues(id,values,labels)
{
	var sel = $(id);
	
	sel._oldval = sel.value;
	
	for (x=sel.length; x >= 0; x--) {
		sel[x] = null;
	}

	//sel[0] = null;
	sel[0] = new Option("-","");

	for (i=0; i < values.length; i++) {
		sel[i + 1] = new Option(labels[i],values[i]);
	}
	
	sel.value = sel._oldval;
}

// Generic function to execute whatever code is returned
function AJAX_EvaluateResponse_callback()
{
	if (_xh.readyState == 4) {
		if (_xh.status == 200) {
			//alert(_xh.responseText);
			eval(_xh.responseText);
		} else {
			alert('AJAX callback failed.');
		}
		AJAX_loadEnd();
	}
}


//
// Post content via a URL and put the result into a DIV handling it as a virtual iframe
//
function AJAX_postVirtualIFrameByID(formobj,id,url,completionCallback) {
	var obj = document.getElementById(id);
	
	return AJAX_postVirtualIFrame(formobj,obj,url,completionCallback);
}


//
// POST data via a URL into a DIV handling it as a virtual iframe
//
function AJAX_postVirtualIFrame(formobj,obj,url,completionCallback) {
	var actualForm = cms_findParentForm(formobj);
	if (actualForm == null) return;
	
	var formData = AJAX_getPostRequestBody(actualForm);
	
	var xmlHttp = GetXMLHTTP();
	if (xmlHttp) {
		//
		// Load the URL
		//
		AJAX_loadStart();
		
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {
				if (xmlHttp.status == 200) {
					//
					// Dump content into object
					//
					obj.innerHTML = xmlHttp.responseText;
					if (completionCallback != null) completionCallback();
				} else {
					//
					// Status wasn't ok..
					//
					//alert('AJAX callback failed.');
				}
				AJAX_loadEnd();
			}
		}
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send(formData);
		
	} else {
		//
		// XMLHTTP doesn't work!
		//
		window.alert('This page requires functionality not supported by your browser. Please upgrade to a more recent or standards compliant browser such as Mozilla Firefox.');
	}	
		
	return false; // block link following
}

//
// Find the parent form of an object
//
function cms_findParentForm(obj)
{
	var stx = obj.tagName;	
	var obp = obj.parentNode || obj.parent;
	
	while (obp) {
		if (obp.tagName == 'FORM') {
			return obp;
		}
		obp = obp.parentNode || obp.parent;
	}
	return null;
}
CMS.findParentForm = cms_findParentForm;

//
// Get POST request body string
//
function AJAX_getPostRequestBody(formobj)
{
	var aParams = new Array();
	
	for (var i=0; i < formobj.elements.length; i++) {
		if (formobj.elements[i]._cms_ignore != '1' && formobj.elements[i].type != 'submit' && (formobj.elements[i].type != 'checkbox' || formobj.elements[i].checked == true)) {
			var sParam = encodeURIComponent(formobj.elements[i].name) + "=" + encodeURIComponent(formobj.elements[i].value);
			aParams.push(sParam);
		}
	}
	
	return aParams.join('&');
}
// Get POST request body string from object other than form (run full traversal)
CMS.Ajax.getPostRequestBodyArray = function(obj)
{
	var aParams = new Array();
	
	for (var i=0; i < obj.childNodes.length; i++) {
		var thisObj = obj.childNodes[i];
		
		if (thisObj.tagName == 'SELECT' ||
		thisObj.tagName == 'TEXTAREA' ||
		(thisObj.tagName == 'INPUT' &&
		(thisObj.type != 'checkbox' || thisObj.checked == true) &&
		(thisObj.type != 'radio' || thisObj.checked == true) &&
		thisObj.type != 'submit' &&
		thisObj.name != null && thisObj.name != '')) {
			var sParam = encodeURIComponent(thisObj.name) + "=" + encodeURIComponent(thisObj.value);
			aParams.push(sParam);
		} else {
			if (thisObj.childNodes.length > 0) {
				aParams = aParams.concat(CMS.Ajax.getPostRequestBodyArray(thisObj));
			}
		}
	}
	
	return aParams;
}

//
// Set the onchange function for all dropdowns inside a parent div
//
function AJAX_traverseChildrenSetDropdownOnChange(objParent, fncOnchange, strDontChange)
{
	for (var i=0; i < objParent.childNodes.length; i++) {
		var thisObj = objParent.childNodes[i];
		
		if (thisObj.tagName == 'SELECT' && thisObj.id != strDontChange) {
			thisObj.onchange = fncOnchange;
		} else {
			if (thisObj.childNodes.length > 0) AJAX_traverseChildrenSetDropdownOnChange(thisObj,fncOnchange,strDontChange);
		}
	}
}

//
// Repost auto searchable field data for AJAX repopulation
//
function RepostSearchData(id_prefix, search_data, s_id, called_by)
{
	_xh = GetXMLHTTP();
	if (_xh)
	{
		AJAX_loadStart();
		
		var requestUrl = "/default.aspx?f=_callback&func=SearchData&sid=" + s_id + "&idpfx=" + id_prefix + "&cby=" + called_by + "&data=" + escape(search_data);
		
		//
		// Initiate XMLHTTP callback
		//
		_xh.onreadystatechange = AJAX_EvaluateResponse_callback;
		_xh.open("GET",requestUrl,true);
		_xh.send(null);
	}
}

//
// Take state and post it
//
function RepostStateForSuburbs(state_id, suburb_id)
{
	var stateList = document.getElementById(state_id);
	var selectedState;
	try { selectedState = stateList.options[stateList.selectedIndex].value; }
	catch(e) { 
		stateList = document.getElementById("sbj_" + state_id);
		selectedState = stateList.options[stateList.selectedIndex].value;
		var altStateTB = document.getElementById("sbj_" + state_id + "_alt");
		try { altStateTB.value = selectedState; }
		catch(e) { }
	}
	_state_id = state_id;
	_suburb_id = suburb_id;
	var requestUrl = "/default.aspx?f=_callback&func=StateForSuburbs&state=" + selectedState;
	
	
	_xh = GetXMLHTTP();
	if (_xh)
	{
		AJAX_loadStart();
		//
		// clear the list
		//
		var sel = $("sbj_" + suburb_id);
		
		//for (x=sel.length; x >= 0; x--) {
		//	sel[x] = null;
		//}
		
		sel.options[0] = new Option("Please wait...","");
		sel.selectedIndex = 0;
		
		//
		// Initiate XMLHTTP callback
		//
		_xh.onreadystatechange = RepostStateForSuburbs_callback;
		_xh.open("GET",requestUrl,true);
		_xh.send(null);
		
		//
		// Set dropdown visible, text box hidden.
		//
		$("sbj_" + _suburb_id + "_alt").style.display='none';
		$("sbj_" + _suburb_id + "_alt").name= _suburb_id + "_alt";
		$("sbj_" + _suburb_id).style.display='inline';
		$("sbj_" + _suburb_id).name=_suburb_id;
	}
}

//
// Handle suburb postback
//
function RepostStateForSuburbs_callback()
{
	if (_xh.readyState == 4) {
		if (_xh.status == 200) {
			eval("var suburbs=" + _xh.responseText);
			
			//
			// populate the list
			//
			var sel = $("sbj_" + _suburb_id);
			
			//sel[0] = null;
			sel.options[0] = new Option("-","");
			
			var sl = suburbs.length;
			for (i=0; i < sl; i++) {
				if (sel[i + 1] == null) {
					sel.options[i + 1] = new Option(suburbs[i],suburbs[i]);
				} else {
					sel.options[i + 1].text = suburbs[i];
					sel.options[i + 1].value = suburbs[i];
				}
			}
			for (x=sel.length; x > suburbs.length; x--) {
				sel.options[x] = null;
			}
			
			
			if (suburbs.length == 0)
			{
				//
				// Set textbox visible, dropdown hidden.
				//
				$("sbj_" + _suburb_id).style.display='none';
				$("sbj_" + _suburb_id).name=_suburb_id + "_alt";
				$("sbj_" + _suburb_id + "_alt").style.display='inline';
				$("sbj_" + _suburb_id + "_alt").name=_suburb_id;
			}
			else
			{
				//
				// Set dropdown visible, text box hidden.
				//
				$("sbj_" + _suburb_id + "_alt").style.display='none';
				$("sbj_" + _suburb_id + "_alt").name=_suburb_id + "_alt";
				$("sbj_" + _suburb_id).style.display='inline';
				$("sbj_" + _suburb_id).name=_suburb_id;
			}			
		} else {
			alert('AJAX callback failed for RepostStateForSuburbs.');
		}
		AJAX_loadEnd();
	}
}

//
// Take suburb and post it
//
function RepostSuburbStateForPostcode(state_id, suburb_id, postcode_id)
{
	var stateList = document.getElementById(state_id);
	var selectedState;
	try { selectedState = stateList.options[stateList.selectedIndex].value; }
	catch(e) { 
		stateList = document.getElementById("sbj_" + state_id);
		selectedState = stateList.options[stateList.selectedIndex].value;
	}
	var suburbList = document.getElementById("sbj_" + suburb_id);
	_state_id = state_id;
	_suburb_id = suburb_id;
	_postcode_id = postcode_id;
	var selectedSuburb = suburbList.options[suburbList.selectedIndex].value;
	var requestUrl = '/default.aspx?f=_callback&func=PostcodeForSuburbState&state=' + selectedState + '&suburb=' + selectedSuburb;
	
	var altSuburbTB = document.getElementById("sbj_" + suburb_id + "_alt");
	try { altSuburbTB.value = selectedSuburb; }
	catch(e) { }
		
	_xh = GetXMLHTTP();
	if (_xh)
	{
		AJAX_loadStart();
		_xh.onreadystatechange = RepostSuburbStateForPostcode_callback;
		_xh.open("GET",requestUrl,true);
		_xh.send(null);
	}
}

//
// Handle suburb postback
//
function RepostSuburbStateForPostcode_callback()
{
	if (_xh.readyState == 4) {
		if (_xh.status == 200) {
			eval("var postcode='" + _xh.responseText + "'");
			
			document.getElementById(_postcode_id).value = postcode;			
		} else {
			alert('AJAX callback failed for RepostSuburbStateForPostcode.');
		}
		AJAX_loadEnd();
	}
}

//
// Handle country postback to disable suburb AJAX altogether if required
//
function RepostCountryForStates(country_id, state_id, suburb_id)
{
	var c_obj = document.getElementById(country_id);
	
	// check that state objects are set up properly
	if (document.getElementById('sbj_' + state_id) == null) {
		//
		// rename the state dropdown box
		//
		document.getElementById(state_id).id = 'sbj_' + state_id;
		
		//
		// create the state text box
		//
		var newElement = document.createElement('input');
		newElement.setAttribute('type','text');
		newElement.setAttribute('class','text');
		newElement.setAttribute('size','20');
		newElement.setAttribute('name', state_id + '_alt');
		newElement.setAttribute('id','sbj_' + state_id + '_alt');
		var oParent = $('sbj_' + state_id).parentNode || $('sbj_' + state_id).parent;
		oParent.appendChild(newElement);
	}
		
	if (c_obj.value == 1)
	{
		//
		// Australia; enable states.
		//
		document.getElementById("sbj_" + state_id).style.display='inline';
		document.getElementById("sbj_" + state_id).name=state_id;
		document.getElementById("sbj_" + state_id + "_alt").style.display='none';
		document.getElementById("sbj_" + state_id + "_alt").name=state_id + "_alt";
		
		//
		// Execute the onchange event.
		//
		if (document.getElementById("sbj_" + state_id).onchange)
			document.getElementById("sbj_" + state_id).onchange();
	} else {
		//
		// Not Australia: disable suburbs.
		//
		document.getElementById("sbj_" + suburb_id).style.display='none';
		document.getElementById("sbj_" + suburb_id).name=suburb_id + "_alt";
		document.getElementById("sbj_" + suburb_id + "_alt").style.display='inline';
		document.getElementById("sbj_" + suburb_id + "_alt").name=suburb_id;
		
		//
		// Not Australia: disable states.
		//
		document.getElementById("sbj_" + state_id).style.display='none';
		document.getElementById("sbj_" + state_id).name=state_id + "_alt";
		document.getElementById("sbj_" + state_id + "_alt").style.display='inline';
		document.getElementById("sbj_" + state_id + "_alt").name=state_id;
	}
}

//
// Show Matching Rows Hides table rows (except those of class 'selected') that don't contain the supplied value.
//

var _showMRscheduled = false;
var _showMRkeypressed = 0;
var _showMRtimeout = 200;
var _showMRtable_obj;
var _showMRinput_obj;
var _showMRcol_idx;

function showMatchingRows(table_obj, input_obj, col_idx) {
	// increment keypress count and decrement again in 400ms
	_showMRkeypressed++;
	setTimeout("_showMRkeypressed--;",_showMRtimeout);
	
	// schedule callback if not done already
	if (_showMRscheduled == false) {
		AJAX_loadStart();
		setTimeout("showMatchingRows_callback();",_showMRtimeout);
		_showMRtable_obj = table_obj;
		_showMRinput_obj = input_obj;
		_showMRcol_idx = col_idx;
		_showMRscheduled = true;
	}
}

// Matching rows callback; actual search. Debounced using the above so search doesn't run while people are typing.
function showMatchingRows_callback(table_obj, input_obj, col_idx) {
	if (_showMRkeypressed != 0) {
		setTimeout("showMatchingRows_callback();",_showMRtimeout);
	} else {
		if (table_obj == null && input_obj == null && col_idx == null) {
			table_obj = _showMRtable_obj;
			input_obj = _showMRinput_obj;
			col_idx = _showMRcol_idx;
		}
		_showMRscheduled = false;
		for (var i=0; i < table_obj.childNodes.length; i++) {
			var this_row = table_obj.childNodes[i];
			
			var value = input_obj.value;

			if (value == null) value = '';

			if (this_row.tagName == 'TR') {
				// we need to set it visible to make the reading of innerHTML behave
				if (document.selection) {
					// IE
					this_row.style.display = 'block';
				} else {
					// DOM
					this_row.style.display = 'table-row';	// default; make it visible
				}
				
				if (this_row.className == 'selected' || this_row.className == 'listhdr' || value == '') {
					// formerly set-visible code
				} else {
					var foundMatch = false;

					//for (var j=0; j < this_row.childNodes.length; j++) {
						var this_cell = this_row.childNodes[col_idx];

						//var re = /<[^>]+>/;

						//var innerText = this_cell.innerHTML.replace(re,'');
						var innerText = this_cell.innerHTML;

						//if (innerText != '' && innerText != null) {
							if (innerText.toLowerCase().indexOf(value.toLowerCase()) >= 0)
								foundMatch = true;
						//}
					//}

					if (foundMatch == false) {
						this_row.style.display = 'none';
					}
				}
				AJAX_loadEnd();
			} else if (this_row.tagName == 'TBODY') {
				showMatchingRows_callback(this_row, input_obj, col_idx);
			}
		}
	}
}

//
// Voting system
//
// KM 1/4/07
//
var _cms_vote_curVoteBlock;
function cms_vote_makeDataVote(data_id,vote,src_data_id,blockId) {
	// Sanity checking for this function is done server-side. Just pass whatever has been put here.
	//alert(user_id + ' voting ' + vote + ' on ' + data_id + ' from ' + src_data_id);

	// Create Request URL
	var requestUrl = '/default.aspx?f=_callback&func=MakeDataVote&d=' + data_id + '&v=' + vote + '&s=' + src_data_id + '&uniq=' + Math.random();
	
	var xmlHttp = GetXMLHTTP();
	if (xmlHttp) {
		AJAX_loadStart();
		_cms_vote_curVoteBlock = blockId;
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {
				AJAX_loadEnd();
				if (xmlHttp.status == 200) {
					var strResponse = '';
					
					if (xmlHttp.responseText == 'Succeeded')
						strResponse = 'Your vote has been recorded. Thankyou.';
					else if (xmlHttp.responseText == 'AlreadyVoted')
						strResponse = 'You have voted on this item previously, but your vote has been updated. Thankyou.';
					else if (xmlHttp.responseText == 'AccessDenied')
						alert('Sorry, you must be a registered user of this site to vote. Please log in or register and try again.');
					else
						alert('Sorry, your vote failed to save. Please try again later.');
					
					if (strResponse != '')
						document.getElementById(blockId).innerHTML = strResponse;
				} else {
					alert('Sorry, there was a problem while attempting to transfer your vote to the server.\n\nOur team has been notified of this issue. Please try again later.');
				}
			}
		}
		xmlHttp.open('GET',requestUrl,true);
		xmlHttp.send(null);
	} else {
		cms_NoAJAXAlert();
	}	
	return false;
}

//
// Full-Text-Search Ajax re-matching
//
// KM 5/3/08
//
CMS.Fts = function() { };

// Submit data via AJAX for search dropdown repopulation
CMS.Fts.submitForRepopulate = function(lFieldList, lValueList, sPostData, iFieldIdx, lFieldIdList, iTemplateId) {
	if (iFieldIdx >= 0) {
		sPostData += '&idx=' + iFieldIdx;
		for (var i=0; i <= iFieldIdx; i++) { sPostData += '&' + encodeURIComponent(lFieldList[i]) + '=' + encodeURIComponent(lValueList[i]); }
		
		var xh = GetXMLHTTP();
		if (xh) {
			AJAX_loadStart();
			iTemplateId = parseInt(iTemplateId);
			var url;
			if (iTemplateId > 0) {
				url = CMS.appRoot + 'ui.ashx?f=fts_repopulate_tmpldata&d=' + iTemplateId;
			} else {
				url = CMS.appRoot + 'ui.ashx?f=fts_repopulate_getdata';
			}		
			xh.onreadystatechange = function() {
				if (xh.readyState == 4) {
					AJAX_loadEnd();
					if (xh.status == 200) {
						//alert(xh.responseText);
						eval(xh.responseText);
						
						for (var i=iFieldIdx + 1; i < lFieldIdList.length; i++) {
							if (lData['t' + i] != undefined) {
								//alert('hasText: ' + i);
								try { AJAX_RepopulateDropdownWithValues(lFieldIdList[i], lData['v' + i], lData['t' + i]); }
								catch(e) { }
							} else {
								//alert('setting: ' + lFieldIdList[i] + ' with ' + lData['v' + i]);
								if (lData['v' + i] != undefined) {
									try { AJAX_RepopulateDropdown(lFieldIdList[i], lData['v' + i]); }
									catch(e) { }
								}
							}
						}
					} else {
						// TODO: Replace with popup warning UI
						alert('A problem was encountered while attempting to narrow your search query down. Our team has been notified and will investigate.');
					}
				}
			}
			xh.open('POST',url,true);
			xh.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xh.send(sPostData);
		}
	}
}

//
// Checks the entered BN link 
//
function RepostBNtoFrom(from_id, to_id)
{
	var from = document.getElementById(from_id).value;
	var to = document.getElementById(to_id).value;
	var requestUrl = '/default.aspx?f=_callback&func=CheckBNtoFrom&from=' + from + '&to=' + to;

	_xh = GetXMLHTTP();
	if (_xh)
	{
		AJAX_loadStart();
		
		//
		// Initiate XMLHTTP callback
		//
		_xh.onreadystatechange = function() {
		    if (_xh.readyState == 4) {
		        AJAX_loadEnd();
		        if (_xh.status == 200) {
		            eval(_xh.responseText);
		        } else {
		            alert('An error occured while attempting to check the entry');
		        }
		    }
		}
		_xh.open("GET",requestUrl,true);
		_xh.send(null);
	}
}

function createrelation(id1s, id2s)
{
	var id1 = document.getElementById(id1s).value;
	//var id2 = document.getElementById(id2s).value;
	var requestUrl = "/default.aspx?f=_callback&func=makeArbitraryRelation&ida=" + id1 + "&idb=" + id2s;

	_xh = GetXMLHTTP();
	if (_xh)
	{
		AJAX_loadStart();
		
		//
		// Initiate XMLHTTP callback
		//
		_xh.onreadystatechange = function() {
		    if (_xh.readyState == 4) {
		        AJAX_loadEnd();
		        if (_xh.status == 200) {
		            eval(_xh.responseText);
		        } else {
		            alert('problem occurred calling the function');
		        }
		    }
		}
		_xh.open("GET",requestUrl,true);
		_xh.send(null);
	}
}
function Removerelation(id1s, id2s)
{
	var id1 = document.getElementById(id1s).value;
	//var id2 = document.getElementById(id2s).value;
	var requestUrl = "/default.aspx?f=_callback&func=removeArbitraryRelation&ida=" + id1 + "&idb=" + id2s;

	_xh = GetXMLHTTP();
	if (_xh)
	{
		AJAX_loadStart();
		
		//
		// Initiate XMLHTTP callback
		//
		_xh.onreadystatechange = function() {
		    if (_xh.readyState == 4) {
		        AJAX_loadEnd();
		        if (_xh.status == 200) {
		            eval(_xh.responseText);
		        } else {
		            alert('problem occurred calling the function');
		        }
		    }
		}
		_xh.open("GET",requestUrl,true);
		_xh.send(null);
	}
}

    function setTitleList(firstEnteredLetter, id)
{   
	var requestUrl = "/default.aspx?f=_callback&func=getTrackTitle&id=" + id + "&FirstEnteredLetter=" + firstEnteredLetter;
	//var requestUrl = "http://beatbox.local/default.aspx?f=_callback&func=getTrackTitle&id=" + id + "&FirstEnteredLetter=" + firstEnteredLetter;

	_xh = GetXMLHTTP();
	if (_xh)
	{
		AJAX_loadStart();
		
		//
		// Initiate XMLHTTP callback
		//
		
		_xh.onreadystatechange = function() { 
		    if (_xh.readyState == 4) {
		        AJAX_loadEnd();
		        if (_xh.status == 200) {
		            var rt = new Array();
		            rt = _xh.responseText.split(";");
                    if (__AutoComplete[id]['isVisible']) {
                        AutoComplete_HideDropdown(id);}		            
		            AutoComplete_Create(id, rt, 6);
		            AutoComplete_ShowDropdown(id);
		        } else {
		            return('');
		        }
		    }
		}
		_xh.open("GET",requestUrl,true);
		_xh.send(null);
	}
}