/*---------------------- Code for Make, Model navigation Start ----------------------------*/
// close the displayed layer for make field or model field by changing its css attrubute.
function closeResults_alert(obj_str) 
{
	if(document.getElementById(obj_str)!=null)
		document.getElementById(obj_str).style.display = "none";
//	document.getElementById(obj_str).style.visibility='hidden';
}
// show the layer for make field or model field.
// while showing one hide another one.
function displayResults_alert(obj_str) 
{
	if(obj_str=="make_op_alert")
	{
		closeResults_alert("model_op_alert")
		closeResults_alert("YearFrom_op_alert")
		closeResults_alert("YearTo_op_alert")
	}
	if(obj_str=="model_op_alert")
	{
		closeResults_alert("make_op_alert")
		closeResults_alert("YearFrom_op_alert")
		closeResults_alert("YearTo_op_alert")
	}
	if(obj_str=="YearFrom_op_alert")
	{
		closeResults_alert("make_op_alert")
		closeResults_alert("model_op_alert")
		closeResults_alert("YearTo_op_alert")
	}
	if(obj_str=="YearTo_op_alert")
	{
		closeResults_alert("make_op_alert")
		closeResults_alert("model_op_alert")
		closeResults_alert("YearFrom_op_alert")
	}
	document.getElementById(obj_str).style.display = "block";
}

// assign getKey_alert function to documents onkeyup event. getKey_alert() function will be called whenever user will release any keyboard key on document.
//document.onkeyup = getKey_alert;
document.onkeydown = getKey_alert;

// variable to hold the pressed keyboard key value.
var keyval=0;

/* the use of fun_alert variable is as follows:

1. one function named "getKey_alert" is assigned to "onkeyup" event of document object.
2. on "onkeyup" event of "make" textbox a function is called "searchMakes_alert".
3. page is calling "searchMakes_alert" function first and then the "getKey_alert" function.
4. we are getting keyboard key code in "getKey_alert" function.
5. so "fun_alert" variable is used to skip the execution of "searchMakes_alert" function at first time and then reexecute the "searchMakes_alert" function inside the getKey_alert function.
*/
var fun_alert=0;
// gets the keyboard key value that is pressed into "keyval" variable.
// call the searchMakes_alert functino if key is pressed on make textbox, and calls searchModels_alert function otherwise.
function getKey_alert(keyStroke)
{
	keyval=(keyStroke)? keyStroke.which : event.keyCode;
	if(fun_alert==1)
	{
		fun_alert=0;
		searchMakes_alert();
	}
	else if(fun_alert==2)
	{
		fun_alert=0;
		searchModels_alert();
	}
	else if(fun_alert==3)
	{
		fun_alert=0;
		return validateform_alert();
	}
	else if(fun_alert==4)
	{
		fun_alert=0;
		searchYearFrom_alert();
	}
	else if(fun_alert==5)
	{
		fun_alert=0;
		searchYearTo_alert();
	}
    return true;
}
// filters the make list according to text value of make field.
var makerow=0;
var makecol=0;
var modelrow=0;
var modelcol=0;
var YearFromrow=0;
var YearFromcol=0;
var YearTorow=0;
var YearTocol=0;

