//var bild0 = new Image(); bild0.src = "pic/_merch.gif";
//var bild1 = new Image(); bild1.src = "pic/_merch_.gif";

function swap(time, time2)
{
  if ((document.images) )// && (!(document.all)) )
	{
// alert(time + " : " + time2 +" : " + top.PIC.window.document.images.HOME.src);
//		        window.document.images[Bildnr].src
 	if( time2 > 50 )
	  {
	  timval="top.PIC.swap(" + time2 + " , 1)"
	  setTimeout(timval, time);
	  }
	else if(time > 50 )
	  {
//	  top.PIC.document.images[0].src = bild1.src ;
	  top.PIC.window.document.images.HOME.src = bild1.src ;
	  setTimeout("top.PIC.swap( 1, 1 )", time);
	  }
	else
	  {
//	  top.PIC.document.images[0].src = bild0.src ;
	  top.PIC.window.document.images.HOME.src = bild0.src ;
	  }
	}
}

var carselect= new Array(20);
var picshow= new Array(100);
var 	listframe="", 
	frameinhalt=0, ixg=0, dir=0, ixk=0,
  	bild="", link="", temp="",
	texttotal="",  pictotal= "",
	textentry= "", textlink=  "",
	linktotal= "", historylist="",
	Faxname="", Faxtel="", Faxemail="", 
	SelectedCar="",SelectedFile="",
	pending=0	;


function xCheckId (link, titel, id, pic, text, jg, fr, km, ztxt)
{
if((top.LIST) && (top.DIR.document.title != 'History'))
  {
    with(top.LIST)
    {
    i =(link).lastIndexOf("?");
    if(i>0) 
      {
      n=(link).substring(i+1,(link).length) ;
// alert(n +'  '+ link);
      if((id == n) || (id == '---') )
  	{
  	top.PIC.listframe=('<CENTER><HR><B>'
		+ '<A HREF="'
		+ link.substring(0,i)
		+ '" TARGET = "MAIN" >'
		+ '<IMG SRC="pic/pfeil_r.gif" BORDER=0><BR>'
		+ titel
		+ '</A><BR>'
		+ '<BR><IMG SRC="'
		+ pic + '"><BR><BR>'
		+ text +'<HR>'
		+ fr + '</B><BR>' + jg + '<BR>' + km 
		+ '<HR>'
		+ ztxt
		+ '<BR><BR><BR></BODY></HTML>'
		);
    	top.DIR.document.close();
   	top.DIR.document.open();
    	top.DIR.document.write('<HTML><HEAD><TITLE>Fahrzeugdetails</TITLE></HEAD><BODY BACKGROUND="_a.jpg" BGCOLOR="#FFFFCC" TEXT="#000000" VLINK="#0000C0" LINK="#800000"><BASE TARGET="MAIN">');
    	top.DIR.document.write(top.PIC.listframe);
    	top.DIR.document.close();
	top.PIC.AddToHistory(link,titel,pic)
	top.LIST.window.history.back();
	}
      }
    }
  }
}

var blink="", ixblink=0, blinkcount=0;

function PicSwap(param)
{
  if ((document.images) && (top.MAIN) )
    {
    if(param >1)
	{
	blinkcount=param;
	}

// alert(ixblink + " : " + blink );
    if(blink != top.MAIN.location.href)
      {
      blink=""; ixblink=0; 
      }
    else
      {
      if((top.MAIN.window.document.images.length > ixblink) && (ixblink >0))
	{	  
	if(param == 0)
	  {
	  top.MAIN.document.images[ixblink].src = "pic/_xw.gif" ;
	  idblink=setTimeout("PicSwap(1)", 400);
	  }
	else
	  {
	  top.MAIN.document.images[ixblink].src = "pic/_xb.gif" ;
	  if(blinkcount-- > 0)
	    {
	    idblink=setTimeout("PicSwap(0)", 400);
	    }
	  }

	}
      }
    }
}


