// BUCHUNGSFORM:
var theactiveid=false;
function showahsearchresultbuchung(theid,selzimmercode){
  if (typeof(selzimmercode)=='undefined') selzimmercode=false;
  //loadingbuchung(theid);
  theactiveid=theid;
  /*if (document.getElementById('startDate') && document.getElementById('startDate').parentNode.parentNode.id=="anfrageform"){
    var anfragestartkalender=document.getElementById('startDate');
    var anfrageendkalender=document.getElementById('endDate');
    anfragestartkalender.id='anfragestartDateInactive';
    anfrageendkalender.id='anfrageendDateInactive';
  }
  */
  
  if ($('ahsearchresultbuchung_'+theid).getStyle('display')=='none'){
		//Effect.BlindDown('ahsearchresultbuchung_'+theid,{ duration: 0.5,afterFinish: function(){ initdetmap(theid)}});
		$('ahsearchresultbuchung_'+theid).show();
		initdetmap(theid);
		$('ahsearchresultbuchungbutton_'+theid).className="button aktiv";
		//$('ahsearchresultanfragebutton_'+theid).className="button";
		if ($('ahsearchresultdetailbutton_'+theid)) $('ahsearchresultdetailbutton_'+theid).className="button";
		//Effect.BlindUp('ahsearchresultdetail_'+theid,{ duration: 0.5});	
    if ($('ahsearchresultdetail_'+theid)) $('ahsearchresultdetail_'+theid).hide();
    	
    if($('ahsearchresultanfrage_'+theid)) $('ahsearchresultanfrage_'+theid).hide();	
    if($('ahsearchresultanfragebutton_'+theid)) $('ahsearchresultanfragebutton_'+theid).className="button";
	}else{
		//Effect.BlindUp('ahsearchresultbuchung_'+theid,{ duration: 0.5});		
		$('ahsearchresultbuchungbutton_'+theid).className="button";
    $('ahsearchresultbuchung_'+theid).hide();	
	}	
	
	
	
  	if (bookingstep1==false || document.getElementById('buchungsstep1form') == null){
  	 
    	//load template:
      new Ajax.Request(bookingstep1file, {
        onSuccess: function(transport) {        
          bookingstep1 = new Template(transport.responseText); 
          
             		
      		$('ahsearchresultbuchungcontent_'+theid).innerHTML=bookingstep1.evaluate(new Object());
      		$('buchungsstep1form').hide();
      		//new Validation('buchungsform',{stopOnFirst:true, immediate : true});
      		//loadingbuchungfinished(theactiveid);
      		/*
      		if (document.getElementById('buchungstartDateInactive')){ //ids der buchungskalender ändern:
            var buchungstartkalender=document.getElementById('buchungstartDateInactive');
            var buchungendkalender=document.getElementById('buchungendDateInactive');
            buchungstartkalender.id='startDate';
            buchungendkalender.id='endDate';
          }
          */
          var tomorrow=new Date(Date.parse(new Date()));
          var nextweek=new Date(Date.parse(new Date())+7*24*60*60*1000); 
          //document.getElementById('startDate').value=(tomorrow.getDate()<10 ? "0"+tomorrow.getDate() : tomorrow.getDate())+"."+(tomorrow.getMonth()+1<10 ? "0"+(tomorrow.getMonth()+1) : (tomorrow.getMonth()+1))+"."+(tomorrow.getFullYear());
      		//document.getElementById('endDate').value=  (nextweek.getDate()<10 ? "0"+nextweek.getDate() : nextweek.getDate())+"."+(nextweek.getMonth()+1<10 ? "0"+(nextweek.getMonth()+1) : (nextweek.getMonth()+1))+"."+(nextweek.getFullYear());
      		//calendar:
          //if( typeof startdatecalendar == 'undefined')	{ initCalendar(); } 		
      		if (anzahlerw==false){ // urlaubssuche:
        	  $('buchungsstep1form').show();
        	}else{
        	  $('buchungsstep1form').hide();
            checkfreerooms();	
        	}
  
        }
      });	
  	}else{
  	  $('buchungsstep1form').hide();
      $('ahsearchresultbuchungstep3').hide();
  	  $('freeroomsdiv').innerHTML='';
  	  $('freeroomsdiv').show();
      /*var aj = new Ajax.Request(
  			proxyurl+"?ah_path=gethotels.php&type=json&schema=detail&culture="+culture+"&id="+theid, {
  				method:'get',
  				evalJSON: 'force',
  				//parameter: {path: 'gethotelsearchfilterdata.php', culture: 'de'},
  				onComplete: function(transport){ makeinfodetailoutput(transport,theid)}
  			}
  		); */
  		var buchungsforminhalt=document.getElementById('buchungsstep1form').parentNode;
  		var buchungsformparent=buchungsforminhalt.parentNode;
  		var oldformidnr=Number(buchungsformparent.id.split('_')[1]);
  		if (oldformidnr!=theid){
  		  $('freeroomsdiv').innerHTML="";
    		$('ahsearchresultbuchung_'+oldformidnr).hide();		
    		$('ahsearchresultbuchungbutton_'+oldformidnr).className="button";
    		buchungsformparent.removeChild(buchungsforminhalt);
    		
    		$('ahsearchresultbuchungcontent_'+theid).appendChild(buchungsforminhalt);
    		
    		//loadingbuchungfinished(theactiveid);
    	 //$('ahsearchresultbuchungcontent_'+theid).innerHTML=ajaxsuchebuchungsformtemplate.evaluate(new Object());	
  	  }
  	  /*
      if (document.getElementById('buchungstartDateInactive')){ //ids der buchungskalender ändern:
        var startkalender=document.getElementById('buchungstartDateInactive');
        var endkalender=document.getElementById('buchungendDateInactive');
        startkalender.id='startDate';
        endkalender.id='endDate';
      }
      */
      if (anzahlerw==false){ // urlaubssuche:
    	  $('buchungsstep1form').show();
    	}else{
    	  $('buchungsstep1form').hide();
        checkfreerooms();	
    	}
  	}
	
	//return false;
}


