//String.prototype.trim = function()
//{
//  return this.replace(/^\s+|\s+$/g, "");
//}  

function selectColor()
{
  var setColorSelect;
  var containerDiv;
  var settingsFrame;
  var pElement;
  var evnt;

//  alert('line10');
////  evnt = top.copyClientXY(event);
  setColorSelect = document.getElementById('selectColor');
//  //if (setColorSelect.selectedIndex != top.frames[5].previousSelectColorIndex && setColorSelect.selectedIndex != 0)
  if (setColorSelect.selectedIndex != 0)
  {
    //alert('line16');
    //alert('line 12 evnt.clientX = ' + evnt.clientX);
//    //previousSelectColorIndex = setColorSelect.selectedIndex;
    containerDiv = document.getElementById('palletteDiv');
    //alert('line 20 containerDiv.id = ' + containerDiv.id);
    //alert('line 21 containerDiv.currentStyle.visibility = ' + containerDiv.currentStyle.visibility);
    //if (containerDiv.currentStyle.display == "block")
    if (containerDiv.currentStyle.visibility == "visible")
    {
      //top.popUp(evnt, containerDiv.id, top);
      return;
    }
    //containerDiv.style.visibility == "visible";
    //containerDiv.style.display == "block";
    containerDiv.className = "ShowDiv";
    //alert('line 28 containerDiv.currentStyle.visibility = ' + containerDiv.style.visibility);
    //alert('line 29 containerDiv.style.display = ' + containerDiv.style.display);
    //    //alert('line 22 containerDiv.id = ' + containerDiv.id);
//    //alert('line 23 top = ' + top);
//    top.popUp(evnt, containerDiv.id, top);
//    topPos = containerDiv.style.top;
//    pxPos = topPos.search(/px/);
//    topPos = topPos.slice(0, pxPos);
//    topPos = Number(topPos) - 50;
//    containerDiv.style.top = topPos + 'px';
    settingsFrame = frames['pallette'];
    pElement = settingsFrame.document.getElementById('palletteP');
    pElement.windowNum = 'alerts';
    if (setColorSelect.selectedIndex == 1)
    {
      pElement.innerHTML = 'Select Foreground Color';
    }
    else 
    {
      pElement.innerHTML = 'Select Background Color';
    }
  }
}

function showAlertDialogbox() 
{
  var evnt;
  var containerDiv;
  var divTop;
  var alertListDiv;
  var alertDialogboxHeaderDiv;
  var alertDialogboxDocument;
  var offsetWidth;
  
  //alert('line 69');
  alertListDiv = top.document.getElementById('alertListDiv');
  if (alertListDiv.currentStyle.visibility == "visible")
  {
    top.popUp(event, 'alertListDiv', top);
  }
 // alert('line 75');
  window.event.returnValue = false;
  window.event.cancelBubble = true;
  //evnt = top.copyClientXY();
  containerDiv = top.document.getElementById('alertDialogboxDiv');
  if (containerDiv.currentStyle.visibility == "visible") 
  {
    top.popUp(event, 'alertDialogboxDiv', top);
  }
  //debugger;
  top.popUp(event, 'alertDialogboxDiv', top);
  divTop = parseInt(containerDiv.style.top) - 250;
  containerDiv.style.top = divTop + 'px';
  //alert('line 20 containerDiv.offsetTop = ' + containerDiv.offsetTop);
  //alert('line 21 containerDiv.clientTop = ' + containerDiv.clientTop);
  //alert('line 22 containerDiv.currentStyle.top = ' + containerDiv.currentStyle.top);
  if (containerDiv.offsetTop < 0) 
  {
    containerDiv.style.top = '0px';
  }
  alertDialogboxHeaderDiv = top.document.getElementById('alertDialogboxHeaderDiv');
  if (!top.alertDialogboxAlreadyOpened)
  {
    new top.movingDiv(containerDiv.id, alertDialogboxHeaderDiv.id);
    top.alertDialogboxAlreadyOpened = true;
  }
  //alert('line 101');
  //top.frames[5].document.getElementById('alertName').focus();
  alertDialogboxDocument = top.frames['alertDialogbox'].document;
  alertDialogboxDocument.getElementById('alertName').focus();
  //alert('line 101 top.frames["alertDialogbox"].document.getElementById("newsSources").offsetWidth = ' + top.frames['alertDialogbox'].document.getElementById("newsSources").offsetWidth);
  offsetWidth = alertDialogboxDocument.getElementById('newsSources').offsetWidth;
  alertDialogboxDocument.getElementById('alertName').style.width = (offsetWidth - 5) + 'px';
  //alert('line 107 alertDialogboxDocument.getElementById("alertName").style.width = ' + alertDialogboxDocument.getElementById('alertName').style.width);
  alertDialogboxDocument.getElementById('newsCategory').style.width = (offsetWidth - 5) + 'px';
  alertDialogboxDocument.getElementById('newsCategoryButton').style.width = (offsetWidth - 5) + 'px';
  alertDialogboxDocument.getElementById('newsSourcesButton').style.width = (offsetWidth ) + 'px';
  //alert('line 109 alertDialogboxDocument.getElementById("newsCategory").style.width = ' + alertDialogboxDocument.getElementById('newsCategory').style.width);
  offsetWidth = alertDialogboxDocument.getElementById('newsIndustry').offsetWidth;
  alertDialogboxDocument.getElementById('indexes').style.width = (offsetWidth) + 'px';
  alertDialogboxDocument.getElementById('newsIndustryButton').style.width = (offsetWidth) + 'px';
  alertDialogboxDocument.getElementById('indexesButton').style.width = (offsetWidth) + 'px';
  //alert('line 112 alertDialogboxDocument.getElementById("indexes").style.width = ' + alertDialogboxDocument.getElementById('indexes').style.width);
  alertDialogboxDocument.getElementById('textSymbols').style.width = (offsetWidth - 5) + 'px';
  //alert('line 114 alertDialogboxDocument.getElementById("textSymbols").style.width = ' + alertDialogboxDocument.getElementById('textSymbols').style.width);
} 

function showAlertList() 
{
  var evnt;
  var containerDiv;

  //alert('line 127');
  window.event.returnValue = false;
  window.event.cancelBubble = true;
  //evnt = top.copyClientXY();
  containerDiv = document.getElementById('alertListDiv');
  if (containerDiv.currentStyle.visibility == "visible") 
  {
    top.popUp(event, 'alertListDiv', top);
  }
  //debugger;
  top.popUp(event, 'alertListDiv', top);
}

function showTickerForDbTDDiv() 
{
  var evnt;
  var containerDiv;
  var frame;
  var txtTicker;
  var divTop;
  
  //alert('line 123');
  frame = top.frames['tickerForDbTD']; 
  frame.db = 'TD ';
  frame.document.getElementById('lblTickerForDb').innerHTML = 'Please Enter a Ticker Symbol';
  frame.document.getElementById('tickerForDbSelect').style.display = 'none';
  txtTicker = frame.document.getElementById('txtTickerForDb');
  txtTicker.style.display = '';
  window.event.returnValue = false;
  window.event.cancelBubble = true;
  containerDiv = top.document.getElementById('tickerForDbTDDiv');
  //containerDiv.className = 'showDiv';
  if (containerDiv.currentStyle.visibility == "visible") 
  {
     top.popUp(event, 'tickerForDbTDDiv', top);   
  }
  top.popUp(event, 'tickerForDbTDDiv', top);
  divTop = parseInt(containerDiv.style.top) - 50;
  containerDiv.style.top = divTop + 'px';
  //     alert('line 136 containerDiv.currentStyle.visibility = ' + containerDiv.currentStyle.visibility);
//     alert('line 137 containerDiv.className = ' + containerDiv.className);
//     alert('line 138 containerDiv.id = ' + containerDiv.id);
//     alert('line 139 containerDiv.currentStyle.top = ' + containerDiv.currentStyle.top);
//     alert('line 140 containerDiv.currentStyle.left = ' + containerDiv.currentStyle.left);
     //     alert('line 141 containerDiv.currentStyle.display = ' + containerDiv.currentStyle.display);
  txtTicker.focus();
  //frame.document.getElementById('lblTickerForDb').focus();
}

function showTickerForDbDiv() 
{
  var evnt;
  var containerDiv;
  var frame;
  var divTop;
  
  //alert('line 149');
  frame = top.frames['tickerForDb'];
  frame.db = 'SC ';
  frame.document.getElementById('lblTickerForDb').innerHTML = 'Please Enter Ticker Symbol(s)<br />Or  Select a Group of Symbols';
  frame.document.getElementById('tickerForDbSelect').style.display = '';
  frame.document.getElementById('txtTickerForDb').style.display = 'none';
  //frame.document.getElementById('txtTickerForDb').value = 'T/NW_RUSSELL_1000';
  window.event.returnValue = false;
  window.event.cancelBubble = true;
  containerDiv = top.document.getElementById('tickerForDbDiv');
  if (containerDiv.currentStyle.visibility == "visible") 
  {
     top.popUp(event, 'tickerForDbDiv', top);   
  }
  top.popUp(event, 'tickerForDbDiv', top);
  divTop = parseInt(containerDiv.style.top) - 50;
  containerDiv.style.top = divTop + 'px';
}

function showAudio()
{
  var evnt;
  var containerDiv;

  window.event.returnValue = false;
  window.event.cancelBubble = true;
  containerDiv = document.getElementById('AudioDiv');
  if (containerDiv.currentStyle.visibility == "visible")
  {
    top.popUp(event, 'AudioDiv', top);
  }
  top.popUp(event, 'AudioDiv', top);
}

function closeAudio()
{
  window.event.returnValue = false;
  window.event.cancelBubble = true;
  top.popUp(event, 'AudioDiv', top);
}

function showCategoryCodes()
{
  var containerDiv;
  
  //alert('line 222');
  window.event.returnValue = false;
  window.event.cancelBubble = true;

  containerDiv = document.getElementById('categoryCodesDiv');
  if (containerDiv.currentStyle.visibility == "visible")
  {
    top.popUp(event, 'categoryCodesDiv', top);
  }
  top.popUp(event, 'categoryCodesDiv', top);
}

function showHistoricalTool()
{
  var evnt;
  var containerDiv;
  var beforeTimeSelect;
  var afterTimeSelect;

  //alert('line 9');
  window.event.returnValue = false;
  window.event.cancelBubble = true;		  
  evnt = top.copyClientXY(event);
	containerDiv = document.getElementById('historicalToolDiv');
	if(containerDiv.currentStyle.visibility == "visible")
	{
	  top.popUp(evnt, 'historicalToolDiv', top);
 	}
 	//debugger;   
 	top.popUp(evnt,'historicalToolDiv', top);
 	//top.frames[3].document.getElementById('exp').focus();
 	//top.frames['historicalTool'].document.getElementById('exp').focus();
 	top.frames['historicalTool'].document.getElementById('textSymbols').focus();
 	//beforeTimeSelect = top.frames[3].document.getElementById('before');
 	beforeTimeSelect = top.frames['historicalTool'].document.getElementById('before');
 	beforeTimeSelect.options[0].selected = true;
 	if (!afterTimeHasBeenSet) 
 	{
 	  //afterTimeSelect = top.frames[3].document.getElementById('after');
 	  afterTimeSelect = top.frames['historicalTool'].document.getElementById('after');
 	  afterTimeSelect.options[3].selected = true;
 	}
}

function hideHistoricalTool()
{
  //alert('line 32');
  top.popUp(event, 'historicalToolDiv', top);
	window.event.returnValue = false;
	window.event.cancelBubble = true;
}

function closeCategoryCodesDialogbox()
{
  //alert('line 151');
  top.popUp(event, 'categoryCodesDiv', top);
}


function closeAlertDialogbox() 
{
  //document.getElementById('alertName').value = '';
  //document.getElementById('exp').value = '';
  setAlertDefaults(top.frames['alertDialogbox']);
  top.popUp(event, 'alertDialogboxDiv', top);
}

function closeAlertList() 
{
  top.popUp(event, 'alertListDiv', top);
}

