function createRequestObject()
{
	var ro;
  var browser = navigator.appName;

  if(browser == "Microsoft Internet Explorer") {
		// on IE, we have to use ActiveX
  	ro = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
  	// on every other browser, we can directly create a new XMLHttpRequest object
    ro = new XMLHttpRequest();
  }
  return ro;
}

var http = createRequestObject();

// this function should be called for user input
// it opens up a php page with a querystring of 'action'
// this function could probably be adapted to POST

function sndReq(firstImage,firstDesc,action)
{
	firstImage = firstImage + "-medium.jpg";
	changeImage(firstImage,firstDesc);
	action= replaceAll(action);
//	alert(action);	
	http.open("get", "generateGallery.php?" + action);
	http.onreadystatechange = handleResponse;
    http.send(null);
}

// handles the response by outputting the text to the div with id=desc
function handleResponse()
{
	if(http.readyState == 4) {
    	document.getElementById('desc').innerHTML = http.responseText;
	}
}


// this function should be called for user input
// it opens up the usercheck.asp page with a querystring of 'action'
function sndUserCheck(action)
{
	http.open("get", "usercheck.asp?username=" + action);
  http.onreadystatechange = handleResponse;
  http.send(null);
}

//replaces all spaces with %20
function replaceAll(strText) 
{
	var strReplaceAll = strText;
	var intIndexOfMatch = strReplaceAll.indexOf( " " );
	// Loop over the string value replacing out each matching substring.
	while (intIndexOfMatch != -1){
		// Relace out the current instance.
		strReplaceAll = strReplaceAll.replace( " ", "%20" );
		// Get the index of any next matching substring.
		intIndexOfMatch = strReplaceAll.indexOf( " " );
	}
	return(strReplaceAll);
}
