/**
 * 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
		{
			var keyword=document.getElementById("searchTerm").value;
//			alert(keyword);
//			var form = document.getElementById("searchFormSubmit");
			var url="/pustak/books/keyword/"+keyword+"-books-1";
//			form.submit();
			xmlHttp = new XMLHttpRequest(); 
	//	    xmlHttp.onreadystatechange = ProcessRequest;
		    xmlHttp.open( "GET", url, true );
		    xmlHttp.send( null );

			//form.submit();
			/*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);
	}
}