function getAlertProperties() 
{
  var queryString = '';
  var expression = '';
  var expressionArray;
  var newsSources = '';
  var newsSourcesArray;
  var newsSourcesSelect;
  var indexes = '';
  var indexesArray;
  var indexesSelect;
  var numHeadlines;
  var numHeadlinesSelect;
  var newsCategory = '';
  var newsCategoriesArray;
  var newsCategorySelect;
  var newsIndustry = '';
  var newsIndustriesArray;
  var newsIndustrySelect;
  var beforeTimeSelect;
  var afterTimeSelect;
  var beforeTime;
  var afterTime;
  var fontSize;
  var fontSizeSelect;
  var fontFamily;
  var fontFamilySelect;
  var tickerChk;
  var headlineChk;
  var filterDuplicatesChk;
  var activeChk;
  var alertName;
  var newName;
  var alreadyActive = false;
  var i;
  var j;
  var txtbox;
  var foregroundColor = ""
  var backgroundColor = ""
  var reqId;
  var alertObj = new Object();
  var expressionTable = document.getElementById('expressionTable');
  var temp;
  var temp2;
  var startIndex = 0;
  var endIndex;
  var subscript = 0;
  var index;
  var keyword;

  //debugger;
  //alert('line 344');
  alertName = document.getElementById('alertName').value;
  if (!alertName)
  {
    alert('Please Enter an Alert Name');
    return;
  }
  temp = expressionTable.rows[1].cells[0].innerHTML.toLowerCase();
  temp = temp.replace(/^\s+|\s+$/g, "");
  for (i = 0; i < temp.length; i++)
  {
    if (temp.charCodeAt(i) >= 32)
    {
      temp = temp.slice(i);
      break;
    }
  }
  temp2 = expressionTable.rows[1].cells[1].innerHTML.toLowerCase();
  temp2 = temp2.replace(/^\s+|\s+$/g, "");
  for (i = 0; i < temp2.length; i++)
  {
    if (temp2.charCodeAt(i) >= 32)
    {
      temp2 = temp2.slice(i);
      break;
    }
  }
  //alert('line 372 temp2 = ' + temp2);
  //alert('line 373 temp2.length = ' + temp2.length);
  //if (expressionTable.rows[1].cells[0].innerHTML || expressionTable.rows[1].cells[1].innerHTML)
  if (temp || temp2)
  {
    expressionArray = new Array();
    //if (expressionTable.rows[1].cells[0].innerHTML && expressionTable.rows[1].cells[0].innerHTML.toLowerCase() != '<div></div>')
    //if (expressionTable.rows[1].cells[0].innerHTML)
    if (temp)
    {
      while (true)
      {
        endIndex = temp.indexOf('<br', startIndex);
        if (temp.slice(startIndex, endIndex).replace(/^\s+|\s+$/g, ""))
        {
          expressionArray[subscript] = temp.slice(startIndex, endIndex).replace(/^\s+|\s+$/g, "");
          subscript++;
        }
        if ((temp.indexOf('>') != -1) && (temp.indexOf('>') < (temp.length - 1)))
        {
          temp = temp.slice(temp.indexOf('>') + 1);
        }
        else
        {
          break;
        } 
      }
    }
    //alert('line 385 expressionArray.length = ' + expressionArray.length);
    //if (expressionTable.rows[1].cells[1].innerHTML && expressionTable.rows[1].cells[1].innerHTML.toLowerCase() != '<div></div>')
    temp = temp2;
    //if (expressionTable.rows[1].cells[1].innerHTML)
    if (temp)
    {
      while (true)
      {
        endIndex = temp.indexOf('<br', startIndex);
        if (temp.slice(startIndex, endIndex).replace(/^\s+|\s+$/g, ""))
        {
          keyword = temp.slice(startIndex, endIndex).replace(/^\s+|\s+$/g, "");
          keyword = top.addQuotes(keyword);
          expressionArray[subscript] = keyword;
          subscript++;
        }
        if ((temp.indexOf('>') != -1) && (temp.indexOf('>') < (temp.length - 1)))
        {
          temp = temp.slice(temp.indexOf('>') + 1);
        }
        else
        {
          break;
        } 
      }
    }
    //alert('line 424 expressionArray.length = ' + expressionArray.length);
    for (i = 0; i < expressionArray.length; i++)
    {
      //alert('line 377 expressionArray[i] = ' + expressionArray[i]);
      if (expression)
      {
        //alert('line 419 expression = ' + expression);
        expression += ' ' + expressionArray[i];
        //alert('line 421 expression = ' + expression);
      }
      else
      {
        //alert('line 425 expression = ' + expression);
        expression = expressionArray[i];
        //alert('line 427 expression = ' + expression);
      }
    }
    //alert('line 438 expression = ' + expression);
    if (expression)
    {
      expression = '(' + expression + ')';
    }  
    //alert('line 442 expression = ' + expression);
  }
  //alert('line 440 expression = ' + expression);
  //alert('line 375 expressionTable.rows[1].cells[2].innerHTML.indexOf('All News Sources') = ' + expressionTable.rows[1].cells[2].innerHTML.indexOf('All News Sources'));
  newsSourcesSelect = document.getElementById('newsSources');
  temp = expressionTable.rows[1].cells[2].innerHTML.toLowerCase();
  temp = temp.replace(/^\s+|\s+$/g, "");
  for (i = 0; i < temp.length; i++)
  {
    if (temp.charCodeAt(i) >= 32)
    {
      temp = temp.slice(i);
      break;
    }
  }
  //newsSources = '(' + newsSourcesSelect.options[newsSourcesSelect.selectedIndex].value + ') ';
  //alert('line 444 expressionTable.rows[1].cells[2].innerHTML.indexOf("All News Sources") = ' + expressionTable.rows[1].cells[2].innerHTML.indexOf('All News Sources'));
  //alert('line 445 expressionTable.rows[1].cells[2].innerHTML = ' + expressionTable.rows[1].cells[2].innerHTML);
  //if (expressionTable.rows[1].cells[2].innerHTML && expressionTable.rows[1].cells[2].innerHTML.indexOf('All News Sources') == -1)
  if (temp && temp.indexOf('All News Sources') == -1)
  {
    //alert('line 448');
    //newsSourcesArray = expressionTable.rows[1].cells[2].innerHTML.split(')(');
    //alert('line 451 temp = ' + temp);
    //for (i = 0; i < temp.length; i++)
    //{
      //alert('line 333 temp.charCodeAt(i) = ' + temp.charCodeAt(i));
    //}
    //startIndex = 0;
    subscript = 0;
    newsSourcesArray = new Array();
    //alert('line 467 temp = ' + temp);
    while (true) 
    {
      endIndex = temp.indexOf('<br', startIndex);
      if (temp.slice(startIndex, endIndex).replace(/^\s+|\s+$/g, ""))
      {
        newsSourcesArray[subscript] = temp.slice(startIndex, endIndex).replace(/^\s+|\s+$/g, "");
        //alert('line 467 newsSourcesArray[subscript] = ' + newsSourcesArray[subscript]);
        subscript++;
      }
      if ((temp.indexOf('>') != -1) && (temp.indexOf('>') < (temp.length - 1)))
      {
        temp = temp.slice(temp.indexOf('>') + 1);
      }
      else
      {
        break;
      }
    }
    for (i = 0; i < newsSourcesArray.length; i++)
    {
      //alert('line 488 newsSourcesArray[i] = ' + newsSourcesArray[i]);
      //alert('line 376 newsSourcesArray[i].length = ' + newsSourcesArray[i].length);
      for (j = 0; j < newsSourcesSelect.options.length; j++)
      {
        //alert('line 492 newsSourcesSelect.options[j].innerHTML = ' + newsSourcesSelect.options[j].innerHTML);
        //alert('line 380 newsSourcesSelect.options[j].innerHTML.length = ' + newsSourcesSelect.options[j].innerHTML.length);
        if (newsSourcesArray[i] == newsSourcesSelect.options[j].innerHTML.toLowerCase())
        {
          //alert('line 491 newsSourcesSelect.options[j].value = ' + newsSourcesSelect.options[j].value);
          if (newsSources)
          {
            //alert('line 499 newsSourcesSelect.options[j].value = ' + newsSourcesSelect.options[j].value);
            newsSources += ' ' + newsSourcesSelect.options[j].value;
            break;
          }
          else
          {
            //alert('line 505');
            newsSources = newsSourcesSelect.options[j].value;
            break;
          }  
        }
      }
    }
    if(newsSources)
    {
      newsSources = '(' + newsSources + ')';
    }   
  }  
  //alert('line 526 newsSources = ' + newsSources);
  numHeadlinesSelect = document.getElementById('numHeadlines');
  numHeadlines = parseInt(numHeadlinesSelect.options[numHeadlinesSelect.selectedIndex].value); indexesSelect
  
  indexesSelect = document.getElementById('indexes');
  temp = expressionTable.rows[1].cells[3].innerHTML.toLowerCase();
  temp = temp.replace(/^\s+|\s+$/g, "");
  //alert('line 533 temp = ' + temp);
  //alert('line 534 temp.length = ' + temp.length);
  //alert('line 525');
  for (i = 0; i < temp.length; i++)
  {
    //alert('line 527 temp.length = ' + temp.length);
    //alert('line 528 i = ' + i);
    //alert('line 529 temp.charCodeAt(i) = ' + temp.charCodeAt(i));
    if (temp.charCodeAt(i) >= 32)
    {
      //alert('line 525');
      temp = temp.slice(i);
      break;
    }
  }
  //alert('line 548 temp.length = ' + temp.length);
  //alert('line 539 (temp && temp.indexOf("All Indexes") == -1) = ' + (temp && temp.indexOf('All Indexes') == -1));
  //alert('line 540 temp = ' + temp);
  //if (expressionTable.rows[1].cells[3].innerHTML && expressionTable.rows[1].cells[3].innerHTML.indexOf('All Indexes') == -1)
  if (temp && temp.indexOf('All Indexes') == -1)
  {
    //alert('line 554');
    //startIndex = 0;
    subscript = 0;
    indexesArray = new Array();
    while (true)
    {
      endIndex = temp.indexOf('<br', startIndex);
      if (temp.slice(startIndex, endIndex).replace(/^\s+|\s+$/g, ""))
      {
        //alert('line 563 temp.slice(startIndex, endIndex).replace(/^\s+|\s+$/g, "") = ' + temp.slice(startIndex, endIndex).replace(/^\s+|\s+$/g, ""));
        indexesArray[subscript] = temp.slice(startIndex, endIndex).replace(/^\s+|\s+$/g, "");
        //alert('line 565 indexesArray[subscript] = ' + indexesArray[subscript]);
        subscript++;
      }
      //alert('line 566 temp.indexOf(">") = ' + temp.indexOf('>') );
      if ((temp.indexOf('>') != -1) && (temp.indexOf('>') < (temp.length - 1)))
      {
        temp = temp.slice(temp.indexOf('>') + 1);
      }
      else
      {
        break;
      }
      //alert('line 558');
    }
    //alert('line 560');
    //alert('line 466 indexesArray.length = ' + indexesArray.length);
    for (i = 0; i < indexesArray.length; i++)
    {
      //alert('line 583 indexesArray[i] = ' + indexesArray[i]);
      for (j = 0; j < indexesSelect.options.length; j++)
      {
        //alert('line 586 indexesSelect.options[j].innerHTML.toLowerCase() = ' + indexesSelect.options[j].innerHTML.toLowerCase());
        if (indexesArray[i] == indexesSelect.options[j].innerHTML.toLowerCase())
        {
          if (indexes)
          {
            //alert('line 594 j = ' + j);
            //alert('line 595 indexesSelect.options[j].value = ' + indexesSelect.options[j].value);
            indexes += ' ' + indexesSelect.options[j].value;
            //alert('line 596 indexes = ' + indexes);
            break;
          }
          else
          {
            //alert('line 481');
            //alert('line 603 j = ' + j);
            //alert('line 604 indexesSelect.options[j].value = ' + indexesSelect.options[j].value);
            indexes = indexesSelect.options[j].value;
            //alert('line 605 indexes = ' + indexes);
            break;
          }
        }
      }
    }
    indexes = '(' + indexes + ')';
    //alert('line 609 indexes = ' + indexes);
  }
  //alert('line 578');
  newsCategorySelect = document.getElementById('newsCategory');
  temp = expressionTable.rows[1].cells[4].innerHTML.toLowerCase();
  temp = temp.replace(/^\s+|\s+$/g, "");
  for (i = 0; i < temp.length; i++)
  {
    if (temp.charCodeAt(i) >= 32)
    {
      temp = temp.slice(i);
      break;
    }
  }
  //if (expressionTable.rows[1].cells[4].innerHTML && expressionTable.rows[1].cells[4].innerHTML.indexOf('All News Categories') == -1)
  if (temp && temp.indexOf('All News Categories') == -1)
  {
    //startIndex = 0;
    subscript = 0;
    newsCategoriesArray = new Array();
    while (true) 
    {
      endIndex = temp.indexOf('<br', startIndex);
      if (temp.slice(startIndex, endIndex).replace(/^\s+|\s+$/g, ""))
      {
        newsCategoriesArray[subscript] = temp.slice(startIndex, endIndex).replace(/^\s+|\s+$/g, "");
        subscript++;
      }
      if ((temp.indexOf('>') != -1) && (temp.indexOf('>') < (temp.length - 1)))
      {
        temp = temp.slice(temp.indexOf('>') + 1);
      }
      else
      {
        break;
      }  
    }
    for (i = 0; i < newsCategoriesArray.length; i++)
    {
      for (j = 0; j < newsCategorySelect.options.length; j++)
      {
        if (newsCategoriesArray[i] == newsCategorySelect.options[j].innerHTML.toLowerCase())
        {
          if (newsCategory)
          {
            //alert('line 389');
            newsCategory += ' ' + newsCategorySelect.options[j].value;
            break;
          }
          else
          {
            //alert('line 395');
            newsCategory = newsCategorySelect.options[j].value;
            break;
          }  
        }
      }
    }
    newsCategory = '(' + newsCategory + ')';
    //alert('line 499 newsCategory = ' + newsCategory);
  }
  //alert('line 634');  
  newsIndustrySelect = document.getElementById('newsIndustry');
  temp = expressionTable.rows[1].cells[5].innerHTML.toLowerCase();
  temp = temp.replace(/^\s+|\s+$/g, "");
  for (i = 0; i < temp.length; i++)
  {
    if (temp.charCodeAt(i) >= 32)
    {
      temp = temp.slice(i);
      break;
    }
  }
  //if (expressionTable.rows[1].cells[5].innerHTML && expressionTable.rows[1].cells[5].innerHTML.indexOf('All News Industries') == -1)
  if (temp && temp.indexOf('All News Industries') == -1)
  {
    //startIndex = 0;
    subscript = 0;
    newsIndustriesArray = new Array();
    while (true)
    {
      endIndex = temp.indexOf('<br', startIndex);
      if (temp.slice(startIndex, endIndex).replace(/^\s+|\s+$/g, ""))
      {
        newsIndustriesArray[subscript] = temp.slice(startIndex, endIndex).replace(/^\s+|\s+$/g, "");
        subscript++;
      }
      if ((temp.indexOf('>') != -1) && (temp.indexOf('>') < (temp.length - 1)))
      {
        temp = temp.slice(temp.indexOf('>') + 1);
      }
      else
      {
        break;
      }
    }
    for (i = 0; i < newsIndustriesArray.length; i++)
    {
      for (j = 0; j < newsIndustrySelect.options.length; j++)
      {
        if (newsIndustriesArray[i] == newsIndustrySelect.options[j].innerHTML.toLowerCase())
        {
          if (newsIndustry)
          {
            //alert('line 389');
            newsIndustry += ' ' + newsIndustrySelect.options[j].value;
            break;
          }
          else
          {
            //alert('line 395');
            newsIndustry = newsIndustrySelect.options[j].value;
            break;
          }  
        }
      }
    }
    newsIndustry = '(' + newsIndustry + ')';
    //alert('line 546 newsIndustry = ' + newsIndustry);  
  }
  //alert('line 692 newsIndustry = ' + newsIndustry);  
  fontSizeSelect = document.getElementById('fontSize');
  fontSize = fontSizeSelect.options[fontSizeSelect.selectedIndex].value;
  fontFamilySelect = document.getElementById('fontFamily');
  fontFamily = fontFamilySelect.options[fontFamilySelect.selectedIndex].value;
  //txtbox = top.frames[5].document.getElementById('displayColor');
  txtbox = top.frames['alertDialogbox'].document.getElementById('displayColor1');
  foregroundColor = txtbox.style.color; 
  backgroundColor = txtbox.style.backgroundColor;
  //alert('line 126 top.expressions = ' + top.expressions);
  //alert('line 612 top.expressions.length = ' + top.expressions.length);
  for (i = 0; i < top.expressions.length; i++) 
  {
    if (top.expressions[i] && top.expressions[i][top.alertNameIndex] == alertName) 
    {
      reqId = i;
      newName = false;
      //alert('line 276 newName = ' + newName);
      if (top.expressions[i][top.activeIndex] == true)
      {
        alreadyActive = true;
      }
      break;
    }
  }
  if (i == top.expressions.length) 
  {
    newName = true;
    top.alertReqID++;
    reqId = top.alertReqID; 
  }
  //alert('line 623');
  //afterTimeSelect = top.frames[5].document.getElementById('after');
  afterTimeSelect = top.frames['alertDialogbox'].document.getElementById('after');
  //alert('line 726 afterTimeSelect.selectedIndex = ' + afterTimeSelect.selectedIndex);
  switch (afterTimeSelect.selectedIndex) 
  {
    case 0:
      afterTime = parseInt(new Date().getTime() / 1000) - 86400;
      break;
    case 1:
      afterTime = parseInt(new Date().getTime() / 1000) - (2 * 86400);
      break;
    case 2:
      afterTime = parseInt(new Date().getTime() / 1000) - (3 * 86400);
      break;
    case 3:
      afterTime = parseInt(new Date().getTime() / 1000) - (7 * 86400);
      break;
    case 4:
      afterTime = parseInt(new Date().getTime() / 1000) - (14 * 86400);
      break;
    case 5:
      afterTime = parseInt(new Date().getTime() / 1000) - (31 * 86400);
      break;
    case 6:
      afterTime = parseInt(new Date().getTime() / 1000) - (92 * 86400);
      break;
    case 7:
      afterTime = parseInt(new Date().getTime() / 1000) - (1100 * 86400);
      break;
    case 9:
      afterTime = afterTimeSelect.options[9].innerHTML;
      break;
  }
  tickerChk = document.getElementById('tkr');
  headlineChk = document.getElementById('hdl');
  filterDuplicatesChk = document.getElementById('dup');
  activeChk = document.getElementById('active');
  //alert('line 700 tickerChk = ' + tickerChk);
  //alert('line 291 headlineChk = ' + headlineChk);
  //alert('line 292 filterDuplicatesChk = ' + filterDuplicatesChk);
  //alert('line 792 expression = ' + expression);
  if (expression) 
  {
    queryString =  expression;
  }
  //alert('line 797 newsSources = ' + newsSources);
  //alert('line 299 newsSources.length = ' + newsSources.length);
  //if (newsSources != '(AllSources) ')
  if (newsSources)
  {
    if (queryString) 
    {
      queryString += ' & ' + newsSources;
    }
    else 
    {
      queryString = newsSources;
    }
    //alert('line 776 queryString = ' + queryString);
  }
  //alert('line 445 newsSources = ' + newsSources);
  if (indexes)
  {
    if (queryString)
    {
      queryString += ' & ' + indexes;
    }
    else
    {
      queryString = indexes;
    }
    //alert('line 776 queryString = ' + queryString);
  }
  //if (newsCategory != '() ')
  if (newsCategory)
  {
    if (queryString) 
    {
      queryString += ' & ' + newsCategory;
    }
    else 
    {
      queryString = newsCategory;
    }
  }
  //if (newsIndustry != '() ')
  if (newsIndustry )
  {
    if (queryString) 
    {
      queryString += ' & ' + newsIndustry;
    }
    else 
    {
      queryString = newsIndustry;
    }
  }
  //alert('line 837 queryString = ' + queryString);
  if (!queryString) 
  {
    queryString = '(allsyms)';
  }
  //alert('line 426 queryString.trim() = ' + queryString.trim());
  //alert('line 723 top.allSyms = ' + top.allSyms);
  if (queryString.search(/allsyms/) >= 0)
  {
    if (top.allSyms == true)
    {
      //alert('line 718 top.expressions.length = ' + top.expressions.length);
      //alert('line 719 newName = ' + newName);
      //alert('line 720 top.expressions[reqId] = ' + top.expressions[reqId]);
      //alert('line 721 top.expressions[reqId][top.exprIndex] = ' + top.expressions[reqId][top.exprIndex]);
      //if (reqId == top.expressions.length || (reqId < top.expressions.length && (top.expressions[reqId][top.exprIndex].search(/allsyms/) != -1)))
      if (newName == true || (top.expressions[reqId][top.exprIndex].search(/allsyms/) != -1))
      {
        alert('You already have an "allsyms" alert');
        return;
      }
    }
    else
    {
      top.allSyms = true;
    }
  }
  //alert('line 774 queryString = ' + queryString);
  alertObj.queryString = queryString;

  //alertObj.numHeadlines = 0;
  alertObj.numHeadlines = numHeadlines;
  alertObj.afterTime = afterTime;
  alertObj.reqId = reqId;
  alertObj.newName = newName;
  alertObj.alertName = alertName;
  alertObj.expression = expression;
  alertObj.newsSources = newsSources;
  alertObj.newsCategory = newsCategory;
  alertObj.newsIndustry = newsIndustry;
  alertObj.indexes = indexes;
//  alert('line 727 expression = ' + expression);
//  alert('line 728 newsSources = ' + newsSources);
//  alert('line 729 newsCategory = ' + newsCategory);
//  alert('line 730 newsIndustry = ' + newsIndustry);
//  alert('line 731 indexes = ' + indexes);
//  //if (newsSources != '(AllSources) ')
//  if (newsSources)
//  {
//    alertObj.newsSources = newsSources;
//  }
//  //if (newsCategory != '() ')
//  if (newsCategory)
//  {
//    alertObj.newsCategory = newsCategory;
//  }
//  //if (newsIndustry != '() ')
//  if (newsIndustry)
//  {
//    alertObj.newsIndustry = newsIndustry;
//  }
//  if (indexes)
//  {
//    alertObj.indexes = indexes;
//  }
  alertObj.afterTime = afterTime;
  alertObj.afterTimeIndex = afterTimeSelect.selectedIndex;
  //alert('line 327 afterTimeSelect.selectedIndex = ' + afterTimeSelect.selectedIndex);
  alertObj.fontFamily = fontFamily;
  alertObj.fontSize = fontSize;
  alertObj.foregroundColor = foregroundColor;
  alertObj.backgroundColor = backgroundColor;
  alertObj.filterDuplicatesChk = filterDuplicatesChk.checked;
  alertObj.tickerChk = tickerChk.checked;
  alertObj.headlineChk = headlineChk.checked;
  alertObj.activeChk = activeChk.checked;
  alertObj.alreadyActive = alreadyActive;
//  alert('line 357 filterDuplicatesChk.checked = ' + filterDuplicatesChk.checked);
//  alert('line 358 tickerChk.checked = ' + tickerChk.checked);
//  alert('line 359 headlineChk.checked = ' + headlineChk.checked);
//  alert('line 360 activeChk.checked = ' + activeChk.checked);
//  alert('line 361 alertObj.filterDuplicatesChk = ' + alertObj.filterDuplicatesChk);
//  alert('line 362 alertObj.tickerChk = ' + alertObj.tickerChk);
//  alert('line 363 alertObj.headlineChk = ' + alertObj.headlineChk);
//  alert('line 364 alertObj.activeChk = ' + alertObj.activeChk);
  alertObj.queryString = queryString;
  //alert('line 922 queryString = ' + queryString);
  recordAlertInfo(alertObj, true);
  //alert('line 859 reqId = ' + reqId);
  //alert('line 391 top.expressions[reqId] = ' + top.expressions[reqId]);
  if (activeChk.checked)
  {
    //alert('line 863 reqId = ' + reqId);
    top.setFont(alertObj, reqId);
    //alert('line 396 reqId = ' + reqId);
    if (alertObj.foregroundColor)
    {
      //alert('line 398 reqId = ' + reqId);
      top.setForegroundColor(alertObj.foregroundColor, alertObj.reqId, false);
      //alert('line 400 reqId = ' + reqId);
    }
    if (alertObj.backgroundColor)
    {
      //alert('line 871 reqId = ' + reqId);
      top.setBackgroundColor(alertObj.backgroundColor, alertObj.reqId, false);
      //alert('line 406 reqId = ' + reqId);
    }
    alertObj.msgType = "AlertAdd";
    //alert('line 944');
    alertRequest(alertObj);
    //alert('line 946');
  }
  //alert('line 410 reqId = ' + reqId);
  setAlertDefaults(window);
  top.popUp(event, 'alertDialogboxDiv', top);
  //alert('line 951');
}

