/**
 * This class represents the search box and the search types

 */
var SearchBox = 
{
	linkBookName : document.getElementById("searchBookName"),
	linkAuthor	: document.getElementById("searchAuthor"),
	linkISBN : document.getElementById("searchISBN"),
	searchTypeField : document.getElementById("searchType"),
	
	/**
	 * Changes the type of the search that is performed
	 */
	changeSearchType : function(type)
	{
		this.searchTypeField.value = type;
		this.linkBookName.className = "search-tab";
		this.linkAuthor.className = "search-tab";
		this.linkISBN.className = "search-tab";
		if (type == "book")
		{
			this.linkBookName.className = "search-tab-selected";
		}
		else if (type == "author")
		{
			this.linkAuthor.className = "search-tab-selected";
		}
		else if (type == "isbn")
		{
			this.linkISBN.className = "search-tab-selected";
		}
	},
	
	submitHandler : function()
	{
		if (typeof(document.getElementById("searchTerm")) == "undefined" || document.getElementById("searchTerm").value == "") 
			return false;
		else
		{
			/*if (document.getElementById("searchType").value == "isbn")
			{
				var normalizedISBN = document.getElementById("searchTerm").value;
				normalizedISBN = normalizedISBN.replace(/-/g,"");
				normalizedISBN = normalizedISBN.replace(/ /g,"");
				document.getElementById("searchTerm").value = normalizedISBN;
			}*/
			return true;
		}
	},
		
	init : function(type)
	{
		if(!type || (type != "isbn" && type != "author" && type != "book"))
		{
			type = "book";
		}
		this.changeSearchType(type);
	}
}

