// ******************************
// RandomQuote.js
// 31 December 2007
// Gregory A. Becerra
// GregBecerra@gmail.com
// ******************************
var cGAB_RandomQuote_QUOTE = 1;
var cGAB_RandomQuote_AUTHOR = 2;
var cGAB_RandomQuote_SOURCE = 3;
var cGAB_RandomQuote_WIKI = 4;

// functions
function fnGAB_RandomQuote_Array(iIndex, iItem, bDebug) {
   
   if(bDebug) document.write('Entered Array()' + '<br/>');
   if(bDebug) document.write('iIndex = ' + iIndex + '<br/>');
   
   if(bDebug) {
      switch(iItem) {
         
         case cGAB_RandomQuote_QUOTE:
            document.write('iItem = QUOTE' + '<br/>');
            break;
         case cGAB_RandomQuote_AUTHOR:
            document.write('iItem = AUTHOR' + '<br/>');
            break;
         case cGAB_RandomQuote_SOURCE:
            document.write('iItem = SOURCE' + '<br/>');
            break;
         case cGAB_RandomQuote_WIKI:
            document.write('iItem = WIKI' + '<br/>');
            break;
         default:
            document.write('iItem = ' + iItem + '<br/>');
            break;
      }
   }
   
   if(bDebug) document.write('Leaving Array()' + '<br/>');

   switch(iIndex) {
   
      case 1:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "People often grudge others what they cannot enjoy themselves.";
            case cGAB_RandomQuote_AUTHOR: return "Aesop";
            case cGAB_RandomQuote_SOURCE: return "The Dog in the Manger";
            case cGAB_RandomQuote_WIKI: return "http://en.wikipedia.org/wiki/Aesop";
         }         
      case 2:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "We are faced with the paradoxical fact that education has become one of the chief obstacles to intelligence and freedom of thought.";
            case cGAB_RandomQuote_AUTHOR: return "Bertrand Russell";
            case cGAB_RandomQuote_SOURCE: return "Interview";
            case cGAB_RandomQuote_WIKI: return "http://www.brainyquote.com/quotes/authors/b/bertrand_russell.html";
         }         
      case 3:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "The truth shall set you free... ask any martyr.";
            case cGAB_RandomQuote_AUTHOR: return "Eric Nunnally";
            case cGAB_RandomQuote_SOURCE: return "Blog. To her sister Cassandra [December 2005]";
            case cGAB_RandomQuote_WIKI: return "http://blog.360.yahoo.com/blog-FjRegnAjcqUVCckOqAx8VkkvaNGaD4Q-?cq=1";
         }         
      case 4:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "I've learned that people will forget what you said, people will forget what you did, but people will never forget how you made them feel.";
            case cGAB_RandomQuote_AUTHOR: return "Maya Angelou";
            case cGAB_RandomQuote_SOURCE: return "";
            case cGAB_RandomQuote_WIKI: return "";
         }         
      case 5:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "99% of the failures come from people who have the habit of making excuses.";
            case cGAB_RandomQuote_AUTHOR: return "George Washington Carver";
            case cGAB_RandomQuote_SOURCE: return "";
            case cGAB_RandomQuote_WIKI: return "";
         }         
      case 6:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "If you is who you ain't, then you ain't who you is.";
            case cGAB_RandomQuote_AUTHOR: return "Mrs. Jenkins";
            case cGAB_RandomQuote_SOURCE: return "";
            case cGAB_RandomQuote_WIKI: return "";
         }         
      case 7:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "Saint, n. a dead sinner revised and edited.";
            case cGAB_RandomQuote_AUTHOR: return "Ambrose Bierce";
            case cGAB_RandomQuote_SOURCE: return "The Devil&#039;s Dictionary [1906]";
            case cGAB_RandomQuote_WIKI: return "http://en.wikipedia.org/wiki/Ambrose_Bierce";
         }         
      case 8:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "It is not the hand but the understanding of a man that may be said to write.";
            case cGAB_RandomQuote_AUTHOR: return "Miguel de Cervantes";
            case cGAB_RandomQuote_SOURCE: return "Don Quixote, Pt. II [1615], bk. III, author's preface, p. 441";
            case cGAB_RandomQuote_WIKI: return "http://en.wikipedia.org/wiki/Miguel_de_Cervantes";
         }         
      case 9:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "Success is the child of audacity.";
            case cGAB_RandomQuote_AUTHOR: return "Benjamin Disraeli";
            case cGAB_RandomQuote_SOURCE: return "";
            case cGAB_RandomQuote_WIKI: return "";
         }         
      case 10:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "If you do not understand White Supremacy (Racism) What it is, and how it works everything else that you understand, will only confuse you.";
            case cGAB_RandomQuote_AUTHOR: return "Dr. Neely Fuller, Jr.";
            case cGAB_RandomQuote_SOURCE: return "";
            case cGAB_RandomQuote_WIKI: return "";
         }         
      case 11:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "Education is the passport to the future, for tomorrow belongs to those who prepare for it today.";
            case cGAB_RandomQuote_AUTHOR: return "Malcolm X";
            case cGAB_RandomQuote_SOURCE: return "";
            case cGAB_RandomQuote_WIKI: return "";
         }         
      case 12:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "You're not supposed to be so blind with patriotism that you can't face reality. Wrong is wrong, no matter who says it.";
            case cGAB_RandomQuote_AUTHOR: return "Malcolm X";
            case cGAB_RandomQuote_SOURCE: return "";
            case cGAB_RandomQuote_WIKI: return "";
         }         
      case 13:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "Don't be in a hurry to condemn because he doesn't do what you do or think as you think or as fast. There was a time when you didn't know what you know today.";
            case cGAB_RandomQuote_AUTHOR: return "Malcolm X";
            case cGAB_RandomQuote_SOURCE: return "";
            case cGAB_RandomQuote_WIKI: return "";
         }         
      case 14:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "Individual rights are not subject to a public vote; a majority has no right to vote away the rights of a minority; the political function of rights is precisely to protect minorities from oppression by majorities (and the smallest minority on earth is the individual).";
            case cGAB_RandomQuote_AUTHOR: return "Ayn Rand";
            case cGAB_RandomQuote_SOURCE: return "";
            case cGAB_RandomQuote_WIKI: return "";
         }         
      case 15:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "It's not that you were the sharpest pencil in the drawer, any would have done. I just happened to pick you.";
            case cGAB_RandomQuote_AUTHOR: return "God.";
            case cGAB_RandomQuote_SOURCE: return "Gerald Nunnally to his son in discussing God's relationship with us.";
            case cGAB_RandomQuote_WIKI: return "";
         }         
      case 16:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "The supreme happiness of life is the conviction that we are loved.";
            case cGAB_RandomQuote_AUTHOR: return "Victor Hugo";
            case cGAB_RandomQuote_SOURCE: return "Les Mis&#233;rables [1862]. Fantine, bk. V, ch. 4";
            case cGAB_RandomQuote_WIKI: return "http://en.wikipedia.org/wiki/Victor_Hugo";
         }         
      case 17:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "When the people of the world all know beauty as beauty, there arises the recognition of ugliness. When they all know the good as good, there arises the recognition of evil.";
            case cGAB_RandomQuote_AUTHOR: return "Lao-tzu";
            case cGAB_RandomQuote_SOURCE: return "The Way of Lao-tzu, 2";
            case cGAB_RandomQuote_WIKI: return "http://en.wikipedia.org/wiki/Laozi";
         }         
      case 18:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "Education has produced a vast population able to read but unable to distinguish what's worth reading.";
            case cGAB_RandomQuote_AUTHOR: return "G. M. Trevelyan";
            case cGAB_RandomQuote_SOURCE: return "";
            case cGAB_RandomQuote_WIKI: return "";
         }         
      case 19:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "A government is the most dangerous threat to man's rights: it holds a legal monopoly on the use of physical force against legally disarmed victims.";
            case cGAB_RandomQuote_AUTHOR: return "Ayn Rand";
            case cGAB_RandomQuote_SOURCE: return "";
            case cGAB_RandomQuote_WIKI: return "";
         }         
      case 20:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "Art is a collaboration between God and the artist, and the less the artist does the better.";
            case cGAB_RandomQuote_AUTHOR: return "Andre Gide";
            case cGAB_RandomQuote_SOURCE: return "";
            case cGAB_RandomQuote_WIKI: return "";
         }   
      case 21:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "Everyone thinks of changing the world, but no one thinks of changing himself.";
            case cGAB_RandomQuote_AUTHOR: return "Leo Tolstoy";
            case cGAB_RandomQuote_SOURCE: return "";
            case cGAB_RandomQuote_WIKI: return "";
         } 
      case 22:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "Another flaw in the human character is that everybody wants to build and nobody wants to do maintenance.";
            case cGAB_RandomQuote_AUTHOR: return "Kurt Vonnegut";
            case cGAB_RandomQuote_SOURCE: return "";
            case cGAB_RandomQuote_WIKI: return "";
         }    
      case 23:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "When everyone is against you, it means that you are absolutely wrong - or absolutely right.";
            case cGAB_RandomQuote_AUTHOR: return "Albert Guinon";
            case cGAB_RandomQuote_SOURCE: return "";
            case cGAB_RandomQuote_WIKI: return "";
         }     
      
      default:
         switch(iItem) {
            case cGAB_RandomQuote_QUOTE: return "Out of range error in javascript.";
            case cGAB_RandomQuote_AUTHOR: return "ERROR";
            case cGAB_RandomQuote_SOURCE: return "Out of range.";
            case cGAB_RandomQuote_WIKI: return "http://gregbecerra.blogspot.com/";
         }         
   }
}