function createcountrieslist(resp){
  var countrieslist = resp.responseJSON;   
  if (countrieslist) { 
    
    countrieslist.each(function(s) {      
      $('land').insert('<option>'+s+'</option>');
    });
     $('land').selectedIndex=0;
  }
}
function createcountrieslistanfrage(resp){
  var countrieslist = resp.responseJSON;   
  if (countrieslist) { 
    
    countrieslist.each(function(s) {      
      $('anfrage_land').insert('<option>'+s+'</option>');
    });
     $('anfrage_land').selectedIndex=0;
  }
}
var trans_id=false;
var hotel_id=false;
var anzahl_erw;
var alterkinder1;
var alterkinder2;
var alterkinder3;
var startdate;
var enddate;
var zspanne;
function checkfreerooms(){
  if (anzahlerw!=false){
    anzahl_erw=anzahlerw;
    alterkinder1=alterkind1;
    alterkinder2=alterkind2;
    alterkinder3=alterkind3;
    startdate=zeitspanne.split(',')[0];
    enddate=zeitspanne.split(',')[1];
    zspanne=zeitspanne;    
  }else{  
    anzahl_erw=document.getElementById('anzahlerwachsene').value;
    alterkinder1=document.getElementById('alterkind1').value;
    alterkinder2=document.getElementById('alterkind2').value;
    alterkinder3=document.getElementById('alterkind3').value;
    startdate=document.getElementById('startDate').value;
    enddate=document.getElementById('endDate').value;
    zspanne=startdate+","+enddate;
  }
  var aj = new Ajax.Request(  
			proxyurl+"?ah_path=geturlaube.php&type=json&schema=urlaubefreezimmer&culture="+culture+"&id="+theactiveid+"&anzahlerw="+anzahl_erw+"&alterkinder1="+alterkinder1+"&alterkinder2="+alterkinder2+"&alterkinder3="+alterkinder3+"&zeitspanne="+zspanne, {
				method:'post',
				evalJSON: 'force',
				//parameter: {path: 'gethotelsearchfilterdata.php', culture: 'de'},
				onComplete: function(transport){ makefreeroomsoutput(transport,theactiveid)}
			}
		); 

  return false;
}

