/**
 * For this is the AJAX.
 * url: the path
 * method: {"GET", "POST"}
 * targetId: string name of the element id in which to stick result
 * finishedHook: function to run when response is ready from the server
 * params: of the form "var1=arse&var2=cake"
 */
function jajax(url, method, targetId, finishedHook, params) {
//	console.log('jajax doing url '+url);
//	console.log('jajax query string '+params);
	
   	var target = document.getElementById(targetId);
   	if (document.getElementById) {
		var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	}
	if (x) {
		x.onreadystatechange = function() {
			if (x.readyState == 4 && x.status == 200) {
				if (target) target.innerHTML = x.responseText;
				if (finishedHook) finishedHook();
			}
		}
		x.open(method, url, true);
		x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		x.send(params);
	}
}


/* Fades the style.opacity of an element over totalTime with
 * the supplied number of samples. 20/sec is smooth.
 * Important side-effects (which stop clicks going to it once out, and get them back again)
 *  If start = 0, sets:  style.display = '' FIRST
 *  If end = 0, sets:  style.display = 'none' LAST
 *    --  and then sets the opacity to the original value so it can be
 *        displayed immediately again with just a display = ''.
 */
function fadeOpacityShowHide(elementName, start, end, samples, totalTime) {
	alert("fadeOpacityShowHide for element "+elementName+" is deprecated!");
	/*
	samples--;
	if (start==0) //we are fading in from invisible
		setTimeout("changeOpac("+opacity+", '"+elementName+"'); document.getElementById('"+elementName+"').style.display='';", 0);
	if (end==0) //we are fading out to invisible
		setTimeout("document.getElementById('"+elementName+"').style.display='none'; changeOpac("+opacity+", '"+elementName+"');", totalTime+1);
	for (i=0; i<=samples; i++) {
		var done = i/samples;
		var opacity = start*(1-done) + end*done;
		var time = done*totalTime;
		//var command = "document.getElementById('"+elementName+"').style.opacity = "+opacity;
		var command = "changeOpac("+opacity+", '"+elementName+"')";
		setTimeout(command, time);
	}
	*/
}

//0 - 1
function changeOpac(opacity, id) {
	alert("changeOpac for id "+id+" is deprecated!");
	
	/*
	 var object = document.getElementById(id).style;
		object.MozOpacity = opacity;
	    object.KhtmlOpacity = opacity;
	    object.opacity = opacity;
	    object.filter = "alpha(opacity=" + (opacity*100) + ")";
	    */
}



/* same but with a finished hook */
function fadeOpacityShowHideWithFinishedHook(elementName, start, end, samples, totalTime, finishedHook) {
	alert("fadeOpacityShowHideWithFinishedHook for element "+elementName+" is deprecated!");

	//fadeOpacityShowHide(elementName, start, end, samples, totalTime);
	//if (finishedHook) setTimeout(finishedHook, totalTime);
}