function Bilder(linkurl)
{
//	alert (top.MAIN.window.document.images.length);
ixblink=0;
for(var i=0; i<100; i++)
	{
	picshow[i]=0;
	}
if((top.PIC) && (top.MAIN))
  {
  linkurl  = linkurl.substring(linkurl.lastIndexOf("/") + 1, linkurl.length);
  linkfile = linkurl.substring(0,linkurl.indexOf("?"));
	j=0;
    	for(var i=0; i < top.MAIN.window.document.images.length ; i++) 
	  {
	  bild=(top.MAIN.window.document.images[i].src).substring(top.MAIN.window.document.images[i].src.lastIndexOf("/") + 1, (top.MAIN.window.document.images[i].src).length);
	  bildtst=bild.substring(0,2);
//alert(bildtst);
	  if(bildtst == "_x")
	    {
	    picshow[i]=1;
	    bild= "_x.gif";
	    while(j < top.MAIN.window.document.links.length)
		{
		temp="" + top.MAIN.window.document.links[j++] ;
// alert(temp);
		link=(temp).substring(temp.lastIndexOf("/") + 1, temp.length);
		if(link.lastIndexOf("?") < 5)
			link="";
		else if(linkfile != (link.substring(0, link.indexOf("?")) ) )
			link="";
	  	
		else if(link != "")
		  {
		  if(link == linkurl)
			{
			bild= "_x.gif";
			if( (i+1) < top.MAIN.window.document.images.length )
			  {
	   		  bild=(top.MAIN.window.document.images[i+1].src).substring(top.MAIN.window.document.images[i+1].src.lastIndexOf("/") + 1, (top.MAIN.window.document.images[i+1].src).length);
			  if(bild[0] == "_")
			    {
			    bild= "_x.gif";
			    }
			  else
			    {
			    blink=top.MAIN.location.href;
			    ixblink=i;
			    for(i=0; i < ixblink; i++)
				{
				if(picshow[i]==1)
				  {
	  			  top.MAIN.document.images[i].src = "pic/_xg.gif" ;
				  }		
				}
			    }
			  }
		  	return(bild);
			}
		  link = "";
		  break;
		  }
		}
	    }
	  }
  }
return("_x.gif");
}

function Mailtest()
  {
  Faxname =top.MAIN.document.forms.Faxmail.Name.value;
  Faxtel  =top.MAIN.document.forms.Faxmail.Tel.value;
  Faxemail=top.MAIN.document.forms.Faxmail.email.value;
  if(SelectedFile == top.MAIN.document.forms.Faxmail.file.value.substring(0,7))
	{
  	top.MAIN.document.forms.Faxmail.Auto.value = SelectedCar;
	}
  return true;
  }

function AddMail()
  {
  if((top.PIC) && (top.MAIN))
    {
    if(top.PIC.carselect)
      {
      if(top.MAIN.document.forms)
	{
        if(top.MAIN.document.forms.Faxmail)
	  {
          if(top.MAIN.document.forms.Name)
	    {
	    top.MAIN.document.forms.Faxmail.Name.value =Faxname;
	    top.MAIN.document.forms.Faxmail.Tel.value  =Faxtel;
	    top.MAIN.document.forms.Faxmail.email.value=Faxemail;
	    }
	  }
	}
      }
    }
  }

function SelCar(href, pic, picw, pich, modell, jg, fr, km, text )
{
if((picw > 0) && (pich >0)) pic= '<IMG SRC="'+ pic + '" WIDTH=' + picw + ' HEIGHT=' + pich + '>';
else	pic='<IMG SRC="pic/_empty.gif"WIDTH=120 HEIGHT=1>';
	//									alert (top.MAIN.location.href.lastIndexOf("?")+4)
if(href == top.MAIN.location.href.substring(top.MAIN.location.href.lastIndexOf("/")+1, top.MAIN.location.href.lastIndexOf("?")+4))
  {
  SelectedCar=modell;
  SelectedFile=href.substring(0,7);
  top.MAIN.document.write( '<TABLE BORDER=0 CELLPADDING=5 CELLSPACING=0 WIDTH=100%>'
  + '<TR BGCOLOR="#F0F0F0"><td colspan=2>&nbsp;</td><td colspan=4><small>Gew&auml;hltes Fahrzeug:</small></td></tr>'
  + '<TR BGCOLOR="#F0F0F0"><TH ROWSPAN=2>&nbsp;</TH><TH ROWSPAN=2 >'+ pic +'&nbsp;</TD><TD WIDTH=80%><B>' + modell + '</b></td><td>' + jg + '</td><td>' + fr + '</td><td>' + km + '</td></tr>'
  + '<TR BGCOLOR="#F0F0F0"><td COLSPAN=4>' + text + '&nbsp;</TD></TR>'
  + '</TABLE><HR><BR>' );
//alert(href + ' --- ' + top.MAIN.location.href.substring(top.MAIN.location.href.lastIndexOf("/")+1, top.MAIN.location.href.length ));
  if(top.MAIN.document.forms.Faxmail)
	{
  	top.MAIN.document.forms.Faxmail.Name.value =Faxname;
	}
  }
}

