//the baseurl for the xmlhttp application
//appurl = '/surf2music/ajaxhub.asp';
appurl = '/ajaxhub.asp';

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

//creates a new xmlhttp instance
function newParser() {
	var nxmlhttp,alerted,output;
	/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
			try {
			nxmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					nxmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
				} catch (E) {
					alert("You must have Microsofts XML parsers available");
				}
			}
		@else
			alert("You must have JScript version 5 or above.");
		nxmlhttp = false;
		alerted = true;
	@end @*/
	
	if (!nxmlhttp && !alerted) {
		//try {
		//	nxmlhttp = new XMLHttpRequest();
		//} catch (e) {
			//alert("Update your browser! http://www.mozilla.org");
		//}
		if (window.XMLHttpRequest) {
		// If IE7, Mozilla, Safari, and so on: Use native object
			nxmlhttp = new XMLHttpRequest();
		}
		else
		{
			if (window.ActiveXObject) {
				// ...otherwise, use the ActiveX control for IE5.x and IE6
				nxmlhttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');
			}
		}
	}
	return nxmlhttp;
}
xmlhttp = newParser();

//display message in target container
function display(target,message) {
	tlayer = new layer(target);
	tlayer.write('');
	tlayer.add(message);
}

//add to display message in target container
function displayadd(target,message) {
	tlayer = new layer(target);
	tlayer.add(message);
}

function cursor_wait() {
return;
	if ($('contenttable'))
		$('contenttable').style.cursor = 'wait';
	if ($('body'))
		$('body').style.cursor = 'wait';
	else if (document.body)
		document.body.style.cursor = 'default';
	
	if ($('loading')) {
		tlayer = new layer('loading');
		tlayer.show();
	}
}

function cursor_clear() {
return;
	if ($('contenttable'))
		$('contenttable').style.cursor = 'default';
	if ($('body'))
		$('body').style.cursor = 'default';
	else if (document.body)
		document.body.style.cursor = 'default';
		
	if ($('loading')) {
		tlayer = new layer('loading');
		tlayer.hide();
	}
}

function parse_string(tstring)
{
//alert(tstring);	
	if (tstring.length > 0 && tstring.indexOf(';;;;') >= 0) {
		toutput = tstring.split(";;;;");
		teller = 0;
		terror = '';
		for (i in toutput) {
			if (toutput[i] != '') {
				//alert(toutput[i]);
				if (tstring.indexOf('<font face="Arial" size=2') < 0) {
					try {
						//alert(toutput[i]);
						eval(toutput[i]);
					} catch(e) {
						terror = terror + '<br><br>' +e+'<br> --- ';//+url;
						//alert(url + ' error: '+e);
					}
					teller++;
				} else
					alert(toutput[i]);
			}
		}
	}
}

function parseUrl(url, async) {
	if (xmlhttp) { 
		d = document;
		xmlhttp = newParser();
		xmlhttp.open("GET", url, async);
		if (async) {
			xmlhttp.onreadystatechange = function () {
				if (xmlhttp.readyState == 4) {
					tstring = xmlhttp.responseText.toString();
					parse_string(tstring);
				}
			}
			xmlhttp.send(null);
		} else {
			xmlhttp.send(null);
			tstring = xmlhttp.responseText.toString();
			parse_string(tstring);
		}
	}
}

function parseUrl2(postdata, async) {
	if (xmlhttp) { 
		d = document;
		xmlhttp = newParser();
//url = url + "&unique=" + Math.floor(Math.random()*9999999);
//alert(url);
		
		xmlhttp.open("POST", appurl,async);
		alert(postdata);
		xmlhttp.send(postdata);
	}
}

function ajaxCall() {	if (arguments.length > 0) {
		cursor_wait();
		callstr = '';
		for (var i = 0; i < arguments.length; i++) {
			vals = arguments[i].split(':');
			if (vals.length == 1)
				callstr = callstr + vals;
			if (vals.length == 2)
				callstr = callstr + (callstr == '' ? '?' : '&') + vals[0] + '=' + vals[1];
			if (vals.length > 2) {
				callstr = callstr + (callstr == '' ? '?' : '&') + vals[0] + '=';
				for (j=1; j<vals.length; j++)
					callstr = callstr + (j <= 1 ? '' : ':') + vals[j];
			}
		}
		parseUrl(appurl + callstr,1);
	}
}



function ajaxCall2() {	if (arguments.length > 0) {
		cursor_wait();
		callstr = '';
		for (var i = 0; i < arguments.length; i++) {
			vals = arguments[i].split(':');
			if (vals.length == 1)
				callstr = callstr + vals;
			if (vals.length == 2)
				callstr = callstr + (callstr == '' ? '?' : '&') + vals[0] + '=' + vals[1];
			if (vals.length > 2) {
				callstr = callstr + (callstr == '' ? '?' : '&') + vals[0] + '=';
				for (j=1; j<vals.length; j++)
					callstr = callstr + (j <= 1 ? '' : ':') + vals[j];
			}
		}
		parseUrl(appurl + callstr,0);
	}
}

function ajaxCall3() {
	if (arguments.length > 0) {
		cursor_wait();
		callstr = '';
		for (var i = 0; i < arguments.length; i++) {
			vals = arguments[i].split(':');
			if (vals.length == 1)
				callstr = callstr + vals;
			if (vals.length == 2)
				callstr = callstr + (callstr == '' ? '' : '&') + vals[0] + '=' + vals[1];
			if (vals.length > 2) {
				callstr = callstr + (callstr == '' ? '' : '&') + vals[0] + '=';
				for (j=1; j<vals.length; j++)
					callstr = callstr + (j <= 1 ? '' : ':') + vals[j];
			}
		}
		parseUrl2(callstr,1);
	}
}

function makenewElement(list,newval,newdisp,selected) {
	thelist = eval("document.navform."+list);
	thelist.options[thelist.options.length] = new Option(newdisp,newval,false,selected == 'true' ? true : false);
}

function mne(list,newval,newdisp,selected) {
	thelist = eval("document.navform."+list);
	thelist.options[thelist.options.length] = new Option(newdisp,newval,false,selected == 'true' ? true : false);
}