// =======================================================================
// Modified Copy of TechTSP's MASTER_FILES/index.js
// =======================================================================
// global state/variables: must be set before calling qs_start_doc
// most are kept the same for all page sets 
//
// CONVENTIONS: 
// -----------
// IMAGES: 
//   img directory for images 
//   img/trans.gif: transparent one pixel image 
//   img/qsbg.jpg: height 1px, width=real wide, 2pixel in color scheme color
//   img/qslogo.jpg:  logo adapted to color scheme 
//
// COLOR VARIABLES 
//   var qs_page_color: scheme's foreground color 
//   var qs_link_color: scheme's foreground color
//   var qs_link_hover: color sufficiently diffent from foregound color
//   var qs_background_color: color scheme foreground color 
//   var qs_background:  color used for off white background in background image
// 	img/qspagecolor.jpg 1 pixel in color scheme color 
//
// MENU
//   the menu is build on the basis of the global qs_menu_target array variable
//   the function qs_build_menu_table builds the main menu on the left of the 
//   web page, qs_menu_across builds the menu references at the bottom of the 
//   page.  qs_location and qs_location_ref are helper fcts. All these functions//   are specific to page sets (Sweden has its own, so does Concorde, ....)
// 
// A minimal web page with menu is build as follows: 
//    1) include this file 
//    2) add script section with: 
//            qs_path = <PATH to this file";
//            qs_doc_start('Menu Item', 'Submenuitem');
//            qs_body_start(true);
//            html();
//    3) page contents 
//    4) script section with 
//            qs_doc_finish("DATE"); 
//            html(); 
// 
// A minimal web page without menu is build as follows: 
//    1) include this file 
//    2) add script section with: 
//            qs_path = <PATH to this file";
//            qs_img_doc_start('Menu Item', 'Submenuitem', 'headline');
//            html();
//    3) page contents 
//    4) script section with 
//            qs_img_doc_finish("DATE");
//            html(); 
//
// optionally the following functions may be called: 
//   qs_doc_title(text)   == set the title to text instead of default string
//   qs_doc_headline(text) == underline headline at beginning of page contents
//
//   qs_spacer_row(w, h) == add a transparent spacer row, sizes are in pixels
//                          maybe called just before qs_doc_finish
//   qs_menu_set_bling_html(html) == insert html above menu 
// ---------------------------------------------------------------------


// ---------------------------------------------------------------------
// these variables are rarely changed 
var qs_trans_img = 'img/trans.gif'; 
var qs_width = 800;

// qspath the path to this file relative to the including file 
var qs_path = '.'; 

var qs_menu_bling_bling; 

function qs_init_vars(menu_loc, sub_menu_loc, tit)
{
   qs_background_img = qs_path + '/' + qs_background_img;
   qs_logo_img = qs_path + '/' + qs_logo_img;
   qs_color_img = qs_path + '/' + qs_color_img;
   qs_trans_img = qs_path + '/' + qs_trans_img;
   qs_my_location = qs_location(menu_loc, sub_menu_loc);
   qs_my_menu = menu_loc; 
   qs_my_sub_menu = sub_menu_loc; 
}

// ---------------------------------------------------------------------
// Menu definition
// is the same for a whole set of pages such as Concorde/Sweden/...
// is specific to each set of pages 
// ---------------------------------------------------------------------
var qs_menu_target = new Array(); 


// PRIVATE (specific to page set)  
function qs_menu_across() 
{
   cur_loc = qs_location(qs_my_menu, qs_my_sub_menu); 
   wd(qs_menu_ref(cur_loc, qs_location('Home', undefined), 
	       'Home')); 
   wd(qs_font_color() + ' | </font>'); 
   wd(qs_menu_ref(cur_loc, qs_location('TSP Games', undefined), 'TSP Games')); 
}

// PRIVATE (specific to page set)  
function qs_location(item_text, sub_item_text ) 
{
   loc = 'Home';
   if (item_text != 'Home')  {
      loc +=  ' > ' + item_text;
   }
   if (sub_item_text != undefined)  {
      loc += ' > ' + sub_item_text; 
   } 
   return loc; 
}

// PRIVATE (specific to page set)  
function qs_location_ref(item_text, sub_item_text) 
{
   loc = qs_location('Home', undefined); 
   s = qs_menu_ref(qs_my_location, loc, 'Home'); 

   if (item_text != 'Home')  {
      loc = qs_location(item_text, undefined); 
      s += ' > ' + qs_menu_ref(qs_my_location, loc, item_text); 
   }
   if (sub_item_text != undefined) { 
      loc = qs_location(item_text, sub_item_text); 
      s += ' > ' + qs_menu_ref(qs_my_location, loc, sub_item_text);
   }
   return s; 
}

