function email_pop()
{
    window.open(basepath + 'send_email?title=Books and Authors : About the Book ::'+stripslashes((document.getElementById("book_name").value))+'&attachment_url=' + global_requesturi + escape('&down=yes&email=yes'),'Email','resizable=1,status=1,scrollbars=1,width=790,height=715');
}
function print_fn()
{
    window.location=global_requesturi_new + "&print_btn=no";
}



function show_review()
{
    document.getElementById('review_area').style.display='block';
    document.getElementById('post_review').style.display='none';
}

function hide_review()
{
    document.getElementById('review_area').style.display='none';
}

function validInput()
{
  var title = document.review.your_title.value;
  var review = document.review.review.value;
  if(trim(title) == "")  {
    alert ("Please enter a title.");
    document.review.your_title.focus();
    return false;
  }
  if(trim(review) == "")  {
    alert ("Please type your review.");
    document.review.review.focus();
    return false;
  }
 return true;
}

function add_comments(bookid,title,author,name,url)
{
   $.ajax(
	{
			type: "POST",
		   	url: basepath + "ajax_about_book",
		  data: "title="+document.review.your_title.value+"&review="+document.review.review.value+"&bookid="+bookid+"&book_title="+title+"&authorid="+author+"&name="+name+"&url="+url+"&flag=save_review",
		   	success: 
		    function(t) 
				{
					$("#comm_review").append(t);		
					document.getElementById('see_all_reviews_link').style.display = 'block';
					document.getElementById('write_review_link').style.display = 'none';
					document.getElementById('post_review').style.display = 'none';
					document.getElementById('review_area').style.display = 'none';
			    },
			error:
			function()
				{
					$("#"+bookid).empty().append("An error occured during processing");
				}
	});

}

// JavaScript Document
function xmlhttpPost(uid, mid, mrid, useful) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
	var strURL = basepath + 'ajax_about_book';
	var ajaxfriendlyurl=strURL.replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/")
    self.xmlHttpReq.open('POST', ajaxfriendlyurl, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
			var output = self.xmlHttpReq.responseText
			var val = output.split("-");
			if(val[0] == 1)
			  var your_review = "You found this review helpful";
			else 
			  var your_review = "You found this review not helpful";
			document.getElementById("helpful"+mrid).innerHTML = val[1]+" out of "+val[2]+" found this review helpful<br />"+your_review;
        }
    }
	var param = "flag=save_useful";
	param += "&mid="+mid;
	param += "&mrid="+mrid;
	param += "&useful="+useful;
    self.xmlHttpReq.send(param);
}

function getquerystring() {
    var form     = document.forms['f1'];
    var word = form.word.value;
    qstr = 'w=' + escape(word);  // NOTE: no '?' before querystring
    return qstr;
}

function updatepage(str){
    document.getElementById("result").innerHTML = str;
}

function all_reviews()
{
    book_tab('seeall','1234567');
}

function addlist(author,name)
{
   $.ajax(
		{
			type: "POST",
		   	url: basepath + "ajax_about_book",
		  data: "authorid="+author+"&name="+name+"&flag=save_author",
		   	success: 
		    function(t) 
	          	{
					document.getElementById(author).innerHTML = t;
	       	   	},
		   	error:
			   	function()
			   	{
			    	$("#"+author).empty().append("An error occured during processing");
			   	}
		 });

}




function print_author_pop(auth_id)
{
    window.open(basepath+'short_bio/'+auth_id+'&down=yes&print=yes','download','resizable=1,status=1,scrollbars=1,width=820,height=600');
}