function AddHistory()
  {
  if((top.PIC) && (top.MAIN))
    {
    if(top.PIC.carselect)
      {
//      CheckFrames();
      ixblink=0;
      textentry = ""; 

      if(  (((top.MAIN.location.href).lastIndexOf("&") +1 ) != (top.MAIN.location.href).length)
	&& ((top.MAIN.location.href).lastIndexOf("?") > 3 )  )

        {
        picsrc = top.PIC.Bilder(top.MAIN.location.href);
//		alert(picsrc);
	if(picsrc == "_x.gif")
		{
		return;
		}
 	top.PIC.AddToHistory(top.MAIN.document.title, "pic/" + picsrc, top.MAIN.location.href); 
	}
      }
    }
  }

var textcheck, outcheck;
function AddToHistory(titel,bild,filename)
  {
  if(top.PIC.carselect)
	{
        var i,j, used = -1 ;
	// Der ewige Mist mit uuml
	if(titel.substring(0,titel.indexOf("-")) =='Auto Occasionen ')
	  {
	  titel=titel.substring(titel.indexOf("-")+1, titel.length);
	  }
	for(i=0; i<titel.length; i++)
	  {
	    j=titel[i] ;
	    if(j == 'Ä') j='&Auml;';
	    if(j == 'Ö') j='&Ouml;';
	    if(j == 'Ü') j='&Uuml;';
	    if(j == 'ä') j='&auml;';
	    if(j == 'ö') j='&ouml;';
	    if(j == 'ü') j='&uuml;';
	    if(j != titel[i])
		{
//			alert(j);
		titel=titel.substring(0,i)+ j + titel.substring(i+1,titel.length);
		}
	  }
//alert(filename);
        top.PIC.textcheck= filename.substring(filename.lastIndexOf("/")+1,filename.length) + "@" + bild + "@" +  titel;
//	outcheck=textcheck + "\n\n";
        for (i=0; i< (top.PIC.carselect.length); i++)
          {
//	  outcheck=outcheck + top.PIC.carselect[i] +"\n";
          if(top.PIC.carselect[i] == top.PIC.textcheck)
                {
                used = i;
		break;
                }
          }
        if(used > 0)
          {
          for (i=used; i > 0; i--)
                {
                top.PIC.carselect[i] = top.PIC.carselect[i-1];
                }
          }
        if(used < 0)
	  {
//alert(i + " [" + top.PIC.textcheck +"]");
          for (i=top.PIC.carselect.length-1; i > 0 ; i--)
                {
                top.PIC.carselect[i] = top.PIC.carselect[i-1];
                }
          }
        top.PIC.carselect[0] = top.PIC.textcheck;
	PicSwap(15);
        if(frameinhalt == 0) 
          { 
          frameinhalt=1;
          }
//        alert("AddHistory " + frameinhalt);
          SetIxkframe(frameinhalt); //

        }
  }

function ClearHistory()
{
var i;
for (i=0; i < top.PIC.carselect.length ; i++)
  {
  top.PIC.carselect[i] = "";
  }
frameinhalt=0;
// DisplayHistory();
}


function SetDirframe(param)
{
if(top.DIR)
  {
  dir=param;
  if( dir == 0)
	{
      	top.DIR.window.location.replace("_ix.htm");
	}
  }
}

function SetIxgframe(param)
{
if(top.IXG)
  {
  ixg=param;
  if(ixg == 0)
	{
      	top.IXG.window.location.replace("_ixf.htm");
	}
  }
}

function SetIxkframe(param)
{
if(top.IXK)
  {
  ixk=param; 
  if(ixk == 0)
	{
      	top.IXK.window.location.replace("_bordery.htm");
	}
  if(ixk > 0)
	{
      	top.IXK.window.location.replace("_ixk1.htm");
	}
  if(ixk < 0)
	{
      	top.IXK.window.location.replace("_ixk0.htm");
	}
  }
}

function DisplayHistory()
{
if((top.IXG) && (top.DIR))
  {
  if (carselect[0] == "")
    {
    frameinhalt=0; 
    SetDirframe(0);
    SetIxgframe(0);
    SetIxkframe(0);
    }
  else
    {
//	alert(ixg +" "+ frameinhalt);

//  alert(frameinhalt +":"+ dir +","+ ixg +","+ ixk +"," ); 

//    if(frameinhalt == 0) //init
//    	{
//	frameinhalt=1; 
//	dir=0; //SetDirframe(0);
//	ixg=1; //SetIxgframe(1);
//	SetIxkframe(1);
//	}


//	alert("ixk:"+ ixk +" "+ frameinhalt);

    CreateText();

//	alert(ixk +" "+ frameinhalt);

    if(frameinhalt >0 )
      {
//      with(top.IXG.document)
    	{
//	alert("Display.IXG");
    	top.IXG.document.close();
    	top.IXG.document.open("text/html","replace");
        top.IXG.document.write(texttotal);
	top.IXG.document.close();
	}
      }
    else
      {
//      with(top.DIR.document)
    	{
//	alert("Display.DIR");
    	top.DIR.document.close();
    	top.DIR.document.open("text/html","replace");
        top.DIR.document.write(texttotal);
	top.DIR.document.close();
	}
      }
    }
  pending=0;
  }
}