function setAlertDefaults(alertDialogbox)
{
  var displayColorStyle;
  var afterSelect;
  var expressionTableRow;

  alertDialogbox.document.getElementById('alertName').value = '';
  //document.getElementById('exp').value = '';
  alertDialogbox.document.getElementById('textSymbols').value = '';
  alertDialogbox.document.getElementById('textKeywords').value = '';
  alertDialogbox.document.getElementById('newsSources').selectedIndex = 0;
  alertDialogbox.document.getElementById('indexes').selectedIndex = 0;
  alertDialogbox.document.getElementById('newsCategory').selectedIndex = 0;
  alertDialogbox.document.getElementById('newsIndustry').selectedIndex = 0;
  afterSelect = alertDialogbox.document.getElementById('after');
  afterSelect.options[9].innerHTML = '';
  afterSelect.selectedIndex = 3; 
  //alert('line 388 afterSelect.selectedIndex = ' + afterSelect.selectedIndex);
  expressionTableRow = alertDialogbox.document.getElementById('expressionTable').rows[1];
  for (var i = 0; i < expressionTableRow.cells.length; i++)
  {
    expressionTableRow.cells[i].innerHTML = '';
  }
  alertDialogbox.document.getElementById('numHeadlines').selectedIndex = 1;
  alertDialogbox.document.getElementById('newsCategory').selectedIndex = 0;
  alertDialogbox.document.getElementById('fontFamily').selectedIndex = 0;
  alertDialogbox.document.getElementById('newsIndustry').selectedIndex = 0;
  alertDialogbox.document.getElementById('selectColor').selectedIndex = 0;
  alertDialogbox.document.getElementById('fontSize').selectedIndex = 0;
  displayColorStyle = alertDialogbox.document.getElementById('displayColor1').style;
  displayColorStyle. backgroundColor= 'beige';
  displayColorStyle.color = 'black';
  displayColorStyle = alertDialogbox.document.getElementById('displayColor2').style;
  displayColorStyle.backgroundColor = 'green';
  displayColorStyle.color = 'black';
  displayColorStyle = alertDialogbox.document.getElementById('displayColor3').style;
  displayColorStyle.backgroundColor = 'white';
  displayColorStyle.color = 'black';
  alertDialogbox.document.getElementById('tkr').checked = false;
  alertDialogbox.document.getElementById('dup').checked = true;
  alertDialogbox.document.getElementById('hdl').checked = false;
  alertDialogbox.document.getElementById('active').checked = true;
}

function setQueryDefaults()
{
  var beforeSelect;
  var afterSelect;
  //alert('line 400');
  //document.getElementById('exp').value = '';
  document.getElementById('textSymbols').value = '';
  document.getElementById('textKeywords').value = '';
  document.getElementById('newsSources').selectedIndex = 0;
  beforeSelect = document.getElementById('before');
  beforeSelect.selectedIndex = 0;
  beforeSelect.options[2].innerHTML = '';
  afterSelect = document.getElementById('after');
  afterSelect.options[9].innerHTML = '';
  afterSelect.selectedIndex = 3;
  document.getElementById('numHeadlines').selectedIndex = 1;
  document.getElementById('newsCategory').selectedIndex = 0;
  document.getElementById('newsIndustry').selectedIndex = 0;
  document.getElementById('tkr').checked = false;
  document.getElementById('dup').checked = true;
  document.getElementById('hdl').checked = false;
}

