<!--


function MM_preloadImages() { //v3.0

}


//-->


//jump menu
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->






/*  ajax search */ 
var t;
	
//call ajax when the function is called
						function ajaxSearch()
						{
						clearTimeout(t);//clear any previous call
						$("#ajax_result").fadeOut('slow');
						
						
						//collect all subcats
						var subcats = document.form2.subcats.value;
						//alert(subcats)
						if (subcats !='')
						{
						subcats = [];
							$('#subcats :selected').each(function(i, selected){
							subcats[i] = $(selected).val();
							});
												
						}
						
						
							
						
						var randomnumber=Math.round(Math.random()*15);//prevent caching in ASP
									$.ajax({
									
											type: "GET",
											url: "http://www.directebooks.com/search/ajax-search.asp",
											data: {search_title: document.form2.search_title.value, search_title_type: $('input[name=search_title_type]:checked').val(), search_author: document.form2.search_author.value, search_author_type: $('input[name=search_author_type]:checked').val(), reader_MD: $('#reader_MD:checked').val(), reader_GL: $('#reader_GL:checked').val(), reader_E1: $('#reader_E1:checked').val(), reader_E3: $('#reader_E3:checked').val(), reader_PP: $('#reader_PP:checked').val(), special_offers: $('#special_offers:checked').val(), isbn: document.form2.isbn.value, catId: document.form2.catId.value, subcats: subcats, sort_: document.form2.sort.value, ref: $('#ref:checked').val(), rand: randomnumber, searchM: 2,memo: $('input[name=memo]:checked').val(),ajax: 1},
											success: function(dataBack){
																	
																	callBack(dataBack)
																	
																	
																}
									
									
										
									});
		
						}		
								
								
							
							
						function callBack(data)		
						{
						
							//$("#loader_ajax").hide();
							window.document.getElementById("ajax_result").innerHTML = ''+ data + '';
							
							$("#ajax_result").fadeIn('slow');
						
						}
						
						
						
						function resetC()
								{
								
							
								clearTimeout(t);//clear any previous call
								
								t=setTimeout(ajaxSearch(),5000);
						
						
								
								}
						
						
						
						
						function readySearch(type)
						{
						
							
							if (type==2){ajaxSearch();}//call function if it is a non input field
							else
							{resetC();}
							
							
							
							
									//prepare the message (without going to the server to save on CPU)
									var search_title = document.form2.search_title.value;
									var search_title_type= $('input[name=search_title_type]:checked').val();
									var search_author= document.form2.search_author.value;
									var search_author_type= $('input[name=search_author_type]:checked').val();
									var reader_MD= $('#reader_MD:checked').val();
									var reader_GL= $('#reader_GL:checked').val();
									var reader_E1= $('#reader_E1:checked').val();
									var reader_E3= $('#reader_E3:checked').val();
									var reader_PP= $('#reader_PP:checked').val();
									var special_offers= $('#special_offers:checked').val();
									var isbn= document.form2.isbn.value;
									var catId= document.form2.catId.value;
									var subcats= document.form2.subcats.value;
									var sort_= document.form2.sort.value;
									
									
									var message = '<strong>You are searching for:</strong>';
									
									/************************************  title   ***********************/
									if (search_title!='')
									{
									
										message = message + " <em><strong>Title: </strong></em>";
										var thisMess ='';
										var oper = ' + ';
										if (search_title_type==3){oper =' <em><strong>or</strong></em> '}
									
									
											if (search_title_type==1)
											{
											
												message = message + " \""+search_title+"\"";
											
											}
											else
											{
											
												//split the words
												var keywords = search_title.split(" ")
												
												for (i=0;i<keywords.length;i++)
														{
														
																												
														 
															if (keywords[i] !=''){
																thisMess = thisMess + keywords[i] + oper;
																}
														}//closes the for loop
											
											
											
											thisMess = thisMess.substring(0,thisMess.length-oper.length);
											
											message = message + " \""+thisMess+"\""
											
											
											
											}
											
									message = message + ', ';
									
									}//end of title
									
									
									
									/******************************* author  **************************/
									
									
									if (search_author!='')
									{
									
									message = message + " <em><strong>Author: </strong></em>";
										
										var thisMess ='';
										var oper = ' + ';
										if (search_author_type==3){oper =' <em><strong>or</strong></em> '}
									
									
											if (search_author_type==1)
											{
											
												message = message + " \""+search_author+"\"";
											
											}
											else
											{
											
												//split the words
												var keywords = search_author.split(" ")
												
												for (i=0;i<keywords.length;i++)
														{
														
																												
														 
															if (keywords[i] !=''){
																thisMess = thisMess + keywords[i] + oper;
																}
														}//closes the for loop
											
											
											
											thisMess = thisMess.substring(0,thisMess.length-oper.length);
											
											message = message + " \""+thisMess+"\""
											
											
											
											}
											
									message = message + ', ';
									
										
									
									}//end of author
									
								/************************ isbn ************************************/
								
								
								if (isbn!= '')
								{
								message = message + "<em><strong>ISBN:</strong></em> " + isbn + ', ' ;
								
								}
								
								
								
								
								
								/***************************************** genders  *************************************/
									
									if (catId !='')
									{
									
										message = message + '<em><strong>Genre:</strong></em> ' + document.form2.catId.options[document.form2.catId.selectedIndex].text + ', ';
									
									
									}
									
									
									/***************************sub genders  **********************************/
									
									
											//subcats contains all
											
											var mess_subcats='';
											if (subcats!='')
											{
											
											message = message + '<em><strong>Sub Genre(s):</strong></em> ' 
														//loop
														for (i=0;i<document.form2.subcats.length;i++)
														{
														
															if (document.form2.subcats.options[i].selected){
															
															
															mess_subcats = mess_subcats + document.form2.subcats.options[i].text +' <em><strong>and</strong></em> '
															
															}
														
														
														}
														if (mess_subcats!='')
														{
														mess_subcats = mess_subcats.substring(0,mess_subcats.length-31);
														
														
														}
														message = message +  mess_subcats + ', '
								
								
											}
								
								
								
								
									
									
								/*************************** readers  ****************************/
								
								var mess_reader ='';
								var totReaders = 0
								
									if (reader_MD==1){
									totReaders++;
									mess_reader = mess_reader + 'Microsoft Reader or ';
									}
									
									if (reader_GL==1){
									totReaders++;
									mess_reader = mess_reader + 'PDF or ';
									}
									
									if (reader_E1==1){
									totReaders++;
									mess_reader = mess_reader + 'Epub unencrypted or ';
									}
									
									if (reader_E3==1){
									totReaders++;
									mess_reader = mess_reader + 'Epub encrypted or ';
									}
									
									if (reader_PP==1){
									totReaders++;
									mess_reader = mess_reader + 'Ereader or ';
									}
									
								
									if (mess_reader!='')
									{
								
									
									
											if (totReaders ==5){
											message = message + '<em><strong>Available in ALL readers</strong></em>, ';
											}
											else
											{
											
											mess_reader = mess_reader.substring(0,mess_reader.length-4);
											
											message = message + '<em><strong>Available in readers: </strong></em>' + mess_reader + ', ';
											
											}
								
									}
									else
									{
											alert("You must select at least one type of reader")
											
									
									}
									
									
									/*******************  special_offers   *******************/
									if (special_offers==1)
									{
									
											message = message + '<strong><em>Returning special offers only</em></strong>, '
									}
									
									
									
									
									
									
									//trim
									message = message.substring(0,message.length-2)
									
									//output the message
									window.document.getElementById("search_message").innerHTML = message;
									window.document.getElementById("search_message").style.border = "solid 1px #FFFFFF";
									
						
						}//end of readySearch()
						
						
						
						
						function callSubs()
						{
						
						if (document.form2.catId.value!= ''){
						
						readySearch(2);
						
						
						var randomnumber=Math.round(Math.random()*15);//prevent caching in ASP
						
						$("#loader_cats").show();
						
						
									$.ajax({
									
											type: "GET",
											url: "http://www.directebooks.com/search/getcats.asp",
											data: {catId: document.form2.catId.value, rand: randomnumber, searchM: 2},
											success: function(dataBack){
																	
																	
																	
																	$("#loader_cats").hide();
																	$("#mess_cat").fadeOut('fast');
																	$("#subcats_container").fadeIn('slow')
																	$("#subcats").fadeIn('slow')
																	
																	
																	
																	//populate the subcats
																var subcats = dataBack.split("-**-");
																
																var cookie_memo = memo12;
																
																if (cookie_memo=='undefined'){cookie_memo = '';}
																
																for (i=0;i<subcats.length;i++)
																{
																
																		
																		document.form2.subcats.options[i] = new Option(subcats[i].substring(subcats[i].indexOf("-*-")+3,subcats[i].length),subcats[i].substring(0,subcats[i].indexOf("-*-")))
																		
																		if (cookie_memo.indexOf(subcats[i].substring(0,subcats[i].indexOf("-*-"))) !=-1)//memo cookie
																		{document.form2.subcats.options[i].selected = true;
																		
																		}
															
																
																}//closes for loop	
																	
																	
																	
																	
																	
																	
																	
																}
									
									
										
									});
						
							}//end if catId !=''
							else
							{
								//all cats selected, we remove all options from the subcats
							
								document.form2.subcats.options.length = 0
							
							}
							
							
							
							
						
						ajaxSearch();
						} 
						
						
							
								
						
		
				
		function showAdv(fie)
		{
		
		if (document.form2.catId.value!=''){
						callSubs();
						}
		
				$("#ajax-adv-search").slideDown("slow");
				
				
				//then pass the focus to the field selected
				if (fie==1){
				//pass the focus
				document.form2.search_title.focus();
				}
				else 
				if (fie==3){
				//pass the focus
				document.form2.isbn.focus();
				}
				if (fie==2){
				//pass the value
				document.form2.catId.value = document.ebook_search.catId.value;
				
				callSubs();
				
				
				}
				
				
				$("#quick_search").fadeOut(500);
				$("#adv_search").fadeIn(500);
				
		
		}
		
		








		function showT()
		{
			
			$(".ajax_showsubmit").show();
			
		}
		
		function closeAdvS()
		{
			$("#ajax-adv-search").slideUp("fast");
			
		}
	
		function clearSearch()
		{
			
				//clear all fields
				
				document.form2.search_title.value ='';
				document.form2.search_author.value ='';				
				document.form2.isbn.value ='';	
				document.form2.search_title_type[0].checked = true ;
				document.form2.search_author_type[0].checked = true ;
				document.form2.reader_MD.checked = true ;
				document.form2.reader_GL.checked = true ;
				document.form2.reader_E1.checked = true ;
				document.form2.reader_E3.checked = true ;
				document.form2.reader_PP.checked = true ;
				document.form2.special_offers.checked = false ;	
				document.form2.catId.value ='';
				document.form2.subcats.options.length = 0;
				
				$("#subcats_container").hide();
				$("#subcats").hide();
				

		}
		
		
	
	$(document).ready(function() {
				

	});
	
	
	
	function addWish(prodId)
	{
	
	  var randnumber = Math.round(Math.random()*15);//prevent caching in ASP
	  
	  
	
	  
	  
		$.ajax({
			   
			
									
											type: "GET",
											url: "http://www.directebooks.com/wishlist/add.asp",
											data: {prodId: prodId,rand:randnumber},
											success: function(dataBack){
																	
																	//hide the add button and show the tick
																	$("#wish_add_"+dataBack+"").hide();
																	$("#wish_tick_"+dataBack+"").show();
																	
																	
																	
																}
									
									
										
									});
		
		
	}
	
	//pre tick for the wish list
	
	
		$(document).ready(function() {
		
		
				
				
			
				
			
				if (wishList!='undefined' && wishList!='')
				{
				
						wishList = wishList.split(",");
						
						
						
						
						
						for (i=0;i<wishList.length;i++)
						{
						
						$("#wish_add_"+wishList[i]+"").hide();
						$("#wish_tick_"+wishList[i]+"").show();
						
						
						}
						
						
					
				
				
				}
		
				
			});






	
	
