//my second ajax script---------------------------------------------------------------------------------------------------
//This requests and receives weather data for a given zip code using a php script on the server

var XMLHttpRequestObject = false;
function getwx(){
		//I nested a function to build a delay using setTimeout	
		//need to fade out the old verse here before we get the new one (like to do after I get it but 
		//I can't figure out how to stop the subsequent function to delay for the fade out	
		Effect.Fade('wxdiv', {from:1.0, to: 0.01}); //if you let it go to zero the div goes away totally momentarily and
		//               everything jerks up. this way you just a shift from the old to the new size.
		setTimeout("getwx2()", 900);//this is to hold up the ajax call until the old verse has faded
									// if it takes more than 0.5 secs for the fade out to finish, you'll get a flash of a 
								//verse and a blank div											
}

function getwx2(){//had to nest this otherwise the ajax function finished while the fade out was happening and the div
// ended up blank and I also wanted the div to fade, resize, then fade in, in that order.
var zip = document.getElementById('zip').value;
if (zip == false){zip = '93063'}

	var url = "get_wx.php?zip="+zip;	
	if (window.XMLHttpRequest){	
		XMLHttpRequestObject = new XMLHttpRequest();
	}
	else {
		if (window.ActiveXObject){
			try{XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}
	//this keeps IE from just going to the cache and not downloading an updated file
	url = url + "&kill_cache=" + new Date().getTime();
	
	if(XMLHttpRequestObject){
		XMLHttpRequestObject.open("GET", url);
		XMLHttpRequestObject.onreadystatechange = function(){
			if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {

/*				var xml_wx = XMLHttpRequestObject.responseXML;
				var description = false;
				new_wx_description_nodes = xml_wx.getElementsByTagName("description");
				new_wx_description = new_wx_description_nodes[0].firstChild.nodeValue;
*/

				var wx_text = XMLHttpRequestObject.responseText;
				document.getElementById("wxdiv").innerHTML = wx_text;
//need to fade in the new here

Effect.Appear('wxdiv');  //script.aculo.us effects.js v1.7.0

				
//clear memory
				delete XMLHttpRequestObject;
				XMLHttpRequestObject = null;
			}
		}
		XMLHttpRequestObject.send(null);


	}

	else {
		document.getElementById("wxdiv").innerHTML = "Sorry, but I couldn't create an XMLHttpRequest";
		Effect.Appear('wxdiv');
	}	
}

function getwx3(){  //things to do: need to add a setTimeout to an intermediate function to get fading in and out to work.
	Effect.Fade('wxdiv2', {from:1.0, to: 0.01}); //script.aculo.us effects.js v1.7.0
	var zip2 = document.getElementById('zip2').value;
	if (zip2 == false){zip2 = '93063'}
	var url = "get_wx.php?zip="+zip2;
	setTimeout( function(){			//the anonomous function is known as a "closure" and makes it possible to pass the parameters url and the function name
		getDataReturnText(url, wx_display_callback)}, 900);  //from ajaxgold
}	

function wx_display_callback(wx_text){
	setTimeout(function(){					//same as above
	document.getElementById("wxdiv2").innerHTML = wx_text;	
	Effect.Appear('wxdiv2'); //script.aculo.us effects.js v1.7.0
	},300);
}

