var xmlHttp

// Basic ajax function. Send the url, any variables and the id of the div the results
// should be displayed in.
// url: test.php
// variables: &var1=blah&var2=blah&var3=blah
function callToServer(url,variables,containerid) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request")
		return
	}
	var d = new Date();
	url = url + '?d=' + d.getTime() + variables;
	xmlHttp.onreadystatechange=function(){ stateChanged(containerid); }
	xmlHttp.open('GET',url,true)
	xmlHttp.send(null)
}

function stateChanged(containerid) { 
	if (xmlHttp.readyState==4) { 
		if (xmlHttp.status==200) {
			document.getElementById(containerid).innerHTML=xmlHttp.responseText; 
		}
	} 
}

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 enterKeyEditName(newName,url,picid,oldName,containerid) {
	callToServer(url,'&picid=' + picid + '&newname=' + newName + '&oldname=' + oldName,containerid);
}


// Display an error message
function errorMsg(errormsg) {
	alert(errormsg);
	document.getElementById('errormsgtxt').innerHTML = errormsg;
	document.getElementById('errormsg').style.display = 'block';
}