var EZT_codedID = '';
var jQuery;
var EZT_SizeInfo;
var EZT_VehicleInfo;
document.ddlPrompt = 'Choose';
document.ddlPromptWidth = 'Select Width';
document.ddlPromptAspect = 'Select Aspect';
document.ddlPromptRim = 'Select Rim Size';
document.ddlPromptYear = 'Select Year';
document.ddlPromptMake = 'Select Make';
document.ddlPromptModel = 'Select Model';
document.ddlPromptOption = 'Select Option';
function EZT_LoadTireSize(a, b, c, d, e, f, g) {
	var h = true;
	EZT_SizeInfo = new EZT_SizeSearch(a, b, c, d, e);
	if (f != null && g != null) {
		EZT_SizeInfo.SetFormValues(f, g)
	}
	EZT_LoadTHtml();
	EZT_InitjQuery("widths")
}
function EZT_LoadVehicleSearch(a, b, c, d, e, f, g, h) {
	EZT_VehicleInfo = new EZT_VehicleSearch(a, b, c, d, e, f);
	if (g != null && h != null) {
		EZT_VehicleInfo.SetFormValues(g, h)
	}
	EZT_InitjQuery("validate")
}
function EZT_LoadVHtml() {
	if (EZT_VehicleInfo != null) {
		var a = EZT_VehicleInfo.yearID;
		var b = EZT_VehicleInfo.makeID;
		var c = EZT_VehicleInfo.modelID;
		var d = EZT_VehicleInfo.optionID;
		var e = EZT_VehicleInfo.submitID;
		var f = document.getElementById(a);
		if (f != null) {
			var g = "EZT-year";
			f.innerHTML = "<select id='" + g + "' onchange='EZT_GetMakes();'><option value=''>Select Year</option></select>"
		}
		var h = document.getElementById(b);
		if (h != null) {
			var g = "EZT-make";
			h.innerHTML = "<select id='" + g + "' onchange='EZT_GetModels();'><option value=''>Select Make</option></select>";
			//h.style.display = 'none'
		}
		var i = document.getElementById(c);
		if (i != null) {
			var g = "EZT-model";
			i.innerHTML = "<select id='" + g + "' onchange='EZT_GetOptions();'><option value=''>Select Model</option></select>";
			//i.style.display = 'none'
		}
		var j = document.getElementById(d);
		if (j != null) {
			var g = "EZT-option";
			j.innerHTML = "<select id='" + g + "' onchange='EZT_ShowVehicleSubmit();'><option value=''>Select Option</option></select>";
			//j.style.display = 'none'
		}
		var k = document.getElementById(e);
		if (k != null) {
			var g = "EZT-veh-submit";
			k.innerHTML = "<input type='submit' id='" + g + "' name='search' value='Search' onclick='EZT_OpenResultsV();' />";
			//k.style.display = 'none'
		}
	}
}
function EZT_LoadTHtml() {
	var a = EZT_SizeInfo.widthID;
	var b = EZT_SizeInfo.aspectID;
	var c = EZT_SizeInfo.rimID;
	var d = EZT_SizeInfo.submitID;
	var e = document.getElementById(a);
	if (e != null) {
		var f = "EZT-width";
		e.innerHTML = "<select id='" + f + "' onchange='EZT_GetAspects();'><option value=''>Select Width</option></select>"
	}
	var g = document.getElementById(b);
	if (g != null) {
		var h = "EZT-aspect";
		g.innerHTML = "<select id='" + h + "' onchange='EZT_GetRims();'><option value=''>Select Aspect</option></select>";
		//g.style.display = 'none'
	}
	var i = document.getElementById(c);
	if (i != null) {
		var j = "EZT-rimsize";
		i.innerHTML = "<select id='" + j + "' onchange='EZT_ShowSizeSubmit();'><option value=''>Select Rim</option></select>";
		//i.style.display = 'none'
	}
	var k = document.getElementById(d);
	if (k != null) {
		var l = "EZT-size-submit";
		k.innerHTML = "<input type='submit' id='" + l + "' name='search' value='Search' onclick='EZT_OpenResults();' />";
		//k.style.display = 'none'
	}
}
function EZT_FetchWidths() {
	var c = "EZT-width";
	var d = EZT_SizeInfo.widthID;
	jQuery(document).ready(function($) {
		var b = EZT_SizeInfo.ezyUrl + "App_Services/TireLibrary.ashx?method=widths&usejson=true&callback=?";
		$.getJSON(b, function(a) {
			if (a != null && a.widths != null) {
				EZT_PopulateList(d, c, a.widths)
			}
		}
		)
	}
	)
}
function EZT_GetAspects() {
	var a = document.getElementById('EZT-width');
	var b = document.getElementById(EZT_SizeInfo.widthID);
	var c = document.getElementById("EZT-aspect");
	var d = document.getElementById(EZT_SizeInfo.aspectID);
	var e = document.getElementById('EZT-rimsize');
	var f = document.getElementById(EZT_SizeInfo.rimID);
	c.selectedIndex = 0;
	e.selectedIndex = 0;
	//d.style.display = 'none';
	//f.style.display = 'none';
	if (a != null && a.value != null && a.value.length > 0) {
		if (c != null) {
			var g = EZT_EncodeQuery(a.value);
			if (g != document.ddlPrompt && g != document.ddlPromptWidth) {
				var h = "width=" + g;
				EZT_InitjQuery("aspects", h)
			}
		}
	}
}
function EZT_FetchAspects(d) {
	var e = "EZT-aspect";
	var f = EZT_SizeInfo.aspectID;
	if (d.length > 0) {
		jQuery(document).ready(function($) {
			var b = "method=aspects&" + d + "&usejson=true&callback=?";
			var c = EZT_SizeInfo.ezyUrl + "App_Services/TireLibrary.ashx?" + b;
			$.getJSON(c, function(a) {
				if (a != null && a.aspects != null) {
					EZT_PopulateList(f, e, a.aspects)
				}
			}
			)
		}
		)
	}
}
function EZT_GetRims() {
	var a = document.getElementById('EZT-width');
	var b = document.getElementById(EZT_SizeInfo.widthID);
	var c = document.getElementById("EZT-aspect");
	var d = document.getElementById(EZT_SizeInfo.aspectID);
	var e = document.getElementById('EZT-rimsize');
	var f = document.getElementById(EZT_SizeInfo.rimID);
	e.selectedIndex = 0;
	//f.style.display = 'none';
	if (c != null && c.value != null && c.value.length > 0) {
		if (e != null) {
			var g = EZT_EncodeQuery(a.value);
			var h = EZT_EncodeQuery(c.value);
			if (g != document.ddlPrompt && g != document.ddlPromptWidth && h != document.ddlPrompt && h != document.ddlPromptAspect) {
				var i = "width=" + g + "&aspect=" + h;
				EZT_InitjQuery("rims", i)
			}
		}
	}
}
function EZT_FetchRims(d) {
	var e = "EZT-rimsize";
	var f = EZT_SizeInfo.rimID;
	if (d.length > 0) {
		jQuery(document).ready(function($) {
			var b = "method=rims&" + d + "&usejson=true&callback=?";
			var c = EZT_SizeInfo.ezyUrl + "App_Services/TireLibrary.ashx?" + b;
			$.getJSON(c, function(a) {
				if (a != null && a.rims != null) {
					EZT_PopulateList(f, e, a.rims)
				}
			}
			)
		}
		)
	}
}
function EZT_Validate() {
	var e = EZT_VehicleInfo.yearID;
	if (EZT_VehicleInfo != null) {
		jQuery(document).ready(function($) {
			var c = "method=validate&usejson=true&callback=?";
			var d = EZT_VehicleInfo.ezyUrl + "App_Services/VehicleLibrary.ashx?" + c;
			$.getJSON(d, function(a) {
				var b = a.validate;
				if (b == 'true') {
					EZT_LoadVHtml();
					EZT_InitjQuery('years')
				} else {
					alert("This feature has not been enabled for this website.")
				}
			}
			)
		}
		)
	}
}
function EZT_FetchYears() {
	if (EZT_VehicleInfo != null) {
		var d = "EZT-year";
		var e = EZT_VehicleInfo.yearID;
		jQuery(document).ready(function($) {
			var b = "method=years&usejson=true&callback=?";
			var c = EZT_VehicleInfo.ezyUrl + "App_Services/VehicleLibrary.ashx?" + b;
			$.getJSON(c, function(a) {
				if (a != null && a.years != null) {
					EZT_PopulateList(e, d, a.years)
				}
			}
			)
		}
		)
	}
}
function EZT_GetMakes() {
	var a = document.getElementById('EZT-year');
	var b = document.getElementById(EZT_VehicleInfo.yearID);
	var c = document.getElementById('EZT-make');
	var d = document.getElementById(EZT_VehicleInfo.makeID);
	var e = document.getElementById('EZT-model');
	var f = document.getElementById(EZT_VehicleInfo.modelID);
	var g = document.getElementById('EZT-option');
	var h = document.getElementById(EZT_VehicleInfo.optionID);
	c.selectedIndex = 0;
	e.selectedIndex = 0;
	g.selectedIndex = 0;
	//d.style.display = 'none';
	//f.style.display = 'none';
	//h.style.display = 'none';
	if (a != null && a.value != null && a.value.length > 0) {
		if (c != null) {
			var i = EZT_EncodeQuery(a.value);
			if (i != document.ddlPromptWidth) {
				var j = "year=" + i;
				EZT_InitjQuery("makes", j)
			}
		}
	}
}
function EZT_FetchMakes(d) {
	if (EZT_VehicleInfo != null) {
		var e = "EZT-make";
		var f = EZT_VehicleInfo.makeID;
		if (d.length > 0) {
			jQuery(document).ready(function($) {
				var b = "method=makes&" + d + "&usejson=true&callback=?";
				var c = EZT_VehicleInfo.ezyUrl + "App_Services/VehicleLibrary.ashx?" + b;
				$.getJSON(c, function(a) {
					if (a != null && a.makes != null) {
						EZT_PopulateList(f, e, a.makes)
					}
				}
				)
			}
			)
		}
	}
}
function EZT_GetModels() {
	var a = document.getElementById('EZT-year');
	var b = document.getElementById(EZT_VehicleInfo.yearID);
	var c = document.getElementById('EZT-make');
	var d = document.getElementById(EZT_VehicleInfo.makeID);
	var e = document.getElementById('EZT-model');
	var f = document.getElementById(EZT_VehicleInfo.modelID);
	var g = document.getElementById('EZT-option');
	var h = document.getElementById(EZT_VehicleInfo.optionID);
	e.selectedIndex = 0;
	g.selectedIndex = 0;
	//f.style.display = 'none';
	//h.style.display = 'none';
	if (c != null && c.value != null && c.value.length > 0) {
		if (e != null) {
			var i = EZT_EncodeQuery(a.value);
			var j = EZT_EncodeQuery(c.value);
			if (i != document.ddlPromptWidth && j != document.ddlPromptMake) {
				var k = "year=" + i + "&make=" + j;
				EZT_InitjQuery("models", k)
			}
		}
	}
}
function EZT_FetchModels(d) {
	if (EZT_VehicleInfo != null) {
		var e = "EZT-model";
		var f = EZT_VehicleInfo.modelID;
		if (d.length > 0) {
			jQuery(document).ready(function($) {
				var b = "method=models&" + d + "&usejson=true&callback=?";
				var c = EZT_VehicleInfo.ezyUrl + "App_Services/VehicleLibrary.ashx?" + b;
				$.getJSON(c, function(a) {
					if (a != null && a.models != null) {
						EZT_PopulateList(f, e, a.models)
					}
				}
				)
			}
			)
		}
	}
}
function EZT_GetOptions() {
	var a = document.getElementById('EZT-year');
	var b = document.getElementById(EZT_VehicleInfo.yearID);
	var c = document.getElementById('EZT-make');
	var d = document.getElementById(EZT_VehicleInfo.makeID);
	var e = document.getElementById('EZT-model');
	var f = document.getElementById(EZT_VehicleInfo.modelID);
	var g = document.getElementById('EZT-option');
	var h = document.getElementById(EZT_VehicleInfo.optionID);
	g.selectedIndex = 0;
	//h.style.display = 'none';
	if (e != null && e.value != null && e.value.length > 0) {
		if (g != null) {
			var i = EZT_EncodeQuery(a.value);
			var j = EZT_EncodeQuery(c.value);
			var k = EZT_EncodeQuery(e.value);
			if (i != document.ddlPromptWidth && j != document.ddlPromptMake && k != document.ddlPromptOption) {
				var l = "year=" + i + "&make=" + j + "&model=" + k;
				EZT_InitjQuery("options", l)
			}
		}
	}
}
function EZT_FetchOptions(d) {
	if (EZT_VehicleInfo != null) {
		var e = "EZT-option";
		var f = EZT_VehicleInfo.optionID;
		if (d.length > 0) {
			jQuery(document).ready(function($) {
				var b = "method=options&" + d + "&usejson=true&callback=?";
				var c = EZT_VehicleInfo.ezyUrl + "App_Services/VehicleLibrary.ashx?" + b;
				$.getJSON(c, function(a) {
					if (a != null && a.options != null) {
						EZT_PopulateList(f, e, a.options)
					}
				}
				)
			}
			)
		}
	}
}
function EZT_PopulateList(a, b, c) {
	var d = document.getElementById(a);
	var e = document.getElementById(b);
	for (var f = e.options.length - 1; f > -1; f--) {
		e.options[f] = null
	}
	var g = new Option(document.ddlPrompt, '', true, true);
	if (EZT_SizeInfo != null) {
		if (a == EZT_SizeInfo.widthID) g = new Option(document.ddlPromptWidth, '', true, true); else if (a == EZT_SizeInfo.aspectID) g = new Option(document.ddlPromptAspect, '', true, true); else if (a == EZT_SizeInfo.rimID) g = new Option(document.ddlPromptRim, '', true, true)
	}
	if (EZT_VehicleInfo != null) {
		if (a == EZT_VehicleInfo.yearID) g = new Option(document.ddlPromptYear, '', true, true);
		if (a == EZT_VehicleInfo.makeID) g = new Option(document.ddlPromptMake, '', true, true);
		if (a == EZT_VehicleInfo.modelID) g = new Option(document.ddlPromptModel, '', true, true);
		if (a == EZT_VehicleInfo.optionID) g = new Option(document.ddlPromptOption, '', true, true)
	}
	e.options[0] = g;
	if (c.indexOf('<html>') < 0) {
		var h = c.split('||');
		if (h != null) {
			for (var i = 0; i < h.length; (i++)) {
				var j = h[i];
				if (j != null) {

					var k = j.split('|');
					var l = k[0];
					var m = l;
					if (k.length > 1) m = k[1];
					if (l.length > 0 && m.length > 0) {
						var n = new Option(l, m, false, false);
						e.options[e.length] = n
					}
				}
			}
		}
		d.style.display = 'block'
	}
}
function EZT_ShowSizeSubmit() {
	var a = document.getElementById(EZT_SizeInfo.submitID);
	var b = document.getElementById('EZT-rimsize');
	if (b.value != document.ddlPromptRim) {
		a.style.display = 'block'
	} //else {
		//a.style.display = 'none'
	//}
}
function EZT_ShowVehicleSubmit() {
	var a = document.getElementById(EZT_VehicleInfo.submitID);
	var b = document.getElementById('EZT-option');
	if (b.value != document.ddlPromptOption) {
		a.style.display = 'block'
	} //else {
		//a.style.display = 'none'
	//}
}
function EZT_OpenResults() {
	var a = '';
	var b = '';
	var c = document.getElementById('EZT-width');
	var d = document.getElementById('EZT-aspect');
	var e = document.getElementById('EZT-rimsize');
	var f = c.value;
	var g = d.value;
	var h = e.value;
	if (f != document.ddlPrompt && c != document.ddlPromptWidth && f.length > 0 && g != document.ddlPrompt && g != document.ddlPromptAspect && g.length > 0 && h != document.ddlPrompt && h != document.ddlPromptRim && h.length > 0) {
		b = "?width=" + f + "&aspect=" + g + "&rim=" + h + "&search=Search"
	}
	if (b.length > 0) {
		if (EZT_codedID.length > 0) {
			a = EZT_SizeInfo.formUrl + b + "&coded=" + EZT_codedID
		} else {
			a = EZT_SizeInfo.formUrl + b
		}
		window.open(a, EZT_SizeInfo.formTarget, "", "false")
	}
}
function EZT_OpenResultsV() {
	var a = '';
	var b = '';
	var c = document.getElementById('EZT-year');
	var d = document.getElementById('EZT-make');
	var e = document.getElementById('EZT-model');
	var f = document.getElementById('EZT-option');
	var g = EZT_EncodeQuery(c.value);
	var h = EZT_EncodeQuery(d.value);
	var i = EZT_EncodeQuery(e.value);
	var j = EZT_EncodeQuery(f.value);
	if (g != document.ddlPromptYear && g.length > 0 && h != document.ddlPromptMake && h.length > 0 && i != document.ddlPromptModel && i.length > 0 && j != document.ddlPromptOption && j.length > 0) {
		b = "?year=" + g + "&make=" + h + "&model=" + i + "&option=" + j + "&search=Search"
	}
	if (b.length > 0) {
		if (EZT_codedID.length > 0) {
			a = EZT_VehicleInfo.formUrl + b + "&coded=" + EZT_codedID
		} else {
			a = EZT_VehicleInfo.formUrl + b
		}
		window.open(a, EZT_VehicleInfo.formTarget, "", "false")
	}
}
function EZT_Append(a, b) {
	if (a == null) a = new Array();
	a[a.length] = b
}
function EZT_EncodeQuery(a) {
	a = a.replace(' ', '+');
	return a
}
function EZT_InitjQuery(a, b) {
	if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.7.1') {
		var c = document.createElement('script');
		c.setAttribute("type", "text/javascript");
		c.setAttribute("src", "http://code.jquery.com/jquery-latest.js");
		c.onload = scriptLoadHandler;
		c.onreadystatechange = function() {
			if (this.readyState == 'complete' || this.readyState == 'loaded') {
				scriptLoadHandler()
			}
		}
		;
		(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(c)
	} else {
		jQuery = window.jQuery;
		main()
	}
	function scriptLoadHandler() {
		jQuery = window.jQuery.noConflict(true);
		main()
	}
	function main() {
		if (a == "widths") {
			EZT_FetchWidths()
		} else if (a == "aspects") {
			EZT_FetchAspects(b)
		} else if (a == "rims") {
			EZT_FetchRims(b)
		} else if (a == "validate") {
			EZT_Validate()
		} else if (a == "years") {
			EZT_FetchYears()
		} else if (a == "makes") {
			EZT_FetchMakes(b)
		} else if (a == "models") {
			EZT_FetchModels(b)
		} else if (a == "options") {
			EZT_FetchOptions(b)
		}
	}
}
function EZT_SizeSearch(a, b, c, d, e) {
	this.widthID = a;
	this.aspectID = b;
	this.rimID = c;
	this.submitID = d;
	this.ezyUrl = e + '';
	if (e.charAt(e.length - 1) != '/') {
		this.ezyUrl = e + '/'
	}
	this.formUrl = this.ezyUrl + 'shoppingcart/tiresearch/';
	this.formTarget = '_blank'
}
;
EZT_SizeSearch.prototype.SetFormValues = function(a, b) {
	this.formUrl = a;
	this.formTarget = b
}
;
function EZT_VehicleSearch(a, b, c, d, e, f) {
	this.yearID = a;
	this.makeID = b;
	this.modelID = c;
	this.optionID = d;
	this.submitID = e;
	this.ezyUrl = f;
	this.ezyUrl = f + '';
	if (f.charAt(f.length - 1) != '/') {
		this.ezyUrl = f + '/'
	}
	this.formUrl = this.ezyUrl + 'shoppingcart/tiresearch/';
	this.formTarget = '_blank'
}
;
EZT_VehicleSearch.prototype.SetFormValues = function(a, b) {
	this.formUrl = a;
	this.formTarget = b
}
;
