/*
   JavaScript utility functions
   author: Klaus Hildner, klaus@hildner.de, http://www.hildner.de
   feel free to reuse code
*/

// define constants

COLOR_TEXT = "#a0a0a0"; // nicely grey
COLOR_BGCOLOR = "#000000"; // black magic

//--------------------------------------------------------------------------------------

function init() { // runs initially
   if(top.frames.length == 0)
      loadFrameset();
} // init

//--------------------------------------------------------------------------------------

// opens an image in a new window ...

function openWindow(URL, width, height) {
   if(null == width)
      width = 1024;
   if(null == height)
      height = 768;
   win = window.open(URL, '', 'WIDTH=' + width + ',HEIGHT=' + height + ',RESIZABLE=YES,LEFT=20,TOP=20,SCROLLBARS=NO');
   win.focus();
   return(win);
} // openWindow

// ... or opens an image in a new document inside an existing window

function openImage(URL, altText) {
   if(null == altText)
      altText = '';

   var sNoPopup = '';
   sNoPopup = '<html><head></head>\n'
     + '<body text="' + COLOR_TEXT + '" BGCOLOR="' + COLOR_BGCOLOR + '">\n'
     + '<table width="100%" height="100%"><tr><td align="center" valign="center">\n'
     + '<a href="javascript:history.back()"><img src="'
     + URL + '" onMouseOver="{window.status=\'click on image to return\';return true}"'
     + ' alt="' + altText + '" border=0></a>\n'
     + '</td></tr></table>\n'
     + '</body></html>\n';

   var sPopup = '';
   sPopup = '<html><head><title>' + URL + '</title></head>\n'
     + '<body onLoad="window.opener.parent.source.adjustSize(this, \'' + URL + '\', \'' + altText + '\')" text="' + COLOR_TEXT + '" bgcolor="' + COLOR_BGCOLOR + '" topmargin="0" leftmargin="0">\n'
     + '<table width="100%" height="100%"><tr><td align="center" valign="center">\n'
     + '<a href=\"javascript:close()\"><img src=\"'
     + URL + '\" onMouseOver=\"{window.status=\'click on image to return\';return true}\"'
     + ' alt=\"' + altText + '\" border=0></a>\n'
     + '</td></tr></table>\n'
     + '</body></html>\n';

   if(parent.source.isPopup == null)
      alert('! parent.source.isPopup == null'); // error condition

   if(! parent.source.isPopup) {
      document.open();
      document.writeln(sNoPopup);
      document.close();
   } // if
   else {
      var res = parent.source.res;
      var width = 1024;
      var height = 768;

      if(res == 0) { // 640x480
         width = 640;
         height = 480;
      } else
      if(res == 1) { // 800x600
         width = 800;
         height = 600;
      } else
      if(res == 2) { // 1024x768
         width = 1024;
         height = 768;
      } else
      if(res == 3) { // 1280x1024
         width = 1280;
         height = 1024;
      } else
      if(res == 4) { // 1600x1200
         width = 1600;
         height = 1200;
      } else { // error
         width = 640;
         height = 480;
      } // else

      // var win = window.open('', (parent.source.imageCounter++) + "x", 'width=1044,height=788,resizable=yes,left=20,top=20,right=20,bottom=20,scrollbars=auto,titlebar=no');
      var win = window.open('', (parent.source.imageCounter++) + 'x', 'width=' + width + ',height=' + height + ',resizable=yes,left=20,top=20,right=20,bottom=20,scrollbars=no,titlebar=no');
      win.document.open;
      win.document.writeln(sPopup);
      win.document.close();
      win.focus();

      // now wait for callback in adjustSize
   } // else
} // openImage

function openImage2(URL, altText, width, height) {
   if(altText == null)
      altText = '';

   var s = '';
   s = '<HTML><HEAD></HEAD>\n'
     + '<BODY TEXT=\"#A0A0A0\" BGCOLOR=\"#000000\">\n'
     + '<A HREF=\"JavaScript:history.back()\"><IMG SRC=\"'
     + URL + "\" onMouseOver=\"{window.status='click on image to return';return true}\""
     + ' ALT=\"' + altText + '\" BORDER=0></A>\n'
     + '</BODY></HTML>';

   if(width == null)
      width = 1024;
   if(height == null)
      height = 768;

   win = window.open("", "", "WIDTH=" + width + ",HEIGHT=" + height + ",RESIZABLE=YES,LEFT=5,TOP=5,SCROLLBARS=YES");
   win.focus();

   win.document.open();
   win.document.write(s);
   win.document.close();
} // openImage2

