
var qs_httpConcorde  = "http://www.math.princeton.edu/tsp/"; 
var qs_httpTspApplet = "http://www.tsp.gatech.edu/methods/cpapp"; 

var report_load = false;
if (report_load) alert("qsopt.js load started"); 

var do_trace = false; 
function trace(s) 
{
   if (do_trace) { 
      alert(s); 
   }
} 
var undefined; 

var html_text = ''; 
var do_alert = false;

// wd collects text that is to be written to the document 
// in the global variable html_text 
// html() calls write html_text and reset it to "" 
// html_stop() defers the effects of html until html_start() is called 
function wd(s)   { html_text += s + '\n'; }

var html_do_it = false;
function html()  { 
  if (html_do_it) {
     if (do_alert)  {
        alert(html_text); 
     }
     document.writeln(html_text);
     html_text = '\n'; 
  }
}
function html_stop()  
{  
   html(); 
   html_do_it = false;
   trace(": html_stop"); 
} 
function html_start()  { 
   html_do_it = true;
   trace(": html_start"); 
} 

function get_params(loc) {
	s = new String(loc); 
	s = s.split("\?")[1]; 
	return s;
}
function alerthtml()  {  // for debugging  
  alert(html_text); 
  html(); 
}

var qs_doc_start_txt = ""; 
function prewd(title)   {
   headTitle = title; 
   if (!title.match("^QSopt ")) {
      headTitle = "QSopt " + title; 
   }
   html_text = '<title>' + headTitle + '</title>\n' +
               '</head>\n' + 
               qs_doc_start_txt + " " + 
               qs_font_color("+2") + title + "</font> " +  html_text; 
}

function get_param(params, p) {
    var ps = new String(params); 
    var pattern = new RegExp(p + '=' + '([^&]*)'); 
    var result = ps.match(pattern); 
    if (result != null) {
       return result[1];
    }
    return undefined;
}

function qs_go_back_ref(txt) 
{
  return "<a href=javascript:history.back();>" + txt + "</a>"; 
} 

// ---------------------------------------------------------------------
// utility routines 
// ---------------------------------------------------------------------
function qs_table_start(b, w, extra) 
{
   width = ""; 
   if (w != undefined) {
      width = " width=" + w + "px"; 
   }
   if (extra == undefined) { extra = ""; }
   s= '<table border=' + b + width + " " + extra + 
		' cellpadding=0 cellspacing=0 vspace=0 hspace=0>';
   return s; 
}

function qs_table_finish() 
{
   return "</table>"; 
}

function leq() { return ' = ' ;  } 
function geq() { return ' &le; ' ;  } 
function eq() { return ' &ge; ' ; } 
function lfloor() { return 'floor('; } 
function lceil() { return ' ceil('; } 
function rfloor() { return ')'; } 
function rceil() { return ')'; } 

var math_begin = true;
function math() 
{ 
   if (math_begin) {
      s = "<code>"; 
   } else {
      s =  "</code>"; 
   }
   math_begin = !math_begin;
   return s; 
}

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_format_ref(fmt)
{
   if (fmt == "MPS") {
      return qs_ref("MPS format", 
                 qs_path + "/" + qs_menu_target[qs_location("Problem Formats", "MPS Format")]); 
   } else {
      if (fmt == "LP") {
         return qs_ref("LP format", 
                  qs_path + "/" + qs_menu_target[qs_location("Problem Formats", "LP Format")]); 
      } else {
         return qs_path + "/" + qs_ref("Problem formats", 
                 qs_menu_target[qs_location("Problem Formats", undefined)]); 
         
      }
   } 
} 

function css_link() {
   return('\n<STYLE type="text/css">\n' + 
	'<!--\n' + 
	'A { text-decoration: none }\n' + 
        'A:hover { color: red }\n' + 
	'-->\n' + 
	'</STYLE>\n');  
}

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;
}

function qs_font_color(sz) 
{
   if (sz != undefined) {
      size = 'size=' + sz; 
   } else {
      size = ''; 
   } 
   return '<font ' + size + ' color=' + qs_page_color + '>'; 
}

function qs_spacer_row(w, h) 
{
   return('<tr><td><img src=' + qs_trans_img + ' height=' + h + 'px ' + 
			 'width=' + w + 'px></td></tr>');
}

function qs_spacer_col(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>');
}
// ---------------------------------------------------------------------
// END: utility routines
// ---------------------------------------------------------------------

