var count=0;
var schleife=0;
var schleife2=0;
var newvehicle;
var oldvehicle="-";

var newvehiclesearch;
var oldvehiclesearch="-";
var newvideosearch;
var oldvideosearch="-";

var newvideonavigation;
var oldvideonavigation="-";


var newlast;
var oldlast="-";
var newvideo;
var oldvideo="-";

var newvideolast;
var oldvideolast="-";

var timer;
var tInterval;
var sInterval;
var suchtextinputrequest='';
var searchaktiv=0;
var keycodepressed;
var start=0;
var startd=0;
var order='';
var sort='';
var orderalt='';

var host = self.location.hostname;

function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      }
    return xmlHttp;
}


function Tastendruck (Ereignis) {
	start=0;

    if (!Ereignis){
    	Ereignis = window.event;
    	keycodepressed=0;
	}else if (Ereignis.keyCode==13){
        keycodepressed=Ereignis.keyCode;
    }else{
    	keycodepressed=0;
    }
}


function autoSuggest(suchtextinput,sucheaktiviert){

	var suchtextinputrequestneu =suchtextinput;
	suchtextinputrequest =suchtextinput;
	if(sucheaktiviert==1){
		 searchaktiv=1;

	}
    timer=0;
    window.clearInterval(tInterval);
    window.clearInterval(sInterval);

	if(keycodepressed == 13 || searchaktiv==1){
		searchaktiv=1;

	}
    tInterval=window.setInterval("autoSuggestSecond('"+suchtextinputrequestneu+"');", 100);


}
document.onkeypress = Tastendruck;


function autoSuggestSecond(suchtextinputrequestneu){
	timer++;
	suchtextinputrequest = suchtextinputrequestneu;
    if(timer==3){
    	if(autoSuggestRequest(suchtextinputrequestneu)){
    		timer=0;
    		window.clearInterval(tInterval);
    	}
    }else if (timer>3){
    	  timer=0;
		  window.clearInterval(tInterval);
    }
}

function autoSuggestRequest(suchtextinputrequestneu){


	suchtextinputrequest = suchtextinputrequestneu;
    if(document.getElementById("suggestBox")&& timer!=0){
        var xmlHttp1= GetXmlHttpObject();
        xmlHttp1.onreadystatechange=function(){
            if(xmlHttp1.readyState==4){
            	if(xmlHttp1.responseText.length>8){
            	var ergebnis = parseFloat(xmlHttp1.responseText.substr(0,8))-10000000;
            	document.getElementById("searchbutton").value=ergebnis+" Autos anzeigen";
            	
                }
                document.getElementById("suggestBox").innerHTML=xmlHttp1.responseText.substr(8,xmlHttp1.responseText.length);
                timer=0;
                window.clearInterval(sInterval);
                schleife=0;
                ajaxFunction();
                return true;
            }
        }
        xmlHttp1.open("GET","http://"+host+"/activeContent/autosuggest.php?st="+suchtextinputrequestneu+"",true);
        xmlHttp1.send(null);

    }
    return false;
}