function qs_games_doc_start(title, subtitle) 
{
   qs_doc_start(title, subtitle); 
}

// =======================================================================
// =======================================================================
// =======================================================================
// from here on it's the same for all page sets 
// -----------------------------------------------------------------------

// -----------------------------------------------------------------------
// always need an undefined 
// -----------------------------------------------------------------------
var undefined; 

// ---------------------------------------------------------------------------
// table 
// ---------------------------------------------------------------------------
var number_of_open_tables = 0; 
function qs_table_start(border, w, extra) 
{
   number_of_open_tables = number_of_open_tables + 1;
   width = ""; 
   if (w != undefined) {
      width = " width=" + w + "px"; 
   }
   if (extra == undefined) { extra = ""; }
   s = '<table cellpadding=0 cellspacing=0 vspace=0 hspace=0' +
       ' border=' + border + 'px ' + width + " " + extra + ">";
   return s; 
}

function qs_table_finish() 
{
   number_of_open_tables--; 
   return "</table>"; 
}

function qs_row_spacer(h) 
{
   return '<tr>' + 
      '<td><img src=' + qs_trans_img + ' height=' + h + 'px ' + '></td>' + 
      '</tr>';
}

function qs_col_spacer(w, h, colsp)
{
   var span = ''; 
   if (colsp != undefined && colsp != 1) span = ' colspan=' + colsp; 
   return('<td' + span + '><img src=' + qs_trans_img + ' height=' + h + 'px ' + 
			 'width=' + w + 'px></td>');
}

// ----------------------------------------------------------------------------
// generators for <a href= ....
// ----------------------------------------------------------------------------
function qs_go_back_ref(txt) 
{
  return "<a href=javascript:history.back();>" + txt + "</a>"; 
} 

function qs_ref(text, target, status) 
{
   s = "<a href='" + target + "'";
   if (status != undefined) {   
     s += ' onMouseOver="window.status=\'' + status + '\'; return true;" ' +
	' onMouseOut="window.status=\'' + qs_my_location + '\'; return true;"';
   }
   s += ">" + text + "</a>"; 
   return s;
} 

function qs_font_color(sz) 
{
   if (sz != undefined) {
      size = 'size=' + sz; 
   } else {
      size = ''; 
   } 
   //return '<font ' + size + '>'; 
   return '<font ' + size + ' color=' + qs_page_color + '>'; 
}

// ---------------------------------------------------------------------------
// support for qs_menu function 
// ---------------------------------------------------------------------------
function qs_menu_ref(cur_loc, item_loc, text)
{
   if (qs_menu_target[item_loc] != undefined) { 
      var href = new String(qs_menu_target[item_loc]); 
      if (href.match(/^http:/)) {
         target_file = href; 
      } else {
         target_file = qs_path + "/" + qs_menu_target[item_loc]; 
      } 
      s = ('<a href=' + target_file + ' ' +
            'onMouseOver="window.status=\'' + item_loc + '\'; return true;" ' +
	    'onMouseOut="window.status=\'' + cur_loc + '\'; return true;">' +
	    text + '</a>'); 
      return s;
   } else {
      return text; 
   }
}

function qs_menu_item(cur_menu, cur_sub_menu, item_text, sub_item_text)
{
   cur_loc = qs_location(cur_menu, cur_sub_menu); 
   item_loc = qs_location(item_text, sub_item_text); 
   subitem  = (sub_item_text != undefined); 
   istext = (item_loc == cur_loc); 
   color = qs_page_color; 
   if (subitem) {
      text = sub_item_text; 
   } else {
      text = item_text;
   }
   if (istext) {
     ptr = '>&nbsp;';  
   } else {
     ptr = '&nbsp'; 
   }
   wd('<tr>'); 
   wd(qs_col_spacer(8,1, 1)); 
   wd(qs_col_spacer(8,1, 1)); 
   wd('<td width=16px><font color=' + color + '>' + ptr + '</font></td>');
   if (subitem) {
       wd(qs_col_spacer(16,1, 1)); 
       wd('<td align=left>'); 
   } else {
       wd('<td colspan=2 align=left>'); 
   } 
   wd(qs_menu_ref(cur_loc, item_loc, text));
   wd('</td></tr>'); 
   return (cur_menu == item_text);
}

