
/****************************************************************
Functions: initMoveSearchButton() + moveSearchButton()
Purpose: Used on pages where multiple search functionalities exist
for instance the index.html page where you can search by "car make"
or "state".  Instead of having to duplicate the search submit button
so that it would appear next to each drop down list, this function
simply moves it next to the appropriate drop down when moused over
/***************************************************************/
function initMoveSearchButton()
{
	if (document.getElementsByTagName)
	{
		if (document.getElementsByTagName("body")[0])
		{
			var pageBody = 	document.getElementsByTagName("body")[0];
			var searchList = getElementsByClassName(pageBody, "ul", "search");			
			if (searchList.length > 0)
			{
				for (i=0;i<searchList.length;i++)
				{
					var searchListItems = searchList[i].getElementsByTagName("li");
					if (searchListItems.length > 0)
					{
						for (j=0;j<searchListItems.length;j++)
						{
							searchListItems[j].onmouseover = function(){
								moveSearchButton(this);
							};
						}
					}
				}
			}
		}		
	}	
}
function moveSearchButton(moveToThis)
{
	if (moveToThis.parentNode)
	{
		var parentList = moveToThis.parentNode;
		/* loops through siblings to find sibling that contains button currently */
		var siblings = parentList.getElementsByTagName("li");
		var btnFound = false;
		var btn = document.createElement("input");
		if (siblings.length > 0)
		{
			for (i=0;i<siblings.length;i++)
			{
				var inputs = siblings[i].getElementsByTagName("input");
				if (inputs.length > 0)
				{
					for (j=0;j<inputs.length;j++)
					{
						var curInput = inputs[j];
						if (curInput.getAttribute("type")=="submit")
						{
							btnFound = true;
							btn = curInput; //copies current element to temp one
							curInput.parentNode.removeChild(curInput);
						}
						if (btnFound)
						{
							//used to exit existing loop
							j = inputs.length;							
						}
					}
					if (btnFound)
					{
						//used to exit existing loop
						i = siblings.length;							
					}
				}
			}
			moveToThis.appendChild(btn);
		}
	}
}

/****************************************************************/
/* function: makeMastheadLink()
/* This function adds an onclick event to the masthead element
/* on the document.  This is done via an onclick event instead of
/* a using a regular <a> tag because of the css-hack/workaround
/* where the text-indent is so to a large negative value.  Because
/* the text is being forced off the screen, the <a> tag would be
/* ineffective.
/****************************************************************/
function makeMastheadLink()
{
	if (document.getElementById)
	{
		if(document.getElementById("masthead"))
		{
			var masthead = document.getElementById("masthead");
			if (document.location.href != "http://www.ausedcar.com/")			
			{
				masthead.onclick = function(){
					document.location.href = "/";
				};
				masthead.style.cursor = "pointer";
			}
		}
	}
}
/****************************************************************/
/* function styleSearchResults()
/* function adds alternating class names "listData1", and 
/* "listData2" to anything table w/ class name = "searchResults".
/* This function also adds a onmouseover event to each row to
/* highlight the row.  This is done by appending the style
/* "listData3" to the existing class name for each row. An 
/* onmouseout event is also added to each which removes this 
/* "listData3" string from the class name thus reverting it back
/* to its original alternating row color.
/****************************************************************/
function styleSearchResults()
{
	if (document.getElementById && getElementsByClassName && document.getElementsByTagName)
	{
		var searchResults = getElementsByClassName(document, "table", "searchResults")
		if (searchResults.length > 0)
		{
			for (i=0;i<searchResults.length;i++)
			{
				var tbody = searchResults[i].getElementsByTagName("tbody");
				if (tbody.length > 0)
				{
					for(j=0;j<tbody.length;j++)
					{
						var rows = tbody[j].getElementsByTagName("tr");
						if (rows.length > 0)
						{
							for(k=0;k<rows.length;k++)
							{
								if ((k%2)==0)
								{
									rows[k].className = "listData1";	
								}
								else
								{
									rows[k].className = "listData2";	
								}
								/* highlights rows */
								rows[k].onmouseover = function(){
									this.className += " listData3";
								};
								/*unhighlights row*/
								rows[k].onmouseout = function(){
									this.className = this.className.replace(" listData3", "");
								};
							}
							
						}	
					}					
				}	
			}			
		}
	}
}
/****************************************************************/
/* Makes all necessary function calls
/****************************************************************/
addLoadEvent(makeMastheadLink);
//addLoadEvent(initMoveSearchButton);
addLoadEvent(styleSearchResults);