//* Random Quotes
//*
//* A small JavaScript library that can be used to randomly
//* select a number of quotes from a pool, and display them
//* on a web page.

// The arrays for the quotes
var QuoteImagePaths = new Array();
var QuoteImages = new Array();

// The number of times the loadQuote function has been called
var quoteLoaded=0;

// An array to keep track of which Quotes have already been chosen.
// This is used to ensure that the same quote is not displayed more than
// once on the same page.
var selectedQuotes = new Array();

// Loop over the array of quote image paths, and initialize
// an array of actual Javascript Images.
function preloadQuotes() {
  if (QuoteImagePaths.length>=1) {
    for (i=0;i<QuoteImagePaths.length;i++){
      QuoteImages[i] = new Image();
      QuoteImages[i].src = QuoteImagePaths[i];
    }
  } else {
    alert("Error: No quotes have been defined!");
  }
}

// Return a number between 0 and the size of the QuoteImagePaths array
function getRandomQuoteID() {
  var tmpid=-1;
  tmpid = Math.round(Math.random()*(QuoteImagePaths.length-1));
  while(tmpid>=QuoteImagePaths.length) { tmpid = Math.round(Math.random()*(QuoteImagePaths.length-1)); }
  return(tmpid);
}

// Get a new, randomly selected quote id which represents it's position
// in the QuoteImages array.  Ensure that it has not already been selected for
// this page, and then mark it as selected.
function getNewQuoteID() {
  var tmpid=-1;
  if (quoteLoaded != QuoteImagePaths.length) {
    tmpid = getRandomQuoteID();
    while(selectedQuotes[tmpid]==1) { tmpid = getRandomQuoteID(); }
    selectedQuotes[tmpid]=1;
    quoteLoaded++;
  }
  return(tmpid);
}

// Load all the images from 1 to numImages
function loadQuotes(numQuotes) {
	var quoteid=-1;

	for (i=1; i<=numQuotes; i++) {
  	quoteid=getNewQuoteID();

  	if (quoteid!=-1 && QuoteImages[quoteid]) {
    	document.images["Quote" + i].src=QuoteImages[quoteid].src;
		}
	}
}



function popMailWin() {
      var pageURL   = escape(self.document.URL);
      var pageTitle = escape(self.document.title);
      var formURL   =
        "/cgi-bin/mail/mailurl2friend.cgi?path=yourpath&url="  + pageURL 
         + "&group=yourgroupcode&title=" + pageTitle; 
      window.open(formURL,"emailpop","height=375,width=350,resizable,scrollbars");
      return false;
   }