function qs_menu_separator(color_img)
{
   wd('<tr>'); 
   wd(qs_col_spacer(8,1, 1));  
   wd('<td colspan=4 height=16px>' + 
      '<img src=' + color_img + ' width=144px height=2px>' + 
      '</td>');
   wd('</tr>'); 
}

function qs_menu_insert_bling_bling(html) 
{
   wd('<tr>'); 
   wd(qs_col_spacer(8,1, 1)); 
   wd('<td colspan=4 width=144px>');
   wd(html); 
   wd('</td></tr>'); 
} 

// --------------------------------------------------------------------------
// fcts used in page building 
// --------------------------------------------------------------------------
var qs_do_head = true; 

// EXPORTED; used in pages that request non default title 
function qs_doc_title(str) 
{
   if (qs_do_head) {
      wd('<meta content="text/html; charset=ISO-8859-1 ' + 
         'http-equiv="content-type">' + 
         '<title>' + str + '</title>' + 
         '</head>'); 
      qs_do_head = false;
   }
}

// EXPORTED 
function qs_menu_set_bling_html(html) 
{
    qs_menu_bling_bling = html; 
}

// EXPOERTED
function qs_doc_start(menu_loc, sub_menu_loc, dotitle, tit) {
   qs_doc_setup(menu_loc, sub_menu_loc, true, dotitle, tit);

   wd(qs_table_start(0, undefined));
   wd(qs_setup_doc_line(10)); 
   // menu in first 2 cols on left,  page content in 2 cols on right 
   wd('<tr>'); 
   wd('<td valign=top ' + qs_debug_color() + 'colspan=2 rowspan=100>');
   qs_build_menu_table(qs_my_menu, qs_my_sub_menu); 
   wd('</td>'); 
   wd('<td rowspan=100 width=16px ' + qs_debug_color() + '>'+ 
		   '<img src=' + qs_trans_img + '></td>'); 
   // page content in its on table 
   wd('<td colspan=2>' + qs_table_start(0, 632, qs_debug_color())); 
   html(); 
}
   
// EXPOERTED
function qs_doc_headline(left)
{
   if (left != undefined) { 
      wd('<tr><td align=left>' + qs_font_color() + left + '</font></td></tr>'); 
   } 
   html(); 
}

// EXPOERTED
function qs_body_start(with_underline)
{
  if (with_underline) { 
     qs_line(true); 
  }
  if (with_underline) {
     wd('<tr><td colspan=2 height=16px><img width=632px height=2px src=' +
        qs_trans_img + '></td>'); 
     wd('</tr>'); 
  } 

  wd('<tr>'); 
  wd('<td width=632px valign=top>'); 
  html();  // spit out HTML before  <SCRIPT> section is eneded 
}

// EXPORTED 
function qs_spacer_row(w, h) 
{
   wd('</td>' ); 
   wd('</tr>' ); 
   wd('<tr>' + 
      '<td><img src=' + qs_trans_img + ' height=' + h + 'px ' + 
			 'width=' + w + 'px>'); 
} 

function qs_spacer_col(w, h) 
{
   if (h == undefined) { h = 1; } 
   wd('<td><img src=' + qs_trans_img + ' height=' + h + 'px ' + 
			 'width=' + w + 'px>'); 
}

// EXPOERTED
function qs_doc_finish(date, spacing) 
{
   wd('</td>'); 
   wd('<td height=460px> <img src=' + qs_trans_img + '> </td>'); 
   wd('</tr>' + qs_table_finish()); // end of main page contents 
   wd('</td></tr>'); 
   if (spacing == undefined) {
      spacing = 36; 
   } 
   if (spacing < 0) {
      spacing = 36; 
   }
   wd(qs_row_spacer( spacing)); 
   qs_line(true); 

   //wd('<tr>'); 
   //wd('<td>'); 
   wd('<tr><td align=left ' + qs_debug_color() + '>'); 
   qs_menu_across(); 
   wd('</td>'); 
   wd('<td align=right' + qs_debug_color() + '>'); 
   wd(qs_go_back_ref("Back")); 
   wd('</td>'); 
   wd('</tr>'); 
   if (date != undefined) { 
      wd(qs_row_spacer( 8)); 
      wd('<tr' + qs_debug_color() + '>' + 
         '<td colspan=2 align=right>' + qs_font_color(-2) + 
              ' Last Updated: ' +   date + 
              '</font></td></tr>');
   }
   wd(qs_row_spacer( 8)); 
   wd(qs_table_finish()); 

   wd('</body>');
   html();
}

