/********************************************************************************
GET THE INFORMATION ABOUT THE COUNTRY AND DISPLAY THE PROVINCE/STATES
********************************************************************************/

//get the country so information can be returned
function getCountry(){
	var country = document.getElementById("country").value;
	var url = "responses/distributors_response.php?country=" + escape(country);
	request.open("GET", url, true);
	request.onreadystatechange = updateCountry;
	request.send(null);
}

//insert the country information into the HTML	
function updateCountry(){
	var country = document.getElementById("country").value;
	if(request.readyState == 4){
		/* Get the response from the server */
		var info = request.responseText;
		/* Upsate the page */
		if(country == "Canada" || country == "United States"){
			document.getElementById('state_selection').innerHTML = info;
			document.getElementById('distributor_info').innerHTML = 'Please select the Province/Territory/State.';
		}else{
			document.getElementById('distributor_info').innerHTML = info;
			document.getElementById('state_selection').innerHTML = '';
		}
		/* Change the background image */
		image = "url(images/distributors/";
		if(country == "Canada"){
			 document.getElementById('distributor_info').style.backgroundImage = image + "canada.jpg)";
		}else if(country == "United States"){
			 document.getElementById('distributor_info').style.backgroundImage = image + "america.jpg)";
		}else if(country == "Germany"){
			 document.getElementById('distributor_info').style.backgroundImage = image + "germany.jpg)";
		}else if(country == "Sweden"){
			 document.getElementById('distributor_info').style.backgroundImage = image + "sweden.jpg)";
		}else{
			 document.getElementById('distributor_info').style.backgroundImage = image + "world.jpg)";
		}
	}
}



/********************************************************************************
GET THE INFORMATION ABOUT THE STATE/PROVINCE AND DISPLAY THE DISTRIBUTOR INFORMATION
********************************************************************************/

//get the state/province so information can be returned
function getState(){
	var state = document.getElementById("state").value;
	var url = "responses/distributors_response.php?state=" + escape(state);
	request.open("GET", url, true);
	request.onreadystatechange = updateState;
	request.send(null);
}

//insert the distributor information into the HTML	
function updateState(){
	if(request.readyState == 4){
		/* Get the response from the server */
		var info = request.responseText;
		/* Upsate the page */
		document.getElementById('distributor_info').innerHTML = info;
	}
}



/********************************************************************************
RESET THE FORM WHEN IT LOADS
********************************************************************************/

function resetForm() {
   for (i=0; i<document.forms.length; i++) {
     document.forms[i].reset();
   }
}