function fnGAB_RandomQuote_GetMin() {
   return 1;
}
function fnGAB_RandomQuote_GetMax() {
   return 20;
}
function fnGAB_RandomQuote_Randomize(iMin,iMax,bDebug){

   if(bDebug) document.write('Entered Randomize()' + '<br/>');
   if(bDebug) document.write('iMin = ' + iMin + '<br/>');
   if(bDebug) document.write('iMax = ' + iMax + '<br/>');

   var iScriptMin = fnGAB_RandomQuote_GetMin();
   if(bDebug) document.write('iScriptMin = ' + iScriptMin + '<br/>');

   var iScriptMax = fnGAB_RandomQuote_GetMax();
   if(bDebug) document.write('iScriptMax = ' + iScriptMax + '<br/>');
   
   if(iMin <= 0) {
      iMin = iScriptMin;
      if(bDebug) document.write('Zero: using default Min' + '<br/>');
   }
   else if(iMin < iScriptMin) {
      iMin = iScriptMin; 
      if(bDebug) document.write('Underflow: using default Min' + '<br/>');
   }
   else if(iMin > iScriptMax) {
      iMin = iScriptMax;
      if(bDebug) document.write('Overflow: using default Max' + '<br/>');
   }
   if(bDebug) document.write('iMin = ' + iMin + '<br/>');
   
   if(iMax <= 0) {
      iMax = iScriptMax;
      if(bDebug) document.write('Zero: using default Max' + '<br/>');
   }
   else if(iMax < iMin) {
      iMax = iMin;
      if(bDebug) document.write('Underflow: using Min' + '<br/>');
   }
   else if(iMax > iScriptMax) {
      iMax = iScriptMax;      
      if(bDebug) document.write('Overflow: using default Max' + '<br/>');
   }
   if(bDebug) document.write('iMax = ' + iMax + '<br/>');
   
   if(iMin == iMax) {
      iResult=iMin;
   }
   else {

      var iRange = (iMax + 1) - iMin;
      if(bDebug) document.write('iRange = ' + iRange + '<br/>');

      var iResult=Math.floor(Math.random()*iRange)+iMin;
   }
   if(bDebug) document.write('iResult = ' + iResult + '<br/>');

   if(bDebug) document.write('Leaving Randomize()' + '<br/>');
   return iResult;
}
function fnGAB_RandomQuote_GetQuote(iItem, bDebug) {
   return fnGAB_RandomQuote_Array(iItem, cGAB_RandomQuote_QUOTE, bDebug);
}
function fnGAB_RandomQuote_GetAuthor(iItem, bDebug) {
   return fnGAB_RandomQuote_Array(iItem, cGAB_RandomQuote_AUTHOR, bDebug);
}
function fnGAB_RandomQuote_GetSource(iItem, bDebug) {
   return fnGAB_RandomQuote_Array(iItem, cGAB_RandomQuote_SOURCE, bDebug);
}
function fnGAB_RandomQuote_GetWiki(iItem, bDebug) {
   return fnGAB_RandomQuote_Array(iItem, cGAB_RandomQuote_WIKI, bDebug);
}
function fnGAB_RandomQuote_Show(bShowTitle, sTitle, sTitleElement,
                                sTitleClass, sTitleStyle,
                                sQuoteClass, sQuoteStyle, 
                                sAuthorClass, sAuthorStyle,
                                iMin, iMax, bShowNumber, bShowSource, bDebug) {

   // PARAMETER DEFINITIONS
   // bShowTitle: boolean, 1=show title, 0=hide
   // sTitle: string, user supplied title, empty="Random Quotes"
   // sTitleElement: string, user supplied element, empty="<h2>"
   // sTitleClass: string, user supplied CSS class
   // sTitleStyle: string, user supplied CSS
   // sQuoteClass: string, user supplied CSS class
   // sQuoteStyle: string, user supplied CSS
   // sAuthorClass: string, user supplied CSS class
   // sAuthorStyle: string, user supplied CSS
   // iMin: start number, 0=default minimum
   // iMax: end number, 0=default maximum
   // bShowNumber: boolean, 1=show quote number, 0=hide
   // bShowSource: boolean, 1=show source link, 0=hide
   // bDebug: boolean, 1=show debug comments, 0=hide
   
   if(bDebug) document.write("Entered Show()" + "<br/>");
   if(bDebug) document.write("bShowTitle = " + bShowTitle + "<br/>");
   if(bDebug) document.write("sTitle = " + sTitle + "<br/>");
   if(bDebug) document.write("sTitleElement = " + sTitleElement + "<br/>");
   if(bDebug) document.write("sTitleClass = " + sTitleClass + "<br/>");
   if(bDebug) document.write("sTitleStyle = " + sTitleStyle + "<br/>");
   if(bDebug) document.write("sQuoteClass = " + sQuoteClass + "<br/>");
   if(bDebug) document.write("sQuoteStyle = " + sQuoteStyle + "<br/>");
   if(bDebug) document.write("sAuthorClass = " + sAuthorClass + "<br/>");
   if(bDebug) document.write("sAuthorStyle = " + sAuthorStyle + "<br/>");
   if(bDebug) document.write("iMin = " + iMin + "<br/>");
   if(bDebug) document.write("iMax = " + iMax + "<br/>");
   if(bDebug) document.write("bShowNumber = " + bShowNumber + "<br/>");
   if(bDebug) document.write("bShowSource = " + bShowSource + "<br/>");
   if(bDebug) document.write("bDebug = " + bDebug + "<br/>");
   
   var iSelection = fnGAB_RandomQuote_Randomize(iMin,iMax,bDebug);
   
   // ********** WRITE TITLE **********
   if(bShowTitle) {
      document.write("<div><");
      
      if(sTitleElement == '')
         document.write("h2");
      else
         document.write(sTitleElement);

      if(sTitleClass != '')
         document.write(" class='" + sTitleClass + "'");
      
      if(sTitleStyle != '')
         document.write(" style='" + sTitleStyle + "'");
   
      document.write(">");
                 
      if(sTitle == '')
         document.write("Random Quotes");
      else
         document.write(sTitle);
         
      document.write("</");
      
      if(sTitleElement == '')
         document.write("h2");
      else
         document.write(sTitleElement);

      document.write("></div>");
   }
   
   // ********** START MAIN **********
   document.write("<div style='cursor:help;' title='" + fnGAB_RandomQuote_GetSource(iSelection, bDebug) + "'>");
   
   // ********** WRITE QUOTE **********
   document.write("<p");
   
   if(sQuoteClass != '')
      document.write(" class='" + sQuoteClass + "'");
      
   if(sQuoteStyle != '')
      document.write(" style='" + sQuoteStyle + "'");   
   
   document.write(">");
   
   if(bShowNumber) 
      document.write(iSelection + ". ");
      
   document.write("&quot;" + fnGAB_RandomQuote_GetQuote(iSelection, bDebug) + "&quot;</p>");
   
   // ********** WRITE AUTHOR **********
   document.write("<p");
   
   if(sAuthorClass != '')
      document.write(" class='" + sAuthorClass + "'");
      
   document.write(" style='cursor:pointer;text-align:right;font-size:120%;");
   
   if(sAuthorStyle != '')
      document.write(sAuthorStyle);
      
   document.write("'>&#151;<a href='" + fnGAB_RandomQuote_GetWiki(iSelection, bDebug) + "'");
   document.write(" title='" + fnGAB_RandomQuote_GetAuthor(iSelection, 0) + " on Wikipedia'>");
   document.write(fnGAB_RandomQuote_GetAuthor(iSelection, bDebug));
   document.write("</a></p>");
   
   if(bShowSource) {
      document.write("<p style='font-family:Verdana;font-size:6.5pt;text-align:center;margin-bottom:0px;padding-bottom:0px;'>");
      document.write("<a href='http://gregbecerra.blogspot.com/2008/01/random-quotes.html'");
      document.write(" title='Get Random Quotes for your blog or website at Greg&#039;s Brain'");
      document.write("><i></i></a>");
      document.write("</p>");
   }
   
   document.write("</div>");
   
   // ********** END MAIN **********
   
   if(bDebug) document.write("Leaving Show()" + "<br/>");
}
function fnGAB_RandomQuote_ShowDefault() {
   fnGAB_RandomQuote_Show(0, '', '', '', '', '', '', '', '', 0, 0, 0, 1, 0);
}
function fnGAB_RandomQuote_ShowDefaultNL() {
   fnGAB_RandomQuote_Show(0, '', '', '', '', '', '', '', '', 0, 0, 0, 0, 0);
}
function fnGAB_RandomQuote_ShowTest() {
   fnGAB_RandomQuote_Show(1, 'Random Quotes', 'h2', 'title', '', '', '', '', '', 0, 0, 1, 1, 0);
}
function fnGAB_RandomQuote_Dump(bDebug) {
   
   if(bDebug) document.write("Entered Dump()");
   
   var iMin = fnGAB_RandomQuote_GetMin();
   if(bDebug) document.write("iMin = " + iMin + "<br/>");

   var iMax = fnGAB_RandomQuote_GetMax();
   if(bDebug) document.write("iMax = " + iMax + "<br/>");
   
   for(i=iMin; i<=iMax; i++) 
      fnGAB_RandomQuote_Show(0, '', '', '', '', '', '', '', '', i, i, 1, 0, bDebug);
      
   if(bDebug) document.write("Leaving Dump()");
}