function makefreeroomsoutput(transport,theid){ 
  var thecontainer=$('freeroomsdiv');
  /*if (anzahlerw!=false){
    var thecontainer=$('ahsearchresultbuchungcontent_'+theid);
  }else{
   
  }*/

  if (transport.responseJSON.length==0){ //keine zimmer gefunden:
    //eval('thecontainer.innerHTML=\'<span class="keinezimmer" >\'+messages.keinezimmergefunden.'+culture+'+\'</span>\'');    
  }else{
    trans_id=transport.responseJSON[0].trans_id;
    hotel_id=transport.responseJSON[0].id;
    var freeroomsdata = transport.responseJSON[0].zimmer; 
    var freeroomsdataconv=new Array();
    var aktuzimmerid = false;
    var zimmerpreisehtml='';
    var zimmerzaehler=-1;
    for (var i=0; i<freeroomsdata.length; i++){
        if(freeroomsdata[i].zimmerid!=aktuzimmerid){
          
          if (zimmerzaehler>-1) freeroomsdataconv[zimmerzaehler].zimmerpreisehtml=zimmerpreisehtml;
          zimmerzaehler++;
          zimmerpreisehtml='';
          
          freeroomsdataconv[zimmerzaehler]=freeroomsdata[i];
          aktuzimmerid=freeroomsdata[i].zimmerid;
          
        }
        var zweitezeileclass="";
        if(i%2 == 0) zweitezeileclass=" color";
        zimmerpreisehtml+='<div class="verpflegungzeile'+zweitezeileclass+'"><span class="verpflegung">'+freeroomsdata[i].verpflegungtxt+'</span><span class="preis">'+freeroomsdata[i].preis+'€</span><a class="button buchen" href="#h'+hotel_id+'" onclick="return zimmerbuchenclick('+theid+',\''+freeroomsdata[i].verpflegung+'\','+freeroomsdata[i].zimmernr+',\''+freeroomsdata[i].preis+'\',\''+freeroomsdata[i].verpflegungtxt+'\',\''+freeroomsdata[i].name+'\')"><span class="links">&nbsp;</span><span class="mitte">Buchen</span><span class="rechts">&nbsp;</span></a><a class="button anfrage"  href="#h'+hotel_id+'" onclick="return showahsearchresultanfrage('+theid+',\''+freeroomsdata[i].asa_name+'\',\''+freeroomsdata[i].verpflegung+'\');"><span class="links">&nbsp;</span><span class="mitte">Anfrage</span><span class="rechts">&nbsp;</span></a></div>';
        if(i==freeroomsdata.length-1){
          freeroomsdataconv[zimmerzaehler].zimmerpreisehtml=zimmerpreisehtml;
        }
        
    }
    
    if (bookingstep2==false){
    	//load template:
      new Ajax.Request(bookingstep2file, {
        onSuccess: function(transport) {
          bookingstep2 = new Template(transport.responseText);   
          var freeroomshtml="";
          for (var i=0; i<freeroomsdataconv.length; i++){
            
            freeroomshtml+=bookingstep2.evaluate(freeroomsdataconv[i]);
          }        
          thecontainer.innerHTML=freeroomshtml;
        }
      });	
  	}else{
      var freeroomshtml="";
      for (var i=0; i<freeroomsdataconv.length; i++){
        freeroomshtml+=bookingstep2.evaluate(freeroomsdataconv[i]);
      }        
      thecontainer.innerHTML=freeroomshtml;
  	}
	}
}


/*


    <input id="hotel_id"      name="hotel_id"       value="#{hotel_id}"       type="hidden" />
		<input id="verpflegung"   name="verpflegung"    value="#{verpflegung}"    type="hidden" />
		<input id="znumber"       name="znumber"        value="#{znumber}"        type="hidden" />
		<input id="anzahl_erw"    name="anzahl_erw"     value="#{anzahl_erw}"     type="hidden" />
		<input id="anzahl_kinder" name="anzahl_kinder"  value="#{anzahl_kinder}"  type="hidden" />
		<input id="from_day"      name="from_day"       value="#{from_day}"       type="hidden" />
		<input id="from_month"    name="from_month"     value="#{from_month}"     type="hidden" />
		<input id="from_year"     name="from_year"      value="#{from_year}"      type="hidden" />
		<input id="to_day"        name="to_day"         value="#{to_day}"         type="hidden" />
		<input id="to_month"      name="to_month"       value="#{to_month}"       type="hidden" />
		<input id="to_year"       name="to_year"        value="#{to_year}"        type="hidden" />
		<input id="preis_gesamt"  name="preis_gesamt"   value="#{preis_gesamt}"   type="hidden" />
		<input id="trans_id"      name="trans_id"       value="#{trans_id}"       type="hidden" />
		


*/