function searchMakes_alert()
{
	if(fun_alert==1)
		return;
	// if left arrow
	if(keyval==37)
	{
		keyval=0;
		no_highlight_make_alert();
		do
		{
			makecol--;
			if(makecol<0)
			{
				makecol=document.getElementById("make_tab_alert").rows[makerow].cells.length-1;
				makerow--;
				if(makerow<0)
				{
					makerow=document.getElementById("make_tab_alert").rows.length-1;
				}
			}
		}
		while(document.getElementById("make_tab_alert").rows[makerow].cells[makecol].innerHTML==" ")
		highlight_make_alert();
	}
	// if up arrow is pressed then select one item above to current item in make list box.
	if(keyval==38)
	{
		keyval=0;
		no_highlight_make_alert();
		do
		{
			makerow--;
			if(makerow<0)
			{
				makerow=document.getElementById("make_tab_alert").rows.length-1;
				makecol--;
				if(makecol<0)
				{
					makecol=document.getElementById("make_tab_alert").rows[makerow].cells.length-1;
				}
			}
		}
		while(document.getElementById("make_tab_alert").rows[makerow].cells[makecol].innerHTML==" ")
		highlight_make_alert();
	}
	// if right arrow
	if(keyval==39)
	{
		keyval=0;
		no_highlight_make_alert();
		do
		{
			makecol++;
			if(document.getElementById("make_tab_alert").rows[makerow].cells.length<=makecol)
			{
				makecol=0;
				makerow++;
				if(document.getElementById("make_tab_alert").rows.length<=makerow)
				{
					makerow=0;
				}
			}
		}
		while(document.getElementById("make_tab_alert").rows[makerow].cells[makecol].innerHTML==" ")
		highlight_make_alert();
	}
	// if down arrow is pressed then select one item below to current item in make list box.
	else if(keyval==40)
	{
		keyval=0;
		no_highlight_make_alert();
		do
		{
			makerow++;
			if(document.getElementById("make_tab_alert").rows.length<=makerow)
			{
				makerow=0;
				makecol++;
				if(document.getElementById("make_tab_alert").rows[makerow].cells.length<=makecol)
				{
					makecol=0;
				}
			}
		}
		while(document.getElementById("make_tab_alert").rows[makerow].cells[makecol].innerHTML==" ")
		highlight_make_alert();
	}
	// if tab key is pressed then get selected value of make list box into make text box.
	else if(keyval==9)// && document.add_listing.makelist_alert.selectedIndex>=0)
	{
		keyval=0;
		getmakevalue_alert(document.getElementById("make_tab_alert").rows[makerow].cells[makecol]);
		document.add_listing.model_txt.focus();
	}
	else if(keyval==13)// && document.add_listing.makelist_alert.selectedIndex>=0)
	{
		keyval=-1;
		getmakevalue_alert(document.getElementById("make_tab_alert").rows[makerow].cells[makecol]);
		document.add_listing.make_txt.focus();
	}
	else
	{
		// get the make textbox value.
		makevalue=document.add_listing.make_txt.value;
/*
		if(makevalue=="") //"Start typing your make")
		{
			document.getElementById("make_iframe_alert").style.width="0px";
			document.getElementById("make_iframe_alert").style.height="0px";
			document.getElementById("make_subop_alert").innerHTML = "<div class=\"inittext\">Start typing your make</div>";
			displayResults_alert("make_op_alert");
			return;
			//makevalue="";
		}
*/
		// show the make list box.
		displayResults_alert("make_op_alert");
		// put the filtered values of make from makelist_alert array into make list box.
		var makecounter=0;
		var trows=0;
		var tcols=0;
		var firstchar="";
		var initchar="";
		for(i=0;i<makelist_alert.length;i++)
		{
			makereg=new RegExp("^"+makevalue+".*", "i");
			if(makelist_alert[i].match(makereg))
			{
				initchar=makelist_alert[i].substring(0,1);
				if(firstchar!="" && firstchar!=initchar)
				{
					makecounter++;
				}
				makecounter++;
				firstchar=initchar;
			}
		}
		if(makecounter==0)
		{
			document.getElementById("make_iframe_alert").style.width="0px";
			document.getElementById("make_iframe_alert").style.height="0px";
			document.getElementById("make_subop_alert").innerHTML = "<div class=\"inittext\">No make found</div>";
			displayResults_alert("make_op_alert");
			return;
		}
		if(makecounter>50)
		{
			trows=Math.ceil(makecounter/5);
			tcols=5;
		}
		else
		{
			tcols=Math.ceil(makecounter/10);
			trows=10;
		}
		trows=Math.ceil(makecounter/tcols);
		var make2darray=new Array();
		var makeid2darray=new Array();
		for(i=0;i<trows;i++)
		{
			make2darray[i]=new Array();
			makeid2darray[i]=new Array();
		}
		var tr=0;
		var tc=-1;
		firstchar="";
		initchar="";
		for(i=0;i<makelist_alert.length;i++)
		{
			makereg=new RegExp("^"+makevalue+".*", "i");
			if(makelist_alert[i].match(makereg))
			{
				initchar=makelist_alert[i].substring(0,1);
				if(firstchar!="" && firstchar!=initchar)
				{
					if(tr!=0)
					{
						//tc++;
						make2darray[tr][tc]="";
						makeid2darray[tr][tc]="";
						tr++;
					}
					if(tr==trows)
					{
						tr=0;
					}
				}
				if(tr==0)
				{
					tc++;
				}
				make2darray[tr][tc]=makelist_alert[i];
				makeid2darray[tr][tc]=makeidlist_alert[i];
				firstchar=initchar;
				tr++;
				if(tr==trows)
				{
					tr=0;
				}
			}
		}
		
		var tabstr="<table id=\"make_tab_alert\">";
		for(i=0;i<trows;i++)
		{
			tabstr+= "<tr>";
			for(j=0;j<tcols;j++)
			{
				if(make2darray[i][j])
				{
					tabstr+="<td nowrap=\"nowrap\" class=\"layer_td\" id=\""+ makeid2darray[i][j] +"\" onclick=\"getmakevalue_alert(this)\" onmouseover=\"no_highlight_make_alert();getmakerow_col_alert(this);this.className='layer_td_hover'\" onmouseout=\"removemakerow_col_alert();this.className='layer_td'\">"+ make2darray[i][j] +"</td>";
				}
				else
				{
					tabstr+="<td> </td>";
				}
			}
			tabstr+= "</tr>";
		}
		tabstr+="</table>";
		document.getElementById("make_subop_alert").innerHTML = tabstr;
		highlight_make_alert();
		var dv=document.getElementById("make_subop_alert");
		document.getElementById("make_iframe_alert").style.width=dv.clientWidth;
		document.getElementById("make_iframe_alert").style.height=dv.clientHeight;
	}
}
function no_highlight_make_alert()
{
	if(document.getElementById("make_tab_alert").rows[makerow].cells[makecol])
		document.getElementById("make_tab_alert").rows[makerow].cells[makecol].className="layer_td";
}
function highlight_make_alert()
{
	if(document.getElementById("make_tab_alert").rows[makerow].cells[makecol])
		document.getElementById("make_tab_alert").rows[makerow].cells[makecol].className="layer_td_hover";
}