// EXPOERTED
function qs_img_doc_start(menu_loc, sub_menu_loc, tit) {
   qs_doc_setup(menu_loc, sub_menu_loc, false, undefined, tit);

   wd(qs_table_start(0, undefined, 'bgcolor="' + qs_background_color + '"'));
   wd('<TR>'); 
   wd(qs_col_spacer(16,12));
   wd(qs_col_spacer(qs_width-16,12));
   wd('</TR>'); 

   wd('<TR>'); 
   wd(qs_col_spacer(16,1));
   if (tit == undefined) { 
       tit = '<img src=' + qs_trans_img + ' width=1px height=1px>'; 
   }
   wd('<TD>' + qs_font_color() + tit + '</font></td>'); 
   wd('</TR>'); 

   wd(qs_row_spacer( 12)); 

   wd('<TR>'); 
   wd(qs_col_spacer(16,1));
   wd('<TD>' ); 
}
   
// EXPOERTED
function qs_img_doc_finish(date) 
{
   wd('</td></TR>'); 
   wd(qs_table_finish()); 
   // end of main page contents 

   wd(qs_table_start(0, undefined, 'bgcolor="' + qs_background_color + '"' ));

   wd(qs_setup_doc_line(12)); 
   // colored line
   wd('<tr>' + 
      '<td colspan=5 align=left>' + 
           '<img src=' + qs_color_img + ' height=3px width=' + 
           qs_width + 'px>' + 
           '</td></tr>');
   wd(qs_setup_doc_line(12)); 

   wd('<tr>'); 
   wd(qs_col_spacer(1,1)); 
   wd('<td align=left>'  + qs_go_back_ref("Back") + '</td>'); 
   wd(qs_col_spacer(1,1)); 
   wd('<TD>'); qs_menu_across(); wd('</td>'); 
   wd('</tr>'); 

   if (date != undefined) { 
      wd('<tr>' + '<td colspan=5 align=right>' + qs_font_color(-2) + 
                  ' Last Updated: ' +   date + '</font></td></tr>');
   } else { 
      wd(qs_row_spacer( 8)); 
   }
   wd(qs_row_spacer( 8)); 
   wd(qs_table_finish()); 
   wd('</body>');
//alert('number_of_open_tables=' + number_of_open_tables); 
   html();
}

function qs_setup_doc_line(height) 
{
   return '<tr>' + 
          qs_col_spacer(8, height, 1) +    // width, height, #colspan
          qs_col_spacer(144, height, 1) + 
          qs_col_spacer(16, height, 1) + 
          qs_col_spacer(632, height, 2) + 
          '</tr>';
   // debugging version
   s = 
      '<tr> ' +
      '<td  height=' + height + 'px ' + 
	       'width=8px bgcolor=yellow><img src=' + qs_trans_img + '></td>' +
      '<td  height=' + height + 'px ' + 
	       'width=144px bgcolor=black><img src=' + qs_trans_img + '></td>' +
      '<td  height=' + height + 'px ' + 
	       'width=16px bgcolor=beige><img src=' + qs_trans_img + '></td>' +
      '<td  height=' + height + 'px ' + 
	       'bgcolor=pink><img width=400px height=1px src=' + qs_trans_img + '></td>' +
      '<td  height=' + height + 'px ' + 
	       'bgcolor=purple><img src=' + qs_trans_img + '></td>' +
      '</tr> '; 
   return s;
} 

