/**********************************************
AJAX functions
**********************************************/

function createRequestObject() {

   var req;

   if(window.XMLHttpRequest){
      // Firefox, Safari, Opera...
      req = new XMLHttpRequest();
   } else if(window.ActiveXObject) {
      // Internet Explorer 5+
      req = new ActiveXObject("Microsoft.XMLHTTP");
   } else {
      // There is an error creating the object,
      // just as an old browser is being used.
      alert('Problem creating the XMLHttpRequest object');
   }

   return req;

}

var http = createRequestObject();
var globalvar = new Object();

function sendRequest(url, parameters, id, handle) {
	http.open('get', url+'?'+parameters);
	globalvar.id = id;
	if(handle == 'true') {http.onreadystatechange = handleResponse;}
	http.send(null);   

}

function handleResponse() {
   if(http.readyState == 4 && http.status == 200){
      var response = http.responseText;
      if(response) {
         document.getElementById(globalvar.id).innerHTML = response;
     }
   }
}

function requestCalendar(month, year, type) {
	sendRequest('src/requestcal.php', 'type=' + type + '&month=' + month + '&year=' + year, 'cal-container', 'true');
}

//some n00b functions...

function changeElement(id, content) {
	document.getElementById(id).value = content;
	document.getElementById(id).innerHTML = content;
}

function hideElement(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showElement(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

function maxDimension(newdim,start) { 
	//resizes images
	//sets max height/width = 250, constrains proportions, second arg is starting image # (in order of occurance in document)
	var contentimages=document.images;
	for (var n = start-1; n < contentimages.length; n++) {
		//alert(contentimages[n].src);
		if(contentimages[n].width > contentimages[n].height) {
			newwidth = newdim;
			newheight = newwidth * contentimages[n].height / contentimages[n].width;
			contentimages[n].width=newwidth;
			contentimages[n].height=newheight;
		}
		else if(contentimages[n].height > contentimages[n].width) {
			newheight = newdim;
			newwidth = newheight * contentimages[n].width / contentimages[n].height;
			contentimages[n].width=newwidth;
			contentimages[n].height=newheight;
		}
		else {
			contentimages[n].width=newdim;
			contentimages[n].height=newdim;
		}
	}
}