// JavaScript Document

//function to call when page is loaded
$(document).ready = function () {
	//start();
	
/*hack for css validating IE specific opacity tags*/
if(document.all) //if IE
{
	var arrElem = document.getElementsByTagName("*");
   
	for (var i=0; i<arrElem.length; i++)
	{
		if(arrElem[i].style.opacity && arrElem[i].style.opacity < 1){
			arrElem[i].style.filter='alpha(opacity='+arrElem[i].style.opacity*100+')'
		}

	}

}

}

/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

/*******************************
     AJAX Functions
*********************************/
function callServer() {

  // Get the search query and type web form
  var query = document.getElementById("query").value;
  var option = document.getElementById("option").value;
  // Only go on if there are values for both fields
  if ((query == null) || (query == "")) return;

  // Build the URL to connect to
  var url = "doSearch.php?query=" + escape(query) + "&option=" + escape(option) + "&count=true";
  // Open a connection to the server
  xmlHttp.open("GET", url, true);

  // Setup a function for the server to run when it's done
  xmlHttp.onreadystatechange = updatePage;

  // Send the request
  xmlHttp.send(null);
}

function updatePage() {
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    document.getElementById("result").innerHTML = response;
  }
}

function searchSubmit() {

  // Get the search query and type web form
  var query = document.getElementById("query").value;
  var option = document.getElementById("option").value;
  // Only go on if there are values for both fields
  if ((query == null) || (query == "")) return;

  // Build the URL to connect to
  parent.location = "doSearch.php?query=" + escape(query) + "&option=" + escape(option);
  // Open a connection to the server
}

/*******************************
     window manipulation scripts
*********************************/

function windowOpen(page)
//receives a string which is used as first part of url
//open window with specified name (page)
	{

	//create the url
	url = '' + page + ""; 

	//open new window with parameters
	window.open(url,"top","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=680,height=480");

	}

/**************************
     document write scripts
***************************/

function footer()
//write the footer
	{ 
		//write the footer to the document that requested it
		this.document.write('<?php echo $_SERVER["SERVER_SOFTWARE"] ?> &nbsp;<a href="http://www.noolvam.co.uk" target="_blank">created by noolvam.co.uk</a>&nbsp;');
	};
	
function logo()
//write the logo
	{ 
		//write the footer to the document that requested it
		this.document.write('<font color="red">B</font>ooks <font color="black">R</font>evisited');
	};

/*********************
     menu scripts
*********************/

function changeStatus(set)
{
var item = set + 'menu';

if (document.getElementById)
  {
	tab = document.getElementById(item).style;
  }

else if (document.all)

  {
	tab =  document.all(item).style;
  }

if (tab.display=='block')
	{
		tab.display = 'none';
	}
else
	{
		tab.display = 'block';
	}

}

function expandItem(mark)
{
	$('.display').hide().removeClass('display');
	$('#'+mark + 'item').addClass('display').show();

}

function closeItems()
{
	$('#bookreviewitem').hide();
	$('#topthreeitem').hide();
	$('#linksitem').hide();
}

/*********************
     time scripts
*********************/

function lastEdit()
{
  var timeday= getTime();
  var the_time= " " + timeday[1] + "/" + timeday[4] + "/" + timeday[5]; 
  this.document.write(the_time);	
}


function fixTime(the_time) {

if (the_time <10) 
{
the_time = "0" + the_time;
}
return the_time;
}


function getTime()
{    // get a date object
    var today = new Date();
  	
    // gather information from date object
    var name = new Array("Jan", "Feb", "March", "April" , "May" ,"June", "July", "Aug", "Sept" , "Oct", "Nov" , "Dec");
    var day = today.getDate();
    var monthn = today.getMonth();
    var month = name[monthn];
    var year= today.getYear();
    var hours = today.getHours();
    var minutes = today.getMinutes();
    var seconds = today.getSeconds();
    var ex='th';
    
    if (day == '1')
    { 
    	ex = 'st';
  	}
    if (day == '2')
    {
  	  ex = 'nd' 
  	}
    if (day=='3')
    {
  	  ex = 'rd'
  	}
    
    // make the minutes and seconds and months look right
    minutes = fixTime(minutes);
    seconds = fixTime(seconds);
    monthn = fixTime(monthn+1);

    // put together the time string and write it out
  var the_time = hours + ":" + minutes + ":" + seconds;
  var the_day = day + "";
  var the_ex = ex + "";
  var the_month = month + "";
  var the_monthn = monthn;
  var the_year = "" + year;
  var returnTimeArray = new Array(the_time, the_day, the_ex, the_month, the_monthn,  the_year);
  
  return returnTimeArray;
}

function showItem(topic)
//show Description popup
{
	$('#'+topic).animate({
		opacity: 'toggle'
	  }, 500, function() {
	    // Animation complete.
	  });;
};

function closeItem(topic)
//show Description popup
{ 
	$('#'+topic).animate({
		opacity: 'toggle'
	  }, 500, function() {
	    // Animation complete.
	  });
};

function changeMenuStatus(){
	//return false;
	//alert(this.className);
	if (this.className != 'closed'){
		this.className = 'closed';
		$('#rightbar_content').animate({
		    opacity: 0,
		    height: 'toggle'
		  }, 1000, function() {
		    // Animation complete.
			  $('#visibleButton').html('<div id="visibleButton" class="closed">[<a href="javascript:changeMenuStatus()">+</a>]</div>');
		  });
		
	}
	else{
		$('#rightbar_content').animate({
		    opacity: 1,
		    height: 'toggle'
		  }, 2000, function() {
		    // Animation complete.
			  $('#visibleButton').html('<div id="visibleButton" class="open">[<a href="javascript:changeMenuStatus()">-</a>]</div>');
		  });
		
		
this.className = 'open';
	}
}