function jump(me) {
   // alert(me.options[me.selectedIndex].value);
   window.location = me.options[me.selectedIndex].value;
} // jump

function adjustSize(win, URL, altText) { // callback function
   var sPopup = '';
   sPopup = '<html><head><title>' + URL + '</title></head>\n'
     + '<body text="' + COLOR_TEXT + '" bgcolor="' + COLOR_BGCOLOR + '" topmargin="0" leftmargin="0">\n'
     + '<table width="100%" height="100%"><tr><td align="center" valign="center">\n'
     + '<a href=\"javascript:close()\"><img src=\"'
     + URL + '\" onMouseOver=\"{window.status=\'click on image to return\';return true}\"'
     + ' alt=\"' + altText + '\" border=0></A>\n'
     + '</td></tr></table>\n'
     + '</body></html>\n';

   // resize window
   // win.resizeTo(win.document.images[0].width + 45, win.document.images[0].height + 65);
   var res = parent.source.res;
   var width = 1024;
   var height = 768;

   if(res == 0) { // 640x480
      width = 640;
      height = 480;
   } else
   if(res == 1) { // 800x600
      width = 800;
      height = 600;
   } else
   if(res == 2) { // 1024x768
      width = 1024;
      height = 768;
   } else
   if(res == 3) { // 1280x1024
      width = 1280;
      height = 1024;
   } else
   if(res == 4) { // 1600x1200
      width = 1600;
      height = 1200;
   } else { // error
      width = 640;
      height = 480;
   } // else

   var width2 = win.document.images[0].width + 45;
   var height2 = win.document.images[0].height + 65;
   var needScrollbars = false;
   if(width < width2) {
      width2 = width; // limit size
      needScrollbars = true;
   } // if
   if(height < height2) {
      height2 = height; // limit size
      needScrollbars = true;
   } // if

   if(! needScrollbars) {
      win.resizeTo(width2, height2); // just resize it
   } // if
   else {
      // was wrong now that we do know the image dimension
      // redo this thing with scrollbars (there is no scrollbars=auto)
      win.close();
      win = window.open('', (parent.source.imageCounter++) + 'x', 'width=' + width2 + ',height=' + height2 + ',resizable=yes,left=20,top=20,right=20,bottom=20,scrollbars=yes,titlebar=no');
      win.document.open;
      win.document.writeln(sPopup);
      win.document.close();         
      win.focus();
   } // else
} // adjustSize

//--------------------------------------------------------------------------------------

function printFooter(subject) {
   // precompute author substring
   if(null == subject)
      subject = 'your web site http://www.hildner.de';
   var author = '<A HREF=\"mailto:klaus@hildner.de (Klaus Hildner)?subject=' + subject + '\">Klaus&nbsp;Hildner</A>';

   // precompute frame target
   var target = "";
   target = ' target="inhalt"';

   var s = '';
   s = '<HR>\n'
     + '<A NAME=\"bottom\"></A>\n'
     + '<TABLE WIDTH="100%"><TR><TD VALIGN=TOP ALIGN=LEFT>' // ** left **
     + '<SCRIPT LANGUAGE=\"javascript\">\n'
     + '<!-- begin script hiding\n'
     + 'var alertMsg ="date last modified";\n'

     + 'document.writeln("<small><a href=\'javascript:\' onMouseOver=\''
     + '{window.status=alertMsg;return true}'
     + '\'>" + new Date(document.lastModified).toGMTString() + "</a></small>")\n'

     + '// end script hiding -->\n'
     + '</SCRIPT>\n'
     + '&#8226;\n'
     + '<small><a href="/html/copyright.html"' + target + '>&copy;&nbsp;2000&nbsp;&#8212;&nbsp;2010</a> by ' + author + '</small>\n'
     + '&#8226;\n'
     + '<small><a href="/html/legal.html"' + target + '>legal&nbsp;info</a></small>\n';

   s += '</TD></TR></TABLE>';

   /*
   // google ads begin
   s += '<script type="text/javascript"\n';
   s += 'src="http://pagead2.googlesyndication.com/pagead/show_ads.js">\n';
   s += '</script>\n';
   // google ads end
   */

   /*
   s += '<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">\n';
   s += '</script>\n';
   s += '<script type="text/javascript">\n';
   s += '_uacct = "UA-288241-2";\n';
   s += 'urchinTracker();\n';
   s += '</script>\n';
   */

   document.writeln(s);
} // printFooter