function recordAlertInfo(alertObj, alertRequest) 
{
  var alertListTable;
  
  //alert('line 960');
  //if (alertObj.newName || alertObj.msgType == 'QueryAdd')
  if (alertObj.newName)
  {
    //alert('line 344 alertObj.activeChk = ' + alertObj.activeChk);
    if (alertObj.activeChk == false)
    {
      //alert('line 578');
      //top.frames[4].insRow(alertObj.reqId, alertObj.alertName, alertObj.activeChk)
      top.frames['alertList'].insRow(alertObj.reqId, alertObj.alertName, alertObj.activeChk)
    }
    else 
    {
      //alert('line 584');
      top.frames['alertList'].insRow(alertObj.reqId, alertObj.alertName, 'checked')//if undefined it should also be checked
    }
  }
  else if(alertObj.alreadyActive)
  {
    if (alertObj.activeChk == false)
    {
      top.sendDeletAlertRequest(requestId);    
 		}
    else
    {
      reqStr = "msgType=AlertDelete&sessionID=" + top.sessionID + "&reqID=" + alertObj.reqId;
      top.sendhttpRequest(reqStr, "nw_web.asp");
    }  
  }
  else if(alertRequest && alertObj.activeChk == true)
  {
    alertListTable = top.frames['alertList'].document.getElementById('tmain1');
    //alert('line 1063 alertListTable = ' + alertListTable);
		for (i = 1; i < alertListTable.rows.length; i++)
		{
		  if (alertListTable.rows[i].cells[4].innerHTML == alertObj.reqId)
      {
        top.frames['alertList'].document.getElementById(alertObj.reqId + '2').checked = true;
        break;
      }
		}    
  } 
  //top.createHeader(alertObj.alertName, alertObj.reqId);
//      //if (alertObj.msgType != 'QueryAdd')
//      if (save)
//      {
//        //top.frames[4].insRow(alertObj.reqId, alertObj.alertName, 'checked')//if undefined it should also be checked
//        alert('line 488');
//        top.createHeader(alertObj.alertName, alertObj.reqId);
//      }
//      else if (alertObj.msgType == 'QueryAdd')
//      {
//        top.createHeader(alertObj.alertName, alertObj.reqId);
//      }
//      else
//      {
//        top.createHeader(alertObj.alertName, alertObj.reqId);
//      }  
//    }     
    top.expressions[alertObj.reqId] = new Array();
    top.expressions[alertObj.reqId][top.alertNameIndex] = alertObj.alertName;
    //alert('line 503');
    //alert('line 1022 alertObj.alertName = ' + alertObj.alertName);
    //alert('(line 345 alertObj.activeChk == false) = ' + (alertObj.activeChk == 'false'));
    //alert('(line 346 alertObj.activeChk == false) = ' + (alertObj.activeChk == false));

//  }
//  //alert('line 388 alertObj.alertName = ' + alertObj.alertName);
  //alert('line 640 alertObj.expression = ' + alertObj.expression);
  //alert('line 389 alertObj.reqId = ' + alertObj.reqId);
  //alert('line 3909 top.exprIndex = ' + top.exprIndex);
  top.expressions[alertObj.reqId][top.exprIndex] = alertObj.expression;
  //alert('line 1032 alertObj.expression = ' + alertObj.expression);
  top.expressions[alertObj.reqId][top.sourcesIndex] = alertObj.newsSources;
  //alert('line 1007 alertObj.newsSources = ' + alertObj.newsSources);
  //alert('line 1008 top.expressions[alertObj.reqId][top.sourcesIndex] = ' + top.expressions[alertObj.reqId][top.sourcesIndex]);
  top.expressions[alertObj.reqId][top.categoryIndex] = alertObj.newsCategory;
  top.expressions[alertObj.reqId][top.industryIndex] = alertObj.newsIndustry;
  top.expressions[alertObj.reqId][top.indexesIndex] = alertObj.indexes;
  top.expressions[alertObj.reqId][top.maxHdlsIndex] = alertObj.numHeadlines;
  top.expressions[alertObj.reqId][top.beforeTimeIndex] = alertObj.beforeTime;
  top.expressions[alertObj.reqId][top.afterTimeIndex] = alertObj.afterTime;
  top.expressions[alertObj.reqId][top.afterTimeIndexIndex] = alertObj.afterTimeIndex;
  //alert('line 398 alertObj.afterTimeIndex = ' + alertObj.afterTimeIndex);
  top.expressions[alertObj.reqId][top.fontFamilyIndex] = alertObj.fontFamily;
  top.expressions[alertObj.reqId][top.fontSizeIndex] = alertObj.fontSize;
  top.expressions[alertObj.reqId][top.foregroundColorIndex] = alertObj.foregroundColor;
  top.expressions[alertObj.reqId][top.backgroundColorIndex] = alertObj.backgroundColor;
  top.expressions[alertObj.reqId][top.filterDuplicatesIndex] = alertObj.filterDuplicatesChk;
  //alert('line 371 alertObj.filterDuplicatesChk.checked = ' + alertObj.filterDuplicatesChk.checked);
  //alert('line 372 top.expressions[alertObj.reqId][top.filterDuplicates] = ' + top.expressions[alertObj.reqId][top.filterDuplicatesIndex]);
  top.expressions[alertObj.reqId][top.tickerRequiredIndex] = alertObj.tickerChk;
  top.expressions[alertObj.reqId][top.matchHeadlineTextIndex] = alertObj.headlineChk;
  top.expressions[alertObj.reqId][top.activeIndex] = alertObj.activeChk;
  if (alertObj.dateCol || alertObj.dateCol == false)
  {
    top.expressions[alertObj.reqId][top.dateColIndex] = alertObj.dateCol;
  }
  if (alertObj.timeCol || alertObj.timeCol == false)
  {
    top.expressions[alertObj.reqId][top.timeColIndex] = alertObj.timeCol;
  }
  if (alertObj.tickerCol || alertObj.tickerCol == false)
  {
    top.expressions[alertObj.reqId][top.tickerColIndex] = alertObj.tickerCol;
  }
  if (alertObj.exchangeCol || alertObj.exchangeCol == false)
  {
    top.expressions[alertObj.reqId][top.exchangeColIndex] = alertObj.exchangeCol;
  }
  if (alertObj.lastPriceCol || alertObj.lastPriceCol == false)
  {
    top.expressions[alertObj.reqId][top.lastPriceColIndex] = alertObj.lastPriceCol;
  }
  top.expressions[alertObj.reqId][top.fullExpressionIndex] = alertObj.queryString;
  //alert('line 1109 alertObj.queryString = ' + alertObj.queryString);
  //alert('line 668 alertObj.tableHeight = ' + alertObj.tableHeight);
  if (!(alertObj.tableHeight == 'undefined'))
  {
    top.expressions[alertObj.reqId][top.tableHeightIndex] = alertObj.tableHeight;
    //alert('line 672 top.expressions[alertObj.reqId][top.tableHeightIndex] = ' + top.expressions[alertObj.reqId][top.tableHeightIndex]);
    //alert('line 673 typeof top.expressions[alertObj.reqId][top.tableHeightIndex] = ' + typeof top.expressions[alertObj.reqId][top.tableHeightIndex]);
//    if (typeof alertObj.tableHeight == 'undefined')
//    {
//      //alert('line 676 typeof top.expressions[alertObj.reqId][top.tableHeightIndex] = ' + typeof top.expressions[alertObj.reqId][top.tableHeightIndex]);
//    }
//    if (typeof top.expressions[alertObj.reqId][top.tableHeightIndex] == 'undefined')
//    {
//      //alert('line 680 typeof top.expressions[alertObj.reqId][top.tableHeightIndex] = ' + typeof top.expressions[alertObj.reqId][top.tableHeightIndex]);
//    }
  }  
  //alert('line 640 alertObj.displayTable = ' + typeof alertObj.displayTable);
  if (typeof alertObj.displayTable == 'undefined')
  {
    alertObj.displayTable = true; //default is to be displayed
  }  
  top.expressions[alertObj.reqId][top.displayTableIndex] = alertObj.displayTable;
  //alert('line 597 alertObj.alreadyActive = ' + alertObj.alreadyActive);
  //alert('line 598 top.expressions[alertObj.reqId][top.activeIndex] = ' + top.expressions[alertObj.reqId][top.activeIndex]);
  //alert('line 691');
  if (top.expressions[alertObj.reqId][top.activeIndex] && !alertObj.alreadyActive)
  {
    //alert('line 603 alertObj.reqId = ' + alertObj.reqId);
    //alert('line 695');
    top.createHeader(alertObj.alertName, alertObj.reqId);
  }  
  //alert('line 698');
}

function alertRequest(alertObj) 
{
  var reqStr;
  var formattedExpression;
  var beforeTime;

  //alert('line 494');
  if (alertObj.beforeTime)
  {
    reqStr = "msgType=" + alertObj.msgType;
  }
  else
  {
    reqStr = "msgType=AlertAdd"; //Make all requests, that beforeTime is not set, updating. Query requests are not saved.
  }  
  reqStr = reqStr + "&sessionID=" + top.sessionID;
  reqStr = reqStr + "&reqID=" + alertObj.reqId;
  formattedExpression = top.formatExpression(alertObj.queryString);
  reqStr = reqStr + "&exp=" + formattedExpression;
  //alert('line 1110 formattedExpression = ' + formattedExpression);
  //alert('line 1121 alertObj.queryString = ' + alertObj.queryString);
  reqStr += "&ticker=" + alertObj.tickerChk;
  reqStr += "&hdl=" + alertObj.headlineChk;
  reqStr += "&dup=" + alertObj.filterDuplicatesChk;
  reqStr += "&numHeadlines=" + alertObj.numHeadlines;
  if (alertObj.beforeTime)
  {
    beforeTime = alertObj.beforeTime;
  }
  else
  {
    beforeTime = parseInt(new Date().getTime() / 1000);
  }  
  reqStr += "&beforeTime=" + beforeTime;
  reqStr += "&afterTime=" + alertObj.afterTime; 
  //alert('line 1241 reqStr = ' + reqStr);
  //alert('line 530 alertObj.filterDuplicatesChk = ' + alertObj.filterDuplicatesChk);
  top.sendhttpRequest(reqStr, "nw_web.asp");
}

function applyAlertSettings() 
{
  var alertListTable;
  var i;
  var confirmed;
  var reqId;
  var alertObj = new Object();
  var alertInfoArray;
  var oddRow;
  
  //alert('line 69');
  alertListTable = document.getElementById('tmain1');
  //alert("line 407 alertListTable.rows.length = " + alertListTable.rows.length);
  for (i = alertListTable.rows.length - 1; i > 0; i--)
  {
    //alert("line 410 i = " + i);
    //alert("line 73 alertListTable.rows[i].cells[4].innerHTML + '2' = " + alertListTable.rows[i].cells[4].innerHTML + '2');
    reqId = alertListTable.rows[i].cells[4].innerHTML;
    //alert("line 461 reqId = " + reqId);
    if (document.getElementById(reqId + '2').checked)
    {
      //alert('Are you sure you want to delete\n Alert: ' + alertListTable.rows[i].cells[0].innerHTML);
      if (!top.document.getElementById("alert_header_" + reqId)) //Alert is inactive. Activate it
      {
        top.createHeader(alertListTable.rows[i].cells[0].innerHTML, reqId);
        top.expressions[reqId][top.activeIndex] = true;
        alertInfoArray = top.expressions[reqId];
        alertObj.reqId = reqId;
        alertObj.queryString = alertInfoArray[top.fullExpressionIndex];
        //alert('line 1212 alertObj.queryString = ' + alertObj.queryString);
        alertObj.ticker = alertInfoArray[top.tickerRequiredIndex];
        alertObj.headline = alertInfoArray[top.matchHeadlineTextIndex];
        alertObj.filterDuplicates = alertInfoArray[top.filterDuplicatesIndex];
        alertObj.numHeadlines = alertInfoArray[top.maxHdlsIndex];
        alertObj.foregroundColor = alertInfoArray[top.foregroundColorIndex];
        alertObj.backgroundColor = alertInfoArray[top.backgroundColorIndex];
        alertObj.fontFamily = top.expressions[alertObj.reqId][top.fontFamilyIndex];
        //alert('line 1181 top.expressions[alertObj.reqId][top.fontFamilyIndex] = ' + top.expressions[alertObj.reqId][top.fontFamilyIndex]);
        alertObj.fontSize = top.expressions[alertObj.reqId][top.fontSizeIndex];
        //alert('line 1188 top.expressions[alertObj.reqId][top.fontSizeIndex] = ' + top.expressions[alertObj.reqId][top.fontSizeIndex]);
        //alert('line 1189 alertObj.fontSize = ' + alertObj.fontSize);
        switch (alertInfoArray[top.afterTimeIndexIndex])
        {
          case 0:
            alertObj.afterTime = parseInt(new Date().getTime() / 1000) - 86400;
            break;
          case 1:
            alertObj.afterTime = parseInt(new Date().getTime() / 1000) - (2 * 86400);
            break;
          case 2:
            alertObj.afterTime = parseInt(new Date().getTime() / 1000) - (3 * 86400);
            break;
          case 3:
            alertObj.afterTime = parseInt(new Date().getTime() / 1000) - (7 * 86400);
            break;
          case 4:
            alertObj.afterTime = parseInt(new Date().getTime() / 1000) - (14 * 86400);
            break;
          case 5:
            alertObj.afterTime = parseInt(new Date().getTime() / 1000) - (31 * 86400);
            break;
          case 6:
            alertObj.afterTime = parseInt(new Date().getTime() / 1000) - (92 * 86400);
            break;
          case 7:
            alertObj.afterTime = parseInt(new Date().getTime() / 1000) - (1100 * 86400);
            break;
          case 9:
            alertObj.afterTime = alertInfoArray[afterTimeIndex];
            break;
        }
        alertObj.msgType = "AlertAdd";    
        //alert('line 1213');
        //alert('line 1222 alertObj.fontSize = ' + alertObj.fontSize);
        alertRequest(alertObj);
        //alert('line 1224 alertObj.fontSize = ' + alertObj.fontSize);
        top.setFont(alertObj, reqId);
        if (alertObj.foregroundColor)
        {
          //alert('line 398 reqId = ' + reqId);
          top.setForegroundColor(alertObj.foregroundColor, alertObj.reqId, false);
          //alert('line 400 reqId = ' + reqId);
        }
        if (alertObj.backgroundColor)
        {
          //alert('line 1220 reqId = ' + reqId);
          top.setBackgroundColor(alertObj.backgroundColor, alertObj.reqId, false);
          //alert('line 406 reqId = ' + reqId);
        }
      }
    }
    else
    {
      if (top.document.getElementById("alert_header_" + reqId)) //alert is active deactivate it
      {
        top.sendDeletAlertRequest(reqId);
      }
    }
    if (document.getElementById(reqId + '3').checked) 
    {
      confirmed = confirm('Are you sure you want to delete\n Alert: ' + alertListTable.rows[i].cells[0].innerHTML);
      if (confirmed)
      {
        if (top.expressions[reqId][top.exprIndex].search(/allsyms/) >= 0)
        {
          top.allSyms = false;
        }
        alertListTable.deleteRow(i);
        if (top.document.getElementById("alert_header_" + reqId)) //alert is active deactivate it
        {
          top.sendDeletAlertRequest(reqId);
        }
        top.expressions[reqId] = undefined;
      }
      //alert('line 477 i = ' + i);
    }
    //alert('line 481 i = ' + i);
  }
  oddRow = true;
  //alert('line 1170 alertListTable.rows.length = ' + alertListTable.rows.length);
  for (i = 0; i < alertListTable.rows.length; i++)
  {
    //alert('line 1172 oddRow = ' + oddRow);
    //alert('line 1174 i = ' + i);
    if (oddRow == true)
    {
      alertListTable.rows[i].className = 'a';
      oddRow = false;
    }
    else
    {
      alertListTable.rows[i].className = 'b';
      oddRow = true;
    }
  }
  top.popUp(event, 'alertListDiv', top);
}