function qs_doc_setup(menu_loc, sub_menu_loc, dobg, dohead, tit) 
{
   if ((dohead != undefined) && (dohead != true)) {
      qs_do_head = false; 
   }
//   alert(menu_loc + '\n' + 
//        sub_menu_loc + '\n' +
//        'bg=' + dobg + '\n' + 
//        'head=' + dohead + '\n' +
//        'dohead=' + qs_do_head + '\n' +
//        'tit=' + tit);

   qs_init_vars(menu_loc, sub_menu_loc, tit); 
   window.status = qs_my_location; 

   if (tit != undefined) {
      tit = '&nbsp;&nbsp;  ' + tit ; 
   } else {
      tit = '';
   }
   qs_doc_title(qs_my_location + tit); 
   bgimg = ''; 
   if (dobg) { 
      bgimg = 'background=' + qs_background_img;
   } else {
      bgimg = 'bgcolor=' + qs_background_color; 
   }
   wd('<body ' + bgimg + 
      ' link=' + qs_link_color +
      ' alink=' + qs_link_hover +
      ' vlink=' + qs_link_visited +
      ' leftmargin=0 topmargin=0' +
   ' marginheight=0 marginwidth=0 >');
   // The Page is a table: with the following row layout
   // | 8 | 144       | 16 | 632 over 2 cols                              
   //  the logo takes up col 1,2,3 over two rows 
   //  the color bar extends on the lower row next to the logo in col 4
   //  the menu takes up he first two columns
   // the document body is inside a table that takes up grid entry 4,4
   
   wd(qs_table_start(0, undefined)); 
   wd(qs_setup_doc_line(1)); 

   // logo (spreads over two rows) 
   // location at right side  
   wd('<tr> ');
    wd('<td rowspan=2 colspan=3 ' + qs_debug_color() + 'width=168px height=72px>' + 
      '<img border=0px width=168px height=72px src="' + qs_logo_img + '" alt="Logo">' + 
      '</td> ');
   wd('<td height=36px colspan=2 align=right bdcolor=blue>' + qs_font_color() + 
       qs_location_ref(qs_my_menu, qs_my_sub_menu) + '</font></td>');
   wd('</tr>');

   // the color bar
   wd('<tr>'); 
   wd('<td height=36px colspan=2>' + 
      '<img src=' + qs_color_img + ' border=0px height=36px width=632px>' +
      '</td></tr>');
   
   wd(qs_table_finish()); 
}

function qs_line()
{
  img = qs_color_img;
  wd('<tr' + qs_debug_color() + '>' + 
     '<td colspan=2 height=16px><img width=632px height=2px src=' + img + '>' +
     '</td></tr>'); 
}


// -----------------------------------------------------------------------
// htm text gathering fcts 
// -----------------------------------------------------------------------
var html_text = ''; 

// EXPOERTED
function wd(s)   { html_text += s + '\n'; }

// EXPOERTED
function alerthtml()  { 
  alert(html_text); 
  html(); 
}

// EXPOERTED
function html()  { 
  document.writeln(html_text);
  html_text = '\n'; 
}

// -----------------------------------------------------------------------
// debugging support
// -----------------------------------------------------------------------
function handle_error(msg, url) 
{
   file = new String(url); 
   if (file.length > 40) {
       file = "..." + file.substring(file.length-40); 
   } 
   alert(file + ": \n" + msg); 
}

window.onerror = handle_error; 

var debug_color_index = 0; 
var debug_color = new Array(); 
debug_color[0] = "red"; 
debug_color[1] = "green";
debug_color[2] = "blue"; 
debug_color[8] = "#777777"; 
debug_color[3] = "yellow"; 
debug_color[4] = "maroon"; 
debug_color[7] = "#555555"; 
debug_color[5] = "purple"; 
debug_color[6] = "orange"; 
debug_color[9] = "pink"; 

function qs_debug_color() 
{
   return ' ';
   // do return s when you want to debug 
   debug_color_index  = debug_color_index + 1;
   if (debug_color_index > 9) debug_color_index = 0; 
   s =  ' bgcolor=' + debug_color[debug_color_index] + ' '; 
   return s;
} 

// --------------------------------------------------------------------------
// pages style sheet
// 
function css_link() {
   var s = ('\n<STYLE type="text/css">\n' +
        '<!--\n' +
   'body, p, td, a { \n' +
   '   font-family: Arial, Helvetica, sans-serif;\n' +
        '   font-size: 14px;\n' +
        '   line-height: 18px;\n' +
   '} \n' +
   '' +
        'A { text-decoration: none; \n' +
   '} \n' +
   'A:hover {\n' +
   '    color: ' + qs_link_hover + '; \n' +
   '}\n' +
        '-->\n' +
        '</STYLE>\n');
   //alert(s);
   return s;
}

// =======================================================================
// end of Copy of TechTSP's index.js 
// =======================================================================

// =======================================================================
// SPECIFICS FOR THSI PAGE SET  
// =======================================================================
// qspath the path to this file relative to the including file 
var qs_path = '.'; 

// these vars are the same for whole sets of pages 
// such as all Sweden/Concorde pages 
// paths are givemn relative to this_location/qs_path
var qs_background_img = 'img/qsbg.jpg'; 
var qs_background_color = '#f8f2f6';
var qs_logo_img = 'img/qslogo.jpg'; 
var qs_color_img = 'img/qspagecolor.jpg'; 