function printTop() {
   var s = '';
   s = '<SMALL>\n'
     + '[<A HREF="#top">top</A>]\n'
     + '</SMALL>';

   document.writeln(s);
} // printTop

function printHome() {
   var s = '';
   s = '<SMALL>\n'
     + '[<A HREF="/html/main-content.html">home</A>]\n'
     + '</SMALL>';

   document.writeln(s);
} // printHome

function printPrev(link, text, textOnMouseOver) {
   if(null == link)
      link = 'javascript:history.back()';
   if(null == text)
      text = 'prev';
   if(null == textOnMouseOver)
      textOnMouseOver = 'go back to previous page';

   var s = '';
   s = '<SMALL>\n'
     + '[<A HREF="' + link + '" onMouseOver=\"{window.status=\'' + textOnMouseOver
     + '\';return true}\">&lt;&nbsp;' + text + '</A>]\n'
     + '</SMALL>';

   document.writeln(s);
} // printPrev

function printNext(link, text, textOnMouseOver) {
   if(null == link)
      link = 'javascript:history.next()';
   if(null == text)
      text = 'next';
   if(null == textOnMouseOver)
      textOnMouseOver = 'go forward to next page';

   var s = '';
   s = '<SMALL>\n'
     + '[<A HREF="' + link + '" onMouseOver=\"{window.status=\'' + textOnMouseOver
     + '\';return true}\">' + text + '&nbsp;&gt;</A>]\n'
     + '</SMALL>';

   document.writeln(s);
} // printNext

function printPrev_de(link, text, textOnMouseOver) {
   if(null == link)
      link = 'javascript:history.back()';
   if(null == text)
      text = 'zur&uuml;ck';
   if(null == textOnMouseOver)
      textOnMouseOver = 'gehe zur&uuml;ck zur vorherigen Seite';

   var s = '';
   s = '<SMALL>\n'
     + '[<A HREF="' + link + '" onMouseOver=\"{window.status=\'' + textOnMouseOver
     + '\';return true}\">&lt;&nbsp;' + text + '</A>]\n'
     + '</SMALL>';

   document.writeln(s);
} // printPrev_de

function printNext_de(link, text, textOnMouseOver) {
   if(null == link)
      link = 'javascript:history.next()';
   if(null == text)
      text = 'vorw&auml;rts';
   if(null == textOnMouseOver)
      textOnMouseOver = 'gehe vorw&auml;rts zur n&auml;chsten Seite';

   var s = '';
   s = '<SMALL>\n'
     + '[<A HREF="' + link + '" onMouseOver=\"{window.status=\'' + textOnMouseOver
     + '\';return true}\">' + text + '&nbsp;&gt;</A>]\n'
     + '</SMALL>';

   document.writeln(s);
} // printNext_de

function printMore(link, text, textOnMouseOver) {
   if(null == link)
      link = 'javascript:history.next()';
   if(null == text)
      text = 'more';
   if(null == textOnMouseOver)
      textOnMouseOver = 'show me more';

   var s = '';
   s = '<SMALL>\n'
     + '[<A HREF="' + link + '" onMouseOver=\"{window.status=\'' + textOnMouseOver
     + '\';return true}\">' + text + '&nbsp;&gt;</A>]\n'
     + '</SMALL>';

   document.writeln(s);
} // printMore

function printMore_de(link, text, textOnMouseOver) {
   printMore(link, 'weiter', 'zeig mir mehr');
} // printMore_de

function printHome(text, textOnMouseOver) {
   if(null == text)
      text = 'home';
   if(null == textOnMouseOver)
      textOnMouseOver = 'go back home';

   var s = '';
   s = '<SMALL>\n'
     + '[<A HREF="/html/main-content.html" onMouseOver=\"{window.status=\'' + textOnMouseOver
     + '\';return true}">' + text + '</A>]\n'
     + '</SMALL>';

   document.writeln(s);
} // printHome