function zimmerbuchenclick(theid,verpflegung,znumber,preis,verpflegungtxt,zimmername){
  $('ahsearchresultbuchungstep3').show();
  startdatearr=startdate.split('.');
  enddatearr=enddate.split('.');
  var diealter=new Array();
  for(var i=0; i<anzahl_erw-1; i++){
    diealter[i]='';    
  }
  var hoteldata;
  for (var i=0; i<data.length; i++){
    if(data[i][0]==theid) hoteldata=data[i];
  }
  
  var anzkinder=0;
  if (alterkinder1>0) anzkinder++;
  if (alterkinder2>0) anzkinder++;
  if (alterkinder3>0) anzkinder++;
  if (alterkinder1>0) diealter.push(alterkinder1);
  if (alterkinder2>0) diealter.push(alterkinder2);
  if (alterkinder3>0) diealter.push(alterkinder3);
  
  
  var buchungsdaten={
    hotel_id: hotel_id,
    verpflegung: verpflegung,
    verpflegungtxt: verpflegungtxt,
    znumber: znumber,
    anzahl_erw: anzahl_erw,
    anzahl_kinder: anzkinder,
    from_day: startdatearr[0],
    from_month: startdatearr[1],
    from_year: startdatearr[2],
    to_day: enddatearr[0],
    to_month: enddatearr[1],
    to_year: enddatearr[2],
    startdate: startdate,
    enddate:enddate,
    preis_gesamt: preis,
    trans_id: trans_id,
    alter: diealter,
    title: hoteldata[1],
    sterne: hoteldata[3],
    name: zimmername,
    adresse: hoteldata[21],
    plz: hoteldata[22],
    ort: hoteldata[7]

  };
  if (bookingstep3==false || document.getElementById('buchungsstep3form') == null){
  	//load template:
  	
  	new Ajax.Request(bookingstep3_namenalterfile, {
      onSuccess: function(transport) {        
        bookingstep3_namenalter = new Template(transport.responseText); 
        
        new Ajax.Request(bookingstep3file, {
          onSuccess: function(transport) {        
            bookingstep3 = new Template(transport.responseText); 
            
            var jsoncoutriesaj = new Ajax.Request(
        			proxyurl+"?ah_path=getjsoncountries.php&culture="+culture, {
        				method:'post',
        				evalJSON: 'force',      				
        				onComplete: createcountrieslist
        			}
        		);    
            
            
        		$('ahsearchresultbuchungstep3').innerHTML=bookingstep3.evaluate(buchungsdaten);
        		
        		var namenaltererwcode='';
            var namenalterkindercode='';
            var personenzaehler=0;
            //alert(fieldsdata.anzahl_erw-1);
            for (var i=0; i<buchungsdaten.anzahl_erw-1; i++){
              var ntemplatedata={personid:personenzaehler,personname:"",personalter:buchungsdaten.alter[personenzaehler],personreadonly:""};              
              namenaltererwcode+=bookingstep3_namenalter.evaluate(ntemplatedata);	              
              personenzaehler++;
            }          
            if (buchungsdaten.anzahl_erw>1){
              $('namealtererw').show();
            }else{
              $('namealtererw').hide();
            }
            if (buchungsdaten.anzahl_kinder>0){
              $('namealterkinder').show();
            }else{
              $('namealterkinder').hide();
            }
            for (var i=0; i<buchungsdaten.anzahl_kinder; i++){              
              var ntemplatedata={personid:personenzaehler,personname:"",personalter:buchungsdaten.alter[personenzaehler],personreadonly:'readonly="true" disabled="true"'};              
              namenalterkindercode+=bookingstep3_namenalter.evaluate(ntemplatedata);	
              personenzaehler++;
            } 
            //alert(namenaltererwcode+"----"+namenalterkindercode);
            //buchungsdaten.namenaltererw=namenaltererwcode;
            //buchungsdaten.namenalterkinder=namenalterkindercode;
            
        		$('namenaltererwdata').innerHTML=namenaltererwcode;
            $('namenalterkinderdata').innerHTML=namenalterkindercode;
        		new Validation('buchungsstep3form',{stopOnFirst:true, immediate : true});
            
        		
        		//calendar:
            //if( typeof startdatecalendar == 'undefined')	{ alert('initCalendar'); initCalendar(); } 		
        		
    
          }
        });	
    		

      }
    });	
  	
    
	}else{
    /*var aj = new Ajax.Request(
			proxyurl+"?ah_path=gethotels.php&type=json&schema=detail&culture="+culture+"&id="+theid, {
				method:'get',
				evalJSON: 'force',
				//parameter: {path: 'gethotelsearchfilterdata.php', culture: 'de'},
				onComplete: function(transport){ makeinfodetailoutput(transport,theid)}
			}
		); */
		var buchungsforminhalt=document.getElementById('buchungsstep1form').parentNode;
		var buchungsformparent=buchungsforminhalt.parentNode;
		var oldformidnr=Number(buchungsformparent.id.split('_')[1]);
    //alert(oldformidnr);
		if (oldformidnr!=theid){
		  //$('freeroomsdiv').innerHTML="";
      $('ahsearchresultbuchung_'+oldformidnr).hide();	
      $('ahsearchresultbuchungbutton_'+oldformidnr).className="button";
    }
		  $('freeroomsdiv').hide();
  			
  		
  		buchungsformparent.removeChild(buchungsforminhalt);
  		
  		$('ahsearchresultbuchungcontent_'+theid).appendChild(buchungsforminhalt);
  		
  		/*

startdate -> #{startdate}
enddate -> #{enddate}
verpflegungtxt -> #{verpflegungtxt}

preis_gesamt -> #{preis_gesamt}

  		*/
  		
  		
      $('hotel_id').value=buchungsdaten.hotel_id;
      $('verpflegung').value=buchungsdaten.verpflegung;
      $('verpflegungtxt').innerHTML=buchungsdaten.verpflegungtxt;
      $('znumber').value=buchungsdaten.znumber;
      $('anzahl_erw').value=buchungsdaten.anzahl_erw;
      $('anzahl_kinder').value=buchungsdaten.anzahl_kinder;
      $('from_day').value=buchungsdaten.from_day;
      $('from_month').value=buchungsdaten.from_month;
      $('from_year').value=buchungsdaten.from_year;      
      $('to_day').value=buchungsdaten.to_day;
      $('to_month').value=buchungsdaten.to_month;
      $('to_year').value=buchungsdaten.to_year;
      
      $('preis_gesamt').value=buchungsdaten.preis_gesamt;
      
      $('trans_id').value=buchungsdaten.trans_id;
      $('alter').value=buchungsdaten.alter;
      $('preis_gesamttxt').innerHTML=buchungsdaten.preis_gesamt+" &euro;";
      $('hotelname').innerHTML=buchungsdaten.title+" "+buchungsdaten.sterne;
      
      $('hoteladresse').innerHTML=buchungsdaten.adresse;
      $('hotelplz').innerHTML=buchungsdaten.plz;
      $('hotelort').innerHTML=buchungsdaten.ort;
      
      $('zimmername').innerHTML=buchungsdaten.name;
      $('startdate').innerHTML=buchungsdaten.from_day+"."+buchungsdaten.from_month+"."+buchungsdaten.from_year;
      $('enddate').innerHTML=buchungsdaten.to_day+"."+buchungsdaten.to_month+"."+buchungsdaten.to_year;
      //alert('jojo');
      var namenaltererwcode='';
      var namenalterkindercode='';
      var personenzaehler=0;
      //alert(fieldsdata.anzahl_erw-1);
      for (var i=0; i<buchungsdaten.anzahl_erw-1; i++){
        var ntemplatedata={personid:personenzaehler,personname:"",personalter:buchungsdaten.alter[personenzaehler],personreadonly:""};              
        namenaltererwcode+=bookingstep3_namenalter.evaluate(ntemplatedata);	              
        personenzaehler++;
      }          
      
      for (var i=0; i<buchungsdaten.anzahl_kinder; i++){              
        var ntemplatedata={personid:personenzaehler,personname:"",personalter:buchungsdaten.alter[personenzaehler],personreadonly:'readonly="true" disabled="true"'};              
        namenalterkindercode+=bookingstep3_namenalter.evaluate(ntemplatedata);	
        personenzaehler++;
      } 
      //buchungsdaten.namenaltererw=namenaltererwcode;
      //buchungsdaten.namenalterkinder=namenalterkindercode; 		
  		
      $('namenaltererwdata').innerHTML=namenaltererwcode;
      $('namenalterkinderdata').innerHTML=namenalterkindercode;
      new Validation('buchungsstep3form',{stopOnFirst:true, immediate : true});
  		//loadingbuchungfinished(theactiveid);
  	 //$('ahsearchresultbuchungcontent_'+theid).innerHTML=ajaxsuchebuchungsformtemplate.evaluate(new Object());	
	 //}
	}
	
	$('ahsearchresultbuchungstep3').show();
	$('freeroomsdiv').hide();
	$('buchungsstep1form').hide();
	return false;
}


