/*
* File: 		ajax.js
* Author: 		Matt Skelton
* Company: 		Broda Seating LTD.
* Date:		December 18, 2008	: Created
*			December 22, 2008 	: Updated
* Description:	This file contains mutliple functions/methods that assist in Ajax implementations of the seatingisbelieving.com website.
* License:		You are free to use any code within this file as you see fit, as long as you include the header of this file. Cheers!
*/

/*
* Finds Distributors by their State
*/
findDistributorByState = function (form)
{
	var loader 				= document.getElementById("loader");
	loader.innerHTML 		= "<img src=\"/system/application/images/icons/ajax_loaders/ajax-loader.gif\" />";
			
	makeAjaxDistributorCall(form.state.options[form.state.selectedIndex].value);
		
	return false;
}

/*
* Finds distributors for a region & updates the searchResults div
*/
function makeAjaxDistributorCall(state)
{
	var xmlHttp = getTransport();
	
	if (xmlHttp == null)
	{
		return;
	}

	var url = "/contact/distributor/ajaxSearch/";
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send("state=" + state);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4)
		{
			var container 				= document.getElementById("searchResults");
			container.style.display 	= "none";
			container.innerHTML 		= xmlHttp.responseText;
			Effect.Appear(container, { duration: 1.0 });
			Effect.BlindDown(container, { duration: 1.0 });
			
			var loader 			= document.getElementById("loader");
			loader.innerHTML 	= "";
		}
	}
}