function ajaxFunction(){

	if(searchaktiv==1)
		ajaxFunction2();
	else{


        if(document.getElementById("newVehicles")){
            var xmlHttp= GetXmlHttpObject();
            xmlHttp.onreadystatechange=function(){

                if(xmlHttp.readyState==4){

                    newvehicle=xmlHttp.responseText;

                    if(newvehicle!=oldvehicle){
                        oldvehicle=newvehicle;
                        var xmlHttp1= GetXmlHttpObject();
                        xmlHttp1.onreadystatechange=function(){
                            if(xmlHttp1.readyState==4){
                                document.getElementById("newVehicles").innerHTML=xmlHttp1.responseText;

                                return true;

                            }
                        }
                        xmlHttp1.open("GET","http://"+host+"/activeContent/autos.php?st="+suchtextinputrequest+"",true);
                        xmlHttp1.send(null);
                    }
                }

            }
            xmlHttp.open("GET","http://"+host+"/activeContent/autos.php?check=1&st="+suchtextinputrequest+"",true);
            xmlHttp.send(null);
        }

        if(document.getElementById("lastView")){
            var xmlHttpLV= GetXmlHttpObject();
            xmlHttpLV.onreadystatechange=function(){

                if(xmlHttpLV.readyState==4){

                    newlast=xmlHttpLV.responseText;

                    if(newlast!=oldlast){


                        oldlast=newlast;
                        var xmlHttpLV2= GetXmlHttpObject();
                        xmlHttpLV2.onreadystatechange=function(){
                            if(xmlHttpLV2.readyState==4){
                                document.getElementById("lastView").innerHTML=xmlHttpLV2.responseText;
                                return true;
                            }
                        }
                        xmlHttpLV2.open("GET","http://"+host+"/activeContent/autos.php?lastview=1&st="+suchtextinputrequest+"",true);
                        xmlHttpLV2.send(null);
                    }
                }
            }
            xmlHttpLV.open("GET","http://"+host+"/activeContent/autos.php?lastviewcheck=1&st="+suchtextinputrequest+"",true);
            xmlHttpLV.send(null);
        }
        if(document.getElementById("videoCars")){
            var xmlHttpVC= GetXmlHttpObject();
            xmlHttpVC.onreadystatechange=function(){

                if(xmlHttpVC.readyState==4){

                    newvideo=xmlHttpVC.responseText;

                    if(newvideo!=oldvideo){
                        oldvideo=newvideo;
                        var xmlHttpVC2= GetXmlHttpObject();
                        xmlHttpVC2.onreadystatechange=function(){
                            if(xmlHttpVC2.readyState==4){
                                document.getElementById("videoCars").innerHTML=xmlHttpVC2.responseText;
                                return true;
                            }
                        }
                        xmlHttpVC2.open("GET","http://"+host+"/activeContent/autos.php?videocars=1&st="+suchtextinputrequest+"",true);
                        xmlHttpVC2.send(null);
                    }
                }
            }

            xmlHttpVC.open("GET","http://"+host+"/activeContent/autos.php?videocarscheck=1&st="+suchtextinputrequest+"",true);
            xmlHttpVC.send(null);
        }
        if(document.getElementById("lastVideoView")){
            var xmlHttpLVV= GetXmlHttpObject();
            xmlHttpLVV.onreadystatechange=function(){

                if(xmlHttpLVV.readyState==4){

                    newvideolast=xmlHttpLVV.responseText;

                    if(newvideolast!=oldvideolast){
                        oldvideolast=newvideolast;
                        var xmlHttpLVV2= GetXmlHttpObject();
                        xmlHttpLVV2.onreadystatechange=function(){
                            if(xmlHttpLVV2.readyState==4){
                                document.getElementById("lastVideoView").innerHTML=xmlHttpLVV2.responseText;
                                return true;
                            }
                        }
                        xmlHttpLVV2.open("GET","http://"+host+"/activeContent/autos.php?lastvideoview=1&st="+suchtextinputrequest+"",true);
                        xmlHttpLVV2.send(null);
                    }
                }
            }
            xmlHttpLVV.open("GET","http://"+host+"/activeContent/autos.php?lastvideoviewcheck=1&st="+suchtextinputrequest+"",true);
            xmlHttpLVV.send(null);
        }
        if(document.getElementById("videoNavigation")){
        	if(document.getElementById('videoKat')){
                var videokattext=document.getElementById('videoKat').value;

            }
            document.getElementById("videoNavigation").style.visibility='visible';
            var xmlHttpVN= GetXmlHttpObject();
            xmlHttpVN.onreadystatechange=function(){

                if(xmlHttpVN.readyState==4){

                    newvideonavigation=xmlHttpVN.responseText;

                    if(newvideonavigation!=oldvideonavigation){
                        oldvideonavigation=newvideonavigation;

                        var videoanzarray = newvideonavigation.split("-");
                        videoanz=videoanzarray[0];
                        document.getElementById("videoanztext").innerHTML="Anzahl AutoVideos im Archiv insgesamt: "+videoanz;
                        var xmlHttpVN2= GetXmlHttpObject();
                        xmlHttpVN2.onreadystatechange=function(){
                            if(xmlHttpVN2.readyState==4){
                                document.getElementById("videoNavigation").innerHTML=xmlHttpVN2.responseText;
                                return true;
                            }
                        }
          	xmlHttpVN2.open("GET","http://"+host+"/activeContent/videos.php?videonavigation=1&start="+start+"&kat="+videokattext,true);
                        xmlHttpVN2.send(null);
                    }
                }
            }

            xmlHttpVN.open("GET","http://"+host+"/activeContent/videos.php?videonavigationcheck=1&start="+start+"&kat="+videokattext,true);
            xmlHttpVN.send(null);
        }


        if(schleife==0){
            schleife=1;
            callAjaxFunction();
        }
    }

}

function callAjaxFunction(){

sInterval=setInterval("if(ajaxFunction());",20000);

}

