//
// kwnext.js
//
// VARIABLE DECLARATIONS
var emailto = "";
var daysInMonth = new Array(0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var digits = "0123456789";
 
// whitespace characters
var whitespace = " \t\n\r";
var popup = "";
var featurePopup=0;
var activePopup = 0;
// prompt strings
var pEntryPrompt = "Please enter a ";
var sDate = "Date in MM/DD/YYYY format, or by click on the calendar image button and select a date";
var iDate = "This field must be a valid date. Please click on the calendar image button to select a date.";

// Global variable defaultEmptyOK defines default return value
var defaultEmptyOK = false
// Global object variable;
var fieldName;
var fieldValue;

// get cookie value
function getcookie(name) {
// alert("cookie="+document.cookie);
    if (document.cookie.length > 0) {
        cookies = document.cookie;
        cookiebeg = cookies.indexOf(name+"=");
        if (cookiebeg > -1)  {
            cookieend = cookies.indexOf(";", cookiebeg);
            if (cookieend == -1)
                cookieend = cookies.length + 1;
            cookievalue = cookies.substring(cookiebeg+name.length+1,cookieend);
// alert("cookie value="+cookievalue);
            return cookievalue;
        }
    }
    return "";
}


function SetCookie (name, value) 
{
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length; 
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null; 
var domain = (argc > 4) ? argv[4] : null; 
var secure = (argc > 5) ? argv[5] : false;
//document.cookie = name + "=" + value +
 ((expires == null) ? "" : ("; expires=" + expires)) +
//lcs  ((path == null) ? "/" : ("; path=/" + path)) +
 ((path == null) ? "/kwnext" : ("; path=/" + path)) +
 ((domain == null) ? "" : ("; domain=" + domain)) + 
 ((secure == true) ? "; secure" : "");
// alert("Cookie set: "+document.cookie);
}


// set cookie value
function setpermcookie(name,value) 
{
// alert ("You are calling setpermcookie function !!! "+name+" - "+value);
    var exp = new Date();
    var webpath = "/kwnext;";
//    var webpath = "/kennyweb;";
    nowPlus3years = exp.getTime() + (1068 * 24 * 60 * 60 * 1000);
    exp.setTime(nowPlus3years);
    // SetCookie(name,value,exp.toGMTString(),"/kwnext");
//    document.cookie = name + "=" + value + "; expires=" + exp.toGMTString() + "; path =" + webpath;
    // document.cookie = name + "=" + value + "; expires=" + exp.toGMTString();
    // document.cookie = name + "=" + value + "; path + "=/;"
    // document.cookie = "KBS=KCL; expires = 01/01/2020; path = /kennywebgad";
//alert(document.cookie);
}

// Check whether string s is empty.
function isEmpty(s)
{
   return ((s == null) || (s.length == 0))
}
 
// Removes all whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.
function stripWhitespace (s) 
{
        return stripCharsInBag (s, whitespace)
}

// charInString (CHARACTER c, STRING s)
// Returns true if single character c (actually a string)
// is contained within string s.
function charInString (c, s)
{
        for (i = 0; i < s.length; i++)  {
                if (s.charAt(i) == c) return true;
        }
        return false
}

// Removes initial (leading) whitespace characters from s.
function stripInitialZero(s)  
{
        var i = 0;
        while ((i < s.length) && charInString (s.charAt(i), '0'))
                i++;
                return s.substring (i, s.length);
}

// Returns true if character c is an English letter
// (A .. Z, a..z).
function isLetter (c) {
        return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

// Returns true if string s is English letters
// (A .. Z, a..z) only.
function isAlphabetic (s)  
{
        var i;
        if (isEmpty(s))
                if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
                else return (isAlphabetic.arguments[1] == true);

        // Search through string's characters one by one
        // until we find a non-alphabetic character.
        // When we do, return false; if we don't, return true.

        for (i = 0; i < s.length; i++)  {
                // Check that current character is letter.
                var c = s.charAt(i);

                if (!isLetter(c))
                        return false;
        }

        // All characters are letters.
        return true;
}

// Returns true if string s is English letters
// (A .. Z, a..z) and numbers only.

function isAlphanumeric (s)
{   var i;

    if (isEmpty(s))
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    // All characters are numbers or letters.
    return true;
}
// isInteger (STRING s [, BOOLEAN emptyOK])
function isInteger (s)
{
    var i;
    if (isEmpty(s))
 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
 
    // Search through string's characters one by one
    // until we find a non-numeric character.
    for (i = 0; i < s.length; i++){
 
        // Check that current character is number.
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
 
    }
 
    // All characters are numbers.
    return true;
}

// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
function isIntegerInRange (s, a, b){
   if (isEmpty(s))
 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);
 
    if (!isInteger(s, false)) return false;
    var num = parseFloat (s);
    return ((num >= a) && (num <= b));
}
  
// Removes all characters which appear in string bag from string s.
function stripCharsInBag (s, bag){
    var i;
    var returnString = "";
 
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

// Returns true if character c is a digit (0 .. 9)
function isDigit (c){
   return ((c >= "0") && (c <= "9"))
}

 
// isNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
function isNonnegativeInteger (s){
   var secondArg = defaultEmptyOK;
 
    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];
 
    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseFloat (s) >= 0) ) );
} 
 
