var validInputData = true;
var checkEmpytField = true;
var InputText = "";
var lastErrorIDStr = "";
var clickOnCheckBox = false;

var browserVersion = navigator.appVersion;

var isNS = (navigator.appName.indexOf("Netscape") > -1) ? true : false;
var isIE = (navigator.appName.indexOf("Explorer") > -1) ? true : false;

var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
var isDyn = (isDOM || isIE4 || isNS4);

var LeftM1 = 10;
var LeftM2 = (isIE ? 92 : 92);

function getRef(id)
{
/*
   if (isDOM) return document.getElementById(id);
   if (isIE4) return document.all[id];
   if (isNS4) return document.layers[id];
*/
   if (isDOM)
   {
      if (document.getElementById(id) != null)
      {
         return document.getElementById(id);
      }
      else
      {
         return null;
      }
   }
   if (isIE4)
   {
      if (document.all[id] != null)
      {
         return document.all[id];
      }
      else
      {
         return null;
      }
   }
   if (isNS4)
   {
      if (document.layers[id] != null)
      {
         return document.layers[id];
      }
      else
      {
         return null;
      }
   }
}

function getSty(id)
{
   return (isNS4 ? getRef(id) : getRef(id).style);
}

function SetValueById(IDStr,value)
{
if (getRef(IDStr) != null)
{
 getRef(IDStr).value = value;
}
}

function SetValueById2(IDStr)
{
   if (getRef(IDStr) != null)
   {
      if (getRef(IDStr).checked == true)
      {
         getRef(IDStr).value = "checked";
      }
      else
      {
         getRef(IDStr).value = "";
      }
   }
}

function EnableDisableItem(IDStr,enable)
{
   getRef(IDStr).disabled = !enable;
   if (!enable)
   {
      getSty(IDStr).color = "gray";
   }
   else
   {
      getSty(IDStr).color = "black";
   }
}

function EnableDisableItems(itemsToEnableID,enable)
{
   var tempItems=itemsToEnableID;
   var IDStr="";

   while (tempItems.length > 0)
   {
      IDStr = tempItems.substr(0,tempItems.indexOf(","));
      if (IDStr == "")
      {
         IDStr=tempItems;
      }
      if (IDStr != "")
      {
         getRef(IDStr).disabled=!enable;
         if (!enable)
         {
            getSty(IDStr).color = "gray";
         }
         else
         {
            getSty(IDStr).color = "black";
         }
         tempItems=tempItems.replace(IDStr,"");
         tempItems=tempItems.replace(",","");
      }
   }
}

function DeleteAllSpace(IDStr)
{
   if ( (IDStr != "") && (getRef(IDStr) != null) )
   {
      var inputStr = getRef(IDStr).value;

      if (inputStr.length > 0)
      {
         while (inputStr.indexOf(" ") > -1)
         {
            inputStr = inputStr.replace(" ","");
         }

         getRef(IDStr).value = inputStr;
      }
   }
}

function DeleteBeginAndEndSpace(IDStr)
{
   var length = 0;
   if ( (IDStr != "") && (getRef(IDStr) != null) )
   {
      var inputStr = getRef(IDStr).value;

      if (inputStr.length > 0)
      {
         while (inputStr.indexOf(" ") == 0)
         {
            inputStr = inputStr.replace(" ","");
         }

         length = inputStr.length;

         while (inputStr.lastIndexOf(" ") == (length-1))
         {
            inputStr = inputStr.substr(0,length-1);
            length = inputStr.length;
         }

         getRef(IDStr).value = inputStr;
      }
   }
}

function getScrollBarWidth()
{
/*
   if ( ((parseInt(browserVersion) > 4.75) && isNS) ||
        ((parseInt(browserVersion) >= 3.0) && isIE) )
   {
      try
      {
         var elem = document.createElement("DIV");
         elem.id = "tempDIV";
         elem.style.width = 100;
         elem.style.height = 100;
         elem.style.overflow = "scroll";
         elem.style.position = "absolute";
         elem.style.visibility = "hidden";
         elem.style.top = "0";
         elem.style.left = "0";

         document.body.appendChild(elem);

         if (isNS)
         {
            scrollWidth = window.outerWidth-window.innerWidth+6;
         }
         else if (isIE)
         {
            scrollWidth = document.getElementById('tempDIV').offsetWidth-document.getElementById('tempDIV').clientWidth;
         };

         document.body.removeChild (elem);
         delete elem;
      }
      catch (ex)
      {
         return false;
      }
   }
   else
   {
      return 0;
   }
*/
   if ( ((parseInt(browserVersion) > 4.75) && isNS) ||
        ((parseInt(browserVersion) >= 3.0) && isIE) )
   {
      var elem = document.createElement("DIV");
      elem.id = "tempDIV";
      elem.style.width = 100;
      elem.style.height = 100;
      elem.style.overflow = "scroll";
      elem.style.position = "absolute";
      elem.style.visibility = "hidden";
      elem.style.top = "0";
      elem.style.left = "0";

      document.body.appendChild(elem);

      if (isNS)
      {
         scrollWidth = window.outerWidth-window.innerWidth+7;
      }
      else if (isIE)
      {
         scrollWidth = document.getElementById('tempDIV').offsetWidth-document.getElementById('tempDIV').clientWidth;
      };

      document.body.removeChild (elem);
      delete elem;

      return scrollWidth;
   }
   else
   {
      return 0;
   }
}

function OverflowSupport()
{
   if (isNS || isIE)
   {
      if ( ((parseInt(browserVersion) > 4.75) && isNS) ||
           ((parseInt(browserVersion) >= 3.0) && isIE) )
      {
         return true;
      }
      else
      {
         return false;
      }
   }
   else
   {
      return true;
   }
}

function FieldsetSupport()
{
   if (isNS || isIE)
   {
      if ( ((parseInt(browserVersion) > 4.75) && isNS) ||
           ((parseInt(browserVersion) >= 3.0) && isIE) )
      {
         return true;
      }
      else
      {
         return false;
      }
   }
   else
   {
      return true;
   }
}

function ClickSupport()
{
   if (isNS || isIE)
   {
      if ( ((parseInt(browserVersion) > 4.75) && isNS) ||
           ((parseInt(browserVersion) >= 3.0) && isIE) )
      {
         return true;
      }
      else
      {
         return false;
      }
   }
   else
   {
      return true;
   }
}

function BrowserSupport()
{
   if (isNS || isIE)
   {
      if ( ((parseInt(browserVersion) > 4.75) && isNS) ||
           ((parseInt(browserVersion) >= 3.0) && isIE) )
      {
         return true;
      }
      else
      {
         return false;
      }
   }
   else
   {
      return false;
   }
}

function checkYearRange(fieldToCheck,referField,rangeLo)
{
   var temp1=parseInt(getRef(fieldToCheck).value);
   var temp2=parseInt(getRef(referField).value);

   if ( (temp1 > temp2) && (temp2 >= rangeLo) )
   {
      getRef(fieldToCheck).value = getRef(referField).value;
   }
}

function setCheckInputText(IDStr)
{
   InputText = getRef(IDStr).value;
}

function posOfInputChar(subStr,Str)
{
   var i = 0;
   var len = subStr.length;
   var subPos = Str.indexOf(subStr);
   var strPos = subStr.indexOf(Str);

   if ((subPos == 0) || (strPos == 0))
   {
      return (Str.length-1);
   }
   else
   {
      for(i=0; i<len; i++)
      {
         if (subStr.charCodeAt(i) != Str.charCodeAt(i))
         {
            return i;
         }
      }
   }
}

function formatText(IDStr,thouStr,dollarSign,percentSign,allowDecimal,numOfDecimalPoint)
{
   var tempStr = getRef(IDStr).value;
   var tempStr2 = "";
   var i = 0;
   var j = 0;

   var decimalPos = tempStr.indexOf(".");
   var decimalNum = "";
   var negativeNum = tempStr.indexOf("-");

   if (negativeNum != -1)
   {
      tempStr = tempStr.replace("-","");
   }

   if (decimalPos != -1)
   {
      decimalNum = tempStr.substring(decimalPos,tempStr.length);
      tempStr = tempStr.replace(decimalNum,"");
      while ( decimalNum.length <= numOfDecimalPoint)
      {
         decimalNum = decimalNum + "0";
      }
   }

   if ( allowDecimal && (decimalPos == -1) )
   {
      decimalNum = ".";
      while (numOfDecimalPoint > 0)
      {
         decimalNum = decimalNum + "0";
         numOfDecimalPoint--;
      }
   }

   var len = tempStr.length;

   if (thouStr)
   {
      var modNum = len%3;
      var divNum = (len-modNum)/3;
      var numComma = divNum;

      if (modNum == 0)
      {
        numComma = divNum-1;
        modNum = 3;
      }

      if (len > 3)
      {
         while (i < len)
         {
            if ( (i == modNum) && (i != 0) )
            {
               tempStr2 = tempStr2 + ",";
               j++;
            }
            else if ( (j < numComma) && (i != 0) )
            {
               if (i == (j*3+modNum))
               {
                  tempStr2 = tempStr2 + ",";
                  j++;
               }
            }

            tempStr2 = tempStr2 + tempStr.charAt(i);
            i++;
         }
         tempStr = tempStr2;
      }
   }

   tempStr = tempStr + decimalNum;

   if (dollarSign)
   {
      tempStr = "$" + tempStr;
   }

   if (percentSign)
   {
      tempStr = tempStr + "%";
   }

   if (negativeNum != -1)
   {
      tempStr = "-" + tempStr;
   }

   getRef(IDStr).value = tempStr;
}