function setStart(startvalue){
	start=startvalue;
	ajaxFunction2();
}
function setStartD(startvalue){
	startd=startvalue;
	ajaxFunction3();
}
function setOrder(ordervalue){
	if(orderalt!=ordervalue)
		sort=' ASC';
	else if(orderalt==ordervalue && sort==' ASC')
        sort=' DESC';
    else
		sort=' ASC';


	orderalt=ordervalue;
	order=ordervalue;



	ajaxFunction3();
}
function setVideoKat(videokat){
	start=0;
	document.getElementById("videoKat").value=videokat;
	ajaxFunction();
}


function setOrder2(ordervalue){
	if(orderalt!=ordervalue)
		sort=' ASC';
	else if(orderalt==ordervalue && sort==' ASC')
        sort=' DESC';
    else
		sort=' ASC';


	orderalt=ordervalue;
	order=ordervalue;



	ajaxFunction2();
}

var videospernavi=6;
function setStartVideo(navigation){

	start=start+(videospernavi*navigation);



	if(start>=videoanz)
        start=0

	if(start<0){

		start=videoanz-(videoanz%videospernavi);

        if(start==videoanz)
            start=videoanz-videospernavi;

	}





	ajaxFunction();
}

var durchlauf=1;
function ajaxFunction2(){

   // document.getElementById("contentBox").innerHTML="<div class='leftbox2'><div class='boxtitle2'>Ihr Suchergebnis</div><div id='newVehicles'></div></div><div class='leftbox'><div class='boxtitle'>Davon mit Videos</div><div id='videoCars' ></div></div>";


	if (document.getElementById("lastViewBox")){
        var Knoten = document.getElementById("lastViewBox");
        document.getElementById("contentBox").removeChild(Knoten);
    }
    if(document.getElementById("lastVideoViewBox")){
    	var Knoten = document.getElementById("lastVideoViewBox");
        document.getElementById("contentBox").removeChild(Knoten);
    }
	if (document.getElementById("newVehiclesBox")){
        var Knoten = document.getElementById("newVehiclesBox");
        document.getElementById("contentBox").removeChild(Knoten);
    }
    if(document.getElementById("videoCarsBox")){
    	var Knoten = document.getElementById("videoCarsBox");
        document.getElementById("contentBox").removeChild(Knoten);
    }
    //document.getElementById("lastVideoViewBox").outerHTML="";
	//document.getElementById("newVehiclesBox").className="leftbox2";
	//document.getElementById("videoCarsBox").class="";





	if(document.getElementById("newVehiclesBoxSuche")){
		document.getElementById("newVehiclesBoxSuche").style.visibility='visible';
        var xmlHttp= GetXmlHttpObject();
        xmlHttp.onreadystatechange=function(){

            if(xmlHttp.readyState==4){

                newvehiclesearch=xmlHttp.responseText;
                if(newvehiclesearch!=oldvehiclesearch){
                    oldvehiclesearch=newvehiclesearch;
                    var xmlHttp1= GetXmlHttpObject();
                    xmlHttp1.onreadystatechange=function(){
                        if(xmlHttp1.readyState==4){
                            document.getElementById("newVehiclesBoxSuche").innerHTML=xmlHttp1.responseText;
                            return true;

                        }
                    }
                    xmlHttp1.open("GET","http://"+host+"/activeContent/suche.php?order="+order+"&sort="+sort+"&newvehicles=1&st="+suchtextinputrequest+"&start="+start,true);
                    xmlHttp1.send(null);
                }
            }

        }
        xmlHttp.open("GET","http://"+host+"/activeContent/suche.php?order="+order+"&sort="+sort+"&check=1&newvehicles=1&st="+suchtextinputrequest+"&start="+start,true);
        xmlHttp.send(null);
    }
	if(document.getElementById("videoCarsBoxSuche")){
		document.getElementById("videoCarsBoxSuche").style.visibility='visible';
        var xmlHttpVC= GetXmlHttpObject();
        xmlHttpVC.onreadystatechange=function(){

            if(xmlHttpVC.readyState==4){

                newvideosearch=xmlHttpVC.responseText;

                if(newvideosearch!=oldvideosearch){
                    oldvideosearch=newvideosearch;
                    var xmlHttpVC2= GetXmlHttpObject();
                    xmlHttpVC2.onreadystatechange=function(){
                        if(xmlHttpVC2.readyState==4){
                            document.getElementById("videoCarsBoxSuche").innerHTML=xmlHttpVC2.responseText;
                            return true;
                        }
                    }
                    xmlHttpVC2.open("GET","http://"+host+"/activeContent/suche.php?order="+order+"&sort="+sort+"&videocars=1&st="+suchtextinputrequest+"&start="+start,true);
                    xmlHttpVC2.send(null);
                }
            }
        }

        xmlHttpVC.open("GET","http://"+host+"/activeContent/suche.php?order="+order+"&sort="+sort+"&videocarscheck=1&st="+suchtextinputrequest+"&start="+start,true);
        xmlHttpVC.send(null);
    }


    if(schleife2==0){
        schleife2=1;
        callAjaxFunction2();
    }

}