// isSignedInteger (STRING s [, BOOLEAN emptyOK])
function isSignedInteger (s){
   if (isEmpty(s))
 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);
 
    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;
 
        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];
 
        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+"))
           startPos = 1;
 
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

// isYear (STRING s [, BOOLEAN emptyOK])
function isYear (s){
   if (isEmpty(s))
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
 
    if (!isNonnegativeInteger(s)) return false;
 
    return (s.length == 4);
}
// isMonth (STRING s [, BOOLEAN emptyOK])
function isMonth (s){
   if (isEmpty(s))
 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
 
    return isIntegerInRange (s, 1, 12);
}
 
 
// isDay (STRING s [, BOOLEAN emptyOK])
function isDay (s){
   if (isEmpty(s))
 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);
 
    return isIntegerInRange (s, 1, 31);
}

// isDate (STRING year, STRING month, STRING day)
function isDate (year, month, day){
 
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false)))
  return false;
 
    var intYear = parseFloat(year);
    var intMonth = parseFloat(month);
    var intDay = parseFloat(day);
 
    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]){
  return false;
    }
 
    if ((intMonth == 2) && (intDay > daysInFebruary(intYear)))
  return false;
 
    return true;
}

// daysInFebruary (INTEGER year)
function daysInFebruary (year){
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) )
) ? 29 : 28 );
}
  
// Display data entry prompt string s in status bar.
function promptEntry (s){
   window.status = pEntryPrompt + s
}

//Valid Date format 99/99/9999
function validDate(dateField){
dateField.value = stripCharsInBag(dateField.value, whitespace)
var md = dateField.value.indexOf('/');
var month = dateField.value.substring(0, md);
var dy = dateField.value.indexOf('/', md+1);
var day = dateField.value.substring(md+1, dy);
var year = dateField.value.substring(dy+1, dateField.value.length);
// alert('mm:' + month + 'dd:' + day + 'yyyy:' + year);
 if (!isEmpty(dateField.value) && !isWhitespace(dateField.value)){
   if(isDate(year, month, day))
     return true;
   else
    alert("Please re-enter date in MM/DD/YYYY format!");
    return false
 }
 return true;
}

// Returns true if string s is empty or whitespace characters only.
function isWhitespace (s){
    var i;
 
    // Is s empty?
    if (isEmpty(s)) return true;
 
    // Search through string's characters one by one
    // until we find a non-whitespace character.
    for (i = 0; i < s.length; i++){
 
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
 
        if (whitespace.indexOf(c) == -1) return false;
    }
 
    // All characters are whitespace.
    return true;
}

/* FUNCTIONS TO INTERACTIVELY CHECK VARIOUS FIELDS. */
function checkDate(dateField){
dateField.value = stripCharsInBag(dateField.value, whitespace)
var md = dateField.value.indexOf('/');
var month = dateField.value.substring(0, md);
var dy = dateField.value.indexOf('/', md+1);
var day = dateField.value.substring(md+1, dy);
var year = dateField.value.substring(dy+1, dateField.value.length);
 
//alert('mm:' + month + 'dd:' + day + 'yyyy:' + year);
 if (!isEmpty(dateField.value) && !isWhitespace(dateField.value)){
   if(isDate(year, month, day))
  return true;
   else
  return warnInvalid(dateField, iDate);
 }
 return true;
}

 function printit(pagename,width1,height1)
 {
	popup = window.open (pagename,'printit',"toolbar=yes,scrollbars=yes,status=no,resizable=yes,width=800,height=500,screenX=0,screenY=0");
         popup.focus();
     }
 