var qs_path = '.'; 
var qs_background_img = 'img/qsbg.jpg'; 
var qs_home_img = 'img/qsbar.jpg'; 
var qs_color_img = 'img/qsblue1.jpg'; 
var qs_trans_img = 'img/trans.gif'; 
var qs_page_color = '#336799';

function qs_small_java_img() { return qs_path + "/img/java17.jpg"; } 

var qs_link_color = qs_page_color;
var qs_link_visited = qs_page_color; 
var qs_link_hover = 'red'; 

var qs_my_location = "QSopt"; 
var qs_my_menu = "UNDEFINED"; 
var qs_my_sub_menu = "UNDEFINED SUB MENU"; 

var qs_menu_target = new Array(); 
qs_menu_target[qs_location("QSopt", undefined)] 
	= "index.html"; 
qs_menu_target[qs_location("Downloads", undefined)] 
	= "downloads/downloads.htm"; 

qs_menu_target[qs_location("LP Info", undefined)] 
	= "lpinfo/linear_programming.htm";
qs_menu_target[qs_location("LP Info", "Links")] 
	= "lpinfo/links.htm";
qs_menu_target[qs_location("LP Info", "Textbooks")] 
	= "lpinfo/textbooks.htm";
//qs_menu_target[qs_location("LP Info", "Codes")] 
	//= "lpinfo/codes.htm";

qs_menu_target[qs_location("Software", undefined)] 
	= "software/software.htm";
qs_menu_target[qs_location("Software", "MS Windows")] 
	= "software/mswindows.htm";
qs_menu_target[qs_location("Software", "Cygwin")] 
	= "software/cygwin.htm";
qs_menu_target[qs_location("Software", "Linux")] 
	= "software/linux.htm";
qs_menu_target[qs_location("Software", "Solaris")] 
	= "software/solaris.htm";
qs_menu_target[qs_location("Software", "Java")] 
	= "software/java.htm";
qs_menu_target[qs_location("Software", "Applications")] 
	= "software/applications.htm";

qs_menu_target[qs_location("Problem Formats", undefined)] 
	= "hlp/ff_formats.htm";
qs_menu_target[qs_location("Problem Formats", "LP Format")] 
	= "hlp/ff_lp_format.htm";
qs_menu_target[qs_location("Problem Formats", "MPS Format")] 
	= "hlp/ff_mps_format.htm";
qs_menu_target[qs_location("Problem Formats", "Examples")] 
	= "hlp/ff_examples.htm";

qs_menu_target[qs_location("Callable Library", undefined)] 
	= "lib/C/lib.htm";
qs_menu_target[qs_location("Callable Library", "Overview")] 
	= "lib/C/overview.htm";
qs_menu_target[qs_location("Callable Library", "Function List")] 
	= "lib/C/fctlist.htm";

qs_menu_target[qs_location("Rational Solver", undefined)] 
	= "ex/index.html";

qs_menu_target[qs_location("Beta", undefined)] 
	= "beta/index.html";

qs_menu_target[qs_location("Contact Info", undefined)] 
	= "contact/contact.htm";

function qs_location( item_text, sub_item_text ) 
{

   loc = 'QSopt';
   if (item_text != 'QSopt')  {
      loc +=  ' > ' + item_text;
   }
   if (sub_item_text != undefined)  {
      loc += ' > ' + sub_item_text; 
   } 
   return loc; 
}

function qs_file_loc_ref(cur_loc, target_file, status, text)
{
   s = ('<a href=' + target_file + ' ' +
         'onMouseOver="window.status=\'' + status + '\'; return true;" ' +
	 'onMouseOut="window.status=\'' + cur_loc + '\'; return true;">' +
	 text + '</a>'); 
   return s;
}

function qs_target_file(item_loc)
{
   return  qs_path + "/" + qs_menu_target[item_loc]; 
}

function qs_menu_ref(cur_loc, item_loc, text)
{
   target_file = qs_path + "/" + qs_menu_target[item_loc]; 
   return qs_file_loc_ref(cur_loc, target_file, item_loc, text); 
}