function unFormatText(IDStr)
{
   var tempStr = getRef(IDStr).value;
   var len = tempStr.length;
   var i = 0;

   if (len > 3)
   {
      while (i < len)
      {
         if (tempStr.charAt(i) != ",")
         {
            tempStr = tempStr.replace(",","");
         }
         i++;
      }
   }


   i = 0;
   while (i < len)
   {
      if ( (tempStr.charAt(i) == " ") ||
           (tempStr.charAt(i) == "$") ||
           (tempStr.charAt(i) == "%") )
      {
         tempStr = tempStr.replace("$","");
         tempStr = tempStr.replace("%","");
         tempStr = tempStr.replace(" ","");
      }
      i++;
   }

   getRef(IDStr).value = tempStr;
   getRef(IDStr).select();
   getRef(IDStr).focus();
}

function isTheFieldEmpty(IDStr,rangeLo,rangeHi,checkRange)
{
   validInputData = true;

   var str = getRef(IDStr).value;
   var tempInt = parseInt(str);

   if (checkEmpytField && ( (lastErrorIDStr == "") || (lastErrorIDStr == IDStr) ) )
   {
      if (str.length==0)
      {
         validInputData = false;
         lastErrorIDStr = IDStr;

         if ((rangeLo=="NewProposal") && (rangeHi=="NewProposal"))
         {
            alert("In order to distinguish between multiple proposals stored in" +
                  '\n' + "this workbook, you must input a proposal description.");
         }
         else if ((rangeLo=="InputRequired") && (rangeHi=="InputRequired"))
         {
            alert("A value is required in this field.");
         }
         else
         {
            alert("Invalid range, please enter value between "+rangeLo+
                  " and "+rangeHi);
         }

         getRef(IDStr).select();
         getRef(IDStr).focus();
      }
      else if (checkRange)
      {
         if ( (tempInt < rangeLo) || (tempInt > rangeHi) )
         {
            validInputData = false;
            lastErrorIDStr = IDStr;

            alert("Invalid range, please enter value between "+rangeLo+
                  " and "+rangeHi);

            getRef(IDStr).select();
            getRef(IDStr).focus();
         }
         else
         {
            lastErrorIDStr = "";
         }
      }
      else
      {
         lastErrorIDStr = "";
      }
   }
}

function checkInputChar(IDStr,allowDecimal,numOfDecimalPoint,allowNegative,saveForDisabledIDStr)
{
   var validChar = false;
   var validRange = false;

   checkEmpytField = false;

   var tempInt = parseInt(getRef(IDStr).value);
   var str = getRef(IDStr).value;
   var decimalPos = str.indexOf(".");
   var tempStr = "";

   var inputCharPos = posOfInputChar(InputText,str);

   if (str.length >= 1)
   {
      if ( ((str.charCodeAt(inputCharPos) >= 48) &&
            (str.charCodeAt(inputCharPos) <= 57)) ||
           (str.charCodeAt(inputCharPos) == 46) ||
           (str.charCodeAt(inputCharPos) == 45) )
      {
         if ( (str.charCodeAt(inputCharPos) == 46) && allowDecimal )
         {
            if (decimalPos > 0)
            {
               if (decimalPos == (str.length-1))
               {
                  validChar = true;
               }
               else if (decimalPos == inputCharPos)
               {
                  if ((str.length-1-decimalPos) <= numOfDecimalPoint)
                  {
                     validChar = true;
                  }
               }
            }
         }
         else if ( (str.charCodeAt(inputCharPos) == 45) && allowNegative )
         {
            if (inputCharPos == 0)
            {
               validChar = true;
            }
         }
         else
         {
            if ( (str.charCodeAt(inputCharPos) != 46) &&
                 (str.charCodeAt(inputCharPos) != 45) )
            {
               if ( allowDecimal && (decimalPos != -1) )
               {
                  if ( (str.length-1-decimalPos) <= numOfDecimalPoint )
                  {
                     validChar = true;
                  }
               }
               else
               {
                  validChar = true;
               }
            }
         }
      }

      if (validChar == false)
      {
         tempStr = str.substring(0,inputCharPos);
         tempStr = tempStr + str.substring(inputCharPos+1,str.length);
         getRef(IDStr).value = tempStr;
         alert("Invalid input");
         getRef(IDStr).select();
         getRef(IDStr).focus();
      }

      if (saveForDisabledIDStr != "")
      {
         getRef(saveForDisabledIDStr).value = getRef(IDStr).value;
      }
   }
   checkEmpytField=true;
}

function saveLoadData(form)
{

   if (form.cbScheduleLoan.checked == false)
   {
      form.saveScheduleLoan.value="False";
   }
   if (form.cbScheduleLoan.checked == true)
   {
      form.saveScheduleLoan.value="True";
   }

   if (form.cbBlackout.checked == false)
   {
      form.saveBlackout.value="False";
   }
   if (form.cbBlackout.checked == true)
   {
      form.saveBlackout.value="True";
   }
}

function goToLocation(pathName)
{
   if (pathName != "")
   {
      location=pathName;
   }
   else
   {
      alert("Can't find link infomation!");
   }
}

function openNewWindow(pathName)
{
   if (pathName != "")
   {
      window.open(pathName);
   }
   else
   {
      alert("Can't find link infomation!");
   }
}

/*
function clearData(totalYears,totalCols,objectName)
{
   var startIndex=0;
   var endIndex=totalYears*totalCols-1;

   while (startIndex <= endIndex)
   {
      objectName[startIndex].value=0;
      startIndex++;
   }
}
*/
function clearData(totalYears,totalCols,objectName,textCols)
{
   var startIndex=0;
   var endIndex=totalYears*totalCols-1;
   var colNum=0;

   while (startIndex <= endIndex)
   {
      colNum=startIndex%totalCols;
      if (textCols.indexOf(colNum) > -1)
      {
         objectName[startIndex].value="";
      }
      else
      {
         objectName[startIndex].value=0;
      }
      startIndex++;
   }
}

function selectedRadioButton(radioButton)
{
   var len = radioButton.length;
   var i=0;

   if (len == null)
   {
      return radioButton;
   }
   else
   {
      for(i=0 ; i<len ; i++)
      {
         if (radioButton[i].checked == true)
         {
            return radioButton[i];
         }
      }
   }
}

function changeLevelData(levelAmount,totalCols,allYear,startYear,endYear,totalYears,itemObject,radioButton)
{
   var startIndex=(startYear-1)*totalCols;
   var endIndex=(endYear*totalCols)-1;

   var colNum = selectedRadioButton(radioButton).value;

   if (allYear)
   {
      startIndex=0;
      endIndex=totalYears*totalCols-1;
   }

   while (startIndex <= endIndex)
   {
      if ((startIndex%totalCols) == colNum)
      {
         itemObject[startIndex].value=levelAmount;
         itemObject[startIndex].onblur();
      }
      startIndex++;
   }
}

function refresh()
{
  location.reload();
}

function changeCursor(IDStr,cursorType)
{
   if ((cursorType == "hand") && isNS)
   {
      getSty(IDStr).cursor = "pointer";
   }
   else if ((cursorType == "pointer") && isIE)
   {
      getSty(IDStr).cursor = "hand";
   }
   else
   {
      getSty(IDStr).cursor=cursorType;
   }
}

function changeFontColor(IDStr,Color)
{
   getSty(IDStr).color=Color;
}

function changeBG(IDStr,bgColor)
{
   getSty(IDStr).background=bgColor;
}

function changeColor(IDStr,bgColor,fontColor)
{
   if (bgColor != "")
   {
      getSty(IDStr).background=bgColor;
   }
   if (fontColor!= "")
   {
      getSty(IDStr).color=fontColor;
   }
}

function setFocus(IDStr)
{
   if (getRef(IDStr) != null)
   {
      getRef(IDStr).select();
      getRef(IDStr).focus();
   }
}

function CheckNumberOfChar(IDStr,NumCharRequired)
{

   if ( (IDStr != "") && (getRef(IDStr) != null) )
   {
      var inputStr = getRef(IDStr).value;

      if (inputStr.length < NumCharRequired)
      {
         alert("This field must be at least "+NumCharRequired+" characters.");
         getRef(IDStr).select();
         getRef(IDStr).focus();
         return 0;
      }
      return inputStr.length;
   }
}

function selectRadioButtonVsCol(radioButton,index,totalCols)
{
   var colNum=index%totalCols;

   radioButton[colNum].checked=true;
}

function selectRadioButtonVsID(IDStr)
{
   getRef(IDStr).checked = true;
}

function openwindow(pathName)
{
   window.open(pathName,"new_window","toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no");
}