// Notify user that required field theField is empty.
function warnEmpty (theField, s){
    theField.focus()
    alert(mPrefix + s + mSuffix)
    return false
}
 
 
// Notify user that contents of field theField are invalid.
function warnInvalid (theField, s){
    theField.select()
    theField.focus()
    alert(s)
    return false
}

function showError()
{
    // document.search_form.cusip.value = msg;
   // alert("showError: ["+msg+"] ["+document.search_form.cusip.value+"]");
    document.location = '/kwnext/error10.html';  
}
/******************************************************
 *    Runs on the caller side                         *
 *    Builds query  data record to be saved           *
 ******************************************************/
function getPref(doc_name,list)
{
   var letter;
   field_name = new String(100);
   var start_point;
   var end_point;
   var no_values;
   var result;
   var resulttemp;
   var fldname;
   // alert('<1> getPref: '+doc_name+' - '+list);    
   start_point = 0;
   no_values = 0;
   for (letter = 0; letter < list.length; letter++)
   {

      if (list.substring(letter,letter+1) == ",")
      {
         end_point = letter;
         field_name[no_values] = list.substring(start_point,end_point);
     //    alert("<1> field_name: "+field_name[no_values]);  
         start_point = letter+1;
         no_values ++;
      }
   }
   field_name[no_values] = list.substring(start_point,list.length+1);
   result = "";
   for (value = 0; value<= no_values; value++)
   {
      fldname = field_name[value];
      eval("result+="+"'<';");
      eval("result+="+"'"+field_name[value]+"';");
      eval("result+="+"'>';");
      eval("result+="+doc_name+field_name[value]+".value;");
      // alert("<3> "+doc_name+field_name[value]+".value");   
   }
   // alert("<3.1> "+result);
   for (letter = 0; letter < result.length; letter++)
   {
      if (result.substring(letter,letter+1) == " ")
      {
           resulttemp = stripWhitespace (result.substring(0,letter+1));

           result = resulttemp+result.substring(letter+1,result.length);
      }

      if (result.substring(letter,letter+1) == "\n")
      {
         if ( (result.substring(letter+1,letter+2) != "<") || (result.substring(letter+1,letter+2) != "\n") )
         {

           result = result.substring(0,letter-1)+","+result.substring(letter+1,result.length);

         }
         else
         {
             result = result.substring(0,letter-1)+result.substring(letter+1,result.length);
         }
     //    alert("<4> "+letter+"  result: "+result);
      }
   }
 // alert("--> getPref: \n["+result+"]"); 
 return result;
}


/******************************************************
 *                                                    *
 *    selectPref(doc_name)                            *
 *                                                    *
 *    parameters: location of caller                  *
 *                                                    *
 *    Populates input fields on the caller side       *
 *    with search criteria.                           *
 *                                                    *
 ******************************************************/
