// Ajax Functions for the page

var ajaxFixturesUrl = "includes/resp_fixtures.php"; // The server-side script

function getFixtures(){
  var ajaxReq = getAjaxObject();
  var rand_no = Math.random();
	// Create a function that will receive data sent from the server
	ajaxReq.onreadystatechange = function()
	{
		if(ajaxReq.readyState == 4  && ajaxReq.status == 200)
		{
			document.getElementById('searchopenfixtures').innerHTML = ajaxReq.responseText;
		}
		
		if(ajaxReq.readyState!=4)
		{
			document.getElementById('searchopenfixtures').innerHTML = "One moment please ...";
			//document.getElementById("ajaxstatus").innerHTML= "One moment please ...";
		}
	}
	
	// arguments
// 	var country = document.fixtsearch.countryid.options[document.fixtsearch.countryid.selectedIndex].value; // country
// 	var state = document.fixtsearch.stateid.options[document.fixtsearch.stateid.selectedIndex].value; // country
// 	var county = document.fixtsearch.countyid.options[document.fixtsearch.countyid.selectedIndex].value; // country
 
	var country = document.getElementById('countryid').value; // country
	var state = document.getElementById('stateid').value; // state
	var county= document.getElementById('countyid').value; // county

	//var gender = document.fixtsearch.gender.options[document.fixtsearch.gender.selectedIndex].value; // country
	var gender=false;
	var genderinp = document.getElementsByName('gender');
	for (var ii=0; ii<genderinp.length; ii++ ){
    if(genderinp[ii].checked==true) gender = genderinp[ii].value;
  }
	//var status = document.fixtsearch.status.options[document.fixtsearch.status.selectedIndex].value; // country
	var status=false;
	var statusinp = document.getElementsByName('status');
	for (var ii=0; ii<statusinp.length; ii++ ){
    if(statusinp[ii].checked==true) status = statusinp[ii].value;
  }
  var startdate = false
  try
  {
    //startdate = document.fixtsearch.startdate.value;
    startdate = document.getElementById('startdate').value;
  }
  catch (e)
  {
    // Something went wrong - do date
  }

// ************************************
// GET
// ************************************
// 	var queryString = "?countryid="+country+"&stateid="+state+"&countyid="+county+"&status="+status+"&gender="+gender+"&startdate="+startdate+"&rq="+rand_no;
// 	ajaxReq.open("GET", ajaxFixturesUrl + queryString, true);
// 	ajaxReq.send(null);


// ************************************
// POST
// ************************************
   var parameters="countryid="+country+"&stateid="+state+"&countyid="+county+'&status='+encodeURI(status)+'&gender='+encodeURI(gender)+'&startdate='+encodeURI(startdate)+"&rq="+rand_no;
   ajaxReq.open("POST", ajaxFixturesUrl, true);
   ajaxReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   ajaxReq.setRequestHeader("Content-length", parameters.length);
   ajaxReq.setRequestHeader("Connection", "close");
   ajaxReq.send(parameters);



}



