//--------------------------------------------
// Javascripts zum BMW und CarFinder 2
// Author: Andreas Percher
// Firma:  automedia GmbH, Köln
//--------------------------------------------

// // // // // // // // // // // // // // // // // // // // // // // // // // //

var searching = false;
var infourl = null;
var infoframe = null;
var suchform = document.forms[0];

var listeUrl = "index.jsp";

// // // // // // // // // // // // // // // // // // // // // // // // // // //

function OpenNextSearch(extrakey,theUrl) {
  var key;

  if (searching==true)
    return;

  searching==true;
  if (theUrl==null)
    theUrl = this.location.href;

  pos = theUrl.lastIndexOf(".jsp");
  if (pos<0)
    theUrl = "/index.jsp";
  else {
    pos = theUrl.lastIndexOf("?");
    if (pos>0)
      theUrl = theUrl.substring(0,pos);

    // (21.03.07 AP)
    // "echte" Url abschneiden
    pos = theUrl.lastIndexOf("/");
    if (pos>0)
      theUrl = theUrl.substring(pos);
  }
  // (26.06.08 AP)
  // Sucheinstiege filtern!!!!
  if (theUrl.indexOf(".htm")>0)
    theUrl = "/ergebnis.jsp";

  key = getKey(extrakey);
  if (key.substring(0,2)=="?&")
    key="?"+key.substring(2);

  // alert(theUrl+key);
  this.location.href = theUrl+key;


  if (infourl!=null && infoframe!=null)
    infoframe.location.href = infourl+key;

  // wenn es die Funktion gibt, dann auch aufrufen...
  // alert(parent.fuss+"  "+parent.fuss.checkHistoryButtons);
  if ( parent.fuss
    && parent.fuss.checkHistoryButtons)
    parent.fuss.checkHistoryButtons();
}

// // // // // // // // // // // // // // // // // // // // // // // // // // //


function openSearchForm(typ)
{
  if (suchform==null)
    suchform=document.forms[0];
  suchform.suchtyp.value=typ;
  OpenNextSearch();
}

// // // // // // // // // // // // // // // // // // // // // // // // // // //

function OpenResult(extrakey)  {
  parent.links.location.href = listeUrl+getKey(extrakey);
}

// // // // // // // // // // // // // // // // // // // // // // // // // // //

function getURL(theUrl,extrakey)  {
  return theUrl+getKey(extrakey);
}

// // // // // // // // // // // // // // // // // // // // // // // // // // //

function OpenResultWith(query)  {
  var url = listeUrl+"?"+query;
  parent.links.location.href = url;
}

// // // // // // // // // // // // // // // // // // // // // // // // // // //

function getKey(extrakey)  {
  var startkey = null;
  var key = "";
  var temp = null;
  var i=0;

  // WORKARROUND !!!!'
  // diese Zeile LÖSCHEN !!!!!
  suchform = document.forms[0];

  // Auswahlen
  if (suchform.elements != null)    // IE
  {
    for(i=0;i<suchform.length;i++)
    {
      temp = suchform.elements[i].name+"=";

      // Hidden, Text und Einzeldropdowns/Selects
      if ( suchform.elements[i].type=="hidden"
        || suchform.elements[i].type=="select-one"
        || suchform.elements[i].type=="text" )
      {
        if (key==null)
          key = "";
        else
          key += "&";
        key+=temp+suchform.elements[i].value;
      }
      else // Checkboxen, nur wenn gecheckt
      if ( suchform.elements[i].type=="checkbox"
        && suchform.elements[i].checked )  {
        if (key==null)
          key = "";
        else
          key += "&";
        key+=temp+suchform.elements[i].value;
      }
    }
  } else
    alert("Laß Dir was einfallen...");
  // was sonst noch ?
  if(extrakey!=null && extrakey.length>0)
    key = extrakey+"&"+key;
  // alert(startkey+key);
  return "?"+key;
}

// // // // // // // // // // // // // // // // // // // // // // // // // // //

function Reset()  {
  var cid = null;
  var url = location.href;
  var pos = 0;

  if (suchform.cid)
    cid = suchform.cid.value;

  pos = url.indexOf("?");
  if (pos>0)
    url = url.substring(0,pos);
  url+="?cid="+cid;
  location.href = url;
}

// // // // // // // // // // // // // // // // // // // // // // // // // // //

function InfoAendern(text) {
  var iTxt = document.getElementById("infotext");  // document.all.infotext
  iTxt.innerHTML = text;
}

function HideInfo(text) {
  var iTxt = document.getElementById("infotext");  // document.all.infotext
  iTxt.style.display = "none";
}

// // // // // // // // // // // // // // // // // // // // // // // // // // //

// bmw-uebergreifende standard-funktion mit zentrierung
function centerPopup(popup_name,popup_url,popup_with,popup_height,myWidth,myHeight,myScrollbar) {
	if(!myWidth) {myWidth = 10;}
	if(!myHeight){myHeight = 50;}
	if(!myScrollbar){myScrollbar = 0;}
	var popup_left = (window.screen.width/2)  - (popup_with/2 + myWidth);
	var popup_top  = (window.screen.height/2) - (popup_height/2 + myHeight);
	window.open(popup_url ,popup_name,"toolbar=no,location=no,status=no,menubar=no,scrollbars=" + myScrollbar + ",resizable=no,width=" + popup_with + ",height=" + popup_height + ",left=" + popup_left + ",top=" + popup_top + ",screenX=" + popup_left + ",screenY=" + popup_top);
}

// // // // // // // // // // // // // // // // // // // // // // // // // // //