function selectPref(doc_name)
{
var tempbuf;
var start_point;
var end_point;
var fld_name;
var no_values;
var counter;
// alert("[1.selectPref] docname: "+doc_name);   
field_name = new String(100);
field_value = new String(100);
   list = document.forms[0].xref;
   tempbuf = list.options[list.selectedIndex].value;
   fieldName =tempbuf;
   document.pref_form.prefname.value = list.options[list.selectedIndex].text;
   document.pref_form.prefdata.value = list.options[list.selectedIndex].value;
   // alert('[2.selectPref] prefname: '+ document.pref_form.prefname.value); 
   // alert('[3.selectPref] prefdata: '+ document.pref_form.prefdata.value); 

   // alert("[4.selectPref] doc_name: "+ doc_name+" - fieldname: " + fieldName );   
   no_values = 1;

   for (counter = 0; counter < tempbuf.length; counter++)
   {
      switch(tempbuf.substring(counter,counter+1))
      {
        case '<':
            if ((counter > 0) && (end_point != counter-2))
            {
               end_point = counter-1;
               field_value[no_values] = tempbuf.substring(start_point,end_point+1);
               field_name[no_values] = fld_name;
               no_values++;
             }
             start_point = counter+1;
             break;
         case '>':
             end_point = counter-1;
             fld_name = tempbuf.substring(start_point,end_point+1);
             start_point = counter+1;
             break;
         case ',':
             end_point = counter-1;
 field_value[no_values] = tempbuf.substring(start_point,end_point+1)+" \\n";
             field_name[no_values] = fld_name;
             // alert("[5.selectPref] field_value["+no_values+"]: "+field_value[no_values]);
             // alert("[6.selectPref] field_name["+no_values+"]: "+field_name[no_values]);  

             no_values++;
             start_point = counter+1;
             break;
        }
        field_value[no_values]=tempbuf.substring(start_point,tempbuf.length+1);
        field_name[no_values] = fld_name;
      }

      field_name[0] = "999999"; 

      for (counter = 1; counter <= no_values; counter++)
      {
          fld_name = field_name[counter];
          eval_fld_name=doc_name+fld_name+".value+="+field_value[counter]
          if ( fld_name != field_name[counter-1]) 
          {
               // alert("[7.selectPref] start docname+fld_name: "+docname+fld_name);  
               eval(doc_name+fld_name+".value='';"); 
               // alert("[8.selectPref] end docname+fld_name: "+docname+fld_name); 

          }
          // alert("[9.selectPref] start docname+fld_name: "+docname+fld_name); 
          eval(doc_name+fld_name+".value+='"+field_value[counter]+"';");
          // alert("[10.selectPref] start docname+fld_name: "+docname+fld_name); 
          if ( ( fld_name == "includequote") && (field_value[counter] == "T"))
          {
                 document.search_form.includequote.checked="defaultChecked";
          }

          // alert("[11.selectPref] field_value["+counter+"] "+field_value[counter]+"\n");   

       }
// alert("[12.selectPref] done");
}

/******************************************************
 *                                                    *
 *    getDetail(businessdate,issueridc,issuealphac)   *
 *                                                    *
 *    parameters: businessdate                        *
 *                issueridc                           *
 *                issuealphac                         *
 *                                                    *
 *    Produce HE detail page.                         *
 *                                                    *
 ******************************************************/
function getDetail(businessdate,issueridc,issuealphac) 
{
    document.hiddenDtl_form.evalbusinessd.value = businessdate;
    document.hiddenDtl_form.issueridc.value = issueridc;
    document.hiddenDtl_form.issuealphac.value = issuealphac;
    document.hiddenDtl_form.target = "_self";
    document.hiddenDtl_form.method = 'post';
    if (businessdate.value=='' )
    {
        alert("Business Date Invalid.");
        document.search_form.issueridc.focus();
             return false;
    }
    document.hiddenDtl_form.action = '/kwnext/iiop/heprcdtl';
    document.hiddenDtl_form.submit();
}
 
function setup()
{
   activePopup=1;
   popup = window.open ('../system/setup.html','setup', "toolbar=no,scrollbars=yes,status =no,resizable=yes,width=330,height=320,screenX=100,screenY=0");
   popup.focus();
}

function emailprivacy(emailname)
{
   activePopup = 1;
   emailto = emailname;
   popup = window.open ('eprivacy.html','search', "toolbar=no,scrollbars=no, status =no,resizable=no,width=680,height=490,screenX=100,screenY=0");
   popup.focus();
}

function cusbcp()
{
   activePopup = 1;
   popup = window.open ('cusbcp.html','search',"toolbar=no,scrollbars=no, status=no,resizable=no,width=440,height=386,screenX=100,screenY=0");
   popup.focus();
}

function emailprivacy2()
{
   activePopup = 1;
   popup = window.open ('form.html','search', "toolbar=no,scrollbars=no, status =no,resizable=yes,width=520,height=485,screenX=100,screenY=0");
   popup.focus();
}

function emailprivacy3()
{
   activePopup = 1;
   popup = window.open ('privacy.html','search', "toolbar=no,scrollbars=no, status =no,resizable=yes,width=520,height=500,screenX=100,screenY=0");
   popup.focus();
}

function emailprivacy4()
{
   activePopup = 1;
   popup = window.open ('ids_ob.htm','search', "toolbar=no,scrollbars=no, status =no,resizable=yes,width=570,height=175,screenX=100,screenY=0");
   popup.focus();
}

function emailprivacy5()
{
   activePopup = 1;
   popup = window.open ('ids_is.htm','search', "toolbar=no,scrollbars=no, status =no,resizable=yes,width=520,height=175,screenX=100,screenY=0");
   popup.focus();
}