var qs_link_hover = '#ff8e05'; // orangy 
var qs_link_color = '#a53e11';
var qs_page_color = '#a53e11';
var qs_link_visited = qs_link_color; 

var qs_my_location = "UNDEFINED MY LOCATION"; 
var qs_my_menu     = "UNDEFINED"; 
var qs_my_sub_menu = "UNDEFINED SUB MENU"; 

// ---------------------------------------------------------------------
// Menu definition
// is the same for a whole set of pages such as Concorde/Sweden/...
// ---------------------------------------------------------------------

var qs_menu_target = new Array(); 

qs_menu_target[qs_location("Home", undefined)] 
	= "../index.html"; 

qs_menu_target[qs_location("TSP Games", undefined)] 
        = 'index.html';  

qs_menu_target[qs_location("Tour Finder", undefined)] 
        = 'tspOnePlayer.html';  

qs_menu_target[qs_location("Tour Race", undefined)] 
        = 'tspTwoPlayers.html';  


// PRIVATE (specific to page set)  
function qs_build_menu_table(menu_loc, sub_menu_loc) 
{
   wd(qs_table_start(0, undefined)); 
   if (qs_menu_bling_bling != undefined) { 
      qs_menu_insert_bling_bling(qs_menu_bling_bling); 
      qs_spacer_row(1, 4); 
      qs_menu_separator(qs_color_img)
   }
   qs_menu_item(menu_loc, sub_menu_loc, 'Home', undefined); 
   qs_menu_separator(qs_color_img)

   qs_menu_item(menu_loc, sub_menu_loc, 'TSP Games', undefined); 
   qs_menu_separator(qs_color_img)

   qs_menu_item(menu_loc, sub_menu_loc, 'Tour Finder', undefined); 
   qs_menu_separator(qs_color_img)

   qs_menu_item(menu_loc, sub_menu_loc, 'Tour Race', undefined); 
   qs_menu_separator(qs_color_img)

   wd(qs_table_finish()); 
}

// PRIVATE (specific to page set)  
function qs_location(item_text, sub_item_text ) 
{
   loc = 'TSP Games';
   if (item_text != 'TSP Games')  {
      loc +=  ' > ' + item_text;
   }
   if (sub_item_text != undefined)  {
      loc += ' > ' + sub_item_text; 
   } 
   return loc; 
}

// PRIVATE (specific to page set)  
function qs_location_ref(item_text, sub_item_text) 
{
   loc = qs_location('TSP Games', undefined); 
   s = qs_menu_ref(qs_my_location, loc, 'TSP Games'); 

   if (item_text != 'TSP Games')  {
      loc = qs_location(item_text, undefined); 
      s += ' > ' + qs_menu_ref(qs_my_location, loc, item_text); 
   }
   if (sub_item_text != undefined) { 
      loc = qs_location(item_text, sub_item_text); 
      s += ' > ' + qs_menu_ref(qs_my_location, loc, sub_item_text);
   }
   return s; 
}



wd(css_link());
if (report_load) alert("index.js loaded"); 

var report_load;
if (report_load) alert("index.js load started"); 

// =======================================================================
// SPECIFICS FOR CONCORDE 
// =======================================================================
function make_applet(w, h, code, ar, params, values) 
{
   wh = " width=" + w + " height=" + h + " "; 
   if (top._ie == true) { 
      app='<OBJECT CLASSID="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" ' + 
           wh + '\n' +
          'CODEBASE="http://java.sun.com/products/plugin/autodl/jinstall-1_4_2-windows-i586.cab#Version=1,4,2,0"> \n' +
          '<PARAM NAME=code VALUE="' + code + '">\n' +
          '<PARAM NAME=archive VALUE="' + ar + '">\n' +
	  '<PARAM NAME=type VALUE="application/x-java-applet;version=1.4.2">\n'; 
	  for (i = 0; i < params.length; i++) {
	     app += '<PARAM NAME=' + params[i] + " VALUE='" + values[i] + "'>\n";
	  } 
          app += 'No Java 2 SDK, Standard Edition v 1.4 support for APPLET!!\n';
          app += '</OBJECT>'; 
   } else { if (top._ns == true) {
      app='<EMBED '+ wh + 
          'type="application/x-java-applet;version=1.4.2" '+ 
	  'pluginspage=' +
	  '"http://java.sun.com/products/plugin/autodl/jinstall-1_4_2-windows-i586.cab#Version=1,4,2,0" ' +
          'code="' + code + '" archive="' + ar + '" ' ;
	  for (i = 0; i < params.length; i++) {
	     app += params[i] + "='" + values[i] + "'\n  "; 
	  } 
	  app += '>\n';
          app += '<NOEMBED> ' + 
                 'No Java 2 SDK, Standard Edition v 1.4 support for APPLET!! ' + 
                 '</NOEMBED>\n' + 
                 '</EMBED>'; 
   } else {
      app = '<APPLET code=' + code + ' archive=' + archive + wh + '>'; 
      for (i = 0; i < params.length; i++) {
	 app += '<PARAM NAME=' + params[i] + " VALUE='" + values[i] + "'>\n";
      } 
      app += '</APPLET>\n' +
             '<BR> If you can not see the above applet you should ' + 
             'download an uptodate java plugin from \n' +
             '<A HREF="http://java.sun.com/products/plugin/1.3/plugin-install.html"> here </A>.'; 
   } }
   return app; 
} 