function getmakerow_col_alert(cur_cell)
{
	makerow=cur_cell.parentNode.rowIndex;
	makecol=cur_cell.cellIndex;
}
function removemakerow_col_alert()
{
	makerow=0;
	makecol=0;
}
function getmakevalue_alert(cur_cell)
{
	if(document.getElementById('make_tab_alert') && document.getElementById('make_tab_alert').rows[makerow].cells[makecol])
	{
		var cur_cell=document.getElementById('make_tab_alert').rows[makerow].cells[makecol];
		document.add_listing.make_txt.value=cur_cell.innerHTML;
		document.add_listing.make.value=cur_cell.id;
	}
	closeResults_alert("make_op_alert");
	document.add_listing.model_txt.value="";
	document.add_listing.model.value="";
}
function searchModels_alert()
{
	if(fun_alert==2)
		return;
	// if left arrow
	if(keyval==37)
	{
		keyval=0;
		no_highlight_model_alert();
		modelcol--;
		if(modelcol<0)
		{
			modelcol=document.getElementById("model_tab_alert").rows[modelrow].cells.length-1;
			modelrow--;
			if(modelrow<0)
			{
				modelrow=document.getElementById("model_tab_alert").rows.length-1;
			}
		}
		highlight_model_alert();
	}
	// if up arrow is pressed then select one item above to current item in make list box.
	if(keyval==38)
	{
		keyval=0;
		no_highlight_model_alert();
		modelrow--;
		if(modelrow<0)
		{
			modelrow=document.getElementById("model_tab_alert").rows.length-1;
			modelcol--;
			if(modelcol<0)
			{
				modelcol=document.getElementById("model_tab_alert").rows[modelrow].cells.length-1;
			}
		}
		highlight_model_alert();
	}
	// if right arrow
	if(keyval==39)
	{
		keyval=0;
		no_highlight_model_alert();
		modelcol++;
		if(document.getElementById("model_tab_alert").rows[modelrow].cells.length<=modelcol)
		{
			modelcol=0;
			modelrow++;
			if(document.getElementById("model_tab_alert").rows.length<=modelrow)
			{
				modelrow=0;
			}
		}
		highlight_model_alert();
	}
	// if down arrow is pressed then select one item below to current item in model list box.
	else if(keyval==40)
	{
		keyval=0;
		no_highlight_model_alert();
		modelrow++;
		if(document.getElementById("model_tab_alert").rows.length<=modelrow)
		{
			modelrow=0;
			modelcol++;
			if(document.getElementById("model_tab_alert").rows[modelrow].cells.length<=modelcol)
			{
				modelcol=0;
			}
		}
		highlight_model_alert();
	}
	// if tab key is pressed then get selected value of model list box into model text box.
	else if(keyval==9)// && document.add_listing.modellist_alert.selectedIndex>=0)
	{
		keyval=0;
		getmodelvalue_alert(document.getElementById("model_tab_alert").rows[modelrow].cells[modelcol]);
	}
	else if(keyval==13)// && document.add_listing.modellist_alert.selectedIndex>=0)
	{
		keyval=-1;
		getmodelvalue_alert(document.getElementById("model_tab_alert").rows[modelrow].cells[modelcol]);
		document.add_listing.model_txt.focus();
	}
	else
	{
		// get the model textbox value.
		modelvalue=document.add_listing.model_txt.value;
/*
		if(modelvalue=="")
		{
			document.getElementById("model_iframe_alert").style.width="0px";
			document.getElementById("model_iframe_alert").style.height="0px";
			document.getElementById("model_subop_alert").innerHTML = "<div class=\"inittext\">Start typing your model</div>";
			displayResults_alert("model_op_alert");
			return;
			//makevalue="";
		}
*/
		// show the model list box.
		displayResults_alert("model_op_alert");
		// put the filtered values of model from modellist_alert array into model list box.
		var modelcounter=0;
		var trows=0;
		var tcols=0;
		modelindex=document.add_listing.make.value;
		for(i=0;i<modellist_alert[modelindex].length;i++)
		{
			modelreg=new RegExp("^"+modelvalue+".*", "i");
			if(modellist_alert[modelindex][i].match(modelreg))
			{
				modelcounter++;
			}
		}
		if(modelcounter==0)
		{
			document.getElementById("model_iframe_alert").style.width="0px";
			document.getElementById("model_iframe_alert").style.height="0px";
			document.getElementById("model_subop_alert").innerHTML = "<div class=\"inittext\">No model found</div>";
			displayResults_alert("model_op_alert");
			return;
		}
		if(modelcounter>50)
		{
			trows=Math.ceil(modelcounter/5);
			tcols=5;
		}
		else
		{
			tcols=Math.ceil(modelcounter/10);
			trows=10;
		}
		trows=Math.ceil(modelcounter/tcols);
		var tr=0;
		var tc=0;
		var model2darray=new Array();
		var modelid2darray=new Array();
		for(i=0;i<trows;i++)
		{
			model2darray[i]=new Array();
			modelid2darray[i]=new Array();
		}
		var tr=0;
		var tc=-1;
		for(i=0;i<modellist_alert[modelindex].length;i++)
		{
			modelreg=new RegExp("^"+modelvalue+".*", "i");
			if(modellist_alert[modelindex][i].match(modelreg))
			{
				if(tr==0)
				{
					tc++;
				}
				model2darray[tr][tc]=modellist_alert[modelindex][i];
				modelid2darray[tr][tc]=modelidlist_alert[modelindex][i];
				tr++;
				if(tr==trows)
				{
					tr=0;
				}
			}
		}
		
		var tabstr="<table id=\"model_tab_alert\">";
		for(i=0;i<trows;i++)
		{
			tabstr+= "<tr>";
			for(j=0;j<tcols;j++)
			{
				if(model2darray[i][j])
				{
					tabstr+="<td nowrap=\"nowrap\" class=\"layer_td\" id=\""+ modelid2darray[i][j] +"\" onclick=\"getmodelvalue_alert(this)\" onmouseover=\"getmodelrow_col_alert(this);this.className='layer_td_hover'\" onmouseout=\"removemodelrow_col_alert();this.className='layer_td'\">"+ model2darray[i][j] +"</td>";
				}
			}
			tabstr+= "</tr>";
		}
		tabstr+="</table>";
		document.getElementById("model_subop_alert").innerHTML = tabstr;
		highlight_model_alert();
		var dv=document.getElementById("model_subop_alert");
		document.getElementById("model_iframe_alert").style.width=dv.clientWidth;
		document.getElementById("model_iframe_alert").style.height=dv.clientHeight;
	}
}
function no_highlight_model_alert()
{
	if(document.getElementById("model_tab_alert").rows[modelrow].cells[modelcol])
		document.getElementById("model_tab_alert").rows[modelrow].cells[modelcol].className="layer_td";
}
function highlight_model_alert()
{
	if(document.getElementById("model_tab_alert").rows[modelrow].cells[modelcol])
		document.getElementById("model_tab_alert").rows[modelrow].cells[modelcol].className="layer_td_hover";
}

