//***********************AJAX - Funktionen******************************//
//*****************Erstellt von Christoph Burth************************//

var DetailDiv, globalCar;

//*********Newsletterregistrierung******************************//
//*********Darstellung der DropDowns zur Fahrzeugauswahl*******//
function typeDropdown(model){
	var requestUrl = "/content/php-bin/ACA/aca_ajaxfunctions.php";
	
	try{
		
		
		var request = new Ajax.Request(
						
						  requestUrl,
						  {
							
							 method:'post',
							 parameters: 'func=typeDropdown&model='+model,
							 onComplete: typdropdownCb
						  }
					  );
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
}


function CleargetCarForProd(id){
	$('scrollThisByCars_'+id).innerHTML = "";
	globalCar = "";
}

function getCarForProd(car, status, id){
	
	globalCar = id;
	$('scrollThisByCars_'+globalCar).innerHTML = "<center><span class = 'LoadingDivSpanText'><br><br>Loading ... </span><br><br><img id='Layer3' src='/Templates/09/pics/loading2.gif' /></center>";
	var requestUrl = "/content/php-bin/ACA/aca_ajaxfunctions.php";
	try{
		
		var request = new Ajax.Request(
						  requestUrl,
						  {
							 method:'post',
							 parameters: 'func=getCarForProd&car='+car+'&status='+status,
							 onComplete: CreategetCarForProd
						  }
					  );
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
	
}

function CreategetCarForProd(response){
	
	try{
		$('scrollThisByCars_'+globalCar).innerHTML = response.responseText;
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}				
	
	
	globalCar = "";
	
}



function getSearchModels(manuf, selected){
	
	//$('useThisCarID').checked = "checked";
	
	var requestUrl = "/content/php-bin/ACA/aca_ajaxfunctions.php";
	try{
		
		var request = new Ajax.Request(
						  requestUrl,
						  {
							 method:'post',
							 parameters: 'func=getSearchModel&manuf='+manuf+'&selected='+selected,
							 onComplete: CreateSearchModel
						  }
					  );
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
	
}


function getSearchModelsHTML(manuf, selected){
	
	//$('useThisCarID').checked = "checked";
	
	var requestUrl = "/content/php-bin/ACA/aca_ajaxfunctions.php";
	try{
		
		var request = new Ajax.Request(
						  requestUrl,
						  {
							 method:'post',
							 parameters: 'func=getSearchModelHTML&manuf='+manuf+'&selected='+selected,
							 onComplete: CreateSearchModelHTML
						  }
					  );
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
	
}



function Clear2StagesNow(){
	$('myCarForSearch_Ausfuehrung').innerHTML = "<div id='myCarForSearch_Ausfuehrung'> \n<select name = 's_Ausfuehrung' id = 'idS_Ausfuehrung' style = 'width:400px;'><option value = '' >w&auml;hlen</option></select></div>";
	$('myCarForSearch_Type').innerHTML = "<div id='myCarForSearch_Type'> \n<select name = 's_type' id = 'idS_type' style = 'width:200px;' ><option value = '' >w&auml;hlen</option></select></div>";
}

function Clear1StagesNow(){
	$('myCarForSearch_Ausfuehrung').innerHTML = "<div id='myCarForSearch_Ausfuehrung'> \n<select name = 's_Ausfuehrung' id = 'idS_Ausfuehrung' style = 'width:400px;'><option value = '' >w&auml;hlen</option></select></div>";
}


function ClearAllStagesNowHTML(){
	
	 
	$('hersteller').selectedIndex = 0;
	$('ModellCell').innerHTML = "<select name = 's_Model' id = 'idS_Model' onChange='Clear1StagesNowHTML(); getSearchTypesHTML(document.getElementById(\"hersteller\").value,this.value);' style = 'width:200px;' ><option value = '' ></option></select>";
	$('AusfuehrungCell').innerHTML = "<div id='myCarForSearch_Ausfuehrung'> \n<select name = 's_Ausfuehrung' id = 'idS_Ausfuehrung' style = 'width:200px;'><option value = '' ></option></select></div>";
	$('TypCell').innerHTML = "<div id='myCarForSearch_Type'> \n<select name = 's_type' id = 'idS_type' style = 'width:200px;' ><option value = '' ></option></select></div>";
}

function Clear2StagesNowHTML(){
	$('AusfuehrungCell').innerHTML = "<div id='myCarForSearch_Ausfuehrung'> \n<select name = 's_Ausfuehrung' id = 'idS_Ausfuehrung' style = 'width:200px;'><option value = '' >w&auml;hlen</option></select></div>";
	$('TypCell').innerHTML = "<div id='myCarForSearch_Type'> \n<select name = 's_type' id = 'idS_type' style = 'width:200px;' ><option value = '' >w&auml;hlen</option></select></div>";
}

function Clear1StagesNowHTML(){
	$('AusfuehrungCell').innerHTML = "<div id='myCarForSearch_Ausfuehrung'> \n<select name = 's_Ausfuehrung' id = 'idS_Ausfuehrung' style = 'width:200px;'><option value = '' >w&auml;hlen</option></select></div>";
}




function CreateSearchModel(response){
	try{
		
		
		
		//$('myCarForSearch_Ausfuehrung').innerHTML = "<div id='myCarForSearch_Ausfuehrung'> \n<select name = 's_Ausfuehrung' id = 'idS_Ausfuehrung' style = 'width:400px;'><option value = '' >w&auml;hlen</option></select></div>";
		//$('myCarForSearch_Type').innerHTML = "<div id='myCarForSearch_Type'> \n<select name = 's_type' id = 'idS_type' style = 'width:200px;' ><option value = '' >w&auml;hlen</option></select></div>";
		$('myCarForSearch_Model').innerHTML = response.responseText;
		
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}				
}



function CreateSearchModelHTML(response){
	try{
		
		$('ModellCell').innerHTML = response.responseText;
		
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}				
}

function selectSearchModels(manuf){
	
	
}

function getSearchTypes(manuf,model,selected){
	
	//alert(manuf);
	//alert(model);
	//alert(selected);
	
	var requestUrl = "/content/php-bin/ACA/aca_ajaxfunctions.php";
	try{
		
		var request = new Ajax.Request(
						  requestUrl,
						  {
							 method:'post',
							 parameters: 'func=getSearchType&manuf='+manuf+'&model='+model+'&myselected='+selected,
							 onComplete: CreateSearchType
						  }
					  );
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
	
}

function getSearchTypesHTML(manuf,model,selected){
	
	//alert(manuf);
	//alert(model);
	//alert(selected);
	
	var requestUrl = "/content/php-bin/ACA/aca_ajaxfunctions.php";
	try{
		
		var request = new Ajax.Request(
						  requestUrl,
						  {
							 method:'post',
							 parameters: 'func=getSearchTypeHTML&manuf='+manuf+'&model='+model+'&myselected='+selected,
							 onComplete: CreateSearchTypeHTML
						  }
					  );
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
	
}



function getSearchAusfuehrung(manuf,model,selected, usethisone){
	
	//alert(manuf);
	//alert(model);
	//alert(selected);
	//alert(usethisone);
	
	var requestUrl = "/content/php-bin/ACA/aca_ajaxfunctions.php";
	try{
		
		var request = new Ajax.Request(
						  requestUrl,
						  {
							 method:'post',
							 parameters: 'func=getSearchAusfuehrung&manuf='+manuf+'&model='+model+'&myselected='+selected+'&usethisone='+usethisone,
							 onComplete: CreateSearchAusfuehrung
						  }
					  );
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
	
}

function getSearchAusfuehrungHTML(manuf,model,selected, usethisone){
	
	//alert(manuf);
	//alert(model);
	//alert(selected);
	//alert(usethisone);
	
	var requestUrl = "/content/php-bin/ACA/aca_ajaxfunctions.php";
	try{
		
		var request = new Ajax.Request(
						  requestUrl,
						  {
							 method:'post',
							 parameters: 'func=getSearchAusfuehrungHTML&manuf='+manuf+'&model='+model+'&myselected='+selected+'&usethisone='+usethisone,
							 onComplete: CreateSearchAusfuehrungHTML
						  }
					  );
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
	
}


function CreateSearchAusfuehrung(response){
	try{

		$('myCarForSearch_Ausfuehrung').innerHTML = response.responseText;
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}				
}


function CreateSearchAusfuehrungHTML(response){
	try{

		$('AusfuehrungCell').innerHTML = response.responseText;
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}				
}

function CreateSearchType(response){
	
	try{
		$('myCarForSearch_Type').innerHTML = response.responseText;
		//$('myCarForSearch_Ausfuehrung').innerHTML = "<div id='myCarForSearch_Ausfuehrung'> \n<select name = 's_Ausfuehrung' id = 'idS_Ausfuehrung' style = 'width:400px;'><option value = '' >w&auml;hlen</option></select></div>";
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}				
}

function CreateSearchTypeHTML(response){
	
	try{
		$('TypCell').innerHTML = response.responseText;
		//$('myCarForSearch_Ausfuehrung').innerHTML = "<div id='myCarForSearch_Ausfuehrung'> \n<select name = 's_Ausfuehrung' id = 'idS_Ausfuehrung' style = 'width:400px;'><option value = '' >w&auml;hlen</option></select></div>";
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}				
}

function typdropdownCb(response){
	try{
		$('typselect').style.visibility = "visible";

		$('typselect').innerHTML = response.responseText;
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
}

function exaktDropdown(type){
	var requestUrl = "/content/php-bin/ACA/aca_ajaxfunctions.php";
	try{
		var request = new Ajax.Request(
						  requestUrl,
						  {
							 method:'post',
							 parameters: 'func=exaktDropdown&type='+type,
							 onComplete: exaktdropdownCb
						  }
					  );
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
}

function exaktdropdownCb(response){
	try{
		
		$('exaktselect').style.visibility = "visible";
		$('exaktselect').innerHTML = response.responseText;
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
}



//********************Userbereich, Warenkorb******************************//
//*********Darstellung der Ebenen zur Adressauswahl und Adressbuch*******//

function DisplayAdress(shipA, index) {
	
	
	if (shipA == 'changeAdress'){
		$('selectAdress').style.visibility = "hidden";
		$('change_adress').style.visibility = "visible";
	}
	
	if (shipA == 'userbereich'){
		
		$('change_adress').style.visibility = "visible";
		$('changeAdress').style.visibility  = "visible";
		if($('divPositioner')) $('divPositioner').style.visibility = "visible";
	}
	
	var requestUrl = "/content/php-bin/ACA/aca_ajaxfunctions.php";
	
	try{
		
		var request = new Ajax.Request(
						  requestUrl,
						  {
							 method:'post',
							 parameters: 'func=changeIt&shipA='+index+'&adress='+shipA,
							 onComplete: showAdress
						  }
					  );

	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
	
}

function showAdress(response){
	
	try{
		$('changeAdress').style.visibility = "visible";
		
		$('change_adress').innerHTML = response.responseText;
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
}


function SaveAdress(id, vorname, nachname, adresse, stadt, plz, telefon, anrede, land) {
	var requestUrl = "/content/php-bin/ACA/aca_ajaxfunctions.php";

	try{
		
		var error = '';
		
		if(vorname.length<1){
			error = 'Bitte geben Sie einen Vornamen ein';	
		}
		if(nachname.length<1){
			error = 'Bitte geben Sie einen Nachname ein';	
		}
		if(adresse.length<2){
			error = 'Bitte geben Sie eine Adresse ein';	
		}
		if(stadt.length<2){
			error = 'Bitte geben Sie eine Stadt ein';	
		}
		if(plz.length<2){
			error = 'Bitte geben Sie eine Postleitzahl ein';
		}
		
		if(anrede.length<2){
			error = 'Bitte waehle eine Anrede aus';	
		}
		if(land.length<2){
			error = 'Bitte waehle ein Land aus';	
		}
		
		if(error.length > 2){ 
			alert (error);
		
		}else{
			//alert ('Juhu');
			var request = new Ajax.Request(
							  requestUrl,
							  {
								 method:'post',
								 parameters: 'func=saveIt&id='+id+'&vorname='+vorname+'&nachname='+nachname+'&adresse='+adresse+'&stadt='+stadt+'&plz='+plz+'&telefon='+telefon+'&anrede='+anrede+'&land='+land,
								 onComplete: useThisNewAdress
							  }
						  );
			
		}

	}
	catch(e){
		alert("Fehlerle: " + e.toString());	
	}
	
}

function useThisNewAdress(response){
	//alert(response.responseText);
	self.location='/shopping_cart.php?shipA='+response.responseText+'&cart=go';
	
}


function CloseIt(response){
	
	try{
		$('changeAdress').style.visibility = "hidden";
		//$('change_Adress').style.visibility = "hidden";
		parent.location.reload();
		DisplayLoginLayer('selectAdress');
				
	}
	catch(e){
		alert("Fehlerle: " + e.toString());	
	}
}


//*********Userbereich******************************//
//*******Darstellung zum ndern der Hauptadresse***//


function DisplayMain(userId) {
	var requestUrl = "/content/php-bin/ACA/aca_ajaxfunctions.php";
	
	
	try{
		
		var request = new Ajax.Request(
						  requestUrl,
						  {
							 method:'post',
							 parameters: 'func=showMain&userId='+userId,
							 onComplete: showMainAdress
						  }
					  );

	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
	
}

function showMainAdress(response){
	
	try{

		$('changeMainAdress').style.visibility = "visible";
		$('change_MainAdress').innerHTML = response.responseText;
		$('change_MainAdress').style.visibility = "visible";
		$('change_MainAdress').style.top = -100+'px';
		$('change_MainAdress').style.postition = 'fixed';
		if($('divPositioner')) $('divPositioner').style.visibility = "visible";
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
}


function changeMainAdress(userId, email, anrede, vorname, nachname, street, adress_plus, city, zip, country, phone, fax, hersteller){
	var requestUrl = "/content/php-bin/ACA/aca_ajaxfunctions.php";
	
	try{
		
		var error = '';
		
		if(email.length<2){
			error = 'Bitte gebe Deine E-Mail ein';	
		}
		if(anrede.length<2){
			error = 'Bitte waehle eine Anrede aus';	
		}
		if(vorname.length<1){
			error = 'Bitte geben Sie einen Vornamen ein';	
		}
		if(nachname.length<1){
			error = 'Bitte geben Sie einen Nachname ein';	
		}
		if(street.length<2){
			error = 'Bitte geben Sie eine Adresse ein';	
		}
		if(city.length<2){
			error = 'Bitte geben Sie eine Stadt ein';	
		}
		if(zip.length<2){
			error = 'Bitte geben Sie eine Postleitzahl ein';
		}
		if(phone.length<2){
			error = 'Bitte geb Deine Telefonnummer ein';	
		}
		
		if(country.length<2){
			error = 'Bitte waehle ein Land aus';	
		}
		
		if(error.length > 2){ 
			alert (error);
		
		}else{
			var request = new Ajax.Request(
						  requestUrl,
						  {
							 method:'post',
							 parameters: 'func=saveMain&userId='+userId+'&email='+email+'&anrede='+anrede+'&vorname='+vorname+'&nachname='+nachname+'&street='+street+'&adress_plus='+adress_plus+'&city='+city+'&zip='+zip+'&country='+country+'&phone='+phone+'&fax='+fax+'&hersteller='+hersteller,
							 onComplete: CloseMain
						  }
					  );
		}

	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
}

function CloseMain(response){
	
	try{
		$('change_MainAdress').style.visibility = "hidden";
		$('changeMainAdress').style.visibility = "hidden";
		
		parent.location.reload()
				
	}
	catch(e){
		alert("Fehlerle: " + e.toString());	
	}
}



function ShowNameTree(marke) {
	var requestUrl = "/content/php-bin/ACA/aca_ajaxfunctions.php";
	
	try{
		$('markenTree').style.visibility = "visible";
		$('showTree').style.visibility = "visible";
		var request = new Ajax.Request(
						  requestUrl,
						  {
							 method:'post',
							 parameters: 'func=showTree&marke='+marke,
							 onComplete: showTrees
						  }
					  );

	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
	
}

function showTrees(response){
	
	try{
		//alert(response.responseText);
		

		$('markenTree').innerHTML = response.responseText;
		
		
	}
	catch(e){
		alert("Fehler: " + e.toString());	
	}
}


function CloseTree(){
	$('markenTree').style.visibility = "hidden";
	$('showTree').style.visibility = "hidden";
		
}


function ShowDetail(ind){
	$('MarkenDetail_'+ind).style.visibility = "visible";
	$('MarkenDetail_'+ind).style.height = "auto";
	$('MarkenDetail_'+ind).style.padding = "10";

}

function CloseDetail(ind){
	DetailDiv = setTimeout('tempCloseDetail('+ind+')', 1000);
}

function tempCloseDetail(ind){
	$('MarkenDetail_'+ind).style.visibility = "hidden";
	$('MarkenDetail_'+ind).style.height = "0";
	$('MarkenDetail_'+ind).style.padding = "0";

}

function HoldDetail(){
	clearTimeout(DetailDiv);
}

