
if(typeof String.prototype.trim !== 'function') 
{   
	String.prototype.trim = function() 
	{     
		return this.replace(/^\s+|\s+$/g, '');    
	};
} 
function isbnValidation()
{
	var currentValue = document.getElementById("book_isbn").value.trim();
	isbnTextLimit(currentValue);
	isbnNumbersLimit(currentValue);
}
//limit the length of the string to 13 characters
function isbnTextLimit(currentValue)
{
	/*var maxLength = 13;
	if(currentValue.length > maxLength)
	{
		currentValue = currentValue.substring(0,maxLength);
		document.getElementById("book_isbn").value = currentValue;
	}*/
	return;
}
//limit the input to digits only
function isbnNumbersLimit(currentValue)
{
	/*if(isNaN(currentValue))
	{
		document.getElementById("book_isbn").value = currentValue.substring(0,currentValue.length-1);

	}*/
	return;
}
//invoked when the Search! button is clicked
function onClickSearch()
{	
	
	var isbn = document.getElementById("book_isbn").value.trim();
	var title = document.getElementById("book_title").value.trim();
	var author = document.getElementById("book_author").value.trim();
	var publisher = document.getElementById("book_publisher").value.trim();
	var year_from = document.getElementById("from_year").value.trim();
	var year_to = document.getElementById("to_year").value.trim();
	var queryString = "";
	var seperator = "";
	
	if(isbn.length > 0)
		{
			//if(isbn.length!=13 && isbn.length!=10)
			//{
			//	alert("ISBN must be 10 or 13 digits");
			//}
			
			//else
			//{
				queryString = "?book_isbn=" + isbn;
				//alert(queryString);
			//}
		}
	
	
	
	else 
	{
		if (title.length > 0)
			{
				if(queryString == "")
			{
					seperator = "?";
			}
		
		else
			{
				seperator = "&";
			}
				queryString += seperator+"book_title=" + title;
				//alert(queryString);
			}
		
	if (author.length >0)
		{
			if(queryString == "")
			{
				seperator = "?";
			}
			else
			{
				seperator = "&";
			}
			queryString += seperator+"book_author=" + author;
			//alert(queryString);
		}
	
	if (publisher.length > 0)
	{
		if(queryString == "")
		{
			seperator = "?";
		}
		else
		{
			seperator = "&";
		}
		queryString += seperator+"book_publisher=" + publisher;
		//alert(queryString);
	}
	
	if (year_from.length > 0 && year_to.length > 0)
		{
			if (year_from.length > 4 || year_to.length > 4)
				{ alert ("error please enter year YYYY");}
			else {
					if(queryString == "")
					{
						seperator = "?";
					}
					else
					{
						seperator = "&";
					}
					
					queryString += seperator+"from_year=" + year_from + "&to_year="+year_to;	
				}
		}


	
	}
	if(queryString.length > 0)
	{
		window.location.search = queryString;
		//alert("added");
	}
	
}