/*Auf display: inline setzen wenn hotelinfos laden
ahsearchresultdetail_#{id}_loading
ahsearchresultbuchungbutton_#{id}_inaktiv
ahsearchresultanfragebutton_#{id}_inaktiv
Auf display: inline setzen wennn Buchung ladet 
ahsearchresultbuchungcontent_#{id}_loading
ahsearchresultanfragebutton_#{id}_inaktiv
ahsearchresultdetailbutton_#{id}_inaktiv
*/
/*
function loadinghotelinfos(theid){
  $('ahsearchresultdetail_'+theid+'_loading').style.display="inline";
  $('ahsearchresultbuchungbutton_'+theid+'_inaktiv').style.display="inline";
  $('ahsearchresultanfragebutton_'+theid+'_inaktiv').style.display="inline";
}
function loadinghotelinfosfinished(theid){
  $('ahsearchresultdetail_'+theid+'_loading').style.display="none";
  $('ahsearchresultbuchungbutton_'+theid+'_inaktiv').style.display="none";
  $('ahsearchresultanfragebutton_'+theid+'_inaktiv').style.display="none";
}
*/
/*
function loadingbuchung(theid){
  $('ahsearchresultbuchungcontent_'+theid+'_loading').style.display="inline";
}
function loadingbuchungfinished(theid){
  $('ahsearchresultbuchungcontent_'+theid+'_loading').style.display="none";
}*/