function getmodelrow_col_alert(cur_cell)
{
	modelrow=cur_cell.parentNode.rowIndex;
	modelcol=cur_cell.cellIndex;
}
function removemodelrow_col_alert()
{
	modelrow=0;
	modelcol=0;
}
function getmodelvalue_alert(cur_cell)
{
	if(document.getElementById('model_tab_alert') && document.getElementById('model_tab_alert').rows[modelrow].cells[modelcol])
	{
		var cur_cell=document.getElementById('model_tab_alert').rows[modelrow].cells[modelcol];
		document.add_listing.model_txt.value=cur_cell.innerHTML;
		document.add_listing.model.value=cur_cell.id;
	}
	closeResults_alert("model_op_alert");
	fun_alert=0;
}
function searchYearFrom_alert()
{
	if(fun_alert==4)
		return;
	// if left arrow
	if(keyval==37)
	{
		keyval=0;
		no_highlight_YearFrom_alert();
		YearFromcol--;
		if(YearFromcol<0)
		{
			YearFromcol=document.getElementById("YearFrom_tab_alert").rows[YearFromrow].cells.length-1;
			YearFromrow--;
			if(YearFromrow<0)
			{
				YearFromrow=document.getElementById("YearFrom_tab_alert").rows.length-1;
			}
		}
		highlight_YearFrom_alert();
	}
	// if up arrow is pressed then select one item above to current item in YearFrom list box.
	if(keyval==38)
	{
		keyval=0;
		no_highlight_YearFrom_alert();
		YearFromrow--;
		if(YearFromrow<0)
		{
			YearFromrow=document.getElementById("YearFrom_tab_alert").rows.length-1;
			YearFromcol--;
			if(YearFromcol<0)
			{
				YearFromcol=document.getElementById("YearFrom_tab_alert").rows[YearFromrow].cells.length-1;
			}
		}
		highlight_YearFrom_alert();
	}
	// if right arrow
	if(keyval==39)
	{
		keyval=0;
		no_highlight_YearFrom_alert();
		YearFromcol++;
		if(document.getElementById("YearFrom_tab_alert").rows[YearFromrow].cells.length<=YearFromcol)
		{
			YearFromcol=0;
			YearFromrow++;
			if(document.getElementById("YearFrom_tab_alert").rows.length<=YearFromrow)
			{
				YearFromrow=0;
			}
		}
		highlight_YearFrom_alert();
	}
	// if down arrow is pressed then select one item below to current item in YearFrom list box.
	else if(keyval==40)
	{
		keyval=0;
		no_highlight_YearFrom_alert();
		YearFromrow++;
		if(document.getElementById("YearFrom_tab_alert").rows.length<=YearFromrow)
		{
			YearFromrow=0;
			YearFromcol++;
			if(document.getElementById("YearFrom_tab_alert").rows[YearFromrow].cells.length<=YearFromcol)
			{
				YearFromcol=0;
			}
		}
		highlight_YearFrom_alert();
	}
	// if tab key is pressed then get selected value of YearFrom list box into YearFrom text box.
	else if(keyval==9)// && document.add_listing.YearFromlist_alert.selectedIndex>=0)
	{
		keyval=0;
		if(document.getElementById("YearFrom_tab_alert")!=null)
			getYearFromvalue_alert(document.getElementById("YearFrom_tab_alert").rows[YearFromrow].cells[YearFromcol]);
		else
			searchYearFrom_alert();
	}
	else if(keyval==13)// && document.add_listing.YearFromlist_alert.selectedIndex>=0)
	{
		keyval=-1;
		getYearFromvalue_alert(document.getElementById("YearFrom_tab_alert").rows[YearFromrow].cells[YearFromcol]);
		document.add_listing.year_from.focus();
	}
	else
	{
		// get the YearFrom textbox value.
		YearFromvalue=document.add_listing.year_from.value;
		// show the YearFrom list box.
		displayResults_alert("YearFrom_op_alert");
		var makeid=0;
		var modelid=0;
		if(document.add_listing.make.value!="")
		{
			makeid = document.add_listing.make.value;
		}
		if(document.add_listing.model.value!="")
		{
			modelid = document.add_listing.model.value;
		}
		var year_list;
		/*
		if(makeid!=0 && modelid!=0)
		{
			year_list=yearlist[makeid][modelid];
		}
		else
		{
			year_list=YearFromlist_alert;
		}
		*/
		year_list=YearFromlist_alert;
		// put the filtered values of YearFrom from YearFromlist_alert array into YearFrom list box.
		var YearFromcounter=0;
		var trows=0;
		var tcols=0;
		for(i=0;i<year_list.length;i++)
		{
			YearFromreg=new RegExp("^"+YearFromvalue+".*", "i");
			if(year_list[i].toString().match(YearFromreg))
			{
				YearFromcounter++;
			}
		}
		if(YearFromcounter>50)
		{
			trows=Math.ceil(YearFromcounter/5);
			tcols=5;
		}
		else
		{
			tcols=Math.ceil(YearFromcounter/10);
			trows=10;
		}
		trows=Math.ceil(YearFromcounter/tcols);
		var YearFrom2darray=new Array();
		for(i=0;i<trows;i++)
		{
			YearFrom2darray[i]=new Array();
		}
		var tr=0;
		var tc=-1;
		for(i=0;i<year_list.length;i++)
		{
			YearFromreg=new RegExp("^"+YearFromvalue+".*", "i");
			if(year_list[i].toString().match(YearFromreg))
			{
				if(tr==0)
				{
					tc++;
				}
				YearFrom2darray[tr][tc]=year_list[i];
				tr++;
				if(tr==trows)
				{
					tr=0;
				}
			}
		}
		
		var tabstr="<table id=\"YearFrom_tab_alert\">";
		for(i=0;i<trows;i++)
		{
			tabstr+= "<tr>";
			for(j=0;j<tcols;j++)
			{
				if(YearFrom2darray[i][j])
				{
					tabstr+="<td nowrap=\"nowrap\" class=\"layer_td\" onclick=\"getYearFromvalue_alert(this)\" onmouseover=\"no_highlight_YearFrom_alert();getYearFromrow_col_alert(this);this.className='layer_td_hover'\" onmouseout=\"removeYearFromrow_col_alert();this.className='layer_td'\">"+ YearFrom2darray[i][j] +"</td>";
					//  id=\""+ YearFromid2darray[i][j] +"\"
				}
			}
			tabstr+= "</tr>";
		}
		tabstr+="</table>";
		document.getElementById("YearFrom_subop_alert").innerHTML = tabstr;
		highlight_YearFrom_alert();
		var dv=document.getElementById("YearFrom_subop_alert");
		document.getElementById("YearFrom_iframe_alert").style.width=dv.clientWidth;
		document.getElementById("YearFrom_iframe_alert").style.height=dv.clientHeight;
		//YearFromrow=-1;
		//YearFromcol=-1;
	}
}
function no_highlight_YearFrom_alert()
{
	if(document.getElementById("YearFrom_tab_alert").rows[YearFromrow].cells[YearFromcol])
		document.getElementById("YearFrom_tab_alert").rows[YearFromrow].cells[YearFromcol].className="layer_td";
}
function highlight_YearFrom_alert()
{
	if(document.getElementById("YearFrom_tab_alert").rows[YearFromrow].cells[YearFromcol])
		document.getElementById("YearFrom_tab_alert").rows[YearFromrow].cells[YearFromcol].className="layer_td_hover";
}