function getimage(arg) {
    if (document.images) {
        rimg = new Image();
        rimg.src = arg;
        return rimg;
    }
}

function changeImages() {    /* from webdesign.about.com */
    if (document.images) {
        for (var i=0; i<changeImages.arguments.length; i+=2) {
            document[changeImages.arguments[i]].src = eval(changeImages.arguments[i+1] + ".src");
        }
    }
}

function tsp_tutorial_step_ref(cur, ref) 
{
   if (cur == ref)  {
      return cur;
   } else {
      return '<a href=tutorial' + ref + '.html> ' + ref + '</a>'; 
   }	
} 

function tsp_tutorial_step(step) 
{
   if (step > 0) {
      prev = '<A href=tutorial' + (step -1) + '.html> Prev </a>'; 
   }  else { 
      prev = '<img src=' + qs_trans_img + '>'; 
   }
   if (step < 13) { 
      next = '<A href=tutorial' + (step + 1) + '.html> Next </a>'; 
   } else {
      next = '<img src=' + qs_trans_img + '>'; 
   }
   if (step != 0) {
      start = '<A href=tutorial0.html> Start </a>'; 
   } else {
      start = '<A href=tutorial0.html> Start </a>'; 
      start = 'Start'; 
   } 
   if (step != 13) {
      finish = '<A href=tutorial13.html> Finish </a>'; 
   } else {
      finish = '<A href=tutorial13.html> Finish </a>'; 
      finish = 'Finish'; 
   } 
   s = ''; 
   s = s + '<IMG src=' + qs_color_img + ' width=100% height=1px>\n';
   s = s + '<TABLE width=100% cellpadding=0 cellspacing=0> \n';
   s = s + '<TR> \n';
   s = s + '<TD align=left> ' + prev + '</TD>\n';
   s = s + '<TD align=center> <IMG src=' + qs_trans_img + '></TD>\n';
   s = s + '<TD align=right> ' + next + '</TD>\n';
   s = s + '</TR>\n';
   s = s + '<TR>\n';
   s = s + '<TD> ' + start + '</TD>\n';
   s = s + '<TD align=center> <TABLE width=100% cellpadding=0 cellspacing=0> <TR align=center>\n';
   for (i = 1; i < 13; i++) {
      s = s + '<TD width=16px> ' + tsp_tutorial_step_ref(step, i) + '&nbsp; </TD>\n';
   } 
   s = s + '</TR></TABLE></TD>\n';
   s = s + '<TD align=right> ' + finish + '</TD>\n';
   s = s + '</TR>\n';
   s = s + '</TABLE>\n';
   s = s + '<IMG src=' + qs_color_img + ' width=100% height=1px>\n';
   return s; 
}

function tsp_tutorial_body_start(step) 
{
   qs_path = ".."; 
   qs_games_doc_start('Cut Applet', 'Tutorial'); // don't do <HEAD> section
   qs_doc_headline('<IMG SRC="image/cptutorial.jpg" ' + 
                   'ALT="Cutting Plane Applet Tutorial">'); 
   qs_body_start(true);
   wd(tsp_tutorial_step(step)); 
   html(); 
}

