
function section(no,title)
	{
		this.no = no;
		this.title = title;
	}

	function book(bookname,author,classify,price,imagename)
	{
		this.bookname = bookname;
		this.author = author;
		this.classify = classify;
		this.price = price;
		this.imagename = imagename;	
	}
	
var sect = new Array();	
var str = new Array();
var sections = new Array();
var nmstr = new Array();
var srchbooks = new Array();
var bknum;
var cb = 0;
var thebook;
	function srchsections(bknme)
	{
		if (document.amatch.isnotfound.value)
			document.amatch.isnotfound.value = ""
		if (srchbooks.length > 0)
		{
		  srchbooks = new Array();
		  
		}
		match = 0;
		thebook = bknme;
		m = 0;
		n = 0;
		var wrd = new RegExp(bknme,"gi");
		var strbk = new Array();
		//alert('sections len  '+ sections.length);
		for (var i =1; i<= sections.length-1 ;++ i)
		{
			
			if (str.length > 0 )
		  		str = new Array();
			m = 0;
			no = i;
			
			
			var numbks = sections[no].length;
			//alert('numbooks  ' + numbks);
			for (var j = 0; j< numbks; ++j)
			{
				
				str[j] = sections[no][j].bookname;
				
			}
			for (var j = 0; j<str.length; ++j)
			{
				bknm = str[j];
				
				matchnow = bknm.match(wrd,"g");
				if (matchnow != null)
				{
					//add a book
					 match = 1;
				   if (n == 0)
				   {	
					//first book is displayed
					bk = str[j];
					au = sections[no][j].author;
					cl = sections[no][j].classify;
					pr = sections[no][j].price;
					bn = sections[no][j].imagename;
					srchbooks[n] = new book(bk,au,cl,pr,bn);
				//alert('bk  '+bk);
		
					m = m+1;
					n = n+1;
					document.amatch1.bookname1.value = bk;
					document.amatch1.author1.value = au;
					document.amatch1.classify1.value = cl;
					document.amatch1.price1.value = pr;
					document.amatch1.bkno.value = bn;
			//added init cb to zero to count books bound correctly
					cb = 0;
					bknum =  bn;        //srchbooks[cb].imagename;
		                 
					getTitle(bn);
				   	
				   }	

				   else
				   {
					bk = str[j];
					au =  sections[no][j].author;
			  		cl = sections[no][j].classify;
			  		pr = sections[no][j].price;
			  		bn = sections[no][j].imagename;
					srchbooks[n] = new book(bk,au,cl,pr,bn);
					isthereatitle = document.amatch1.atitle.value;
					if (isthereatitle.length == 0)
						getTitle(bn);
					m = m+1;
					n =n+1;
					
				    }//end match == 1	
				}//end match now
			}//end for j
		}//end for i
	
	if (match == 1)
	 document.amatch1.nummatches.value = srchbooks.length+ ' Books Found';

//alert('match before match == 0' +'  '+ match);
	if (match == 0)
	{
	 //alert('srchbooks len  ' + srchbooks.length);
	   if (srchbooks.length == 0)
	   {
	    document.amatch1.bookname1.value = "";
	    document.amatch1.author1.value = "";	
          document.amatch1.classify1.value = "";
	    document.amatch1.price1.value = "";
	    document.amatch1.nummatches.value ="";
	    document.amatch1.atitle.value = "";
	   }
  	   document.amatch.isnotfound.value ="Sorry! No Match Found ";	
      }//end matches
	}//end function

	function sprevious()
	{
		if (document.amatch.isnotfound)
			   document.amatch.isnotfound.value ="";
	
		if (document.amatch1.bookname1.value)
		         booknme = document.amatch1.bookname1.value;


		if (srchbooks.length == 0)
		{
			booknm = document.srch.bk.value;
		
			srchsections(booknm);//reinit array
			//fix cb
//the first book will now be in list
			for (var i = 0; i < srchbooks.length; ++i)
			{
			   nmstr[i] = srchbooks[i].bookanme;
		if (srchbooks[i].bookname == booknme)
					cb = i;
			
			}		
		}
			//  alert(cb +' cb value'); 				
			  if (cb  >= 0)
			  {
				if (cb == srchbooks.length)
					cb = cb -2;
				else if (cb > 0)
					cb = cb-1;
 
	     
		document.amatch1.bookname1.value=srchbooks[cb].bookname;
		document.amatch1.author1.value=srchbooks[cb].author;
		document.amatch1.classify1.value=srchbooks[cb].classify;
		document.amatch1.price1.value=srchbooks[cb].price;
		bknum = srchbooks[cb].imagename;
		
		getTitle(bknum);	  
		}//end if cb
		      		
		

	}//end sprevious
	function snext()
	{
		if (document.amatch.isnotfound)
			   document.amatch.isnotfound.value ="";
		if (document.amatch1.bookname1.value)
			    booknme = document.amatch1.bookname1.value;
		//alert(srchbooks.length);
		if (srchbooks.length == 0)
		{
			booknm = document.srch.bk.value;
			srchsections(booknm);
		    		
			for (var i = 0; i<srchbooks.length; ++i)
			{
				if (srchbooks[i].bookname == booknme)
					cb = i;

			}
		}		
	//alert("cb value  "+cb);	
		if (cb < srchbooks.length - 1  )
		{		
		
			
				cb = cb +1;	
			thebook = srchbooks[cb].bookname;
			theauthor = srchbooks[cb].author;
			theclassify = srchbooks[cb].classify;
			theprice = srchbooks[cb].price;
			thebooknum = srchbooks[cb].imagename;	  				
	document.amatch1.bookname1.value=thebook
	document.amatch1.author1.value=theauthor;
	document.amatch1.classify1.value=theclassify;
	document.amatch1.price1.value=theprice;
	bknum = srchbooks[cb].imagename;
	getTitle(bknum);
		
		}//end if cb 

	}//end snext
	function sfirst()
	{
		if (document.amatch.isnotfound)
			   document.amatch.isnotfound.value ="";
		
		if (srchbooks.length == 0)
		{
			booknm = document.srch.bk.value;
			srchsections(booknm);

		}		
//alert('srchbooks len in sfirst ' + srchbooks.length);
		cb = 0;
		document.amatch1.bookname1.value=srchbooks[cb].bookname;
		document.amatch1.author1.value=srchbooks[cb].author;
		document.amatch1.classify1.value=srchbooks[cb].classify;
		document.amatch1.price1.value=srchbooks[cb].price;
		bknum = srchbooks[cb].imagename;
		getTitle(bknum);
	


	}