function getYearFromrow_col_alert(cur_cell)
{
	YearFromrow=cur_cell.parentNode.rowIndex;
	YearFromcol=cur_cell.cellIndex;
}
function removeYearFromrow_col_alert()
{
	YearFromrow=0;
	YearFromcol=0;
}
function getYearFromvalue_alert()
{
	if(document.getElementById('YearFrom_tab_alert').rows.length!=0)
	{
		var cur_cell=document.getElementById('YearFrom_tab_alert').rows[YearFromrow].cells[YearFromcol];
		document.add_listing.year_from.value=cur_cell.innerHTML;
	}
	closeResults_alert("YearFrom_op_alert");
	var yfromval=document.add_listing.year_from.value;
	var d = new Date();
	var cur_year=d.getFullYear() + 1;
	if(yfromval=="")
		return;
	if(!yfromval.match("[0-9]+"))
	{
		alert("Please provide year between 1900 and "+cur_year.toString()+".");
		document.add_listing.year_from.value="";
		document.add_listing.year_from.focus();
		return;
	}

	if(yfromval.toString().length==2)
	{
		var newval=cur_year-(cur_year%100) + parseFloat(yfromval);
		if(newval>cur_year)
			newval=cur_year-100-(cur_year%100) + parseFloat(yfromval);
		document.add_listing.year_from.value=newval;
	}
	else if(yfromval<1900 || yfromval>cur_year)
	{
		alert("Please provide year between 1900 and "+cur_year.toString()+".");
		document.add_listing.year_from.value="";
		document.add_listing.year_from.focus();
	}
}
//--------------------------------------------------------------------------------------------
function searchYearTo_alert()
{
	if(fun_alert==5)
		return;
	// if left arrow
	if(keyval==37)
	{
		keyval=0;
		no_highlight_YearTo_alert();
		YearTocol--;
		if(YearTocol<0)
		{
			YearTocol=document.getElementById("YearTo_tab_alert").rows[YearTorow].cells.length-1;
			YearTorow--;
			if(YearTorow<0)
			{
				YearTorow=document.getElementById("YearTo_tab_alert").rows.length-1;
			}
		}
		highlight_YearTo_alert();
	}
	// if up arrow is pressed then select one item above to current item in YearTo list box.
	if(keyval==38)
	{
		keyval=0;
		no_highlight_YearTo_alert();
		YearTorow--;
		if(YearTorow<0)
		{
			YearTorow=document.getElementById("YearTo_tab_alert").rows.length-1;
			YearTocol--;
			if(YearTocol<0)
			{
				YearTocol=document.getElementById("YearTo_tab_alert").rows[YearTorow].cells.length-1;
			}
		}
		highlight_YearTo_alert();
	}
	// if right arrow
	if(keyval==39)
	{
		keyval=0;
		no_highlight_YearTo_alert();
		YearTocol++;
		if(document.getElementById("YearTo_tab_alert").rows[YearTorow].cells.length<=YearTocol)
		{
			YearTocol=0;
			YearTorow++;
			if(document.getElementById("YearTo_tab_alert").rows.length<=YearTorow)
			{
				YearTorow=0;
			}
		}
		highlight_YearTo_alert();
	}
	// if down arrow is pressed then select one item below to current item in YearTo list box.
	else if(keyval==40)
	{
		keyval=0;
		no_highlight_YearTo_alert();
		YearTorow++;
		if(document.getElementById("YearTo_tab_alert").rows.length<=YearTorow)
		{
			YearTorow=0;
			YearTocol++;
			if(document.getElementById("YearTo_tab_alert").rows[YearTorow].cells.length<=YearTocol)
			{
				YearTocol=0;
			}
		}
		highlight_YearTo_alert();
	}
	// if tab key is pressed then get selected value of YearTo list box into YearTo text box.
	else if(keyval==9)// && document.add_listing.YearTolist.selectedIndex>=0)
	{
		keyval=0;
		if(document.getElementById("YearTo_tab_alert")!=null)
			getYearTovalue_alert(document.getElementById("YearTo_tab_alert").rows[YearTorow].cells[YearTocol]);
		else
			searchYearTo_alert();
	}
	else if(keyval==13)// && document.add_listing.YearTolist.selectedIndex>=0)
	{
		keyval=-1;
		getYearTovalue_alert(document.getElementById("YearTo_tab_alert").rows[YearTorow].cells[YearTocol]);
		document.add_listing.year_to.focus();
	}
	else
	{
		// get the YearTo textbox value.
		YearTovalue=document.add_listing.year_to.value;
		// show the YearTo list box.
		displayResults_alert("YearTo_op_alert");
		// put the filtered values of YearTo from YearTolist array into YearTo list box.
		var makeid=0;
		var modelid=0;
		if(document.add_listing.make.value!="")
		{
			makeid = document.add_listing.make.value;
		}
		if(document.add_listing.model.value!="")
		{
			modelid = document.add_listing.model.value;
		}
		var year_list;
		/*
		if(makeid!=0 && modelid!=0)
		{
			year_list=yearlist[makeid][modelid];
		}
		else
		{
			year_list=YearFromlist_alert;
		}
		*/
		year_list=YearFromlist_alert;

		var YearTocounter=0;
		var trows=0;
		var tcols=0;
		var yfromvalue=document.add_listing.year_from.value;
		for(i=0;i<year_list.length;i++)
		{
			YearToreg=new RegExp("^"+YearTovalue+".*", "i");
			if(year_list[i].toString().match(YearToreg) && year_list[i]>= parseInt(yfromvalue))
			{
				YearTocounter++;
			}
		}
		if(YearTocounter>50)
		{
			trows=Math.ceil(YearTocounter/5);
			tcols=5;
		}
		else
		{
			tcols=Math.ceil(YearTocounter/10);
			trows=10;
		}
		trows=Math.ceil(YearTocounter/tcols);
		var YearTo2darray=new Array();
		for(i=0;i<trows;i++)
		{
			YearTo2darray[i]=new Array();
		}
		var tr=0;
		var tc=-1;
		for(i=0;i<year_list.length;i++)
		{
			YearToreg=new RegExp("^"+YearTovalue+".*", "i");
			if(year_list[i].toString().match(YearToreg) && year_list[i]>= parseInt(yfromvalue))
			{
				if(tr==0)
				{
					tc++;
				}
				YearTo2darray[tr][tc]=year_list[i];
				tr++;
				if(tr==trows)
				{
					tr=0;
				}
			}
		}
		
		var tabstr="<table id=\"YearTo_tab_alert\">";
		for(i=0;i<trows;i++)
		{
			tabstr+= "<tr>";
			for(j=0;j<tcols;j++)
			{
				if(YearTo2darray[i][j])
				{
					tabstr+="<td nowrap=\"nowrap\" class=\"layer_td\" onclick=\"getYearTovalue_alert(this)\" onmouseover=\"no_highlight_YearTo_alert();getYearTorow_col_alert(this);this.className='layer_td_hover'\" onmouseout=\"removeYearTorow_col_alert();this.className='layer_td'\">"+ YearTo2darray[i][j] +"</td>";
					//  id=\""+ YearToid2darray[i][j] +"\"
				}
			}
			tabstr+= "</tr>";
		}
		tabstr+="</table>";
		document.getElementById("YearTo_subop_alert").innerHTML = tabstr;
		highlight_YearTo_alert();
		var dv=document.getElementById("YearTo_subop_alert");
		document.getElementById("YearTo_iframe_alert").style.width=dv.clientWidth;
		document.getElementById("YearTo_iframe_alert").style.height=dv.clientHeight;
	}
}
function no_highlight_YearTo_alert()
{
	if(document.getElementById("YearTo_tab_alert").rows[YearTorow].cells[YearTocol])
		document.getElementById("YearTo_tab_alert").rows[YearTorow].cells[YearTocol].className="layer_td";
}
function highlight_YearTo_alert()
{
	if(document.getElementById("YearTo_tab_alert").rows[YearTorow].cells[YearTocol])
		document.getElementById("YearTo_tab_alert").rows[YearTorow].cells[YearTocol].className="layer_td_hover";
}