function submitform(){
  var valid = new Validation('buchungsstep3form', {onSubmit:false});
  var result = valid.validate();

  if (result) {
    //form ist ok, abschicken:
    $('ahsearchresultbuchungstep3').hide();
    ///proxyurl+'?ah_path=gethotelsearchresults.php&culture=de'
    
    
    //load template:
    new Ajax.Request(danketemplatefile, {
      onSuccess: function(transport) {
        thedanketemplate = new Template(transport.responseText);   
        for (var i=0; i<parseFloat($('anzahl_erw').value)+parseFloat($('anzahl_kinder').value)-1; i++){              
          $('alterhaupt'+i).removeAttribute('readonly');
          $('alterhaupt'+i).removeAttribute('disabled');
        }
        var aj = new Ajax.Request(
    			proxyurl+"?ah_path=makebooking.php", {
    				method:'post',
    				evalJSON: 'force',
    				parameters: $('buchungsstep3form').serialize(true),
    				//parameter: {path: 'gethotelsearchfilterdata.php', culture: 'de'},
    				onComplete: showdanke
    			}
    		); 
      }
    });	
    
    
  }
  return false;
}


function showdanke(resp){
  antwortdata = resp.responseJSON;   
  
  if (antwortdata) { 
    $('ahsearchresultbuchungstep3').update(thedanketemplate.evaluate(antwortdata));	
    $('ahsearchresultbuchungstep3').show();
  }
}

function backtozimmer(){
  $('ahsearchresultbuchungstep3').hide();
	$('freeroomsdiv').show();
	$('buchungsstep1form').show();
	return false;
}

// ANFRAGEFORM:
var theactiveid=false;
var selzimmercode=false;


var anfrstartdateval;
var anfrenddateval;
var anfranzahlerwval;
var anfralterkind1val;
var anfralterkind2val;
var anfralterkind3val;
var anfrverpflegung=false
 //                                  370,                      'preis_hp',502,'1 036,00','Halbpension','Komfortzimmer B')
