function NewWindow(mypage, myname, w, h, scroll,lcid) {
if (lcid=='')
{
	return true;
}
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) {
	win.window.focus();
}
}
function PopUpLKP(URL) {
  var w = '650';
  var h = '400';
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  var winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
  var lookup = window.open(URL,"LookUpWindow",winprops);
  lookup.window.focus();
}
function PopUpDyn(lcSID,DynQryStr,DynValue) {
  if (DynValue == '') {
    alert('Please fill in Search Criteria') ;
    return false ;
  }
  else {
    PopUpLKP('DynLookup.FPC?SID='+lcSID+'&'+DynQryStr+'='+DynValue);
  }
}
function PopUpFuzzy(lcSID,DynTable,DynField,DynValue,DynCallBox,DynName) {
  PopUpLKP('DynLookup.FPC?SID='+lcSID+'&DynTab='+DynTable+'&DynFld='+DynField+'&DynVal='+DynValue+'&DynCallBox='+DynCallBox+'&DynName='+DynName);
}
function PopUpFuzzySideBar(lcSID,DynTable,DynField,DynValue,DynCallBox,DynName,SideBar) {
  PopUpLKP('DynLookupfpcadv.FPC?SID='+lcSID+'&DynTab='+DynTable+'&DynFld='+DynField+'&DynVal='+DynValue+'&DynCallBox='+DynCallBox+'&DynName='+DynName+'&SideBar=1');
}
//Add This to handle Calendar
//function PopUpCalendar(LMCalValue,UMCalValue,CalValue,CalCallBox,CalName,CalRelName) {
//  PopUpLKP('PopupCalendar.FPC?LMCalVal='+LMCalValue+'&UMCalVal='+UMCalValue+'&CalVal='+CalValue+'&CalCallBox='+CalCallBox+'&CalName='+CalName+'&CalRelName='+CalRelName);
//}
function MakeList(myobj, myRetrunBox){
  var max = myobj.length;
  var myreturn = '';
  for (var idx = 0; idx < max; idx++) {
    if (myobj.options[idx].selected == true) {
        mySelect = myobj.options[idx].value ;
//    	myreturn += myobj.options[idx].value + ',' ;
    	myreturn += myobj.options[idx].value + ';' ;
    }
  }
  myreturn = myreturn.substring(0,myreturn.length-1) ;
  eval("window.opener.document.Page1."+myRetrunBox).value=myreturn;
  self.close();
}
function Old_NewMakeList(myobj, myRetrunBox){
alert('In Here')
  var max = myobj.length;
//  var nMaxSelAllowed = 25;
//  var nSelected = 0;
  var myreturn = '';
  // initial the last matched value and id
  var lastselectedid = -1 ;
  var lastselectedvalue = '        ' ;
  // Run through all options to return value to opener textbox, except the first one

  for (var idx = 1; idx < max; idx++) {
    var CurrentOption = myobj.options[idx].value ;
    // Match the selection to the opener textbox values
    if (myobj.options[idx].selected == true) {

      // Increment the nSelected
//      nSelected = nSelected + 1;
//      if (nSelected > nMaxSelAllowed) {
//        alert('You have selected more than 25 items.\n Please limit your search criteria and try again.');
//        return false;
//      }
      // Remove last selection if the current one contain the last one.
//      var CheckCurrentOption = ','+CurrentOption
      var CheckCurrentOption = ';'+CurrentOption
//      if (CheckCurrentOption.match(','+lastselectedvalue)) {
      if (CheckCurrentOption.match(';'+lastselectedvalue)) {
        // Decrement the nSelected
//        nSelected = nSelected - 1;
        myreturn = myreturn.substring(0,myreturn.length-lastselectedvalue.length-1) ;
      }
//      myreturn += myobj.options[idx].value + ',' ;
      myreturn += myobj.options[idx].value + ';' ;
      lastselectedid = idx ;
      lastselectedvalue = CurrentOption ;
    }
  }
  myreturn = myreturn.substring(0,myreturn.length-1) ;
alert(myreturn);
  eval("window.opener.document.Page1."+myRetrunBox).value=myreturn;
// The line below was added back by joe.
  eval("window.opener.document.Page1."+myRetrunBox+"_d").value=myreturn;
//eval("window.opener.document.Page1."+myRetrunBox).disabled = "";
//Following line has been commented according to the requirement.
//eval("window.opener.document.Page1.page1_frmqry_"+myRetrunBox+"hidden").value=myreturn;
  window.opener.focus();
  window.opener.document.Page1.submit();
//eval("window.opener.document.Page1."+myRetrunBox).disabled = 'disabled';
  self.close();
}
function NewMakeList(myobj, myRetrunBox){

  var max = myobj.length;
//  var nMaxSelAllowed = 25;
//  var nSelected = 0;
  var myreturn = '';
  // initial the last matched value and id
  var lastselectedid = -1 ;
  var lastselectedvalue = '        ' ;
  // Run through all options to return value to opener textbox, except the first one

  for (var idx = 1; idx < max; idx++) {
    var CurrentOption = myobj.options[idx].value ;
    // Match the selection to the opener textbox values
    if (myobj.options[idx].selected == true) {

      // Increment the nSelected
//      nSelected = nSelected + 1;
//      if (nSelected > nMaxSelAllowed) {
//        alert('You have selected more than 25 items.\n Please limit your search criteria and try again.');
//        return false;
//      }
      // Remove last selection if the current one contain the last one.
//      var CheckCurrentOption = ','+CurrentOption
      var CheckCurrentOption = ';'+CurrentOption
//      if (CheckCurrentOption.match(','+lastselectedvalue)) {
      if (CheckCurrentOption.match(';'+lastselectedvalue)) {
        // Decrement the nSelected
//        nSelected = nSelected - 1;
        myreturn = myreturn.substring(0,myreturn.length-lastselectedvalue.length-1) ;
      }
//      myreturn += myobj.options[idx].value + ',' ;
      myreturn += myobj.options[idx].value + ';' ;
      lastselectedid = idx ;
      lastselectedvalue = CurrentOption ;
    }
  }
  myreturn = myreturn.substring(0,myreturn.length-1) ;
  eval("window.opener.document.Page1."+myRetrunBox).value=myreturn;
  eval("window.opener.document.Page1."+myRetrunBox+"_d").value=myreturn;
  window.opener.focus();
  window.opener.document.Page1.submit();
  self.close();
}
function PopSelList(myobj,myPopBox){
  var mysearch = eval('window.opener.document.Page1.'+myPopBox).value;
  var max = myobj.length;
  // Check the opener text value is not empty
  if (mysearch != "") {
    // Add leading and trailing "," to make it unique
//    mysearch = ','+mysearch+',';
    mysearch = ';'+mysearch+';';
    // Run through all options to make selections if the value from the opener textbox is not empty
    for (var idx2 = 1; idx2 < max; idx2++) {
      var CurrentOption = myobj.options[idx2].value ;
      // Match the selection to the opener textbox values
//      if (mysearch.match(','+CurrentOption+',')) {
      if (mysearch.match(';'+CurrentOption+';')) {
        myobj.options[idx2].selected = true;
      }
    }
  }
}
function ABIHorNav (Qstring) {
    loForm = document.Page1 ;
    // alert(Qstring);
    loForm.action='Search.FPC?pg=213&ACP='+Qstring ;
    loForm.submit();
}
function ABINewWindow_draft(mypage, myname, type, scroll) {
  var h = screen.height / 2 ;
  var w = screen.width * 0.33 ;
  var l = screen.width - w ;
  if (type == 1) {
    // this is search result display window
    var t = 0 ;
  }
  else {
    // this is text search display window
    var t = h  ;
  }
  winprops = 'height='+h+',width='+w+',top='+t+',left='+l+',scrollbars='+scroll+',resizable'
  win = window.open(mypage, myname, winprops)
  if (parseInt(navigator.appVersion) >= 4) {
	win.window.focus();
  }
}
function SearchABI (cValue,cAgency,cSID) {
    if (cValue == '') {
        return false;
    }
    ABINewWindow('ABIWordSearch.FPC?q='+cValue+'&AGCY='+cAgency+'&SID='+cSID,'ABISearchResult','1','yes')
}
//function ShowSearchABI (cShowMainPage,cShowPage,cShowID,cSID) {
function ShowSearchABI (cShowMainPage,cShowPage,cShowID,cSID,cAgency) {
//    ABINewWindow('ABIDisplayText.FPC?SID='+cSID+'&pid='+cShowPage+'&cid='+cShowID,'ABITextSearchResult','2','yes') ;
    if ((cAgency == 'ZGAO') || (cAgency == 'ZHEARINGS')) {
        NewWindow(cShowMainPage, 'ABIPOPUP', '550', '375', 'yes')
    }
    else {
        window.opener.location.href = 'Search.FPC?pg=213&ACP='+cShowMainPage ;
        self.focus() ;
    }
//  window.opener.location.href = 'Search.FPC?pg=213&ACP='+cShowMainPage ;
//    self.focus() ;
//    win1.focus() ; // ABITextSearchResult windows
//    win2.focus() ; // ABISearchResult windows
}
function ABINewWindow(mypage, myname, type, scroll) {
  var hoff = 52 ;
//  var h = (screen.height / 2) - hoff ;
  var h = screen.height - hoff ;
  var w = screen.width * 0.33 ;
  var l = screen.width - w - 10 ;
  if (type == 1) {
    // this is search result display window
    var t = 0 ;
    winprops = 'height='+h+',width='+w+',top='+t+',left='+l+',scrollbars='+scroll+',resizable'
    // clear window first
    win1 = window.open('blankPage.htm', myname, winprops)
    win1 = window.open(mypage, myname, winprops)
    if (parseInt(navigator.appVersion) >= 4) {
	  win1.window.focus();
    }
  }
//  else {
//    // this is text search display window
//    var t = h + (hoff - 16)  ;
//    winprops = 'height='+h+',width='+w+',top='+t+',left='+l+',scrollbars='+scroll+',resizable'
//    // clear window first
//    win2 = window.open('blankPage.htm', myname, winprops)
//    win2 = window.open(mypage, myname, winprops)
//    if (parseInt(navigator.appVersion) >= 4) {
//	  win2.window.focus();
//    }
//  }
}
function PopUpDyn (lcSID,DynQryStr,DynValue) {
  if (DynValue == '') {
    alert('Please fill in Search Criteria') ;
    return false ;
  }
  else {
    PopUpLKP('DynLookup.FPC?SID='+lcSID+'&'+DynQryStr+'='+DynValue);
  }
}
function SavePopUpDyn (lcValue, lcBoxName, llWaitWindow) {
  if (lcValue == '') {
    alert('Please select an item and click select button again') ;
    return false ;
  }
  else {
    // fill in the right textbox to the opener browser
    eval("window.opener.document.Page1.txt"+lcBoxName+"Value").value=lcValue ;
    // show wait windows
    if (llWaitWindow) {
      NewWindow('WaitForProcessing.htm','WaitWindow','351','109','no');
    }
    // make the page submit and close this browser
    window.opener.document.Page1.submit() ;
    self.close() ;
    return false;
  }
}
//function PCompLink (lcValue) {
//  if (lcValue == '') {
//    alert('Please select an item and click select button again') ;
//    return false ;
//  }
//  else {
//    // fill in the right textbox to the opener browser
//    document.Page1.txtDUN1Value.value=lcValue ;
//    // show wait windows
//    NewWindow('WaitForProcessing.htm','WaitWindow','351','109','no');
//    // make the page submit
//    document.Page1.submit() ;
//  }
//}
function PCompLink (lcID) {
oThisForm = document.Page1 ;
oThisForm.txtDUN1Value.value=lcID ;
NewWindow('WaitForProcessing.htm','WaitWindow','351','109','no');
oThisForm.submit();
}
function GoToStep(cStep) {
    document.Page1.action = window.document.Page1.action+"#Step"+cStep ;
    document.Page1.submit() ;
}
function GoTo(cURL) {
    document.Page1.action = cURL ;
    document.Page1.submit() ;
}
// function OBIUpdateUserControl(tcOpenerBoxReturn) {
//  eval("window.opener.document.Page1."+tcOpenerBoxReturn).value=lcValue ;
function OBIUpdateUserControl() {
  window.opener.focus();
  window.opener.document.Page1.submit();
  self.close();
}
function clearadvsrch()
{
	document.Page1.clearset.value='set';
	document.Page1.submit() ;
      return true ;
}
function RequestCall (tcWhatReportID, tcWhatRequest, tcResetQuery, tcpageid, tcStaticDisplayType) {
    if (tcWhatRequest == '') {
        return false ;
    }
    else {
        document.Page1.lcWhatReportID.value = tcWhatReportID ;
        document.Page1.lcWhatRequest.value = tcWhatRequest ;
 	  document.Page1.lcpageid.value = tcpageid ;
        if (tcResetQuery != null) {
            document.Page1.lcResetQuery.value = 'yes' ;
            document.Page1.lcPageStatus.value = '' ;
            document.Page1.ValueSelect.value = '' ;
            document.Page1.IDSelect.value = '';
        }
        if (tcWhatReportID == 0) {
            document.Page1.lcPageStatus.value = 'Advanced Search' ;
        }
        if (tcStaticDisplayType != null) {
            document.Page1.lcStaticDisplayType.value = '1' ;
        }
        document.Page1.action = "search.fpc?pg="+tcpageid ;
        document.Page1.submit() ;
        return true ;
    }
}
function GetSelectedDisplayValue (tcFormName, tcBoxName, tcShowInName) {
  var selected_index = tcFormName.elements[tcBoxName].selectedIndex;
  var selected_option_text = tcFormName.elements[tcBoxName].options[selected_index].text;
  if (tcShowInName != undefined) {
    eval(tcShowInName).innerHTML=selected_option_text ;
  }
  else {
    return selected_option_text ;
  }
}