function getYearTorow_col_alert(cur_cell)
{
	YearTorow=cur_cell.parentNode.rowIndex;
	YearTocol=cur_cell.cellIndex;
}
function removeYearTorow_col_alert()
{
	YearTorow=0;
	YearTocol=0;
}
function getYearTovalue_alert()
{
	if(document.getElementById('YearTo_tab_alert').rows.length!=0)
	{
		var cur_cell=document.getElementById('YearTo_tab_alert').rows[YearTorow].cells[YearTocol];
		document.add_listing.year_to.value=cur_cell.innerHTML;
	}
	closeResults_alert("YearTo_op_alert");
	var ytoval=document.add_listing.year_to.value;
	var d = new Date();
	var cur_year=d.getFullYear() + 1;
	if(ytoval=="")
		return;
	if(!ytoval.match("[0-9]+"))
	{
		alert("Please provide year between 1900 and "+cur_year.toString()+".");
		document.add_listing.year_to.value="";
		document.add_listing.year_to.focus();
		return;
	}
		
	if(ytoval.toString().length==2)
	{
		newval=cur_year-(cur_year%100) + parseFloat(ytoval);
		if(newval>cur_year)
			newval=cur_year-100-(cur_year%100) + parseFloat(ytoval);
		document.add_listing.year_to.value=newval;
	}
	else if(ytoval<1900 || ytoval>cur_year)
	{
		alert("Please provide year between 1900 and "+cur_year.toString()+".");
		document.add_listing.year_to.value="";
		document.add_listing.year_to.focus();
		return false;
	}
}

