/*
 * File........: gtab.js
 * Created.....: 2005/05/30
 * Copyright...: (c) 2005 All Rights Reserved.
 */

function Ausw(obj)
{
 if(!bWait)
 {
  if(typeof obj != "object") return;
  if(obj.selectedIndex < 0)  return;
  if(obj.options[obj.selectedIndex].value == ""  ) return;
  if(obj.options[obj.selectedIndex].value == "*" ) return;
  document.p.tab.value = obj.name;
  document.p.idx.value = obj.options[obj.selectedIndex].value;
  
  //reset der abhaengigen Tabellen
  if ((document.p.tab.value == "t_manuf") && (document.p.idx.value == -1))
  {
    document.p.tab2.value = "t_model";
    document.p.tab3.value = "t_smod";
  }
  if ((document.p.tab.value == "t_model") && (document.p.idx.value == -1))
    document.p.tab2.value = "t_smod";

  if(document.p.show)
    document.p.show.value = flagListe();
  showWait();
  document.p.submit();	
  bWait = true;
 } else
 { alert(sWait); bWait = false; }
}

function Check(obj,bEquip)
{
 if(!bWait) {
  if (typeof obj != "object") return;
  if(document.p.show)
	document.p.show.value = flagListe();
  if(bEquip && document.p.action.lastIndexOf("#equip") == -1)
    document.p.action += "#equip";
  document.p.tab.value = obj.name;
  document.p.idx.value = obj.value;
  // toggle '0x' for different URL
  if(document.p.show && document.location.href.lastIndexOf("show=00") == -1)
    document.p.show.value = '00' + document.p.show.value;
  showWait();
  document.p.submit();
  bWait = true;
 } else
 { alert(sWait); bWait = false; }
}

function rSel(tab,tab2,tab3)
{
  document.p.tab.value = tab;
  if(tab2)
    document.p.tab2.value = tab2;
  if(tab3)
    document.p.tab3.value = tab3;
  document.p.idx.value = "-1";
  if(document.p.show)
    document.p.show.value = flagListe();
  showWait();
  document.p.submit();
  bWait = true;
}

// Fahrzeugsuche nach Postleitzahl und Umkreis
function doDSearch(obj)
{
  if(!bWait)
  {
   if (typeof obj != "object") return;
   if (obj.name=='UkPLZ')
   {
     if (document.p.PostCode.value == obj.value) return;
     if (obj.value!="")
     {
      if (isNaN(obj.value)||(obj.value.length!=5)) 
      {
       obj.value=document.p.PostCode.value;
       openinfo(1,'LOC',400,250);
       return;
      }
     }  
     document.p.PostCode.value = obj.value;
     document.p.Distance.value = "-2";
     document.s.UkDist.selectedIndex = 0; 
   }
   if (obj.name=='UkDist')
   {
     document.p.Distance.value = obj.options[obj.selectedIndex].value;
     if (document.p.PostCode.value=="") return;
     if (document.p.Distance.value=="-1") return;
     document.p.tab.value="dist";
	 if(document.p.show)
       document.p.show.value = flagListe();
     showWait();
     document.p.submit();
     bWait = true;     
   }   
 } else
 { alert(sWait); bWait = false; }
}

function showResultList()
{
  //wenn Umkreissuche noetig, dann ausfuehren
  if (document.p.Distance.value == "-2")  //PLZ wurde geaendert
  {
     document.p.tab.value="dist2";
	 if(document.p.show)
       document.p.show.value = flagListe();
	 showWait();
     document.p.submit();
     bWait = true;     
  }  
  else
  { showWait();
    changeView('list',0);
  }
}

function showWaitImg()
{ if(bWait) document.images.waitimg.src = 'i/wait_large.gif';
}

function showWait()
{
  if(document.getElementById)
    setTimeout("showWaitImg()",500);
}

function flagListe()
{
  var stat = getViewStat();
  var flags = 0;
  for (var i=stat.length-1;i>=0;i--)
  { flags <<= 1;
	if(stat.charAt(i)=='1')
	  flags |= 1;
  }
  return flags;
}