var before;
var after;

function makeChange(refresh)
{
	if(document.automotive.make[document.automotive.make.selectedIndex].value=='select')
	{
		var k=0;
		document.automotive.year.options.length = maxYear - minYear + 2;  //Code added on 11/07/00
		document.automotive.year.options[k].text='Year';
		document.automotive.year.options[k].value='select';
		k++;
		
		for(var j=maxYear; j>=minYear; j--)
		{
			document.automotive.year.options[k].value=j;
			document.automotive.year.options[k].text=j;
			k++;
		} 
	}
	else
	{
		var found=false;
		if(document.automotive.year[document.automotive.year.selectedIndex].value!='select')
			var savedValue=document.automotive.year[document.automotive.year.selectedIndex].text;
		if(document.automotive.make[document.automotive.make.selectedIndex].value!='select')
		{
			var i=0;
			while(data[i][0]!=document.automotive.make[document.automotive.make.selectedIndex].value)
				i++;
		}
		var k=0;

		k++;
		var backlengtharr = 0;
		var backwardsarr = new Array();

		//Code added on 11/07/00

		var lastvalue=data[i][0];
		var temp = i;
		while(temp<lengtharr &&  data[temp][0]==lastvalue)
		{
			

			for(var j=data[temp][2]; j>=data[temp][1]; j--)
			{
				
				k++;
	
			}
			lastvalue=data[temp][0];
			temp++;
		} 
		
		//end Code Added

		document.automotive.year.options.length = k;
		document.automotive.year.options[0].text='Year';
		document.automotive.year.options[0].value='select';

		var lastvalue=data[i][0];
		var k =1;

		while(i<lengtharr &&  data[i][0]==lastvalue)
		{
			

			for(var j=data[i][2]; j>=data[i][1]; j--)
			{
				backwardsarr[backlengtharr++]=j;
				document.automotive.year.options[k].text=j;
				document.automotive.year.options[k].value=j;
				k++;
				if(j==savedValue)
				{
					document.automotive.year.selectedIndex=k-1;
					found=true;
				}
			}
			lastvalue=data[i][0];
			i++;
		} 


		//The following Code commented on 11/07/00
		/*for(var i=k; i<=maxYear-minYear+1; i++)
		{
			document.automotive.year.options[i].value='';
			document.automotive.year.options[i].text='';
		}*/

		if(!found)
			document.automotive.year.selectedIndex=0;
	}	
	if(refresh)
		checkforrefresh();
}
function yearChange(refresh)
{
	var makes=new Array();
	var k=0;
	var savedValue=document.automotive.make[document.automotive.make.selectedIndex].text;
	

	var i=0;
	while( i<lengtharr )
	{
		if(document.automotive.year[document.automotive.year.selectedIndex].value!='select')
		{
			if((data[i][1] <= document.automotive.year[document.automotive.year.selectedIndex].value)  && (data[i][2] >= document.automotive.year[document.automotive.year.selectedIndex].value))
			{
				makes[k]=data[i][0];
				k++;
		
			//Code added on 11/07/00
			var lastvalue=data[i][0];
			while(i<lengtharr && lastvalue==data[i][0])
			  {
		           //alert("Coming into while and model = " + data[i][0]);
			   i++;
			   }
			//end Code Added

			}
			else
			++i;
		}
		else
		{
			makes[k]=data[i][0];
			k++;

		//Code added on 11/07/00
		var lastvalue=data[i][0];
		while(i<lengtharr && lastvalue==data[i][0])
		  {
	           //alert("Coming into while and model = " + data[i][0]);
		   i++;
		   }
		//end Code Added


		}	



	}

	var found=false;
	var j=0;

	document.automotive.make.options[j].value='select';
	document.automotive.make.options[j].text='Make';

	j++;


	document.automotive.make.options.length = k+1;

	for(var i=0; i<k; i++)
	{
		//alert("testing="+j);
		document.automotive.make.options[j].value=makes[i];
		document.automotive.make.options[j].text=makes[i];
		//alert('successful');
		if(makes[i]==savedValue)
		{
			document.automotive.make.selectedIndex=j;
			found=true;
		}
		j++;
	}
	if(!found)
		document.automotive.make.selectedIndex=0;

	//The following Code Commented on 11/07/00
	/*for(var i=j; i<=numMakes; i++)
	{
		document.automotive.make.options[i].value='';
		document.automotive.make.options[i].text=''
	}*/
	if(refresh)
		checkforrefresh();


}

function setMakes()
{
	var k=0;
	document.automotive.make.options[k].value='select';
	document.automotive.make.options[k].text='Make';
	k++;	
	var j=0;
	while(j<lengtharr)
	{
		document.automotive.make.options[k].value=data[j][0];
		document.automotive.make.options[k].text=data[j][0];
		k++;
		var lastvalue=data[j][0];
		while(j<lengtharr && lastvalue==data[j][0])
		{
			j++;
		}
	}
	document.automotive.year.options[0].value='select';
	document.automotive.year.options[0].text= 'Year';
	var i=1;
	var currYear=maxYear;
	while(currYear >= minYear)
	{
		document.automotive.year.options[i].value=currYear;
		document.automotive.year.options[i].text=currYear;
		i++;
		currYear--;
	}
	
	if(execute)
	{
		var i=0;
		while(document.automotive.year[i].value!=currentYear)
			i++;
		document.automotive.year.selectedIndex=i;
		yearChange(false);
		
		var i=0;
		while(document.automotive.make[i].value!=currentMake)
			i++;
		document.automotive.make.selectedIndex=i;
		makeChange(false);
	}
	else
	{
		document.automotive.make.selectedIndex=0;
		document.automotive.year.selectedIndex=0;
	}
	/*if(navigator.appName=="Microsoft Internet Explorer" && parseInt(navigator.appVersion)==4)
	{
		document.automotive.year.style.pixelWidth = 200;
		document.automotive.make.style.pixelWidth = 200;
		document.automotive.model.style.pixelWidth = 200;
	}*/
	
}
function checkforrefresh()
{
	if(document.automotive.year.selectedIndex!=0 && document.automotive.make.selectedIndex!=0)
	{
		document.automotive.model.selectedIndex=0;
		document.automotive.model.options[0].value="";
		//document.automotive.pagename.value="/autowizard/Dispatcher?REQUEST=MODEL_LIST";
		document.automotive.action="/LightProducts/Dispatcher?REQUEST=NIGHTHAWKSEARCH&CHANNEL=Consumer&APPLICATION=Automotive&GETMODELS=true";
		//document.automotive.target = window.self;
		//alert(document.automotive.target);
		document.automotive.model.options[0].text="Retrieving models...";
		document.automotive.submit(); 
	}	
}
function nextPage()
{
	if(document.automotive.model.selectedIndex!=0 && document.automotive.year.selectedIndex!=0 && document.automotive.make.selectedIndex!=0)
	{
		var url = "AppLogic+FTContentServer?pagename=GE_Lighting/Wizards/Automotive/results&year=" + escape(document.automotive.year[document.automotive.year.selectedIndex].value) + "&make=" + escape(document.automotive.make[document.automotive.make.selectedIndex].value) + "&model=" + escape(document.automotive.model[document.automotive.model.selectedIndex].value);
		window.open(url,"autoresults",'resizable=yes,scrollbars=yes,width=495,height=500,screenX=20,screenY=20,top=40,left=40');
	}
}

