/******************************************************************************
 *  Global Variables!
******************************************************************************/ 

// This variable holds the AJAX goodness.
var xmlHttp = GetXmlHttpObject();
// This variable holds the AJAX goodness.
var xmlHttp2 = GetXmlHttpObject();
// This variable holds the iteration number of the images for the verification code.  This is so the images don't cache
var validateCount = 1;

var MPLDivId = 0;



/******************************************************************************
 *  ExtendedSectionMenu Function
 *  
 *  This function toggles the openning of the sub sports menu.  If
 *    extendedSectionExpanded = 0, it will check the AJAX.  Otherwise it will 
 *    close.  It also changes the SportMenuId link so that if the Sport link is 
 *    clicked while the sub menu is open, it will close it before allowing the
 *    closing of the sport menu.     
******************************************************************************/  
function GenerateValidate() {  
  // Start of the AJAX call
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null) { //If you suck at life
    alert ("Browser does not support HTTP Request");
    return;
  }
  // This is the file called that holds the query/layout
  var url="validateScript.php?VNum="+validateCount;
  validateCount++;
  xmlHttp.onreadystatechange=stateChanged ;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}


function openState(stateAbbr) {  
  // Start of the AJAX call
  xmlHttp2=GetXmlHttpObject()
  if (xmlHttp2==null) { //If you suck at life
    alert ("Browser does not support HTTP Request");
    return;
  }
  // This is the file called that holds the query/layout
  var url="statePopulate.php?State="+stateAbbr;
  validateCount++;
  xmlHttp2.onreadystatechange=stateChanged2 ;
  xmlHttp2.open("GET",url,true);
  xmlHttp2.send(null);
}
/******************************************************************************
 *  stateChanged Function
 *  This function reads in the query call from getSubSports.dbml and takes
 *    what that file creates and posts it to the SubSectionContent div.  If
 *    there is no content for that div it directly links to the sport.  If 
 *    there is then it slides the menu.  
******************************************************************************/ 
function stateChanged()  { 
  if (xmlHttp.readyState==4 || xmlHttp.readyState=='complete') { 
     if (xmlHttp.responseText == '') {
      window.location.href='#';
     }
     else {
      document.getElementById('verifyImgTd').innerHTML=xmlHttp.responseText;
     }
  } 
}

function stateChanged2()  { 
  if (xmlHttp2.readyState==4 || xmlHttp2.readyState=='complete') { 
     if (xmlHttp2.responseText == '') {
      window.location.href='#';
     }
     else {
      document.getElementById('stateContainer').innerHTML=xmlHttp2.responseText;
     }
  } 
}

/******************************************************************************
 *  GetXmlHttpObject Function
 *  This function creates the needed vars and functions for the ajax variable
 *    declared at the top of this file with the other global variables.   
******************************************************************************/ 
function GetXmlHttpObject() {
var xmlHttp=null;
  try
   {
   // Firefox, Opera 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;
}

function SwapMPL(MPLID) {
  if (MPLDivId != 0)
    document.getElementById('MPL'+MPLDivId).style.display='none';
  if (MPLID != MPLDivId) {
    document.getElementById('MPL'+MPLID).style.display='block';
    MPLDivId = MPLID;
  }
  else MPLDivId = 0;
}