function ajaxFunction()
{
var xmlHttp, xmlHttp2;
try
  {  // Firefox, Opera 8.0+, Safari  
	xmlHttp=new XMLHttpRequest();
	xmlHttp2=new XMLHttpRequest();
  }
catch (e)
  {  // Internet Explorer  
  try
    {    
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {    
    try
      {      
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {      
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }

  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
	splitStr = xmlHttp.responseText.split(",");
        /*document.myForm.tarea.value=splitStr;*/
	if( ready2 == 1 )
		createURL();
	else
	    ready1 = 1;
	delete xmlHttp;

      }
/*    else	{
	document.myForm.tarea.value="";
	}*/
    }



  xmlHttp2.onreadystatechange=function()
    {
    if(xmlHttp2.readyState==4)
      {
	splitStr2 = xmlHttp2.responseText.split(",");
	if( ready1 )
		createURL();
	else
	    ready2 = 1;
	delete xmlHttp2;
      }
    }
 

  var url2 = "http://news.csusb.edu/kjunk2.asp";
  xmlHttp2.open("GET",url2,true);
  xmlHttp2.send(null);

  var url = "http://news.csusb.edu/kjunk.asp";
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  }


function createURL()	{
	var altStr = "California State University, San Bernardino, California, zip code 9 2 4 0 7. Weather observation for today at " + splitStr[1] + ".";
	var ttlStr = "California State University, San Bernardino, Zip code 92407. Weather observation for today a_t " + splitStr[1] + ".";

	if( parseFloat(splitStr[4] ) <= 0.000 )	{
		altStr = altStr + " Temperature " + parseInt(splitStr[9]) + " degrees and there is no wind. It last blew from the " + translateWindDirection(splitStr[3]) + ".";
		ttlStr = ttlStr + " Temperature: " + parseInt(splitStr[9]) + ", There is no wind.  It was last blowing from the " + translateWindDirection(splitStr[3]) + ".";
		}
	if( parseFloat(splitStr[4] ) > 0.000 )	{
		altStr = altStr + " Temperature " + parseInt(splitStr[9]) + " degrees, wind is blowing at " + parseInt(splitStr[4]) + " miles per hour from the " + translateWindDirection(splitStr[3]) + ".";
		ttlStr = ttlStr + " Temperature: " + parseInt(splitStr[9]) + ", Wind is blowing at " + parseInt(splitStr[4]) + " mph from the " + translateWindDirection(splitStr[3]) + ".";
		}

	var rnrt = parseFloat(splitStr2[257]);

	if( rnrt > 0 && rnrt < 0.1 )	{
		altStr = altStr + " It is drizzling.";
		ttlStr = ttlStr + " It is drizzling.";
		}
	if( rnrt >= 0.1 && rnrt < 0.5 )	{
		altStr = altStr + " It is raining.";
		ttlStr = ttlStr + " It is raining.";
		}
	if( rnrt >= 0.5 && rnrt < 1.00 ) {
		altStr = altStr + " It is raining hard.";
		ttlStr = ttlStr + " It is raining hard.";
		}
	if( rnrt >= 1.00 )	{
		altStr = altStr + " It is raining hard enough that flooding is possible.";
		ttlStr = ttlStr + " It is raining hard enough that flooding is possible.";
		}

	var wdsp = parseInt( splitStr[4] );

	if( wdsp >= 19 && wdsp <= 24 ) 	{
		altStr = altStr + "Preliminary Wind Advisory is in effect.";
		ttlStr = ttlStr + "Preliminary Wind Advisory is in effect.";
		}
	if( wdsp >= 25 && wdsp <= 31 ) 	{
		altStr = altStr + "High Wind Advisory is in effect.";
		ttlStr = ttlStr + "High Wind Advisory is in effect.";
		}
	if( wdsp >= 32 && wdsp <= 46 ) 	{
		altStr = altStr + "High Wind Alert is in effect.";
		ttlStr = ttlStr + "High Wind Alert is in effect.";
		}
	if( wdsp >= 47 ) {	
		altStr = altStr + "High Wind Warning is in effect.";
		ttlStr = ttlStr  + "High Wind Warning is in effect.";
		}
	var myImg = document.getElementById("WXBug");
	myImg.src = "http://weather.csusb.edu/WebWX/WXSynop.aspx?Graph=RAWGPH&amp;TMPOUT=" + splitStr[9] + "&amp;WNDSPD=" + splitStr[4] + "&amp;WNDDIR=" + splitStr[3] + "&amp;THTIME=" + splitStr[1] + "&amp;RNRATE=" + splitStr2[257];
	ttlStr = altStr;
	myImg.alt = altStr;
	myImg.title = ttlStr;
	ready1 = 0;
	ready2 = 0;
//	document.myForm.urldata.value = "http://weather.csusb.edu/WebWX/WXSynop.aspx?Graph=RAWGPH&amp;TMPOUT=" + splitStr[9] + "&amp;WNDSPD=" + splitStr[4] + "&amp;WNDDIR=" + splitStr[3] + "&amp;THTIME=" + splitStr[1] + "&amp;RNRATE=" + splitStr2[257];
	/*document.myForm.urldata.value = altStr;*/
	}


function translateWindDirection( WindDir )	{
	var wdir = parseInt( WindDir );
	if( wdir > 348 || wdir <= 11 )	return "North";
	if( wdir > 11  && wdir <= 33 )  return "North Northeast";
	if( wdir > 33  && wdir <= 55 )	return "Northeast";
	if( wdir > 55  && wdir <  78 )	return "East Northeast";
	if( wdir >= 78 && wdir <= 101 )	return "East";
	if( wdir > 101 && wdir <= 123 )	return "East Southeast";
	if( wdir > 123 && wdir <= 145 )	return "Southeast";
	if( wdir > 145 && wdir < 168 )	return "South Southeast";
	if( wdir >= 168 && wdir <= 191 ) return "South";
	if( wdir > 191 && wdir <= 213 )	return "South Southwest";
	if( wdir > 213 && wdir <= 235 )	return "Southwest";
	if( wdir > 235 && wdir < 258 )	return "West Southwest";
	if( wdir >= 258 && wdir <= 281 ) return "West";
	if( wdir > 281 && wdir <= 303 ) return "West Northwest";
	if( wdir > 303 && wdir <= 325 )	return "Northwest";
	if( wdir > 325 && wdir <= 348 )	return "North Northwest";

	return "";
	}
