function make_combobox_by_item( form, menu_list, current_item )
{
  form.options.length = 0;
  form.selectedIndex = 0;
  for(idx = 0; idx < menu_list.length; idx++) {
    form.options[idx] = new Option( menu_list[idx] );
    if ( menu_list[idx] == current_item ) {
      form.selectedIndex = idx;
    }
  }

}

function make_combobox_by_item_value( form, items, values, current_value )
{
  form.options.length = 0;
  form.selectedIndex = 0;
  for(idx = 0; idx < values.length; idx++) {
    form.options[idx] = new Option( items[idx], values[idx] );
  }
  form.selectedIndex = current_value;
}

function trim( str )
{
  while ( str.substring(0,1) == ' ' ) {
     str = str.substring(1, str.length);
  }

  while ( str.substring( str.length-1, str.length) == ' ' ) {
     str = str.substring(0, str.length-1);
  }

  while ( str.substring(0,1) == '0' ) {
     str = str.substring(1, str.length);
  }

  return  str ;
}

function ValidateCik( cik )
{
  cik = trim(cik);
  if ( cik.length == 0 ) {
    alert( "Please input a symbol or cik!" );
    return false;
  }
  return true;
}

function OnCikSearch( form, cik )
{
  cik = trim(cik);
  if ( cik.length == 0 ) {
    alert( "Please input a symbol or cik!" );
    return false;
  } else {
    form.action = "/insider-trading/" + cik + ".htm";
    return true;
  }
}

function JDialog(cmd, name, attr) {
  dialog = window.open(cmd, name, attr+',top=0,left=0');
  dialog.focus();
}

function cikDialog()
{
  cmd = "/site/cik-lookup.htm";
  var attr = "width=700,height=650,menubar=0,resizable=1,titlebar=0,scrollbars=1";
  JDialog( cmd, "_popup", attr );
}

function singleQuoteDialog( cmd ) {

  var attr = 'menubar=0,resizable=1,titlebar=0,scrollbars=1,width=800,height=650';
  JDialog(cmd, '_quoteDlg', attr);

}

function singleQuoteDialog1( symbol ) {
  var attr = 'menubar=0,resizable=1,titlebar=0,scrollbars=1,width=800,height=650';
  JDialog( "/quote/inetquote.php?s=" + symbol, '_quoteDlg', attr);
}

function showDetail( cmd ) {

  var attr = 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes';
  JDialog( cmd, '_detail', attr );

}

function multiQuotesDialog( cmd ) {

  singleQuoteDialog( cmd );

}

function multiQuotesDialog1( symbols ) {
  var attr = 'menubar=0,resizable=1,titlebar=0,scrollbars=1,width=800,height=650';
  JDialog( "/quote/realtimequotes.php?s=" + symbols, '_quoteDlg', attr);
}

function statusMsg()
{
  window.status="";
  return true;
}

function gotoUrl( url )
{
  document.location.href = url;
}

function makeUrl( dir, basename )
{
  return "/" + dir + "/" + basename + ".htm";
}

function gotoSite( basename )
{
  gotoUrl( makeUrl( "site", basename ) );
}

function gotoAccount( basename )
{
  gotoUrl( "/account/" + basename );
}

function showChart( basename )
{
  gotoUrl( "/ichart-" + basename + ".png" );
}

function sendToFriend()
{
  document.location.href='mailto:?subject=Real time insider trading monitoring website.&body=Hi, I found this website and thought you might like it too at http://www.secform4.com';
}

function gotoTraining( basename )
{
  gotoUrl( makeUrl( "training", basename ) );
}

function rootUrl( basename )
{
  gotoUrl( "/" + basename + ".htm" );
}

function showFiling( cik, dir )
{
  gotoUrl( makeUrl( "filings", cik + "/" + dir ) );
}

function cikRecord( cik )
{
  gotoUrl( "/insider-trading/" + cik + ".htm" );
}

function createUrl( baseName, extension, parent, root )
{
  gotoUrl( root + parent + baseName + extension );
}

function populate_user_day_menu( current_day, start_day, end_day )
{
  form = document.user_day_form.user_day;
  form.options.length = 0;

  total_days = end_day - start_day;

  items = new Array();
  values = new Array();

  day = start_day;
  for ( idx=0; idx < total_days; idx++ ) {
    if ( day==0 ) {
      dayStr = "Today";
    } else if ( day==1) {
      dayStr = "Yesterday";
    } else {
      dayStr = day + " days ago";
    }
    items[idx] =  dayStr;
    values[idx] =  day;

    day++;
  }
  make_combobox_by_item_value( form, items, values, current_day - start_day )
}