function qs_location_ref(item_text, sub_item_text ) 
{
   loc = qs_location('QSopt', undefined); 
   s = qs_menu_ref(qs_my_location, loc, 'QSopt', qs_menu_target[loc]); 
   if (item_text != 'QSopt') { 
      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_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); 
   target_file = qs_path + "/" + qs_menu_target[item_loc]; 
   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) {
     // item represents current location
     ptr = '>&nbsp;';  
   } else {
     // if (item is Software:Java) and therefore not current location 
     // then show it with Java logo 
     // then show it with Java logo 
     ptr = '&nbsp'; 
     //if (item_loc == qs_location("Software", "Java")) {
	//ptr = "<img src=" + qs_path + "/img/java16.jpg>";
     //} else if (item_loc == qs_location("Software", undefined) &&  
                //(cur_menu != "Software")) {
	//ptr = "<img src=" + qs_path + "/img/java16.jpg>";
     //}
   }
   wd('<tr>'); 
   wd(qs_spacer_col(8,1, 1)); 
   wd(qs_spacer_col(8,1, 1)); 
   //wd('<td width=18px><font color=' + color + '>' + ptr + '</font></td>');
   wd('<td width=16px><font color=' + color + '>' + ptr + '</font></td>');
   if (subitem) {
       wd(qs_spacer_col(16,1, 1)); 
       wd('<td align=left>'); 
   } else {
       wd('<td colspan=2 align=left>'); 
   } 
   if (item_loc == qs_location("Software", "Java")) { 
      text = text + "&nbsp; <img border=0px src=" + qs_small_java_img() + ">"; 
   }
   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_spacer_col(8,1, 1));  
   wd('<td colspan=4 height=16px><img src=' + color_img + ' width=144px height=2px></td>');
   wd('</tr>'); 
}

function qs_menu(menu_loc, sub_menu_loc) 
{
   wd('<table border=0px cellpadding=0 cellspacing=0 vspace=0 hspace=0>');

   qs_menu_item(menu_loc, sub_menu_loc, 'QSopt', undefined); 
   qs_menu_separator(qs_color_img)

   qs_menu_item(menu_loc, sub_menu_loc, 'Downloads', undefined); 
   qs_menu_separator(qs_color_img)

   if (qs_menu_item(menu_loc, sub_menu_loc, 'LP Info', undefined)) {  
      qs_menu_item(menu_loc, sub_menu_loc, 'LP Info', 'Links'); 
      qs_menu_item(menu_loc, sub_menu_loc, 'LP Info', 'Textbooks'); 
      //qs_menu_item(menu_loc, sub_menu_loc, 'LP Info', 'Codes'); 
   }
   qs_menu_separator(qs_color_img)

   if (qs_menu_item(menu_loc, sub_menu_loc, 'Software', undefined)) {  
      qs_menu_item(menu_loc, sub_menu_loc, 'Software', 'MS Windows'); 
      qs_menu_item(menu_loc, sub_menu_loc, 'Software', 'Cygwin'); 
      qs_menu_item(menu_loc, sub_menu_loc, 'Software', 'Linux'); 
      qs_menu_item(menu_loc, sub_menu_loc, 'Software', 'Solaris'); 
      qs_menu_item(menu_loc, sub_menu_loc, 'Software', 'Java'); 
      qs_menu_item(menu_loc, sub_menu_loc, 'Software', 'Applications'); 
   }
   qs_menu_separator(qs_color_img)

   if (qs_menu_item(menu_loc, sub_menu_loc, 'Problem Formats', undefined)) {  
      qs_menu_item(menu_loc, sub_menu_loc, 'Problem Formats', 'LP Format'); 
      qs_menu_item(menu_loc, sub_menu_loc, 'Problem Formats', 'MPS Format'); 
      qs_menu_item(menu_loc, sub_menu_loc, 'Problem Formats', 'Examples'); 
   }
   qs_menu_separator(qs_color_img)

   if (qs_menu_item(menu_loc, sub_menu_loc, 'Callable Library', undefined)) {  
       qs_menu_item(menu_loc, sub_menu_loc, 'Callable Library', 'Overview');
       qs_menu_item(menu_loc, sub_menu_loc, 'Callable Library', 'Function List');
   }
   qs_menu_separator(qs_color_img)

   if (qs_menu_item(menu_loc, sub_menu_loc, 'Rational Solver', undefined)) {  
   }
   qs_menu_separator(qs_color_img)

   if (qs_menu_item(menu_loc, sub_menu_loc, 'Beta', undefined)) {  
   }
   qs_menu_separator(qs_color_img)

   if (qs_menu_item(menu_loc, sub_menu_loc, 'Contact Info', undefined)) {  
   }
   wd('</table>');  // end table of menu items
}

