



function initList(action) {
	var outputDiv;
	var postValues = "action=";
	 
		
	postValues += action;
	
	switch (action) {
		case "tireSizeList":
			outputDiv = "selectTireSizes";
			break;
			
		case "tireBrands":
			outputDiv = "selectBrands";
			postValues += "&CustomerName="+CustomerName;
			break;
			
		case "initYears":
			outputDiv = "yearMakeModel";
			break;
			
	}

	sendPostData(outputDiv, postValues);
	
	


}

function updateYearMakeModel(changed){
	
	var outputDiv;
	var postValues = "action=" + changed;
	var year = document.getElementById('year').value;
	var make = document.getElementById('make').value;
	var model = document.getElementById('model').value;
	var option = document.getElementById('option').value;
	clearMakeData();
	initList('tireSizeList');
	
	var postValues1 = "&year="+year;
	postValues1 += "&make="+ make;
	postValues1 += "&model="+ model;
	postValues1 += "&option="+ option;
	
	switch (changed) {
		case 'changeYear':
			
			postValues = "action=" + changed + postValues1;

			outputDiv = "yearMakeModel";
			sendPostData(outputDiv, postValues);
			break;
		case 'changeMake':
			postValues = "action=" + changed + postValues1;
			outputDiv = "carMake";
			sendPostData(outputDiv, postValues); // fall through to model
		case 'changeModel':	
			postValues = "action=changeModel" + postValues1;
			outputDiv = "carModel";
			sendPostData(outputDiv, postValues); // fall through to option

		case 'changeOption':
			postValues = "action=changeOption" + postValues1;
			outputDiv = "carOptions";
			sendPostData(outputDiv, postValues);

			break;		
	}
	
	

}




function sendPostData(outputDiv, postValues) {
	var xmlHttp;  // The variable that makes Ajax possible!

	var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
	var url = "eTireLinkRetail/eTireLinkRetail_TireGuide_BE.php";



	xmlHttp = new GetXmlHttpObject();
	if (xmlHttp==null) {
  		alert ("Your browser does not support AJAX!");
 		return;
 		} 

	// Create a function that will receive data sent from the server
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4){

		document.getElementById(outputDiv).innerHTML=xmlHttp.responseText;

		}
	}


	xmlHttp.open("post", url,true);
    xmlHttp.setRequestHeader("Content-Type", contentType);
	xmlHttp.send(postValues); 
}





function displayCarModelTireSize(year, make, model, option)
{
	var outputDiv = 'tireSizes';
	var postValues = "action=detail";
	postValues += "&year="+year;
	postValues += "&make="+make;
	postValues += "&model="+model;
	postValues += "&option="+option;
	
	
	//alert ('post=  ' + postValues);
	sendPostData(outputDiv, postValues);

}

//Browser Support Code
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
function clearAllMakeData() 
{

	initList('initYears');
	document.getElementById('tireSizes').innerHTML = "<p>&nbsp;</p>";


}



function clearMakeData() 
{

	document.getElementById('tireSizes').innerHTML = "<p>&nbsp;</p>";


}






function validateCarTireSize()
{
	var yearExists = document.TireInfo.year.selectedIndex;
	var makeExists = document.TireInfo.make.selectedIndex;
	var modelExists = document.TireInfo.model.selectedIndex;
	var optionsExists =document.TireInfo.option.selectedIndex;

	
	
	if ((modelExists >0) && (makeExists >0) && (yearExists >0) &&  (optionsExists >0)) {
		//return true;
		displayCarModelTireSize(document.getElementById('year').value,document.getElementById('make').value,document.getElementById('model').value,document.getElementById('option').value);
		
		}
	return false;
}	

function validateTireSize()
{
	var widthExists = document.TireInfo.width.value;
	var ratioExists = document.TireInfo.ratio.value;
	var rimExists = document.TireInfo.rim.value;
	
	var chks = document.getElementsByName('optSize');
	
	var hasChecked = false;
        // Get the checkbox array length and iterate it to see if any of them is selected
    for (var i = 0; i < chks.length; i++)
        {
                if (chks[i].checked)
                {
                        hasChecked = true;
                        break;
                }
        }

	
	

	if ( ((widthExists >0) && (ratioExists >0) && (rimExists >0)) || (hasChecked)) {
		return true;
		
	}
	
	return false;
}	