//--------------------------------------------------------------------------------------------
function getyearfrom_alert()
{
	var yfromval=document.add_listing.year_from.value;
	var d = new Date();
	var cur_year=d.getFullYear();
	if(yfromval=="")
		return;
	if(!yfromval.match("[0-9]+"))
	{
		alert("Please provide year between 1900 and "+cur_year.toString()+".");
		document.add_listing.year_from.value="";
		document.add_listing.year_from.focus();
		return;
	}

	if(yfromval.toString().length==2)
	{
		var newval=cur_year-(cur_year%100) + parseFloat(yfromval);
		if(newval>cur_year)
			newval=cur_year-100-(cur_year%100) + parseFloat(yfromval);
		document.add_listing.year_from.value=newval;
	}
	else if(yfromval<1900 || yfromval>cur_year)
	{
		alert("Please provide year between 1900 and "+cur_year.toString()+".");
		document.add_listing.year_from.value="";
		document.add_listing.year_from.focus();
	}
}

function getyearto_alert()
{
	var ytoval=document.add_listing.year_to.value;
	var d = new Date();
	var cur_year=d.getFullYear();
	if(ytoval=="")
		return;
	if(!ytoval.match("[0-9]+"))
	{
		alert("Please provide year between 1900 and "+cur_year.toString()+".");
		document.add_listing.year_to.value="";
		document.add_listing.year_to.focus();
		return;
	}
		
	if(ytoval.toString().length==2)
	{
		newval=cur_year-(cur_year%100) + parseFloat(ytoval);
		if(newval>cur_year)
			newval=cur_year-100-(cur_year%100) + parseFloat(ytoval);
		document.add_listing.year_to.value=newval;
	}
	else if(ytoval<1900 || ytoval>cur_year)
	{
		alert("Please provide year between 1900 and "+cur_year.toString()+".");
		document.add_listing.year_to.value="";
		document.add_listing.year_to.focus();
		return false;
	}
}

