//Global Variables //

var num=0;
var interval = null;
var mkIndex=0;
//End//
function doLists(course,race_id)  {
	model = race_id.toUpperCase();
	course = course.toUpperCase();
	num++;

	if (num < 50)  {
		if (typeof get_dates == 'function' && typeof get_range =='function' && typeof _meeting=='object' && typeof make_v=='object' && typeof make_d=='object')  {
			get_dates(course);
			if (document.qSearch && document.qSearch.r_date && typeof document.qSearch.r_date.selectedIndex == 'number')  {
				mkIndex = document.qSearch.r_date.selectedIndex;
			}
			get_range(_meeting[mkIndex], _race_id[mkIndex], race_id);
			clearInterval(interval);
		}
	} else {
		clearInterval(interval);
	}
}

function get_dates(req_course)	{
	var dropDown;
	selectedIndex = 0;

	if (document.qSearch && document.qSearch.r_date)  {
		dropDown = document.qSearch.r_date;
	}
	else if(document.search && document.search.r_date)  {
		dropDown=document.search.r_date;
	}
	else if (document.forms[0] && document.forms[0].r_date)  {
		dropDown = document.forms[0].r_date;
	}

	if (dropDown)  {
			dropDown.length = 0;

			for(index=0; index<make_d.length; index++)	{

				dropDown[index] = new Option(make_d[index],make_v[index]);

				if (make_d[index]=="Make" || make_d[index]=="MAKE")  {
					dropDown[index] = new Option(make_d[index],"");
				}

				if (make_d[index]=="ANY MAKE")  {
					dropDown[index] = new Option(make_d[index],"ANY");
				}

				if(make_d[index].toUpperCase() == req_course){
					selectedIndex = index;

				}
			  }
			dropDown.options[selectedIndex].selected = true;
		}
		select_date(req_course);
}

function get_range(ranges,race_id,req_model)	{

	selectedIndex = 0;
	var dropDown;

	if (document.qSearch && document.qSearch.race_id)  {
		dropDown = document.qSearch.race_id;
	} else if(document.search && document.search.race_id)  {
		dropDown=document.search.race_id;
	} else if (document.forms[0] && document.forms[0].race_id)  {
		dropDown = document.forms[0].race_id;
	}

	if (dropDown)  {

		dropDown.length = 0;

		for(index=0; index<ranges.length; index++)	{

			dropDown[index] = new Option(ranges[index],race_id[index]);

			if (ranges[index]=="Model" || ranges[index]=="MODEL")  {
				dropDown[index] = new Option(ranges[index],"");
			  }

			  if (ranges[index]=="ANY MODEL")  {
				dropDown[index] = new Option(ranges[index],"ANY");
			  }
			  
			if(race_id[index].toUpperCase() == req_model){
				selectedIndex = index;
			}
			else if (ranges[index].toUpperCase() == "ANY MODEL" && req_model == "ANY")  {
				selectedIndex = index;
			}
		}
		dropDown.options[selectedIndex].selected = true;
	}
}

function select_date(req_date)  {
	var dropDown;

	if (req_date == null)  {
		req_date="";
	}

	if (document.qSearch && document.qSearch.r_date)  {
		dropDown = document.qSearch.r_date;
	}
	else if(document.search && document.search.r_date)  {
		dropDown=document.search.r_date;
	}
	else if (document.forms[0] && document.forms[0].r_date)  {
		dropDown = document.forms[0].r_date;
	}

	if (dropDown)  {
		for (x=0; x<dropDown.length; x++)  {
			mk=dropDown.options[x].value;
			if ( mk.toUpperCase()==req_date)  {
				if (dropDown.options[x].selected==false)   {
					dropDown.options[x].selected=true;
				}
			}
		}
	}
}
