/* ============================================================================
*  The function setupMakeModel is run at the loading of the webpage. The
*  odd mechanics of the structure is to be as compatible with as many browers
*  as possible. The function will populate the makes after the browser is
*  finished loading the page.
*  ========================================================================= */
function setupMakeModel()
{
	resetMakeSelection(document.quoteform.automake);
	resetModelSelection(document.quoteform.automodel);

	fillMakeSelection(document.quoteform.automake);

	if (typeof(in_automake) != 'undefined'
		&& in_automake != ''
		&& typeof(in_automodel) != 'undefined'
		&& in_automodel != ''
		)
		selectMakeModel(document.quoteform.automake, in_automake, document.quoteform.automodel, in_automodel);
}

/* ============================================================================
*  Validate form, and if everything is okay, submit it!
*  ========================================================================= */
//function getDistances()
//{
//	document.getElementById('light').style.display='block';
//	document.getElementById('fade').style.display='block';
//	//document.getElementById("quoteform").disabled = true;
//
//	// Start the distance computations
//	getMiles(document.getElementById("fromtext").value
//			, document.getElementById("totext").value
//			, function(code, result)
//				{
//					if (code != null && result != null)
//					{
//						if (code == "from" || code == "to")
//						{
//							displayCityStateOptions(code, result)
//						}
//						else
//						{
//							var errorElem;
//							if (code == "fromerror") errorElem = document.getElementById("fromtext");
//							if (code == "toerror") errorElem = document.getElementById("totext");
//
//							if (errorElem != null) errorElem.style.backgroundColor = "rgb(250,175,175)";
//
//							displayCalcError(result);
//						}
//					}
//					else
//					{
//						displayCalcError("Unspecified Error has occurred. Please let us know.");
//					}
//
//					document.getElementById('light').style.display='none';
//					document.getElementById('fade').style.display='none';
//					//if (document.getElementById("quoteform").disabled) document.getElementById("quoteform").disabled = false;
//
//				}
//			);
//}


/* ============================================================================
*  Displays options that come back from Maps API
*  ========================================================================= */
function displayCityStateOptions(which, result)
{
	var thisSelect = document.getElementById(which+"select");
	thisSelect.length = 0;

	for (var i = 0; i < result.length; i++)
	{
		thisSelect.options[i] = new Option();
		thisSelect.options[i].text = result[i];
		thisSelect.options[i].value = result[i];
	}

	var thisSelectInput = document.getElementById(which+"selectinput");
	var thisTextInput = document.getElementById(which+"textinput");

	thisTextInput.style.display = "none";
	thisSelectInput.style.display = "block";
	thisSelect.style.color = "rgb(255,0,0)";
	thisSelect.style.fontWeight = "bold";
	thisSelect.style.width = "10em";
}

/* ============================================================================
*  Displays an error message
*  ========================================================================= */
function displayCalcError(message)
{
	//var resultmessage = document.getElementById("resultmessage");
	//resultmessage.innerHTML = message;

	if (message != '') alert(message);
}