function hidemakemodel_alert()
{
	closeResults_alert("make_op_alert");
	closeResults_alert("model_op_alert");
}
// on enter key press check form validation
// if enter kay is pressed on make or model list to choose item then do accordingly.
// otherwise post the form.
function validateform_alert()
{
	if(document.getElementById("make_op_alert").style.display == "block")
	{
		//getmakevalue_alert(document.getElementById("make_tab_alert").rows[makerow].cells[makecol]);
		//document.add_listing.make_txt.focus();
		return false;
	}
	else if(document.getElementById("model_op_alert").style.display == "block")
	{
		//getmodelvalue_alert(document.getElementById("model_tab_alert").rows[modelrow].cells[modelcol]);
		//document.add_listing.model_txt.focus();
		return false;
	}
	else if(document.getElementById("YearFrom_op_alert").style.display == "block")
	{
		//getmakevalue_alert(document.getElementById("make_tab_alert").rows[makerow].cells[makecol]);
		//document.add_listing.make_txt.focus();
		return false;
	}
	else if(document.getElementById("YearTo_op_alert").style.display == "block")
	{
		//getmodelvalue_alert(document.getElementById("model_tab_alert").rows[modelrow].cells[modelcol]);
		//document.add_listing.model_txt.focus();
		return false;
	}
	else
		return true;
/*
	if(fun_alert==3)
	{
		return false;
	}
	if(keyval==-1)
	{
		keyval=0;
		return false;
	}
	else
	{
		document.add_listing.submit();
	}
*/
}
/*---------------------- Code for Make, Model navigation End ----------------------------*/