function callAjaxFunction2(){

sInterval=setInterval("if(ajaxFunction2());",20000);

}
function confirmSuggest(suchtextsuggest){



    var suchtextinputrequestneu=suchtextsuggest;
    suchtextinputrequest=suchtextsuggest;
    
	document.getElementById('suchtext').value=suchtextsuggest;
	document.getElementById("suggestBox").innerHTML="";
	ajaxFunction();


}
function startplayer(videoidnavi,linktext,datum,filmlaenge,clickgesamt,bild,haendler){


	document.getElementById("linktexttext").innerHTML=linktext;
	document.getElementById("moviedatum").innerHTML=datum;
	document.getElementById("movielaenge").innerHTML=filmlaenge;
	document.getElementById("movieclicks").innerHTML=clickgesamt;
	document.getElementById("movielink").innerHTML='<a href="videoarchiv.php?id='+videoidnavi+'">Link zu diesem Video</a>';
	document.getElementById("movielinktext").value='http://www.autopod.de/videoarchiv.php?id='+videoidnavi



	window.document.title="Auto Video "+linktext+" autopod.de Fahrzeugvideo";

	player.location.href='videonojs.php?id='+videoidnavi+'&bildm='+bild;

	var typetext = linktext.split(" ");

	if(typetext[0]!=''){

		related.location.href='relatedvideos.php?type='+typetext[0]+'&type2='+typetext[1];
		dealer.location.href='dealer.php?dealer='+haendler;

	}



//window.setTimeout("player.location.href='videonojs.php?id="+videoidnavi+"&play=1'",500);
}
function startplayerparent(videoidnavi,linktext,datum,filmlaenge,clickgesamt,bild,haendler){


	parent.document.getElementById("linktexttext").innerHTML=linktext;
	parent.document.getElementById("moviedatum").innerHTML=datum;
	parent.document.getElementById("movielaenge").innerHTML=filmlaenge;
	parent.document.getElementById("movieclicks").innerHTML=clickgesamt;
	parent.document.getElementById("movielink").innerHTML='<a href="videoarchiv.php?id='+videoidnavi+'">Link zu diesem Video</a>';
	parent.document.getElementById("movielinktext").value='http://www.autopod.de/videoarchiv.php?id='+videoidnavi



	parent.document.title="Auto Video "+linktext+" autopod.de Fahrzeugvideo";

	parent.player.location.href='videonojs.php?id='+videoidnavi+'&bildm='+bild;
	parent.dealer.location.href='dealer.php?dealer='+haendler;




//window.setTimeout("player.location.href='videonojs.php?id="+videoidnavi+"&play=1'",500);
}
function ajaxFunction3(){



    if(document.getElementById("newVehiclesBoxDealer")){




        var xmlHttpVD= GetXmlHttpObject();
        xmlHttpVD.onreadystatechange=function(){
            if(xmlHttpVD.readyState==4){
                document.getElementById("newVehiclesBoxDealer").innerHTML=xmlHttpVD.responseText;
                return true;
            }
        }

        xmlHttpVD.open("GET","http://"+host+"/activeContent/dealer.php?order="+order+"&sort="+sort+"&start="+startd+"&dealer="+dealer,true);
        xmlHttpVD.send(null);

    }


}

function advertshow(){
	var nix;

	nix=window.open("videoadvert.php?videofile=mittevoiceover.mp4","nix","width=520,height=288,left=300,top=200,scrollbars=no,resizable=no,menubar=no, status=no,toolbar=no");

	window.setTimeout("if(!nix){advertshow2()}",500);
}

function advertshow2(){

	document.getElementById("advertshow").innerHTML="<div style='width:520px;background-color:#ffffff'><div style='width:520px;text-align:right;cursor:pointer;' onclick='document.getElementById(\"advertshow\").innerHTML=\"\"'>X SCHLIESSEN</div><div style='width:520px'><iframe src='videoadvert.php?videofile=mittevoiceover.mp4' marginheight='0' marginwidth='0' scrolling='no' frameborder='0' width='520' height='288'></iframe></div></div>";


}