function editSettings()
{
  var i;
  var j;
  var source;
  var reqId;
  var alertInfo;
  var sourcesSelect;
  var numHeadlinesSelect;
  var afterTimeSelect;
  var newsCategorySelect;
  var newsIndustrySelect;
  var indexesSelect;
  var fontFamilySelect;
  var fontSizeSelect;
  var setColor;
  var tkr;
  var hdl;
  var dup;
  var active;
  var alertDialogbox;
  var expressionTableRow;
  var stringArray;
  var str;
  var keyword;
  var startedKeyword;
  var parenthesisPos;
  var quotesPos;
  var keywords;
  var symbolsArray = "";
  var c;
  
  //alert('line 1383 ' );
  showAlertDialogbox();
  //top.frames[5].document.getElementById('exp').focus();
  alertDialogbox = top.frames['alertDialogbox']; 
  //alert('line 1173 ' + top.frames['alertList'].document.getElementById('11').currentStyle.color);
  //alert('line 1175 ' + top.frames['alertList'].document.getElementById('tmain1').currentStyle.color);
  //alert('line 1174 ' + top.frames['alertList'].document.getElementById('21').currentStyle.color);
//  for(i = 0; i < top.frames['alertList'].document.getElementById('tmain1').rows; i++)
//  {
//    alert(top.frames['alertList'].document.getElementById('tmain1').rows[i].currentStyle.color)
//  }  
  expressionTableRow = alertDialogbox.document.getElementById('expressionTable').rows[1];
  //alertDialogbox.document.getElementById('exp').focus();
  source = event.srcElement;
  //alert('line 1233 source.nodeName = ' + source.nodeName);
  //alert('line 1234 source.id = ' + source.id);
  reqId = source.id.slice(0,-1);
  //alert('line 1236 reqId = ' + reqId);
  alertInfo = top.expressions[reqId];
  //top.frames[5].document.getElementById('alertName').value = alertInfo[top.alertNameIndex];
  alertDialogbox.document.getElementById('alertName').value = alertInfo[top.alertNameIndex];
  //top.frames[5].document.getElementById('exp').value = alertInfo[top.exprIndex];
  //alert('line 1241 alertInfo[top.exprIndex] = ' + alertInfo[top.exprIndex]);
  if (alertInfo[top.exprIndex])
  {
    //stringArray = alertInfo[top.exprIndex].slice(1, alertInfo[top.exprIndex].length - 1).split(' ');
    //stringArray = alertInfo[top.exprIndex].slice(1, alertInfo[top.exprIndex].search(/\)/)).split(' ');
    /*for (i = 0; i < stringArray.length; i++)
    {
      if (stringArray[i].charCodeAt(0) != 34)
      {
        if (expressionTableRow.cells[0].innerHTML)
        {
          expressionTableRow.cells[0].innerHTML += stringArray[i] + '<div></div>';
        }
        else
        {
          expressionTableRow.cells[0].innerHTML = stringArray[i] + '<div></div>';
        }
      }
      else
      {
        if (expressionTableRow.cells[1].innerHTML)
        {
          expressionTableRow.cells[1].innerHTML += stringArray[i].slice(1, stringArray[i].length - 1) + '<div></div>';
        }
        else
        {
          expressionTableRow.cells[1].innerHTML = stringArray[i].slice(1, stringArray[i].length - 1) + '<div></div>';
        }
      }
    }*/
    //alert('line 1363 alertInfo[top.exprIndex] = ' + alertInfo[top.exprIndex]);
    //alert('line 1364 alertInfo[top.exprIndex].length = ' + alertInfo[top.exprIndex].length);
    c = alertInfo[top.exprIndex].replace(/^\s+|\s+$/g, "").charCodeAt(0);
    quotesPos = alertInfo[top.exprIndex].replace(/^\s+|\s+$/g, "").indexOf('"');
    //alert('line 1445 quotesPos = ' + quotesPos);
    //alert('line 1446 c = ' + c);
    if (quotesPos == 0 || (c == 40 && quotesPos == 1) )//There aren't any symbols
    {
      //alert('line 1450 alertInfo[top.exprIndex].search(/\)/)) = ' + alertInfo[top.exprIndex].search(/\)/));
      //alert('line 1451 alertInfo[top.exprIndex].slice(1, alertInfo[top.exprIndex].search(/\)/)) = ' + alertInfo[top.exprIndex].slice(1, alertInfo[top.exprIndex].search(/\)/)));
      keywords = alertInfo[top.exprIndex].slice(1, alertInfo[top.exprIndex].search(/\)/)).replace(/^\s+|\s+$/g, "");
      //alert('line 1453 keywords = ' + keywords);
    }
    else if (quotesPos == - 1)//There aren't any keywords
    {
      //alert('line 1372 alertInfo[top.exprIndex].search(/\)/) = ' + alertInfo[top.exprIndex].search(/\)/));
      symbolsArray = alertInfo[top.exprIndex].slice(1, alertInfo[top.exprIndex].search(/\)/)).replace(/^\s+|\s+$/g, "").split(' ');
    }
    else
    {
      symbolsArray = alertInfo[top.exprIndex].slice(1, alertInfo[top.exprIndex].indexOf('"')).replace(/^\s+|\s+$/g, "").split(' ');
      keywords = alertInfo[top.exprIndex].slice(alertInfo[top.exprIndex].indexOf('"') + 1, alertInfo[top.exprIndex].search(/\)/)).replace(/^\s+|\s+$/g, "");
    }
    //alert('line 1465 symbolsArray = ' + symbolsArray);
    if (symbolsArray)
    {
      for (i = 0; i < symbolsArray.length; i++)
      {
        //alert('line 1456 symbolsArray[i] = ' + symbolsArray[i]);
        if (expressionTableRow.cells[0].innerHTML)
        {
          expressionTableRow.cells[0].innerHTML += symbolsArray[i] + '<br />';
        }
        else
        {
          expressionTableRow.cells[0].innerHTML = symbolsArray[i] + '<br />';
        }
      }
    }
    //alert('line 1468 keywords = ' + keywords);
    //alert('line 1469 keywords.length = ' + keywords.length);
    if (keywords)
    {
      for (i = 0; i < keywords.length; i++)
      {
        //alert('line 1487');
        //alert('line 1488 keywords.charAt(i) = ' + keywords.charAt(i));
        if (keywords.charCodeAt(i) != 34)
        {
          if (keywords.charCodeAt(i) != 32)
          {
            expressionTableRow.cells[1].innerHTML += keywords.charAt(i);
            //alert('line 1496 expressionTableRow.cells[1].innerHTML = ' + expressionTableRow.cells[1].innerHTML);
          }
          else
          {
            expressionTableRow.cells[1].innerHTML += '<br />';
            //alert('line 1501 expressionTableRow.cells[1].innerHTML = ' + expressionTableRow.cells[1].innerHTML);
          }
        }
        else
        {
          //startedKeyword = !startedKeyword;
        }
      }
      expressionTableRow.cells[1].innerHTML += '<br />';
    }
    //alert('line 1507 expressionTableRow.cells[1].innerHTML = ' + expressionTableRow.cells[1].innerHTML);
  }
  
  
  sourcesSelect = alertDialogbox.document.getElementById('newsSources');
  //alert('line 1373 alertInfo[top.sourcesIndex] = ' + alertInfo[top.sourcesIndex]);
//  alert('line 1271 alertInfo[top.sourcesIndex].slice(1, alertInfo[top.sourcesIndex].length - 1) = ' + alertInfo[top.sourcesIndex].slice(1, alertInfo[top.sourcesIndex].length - 1));
//  alert('line 1272 alertInfo[top.sourcesIndex].slice(1, alertInfo[top.sourcesIndex].length - 1).split(" ") = ' + alertInfo[top.sourcesIndex].slice(1, alertInfo[top.sourcesIndex].length - 1).split(' '));
  if (alertInfo[top.sourcesIndex])
  {
    stringArray = alertInfo[top.sourcesIndex].slice(1, alertInfo[top.sourcesIndex].length - 1).split(' ');
    //alert('line 1219 stringArray.length = ' + stringArray.length);
    for (i = 0; i < stringArray.length; i++)
    {
      //alert('line 1222 stringArray[i] = ' + stringArray[i]);
      //alert('line 1223 stringArray[i].length = ' + stringArray[i].length);
      for (j = 0; j < sourcesSelect.options.length; j++)
      {
        //alert('line 1225 sourcesSelect.options[j].value = ' + sourcesSelect.options[j].value);
        //alert('line 1226 sourcesSelect.options[j].value.length = ' + sourcesSelect.options[j].value.length);
        if (sourcesSelect.options[j].value == stringArray[i])
        {
          if (expressionTableRow.cells[2].innerHTML)
          {
            //alert('line 1229 expressionTableRow.cells[2].innerHTML = ' + expressionTableRow.cells[2].innerHTML);
            expressionTableRow.cells[2].innerHTML += sourcesSelect.options[j].innerHTML + '<br />';
            //alert('line 1394 sourcesSelect.options[j].innerHTML = ' + sourcesSelect.options[j].innerHTML);
          }
          else
          {
            //alert('line 1235 expressionTableRow.cells[2].innerHTML = ' + expressionTableRow.cells[2].innerHTML);
            expressionTableRow.cells[2].innerHTML = sourcesSelect.options[j].innerHTML + '<br />';
            //alert('line 1400 sourcesSelect.options[j].innerHTML = ' + sourcesSelect.options[j].innerHTML);
            //alert('line 1237 expressionTableRow.cells[2].innerHTML = ' + expressionTableRow.cells[2].innerHTML);
          }
          break;
        }
      }
    }
  }  
  //sourcesSelect = top.frames[5].document.getElementById('newsSources');
  //alertDialogbox.document.getElementById('exp').value = alertInfo[top.exprIndex];
  //alert('line 561 sourcesSelect.options.length = ' + sourcesSelect.options.length);