function qs_menu_across() 
{
   cur_loc = qs_location(qs_my_menu, qs_my_sub_menu); 
   wd(qs_menu_ref(cur_loc, qs_location('QSopt', undefined), 
	       'QSopt')); 
   wd(qs_font_color() + '|</font>'); 
   wd(qs_menu_ref(cur_loc, qs_location('Problem Formats', undefined), 
               'Problem Formats')); 
   wd(qs_font_color() + '|</font>'); 
   wd(qs_menu_ref(cur_loc, qs_location('Downloads', undefined), 
               'Downloads')); 

}

function qs_doc_no_menu_start(menu_loc, sub_menu_loc, dobg) {
   // The Page is a table: with two cols on the left for navigation, 
   // a gutter column and a col for the actual text contents:  
   // | NAVIGATION                                  | gutter  | 2 col page content 
   // | 8px | 8px | '>' | menu-item                 | 16px    | 624pixel
   // | 8px | 8px | '>' | 16px | submenu-item       | 16px    | 624pixel
   //  
   // the first rows define a header 
   //    row 0: spacer
   //    row 1: QSopt on left and current location, someting like 'QSopt | Downloads'
   //    row 2: spacer
   //    row 3: colored bar 
   //    row 4: spacer 
   // 
   
   qs_background_img = qs_path + '/' + qs_background_img;
   qs_home_img = qs_path + '/' + qs_home_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; 
   window.status = qs_my_location; 
 
   wd('<body'); 
   if (dobg) {
      wd(' background=' + qs_background_img); 
   }
   wd(' link=' + qs_link_color +
      ' alink=' + qs_link_hover +
      ' vlink=' + qs_link_visited +
      ' leftmargin=0 topmargin=0' +
      ' marginheight=0 marginwidth=0 >');
   wd('<table valign=middle border=0px cellpadding=0 cellspacing=0 vspace=0 hspace=0>');
   
   // empty row 
   wd('<tr>');
   wd(qs_spacer_col(8, 16, 1));    // width, height, #colspan
   wd(qs_spacer_col(8, 16, 1)); 
   wd(qs_spacer_col(16, 16, 1)); 
   wd(qs_spacer_col(16, 16, 1)); 
   wd(qs_spacer_col(112, 16, 1)); 
   wd(qs_spacer_col(16, 16, 1)); 
   wd(qs_spacer_col(624, 16, 2)); 
   wd('</tr> ');

   // row: QSopt icon/logo and location
   wd('<tr> ');
   wd(qs_spacer_col(16, 16, 2));    // width, height, #colspan
   wd('<td colspan=3 width=144px align=left>' + 
      '    <img src="' + qs_path + '/img/qsopticon.jpg" alt="QSopt">' + 
      '</td> ');
   wd(qs_spacer_col(1, 16, 1)); 
   wd('<td colspan=1 align=left> '); 

   qs_doc_start_txt = html_text; 
//alert("qs_doc_start_txt=" + qs_doc_start_txt); 
   html_text = ""; 
   // qs_new_message()

   wd('</td>'); 
   wd('<td align=right '   + qs_font_color());
   wd(qs_location_ref(qs_my_menu, qs_my_sub_menu) + '</font></td>');
   wd('</tr>');


   // empty row
   wd(qs_spacer_row(1, 16));
   
   // title image 
   if (menu_loc == 'QSopt') { 
      wd('<tr><td colspan=8><img src=' + qs_home_img + ' width=800px></td></tr>');
   } else {
      wd('<tr><td colspan=8>'); 
      if (false && qs_my_location == qs_location("Software", "Java")) {
          wd('<img src=' + qs_color_img + ' height=33px width=161px>' + 
          '<img border=0px src='+ qs_path + '/img/java32.jpg>' + 
          '<img src=' + qs_color_img + ' height=33px width=607px>');
      } else {
          wd('<img src=' + qs_color_img + ' height=34px width=800px>');
      } 
      wd('</td></tr>');
   }
   
   // empty row 
   wd(qs_spacer_row(1, 16));
}
   
function qs_doc_start(menu_loc, sub_menu_loc) {
   trace("qs_doc_start"); 
   qs_doc_no_menu_start(menu_loc, sub_menu_loc, true); 
   // menu in first 4 cols on left,  page content in 2 cols on right 
   wd('<tr><td valign=top colspan=5 rowspan=100>');
   qs_menu(qs_my_menu, qs_my_sub_menu); 
   wd('</td>'); 
   wd('<td rowspan=100><img width=16px height=16px src=' +
       qs_trans_img + '></td>'); 
}