function emailprivacy6()
{
   activePopup = 1;
   popup = window.open ('ids_gics.htm','search', "toolbar=no,scrollbars=no, status =no,resizable=yes,width=520,height=175,screenX=100,screenY=0");
   popup.focus();
}

function sendemail()
{
//   emailto = emailname;
//   document.location="mailto:"+emailto;
   location.href="mailto:"+emailto;
}

function search()
{
 activePopup=1;
   popup = window.open ('hmdsearch.html','search', "toolbar=no,scrollbars=no, status =no,resizable=no,width=680,height=490,screenX=100,screenY=0");
   popup.focus();
}

function kb_search()
{
 activePopup=1;
   popup = window.open ('kb_search.html','kbsearch', "toolbar=no,scrollbars=yes, status =no,resizable=no,width=716,height=480,screenX=100,screenY=0");
   popup.focus();
}
function popupWhatsnew()                                                        
{
   document.location="/kwnext/whatsnew.html";                         
}  

function popupSupport()
{
    document.location = '/kwnext/support.html'; 
}

function popupFaq()
{
   document.location = '/kwnext/faq.html';
}

function popupContact()  
{                                            
   activePopup=1;                                                        
   popup = window.open ('/kwnext/contact.html','sys', "toolbar=no,scrollbars=yes,status =no,resizable=yes,width=520,height=500,screenX=100,screenY=0");
   popup.focus();                                                                                                                   
}

function hsghelp()                                                              
{   
 document.location = '/kwnext/help/hsg/hsghelp.html';                       
}

function hmdhelp()                                                              
{                   
 document.location = '/kwnext/help/hmd/hmdhelp.html';              
}                                                                                
function kbshelp()
{
    document.location = '/kwnext/help/kbs/index.htm';
}


function Is ()
{   // convert all characters to lowercase to simplify testing 
    var agt=navigator.userAgent.toLowerCase(); 

    // browser version
    // Note: On IE5, these return 4, so use is.ie5up to detect IE5. 
    this.major = parseInt(navigator.appVersion); 
    this.minor = parseFloat(navigator.appVersion); 

    this.nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) 
              && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
              && (agt.indexOf('webtv')==-1)); 
    this.nav2 = (this.nav && (this.major == 2)); 
    this.nav3 = (this.nav && (this.major == 3)); 
    this.nav4 = (this.nav && (this.major == 4)); 
    this.nav4up = (this.nav && (this.major >= 4)); 
    this.navonly      = (this.nav && ((agt.indexOf(";nav") != -1) || 
                        (agt.indexOf("; nav") != -1)) ); 
    this.nav5 = (this.nav && (this.major == 5)); 
    this.nav5up = (this.nav && (this.major >= 5)); 
  
    this.ie   = (agt.indexOf("msie") != -1); 
    this.ie3  = (this.ie && (this.major < 4)); 
    this.ie4  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")==-1)); 
    this.ie4up  = (this.ie  && (this.major >= 4)); 
    this.ie5  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1)); 
    this.ie5up  = (this.ie  && !this.ie3 && !this.ie4); 

    this.ver4up  = (this.ie4up || this.nav4up); 

    //platform
    this.mac    = (agt.indexOf("mac")!=-1); 
} 

//create the is.user agent object
var is = new Is();
 
//create an array object supported in js 1.0
//start at 1 so the date functions make sense
function makeArray(i)
{
    this.length = i;
    for(index=1;index<(i+1);index++)
    {
       this[index] = null;
    }
    return this;
}

//open multiple windows
//define an array so only one open window function is necessary
windowContainer = new makeArray(3);

/*
   parameters are the window number (index in the array) starting with 1,
   url, name of the window, width, height, x position, y position,
   turn scrollbars on/off 
*/

function makeRemote(indx,url,winName,x,y,sX,sY,scroll)
{
        if (!windowContainer[indx] || windowContainer[indx].closed)
        {
          if (is.ver4up) windowContainer[indx]=window.open(url,winName,"width=" + x + ",height=" + y + ",screenX=" + sX + ",screenY=" + sY + ",left=" + sX + ",top=" + sY + ",scrollbars=" + scroll );
          else windowContainer[indx]=window.open(url,winName,"width=" + x + ",height=" + y + ",scrollbars=" + scroll );
        }
        else
        {   //check if a new url is to loaded
            if ( windowContainer[indx].document.location.href.indexOf(url) == -1 ) windowContainer[indx].document.location.href = url;
        }
        if (window.focus) windowContainer[indx].focus();
      return;
}