//  for (i = 0; i < sourcesSelect.options.length; i++)
//  {
//    if (sourcesSelect.options[i].value == alertInfo[top.sourcesIndex])
//    {
//      //alert('line 561 i = ' + i);
//      sourcesSelect.options[i].selected = true;
//      break;
//    }
//  }
  //alert('line 565');
  //numHeadlinesSelect = top.frames[5].document.getElementById('numHeadlines');
  numHeadlinesSelect = top.frames['alertDialogbox'].document.getElementById('numHeadlines');
  for (i = 0; i < numHeadlinesSelect.options.length; i++)
  {
    if (numHeadlinesSelect.options[i].value == alertInfo[top.maxHdlsIndex])
    {
      //alert('line 572 i = ' + i);
      numHeadlinesSelect.options[i].selected = true;
      break;
    }
  }
  //alert('line 575');
  //afterTimeSelect = top.frames[5].document.getElementById('after');
  afterTimeSelect = alertDialogbox.document.getElementById('after');
  afterTimeSelect.options[alertInfo[top.afterTimeIndexIndex]].selected = true;
  //alert('line 590 alertInfo[top.afterTimeIndexIndex] = ' + alertInfo[top.afterTimeIndexIndex]);

  indexesSelect = alertDialogbox.document.getElementById('indexes');
  if (alertInfo[top.indexesIndex])
  {
//    alert('line 1339 alertInfo[top.indexesIndex] = ' + alertInfo[top.indexesIndex]);
//    alert('line 1340 alertInfo[top.indexesIndex].slice(1, alertInfo[top.indexesIndex].length - 1) = ' + alertInfo[top.indexesIndex].slice(1, alertInfo[top.indexesIndex].length - 1));
//    alert('line 1341 alertInfo[top.indexesIndex].slice(1, alertInfo[top.indexesIndex].length - 1).split(" ") = ' + alertInfo[top.indexesIndex].slice(1, alertInfo[top.indexesIndex].length - 1).split(' '));
    stringArray = alertInfo[top.indexesIndex].slice(1, alertInfo[top.indexesIndex].length - 1).split(' ');
    //alert('line 1279 stringArray.length = ' + stringArray.length);
    for (i = 0; i < stringArray.length; i++)
    {
      //alert('line 1281 stringArray[i] = ' + stringArray[i]);
      for (j = 0; j < indexesSelect.options.length; j++)
      {
        if (indexesSelect.options[j].value == stringArray[i])
        {
          //alert('line 1286 indexesSelect.options[j].value = ' + indexesSelect.options[j].value);
          if (expressionTableRow.cells[3].innerHTML)
          {
            expressionTableRow.cells[3].innerHTML = indexesSelect.options[j].innerHTML + '<br />';
            //alert('line 1290 expressionTableRow.cells[3].innerHTML = ' + expressionTableRow.cells[3].innerHTML);
          }
          else
          {
            expressionTableRow.cells[3].innerHTML = indexesSelect.options[j].innerHTML + '<br />';
            //alert('line 1295 expressionTableRow.cells[3].innerHTML = ' + expressionTableRow.cells[3].innerHTML);
          }
          break;
        }
      }
    }
  }
  newsCategorySelect = alertDialogbox.document.getElementById('newsCategory');
  //alert('line 1306 alertInfo[top.categoryIndex] = ' + alertInfo[top.categoryIndex]);
  //alert('line 1307 alertInfo[top.categoryIndex].length = ' + alertInfo[top.categoryIndex].length);
  if (alertInfo[top.categoryIndex])
  {
    stringArray = alertInfo[top.categoryIndex].slice(1, alertInfo[top.categoryIndex].length - 1).split(' ');
    //alert('line 1309 stringArray.length = ' + stringArray.length);
    for (i = 0; i < stringArray.length; i++)
    {
      for (j = 0; j < newsCategorySelect.options.length; j++)
      {
        if (newsCategorySelect.options[j].value == stringArray[i])
        {
          if (expressionTableRow.cells[4].innerHTML)
          {
            expressionTableRow.cells[4].innerHTML += newsCategorySelect.options[j].innerHTML + '<br />';
          }
          else
          {
            expressionTableRow.cells[4].innerHTML = newsCategorySelect.options[j].innerHTML + '<br />';
          }
          break;
        }
      }
    }
  }  
//  for (i = 0; i < newsCategorySelect.options.length; i++)
//  {
//    if (newsCategorySelect.options[i].value == alertInfo[top.categoryIndex])
//    {
//      //alert('line 596 i = ' + i);
//      newsCategorySelect.options[i].selected = true;
//      break;
//    }
//  }
  //alert('line 595');
  //newsIndustrySelect = top.frames[5].document.getElementById('newsIndustry');
  newsIndustrySelect = alertDialogbox.document.getElementById('newsIndustry');
  if (alertInfo[top.industryIndex])
  {
    stringArray = alertInfo[top.industryIndex].slice(1, alertInfo[top.industryIndex].length - 1).split(' ');
    for (i = 0; i < stringArray.length; i++)
    {
      for (j = 0; j < newsIndustrySelect.options.length; j++)
      {
        if (newsIndustrySelect.options[j].value == stringArray[i])
        {
          if (expressionTableRow.cells[5].innerHTML)
          {
            expressionTableRow.cells[5].innerHTML += newsIndustrySelect.options[j].innerHTML + '<br />';
          }
          else
          {
            expressionTableRow.cells[5].innerHTML = newsIndustrySelect.options[j].innerHTML + '<br />';
          }
          break;
        }
      }
    }
  }  
//  for (i = 0; i < newsIndustrySelect.options.length; i++)
//  {
//    if (newsIndustrySelect.options[i].value == alertInfo[top.industryIndex])
//    {
//      //alert('line 607 i = ' + i);
//      newsIndustrySelect.options[i].selected = true;
//      break;
//    }
//  }
  //alert('line 605');
  fontFamilySelect = top.frames['alertDialogbox'].document.getElementById('fontFamily');
  for (i = 0; i < fontFamilySelect.options.length; i++)
  {
    if (fontFamilySelect.options[i].value == alertInfo[top.fontFamilyIndex])
    {
      //alert('line 618 i = ' + i);
      fontFamilySelect.options[i].selected = true;
      break;
    }
  }
  //alert('line 615');
  //fontSizeSelect = top.frames[5].document.getElementById('fontSize');
  fontSizeSelect = top.frames['alertDialogbox'].document.getElementById('fontSize');
  for (i = 0; i < fontSizeSelect.options.length; i++)
  {
    if (fontSizeSelect.options[i].value == alertInfo[top.fontSizeIndex])
    {
      //alert('line 629 i = ' + i);
      fontSizeSelect.options[i].selected = true;
      break;
    } 
  }
  //alert('line 615');'alertDialogbox'
  //setColor = top.frames[5].document.getElementById('displayColor');
  setColor = top.frames['alertDialogbox'].document.getElementById('displayColor1');
  setColor.style.color = alertInfo[top.foregroundColorIndex];
  setColor.style.backgroundColor = alertInfo[top.backgroundColorIndex];
  //tkr = top.frames[5].document.getElementById('tkr');
  tkr = top.frames['alertDialogbox'].document.getElementById('tkr');
  tkr.checked = alertInfo[top.tickerRequiredIndex];
  //alert('line 640 alertInfo[top.tickerRequiredIndex] = ' + alertInfo[top.tickerRequiredIndex]);
  //dup = top.frames[5].document.getElementById('dup');
  dup = top.frames['alertDialogbox'].document.getElementById('dup');
  dup.checked = alertInfo[top.filterDuplicatesIndex];
  //alert('line 643 alertInfo[top.filterDuplicatesIndex] = ' + alertInfo[top.filterDuplicatesIndex]);
  //hdl = top.frames[5].document.getElementById('hdl');
  hdl = top.frames['alertDialogbox'].document.getElementById('hdl');
  hdl.checked = alertInfo[top.matchHeadlineTextIndex];
  //alert('line 646 alertInfo[top.matchHeadlineTextIndex] = ' + alertInfo[top.matchHeadlineTextIndex]);
  //active = top.frames[5].document.getElementById('active');
  active = top.frames['alertDialogbox'].document.getElementById('active');
  active.checked = alertInfo[top.activeIndex];
  //alert('line 649 alertInfo[top.activeIndex] = ' + alertInfo[top.activeIndex]);
  //alert('line 640');
}

function buildHistoricalQuery() 
{
  var queryString = '';
  var expression = '';
  var newsSources = '';
  var newsSourcesSelect;
  var numHeadlines;
  var numHeadlinesSelect;
  var newsCategory;
  var newsCategorySelect;
  var newsIndustry;
  var newsIndustrySelect;
  var beforeTimeSelect;
  var afterTimeSelect;
  var beforeTime;
  var afterTime;
  var tickerChk;
  var headlineChk;
  var filterDuplicatesChk;
  var reqStr;
  var formattedExpression;
  var alertObj = new Object();
  var i;

  //alert('line 60');
  //if (document.getElementById('exp').value)
  //{
  //expression = '(' + document.getElementById('exp').value + ') ';
  //}
  if (document.getElementById('textSymbols').value)
  {
    expression = '(' + document.getElementById('textSymbols').value + ' ';
  }
  if (document.getElementById('textKeywords').value)
  {
    if (expression)
    {
      expression += document.getElementById('textKeywords').value;
    }
    else
    {
      expression = '(' + document.getElementById('textKeywords').value;
    }
  }
  if (expression)
  {
    expression += ') ';
  }
  newsSourcesSelect = document.getElementById('newsSources');
  //newsSources = '(' + newsSourcesSelect.options[newsSourcesSelect.selectedIndex].value + ') ';
  for (i = 0; i < newsSourcesSelect.length; i++)
  {
    if (newsSourcesSelect.options[i].selected)
    {
      if (!newsSources)
      {
        newsSources = newsSourcesSelect.options[i].value;
      }
      else
      {
        newsSources += ' ' + newsSourcesSelect.options[i].value;
      }
    }
  }
  if (newsSources)
  {
    newsSources = '(' + newsSources + ') ';
  }
  //alert('line 1673 newsSources = ' + newsSources);
  numHeadlinesSelect = document.getElementById('numHeadlines');
  numHeadlines = parseInt(numHeadlinesSelect.options[numHeadlinesSelect.selectedIndex].value);
  newsCategorySelect = document.getElementById('newsCategory');
  //newsCategory = '(' + newsCategorySelect.options[newsCategorySelect.selectedIndex].value + ') ';
  for (i = 0; i < newsCategorySelect.length; i++)
  {
    if (newsCategorySelect.options[i].selected)
    {
      if (!newsCategory)
      {
        newsCategory = newsCategorySelect.options[i].value;
      }
      else
      {
        newsCategory += ' ' + newsCategorySelect.options[i].value;
      }
    }
  }
  if (newsCategory)
  {
    newsCategory = '(' + newsCategory + ') ';
  }
  newsIndustrySelect = document.getElementById('newsIndustry');
  //newsIndustry = '(' + newsIndustrySelect.options[newsIndustrySelect.selectedIndex].value + ') ';
  for (i = 0; i < newsIndustrySelect.length; i++)
  {
    if (newsIndustrySelect.options[i].selected)
    {
      if (!newsIndustry)
      {
        newsIndustry = newsIndustrySelect.options[i].value;
      }
      else
      {
        newsIndustry += ' ' + newsIndustrySelect.options[i].value;
      }
    }
  }
  if (newsIndustry)
  {
    newsIndustry = '(' + newsIndustry + ') ';
  }
  //beforeTimeSelect = top.frames[3].document.getElementById('before');
  //afterTimeSelect = top.frames[3].document.getElementById('after');
  beforeTimeSelect = top.frames['historicalTool'].document.getElementById('before');
  afterTimeSelect = top.frames['historicalTool'].document.getElementById('after');
  switch (beforeTimeSelect.selectedIndex) 
  {
    case 0:
      beforeTime = new Date().getTime();
      beforeTime = parseInt(beforeTime / 1000);
      break;
    case 2:
      beforeTime = beforeTimeSelect.options[2].value;
      alertObj.beforeTime = beforeTime;
      //alert('line 1689 beforeTime = ' + beforeTime);
      break;
  }
  switch (afterTimeSelect.selectedIndex) 
  {
    case 0:
      //afterTime = parseInt(new Date().getTime() / 1000) - 86400;
      afterTime = beforeTime - 86400;
      break;
    case 1:
      //afterTime = parseInt(new Date().getTime() / 1000) - (2 * 86400);
      afterTime = beforeTime - (2 * 86400);
      break;
    case 2:
      //afterTime = parseInt(new Date().getTime() / 1000) - (3 * 86400);
      afterTime = beforeTime - (3 * 86400);
      break;
    case 3:
      //afterTime = parseInt(new Date().getTime() / 1000) - (7 * 86400);
      afterTime = beforeTime - (7 * 86400);
      //alert('line 862 parseInt(new Date().getTime() / 1000) = ' + parseInt(new Date().getTime() / 1000));
      //alert('line 863 7 * 86400 = ' + 7 * 86400);
      //alert('line 864 afterTime = ' + afterTime);
      //alert('line 865 beforeTime = ' + beforeTime);
      break;
    case 4:
      //afterTime = parseInt(new Date().getTime() / 1000) - (14 * 86400);
      afterTime = beforeTime - (14 * 86400);
      break;
    case 5:
      //afterTime = parseInt(new Date().getTime() / 1000) - (31 * 86400);
      afterTime = beforeTime - (31 * 86400);
      break;
    case 6:
      //afterTime = parseInt(new Date().getTime() / 1000) - (92 * 86400);
      afterTime = beforeTime - (92 * 86400);
      break;
    case 7:
      //afterTime = parseInt(new Date().getTime() / 1000) - (1100 * 86400);
      afterTime = beforeTime - (1100 * 86400);
      break;
    case 9:
      afterTime = afterTimeSelect.options[9].innerHTML;
      break;
  }
  tickerChk = document.getElementById('tkr');
  headlineChk = document.getElementById('hdl');
  filterDuplicatesChk = document.getElementById('dup');
  
  if (expression)
  {
    queryString = expression;
  }
  if (newsSources && newsSources != '(AllSources) ') 
  {
    if (queryString)
    {
      queryString += ' & ' + newsSources;
    }
    else
    {
      queryString = newsSources;
    }
  }
  //alert('line 1792 queryString = ' + queryString);
  //if (newsCategory != '() ')
  if (newsCategory)
  {
    if (queryString)
    {
      queryString += ' & ' + newsCategory;
    }
    else 
    {
      queryString = newsCategory;
    } 
  }
  //alert('line 1805 queryString = ' + queryString);
  //if (newsIndustry != '() ')
  if (newsIndustry)
  {
    if (queryString) 
    {
      queryString += ' & ' + newsIndustry;
    }
    else
    {
      queryString = newsIndustry;
    }
  }
  //alert('line 1818 queryString = ' + queryString);
  if (!queryString) 
  {
    queryString = '(allsyms)';
  }
  if (queryString.search(/allsyms/) >= 0)
  {
    if (top.allSyms == true)
    {
      alert('You already have an "allsyms" alert');
      return;
    }
    else
    {
      top.allSyms = true;
    }
  }
  //alertObj.queryString = queryString;
  alertObj.msgType = "QueryAdd";
  alertObj.numHeadlines = numHeadlines;
  alertObj.afterTime = afterTime;
  alertObj.reqId = ++top.queryReqID;
  alertObj.newName = false;
  alertObj.alertName = queryString;
  alertObj.expression = expression;
  alertObj.newsSources = newsSources;
  alertObj.newsCategory = newsCategory;
  alertObj.newsIndustry = newsIndustry;
  ////////////////////alertObj.indexes = indexes;
  //  if (newsSources != '(AllSources) ')
//  {
//    alertObj.newsSources = newsSources;
//  }
//  if (newsCategory != '() ')
//  {
//    alertObj.newsCategory = newsCategory;
//  }
//  if (newsIndustry != '() ')
//  {
//    alertObj.newsIndustry = newsIndustry;
//  }  
  alertObj.afterTime = afterTime;
  alertObj.afterTimeIndex = afterTimeSelect.selectedIndex;
  alertObj.filterDuplicatesChk = filterDuplicatesChk.checked;
  alertObj.tickerChk = tickerChk.checked;
  alertObj.headlineChk = headlineChk.checked;
  alertObj.activeChk = true;
  alertObj.queryString = queryString;
  recordAlertInfo(alertObj);
  //alert('line 830 queryString = ' + queryString);
//  alert('line 891 tickerChk.checked = ' + tickerChk.checked);
//  alert('line 892 headlineChk.checked = ' + headlineChk.checked);
//  alert('line 893 alertObj.tickerChk = ' + alertObj.tickerChk);
//  alert('line 894 alertObj.headlineChk = ' + alertObj.headlineChk);
  alertRequest(alertObj);
  setQueryDefaults();
  
  /*reqStr = "msgType=QueryAdd";
  reqStr = reqStr + "&sessionID=" + top.sessionID;
  top.queryReqID++;
  reqStr = reqStr + "&reqID=" + top.queryReqID;
  formattedExpression = top.formatExpression(queryString);
  reqStr = reqStr + "&exp=" + formattedExpression;
  if (tickerChk.checked)
  {
    reqStr += "&ticker=true";
  }
  else
  {
    reqStr += "&ticker=false";
  }
  if (headlineChk.checked) 
  {
    reqStr += "&hdl=true";
  }
  else 
  {
    reqStr += "&hdl=false";
  }
  if (filterDuplicatesChk.checked) 
  {
    reqStr += "&dup=true";
  }
  else 
  {
    reqStr += "&dup=false";
  }
  reqStr += "&numHeadlines=" + numHeadlines;
  reqStr += "&beforeTime=" + beforeTime;
  reqStr += "&afterTime=" + afterTime;
  //alert('line 1796 reqStr = ' + reqStr);
  top.createHeader(queryString, 'query');
  //alert('line 190');
  top.sendhttpRequest(reqStr, "nw_web.asp");
  top.expressions[top.queryReqID] = new Array();
  top.expressions[top.queryReqID][0] = expression;*/
  //alert('line 192');
  //alert('line 1803 queryString = ' + queryString);
  top.popUp(event, 'historicalToolDiv', top);
  //alert('line 194');
}  