function qs_doc_no_menu_headline(headline)
{
   title = new String(headline); 
   prewd(title); 
}

function qs_doc_headline(left, right) 
{
   wd('</tr>'); 
   title = new String(left); 
   prewd(title);
   wd('<tr>'); 
   if (right != undefined) { 
      wd('<td align=right width=624px valign=top colspan=2>'); 
      wd(right + "</td></tr>"); 
      wd(qs_spacer_row(1,16)); 
   }
}

function qs_line(visible)
{
   if (visible) 
      img = qs_color_img;
   else 
      img = qs_trans_img;
   wd('<tr><td colspan=2 height=16px><img width=624px height=2px src=' +
         img + '></td></tr>'); 
}

function qs_no_menu_line(visible)
{
	if (visible) 
		img = qs_color_img;
	else 
		img = qs_trans_img;
	wd('<tr><td colspan=8 height=16px><img width=800px height=2px src=' + 
			img + '></td></tr>'); 
}

function qs_doc_no_menu_body_start(headline)
{
   if (headline) {
      qs_doc_no_menu_headline(headline);
      //qs_no_menu_line(true); 
   } 
   html_start(); 
   wd("<tr><td  colspan=8 width=800px>"); 
   html(); 
}

function qs_body_start()
{
  trace("> qs_body_start"); 
  wd('<tr>'); 
  wd('<td valign=top width=624px valign=top colspan=2>'); 
  html_start(); 
  html();  // spit out HTML before  <SCRIPT> section is ended 
  trace("< qs_body_start"); 
}

function qs_doc_finish(date) 
{
   trace("> qs_doc_finish"); 
   wd('</td>'); 
   wd('<td rowspan=1 width=1px height=280px> &nbsp; </td>'); 
   wd('</tr>'); // end of main page contents 
   //wd('<tr><td> Home </td>'); 
   wd(qs_spacer_row(1, 36)); 
   qs_line(true); 
   wd('<tr><td colspan=1>'); 
   qs_menu_across(); 
   wd('</td>'); 
   wd('<td align=right>'); 
   wd(qs_go_back_ref("Back")); 
   wd('</td>'); 
   wd('</tr>'); 
   if (date != undefined) { 
      wd(qs_spacer_row(1, 8)); 
      wd('<tr><td colspan=2 align=right>' + qs_font_color(-2) + 
              ' Last Updated: ' +   date + 
              '</font></td></tr>');
   }
   wd(qs_spacer_row(1, 8)); 
   wd('</table>');
   wd('</body>');
   html();
   trace("> qs_doc_finish"); 
}

function qs_doc_no_menu_finish(date) 
{
   wd('</TD></TR>'); 
   wd(qs_spacer_row(1, 36)); 
   qs_no_menu_line(true); 
   wd('<TR>'); 
   wd(qs_spacer_col(1,1)); 
   wd('<td colspan=4>'); 
   wd(qs_go_back_ref("Back")); 
   wd('</td>'); 
   wd('<td colspan=3 align=right>'); 
   qs_menu_across(); 
   wd('</td>'); 
   wd('</tr>'); 
   if (date != undefined) { 
      wd(qs_spacer_row(1, 8)); 
      wd('<tr><td colspan=8 align=right>' + qs_font_color(-2) + 
              ' Last Updated: ' +   date + 
              '</font></td></tr>');
   }
   wd(qs_spacer_row(1, 8)); 
   wd('</table>');
   wd('</body>');
   html();
}


function qs_new_message() 
{
   if (qs_my_location != qs_location("Software", "Java")) {
      s = '<img align=center border=0px src='+ qs_path + '/img/java32.jpg>' + 
           '<font color="red"> ' + 
           '&nbsp; NEW</font> ' + 
            qs_font_color() + ' experimemtal Java Version </font>'; 
      s =  qs_ref(s, 
             qs_path + "/" + qs_menu_target[qs_location("Software", "Java")],
             qs_location("Software", "Java"));
      return s; 
   }
   return "&nbsp;"; 
} 

html_start(); 
wd(css_link());
html();
html_stop(); 
if (report_load) alert("qsopt.js loaded"); 