function slast()

	{
		if (document.amatch.isnotfound)
			   document.amatch.isnotfound.value ="";
		//alert('srchbooks len ' +srchbooks.length);
		if (srchbooks.length == 0 )
		{
			booknm = document.srch.bk.value;
			srchsections(booknm);
			
		}
	//alert('in last srchsections len' +'  '+ srchsections.length);
		cb = srchbooks.length- 1;
		document.amatch1.bookname1.value=srchbooks[cb].bookname;
		document.amatch1.author1.value=srchbooks[cb].author;
		document.amatch1.classify1.value=srchbooks[cb].classify;
		document.amatch1.price1.value=srchbooks[cb].price;
		bknum = srchbooks[cb].imagename;
		getTitle(bknum);


	}
	function getTitle(thisbook)
	{
	//alert('from get title  '+ thisbook);
		bknum = thisbook;
		indx = bknum.indexOf('i');
		asect = bknum.substring(0,indx);
		
		indx = asect.indexOf('t');
		len = asect.length;
		sectno= asect.substring(indx+1,len);
		//alert(sectno);
		 atitle = sect[sectno-1].title;
		indx = atitle.indexOf('<');
		//alert('indx ' +indx);
	    if (indx >0)
	    {
		len = atitle.length;
		atitle = atitle.substring(0,indx)+ atitle.substring(indx+4,len);
	    }
		document.amatch1.atitle.value =atitle;

	}

	function showsrchbook()
	{
		
		
		bkum = document.amatch1.bkno.value
		ndx = bknum.indexOf('i');
		//alert('ndx: ' +ndx);
		sectno = bknum.substring(4,ndx); 
		//alert('sectno: '+ sectno); 
		if (sectno >= 10)
			theurl1 = 'sections/section'+sectno+'/images/'+bknum+'.htm';
		else	
			theurl1 = 'sections/section0'+sectno+'/images/'+bknum+'.htm';
		
		//alert(theurl1);
		parent.frames[1].location.href = theurl1;
		

	}

	function findstrg(bkname)
	{
		
		var wrd = new RegExp(bkname,"gi");
		document.amatch.isnotfound.value = bkname;
		if (document.srch.bk.value)
			document.srch.bk.value = "";
		//alert ('section no '+ sect[1].no);	
		for (var j = 0; j<sections[no].length;++j)
		{
			//generate book name string
				 str[j] = sections[no][j].bookname;
			//document.amatch.isnotfound.value = str[j];
		}//end for j sections
			matches = 0;
		
		for (var i = 0; i < str.length;++i)
		{ 
			bknm = str[i];
			
			matchnow = bknm.match(wrd,"g");
			
		   if (matchnow != null)
		   {
				matches = matches + 1
				booknme = str[i]
			 if (matches == 1)
			 {
			theauthor =  sections[no][i].author;
			theclassify = sections[no][i].classify;
			theprice = sections[no][i].price;
					
			document.amatch1.bookname1.value = booknme;						document.amatch1.author1.value = theauthor;
			document.amatch1.classify1.value = theclassify;
			document.amatch1.price1.value = theprice;
			
			 }//end matches
			if (document.amatch.isnotfound)
			   document.amatch.isnotfound.value ="";	
			}//end match now
		
		}//end for
    if (matches == 0)
	{
	if (document.amatch1.bookname1.value)
	{
	  document.amatch1.bookname1.value = "";
	  document.amatch1.author1.value = "";	
        document.amatch1.classify1.value = "";
	  document.amatch1.price1.value = "";
	}
  	   document.amatch.isnotfound.value ="Sorry! No Match Found";	
    }//end matches
  }//end function findstrg
	function previous()
	{
		if (document.amatch.isnotfound)
			   document.amatch.isnotfound.value ="";
		if (document.amatch1.bookname1.value)
		         booknm = document.amatch1.bookname1.value;
			
		for (var j = 0; j<sections[no].length;++j)
		{
			
			//generate book name string
			str[j] = sections[no][j].bookname;
		
			if (str[j] == booknm)
			{	
			       if (j != 0)
				{
		document.amatch1.bookname1.value=sections[no][j-1].bookname;
		document.amatch1.author1.value=sections[no][j-1].author;
		document.amatch1.classify1.value=sections[no][j-1].classify;
		document.amatch1.price1.value=sections[no][j-1].price;
				}//end if j 
			}//end if str j		
		}//end for j sections
	     
	}
	function next()
	{
		if (document.amatch.isnotfound)
			   document.amatch.isnotfound.value ="";
		if (document.amatch1.bookname1.value.length)
			    booknm = document.amatch1.bookname1.value;
		      	
		
		for (var j = 0; j<sections[no].length;++j)
		{
			//generate book name string
				 str[j] = sections[no][j].bookname;
			
			if (str[j] == booknm)
			{
				
				if (j < sections[no].length - 1)
				{			  				document.amatch1.bookname1.value=sections[no][j+1].bookname;
	document.amatch1.author1.value=sections[no][j+1].author;
	document.amatch1.classify1.value=sections[no][j+1].classify;
	document.amatch1.price1.value=sections[no][j+1].price;
				}//end if j 
			}//end if str j
		
			
		}//end for j sections
	
	      	
	}//end next
	function first()
	{
	//pick first book
		if (document.amatch.isnotfound)
			   document.amatch.isnotfound.value ="";
		
		document.amatch1.bookname1.value=sections[no][0].bookname;
		document.amatch1.author1.value=sections[no][0].author;
		document.amatch1.classify1.value=sections[no][0].classify;
		document.amatch1.price1.value=sections[no][0].price;
	}

	function last()
	{
	//pick last book
		if (document.amatch.isnotfound)
			   document.amatch.isnotfound.value ="";
				
		indx = sections[no].length - 1;
		
		document.amatch1.bookname1.value=sections[no][indx].bookname;
		document.amatch1.author1.value=sections[no][indx].author;
		document.amatch1.classify1.value=sections[no][indx].classify;
		document.amatch1.price1.value=sections[no][indx].price;
	}

	function booknmsel()
	{
	//this used to navigate instead of buttons
		
		for (var i = 0; i < document.sel.selbk.length ; ++i)
		{
					
			if (document.sel.selbk.options[i].selected)
			{
			thename = document.sel.selbk.options[i].value;
			document.amatch.isnotfound.value = thename;
			findstrg(thename);
			}
		}//end for
	}//end booknm

	function showthebook()
	{
		//num = no+1;
		
		sectionno="section0"+no;
		// find name of book
		//if no match then this will not be initialized
		thebknm =document.amatch1.bookname1.value;
		for (var j = 0; j < sections[no].length; ++j)
		{
			bknm = sections[no][j].bookname;
			
			if (thebknm == bknm)
			{
				
				//document.write(bknm+" sect no "+no);
				bkimg = sections[no][j].imagename;
				bkurl ="images/"+bkimg+".htm";
				parent.frames[1].location.href = bkurl;
				
			}

		}
		
			
	}//end show the book