function showDialogbox(selectId) 
{
  var yearSelect;
  var monthSelect;
  var dayOfMonthSelect;
  var hourSelect;
  var minuteSelect;
  var secondSelect;
  var year;
  var month;
  var dayOfMonth;
  var hour;
  var minute;
  var second;
  var dateObj = new Date();
  var secondsSince1970;
  var timeSelect;
  var i;
  var containerDiv;
  var divTop;
  var height;
  
  //alert('line 938 ');
  //alert('line 204 top.afterTimeHasBeenSet = ' + top.afterTimeHasBeenSet);
  //alert('line 935 selectId = ' + selectId);
  //top.timeSelectId = selectId;
  timeSelectId = selectId;
  //timeSelect = top.frames[3].document.getElementById(selectId);
  timeSelect = document.getElementById(selectId);
  //alert('line 939 timeSelect.options[timeSelect.selectedIndex].value = ' + timeSelect.options[timeSelect.selectedIndex].value);
  if (timeSelect.options[timeSelect.selectedIndex].value != 'user entry') 
  {
    //alert('line 227 selectId = ' + selectId);
    if (selectId == 'after')
    {
      previousAftertimeIndex = timeSelect.selectedIndex;
      //top.previousAftertimeIndex = timeSelect.selectedIndex;
      //alert('line 236 top.previousAftertimeIndex = ' + top.previousAftertimeIndex);
      //alert('line 237 timeSelect.selectedIndex = ' + timeSelect.selectedIndex);
    }
    else
    {
      //top.previousBeforetimeIndex = timeSelect.selectedIndex;
      previousBeforetimeIndex = timeSelect.selectedIndex;
    }
  }
  else
  {
    //alert('line 958');
    /*top.popUp(event, 'timeDialogboxDiv', top.frames[3]);
    containerDiv = top.frames[3].document.getElementById('timeDialogboxDiv');
    alert('line 249 containerDiv.style.top = ' + containerDiv.style.top);
    divTop = parseInt(containerDiv.style.top) - 50;
    containerDiv.style.top = divTop + 'px';*/
    //alert('line 252 containerDiv.style.top = ' + containerDiv.style.top);
    //top.frames[3].document.getElementById('timeDialogboxDiv').className = 'showDiv';
    document.getElementById('timeDialogboxDiv').className = 'showDiv';
    //alert("line 1951 parseInt(top.document.getElementById('alertDialogboxDiv').style.height = " + parseInt(top.document.getElementById('alertDialogboxDiv').style.height));
    height = parseInt(top.document.getElementById('alertDialogboxDiv').style.height) + 57;
    top.document.getElementById('alertDialogboxDiv').style.height = height + 'px';
    //alert('line 966');
    if (selectId == 'before' || (selectId == 'after' && !top.afterTimeHasBeenSet)) 
    {
      //yearSelect = top.frames[4].document.getElementById('year');
      //yearSelect = top.frames[3].frames[0].document.getElementById('year');
      yearSelect = frames['timeDialogbox'].document.getElementById('year');
      //alert('line 974 ');
      year = dateObj.getFullYear();
      for (i = 0; i < yearSelect.options.length; i++) {
        if (year == yearSelect.options[i].value) {
          yearSelect.selectedIndex = i;
          break;
        }
      }
      //monthSelect = top.frames[4].document.getElementById('month');
      //monthSelect = top.frames[3].frames[0].document.getElementById('month');
      monthSelect = frames['timeDialogbox'].document.getElementById('month');
      month = dateObj.getMonth();
      for (i = 0; i < monthSelect.options.length; i++) {
        if (month == monthSelect.options[i].value) {
          monthSelect.selectedIndex = i;
          break;
        }
      }
      //dayOfMonthSelect = top.frames[4].document.getElementById('dayofmonth');
      //dayOfMonthSelect = top.frames[3].frames[0].document.getElementById('dayofmonth');
      dayOfMonthSelect = frames['timeDialogbox'].document.getElementById('dayofmonth');
      dayOfMonth = dateObj.getDate();
      for (i = 0; i < dayOfMonthSelect.options.length; i++) {
        if (dayOfMonth == dayOfMonthSelect.options[i].value) {
          dayOfMonthSelect.selectedIndex = i;
          break;
        }
      }
      //hourSelect = top.frames[4].document.getElementById('hour');
      //hourSelect = top.frames[3].frames[0].document.getElementById('hour');
      hourSelect = frames['timeDialogbox'].document.getElementById('hour');
      hour = dateObj.getHours();
      for (i = 0; i < hourSelect.options.length; i++) {
        if (hour == hourSelect.options[i].value) {
          hourSelect.selectedIndex = i;
          break;
        }
      }
      //minuteSelect = top.frames[4].document.getElementById('minute');
      //minuteSelect = top.frames[3].frames[0].document.getElementById('minute');
      minuteSelect = frames['timeDialogbox'].document.getElementById('minute');
      minute = dateObj.getMinutes();
      for (i = 0; i < minuteSelect.options.length; i++) {
        if (minute == minuteSelect.options[i].value) {
          minuteSelect.selectedIndex = i;
          break;
        }
      }
      //secondSelect = top.frames[4].document.getElementById('second');
      //secondSelect = top.frames[3].frames[0].document.getElementById('second');
      secondSelect = frames['timeDialogbox'].document.getElementById('second');
      second = dateObj.getSeconds();
      for (i = 0; i < secondSelect.options.length; i++) {
        if (second == secondSelect.options[i].value) {
          secondSelect.selectedIndex = i;
          break;
        }
      }
    }
    if (selectId == 'after') 
    {
      top.afterTimeHasBeenSet = true;
    }
  }
}

function getCurrentTime()
{
  var dateObj = new Date();
  var dateObj2;
  var indx;
  var dateAndTime;
  
  indx = dateObj.toLocaleString().search(/ /) + 1;
  currentTime = dateObj.toLocaleString().slice(indx);
//  dateAndTime = Date.parse(currentTime);
//  dateObj2 = new Date(dateAndTime);
  //  return dateObj2.toLocaleString();
  return currentTime;
}

/*function checkKeyTimeTextbox(e) 
{
  //alert('line 177');
  if(!e)
  {
    e = top.event;
  }
  //alert('line 182 e.srcElement = ' + e.srcElement);
  //alert('line 183 e.keyCode = ' + e.keyCode);
  if (e.keyCode == 13)
	{
	  closeTextbox();
	}
}*/

function closeDisplay()
{
  var timeSelect;
  var height;
  
  //alert('line 344');
  //top.popUp(event, 'timeDialogboxDiv', top.frames[3]);
  //timeSelect = top.frames[3].document.getElementById(top.timeSelectId);
  timeSelect = parent.document.getElementById(parent.timeSelectId);
  if (top.timeSelectId == 'after') 
  {
    timeSelect.selectedIndex = top.previousAftertimeIndex;
    //alert('line 324 timeSelect.selectedIndex = ' + timeSelect.selectedIndex);
    //alert('line 325 previousAftertimeIndex = ' + top.previousAftertimeIndex);
  }
  else 
  {
    timeSelect.selectedIndex = top.previousBeforetimeIndex;
  }
  parent.document.getElementById('timeDialogboxDiv').className = 'hideDiv';
  height = parseInt(top.document.getElementById('alertDialogboxDiv').style.height) - 57;
  top.document.getElementById('alertDialogboxDiv').style.height = height + 'px';
}

function setDateAndTime()
{
  var yearSelect;
  var monthSelect;
  var dayOfMonthSelect;
  var hourSelect;
  var minuteSelect;
  var secondSelect;
  var year;
  var month;
  var dayOfMonth;
  var hour;
  var minute;
  var second;
  var dateObj = new Date();
  var secondsSince1970;
  var timeSelect;
  var height;
  
  //yearSelect = top.frames[4].document.getElementById('year');
  yearSelect = document.getElementById('year');
  //alert('line 1102 yearSelect = ' + yearSelect);
  dateObj.setFullYear(yearSelect.options[yearSelect.selectedIndex].value);
  //monthSelect = top.frames[4].document.getElementById('month');
  monthSelect = document.getElementById('month');
  dateObj.setMonth(monthSelect.options[monthSelect.selectedIndex].value);
  //dayOfMonthSelect = top.frames[4].document.getElementById('dayofmonth');
  dayOfMonthSelect = document.getElementById('dayofmonth');
  dateObj.setDate(dayOfMonthSelect.options[dayOfMonthSelect.selectedIndex].value);
  //hourSelect = top.frames[4].document.getElementById('hour');
  hourSelect = document.getElementById('hour');
  dateObj.setHours(hourSelect.options[hourSelect.selectedIndex].value);
  //minuteSelect = top.frames[4].document.getElementById('minute');
  minuteSelect = document.getElementById('minute');
  dateObj.setMinutes(minuteSelect.options[minuteSelect.selectedIndex].value);
  //secondSelect = top.frames[4].document.getElementById('second');
  secondSelect = document.getElementById('second');
  secondsSince1970 = dateObj.setSeconds(secondSelect.options[secondSelect.selectedIndex].value);
  secondsSince1970 = parseInt(secondsSince1970 / 1000);
  //alert('line 2086 secondsSince1970 = ' + secondsSince1970);
  //alert('line 1227 dateObj.getTime() / 1000 = ' + dateObj.getTime() / 1000);
  //alert('line 1228 dateObj.toLocaleString()  = ' + dateObj.toLocaleString() );
  //alert('line 1229 new Date().getTime() / 1000 = ' + new Date().getTime() / 1000);
  //alert('line 1230 new Date().toLocaleString() = ' + new Date().toLocaleString());
  //alert('line 2091 parent.timeSelectId = ' + parent.timeSelectId);
  timeSelect = parent.document.getElementById(parent.timeSelectId);
  //alert('line 2093 timeSelect.options.length = ' + timeSelect.options.length);
  timeSelect.options[timeSelect.options.length - 1].selected = true;
  timeSelect.options[timeSelect.options.length - 1].value = secondsSince1970;
  //alert('line 348 timeSelect.options[timeSelect.options.length - 1].value = ' + timeSelect.options[timeSelect.options.length - 1].value);
  timeSelect.options[timeSelect.options.length - 1].innerHTML = (Number(monthSelect.options[monthSelect.selectedIndex].value) + 1) + '/' + (Number(dayOfMonthSelect.options[dayOfMonthSelect.selectedIndex].value) + 1) + '/' + yearSelect.options[yearSelect.selectedIndex].innerHTML.slice(2) + ' ' + hourSelect.options[hourSelect.selectedIndex].innerHTML + ':' + minuteSelect.options[minuteSelect.selectedIndex].innerHTML;
  //alert('line 403');
  //top.popUp(event, 'timeDialogboxDiv', top.frames[3]);
  parent.document.getElementById('timeDialogboxDiv').className = 'hideDiv';
  height = parseInt(top.document.getElementById('alertDialogboxDiv').style.height) - 57;
  top.document.getElementById('alertDialogboxDiv').style.height = height + 'px';
  //if (top.timeSelectId == 'after')
  if (parent.timeSelectId == 'after')
  {
    //top.previousAftertimeIndex = timeSelect.options.length - 1;
    parent.previousAftertimeIndex = timeSelect.options.length - 1;
    //alert('line 387 top.previousBeforetimeIndex = ' + top.previousBeforetimeIndex);
  }
  else
  {
    //top.previousBeforetimeIndex = timeSelect.options.length - 1;
    parent.previousBeforetimeIndex = timeSelect.options.length - 1;
  }
}