function openRequestForm(pathName)
{
   window.open(pathName,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=700,height=510");
}

function openwindowFull(pathName)
{
   w_height=screen.availheight-105;
   w_width=screen.availwidth-5;
   window.open(pathName,"new_window","toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,left=0,top=0,height=" + w_height + ",width=" + w_width);
}

function openwindowPDF(pathName,IDStr1,IDStr2,IDStr3)
{
   if (getRef(IDStr1) != null)
   {
      pathName = pathName + "&LIType=" + getRef(IDStr1).value;
   }

   if (getRef(IDStr2) != null)
   {
      pathName = pathName + "&FileType=" + getRef(IDStr2).value;
   }

   if (getRef(IDStr3) != null)
   {
      if (getRef(IDStr3).checked)
      {
         pathName = pathName + "&Highlight=on";
      }
      else
      {
         pathName = pathName + "&Highlight=off";
      }
   }

   window.open(pathName,"new_window","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no");
}

function openNewWindowPDF(pathName,IDStr1,IDStr2,IDStr3)
{
   var openNewWindow = true;

   if (getRef(IDStr1) != null)
   {
      pathName = pathName + "&LIType=" + getRef(IDStr1).value;
   }

   if (getRef(IDStr2) != null)
   {
      pathName = pathName + "&FileType=" + getRef(IDStr2).value;
   }

   if (getRef(IDStr3) != null)
   {
      if (getRef(IDStr3).checked)
      {
         pathName = pathName + "&Highlight=on";
      }
      else
      {
         pathName = pathName + "&Highlight=off";
      }
   }

   if (getRef(IDStr2) != null)
   {
     if (getRef(IDStr2).value == "Export")
     {
         var returnValue = confirm("                     * * *  IMPORTANT MESSAGE  * * *" + '\n' + '\n' +
                                   "Any editing of the copied document that involves any legal or tax " + '\n' +
                                   "issue or consequence must only be done by qualified legal or tax " + '\n' +
                                   "counsel.  The party licensed to use the System is responsible for " + '\n' +
                                   "presenting the material only in suitable situations.")
         if (returnValue == false)
         {
            openNewWindow = false;
         }
     }
   }

   if (openNewWindow == true)
   {
      if (getRef(IDStr2).value == "Export")
      {
         goToLocation(pathName);
      }
      else
      {
         window.open(pathName,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no");
      }
   }
}

function PreviewAndRequestDocs(pathName,IDStr1,IDStr2,IDStr3,requestedDoc)
{
   var returnValue = false;
   var tempStr = "";
   var tempStr2 = "";
   var fileName = "";
   var fileValue = 0;

   tempStr2 = pathName;

   if (requestedDoc)
   {
      if ( (tempStr2.indexOf("LIType=Fixed") == -1) &&
           (tempStr2.indexOf("LIType=Flexible") == -1) &&
           (getRef(IDStr1) != null) )
      {
         tempStr2 = tempStr2 + "&LIType=" + getRef(IDStr1).value;
      }

      if (tempStr2.indexOf("LIType=Fixed") > -1)
      {
         tempStr = tempStr2.substr(0,tempStr2.indexOf("Fixed="));
         tempStr2 = tempStr2.replace(tempStr+"Fixed=","");

         fileName = tempStr2;
         if (tempStr2.indexOf("&") > -1)
         {
            fileName = tempStr2.substr(0,tempStr2.indexOf("&"));
         }
      }
      else if (tempStr2.indexOf("LIType=Flexible") > -1)
      {
         tempStr = tempStr2.substr(0,tempStr2.indexOf("Flexible="));
         tempStr2 = tempStr2.replace(tempStr+"Flexible=","");

         fileName = tempStr2;
         if (tempStr2.indexOf("&") > -1)
         {
            fileName = tempStr2.substr(0,tempStr2.indexOf("&"));
         }
      }

      fileName = fileName.toUpperCase();

      if (fileName.indexOf(".PDF") == -1)
      {
         if ( (fileName != 'SPECDOCA') &&
              (fileName != 'SPECDOCP') &&
              (fileName != 'INSMENUW') &&
              (fileName != 'TAM')      &&
              (fileName != 'MORE83B')  &&
              (fileName != 'IRSNOTB')  &&
              (fileName != 'SEC83B')   &&
              (fileName != 'RATES')    &&
              (fileName != 'IRSTBLEB') &&
              (fileName != 'MULT83B') )

         {
            returnValue = confirm("                     * * *  Request Documents  * * *" + '\n' + '\n' +
                                  "If you would like a copy of the specific set of specimen documents" + '\n' +
                                  "that accompany this Highlights Of The Plan, click the OK button," + '\n' +
                                  "otherwise, click the CANCEL button to preview the document.");
         }
      }
   }

   if (returnValue == false)
   {
      openNewWindowPDF(pathName,IDStr1,IDStr2,IDStr3);
   }
   else
   {
      if (getRef(IDStr1) != null)
      {
         pathName = pathName + "&LIType=" + getRef(IDStr1).value;
      }

      /*
      if (getRef(IDStr2) != null)
      {
         pathName = pathName + "&FileType=" + getRef(IDStr2).value;
      }

      if (getRef(IDStr3) != null)
      {
         if (getRef(IDStr3).checked)
         {
            pathName = pathName + "&Highlight=on";
         }
         else
         {
            pathName = pathName + "&Highlight=off";
         }
      }
      */

      tempStr = pathName.substr(0,pathName.indexOf("?")+1);
      pathName = pathName.replace(tempStr,"");
      tempStr = tempStr.substr(0,tempStr.lastIndexOf("/"));

      pathName = tempStr+"/RequestDocs?"+pathName;

      window.open(pathName,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=700,height=510");
   }
}

function printpage()
{
   // window.print();

   if (window.print)
   {
      window.print() ;
   }
   else
   {
      var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
      document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
      WebBrowser1.ExecWB(6, 2);  //Use a 1 vs. a 2 for a prompting dialog box
      WebBrowser1.outerHTML = "";
   }
}

function setClickOnCheckBox()
{
   clickOnCheckBox = true;
}

function hL(IDStr)
{
   if (getRef(IDStr) != null)
   {
      getRef(IDStr).className="HightLight";
   }
}

function dL(IDStr)
{
   if (getRef(IDStr) != null)
   {
      getRef(IDStr).className="";
   }
}

function selectRow(CheckBoxAllIDStr,CheckBoxIDPrefix,RowIDPrefix,selectedRowBGColor,startIndex,endIndex)
{
   var i=0;
   var count=0;
   var totalChecked=0;
   var CheckBoxIDStr = "";
   var RowIDStr = "";

   for(i=startIndex; i<=endIndex; i++)
   {
      CheckBoxIDStr = CheckBoxIDPrefix+i;
      RowIDStr = RowIDPrefix+i;

      count++;

      if (getRef(CheckBoxIDStr) != null)
      {
         if (getRef(CheckBoxIDStr).checked)
         {
            if (getRef(RowIDStr) != null)
            {
               getSty(RowIDStr).background=selectedRowBGColor;
               getSty(RowIDStr).color='#ffffff';
            }

            totalChecked++;
         }
         else
         {
            if (getRef(RowIDStr) != null)
            {
               getSty(RowIDStr).background='#ffffff';
               getSty(RowIDStr).color='#000000';
            }
         }
      }
   }

   if (getRef(CheckBoxAllIDStr) != null)
   {
      getRef(CheckBoxAllIDStr).checked=(count==totalChecked)?true:false;
   }
}

function selectRowAll(CheckBoxAllIDStr,CheckBoxIDPrefix,RowIDPrefix,selectedRowBGColor,startIndex,endIndex)
{
   var i=0;
   var CheckBoxIDStr = "";
   var SelectedAll = false;

   var RowIDStr = "";
   var tempNum = "";

   if (getRef(CheckBoxAllIDStr) != null)
   {
      SelectedAll = getRef(CheckBoxAllIDStr).checked;

      for(i=startIndex; i<=endIndex; i++)
      {
         RowIDStr = RowIDPrefix+i;
         CheckBoxIDStr = CheckBoxIDPrefix+i;

         if (getRef(RowIDStr) != null)
         {
            if (SelectedAll)
            {
               getSty(RowIDStr).background=selectedRowBGColor;
               getSty(RowIDStr).color='#ffffff';
            }
            else
            {
               getSty(RowIDStr).background='#ffffff';
               getSty(RowIDStr).color='#000000';
            }
         }

         if (getRef(CheckBoxIDStr) != null)
         {
            getRef(CheckBoxIDStr).checked = SelectedAll;
         }
      }
   }
}

function selectRowSingle(RowsNum,RowIDPrefix,selectedRowBGColor,startIndex,endIndex)
{
   var i=0;
   var RowIDStr = "";
   var tempNum = "";
   var backgroundColor = "";
   var tempRowsNum=RowsNum;

   if (clickOnCheckBox == false)
   {
      for(i=startIndex; i<=endIndex; i++)
      {
         RowIDStr = RowIDPrefix+i;
         if (getRef(RowIDStr) != null)
         {
            getSty(RowIDStr).background='#ffffff';
            getSty(RowIDStr).color='#000000';
         }
      }

      RowIDStr = RowIDPrefix+RowsNum;

      if (getRef(RowIDStr) != null)
      {
         getSty(RowIDStr).background=selectedRowBGColor;
         getSty(RowIDStr).color='#ffffff';
      }
   }

/*
   if (clickOnCheckBox == false)
   {
      for(i=startIndex; i<=endIndex; i++)
      {
         if (i != RowsNum)
         {
            RowIDStr = RowIDPrefix+i;
            getSty(RowIDStr).background='#ffffff';
            getSty(RowIDStr).color='#000000';
         }
      }

      RowIDStr = RowIDPrefix+RowsNum;

      backgroundColor = getSty(RowIDStr).background;
      if (backgroundColor.indexOf(selectedRowBGColor) > -1)
      {
         getSty(RowIDStr).background='#ffffff';
         getSty(RowIDStr).color='#000000';
      }
      else
      {
         getSty(RowIDStr).background=selectedRowBGColor;
         getSty(RowIDStr).color='#ffffff';
      }
   }
*/
   clickOnCheckBox = false;
}

function selectRowMultiple(RowsNum,RowIDPrefix,selectedRowBGColor,startIndex,endIndex)
{
   var i=0;
   var RowIDStr = "";
   var tempNum = "";
   var backgroundColor = "";
   var tempRowsNum=RowsNum;

   if (clickOnCheckBox == false)
   {
      while (tempRowsNum.length > 0)
      {
         tempNum = tempRowsNum.substr(0,tempRowsNum.indexOf(","));

         if (tempNum == "")
         {
            tempNum=tempRowsNum;
         }

         if (tempNum != "")
         {
            RowIDStr = RowIDPrefix + tempNum;
            backgroundColor = getSty(RowIDStr).background;
            if (backgroundColor.indexOf(selectedRowBGColor) > -1)
            {
               getSty(RowIDStr).background='#ffffff';
               getSty(RowIDStr).color='#000000';
            }
            else
            {
               getSty(RowIDStr).background=selectedRowBGColor;
               getSty(RowIDStr).color='#ffffff';
            }

            tempRowsNum=tempRowsNum.replace(tempNum,"");
            tempRowsNum=tempRowsNum.replace(",","");
         }
      }
   }

   clickOnCheckBox = false;
}

function checkInputRequiredFields(fieldsToCheck,checkField)
{
   validInputData = true;

   var fieldID = "";
   var tempFieldsToCheck=fieldsToCheck;
   var fieldValue = "";

   while (tempFieldsToCheck.length > 0)
   {
      fieldID = tempFieldsToCheck.substr(0,tempFieldsToCheck.indexOf(","));

      if (fieldID == "")
      {
         fieldID=tempFieldsToCheck;
      }

      if (fieldID != "")
      {
         if ( (lastErrorIDStr == "") || (lastErrorIDStr == fieldID) )
         {
            fieldValue = getRef(fieldID);

            if (fieldValue != null)
            {
               fieldValue = fieldValue.value;
               if (fieldValue.length == 0)
               {
                  if (checkField)
                  {
                     validInputData = false;
                     lastErrorIDStr = fieldID;

                     alert("A value is required in this field.");
                     getRef(fieldID).select();
                     getRef(fieldID).focus();
                  }

                  return -1;
               }
               else
               {
                 lastErrorIDStr = "";
               }
            }
         }

         tempFieldsToCheck=tempFieldsToCheck.replace(fieldID,"");
         tempFieldsToCheck=tempFieldsToCheck.replace(",","");
      }
   }

   lastErrorIDStr = "";
   return 0;
}

function checkInputRequiredFieldsForSchedule(totalYears,totalCols,objectName,ColToCheck,InputRequiredCols)
/*
   InputRequiredCols is the group of number before or next to the ColToCheck.
   For example, if ColToCheck column number is 1, you want to check input
   required column 4, the InputRequiredCols is equal 4-1=3, and you want
   to check input required column 0, the InputRequiredCols is equal 0-1=-1.
*/
{
   validInputData = true;

   var IRColNum = 0;
   var IRColNumStr = "";
   var tempInputRequiredCols = "";
   var fieldValue = "";
   var fieldValueInt = 0;
   var IRColFieldValue = "";

   var startIndex = 0;
   var endIndex = totalYears*totalCols-1;
   var colNum = 0;

   var tempIndex = 0;

   if (InputRequiredCols.length > 0)
   {
      while (startIndex <= endIndex)
      {
         colNum=startIndex%totalCols;
         fieldValue = objectName[startIndex].value;
         fieldValueInt = parseInt(fieldValue);
         tempInputRequiredCols = InputRequiredCols;

         if ( (colNum == ColToCheck) && (fieldValueInt > 0) )
         {
            while (tempInputRequiredCols.length > 0)
            {
               IRColNumStr = tempInputRequiredCols.substr(0,tempInputRequiredCols.indexOf(","));

               if (IRColNumStr == "")
               {
                  IRColNumStr=tempInputRequiredCols;
               }

               if (IRColNumStr != "")
               {
                  IRColNum = parseInt(IRColNumStr);
                  tempIndex = startIndex+IRColNum;
                  if ( (lastErrorIDStr == "") || (lastErrorIDStr == objectName[tempIndex].id) )
                  {
                     IRColFieldValue = objectName[tempIndex].value;

                     if (IRColFieldValue.length == 0)
                     {
                        validInputData = false;
                        lastErrorIDStr = objectName[tempIndex].id;

                        alert("A value is required in this field.");
                        objectName[tempIndex].select();
                        objectName[tempIndex].focus();

                        return -1;
                     }
                     else
                     {
                        lastErrorIDStr == "";
                     }
                  }

                  tempInputRequiredCols=tempInputRequiredCols.replace(IRColNumStr,"");
                  tempInputRequiredCols=tempInputRequiredCols.replace(",","");
               }
            }
         }

         startIndex++;
      }
   }

   lastErrorIDStr = "";
   return 0;
}

function gotoInputRequiredField(fieldsToCheck,checkField,displayErrorMsg)
{
   var fieldID = "";
   var tempFieldsToCheck=fieldsToCheck;
   var fieldValue = "";

   while (tempFieldsToCheck.length > 0)
   {
      fieldID = tempFieldsToCheck.substr(0,tempFieldsToCheck.indexOf(","));

      if (fieldID == "")
      {
         fieldID=tempFieldsToCheck;
      }

      if (fieldID != "")
      {
         fieldValue = getRef(fieldID);

         if (fieldValue != null)
         {
            fieldValue = fieldValue.value;

            if (fieldValue.length == 0)
            {
               if (checkField)
               {
                  if (displayErrorMsg)
                  {
                     alert("A value is required in this field.");
                  }

                  getRef(fieldID).select();
                  getRef(fieldID).focus();

                  return -1;
               }
            }
         }
         tempFieldsToCheck=tempFieldsToCheck.replace(fieldID,"");
         tempFieldsToCheck=tempFieldsToCheck.replace(",","");
      }
   }

   return 0;
}

function numOfRowsSelected(RowIDPrefix,selectedRowBGColor,startIndex,endIndex)
{
   var i=0;
   var count=0;
   var RowIDStr = "";
   var backgroundColor = "";

   for(i=startIndex; i<=endIndex; i++)
   {
      RowIDStr = RowIDPrefix+i;
      backgroundColor = getSty(RowIDStr).background;
      if (backgroundColor.indexOf(selectedRowBGColor) > -1)
      {
         count++;
      }
   }
   return count;
}

function getSelectedCaseLink(RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex)
{
   var i=0;
   var anchorIDStr = "";
   var RowIDStr = "";
   var backgroundColor = "";

   for(i=startIndex; i<=endIndex; i++)
   {
      RowIDStr = RowIDPrefix+i;
      backgroundColor = getSty(RowIDStr).background;
      if (backgroundColor.indexOf(selectedRowBGColor) > -1)
      {
         anchorIDStr = anchorPrefix+i;
         return getRef(anchorIDStr).href;
      }
   }
}

function editCase(RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex)
{
   var linkStr = "";
   var count = numOfRowsSelected(RowIDPrefix,selectedRowBGColor,startIndex,endIndex);

   if (count <= 0)
   {
      alert("No Case selected!");
   }
   else if (count > 1)
   {
      alert("Please select only one Case!");
   }
   else
   {
      linkStr = getSelectedCaseLink(RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex);
      goToLocation(linkStr);
   }
}

function PreviewCase(RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex,ScriptsVirtualDir)
{
   var ModulePath = "";
   var linkStr = "";
   var count = numOfRowsSelected(RowIDPrefix,selectedRowBGColor,startIndex,endIndex);

   if (count <= 0)
   {
      alert("No Case selected!");
   }
   else if (count > 1)
   {
      alert("Please select only one Case!");
   }
   else
   {
      linkStr = getSelectedCaseLink(RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex);

      var tempStr = linkStr.substr(0,linkStr.indexOf("?")+1);

      linkStr = linkStr.replace(tempStr,"");

      var tempStr2 = linkStr;
      tempStr = tempStr.substr(0,tempStr2.indexOf("WhichProc="));
      tempStr2 = tempStr2.replace(tempStr,"");
      var tempModuleNum = parseInt(tempStr2);

      if (tempModuleNum = 187)
      {
         ModulePath = "A7872CGI.exe/LoanHistoryReport?"
      }

      linkStr = ScriptsVirtualDir + ModulePath + linkStr + "&PageNum=1&PageNumber=1";
      openwindowFull(linkStr);
   }
}

function getSelectedCaseDescription(RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex)
{
   var i=0;
   var anchorIDStr = "";
   var RowIDStr = "";
   var backgroundColor = "";

   for(i=startIndex; i<=endIndex; i++)
   {
      RowIDStr = RowIDPrefix+i;
      backgroundColor = getSty(RowIDStr).background;
      if (backgroundColor.indexOf(selectedRowBGColor) > -1)
      {
         anchorIDStr = anchorPrefix+i;
         return getRef(anchorIDStr).name;
      }
   }
}

function getSelectedCases2(RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex)
{
   var i = 0;
   var WhichProcPos = 0;
   var PropNumberPos = 0;

   var RowIDStr = "";
   var anchorIDStr = "";
   var tempCaseInfo = "";
   var selectedCases = "";
   var selectedCasesNum = "";
   var tempCaseNum = -1;
   var selectedModulesNum = "";
   var tempModuleNum = -1;
   var tempStr = "";
   var tempStr2 = '';
   var tempStr3 = '';
   var backgroundColor = "";

   for(i=startIndex; i<=endIndex; i++)
   {
      tempCaseInfo = "";
      RowIDStr = RowIDPrefix+i;

      backgroundColor = "";
      if (getRef(RowIDStr) != null)
      {
         backgroundColor = getSty(RowIDStr).background;
      }

      if (backgroundColor.indexOf(selectedRowBGColor) > -1)
      {
         anchorIDStr = anchorPrefix+i;
         if (selectedCasesNum != "")
         {
            selectedCasesNum = selectedCasesNum + ",";
         }

         if (selectedModulesNum != "")
         {
            selectedModulesNum = selectedModulesNum + ",";
         }

         tempCaseInfo = "";
         if (getRef(anchorIDStr) != null)
         {
            tempCaseInfo = getRef(anchorIDStr).href;
         }

         WhichProcPos = tempCaseInfo.indexOf("WhichProc=");
         PropNumberPos = tempCaseInfo.indexOf("PropNumber=");

         if (WhichProcPos < PropNumberPos)
         {
            tempStr2 = "WhichProc=";
            tempStr3 = "PropNumber=";
         }
         else
         {
            tempStr2 = "PropNumber=";
            tempStr3 = "WhichProc=";
         }

         tempStr = tempCaseInfo.substr(0,tempCaseInfo.indexOf(tempStr2));
         tempCaseInfo = tempCaseInfo.replace(tempStr,"");
         tempCaseInfo = tempCaseInfo.replace(tempStr2,"");

         if (tempStr2 == "WhichProc=")
         {
            tempModuleNum = parseInt(tempCaseInfo);
         }
         else
         {
            tempCaseNum = parseInt(tempCaseInfo);
         }

         tempStr = tempCaseInfo.substr(0,tempCaseInfo.indexOf(tempStr3));
         tempCaseInfo = tempCaseInfo.replace(tempStr,"");
         tempCaseInfo = tempCaseInfo.replace(tempStr3,"");

         if (tempStr3 == "WhichProc=")
         {
            tempModuleNum = parseInt(tempCaseInfo);
         }
         else
         {
            tempCaseNum = parseInt(tempCaseInfo);
         }

         selectedModulesNum = selectedModulesNum + tempModuleNum;
         selectedCasesNum = selectedCasesNum + tempCaseNum;
      }
   }

   selectedCases = "LUProc=" + selectedModulesNum + "&LUPNum=" + selectedCasesNum;
   return selectedCases;
}

function getSelectedCases(RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex)
{
   var i = 0;
   var WhichProcPos = 0;
   var PropNumberPos = 0;

   var RowIDStr = "";
   var anchorIDStr = "";
   var tempCaseInfo = "";
   var selectedCases = "";
   var selectedCasesNum = "";
   var tempCaseNum = -1;
   var selectedModulesNum = "";
   var tempModuleNum = -1;
   var tempStr = "";
   var tempStr2 = '';
   var tempStr3 = '';
   var backgroundColor = "";

   for(i=startIndex; i<=endIndex; i++)
   {
      tempCaseInfo = "";
      RowIDStr = RowIDPrefix+i;

      backgroundColor = getSty(RowIDStr).background;
      if (backgroundColor.indexOf(selectedRowBGColor) > -1)
      {
         anchorIDStr = anchorPrefix+i;
         if (selectedCasesNum != "")
         {
            selectedCasesNum = selectedCasesNum + ",";
         }

         if (selectedModulesNum != "")
         {
            selectedModulesNum = selectedModulesNum + ",";
         }

         tempCaseInfo = getRef(anchorIDStr).href;

         WhichProcPos = tempCaseInfo.indexOf("WhichProc=");
         PropNumberPos = tempCaseInfo.indexOf("PropNumber=");

         if (WhichProcPos < PropNumberPos)
         {
            tempStr2 = "WhichProc=";
            tempStr3 = "PropNumber=";
         }
         else
         {
            tempStr2 = "PropNumber=";
            tempStr3 = "WhichProc=";
         }

         tempStr = tempCaseInfo.substr(0,tempCaseInfo.indexOf(tempStr2));
         tempCaseInfo = tempCaseInfo.replace(tempStr,"");
         tempCaseInfo = tempCaseInfo.replace(tempStr2,"");

         if (tempStr2 == "WhichProc=")
         {
            tempModuleNum = parseInt(tempCaseInfo);
         }
         else
         {
            tempCaseNum = parseInt(tempCaseInfo);
         }

         tempStr = tempCaseInfo.substr(0,tempCaseInfo.indexOf(tempStr3));
         tempCaseInfo = tempCaseInfo.replace(tempStr,"");
         tempCaseInfo = tempCaseInfo.replace(tempStr3,"");

         if (tempStr3 == "WhichProc=")
         {
            tempModuleNum = parseInt(tempCaseInfo);
         }
         else
         {
            tempCaseNum = parseInt(tempCaseInfo);
         }

         selectedModulesNum = selectedModulesNum + tempModuleNum;
         selectedCasesNum = selectedCasesNum + tempCaseNum;
      }
   }

   selectedCases = "WhichProc=" + selectedModulesNum + "&PropNumber=" + selectedCasesNum;
   return selectedCases;
}

function confirmationDeleteCase(RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex,pathName)
{
   var i=0;
   var RowIDStr = "";
   var linkStr = "";
   var CaseDescription = "";
   var count = numOfRowsSelected(RowIDPrefix,selectedRowBGColor,startIndex,endIndex);

   if (count <= 0)
   {
      alert("No Case selected!");
   }
   else
   {
      if (count > 1)
      {
         CaseDescription = "selected Cases?";
      }
      else
      {
         CaseDescription = "Case " + getSelectedCaseDescription(RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex)+"?";
      }

      var okToDelete = confirm("Do you really want to delete "+CaseDescription);

      if (okToDelete == true)
      {
         linkStr = pathName + getSelectedCases(RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex);
         goToLocation(linkStr);
      }
   }
}

function getSelectedCaseInfo(RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex)
{
   var i=0;
   var anchorIDStr = "";
   var RowIDStr = "";
   var backgroundColor = "";
   var tempCaseInfo = "";
   var tempStr = "";

   for(i=startIndex; i<=endIndex; i++)
   {
      RowIDStr = RowIDPrefix+i;
      backgroundColor = getSty(RowIDStr).background;
      if (backgroundColor.indexOf(selectedRowBGColor) > -1)
      {
         anchorIDStr = anchorPrefix+i;
         tempCaseInfo = getRef(anchorIDStr).href;

         tempStr = tempCaseInfo.substr(0,tempCaseInfo.indexOf("?"));
         tempCaseInfo = tempCaseInfo.replace(tempStr,"");
         tempCaseInfo = tempCaseInfo.replace("?","");
         return tempCaseInfo;
      }
   }
}

function CopyCase(RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex,pathName)
{
   var linkStr = "";
   var count = numOfRowsSelected(RowIDPrefix,selectedRowBGColor,startIndex,endIndex);

   if (count <= 0)
   {
      alert("No Case selected!");
   }
   else if (count > 1)
   {
      alert("Please select only one Case!");
   }
   else
   {
      linkStr = pathName + getSelectedCaseInfo(RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex);
      goToLocation(linkStr);
   }
}

function getSelectedModuleLink(radioPrefix,startIndex,endIndex)
{
   var i=0;
   var radioIDStr = "";

   for(i=startIndex; i<=endIndex; i++)
   {
      radioIDStr = radioPrefix+i;

      if (getRef(radioIDStr).checked == true)
      {
         return getRef(radioIDStr).value;
      }
   }
}

function createNewCase(radioPrefix,startIndex,endIndex,formObject)
{
   var linkStr = getSelectedModuleLink(radioPrefix,startIndex,endIndex);

   formSubmit(linkStr,formObject);
}

function startTimeout()
{
	setTimeout("changeFontColor('clientWBCell','#0000ff')", 1000);
}

function checkSignInName(IDStr)
{
   var validChar = false;
   var tempStr = "";

   checkEmpytField = false;

   var str = getRef(IDStr).value;

   var inputCharPos = posOfInputChar(InputText,str);

   if (str.length >= 1)
   {
      if ( ((str.charCodeAt(inputCharPos) >= 48) &&      //0-9
            (str.charCodeAt(inputCharPos) <= 57)) ||
           ((str.charCodeAt(inputCharPos) >= 65) &&      //A-Z
            (str.charCodeAt(inputCharPos) <= 90)) ||
           ((str.charCodeAt(inputCharPos) >= 97) &&      //a-z
            (str.charCodeAt(inputCharPos) <= 122)) ||
           (str.charCodeAt(inputCharPos) == 95) )        //_
      {
         validChar = true;
      }

      if (validChar == false)
      {
         tempStr = str.substring(0,inputCharPos);
         tempStr = tempStr + str.substring(inputCharPos+1,str.length);
         getRef(IDStr).value = tempStr;
         alert("Invalid input");
         getRef(IDStr).select();
         getRef(IDStr).focus();
      }
   }
   checkEmpytField=true;
}

function ValidateFields(fieldsID,fieldsDescption)
{
   var tmpfieldsID=fieldsID;
   var IDStr="";
   var fieldDescp="";

   while (tmpfieldsID.length > 0)
   {
      IDStr = tmpfieldsID.substr(0,tmpfieldsID.indexOf(","));
      fieldDescp = fieldsDescption.substr(0,fieldsDescption.indexOf(","));

      if (IDStr == "")
      {
         IDStr=tmpfieldsID;
         fieldDescp=fieldsDescption;
      }

      if (IDStr != "")
      {
         if (getRef(IDStr).value == "")
         {
            alert("The "+fieldDescp+" you entered was empty.");
            getRef(IDStr).select();
            getRef(IDStr).focus();

            return -1;
         }

         tmpfieldsID=tmpfieldsID.replace(IDStr,"");
         tmpfieldsID=tmpfieldsID.replace(",","");

         fieldsDescption=fieldsDescption.replace(fieldDescp,"");
         fieldsDescption=fieldsDescption.replace(",","");
      }
   }

   return 0;
}

function isValidForm(sinID,pwdID,fnID,lnID,saID,bMonthID,bDayID,bYearID,zipcodeID,sexID,extID)
{
   var signInName = "";
   var password = "";
   var firstName = "";
   var lastName = "";
   var securityAnswer = "";
   var birthYear = "";
   var zipCode = "";
   var checkMonth = false;
   var monthIndex = 0;
   var checkDay = false;
   var dayIndex = 0;
   var checkYear = false;
   var checkSex = false;
   var sexIndex = 0;
   var companyExt = "";

   if ( getRef(sexID) != null)
   {
      checkSex = true;
      sexIndex = getRef(sexID).selectedIndex;
   }

   if ( getRef(bMonthID) != null)
   {
      checkMonth = true;
      monthIndex = getRef(bMonthID).selectedIndex;
   }

   if ( getRef(bDayID) != null)
   {
      checkDay = true;
      dayIndex = getRef(bDayID).selectedIndex;
   }

   if ( (sinID != "") && (getRef(sinID) != null) )
   {
      signInName = getRef(sinID).value;
   }
   if ( (pwdID != "") && (getRef(pwdID) != null) )
   {
      password = getRef(pwdID).value;
   }
   if ( (fnID != "") && (getRef(fnID) != null) )
   {
      firstName = getRef(fnID).value;
   }
   if ( (lnID != "") && (getRef(lnID) != null) )
   {
      lastName = getRef(lnID).value;
   }
   if ( (saID != "") && (getRef(saID) != null) )
   {
      securityAnswer = getRef(saID).value;
   }
   if ( (bYearID != "") && (getRef(bYearID) != null) )
   {
      checkYear = true;
      birthYear = getRef(bYearID).value;
   }
   if ( (zipcodeID != "") && (getRef(zipcodeID) != null) )
   {
      zipCode = getRef(zipcodeID).value;
   }
   if ( (extID != "") && (getRef(extID) != null) )
   {
      companyExt = getRef(extID).value;
   }

   if ( (signInName.length == 0) && (sinID != "") && (getRef(sinID) != null) )
   {
      alert("The Sign-In Name you entered was empty.");
      getRef(sinID).select();
      getRef(sinID).focus();

      return -1;
   }
   else if ( (password.length == 0) && (pwdID != "") && (getRef(pwdID) != null) )
   {
      alert("The new password you entered was empty.");
      getRef(pwdID).select();
      getRef(pwdID).focus();

      return -1;
   }
   else if ( (password.length > 32) && (pwdID != "") && (getRef(pwdID) != null) )
   {
      alert("Your new password must be no greater than 32 characters.");
      getRef(pwdID).select();
      getRef(pwdID).focus();

      return -1;
   }
   else if ( (password.length < 6) && (pwdID != "") && (getRef(pwdID) != null) )
   {
      alert("Your new password must be at least 6 characters.");
      getRef(pwdID).select();
      getRef(pwdID).focus();

      return  -1;
   }
   else if ( (signInName.length != 0) &&
             (getRef(pwdID) != null) &&
             (getRef(sinID) != null) &&
             (sinID != "") &&
             (pwdID != "") &&
             (signInName.indexOf(password) >= 0 || password.indexOf(signInName) >= 0) )
   {
      alert("Your new password is too similar to your Sign-In Name.");
      getRef(pwdID).select();
      getRef(pwdID).focus();

      return -1;
   }
   else if ( (firstName.length > 2) &&
             (getRef(fnID) != null) &&
             (getRef(pwdID) != null) &&
             (fnID != "") &&
             (pwdID != "") &&
             (password.indexOf(firstName) >= 0) )
   {
      alert("Your new password is too similar to your first or last name.");
      getRef(pwdID).select();
      getRef(pwdID).focus();

      return -1;
   }
   else if ( (lastName.length > 2) &&
             (getRef(lnID) != null) &&
             (getRef(pwdID) != null) &&
             (lnID != "") &&
             (pwdID != "") &&
             (password.indexOf(lastName) >=0) )
   {
      alert("Your new password is too similar to your first or last name.");
      getRef(pwdID).select();
      getRef(pwdID).focus();

      return -1;
   }
   else if ( (securityAnswer.length == 0) && (saID != "") && (getRef(saID) != null) )
   {
      alert("The security answer you entered was empty.");
      getRef(saID).select();
      getRef(saID).focus();

      return -1;
   }
   else if ( (checkMonth) && (monthIndex == 0) && (bMonthID != "") )
   {
      alert("The month of birthday you entered was empty.");
      getRef(bMonthID).select();
      getRef(bMonthID).focus();

      return -1;
   }
   else if ( (checkDay) && (dayIndex == 0) && (bDayID != "") )
   {
      alert("The day of birthday you entered was empty.");
      getRef(bDayID).select();
      getRef(bDayID).focus();

      return -1;
   }
   else if ( (checkYear) && (birthYear.length == 0) && (bYearID != "") )
   {
      alert("The year of birthday you entered was empty.");
      getRef(bYearID).select();
      getRef(bYearID).focus();

      return -1;
   }
   else if ( (zipCode.length == 0) && (zipcodeID != "") && (getRef(zipcodeID) != null) )
   {
      alert("The zip/postal code you entered was empty.");
      getRef(zipcodeID).select();
      getRef(zipcodeID).focus();

      return -1;
   }
   else if ( (firstName.length == 0) && (fnID != "") && (getRef(fnID) != null) )
   {
      alert("The first name you entered was empty.");
      getRef(fnID).select();
      getRef(fnID).focus();

      return -1;
   }
   else if ( (lastName.length == 0) && (lnID != "") && (getRef(lnID) != null) )
   {
      alert("The last name you entered was empty.");
      getRef(lnID).select();
      getRef(lnID).focus();

      return -1;
   }
   else if ( (companyExt.length == 0) && (extID != "") && (getRef(extID) != null) )
   {
      alert("The Company 3 Letters Code you entered was empty.");
      getRef(extID).select();
      getRef(extID).focus();

      return -1;
   }
   else if ( (checkSex) && (sexIndex == 0) && (sexID != "") )
   {
      alert("The gender you entered was empty.");
      getRef(sexID).select();
      getRef(sexID).focus();

      return -1;
   }
   else
   {
      if ( checkMonth && checkDay && checkYear && (bMonthID !="") && (bDayID !="") && (birthYear !="") )
      {
         var bDay = getRef(bDayID).options[getRef(bDayID).selectedIndex].text;
         var birthDay = getRef(bMonthID).options[getRef(bMonthID).selectedIndex].text + " " +
                         bDay + ", " + birthYear;

         var checkDay = new Date(birthDay);
         var monthName = new Array("January","February","March","April",
                                   "May","June","July","August",
                                   "September","October","November","December");

         if (checkDay.getDate() != bDay)
         {
            alert("You didn't specify a valid day of month for the birthday.");
            getRef(bDayID).select();
            getRef(bDayID).focus();

            return -1;
         }
         else
         {
            return 0;
         }
      }
      else
      {
         return 0;
      }
   }
}

function validateDateMMYYYY(IDStr)
{
   validInputData = true;

   var tempDate = getRef(IDStr).value;

   if (tempDate.charAt(0) == "0")
   {
      tempDate = tempDate.replace("0","");
   }

   var monthNum = parseInt(tempDate);
   var year = "";

   if (tempDate.indexOf("/") != -1)
   {
      year = tempDate.substr(tempDate.indexOf("/")+1,4);
   }
   else if (tempDate.indexOf("-") != -1)
   {
      year = tempDate.substr(tempDate.indexOf("-")+1,4);
   }

   tempDate = getRef(IDStr).value;

   if ( ((lastErrorIDStr == "") || (lastErrorIDStr == IDStr)) && (tempDate.length > 0) )
   {
      if ( (monthNum >= 1) && (monthNum <= 12) && (year.length = 4) )
      {
         var monthName = new Array("January","February","March","April",
                                   "May","June","July","August",
                                   "September","October","November","December");
         var tempDate = monthName[monthNum-1] + " 01, " + year;
         var checkDate = new Date(tempDate);

         if ( (checkDate == "NaN") ||
              (checkDate == "Invalid Date") ||
              (monthName[checkDate.getMonth()] == undefined) )
         {
            validInputData = false;
            lastErrorIDStr = IDStr;

            alert("Invalid date!");
            getRef(IDStr).select();
            getRef(IDStr).focus();

            return -1;
         }
         else
         {
            tempDate = getRef(IDStr).value;
            monthNum = tempDate.substr(0,tempDate.indexOf("/"));
            if (monthNum.length < 2)
            {
               getRef(IDStr).value = "0"+getRef(IDStr).value;
            }
         }
      }
      else
      {
         validInputData = false;
         lastErrorIDStr = IDStr;

         alert("Invalid date!");
         getRef(IDStr).select();
         getRef(IDStr).focus();

         return -1;
      }

      lastErrorIDStr = "";
      return 0;
   }
}

function validateDateMMDDYYYY(IDStr)
{
   validInputData = true;

   var tempDate = getRef(IDStr).value;

   if (tempDate.charAt(0) == "0")
   {
      tempDate = tempDate.replace("0","");
   }

   var monthNum = parseInt(tempDate);

   if (tempDate.indexOf("/") != -1)
   {
      tempDate = tempDate.substr(tempDate.indexOf("/")+1,tempDate.length);
   }
   else if (tempDate.indexOf("-") != -1)
   {
      tempDate = tempDate.substr(tempDate.indexOf("/")+1,tempDate.length);
   }

   if (tempDate.charAt(0) == "0")
   {
      tempDate = tempDate.replace("0","");
   }

   var dayNum = parseInt(tempDate);

   var year = "";

   if (tempDate.indexOf("/") != -1)
   {
      year = tempDate.substr(tempDate.indexOf("/")+1,4);
   }
   else if (tempDate.indexOf("-") != -1)
   {
      year = tempDate.substr(tempDate.indexOf("-")+1,4);
   }

   var yearNum = parseInt(year);
   tempDate = getRef(IDStr).value;

   if ( ((lastErrorIDStr == "") || (lastErrorIDStr == IDStr)) && (tempDate.length > 0) )
   {
      if ( (dayNum >= 1) && (dayNum <= 31) && (monthNum >= 1) && (monthNum <= 12) && (year.length = 4) )
      {
         var checkDate = new Date(yearNum,monthNum-1,dayNum);

         if ( (checkDate == "NaN") ||
              (checkDate == "Invalid Date") ||
              (checkDate.getDate() != dayNum) ||
              (checkDate.getMonth() != (monthNum-1)) ||
              (checkDate.getYear() != yearNum) )
         {
            validInputData = false;
            lastErrorIDStr = IDStr;

            alert("Invalid date!");
            getRef(IDStr).select();
            getRef(IDStr).focus();

            return -1;
         }
         else
         {
            tempDate = getRef(IDStr).value;
            monthNum = tempDate.substr(0,tempDate.indexOf("/"));
            if (monthNum.length < 2)
            {
               getRef(IDStr).value = "0"+getRef(IDStr).value;
            }
            tempDate = getRef(IDStr).value;

            if (tempDate.length < 10)
            {
               getRef(IDStr).value = tempDate = tempDate.replace("/","/0");
            }
         }
      }
      else
      {
         validInputData = false;
         lastErrorIDStr = IDStr;

         alert("Invalid date!");
         getRef(IDStr).select();
         getRef(IDStr).focus();

         return -1;
      }

      lastErrorIDStr = "";
      return 0;
   }
}

function validateEMailAddress(IDStr)
{
   validInputData = true;
   var index = 0;

   if (getRef(IDStr) != null)
   {

      DeleteAllSpace(IDStr);

      var fieldValue = getRef(IDStr).value;

      if (fieldValue.length == 0)
      {
         validInputData = false;
         lastErrorIDStr = IDStr;

         alert("A value is required in this field.");
         getRef(IDStr).select();
         getRef(IDStr).focus();

         return -1;
      }

      while (fieldValue.length > 0)
      {
         tempValue = fieldValue.substr(0,fieldValue.indexOf(","));

         if (tempValue == "")
         {
            tempValue=fieldValue;
         }

         index = tempValue.indexOf("@");

         if (tempValue != "")
         {
            if ( (index <= 0) || (tempValue.lastIndexOf("@") != index) )
            {
               validInputData = false;
               lastErrorIDStr = IDStr;

               alert("Invalid Email Address!");
               getRef(IDStr).select();
               getRef(IDStr).focus();

               return -1;
            };


            fieldValue=fieldValue.replace(tempValue,"");
            fieldValue=fieldValue.replace(",","");
         }
      }

      return 0;
   }
}

function hash(form)
{
   var passwd = form.signinPassword.value;
   var challenge = form["challenge"].value;
   var hash1 = calcMD5(passwd);
   var hash2 = calcMD5(hash1) + challenge;
   var hash;
   var url;

   if (form.signinPassword.value)
   {
      hash=calcMD5(hash2);
   }
   else
   {
      hash="";
   }

   url = form.action+"&SIN="+form.signinName.value+"&RTPwd="+hash+"&CHLGStr="+challenge;
   location.href = url;

   // prevent from running this again. Allow the server response to submit the form directly
   form.onsubmit = null;

   // abort normal form submission
   return false;
}

function hash2(form)
{
   var challenge = "";
   var oldPassword = "";

   var signinName = "";
   var password = "";
   var password2 = "";

   var sinID = "";
   var pwdID = "";
   var pwdID2 = "";

   var pwdHash = "";

   if (form["challenge"])
   {
      challenge = form["challenge"].value;
   }
   if (form["oldPassword"])
   {
      oldPassword = form["oldPassword"].value;

      if (oldPassword.length == 0)
      {
         alert("A value is required in this field.");
         getRef("oldPassword").select();
         getRef("oldPassword").focus();

         return false;
      }

      var hashOld1 = calcMD5(oldPassword);
      var hashOld2 = calcMD5(hashOld1) + challenge;
      var hashOld = calcMD5(hashOld2);
   }

   if (form["signinName"])
   {
      signinName = form.signinName.value;
      sinID = "signinName";
   }

   if (form["signinPassword"])
   {
      password = form.signinPassword.value;
      pwdID = "signinPassword";
   }

   if (form["signinPassword2"])
   {
      password2 = form.signinPassword2.value;
      pwdID2 = "signinPassword2";
   }

   if (form["firstName"])
   {
      var firstName = form.firstName.value;
   }

   if (form["firstName"])
   {
      var lastName = form.lastName.value;
   }

   if (password != password2)
   {
      alert("You new password entries did not match.");
      getRef(pwdID2).select();
      getRef(pwdID2).focus();

      return false;
   }

   if (isValidForm(sinID,pwdID,"firstName","lastName","passwordA","birthMonth","birthDay","birthYear","zipCode","sex","comExt") == 0)
   {

      pwdHash = password;

      if (form["signinPassword"])
      {
         pwdHash = calcMD5(calcMD5(password));
      }

      if(form["signinPassword"] && form["signinPassword"].type != "hidden"){
        form["signinPassword"].value = pwdHash;
      }

      if(form["signinPassword2"] && form["signinPassword2"].type != "hidden"){
        form["signinPassword2"].value = pwdHash;
      }

      if (form["oldPassword"])
      {
        form["oldPassword"].value = hashOld;
      }

      // prevent from running this again. Allow the server response to submit the form directly
      form.onsubmit=null;

      return true;
   }

   return false;
}

function hash3(form)
{
   var challenge = "";
   var oldPassword = "";

   var signinName = "";
   var password = "";
   var password2 = "";

   var sinID = "";
   var pwdID = "";
   var pwdID2 = "";

   var pwdHash = "";

   if (form["challenge"])
   {
      challenge = form["challenge"].value;
   }
   if (form["oldPassword"])
   {
      oldPassword = form["oldPassword"].value;

      if (oldPassword.length == 0)
      {
         alert("A value is required in this field.");
         getRef("oldPassword").select();
         getRef("oldPassword").focus();

         return false;
      }

      var hashOld1 = calcMD5(oldPassword);
      var hashOld2 = calcMD5(hashOld1) + challenge;
      var hashOld = calcMD5(hashOld2);
   }

   if (form["signinName"])
   {
      signinName = form.signinName.value;
      sinID = "signinName";
   }

   if (form["signinPassword"])
   {
      password = form.signinPassword.value;
      pwdID = "signinPassword";
   }

   if (form["signinPassword2"])
   {
      password2 = form.signinPassword2.value;
      pwdID2 = "signinPassword2";
   }

   if (form["firstName"])
   {
      var firstName = form.firstName.value;
   }

   if (form["firstName"])
   {
      var lastName = form.lastName.value;
   }

   if (password != password2)
   {
      alert("You new password entries did not match.");
      getRef(pwdID2).select();
      getRef(pwdID2).focus();

      return false;
   }

   if (isValidForm("",pwdID,"","","","","","","","","") == 0)
   {

      pwdHash = password;

      if (form["signinPassword"])
      {
         pwdHash = calcMD5(calcMD5(password));
      }

      if(form["signinPassword"] && form["signinPassword"].type != "hidden"){
        form["signinPassword"].value = pwdHash;
      }

      if(form["signinPassword2"] && form["signinPassword2"].type != "hidden"){
        form["signinPassword2"].value = pwdHash;
      }

      if (form["oldPassword"])
      {
        form["oldPassword"].value = hashOld;
      }

      if (form["zipCode"])
      {
         var zipCode = form["zipCode"].value;
         if (zipCode.length > 0)
         {
           zipCode = zipCode.toLowerCase();
           form["zipCode"].value = calcMD5(calcMD5(zipCode)+challenge);
         }
      }

      if (form["eMail"])
      {
         var eMail = form["eMail"].value;
         if (eMail.length > 0)
         {
            eMail = eMail.toLowerCase();
            form["eMail"].value = calcMD5(calcMD5(eMail)+challenge);
         }
      }

      if (form["passwordA"])
      {
         var passwordA = form["passwordA"].value;
         if (passwordA.length > 0)
         {
            passwordA = passwordA.toLowerCase();
            form["passwordA"].value = calcMD5(calcMD5(passwordA)+challenge);
         }
      }

      // prevent from running this again. Allow the server response to submit the form directly
      form.onsubmit=null;

      return true;
   }

   return false;
}

function saveCBandGoToLocation(pathName,CBIDStr,RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex,QueryFieldName)
{
   var tempStr = "";
   var selectedCases = "";

   if (pathName != "")
   {
      selectedCases = getSelectedCases2(RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex);

      if (getRef(CBIDStr).checked)
      {
         tempStr = "&"+QueryFieldName+"=true";
      }
      else
      {
         tempStr = "&"+QueryFieldName+"=false";
      }
      location=pathName+tempStr+"&"+selectedCases;
   }
   else
   {
      alert("Can't find link infomation!");
   }
}

function SortWhich(pathName,RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex)
{
   var selectedCases = "";

   if (pathName != "")
   {
      selectedCases = getSelectedCases2(RowIDPrefix,anchorPrefix,selectedRowBGColor,startIndex,endIndex);

      location=pathName+"&"+selectedCases;
   }
   else
   {
      alert("Can't find link infomation!");
   }
}

function formSubmit(actionStr,formObject)
{
   if (validInputData)
   {
      formObject.action=actionStr;
      formObject.submit();
   }
   validInputData=true;
}

function formSubmit2(actionStr,formObject,inputRequiredFields)
{
   if (validInputData)
   {
      if (checkInputRequiredFields(inputRequiredFields,true) != -1)
      {
         formObject.action=actionStr;
         formObject.submit();
      }
   }
   validInputData=true;
}

function formSubmit3(actionStr,formObject,inputRequiredFields,totalYears,totalCols,objectName,ColToCheck,ScheduleInputRequiredCols)
{
   if (validInputData)
   {
      if ( (checkInputRequiredFields(inputRequiredFields,true) != -1) &&
           (checkInputRequiredFieldsForSchedule(totalYears,totalCols,objectName,ColToCheck,ScheduleInputRequiredCols) != -1) )
      {
         formObject.action=actionStr;
         formObject.submit();
      }
   }
   validInputData=true;
}

//for Section 7872 Admin. only
function formSubmit4(actionStr,formObject,inputRequiredFields,totalYears,schedule1ObjectName,schedule2ObjectName)
{
   if (validInputData)
   {
      if (checkInputRequiredFields(inputRequiredFields,true) == -1)
      {
         validInputData=true;
         return false;
      }

      if (schedule1ObjectName != null)
      {
         if (checkInputRequiredFieldsForSchedule(totalYears,3,schedule1ObjectName,'1','-1') == -1)
         {
            validInputData=true;
            return false;
         }
      }

      if (schedule2ObjectName != null)
      {
         if (checkInputRequiredFieldsForSchedule(totalYears,2,schedule2ObjectName,'1','-1') == -1)
         {
            validInputData=true;
            return false;
         }
      }

      formObject.action=actionStr;
      formObject.submit();
   }
   validInputData=true;
}

// Cookie code from The JavaScript Source
function GetCookie (name)
{
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;

   while (i < clen)
   {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
         return getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break;
   }
   return null;
}

function getCookieVal(offset)
{
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
   endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}

function SetCookie2(name, value)
{
   var argv = SetCookie2.arguments;
   var argc = SetCookie2.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 + "=" + escape (value) +
   ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
   ((path == null) ? "" : ("; path=" + path)) +
   ((domain == null) ? "" : ("; domain=" + domain)) +
   ((secure == true) ? "; secure" : "");
}

function ExpireCookie(name)
{
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie(name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function DeleteCookie(name)
{
   var exp = new Date();
   exp.setTime(exp.getTime() - 1);
   var cval = GetCookie(name);
   document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function selectAllCBC(selected)
{
   var i = 0;
   var CheckBoxIDStr = "";
   var TotalNumOfCBC = 50;

   if (getRef("TotalNumOfCBC") != null)
   {
      TotalNumOfCBC = getRef("TotalNumOfCBC").value;
   }

   for(i=1; i<=TotalNumOfCBC; i++)
   {
      CheckBoxIDStr = "CBCSelect"+i;
      if (getRef(CheckBoxIDStr) != null)
      {
         getRef(CheckBoxIDStr).checked=selected;
         SetValueById2(CheckBoxIDStr);
      }
   }
}

function CBCFormSubmit(form)
{
   var i = 0;
   var CheckBoxIDStr = "";
   var TotalNumOfCBC = 50;
   var CBCSelected = false;

   if (getRef("TotalNumOfCBC") != null)
   {
      TotalNumOfCBC = getRef("TotalNumOfCBC").value;
   }

   for(i=1; i<=TotalNumOfCBC; i++)
   {
      CheckBoxIDStr = "CBCSelect"+i;
      if (getRef(CheckBoxIDStr) != null)
      {
         if (getRef(CheckBoxIDStr).checked == true)
         {
            CBCSelected = true;
            break;
         }
      }
   }

   if (CBCSelected)
   {
      form.submit();
      //location.href = form.action;

     // prevent from running this again. Allow the server response to submit the form directly
     //form.onsubmit = null;
   }
   else
   {
      alert("No CBC selected!");
   }

   // abort normal form submission
   return false;
}

function selectAllDoc(selected)
{
   var i = 0;
   var CheckBoxIDStr = "";
   var TotalNumOfDoc = 50;

   if (getRef("TotalNumOfDoc") != null)
   {
      TotalNumOfDoc = getRef("TotalNumOfDoc").value;
   }

   for(i=1; i<=TotalNumOfDoc; i++)
   {
      CheckBoxIDStr = "cbBox"+i;
      if (getRef(CheckBoxIDStr) != null)
      {
         getRef(CheckBoxIDStr).checked=selected;
      }
   }
}

function ExportDocuments(pathName,LITypeIDStr,HighlightIDStr)
{
   var i = 0;
   var CheckBoxIDStr = "";
   var TotalNumOfDoc = 50;
   var DocSelected = false;
   var ExportDocName = "";
   var tmpName = "";
   var LIType = "Fixed=";

   if (getRef("TotalNumOfDoc") != null)
   {
      TotalNumOfDoc = getRef("TotalNumOfDoc").value;
   }

   for(i=1; i<=TotalNumOfDoc; i++)
   {
      CheckBoxIDStr = "cbBox"+i;
      if (getRef(CheckBoxIDStr) != null)
      {
         if (getRef(CheckBoxIDStr).checked == true)
         {
            DocSelected = true;
            break;
         }
      }
   }

   if (DocSelected)
   {
      if (getRef(LITypeIDStr) != null)
      {
         LIType = getRef(LITypeIDStr).value+"=";
         pathName = pathName + "&LIType=" + getRef(LITypeIDStr).value;
      }

      pathName = pathName + "&FileType=Export";

      if (getRef(HighlightIDStr) != null)
      {
         if (getRef(HighlightIDStr).checked)
         {
            pathName = pathName + "&Highlight=on";
         }
         else
         {
            pathName = pathName + "&Highlight=off";
         }
      }


      ExportDocName = "&ExportFile=";

      for(i=1; i<=TotalNumOfDoc; i++)
      {
         CheckBoxIDStr = "cbBox"+i;
         if (getRef(CheckBoxIDStr) != null)
         {
            if (getRef(CheckBoxIDStr).checked == true)
            {
               tmpName = getRef(CheckBoxIDStr).value;

               if (tmpName.indexOf(LIType) == 0)
               {
                  tmpName = tmpName.substr(LIType.length,tmpName.indexOf(";")-LIType.length);
               }
               if (tmpName.indexOf(LIType) > 0)
               {
                  tmpName = tmpName.substr(tmpName.indexOf(LIType)+LIType.length,tmpName.length-tmpName.indexOf(LIType)-LIType.length);
               }

               if (i==1)
               {
                  ExportDocName = ExportDocName + tmpName;
               }
               else
               {
                  ExportDocName = ExportDocName + "," + tmpName;
               }
            }
         }
      }

      var returnValue = confirm("                     * * *  IMPORTANT MESSAGE  * * *" + '\n' + '\n' +
                                "Any editing of the copied document that involves any legal or tax " + '\n' +
                                "issue or consequence must only be done by qualified legal or tax " + '\n' +
                                "counsel.  The party licensed to use the System is responsible for " + '\n' +
                                "presenting the material only in suitable situations.")

      pathName = pathName + ExportDocName;

      if (returnValue == true)
      {
         goToLocation(pathName);
      }
   }
   else
   {
      alert("No document selected to export!");
   }
}

function DODFormSubmit(form,pathName,submitType,LITypeIDStr,HighlightIDStr)
{
   var i = 0;
   var CheckBoxIDStr = "";
   var TotalNumOfDoc = 50;
   var DocSelected = false;

   form.action = pathName;

   if (submitType == "Search")
   {
      form.submit();
   }
   else if (submitType == "Export")
   {
           if (getRef("TotalNumOfDoc") != null)
           {
              TotalNumOfDoc = getRef("TotalNumOfDoc").value;
           }

           for(i=1; i<=TotalNumOfDoc; i++)
           {
              CheckBoxIDStr = "cbBox"+i;
              if (getRef(CheckBoxIDStr) != null)
              {
                 if (getRef(CheckBoxIDStr).checked == true)
                 {
                    DocSelected = true;
                    break;
                 }
              }
           }


           if (DocSelected)
           {
              if (getRef(LITypeIDStr) != null)
              {
                 LIType = getRef(LITypeIDStr).value+"=";
                 pathName = pathName + "&LIType=" + getRef(LITypeIDStr).value;
              }

              if (pathName.indexOf("FileType=Export") == -1)
              {
                 pathName = pathName + "&FileType=Export";
              }

              if (getRef(HighlightIDStr) != null)
              {
                 if (getRef(HighlightIDStr).checked)
                 {
                    pathName = pathName + "&Highlight=on";
                 }
                 else
                 {
                    pathName = pathName + "&Highlight=off";
                 }
              }

              var returnValue = confirm("                     * * *  IMPORTANT MESSAGE  * * *" + '\n' + '\n' +
                                        "Any editing of the copied document that involves any legal or tax " + '\n' +
                                        "issue or consequence must only be done by qualified legal or tax " + '\n' +
                                        "counsel.  The party licensed to use the System is responsible for " + '\n' +
                                        "presenting the material only in suitable situations.")

              if (returnValue == true)
              {
                 form.submit();
              }
              else
              {
                 form.action = "";
              }
           }
           else
           {
              alert("No document selected to export!");
              form.action = "";
           }
   }
}


