// state downdown control

function startState() {
	// returns just the anchor 
	var startingState = window.location.hash.replace("#","");
	
	if (startingState != "") {
		ajaxFunction(startingState);
	}
}

function checkChange() {
	var state = document.forms['states'].elements[0].value;
	window.location = "http://bestbuyinc.com/community_relations/scholarship.htm#" + state;
	ajaxFunction(state);
	return false;
}

function ajaxFunction(state) {
	var optionsLength = document.forms['states'].list.options.length;
	for (var i=1; i < optionsLength; i++) {
		//console.log(document.forms['states'].list.options[i].value);
		if (document.forms['states'].list.options[i].value == state) {
			document.forms['states'].list.options[i].selected = true;
		}
	}
	var xmlhttp;
	if (window.XMLHttpRequest) {
 		// code for IE7+, Firefox, Chrome, Opera, Safari
  	xmlhttp=new XMLHttpRequest();
  } else if (window.ActiveXObject) {
	  // code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  } else {
  	alert("Your browser does not support XMLHTTP!");
  }
  
  xmlhttp.onreadystatechange=function() {
		if(xmlhttp.readyState==4) {
		  document.getElementById("state_winners").innerHTML = xmlhttp.responseText;
	  }
	}
	
	xmlhttp.open("GET", "states/"+state+".html",true);
	xmlhttp.send(null);
  
}