function printLink(URL, text, textOnMouseOver) {
   if(null == URL)
      alert('printLink(): ERROR: no URL specified!');
   if(null == text)
      alert('printLink(): ERROR: no text specified!');
   if(null == textOnMouseOver)
      textOnMouseOver = text;

   var s = '';
   s = '<SMALL>\n'
     + '[<A HREF="' + URL + '" onMouseOver=\"{window.status=\'' + textOnMouseOver
     + '\';return true}">' + text + '</A>]\n'
     + '</SMALL>';

   document.writeln(s);
} // printLink

function printTopHome() {
   printTop();
   printHome();
} // printTopHome

function printHeader(prevText, nextText) {
   printPrev(prevText);
   printNext(nextText);
   printHome();
} // printHeader

//--------------------------------------------------------------------------------------

function shake(n) {
   if(parent.moveBy)
      for (i = 10; i > 0; i--)
         for (j = n; j > 0; j--) {
            parent.moveBy(0,i)
            parent.moveBy(i,0)
            parent.moveBy(0,-i)
            parent.moveBy(-i,0)
         } // for
} // shake

//--------------------------------------------------------------------------------------

function loadFrameset() {
   top.location = '/html/main.html?' + self.location;
} // loadFrameset

function loadFile(mFile) {
   if(mFile == null)
      mFile = "/html/main-content.html"

   parent.frames['inhalt'].document.location = mFile;
} // loadFile

/*
function loadFileInFrame(mFile) {
   top.location.href = '/html/main.html'; // rewrite whole thing
   waitFrame('top.frame[\'source\'].loadFile(\'' + mFile + '\')'); // add content frame
} // loadFileInFrame

function waitFrame(expr) { // found on http://www.bath.ac.uk/~ccsnad/java/jsfaq.html#framesync
   // does not work if current document is replaced (I think)!
   // if(! top.loadDone) {
   if(! top.frames['inhalt']) {
      // XXX expr had better not contain unescaped single quotes!
      setTimeout("waitFrame('" + expr + "')", 500) // retry every 500 ms
      // setTimeout('waitFrame("' + expr + '")', 500); // retry every 500 ms
   } else {
      eval(expr);
   } // else
} // waitFrame
*/

function printPersonalDropdown(n) {
   a = new Array(38);

   a[0] = 'I.html';
   a[1] = 'me, myself, + I';
   a[2] = 'baby.html';
   a[3] = '- baby';
   a[4] = 'child.html';
   a[5] = '- child';
   a[6] = 'school.html';
   a[7] = '- school';
   a[8] = 'student.html';
   a[9] = '- student';
   a[10] = 'tp.html';
   a[11] = '- tradingproduce.com';
   a[12] = 'wedding.html';
   a[13] = '- wedding';
   a[14] = 'sf.html';
   a[15] = '- San Francisco';
   a[16] = 'bm.html';
   a[17] = '- Burning Man';
   a[18] = 'rafting.html';
   a[19] = '- rafting';
   a[20] = 'paradise.html';
   a[21] = '- paradise';
   a[22] = 'mbike.html';
   a[23] = '- mountain biking';
   a[24] = 'sgermany.html';
   a[25] = '- back home';
   a[26] = 'gbritain.html';
   a[27] = '- Great Britain';
   a[28] = 'frankfurt.html';
   a[29] = '- Frankfurt';
   a[30] = 'crete.html';
   a[31] = '- Crete';
   a[32] = 'tunisia.html';
   a[33] = '- Tunisia';
   a[34] = 'nl.html';
   a[35] = '- Netherlands';
   a[36] = 'italy.html';
   a[37] = '- Italy';

   var s = '';
   s = '<form name="jumpdummy">\n'
     + '<select name="jumplist" onChange="jump(this)" style="font-size: 9; background: #000000; color: #a0a0a0">\n';

   for(i = 0; i <= 38; i += 2) {
      s += '<option value="' + a[i] + '"';
      if(i / 2 + 1 == n)
         s += ' selected';
      s += '>' + a[i + 1] + '</option>\n';
   } // for

   s += '</select>\n'
     + '</form>\n';

   document.writeln(s);
} // printPersonalDropdown

// include some cookie routines + maybe some routines for sorting etc.

// <xxx script type="text/javascript"><xxx !--
google_ad_client = "pub-0335693363861472";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_channel ="6263760941";
google_page_url = document.location;
google_color_border = "333333";
google_color_bg = "000000";
google_color_link = "FFFFFF";
google_color_url = "999999";
google_color_text = "CCCCCC";
//--xxx></xxx script>
// <xxxscript type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
// <xxx /script>

init();

