// Funkcje specyficzne dla listing_search_adv.asp

function SearchAdvSelTab(pageNo)
{
  var form = document.forms['ListingSearch'];
  if(!CheckListingSearchForm(form)) return;
  form.action = 'listing_search_adv.asp?ListingSearchPageNo=' + pageNo;
  form.submit();
}

function SearchListings()
{
  var form = document.forms['ListingSearch'];
  if(!CheckListingSearchForm(form)) return;
  form.action = 'show_listings.asp';
  form.submit();
}

function SearchArchiveListings(removed)
{
  var form = document.forms['ListingSearch'];
  if(!CheckListingSearchForm(form)) return;
  form.elements['s_Removed'].value = (removed ? '1' : '0');
  form.action = 'show_archive_listings.asp';
  form.submit();
}

function CheckListingSearchForm(form)
{
  if(!CheckFormFields(form)) return false;
  if(typeof(AddLastLocation) == 'function') AddLastLocation(form);
  return true;
}

function OnUnitChoosen( unitID, unitCat, unitName )
{
  var opt
  
  form = document.forms['ListingSearch'] 
  switch(unitCat)
  {
    case 1:
      if(form.AgentID.options[2])
      {
        opt = form.AgentID.options[2]
      }
      else
      {
        opt = new Option("", "")
        form.AgentID.options[2] = opt
      }
      if(form.CompanyID.options[2])        
      {
        form.CompanyID.options[0].selected = true 
        form.CompanyID.options[2]=null
      }
    break;
    case 3:
      if(form.CompanyID.options[2])
      {
        opt = form.CompanyID.options[2]
      }
      else
      {
        opt = new Option("", "")
        form.CompanyID.options[2] = opt
      }   
      if(form.AgentID && form.AgentID.options[2]) 
      {
        form.AgentID.options[0].selected = true
        form.AgentID.options[2]=null
      }   
    break;
  }
  opt.value = unitID
  opt.text  = LongTextEllipsis(unitName, 35, '...');
  opt.selected = true
  
  form.s4UnitName.value = unitName    
  form.s_RestrictToUserID.value = unitID
}  

function SelectUser(sel, srchType)
{
  form = document.forms['ListingSearch']
  if(sel.selectedIndex == 2)
    form.s_RestrictToUserID.value = sel.options[2].value    
  else if(sel.selectedIndex == 1){ // opcja "Wybierz"
    sel.selectedIndex = 0;
    UnitChoose(srchType, VirtDir);
  }else
    form.s_RestrictToUserID.value = ""
}

function sca_OnGDDisabledChange(disabled)
{
  SetElementVisibility('sca_gd_Message', disabled);
  SetElementVisibility('sca_gd_LocationList', disabled);
}

function scapropcatChanged(cntrl)
{
  var form = document.forms['ListingSearch'];
  form.submit();
}
