
var level1=0;
var level2=0;
var level3=0;


function validate_form() {
	year = document.theform.year.options[document.theform.year.options.selectedIndex].value;
	if(level1 == 0 || level2 == 0 || level3 == 0 || year == 0) {
		alert("Please complete your selection");
		return false;
	} else {
		if(Ford_GM[m[level1].b[level2].y[level3].m] != null && year != -1) {
			window.location.href=m[level1].id + "_" + m[level1].b[level2].y[level3].v + "_" + year + ".php3";
		} else {
			window.location.href=m[level1].id + "_" + m[level1].b[level2].y[level3].v + ".php3";
		}
	}
	return false;
}

Ford_GM_Make = new Array();

function initialize(form,name) {
	thisform = eval("form."+name);
	clear_choice(thisform);
	for(i=1;i<m.length;i++) {
		thisform.options[i] = new Option(m[i].n,i);
		outer_loop:
		for(j=1;j<m[i].b.length;j++) {
			for(k=1;k<m[i].b[j].y.length;k++) {
				if(Ford_GM[m[i].b[j].y[k].m] != null) {
					Ford_GM_Make[m[i].n] = i;
					break outer_loop;
				}
			}
		}
	}
}

function change_body_type(form,name,id) {
	thisform = eval("form."+name);
	clear_choice(thisform);
	clear_choice(eval("form.model"));
	clear_choice(eval("form.year"));
	if(id == 0) {
		alert('Please select a Make');
		return;
	}
	level1=id;
	level2=0;
	level3=0;
	for(i=1;i<m[level1].b.length;i++) {
		thisform.options[i] = new Option(m[level1].b[i].b,i);			
	}
}


function change_model(form,name,id) {
	thisform = eval("form."+name);
	clear_choice(thisform);
	clear_choice(eval("form.year"));
	if(id == 0) {
		alert('Please select a Body Type');
		return;
	}
	level2=id;
	level3=0;
	for(i=1;i<m[level1].b[level2].y.length;i++) {
		thisform.options[i] = new Option(m[level1].b[level2].y[i].m,i);			
	}
}


function change_year(form,name,id) {
	thisform = eval("form."+name);
	clear_choice(thisform);
	level3=id;
	if(id == 0) {
		alert('Please select a Model');
		return;
	}
	if(Ford_GM_Make[m[level1].n] == null) {
		thisform.options[thisform.options.length] = new Option("All Years",-1);
	} else {
		start = m[level1].b[level2].y[id].s;
		end = m[level1].b[level2].y[id].e;
		while (start<=end) {
			thisform.options[thisform.options.length] = new Option(start,start);
			start++;
		}
		thisform.options[thisform.options.length] = new Option("All Previous Years",-1);
	}
}

function clear_choice(thisform) {
	for(i=thisform.options.length;i>0;i--) {
		thisform.options[i] = null;
	}
	thisform.options[0].selected=true;
}

function M(n,id) {
  this.n = n;
  this.id = id;
  this.b = new Array();
}

function B(b,id) {
	this.b = b;
	this.id = id;
	this.y = new Array();
}

function Y(m,v,s, e) {
   this.m = m;
   this.v = v;
   this.s = s;
   this.e = e;
}

m = new Array();

Ford_GM = new Array();