function showahsearchresultanfrage(theid,pselzimmercode, pverpflegung){
  if (typeof(pselzimmercode)=='undefined'){ 
    selzimmercode=false;
  }else{
    selzimmercode=pselzimmercode;
  }
  if (typeof(pverpflegung)=='undefined'){ 
    anfrverpflegung=false;
  }else{  //anfrage kommt von buchung:
    anfrverpflegung=pverpflegung.split('_')[1];
    
  }
  //loadingbuchung(theid);
  theactiveid=theid;
  if (document.getElementById('startDate') && document.getElementById('startDate').parentNode.parentNode.id=="buchungsstep1form"){
    var buchungstartkalender=document.getElementById('startDate');
    var buchungendkalender=document.getElementById('endDate');
    if (anfrverpflegung!=false){
      anfrstartdateval=document.getElementById('startDate').value;
      anfrenddateval=document.getElementById('endDate').value;
      anfranzahlerwval=document.getElementById('anzahlerwachsene').value;
      anfralterkind1val=document.getElementById('alterkind1').value;
      anfralterkind2val=document.getElementById('alterkind2').value;
      anfralterkind3val=document.getElementById('alterkind3').value;
    }
    //buchungstartkalender.id='buchungstartDateInactive';
    //buchungendkalender.id='buchungendDateInactive';
  }
  
  var buchungsdaten={
    hotel_id: theid,
    trans_id: trans_id
  };
  
  if ($('ahsearchresultanfrage_'+theid).getStyle('display')=='none'){
		//Effect.BlindDown('ahsearchresultbuchung_'+theid,{ duration: 0.5,afterFinish: function(){ initdetmap(theid)}});
		$('ahsearchresultanfrage_'+theid).show();
		initdetmap(theid);
		$('ahsearchresultanfragebutton_'+theid).className="button aktiv";
		//$('ahsearchresultanfragebutton_'+theid).className="button";
		$('ahsearchresultdetailbutton_'+theid).className="button";
		//Effect.BlindUp('ahsearchresultdetail_'+theid,{ duration: 0.5});	
    $('ahsearchresultdetail_'+theid).hide();	
    
    $('ahsearchresultbuchung_'+theid).hide();
		$('ahsearchresultbuchungbutton_'+theid).className="button";
	}else{
		//Effect.BlindUp('ahsearchresultbuchung_'+theid,{ duration: 0.5});		
		$('ahsearchresultanfragebutton_'+theid).className="button";
    $('ahsearchresultanfrage_'+theid).hide();	
	}	
	
	if (anfrage==false || document.getElementById('anfrageform') == null){
	
  	//load template:
    new Ajax.Request(anfragefile, {
      onSuccess: function(transport) {        
        anfrage = new Template(transport.responseText); 
        
    		$('ahsearchresultanfragecontent_'+theid).innerHTML=anfrage.evaluate(buchungsdaten);
    		/*if (document.getElementById('anfragestartDateInactive')){ //ids der buchungskalender ändern:
          var startkalender=document.getElementById('anfragestartDateInactive');
          var endkalender=document.getElementById('anfrageendDateInactive');
          startkalender.id='startDate';
          endkalender.id='endDate';
        }
       
        */
        
        
    		if (anzahlerw!=false){ //urlaubsuche:
          anzahl_erw=anzahlerw;
          $('anfrage_anzahlerwachsene').value=anzahlerw;
          $('anfrage_alterkind1').value=alterkind1;
          $('anfrage_alterkind2').value=alterkind2;
          $('anfrage_alterkind3').value=alterkind3;                 
          startdate=zeitspanne.split(',')[0];
          enddate=zeitspanne.split(',')[1];
          document.getElementById('startDate').value=startdate;
      		document.getElementById('endDate').value=enddate;
        }else{  
          //var tomorrow=new Date(Date.parse(new Date())+1*24*60*60*1000);
          var tomorrow=new Date(Date.parse(new Date()));
          var nextweek=new Date(Date.parse(new Date())+7*24*60*60*1000); 
          var startDaten=document.getElementsByName('startDate');
          for (var i=0; i<startDaten.length; i++){
            startDaten[i].value=(tomorrow.getDate()<10 ? "0"+tomorrow.getDate() : tomorrow.getDate())+"."+(tomorrow.getMonth()+1<10 ? "0"+(tomorrow.getMonth()+1) : (tomorrow.getMonth()+1))+"."+(tomorrow.getFullYear());
      		}
      		var endDaten=document.getElementsByName('endDate');
          for (var i=0; i<endDaten.length; i++){
            endDaten[i].value=  (nextweek.getDate()<10 ? "0"+nextweek.getDate() : nextweek.getDate())+"."+(nextweek.getMonth()+1<10 ? "0"+(nextweek.getMonth()+1) : (nextweek.getMonth()+1))+"."+(nextweek.getFullYear());
          }
        }
    		/*
    		if( typeof startdatecalendar == 'undefined')	{ initCalendar(); } 		
        */
        
        
        
        var jsoncoutriesaj = new Ajax.Request(
    			proxyurl+"?ah_path=getjsoncountries.php&culture="+culture, {
    				method:'post',
    				evalJSON: 'force',      				
    				onComplete: createcountrieslistanfrage
    			}
    		);  
    		var jsonhotelanfragedata = new Ajax.Request(
    			proxyurl+"?ah_path=getjsonhotelanfragedata.php&culture="+culture+"&id="+theactiveid, {
    				method:'post',
    				evalJSON: 'force',      				
    				onComplete: createhotelanfragedata
    			}
    		);
    		new Validation('anfrageform',{stopOnFirst:true, immediate : true});
    		
    		if (typeof onanfrageloaded != 'undefined'){ //function wird aufgerufen sobald alles fertig ist:
          onanfrageloaded();
        }
    		
    		
      }
    });	
	}else{
	  $('anfrageform').show();
    
		var anfrageforminhalt=document.getElementById('anfrageform').parentNode;
		var anfrageformparent=anfrageforminhalt.parentNode;
		var oldformidnr=Number(anfrageformparent.id.split('_')[1]);
		if (oldformidnr!=theid){
		  $('ahsearchresultanfrage_'+oldformidnr).hide();		
  		$('ahsearchresultanfragebutton_'+oldformidnr).className="button";
  		anfrageformparent.removeChild(anfrageforminhalt);
  		
  		$('ahsearchresultanfragecontent_'+theid).appendChild(anfrageforminhalt);
  		
      
	  }
	  $('anfrage_hotel_id').value=buchungsdaten.hotel_id;
    $('anfrage_trans_id').value=buchungsdaten.trans_id;
    /*  
    if (document.getElementById('anfragestartDateInactive')){ //ids der buchungskalender ändern:
      var startkalender=document.getElementById('anfragestartDateInactive');
      var endkalender=document.getElementById('anfrageendDateInactive');
      startkalender.id='startDate';
      endkalender.id='endDate';
    }
    */
    if (anzahlerw!=false){ //urlaubsuche:
      anzahl_erw=anzahlerw;
      $('anfrage_anzahlerwachsene').value=anzahlerw;
      $('anfrage_alterkind1').value=alterkind1;
      $('anfrage_alterkind2').value=alterkind2;
      $('anfrage_alterkind3').value=alterkind3;                 
      startdate=zeitspanne.split(',')[0];
      enddate=zeitspanne.split(',')[1];
      document.getElementById('startDate').value=startdate;
  		document.getElementById('endDate').value=enddate;
    }else{  
      var tomorrow=new Date(Date.parse(new Date()));
      var nextweek=new Date(Date.parse(new Date())+7*24*60*60*1000); 
      var startDaten=document.getElementsByName('startDate');
      for (var i=0; i<startDaten.length; i++){
        startDaten[i].value=(tomorrow.getDate()<10 ? "0"+tomorrow.getDate() : tomorrow.getDate())+"."+(tomorrow.getMonth()+1<10 ? "0"+(tomorrow.getMonth()+1) : (tomorrow.getMonth()+1))+"."+(tomorrow.getFullYear());
  		}
  		var endDaten=document.getElementsByName('endDate');
      for (var i=0; i<endDaten.length; i++){
        endDaten[i].value=  (nextweek.getDate()<10 ? "0"+nextweek.getDate() : nextweek.getDate())+"."+(nextweek.getMonth()+1<10 ? "0"+(nextweek.getMonth()+1) : (nextweek.getMonth()+1))+"."+(nextweek.getFullYear());
      }
    }
    var jsonhotelanfragedata = new Ajax.Request(
			proxyurl+"?ah_path=getjsonhotelanfragedata.php&culture="+culture+"&id="+theactiveid, {
				method:'post',
				evalJSON: 'force',      				
				onComplete: createhotelanfragedata
			}
		);
  }
  
	
	//return false;
}