function searchForCategoryCode()
{
  var expression = '';
  var alertName;
  var categoryCodesSelect;
  var newsIndustry = '';
  var newsIndustrySelect;
  var i;
  
  //alert('line 1304 top.frames["categoryCodesFrame"] = ' + top.frames['categoryCodesFrame']);
  //categoryCodesSelect = top.frames[6].document.getElementById('newsCategory');
  categoryCodesSelect = top.frames['categoryCodesFrame'].document.getElementById('newsCategory');
  //alert('line 2009 categoryCodesSelect.selectedIndex = ' + categoryCodesSelect.selectedIndex);
  for (i = 0; i < categoryCodesSelect.length; i++)
  {
    if (categoryCodesSelect.options[i].selected)
    {
      if (!expression)
      {
        expression = categoryCodesSelect.options[i].value;
        if (expression)
        {
          alertName = categoryCodesSelect.options[i].innerHTML;
        }
      }
      else
      {
        expression += ' ' + categoryCodesSelect.options[i].value;
      }
    }
  }
//  if (categoryCodesSelect.options[categoryCodesSelect.selectedIndex].value)
//  {
//    expression = categoryCodesSelect.options[categoryCodesSelect.selectedIndex].value;
//  }
//  alertName = categoryCodesSelect.options[categoryCodesSelect.selectedIndex].innerHTML;
//  if (alertName == 'ALL') alertName = '';
  newsIndustrySelect = document.getElementById('newsIndustry');
  //newsIndustry = '(' + newsIndustrySelect.options[newsIndustrySelect.selectedIndex].value + ') ';
  for (i = 0; i < newsIndustrySelect.length; i++)
  {
    if (newsIndustrySelect.options[i].selected)
    {
      if (newsIndustrySelect.options[i].value)
      {
        if (!newsIndustry)
        {
          if (expression)
          {
            newsIndustry = ' and (' + newsIndustrySelect.options[i].value;
          }
          else
          {
            newsIndustry =  newsIndustrySelect.options[i].value;
            alertName = newsIndustrySelect.options[i].innerHTML;
          }
        }
        else
        {
          newsIndustry += ' ' + newsIndustrySelect.options[i].value;
        }
      }  
    }
  }
  if (newsIndustry)
  {
    if (expression)
    {
      expression += newsIndustry + ')';
    }
    else
    {
      expression = newsIndustry ;
    }
  }

//  if(newsIndustrySelect.options[newsIndustrySelect.selectedIndex].value)
//  {
//    if (expression)
//    {
//      expression += 'and (' + newsIndustrySelect.options[newsIndustrySelect.selectedIndex].value + ') ';
//    }
//    else
//    {
//      expression += '(' + newsIndustrySelect.options[newsIndustrySelect.selectedIndex].value + ') ';
//    }  
//  }  
  //alert('line 2014 expression = ' + expression);
  if (expression)
  {
//    if (!alertName)
//    {
//      alertName = newsIndustrySelect.options[newsIndustrySelect.selectedIndex].innerHTML;
//    }
//    alert('line 2021 alertName = ' + alertName);
    top.createAlertMsg(expression, 'alert', alertName)
  }  
  top.popUp(event, 'categoryCodesDiv', top);
}



/*function closeTextbox()
{
  var containerDiv;
  var TimeSelect;
  var TimeText;

  containerDiv = document.getElementById('beforeTimeTextboxDiv');
  if (containerDiv.currentStyle.visibility == "hidden") 
  {
    return;
  } 
  //alert('line 200 event.type = ' + event.type);
  //alert('line 193 top.timeSelectId = ' + top.timeSelectId);
  TimeSelect = top.frames[3].document.getElementById(top.timeSelectId);
  //alert('line 195 TimeSelect = ' + TimeSelect);
  TimeText = top.document.getElementById('beforeTimeTextbox');
  TimeSelect.options[TimeSelect.options.length - 1].selected = true;
  //alert('line 198 top.timeSelectId = ' + top.timeSelectId);
  //alert('line 200 beforeTimeSelect.options[TimeSelect.options.length - 1].value = ' + beforeTimeSelect.options[TimeSelect.options.length - 1].value);
  TimeSelect.options[TimeSelect.options.length - 1].value = TimeText.value;
  //alert('line 202 ');
  TimeSelect.options[TimeSelect.options.length - 1].innerHTML = TimeText.value;
  //alert('line 204 ' );
  top.popUp(event,'beforeTimeTextboxDiv');
  //alert('line 205 ');
  //alert('line 208 top.event.srcElement = ' + top.event.srcElement);
  //alert('line 209 top.event.keyCode = ' + top.event.keyCode);
}*/

function addExpression()
{
  var source = event.srcElement;
  var expressionTableRow = document.getElementById('expressionTable').rows[1];
  var charCode;
  

  window.event.cancelBubble = true;
  if (event.keyCode != 13) return;
  window.event.returnValue = false;
  if (source.id == 'textKeywords')
  {
    expressionTableRow.cells[1].innerHTML += source.value + '<br />';
  }
  else
  {
    expressionTableRow.cells[0].innerHTML += source.value + '<br />';
  }
  source.value = '';
}

function selectNewsSources()
{
  var source = event.srcElement;
  var expressionTableRow = document.getElementById('expressionTable').rows[1];
  var newsSourcesSelect = document.getElementById('newsSources');
  var i;

  //alert('line 1512');
//  if (source.options.selectedIndex == 0)
//  {
//    expressionTableRow.cells[2].innerHTML = source.options[source.options.selectedIndex].innerHTML + '<div></div>';
//  }
//  else if (expressionTableRow.cells[2].innerHTML.indexOf('All News Sources') == -1)
//  {
//    expressionTableRow.cells[2].innerHTML += source.options[source.options.selectedIndex].innerHTML + '<div></div>';
//  }
//  else
//  {
//    expressionTableRow.cells[2].innerHTML = source.options[source.options.selectedIndex].innerHTML + '<div></div>';
//  }
  if (newsSourcesSelect.options[0].selected)
  {
    expressionTableRow.cells[2].innerHTML = newsSourcesSelect.options[0].innerHTML + '<br />';
  }
  else
  {
    for (i = 1; i < newsSourcesSelect.length; i++)
    {
      if (newsSourcesSelect.options[i].selected)
      {
        if (expressionTableRow.cells[2].innerHTML.indexOf('All News Sources') == -1)
        {
          expressionTableRow.cells[2].innerHTML += newsSourcesSelect.options[i].innerHTML + '<br />';
        }
        else
        {
          expressionTableRow.cells[2].innerHTML = newsSourcesSelect.options[i].innerHTML + '<br />';
        }
      }
    }
  }
  newsSourcesSelect.options.selectedIndex = 0;
}

function selectIndexes()
{
  var source = event.srcElement;
  var expressionTableRow = document.getElementById('expressionTable').rows[1];
  var indexesSelect = document.getElementById('indexes');
  var i;

//  if (source.options.selectedIndex == 0)
//  {
//    expressionTableRow.cells[3].innerHTML = source.options[source.options.selectedIndex].innerHTML + '<div></div>';
//  }
//  else if(expressionTableRow.cells[3].innerHTML.indexOf('All Indexes') == -1)
//  {
//    expressionTableRow.cells[3].innerHTML += source.options[source.options.selectedIndex].innerHTML + '<div></div>';
//  }
//  else
//  {
//    expressionTableRow.cells[3].innerHTML = source.options[source.options.selectedIndex].innerHTML + '<div></div>';
//  }
  if (indexesSelect.options[0].selected)
  {
    expressionTableRow.cells[3].innerHTML = indexesSelect.options[0].innerHTML + '<br />';
  }
  else
  {
    for (i = 1; i < indexesSelect.length; i++)
    {
      if (indexesSelect.options[i].selected)
      {
        if (expressionTableRow.cells[3].innerHTML.indexOf('All Indexes') == -1)
        {
          expressionTableRow.cells[3].innerHTML += indexesSelect.options[i].innerHTML + '<br />';
        }
        else
        {
          expressionTableRow.cells[3].innerHTML = indexesSelect.options[i].innerHTML + '<br />';
        }
      }
    }
  }
  indexesSelect.options.selectedIndex = 0;
}

function selectNewsCategories()
{
  var source = event.srcElement;
  var expressionTableRow = document.getElementById('expressionTable').rows[1];
  var newsCategorySelect = document.getElementById('newsCategory');
  var i;

//  if (source.options.selectedIndex == 0)
//  {
//    expressionTableRow.cells[4].innerHTML = source.options[source.options.selectedIndex].innerHTML + '<div></div>';
//  }
//  else if (expressionTableRow.cells[4].innerHTML.indexOf('All News Categories') == -1)
//  {
//    expressionTableRow.cells[4].innerHTML += source.options[source.options.selectedIndex].innerHTML + '<div></div>';
//  }
//  else
//  {
//    expressionTableRow.cells[4].innerHTML = source.options[source.options.selectedIndex].innerHTML + '<div></div>';
//  }
  if (newsCategorySelect.options[0].selected)
  {
    expressionTableRow.cells[4].innerHTML = newsCategorySelect.options[0].innerHTML + '<br />';
  }
  else
  {
    for (i = 1; i < newsCategorySelect.length; i++)
    {
      if (newsCategorySelect.options[i].selected)
      {
        if (expressionTableRow.cells[4].innerHTML.indexOf('All News Categories') == -1)
        {
          expressionTableRow.cells[4].innerHTML += newsCategorySelect.options[i].innerHTML + '<br />';
        }
        else
        {
          expressionTableRow.cells[4].innerHTML = newsCategorySelect.options[i].innerHTML + '<br />';
        }
      }
    }
  }
  newsCategorySelect.options.selectedIndex = 0;
}

function selectNewsIndustries()
{
  var source = event.srcElement;
  var expressionTableRow = document.getElementById('expressionTable').rows[1];
  var newsIndustrySelect = document.getElementById('newsIndustry');
  var i;
  
//  if (source.options.selectedIndex == 0)
//  {
//    expressionTableRow.cells[5].innerHTML = source.options[source.options.selectedIndex].innerHTML + '<div></div>';
//  }
//  else if (expressionTableRow.cells[5].innerHTML.indexOf('All News Industries') == -1)
//  {
//    expressionTableRow.cells[5].innerHTML += source.options[source.options.selectedIndex].innerHTML + '<div></div>';
//  }
//  else
//  {
//    expressionTableRow.cells[5].innerHTML = source.options[source.options.selectedIndex].innerHTML + '<div></div>';
  //  }
  if (newsIndustrySelect.options[0].selected)
  {
    expressionTableRow.cells[5].innerHTML = newsIndustrySelect.options[0].innerHTML + '<br />';
  }
  else
  {
    for (i = 1; i < newsIndustrySelect.length; i++)
    {
      if (newsIndustrySelect.options[i].selected)
      {
        if (expressionTableRow.cells[5].innerHTML.indexOf('All News Industries') == -1)
        {
          expressionTableRow.cells[5].innerHTML += newsIndustrySelect.options[i].innerHTML + '<br />';
        }
        else
        {
          expressionTableRow.cells[5].innerHTML = newsIndustrySelect.options[i].innerHTML + '<br />'; 
        }    
      }
    }
  }
  newsIndustrySelect.options.selectedIndex = 0;
}

function deleteHilitedText()
{
  var expressionTable = document.getElementById('expressionTable');
  var i;
  var endIndex;
  
  if (event.keyCode == 46)
  {
    document.selection.createRange().text = ''; //other browsers use document.getSelection()
    for (i = 0; i < expressionTable.rows[1].cells.length; i++)
    {
      //alert('line 2548 expressionTable.rows[1].cells[' + i + '].innerHTML = ' + expressionTable.rows[1].cells[i].innerHTML);
      expressionTable.rows[1].cells[i].innerHTML.replace(/^\s+|\s+$/g, "");
      //while (expressionTable.rows[1].cells[i].innerHTML.slice(0, 11).toLowerCase() == '<div></div>')
      while (expressionTable.rows[1].cells[i].innerHTML.slice(0, 3).toLowerCase() == '<br')
      {
        endIndex = expressionTable.rows[1].cells[i].innerHTML.indexOf('>') + 1;
        expressionTable.rows[1].cells[i].innerHTML = expressionTable.rows[1].cells[i].innerHTML.slice(endIndex);
        expressionTable.rows[1].cells[i].innerHTML.replace(/^\s+|\s+$/g, "");
        //alert('line 2556 expressionTable.rows[1].cells[' + i + '].innerHTML = ' + expressionTable.rows[1].cells[i].innerHTML);
      }
    }
  }  
}
