var xmlHttp

function TRIM(stringToTrim) {
  return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function get_weeks(season,base)
  {
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
    {
    alert("Your browser does not support AJAX!");
    return false;
    }

  var weekList = document.getElementById("week");
  var optionItem;

  if (season.length==0)
    {
    // clear existing values in Week List
    for (var count = weekList.options.length=1; count >-1; count--)
    {
       weekList.options[count] = null;
    }

    textValue = "Select One";
    optionItem = new Option(textValue, textValue, false, false);
    weekList.options[0] = optionItem;

    return false;
    }
  var url= base+"season_weeks.php";
  url=url+"?q="+season;
  xmlHttp.onreadystatechange=stateChanged;
  xmlHttp.open("GET",url,false);
  xmlHttp.send(null);
  var result = xmlHttp.ResponseText;
  var weeks = result.split(",");
  var size = weeks.length;

  // clear existing values in User List
  for (var count = weekList.options.length=1; count >-1; count--)
  {
     weekList.options[count] = null;
  }
  // create new list
  for (var count = 0; count < size; count++)
  {
     textValue = weeks[count];
     optionItem = new Option(textValue, textValue, false, false);
     weekList.options[weekList.length] = optionItem;
  }
  weekList.options[0].selected = true;
}

// Watches for change in state of season
function stateChanged()
  {
  if(xmlHttp.readyState==4)
    {
    document.getElementById("week").innerHTML=xmlHttp.responseText;
    }
}

// Tests for AJAX Compatibility of browers.
function GetXmlHttpObject()
  {
  var xmlHttp=null;
  try
    {
    // Firefox, Oper 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}