function submitrequestform(){
  var valid = new Validation('anfrageform', {onSubmit:false});
  var result = valid.validate();

  if (result) {
    //form ist ok, abschicken:
    $('anfrageform').hide();
    ///proxyurl+'?ah_path=gethotelsearchresults.php&culture=de'
    
    
    //load template:
    new Ajax.Request(anfragedanketemplatefile, {
      onSuccess: function(transport) {
        theanfragedanketemplate = new Template(transport.responseText);   
        
        var aj = new Ajax.Request(
    			proxyurl+"?ah_path=makerequest.php", {
    				method:'post',
    				evalJSON: 'force',
    				parameters: $('anfrageform').serialize(true),
    				//parameter: {path: 'gethotelsearchfilterdata.php', culture: 'de'},
    				onComplete: showanfragedanke
    			}
    		); 
      }
    });	
    
    
  }
  return false;
}


function showanfragedanke(resp){
  antwortdata = resp.responseJSON;   
  
  if (antwortdata) { 
    $('anfragedanke').update(theanfragedanketemplate.evaluate(antwortdata));	
    $('anfragedanke').show();
  }
}

function createhotelanfragedata(resp){
  var zimmerlist = resp.responseJSON.zimmerlist;   
  var verpflegungenlist = resp.responseJSON.verpflegungenlist;
  $('anfrage_zimmer').update('');
  $('anfrage_verpflegung').update('');   
  if (zimmerlist) {  
    var x=0;  
    var selindex=0;  
    zimmerlist.each(function(s) {
      if (selzimmercode==s.value){
        $('anfrage_zimmer').insert('<option value="'+s.value+'" selected="selected">'+s.name+'</option>');
        selindex=x;
      }else{
        $('anfrage_zimmer').insert('<option value="'+s.value+'">'+s.name+'</option>');
      }
      x++;
    });
    
    $('anfrage_zimmer').selectedIndex=selindex;
    
  }
  if (verpflegungenlist) {    
    verpflegungenlist.each(function(s) {      
      $('anfrage_verpflegung').insert('<option value="'+s.value+'">'+s.name+'</option>');
    });
     $('anfrage_verpflegung').selectedIndex=0;
  }
  //alert(anfralterkind1val);
  if (anfrverpflegung!=false){
    document.getElementById('startDate').value=anfrstartdateval;
    document.getElementById('endDate').value=anfrenddateval;
    document.getElementById('anfrage_anzahlerwachsene').value=anfranzahlerwval;
    document.getElementById('anfrage_alterkind1').value=anfralterkind1val;
    document.getElementById('anfrage_alterkind2').value=anfralterkind2val;
    document.getElementById('anfrage_alterkind3').value=anfralterkind3val;
    document.getElementById('anfrage_verpflegung').value=anfrverpflegung;
  }
}