function tsp_color_table() 
{
return (qs_table_start(0, 450) + '\n' +  
   '<tr align=center>\n' + 
   '<td bgcolor="#ffffff" height=10><IMG SRC="' + qs_trans_img + '" > </td>\n' + 
   '<td bgcolor="#f4ffcc"><IMG SRC="' + qs_trans_img + '" ></td>\n' + 
   '<td bgcolor="#ffff7f"><IMG SRC="' + qs_trans_img + '" ></td>\n' + 
   '<td bgcolor="#ffff00"><IMG SRC="' + qs_trans_img + '" ></td>\n' + 
   '<td bgcolor="#ff9f00"><IMG SRC="' + qs_trans_img + '" ></td>\n' + 
   '<td bgcolor="#ff0000"><IMG SRC="' + qs_trans_img + '" ></td>\n' + 
   '<td bgcolor="#ff3caa"><IMG SRC="' + qs_trans_img + '" ></td>\n' + 
   '<td bgcolor="#dc00ff"><IMG SRC="' + qs_trans_img + '" ></td>\n' + 
   '<td bgcolor="#0000ff"><IMG SRC="' + qs_trans_img + '" ></td>\n' + 
   '<td bgcolor="#000087"><IMG SRC="' + qs_trans_img + '" ></td>\n' + 
   '<td bgcolor="#000000"><IMG SRC="' + qs_trans_img + '" ></td>\n' + 
   '</tr>\n' + 
   '<tr height=2> <td><IMG SRC="' + qs_trans_img + '"> </td></tr>\n' + 
   '<tr align=center>\n' + 
   '<td>0.01</td>\n' + 
   '<td>0.15</td>\n' + 
   '<td>0.25</td>\n' + 
   '<td>0.35</td>\n' + 
   '<td>0.45</td>\n' + 
   '<td>0.55</td>\n' + 
   '<td>0.65</td>\n' + 
   '<td>0.75</td>\n' + 
   '<td>0.85</td>\n' + 
   '<td>0.95</td>\n' + 
   '<td>1.00</td>\n' + 
   '</tr>\n' + 
   qs_table_finish() + '\n' + 
   '(Greatest Values for Each Color)<br>\n');
}

function make_tsp_applet(w, h, code, ar, gw, xpert, 
                         nodeShape, fontSize, graphName, graph)
{
   var pars = new Array(), vals = new Array(); 
   var i = 0; 
   pars[i] = 'GraphWidth';      vals[i] = gw; 		i++;
   pars[i] = 'GraphHeight';     vals[i] = gw;		i++;
   pars[i] = 'GraphFontSize';   vals[i] = fontSize;	i++;
   pars[i] = 'NodeShape';       vals[i] = nodeShape;	i++;
   pars[i] = 'GraphBackground'; vals[i] = 13421772;	i++;
   pars[i] = 'GraphForeground'; vals[i] = 0;		i++;
   pars[i] = 'Expert';          vals[i] = xpert; 		i++;
   // pars[i] = 'TRACE';           vals[i] = "qs.TSP,qs.gui.IGUI"; 	i++;
   pars[i] = 'GraphName';       vals[i] = graphName;	i++;
   pars[i] = 'Graph';           vals[i] = graph;		i++;

s = '<center><p><B>Color Coding of LP\'s edge values</B>\n'; 
s = s  + '<BR>\n'; 
s = s  + '<' + qs_trans_img + ' height=12px>\n'; 
s = s + tsp_color_table();
s = s + '</p><p>\n'; 
s = s + qs_table_start(2, undefined) + '<tr><td>\n';
s = s + make_applet(w, h, code, ar, pars, vals) + '\n';  	
s = s + '</td></tr>' + qs_table_finish() + '<p>\n'; 
s = s + '</center>';
return s;
} 

if (document.images) {
    prevoff = getimage("img/prevswhite.gif");
    nextoff = getimage("img/nextswhite.gif");
    backoff = getimage("img/backwhite.gif");

    prevon = getimage("img/prevsblack.gif");
    nexton = getimage("img/nextsblack.gif");
    backon = getimage("img/backblack.gif");
}

var _info = navigator.userAgent; 
var _ns = false; 
var _ns6 = false;
var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0 && 
          _info.indexOf("Windows 3.1") < 0);

var _ns = (navigator.appName.indexOf("Netscape") >= 0 && 
              ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0 && 
               java.lang.System.getProperty("os.version").indexOf("3.5") < 0)
               || (_info.indexOf("Sun") > 0) || (_info.indexOf("Linux") > 0)));
var _ns6 = ((_ns == true) && (_info.indexOf("Mozilla/5") >= 0));

wd(css_link()); 
html(); 