function showStatus(msg)
{
   window.status = msg;
   return true;
}

// Notify user that required field theField is empty.
function warnEmpty (theField, s){
    theField.focus()
    alert(mPrefix + s + mSuffix)
    return false
}
 
function stripCharsInBag (s, bag)
{
    var i;
    var returnString = "";
 
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
 
function closeSearch()
{
   window.close()
}
 
function getCurrDate()
{
   today = new Date();
   document.search_form.loactivityd.value = padAZero((today.getMonth()+1).toString()) + '/'+padAZero((today.getDate()).toString()) + '/' +padAZero(today.getFullYear().toString());
   document.search_form.hiactivityd.value = padAZero((today.getMonth()+1).toString()) + '/'+padAZero((today.getDate()).toString()) + '/' +padAZero(today.getFullYear().toString());
   /*
   alert('mm:' + today.getMonth() + ' dd:' + today.getDate() + ' yy:' + today.getFullYear());
  */
}
 
 
function validHMDDate(dateField)
{
 dateField.value = stripCharsInBag(dateField.value, whitespace)
 var md    = dateField.value.indexOf('/');
 var month = dateField.value.substring(0, md);
 var dy    = dateField.value.indexOf('/', md+1);
 var day   = dateField.value.substring(md+1, dy);
 var year  = dateField.value.substring(dy+1, dateField.value.length);
   if((year < 1998) ||
      (year < 1999 && month < 12) ||
      (year < 1999 && month < 13 && day < 14))
   {
            alert("Starting or Ending Date can not be less then Dec-14-1998");
            return false
   }
return true;
}
 
function DoExport()
{
   document.search_form.htmlflag.value = '0';
   document.search_form.action = "/kwnext/iiop/heprctbl";
   document.search_form.target = "_self";
   document.search_form.method = "post";
   document.search_form.submit();
}
 
function padAZero(s)
{
if(s.length==1)
        s = "0" + s;
return s;
}
 
function stripCharsInBag (s, bag)
{
    var i;
    var returnString = "";
 
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

/******************************************************
 *                                                    *
 *    parameters: none                                *
 *                                                    *
 *    Create Preference page and populates it with    *
 *    available queries.                              *
 *                                                    *
 ******************************************************/
function userpref(mode)
{
   document.search_form.appname.value = mode;
   activePopup=1;
   switch (mode)
   {
        case "KBS":
            popup = window.open ('/kwnext/kwgetquery.html', 'userpref', "toolbar=no,scrollbars=no, status=no,resizable=yes,width=790,height=465,screenX=150,screenY=300");                                                                              
            document.search_form.fieldnames.value = 'cusip,bond,issueDesc,type,class1,subclass,fromCoupon,toCoupon,fromMaturityDate,toMaturityDate,fromDatedDate,toDatedDate,fromCreditAgency,fromCrditType,fromRating1,toRating1,toCreditAgency,toCrditType,fromRating2,toRating2'
            break;                                                              
        case "HSG":
            popup = window.open ('/kwnext/kwgetquery.html', 'userpref', "toolbar=no,scrollbars=no, status=no,resizable=yes,width=690,height=530,screenX=150,screenY=300");
            document.search_form.fieldnames.value = 'cusip,datedfrom,datedto,states'
            break;
          case "QL": 
            if (featurePopup==1)
            {
               popup.focus();
               popup.close();
               featurePopup=0;
            }                                                  
            popup = window.open ('/kwnext/kwgetquery.html', 'userpref', "toolbar=no,scrollbars=no, status=no,resizable=yes,width=690,height=480,screenX=150,screenY=300");                                                                              
            document.search_form.fieldnames.value = 'cusip,includequote'
            break;                                                               
          case "HE":
            popup = window.open ('/kwnext/kwgetquery.html', 'userpref', "toolbar=no,scrollbars=no, status=no,resizable=yes,width=690,height=530,screenX=150,screenY=300");
            document.search_form.fieldnames.value = 'cusip,loactivityd,hiactivityd'
            break;
        default:
            document.location = '/kwnext/error.html';
    }
  
   document.search_form.docname.value = 'document.search_form.';
   document.search_form.action = "/kwnext/iiop/kwgetquery";
   document.search_form.target = "userpref";
   document.search_form.method = "post";
   document.search_form.submit();
   popup.focus();
}

function relogin(mode)         
{                               
   if (mode == "Y")                         
   { 
       activePopup=1;
       popup.close();                             
       document.location = '/kwnext/index.html';
   }

}    

function closePopup(appname)
{                                                           
   switch (appname)
   {
        case "KBS":
            userpref('KBS');
            break;
        case "HSG":                                       
            userpref('HSG');                                
            break;
        case "HE":                                        
            userpref('HE');                                 
            break;                                          
        case "QL":                                        
            userpref('QL');                                 
            break;                                          
        default:                                       
            document.location = '/kwnext/hsg/error.html';
    }
}
function setActivePopup()
{
 //alert("setActivePopup: "+activePopup);
 if (activePopup == 1)                                                          
 {
//alert("setActivePopup: "+activePopup);
     popup.close();                                                             
     activePopup=0;                   
//alert("setActivePopup: "+activePopup);                                          
 }
}
   
function logOff()
{
   document.search_form.action = "/kwnext/iiop/kwlogoff";  
   document.search_form.target = "_self";  
   document.search_form.method = "post";
   document.search_form.submit();                
}

/********************* HOUSING and KBS **************************/
var currentmap='';
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
} 

function LoadAllImages() {
    MM_preloadImages('/kwnext/media/hdrmap.gif','#10');
    MM_preloadImages('/kwnext/media/hdrsearch.gif','#20');
    MM_preloadImages('/kwnext/media/hdrnewinfo.gif','#30');
    MM_preloadImages('/kwnext/media/hdrhelp.gif','#40');
}
 
function map_menu() {
    MM_swapImage('document.menu','document.menu','/kwnext/media/hdrmap.gif','#10');
    document.location = '/kwnext/hsg/hsgmap.html';
}
 
function search_menu() {
 activePopup=1;
     popup = window.open ('/kwnext/hsg/hsgsearch.html','hsgsearch',"toolbar=no,scrollbars=no,status =no,resizable=no,width=400,height=360,screenX=100,screenY=200");
    popup.focus();

    MM_swapImage('document.menu','document.menu','/kwnext/media/hdrsearch.gif','#20');
}
 
function newinfo_menu() {
    MM_swapImage('document.menu','document.menu','/kwnext/media/hdrnewinfo.gif','#30');
    getNewInfo();
}
 
function help_menu() {
    MM_swapImage('document.menu','document.menu','/kwnext/media/hdrhelp.gif','#40');
    document.location = 'help.html';
}
 
function getMap(region) {
    switch (region)  {
        case "NE":
            document.location = '/kwnext/hsg/hsgmapne.html';
            break;
        case "SE":
            document.location = '/kwnext/hsg/hsgmapse.html';
            break;
        case "MW":
            document.location = '/kwnext/hsg/hsgmapmw.html';
            break;
        case "WEST":
            document.location = '/kwnext/hsg/hsgmapwest.html';
            break;
        default:
            document.location = '/kwnext/hsg/hsgmap.html';
    }
    currentmap=region;
}
 
function getCurrentMap() {
        getMap(currentmap);
}
 
function runCallRpt(issuer,secseqnum,pagenum){
    document.detailform.criteria.value='100~'+issuer+'~~'+secseqnum+'~'+pagenum;
    document.detailform.action = "/kwnext/iiop/hsgcallrpttest";
    document.detailform.target = "_self";
    document.detailform.method = "post";
    document.detailform.submit();
}
 
function runCallRptByIssue(issuer,alpha,pagenum){
    document.detailform.criteria.value='200~'+issuer+'~'+alpha+'~~'+pagenum;
    document.detailform.action = "/kwnext/iiop/hsgcallrpttest";
    document.detailform.target = "_self";
    document.detailform.method = "post";
    document.detailform.submit();
}
/* WAS search_form */ 
function runIssuerScan(criteria, startingAt, pagestarts){
    document.searchform.criteria.value=criteria;
    document.searchform.startingAt.value=startingAt;
    document.searchform.pagestarts.value=pagestarts;
    document.searchform.action = "/kwnext/iiop/hsgissrscantest";
    document.searchform.target = "_self";
    document.searchform.method = "post";
    document.searchform.submit();
}
 
function getIssuerByState(states){
    runIssuerScan('100~'+states+'~~~',',0','');
}
 
function getIssuerByIssuer(issuer){
    runIssuerScan('100~~'+issuer+'~~',',0','');
}
 
function getNewInfo(){
    runIssuerScan('200~~~~',',0,','');
}
                                               
function prod_demo()                                                           
{        
    popup_close();     
    document.location = '/kwnext/demo/demo1.html';                              
}                                                                              

function runSearch(cusip,datedfrom,datedto,states,hsgmode) {

   var nostates = 0;     
   var letter;                                                                  
   var fldname;     
   var issuer = "";
   var issuealpha = "";
   var criteria = "";
   var startingAt = "";
   var pagestarts = "";
   var resulttemp = "";
   var errorflag = true;
   // verify that basic criteria present
   if ((cusip.value.length==0)&&(states.value.length==0))
   {
       alert('At least a CUSIP/Issuer or state must be entered');
       document.search_form.cusip.focus();
       popup.focus();
       errorflag = true;
    }
    else
    {
       for (letter = 0; letter < states.value.length; letter++)           
       {                                                         

           switch(states.value.substring(letter,letter+1)) 
           {                                                            
              case '\n':
                 resulttemp=resulttemp+",";  
                 nostates++;
                 break;                                                         
              case '\r':                                                        
                 break;                                                         
              case '\f':                                                        
                 break;                                                         
              case ' ':                                                         
                 break;                                                         
              default:        
                 resulttemp=resulttemp+states.value.substring(letter,letter+1); 
                 break;                  
            }
          }
          resulttemp=resulttemp+",";                                     
          nostates++;                                                    
        }
   
       for (letter = states.value.length; letter > 0; letter--)                 
       { 
          if(resulttemp.substring(letter,letter+1) ==",")
          {
             resulttemp = resulttemp.substring(0,letter);
             break;
          }
       }

    if (nostates > 10)                                                          
    { 
        alert("You can't enter more the 10 states per search."); 
        document.search_form.states.focus();    
        popup.focus();
        errorflag = false;
    }
    else
    {
    
        states.value = resulttemp;
    }
        // validate dates
        var datedfromdb = datedfrom.value;
        var datedtodb   = datedto.value;
        
        if (datedfromdb.length > 0)  {
                datedfromdb = datedfromdb.substring(6,10)
                        + '-' + datedfromdb.substring(0,2)
                        + '-' + datedfromdb.substring(3,5);
        }
        if (datedtodb.length > 0)  {
                datedtodb = datedtodb.substring(6,10)
                        + '-' + datedtodb.substring(0,2)
                        + '-' + datedtodb.substring(3,5);
        }

        // issuer scan setup
        if ((cusip.value.length==6)||(states.value.length>1))
        {
            issuer = cusip.value.substring(0,6);
            criteria=
               hsgmode.value
                   + "~" + states.value
                   + "~" + issuer
                   + "~" + datedfromdb
                   + "~" + datedtodb;
            startingAt=",0";

            if (errorflag == true)
            {
               runIssuerScan(criteria, startingAt, pagestarts);
               popup.close();
            } 
        }
        // call rpt lookup using full cusip
        else if (cusip.value.length >= 8)  {
            issuer     = cusip.value.substring(0,6);
            issuealpha = cusip.value.substring(6,8);

            if (errorflag == true)                                              
            {   
                runCallRptByIssue(issuer, issuealpha, 1);
                popup.close();
            }
        }
        // invalid cusip
        else  {
            alert('Invalid CUSIP');
            document.search_form.cusip.focus();
            popup.focus();
        }

}
/************************************************/
/* This is a QuickLink Demo                     */
/************************************************/
function popupQl()     
{    
   popup = window.open ('/kwnext/ql_test/ql02.html','QuickLink', "toolbar=no,scrollbars=no ,status =no,resizable=no ,width=142,height=390,screenX=640,screenY=0"); 
   popup.focus();   
}

function showQl3()
{
 window.close(); 
   opener.location = '/kwnext/ql_test/ql03.html';

}
    function popLogon()
    {
       popup = window.open ("login.html", 'logon', "toolbar=no,scrollbars=no, status=no,resizable=yes,width=290,height=190,screenX=100,screenY=200");
        popup.focus();
         

    }

function showQl4() 
{                                                                       
 window.close();                                      
   opener.location = '/kwnext/ql_test/ql04.html';      
}   