function stripslashes(str) {
    str=str.replace(/\\'/g,'\'');
    str=str.replace(/\\"/g,'"');
    str=str.replace(/\"/g,'"');
    str=str.replace(/\\\\/g,'\\');
    str=str.replace(/\\0/g,'\0');
    return str;
}



function opennewsletter_tmp(a,b,c,d,path,e,hide)
{
var reviewappend="#"+path;
var reviewhide="#"+hide;
 $(reviewappend).show();
 $(reviewappend).empty().append("Loading........");

query_string = "";
  $.ajax({
	  type: "POST",
	  url: basepath + 'reviews_more/'+b+'/'+e+'/'+d+'/'+path+'/'+hide,
	  data: query_string,
	  success: 
	  function(result){
	  $(reviewappend).empty().append(result);
	  $(reviewhide).hide();
	  },
	  error:
	  function(error){
	       document.getElementById("youremail").innerHTML=result;
	  } 
	 });
	 
 } //End "openn
 
function hide_Review(hide,show) {
     var reviewshow="#"+show;
     var reviewhide="#"+hide;
     $(reviewhide).hide();
     $(reviewshow).show();
}
 
function cancel_review(seeall_count) {
     $("#review_area").hide();
     document.getElementById("post_review").style.display="block";
}

function addBook(bookid,title,author,name,url,userid)
{
	if (userid == 0)
	{
	    var agree=confirm("You need to login inorder to add this book to your marked list. Press ok to proceed to login page. Once logged in successfully you will be taken back to this page");
	    if (agree)
	    {
	        window.location = basepath + "user/?" + d_destination;
	    	return true ;
	    }
	    else
	    {
			document.getElementById("chk_addbook").checked = false;
			return false;
		}
    }
	else
	{
		$.ajax(
		{
			type: "POST",
		   	url: basepath + "ajax_about_book",
			  data: "bookid="+bookid+"&title="+title+"&authorid="+author+"&name="+name+"&url="+url+"&flag=save_book",
		   	success: 
    		    function(t) 
	          	{
					alert(t);										
					document.getElementById("second_tool").innerHTML='<a href="' + global_requesturi_new + '&down=yes" target="_blank"><img id="newtools-pad" src="' + themepath + '/images/icon_download.gif"  style=" cursor:pointer" alt="Download" title="Download" /></a><img id="newtools-pad" src="' + themepath + '/images/icon_tooltip5.gif" onclick="email_pop()" style="cursor:pointer" alt="Email" title="Email" /><img id="newtools-pad" src="' + themepath + '/images/icon_tooltip6.gif" onclick="print_pop()" style=" cursor:pointer" alt="Print" title="Print" /><img id="newtools-pad" src="' + themepath + '/images/icon_tooltip7.gif" />';
	       	   	},
		   	error:
			   	function()
			   	{
			    	$("#"+author).empty().append("An error occured during processing");
			   	}
		 } );
	}
}

function addBookRead(bookid,title,author,name,url,userid,row,callback)
{
    if(document.getElementById("read_tick_"+row).checked) {
	if (userid == 0)
	{
    	var agree=confirm("You need to login inorder to add this book to your marked list. Press ok to proceed to login page. Once logged in successfully you will be taken back to this page");
		if (agree)
		{
		  window.location = basepath + "user/?" + d_destination + callback;
			return true;
		}
		else
			return false;
		}
   else {
   
   $.ajax(
		{
		type: "POST",
	   	url: basepath + "ajax_about_book",
		  data: "bookid="+bookid+"&title="+title+"&authorid="+author+"&name="+name+"&url="+url+"&flag=save_book",
	   	success: 
    	    function(t) 
          	{
				document.getElementById("read_"+row).innerHTML='<span style="color:#AF5231">Book added successfully to your marked list</span>';
       	   	},
	   	error:
		   	function()
		   	{
		    	$("#"+author).empty().append("An error occured during processing");
		   	}
		 });
		}
}// End for checkbox checked
}

 

function addAuthor(author,name)
{
    if (global_uid == '0')
    {
    var agree=confirm("You need to login inorder to add this author to your marked list. Press ok to proceed to login page. Once logged in successfully, you will be taken back to this page");
    if (agree)
    {
    window.location = basepath + "user/?" + d_destination;
    	return true ;
    }
    else  {
      document.getElementById("chk_abtauthor").checked = false;
    	return false ;
    	}
    }
  else {  
   $.ajax(
		{
		type: "POST",
	   	url: basepath + "ajax_about_book",
        data: "authorid="+author+"&name="+name+"&flag=save_author",
	   	success: 
    	    function(t) 
          	{
				//document.getElementById(author).innerHTML = t;
				alert(t);
				document.getElementById("second_tool").innerHTML='<a href="' + global_requesturi_new + '&down=yes" target="_blank"><img id="newtools-pad" src="' + themepath + '/images/icon_download.gif"  style=" cursor:pointer" alt="Download" title="Download" /></a><img id="newtools-pad" src="' + themepath + '/images/icon_tooltip5.gif" onclick="email_pop()" style="cursor:pointer" alt="Email" title="Email" /><img style="cursor:pointer" id="newtools-pad" src="' + themepath + '/images/icon_tooltip6.gif" onclick="javascript:print_author_pop('+author+')" alt="Print" title="Print" /><img id="newtools-pad" src="' + themepath + '/images/icon_tooltip7.gif" />';
				document.getElementById("author_tick").value='1';
       	   	},
	   	error:
		   	function()
		   	{
		    	$("#"+author).empty().append("An error occured during processing");
		   	}
			 });
      } 
}

function print_pop()
{
    window.open(global_requesturi_new +'&down=yes&print=yes','download','resizable=1,status=1,scrollbars=1,width=820,height=600');
}


function checkLibraryHoldings( query )
{
    var statusDiv = $('#libHoldingsCheck');
    // TODO show animation while loading
    // TODO check for error on return
    statusDiv.load( '../about_the_book_lib_holdings_preview/' + global_arg1 + '/' + escape(query) );
}