function CreateText()
{
    var i,j,k,l,t;

    textlink=location.href.substring(0,location.href.lastIndexOf("/")+1 );
    texttotal="<HTML><HEAD><TITLE>History</TITLE></HEAD><BASE TARGET=\"MAIN\"><BODY BACKGROUND=\"_a0x.gif\" BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\" VLINK=\"#0000C0\" LINK=\"#800000\"><CENTER>"
	+ "<TABLE BORDER=0><TR><TD>&nbsp;&nbsp;&nbsp;&nbsp;</TD><TD ALIGN=CENTER><FONT SIZE=1 FACE=\"Arial\",\"Helvetica\" >\n"
	+ "<BR><BR><A HREF=\"/cgi/history.pl?"
	+ textlink
	;

    textentry= "";  textlink=  ""; linktotal= ""; historylist="";
    pictotal= "<BR><BR>";

    for(i=0; i < top.PIC.carselect.length ; i++)
	{
	textentry= "" + top.PIC.carselect[i];
	j= (textentry).indexOf("@");
	if(j > 8)
	    {
//		alert(textentry + " ixk="+ ixk +" frameinhalt="+ frameinhalt);
	    k= (textentry).lastIndexOf("/",j);
	    l= (textentry).lastIndexOf("@");

	    textlink=(textentry).substring(k+1,j);
	    pictotal = pictotal 
	        + "\n <A HREF=\""
	    	+ textlink + '"'// + "&"
//	    	+ ' TARGET="MAIN"'
	    	+ " ><IMG SRC=\""
		+ textentry.substring(j+1, l)
		+ "\" WIDTH=56 VSPACE=2 BORDER=0 ALT=\""
	    	+ textentry.substring(l+1,textentry.length)
		+ "\" >"
		;
  	    if(!(top.DIR.IXDETAILS ))
		{
	    	pictotal = pictotal + "<BR>"
	    	  + textentry.substring(l+1,textentry.length)
		  + "</A><BR><BR>\n"
	    	  ;
		}
	    else
		{
	    	pictotal = pictotal + "</A> &nbsp;&nbsp;&nbsp;" ;
		}
	    texttotal = texttotal + "&" + textlink;

	    }
	}

//	alert(pictotal);
    if(frameinhalt > 0)
	{
	texttotal = texttotal + "\" TARGET=\"MAIN\" ><IMG SRC=\"pic/pfeil_l.gif\" ";
	}
    else
	{
	texttotal = texttotal + "\" TARGET=\"MAIN\" ><IMG SRC=\"pic/pfeil_r.gif\" ";
	}

    texttotal = texttotal + "BORDER=0 ALT=\"Alle Fahrzeuge in einer Liste\" ><BR>History anzeigen</A> " 
	+ linktotal
	+ pictotal
	+ "</TD></TR></TABLE></CENTER><PRE>"
//	+ outcheck
	+ "</PRE></FONT></BODY></HTML>"
	;
}


function CheckFrames()
{
      if(  (top.IXG) && (top.DIR) )
	{
	if (top.IXG.document.title == top.DIR.document.title)
	  {
//		alert("FrameError");
//	  UpdateHistory(0); // history=links, menu=rechts
//	  DisplayHistory();
	  }
	}
}

function LeftHistory()
{
        frameinhalt =-1;
	dir=1;

if (top.IXG.document.title == "History")
		SetIxgframe(0);
top.PIC.DisplayHistory();
}

function RightHistory()
{
	frameinhalt = 1;
	ixg=1;

if (top.DIR.document.title == "History")
	SetDirframe(0);
top.PIC.DisplayHistory();
}

function Update_History(OnOff)
{
if(OnOff > 0)
	{
	top.PIC.frameinhalt =-1;
	top.PIC.dir=-1; //	SetDirframe(-1);
	top.PIC.SetIxgframe(0);
	top.PIC.SetIxkframe(-1);
	}
else 
	{
	top.PIC.frameinhalt =1;
	top.PIC.SetDirframe(0);
	top.PIC.ixg=1; //	SetIxgframe(1);
	top.PIC.SetIxkframe(1);
	}
//  alert("UpdateHistory");
}
