var xmlhttp;
var hvclicked="N";
var kenmerken_opties="N";
var land_filter="N";
var region_filter="N";
var acc_filter="N";
var bedroom_filter="N";
var person_filter="N";
function load_data(url,xtype)
{
xmlhttp=null
// Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  }
// IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmlhttp!=null)
  {

	  if(xtype=="region") {
		xmlhttp.onreadystatechange=onResponse2;
	  }else
	   if(xtype=="get_coordinate") {
	    document.getElementById('coord_show').innerHTML="Loading Coordinate Suggestion..";
		xmlhttp.onreadystatechange=onResponse_coord;
	  }else
	  if(xtype=="search_booking1") {
		xmlhttp.onreadystatechange=onResponse6;
	  }else
	  if(xtype=="search_booking2") {
		xmlhttp.onreadystatechange=onResponse7;
	  }else
	  if(xtype=="bookingdate") {
		document.getElementById('booking_show').innerHTML="<div style=\"width:100%; text-align:center; color:red; border:1px dotted gray;\">Datum laden..</div>";
		xmlhttp.onreadystatechange=onResponse8;
	  }else
	   if(xtype=="bookingdate2") {
		document.getElementById('booking_show').innerHTML="<div style=\"width:100%; text-align:center; color:red; border:1px dotted gray;\">Datum laden..</div>";
		xmlhttp.onreadystatechange=onResponsex;
	  }else
	  if(xtype=="search_booking_day") {
		xmlhttp.onreadystatechange=onResponse9;
	  }else
	  if(xtype=="get_cal") {
		document.getElementById('house_calendar').innerHTML="<div style=\"width:100%; text-align:center; color:green; border:1px dotted gray;\">Kalender laden..</div>";
		xmlhttp.onreadystatechange=onResponse_cal;
	  }else
	  if(xtype=="load_charFilter") {
		if(kenmerken_opties=="Y"){
			kenmerken_opties="N";
			document.getElementById('load_charFilter').innerHTML='';
			document.getElementById('load_charFilter').style.display='none';
			document.getElementById('kenmerken_opties').innerHTML='+ Kenmerken/opties :';
		}else
		{
			kenmerken_opties="Y";
			document.getElementById('load_charFilter').style.display='';
			document.getElementById('load_charFilter').innerHTML="<div style=\"text-align:center; color:green; border:1px dotted gray;\">Kenmerken/opties laden..</div>";
			xmlhttp.onreadystatechange=load_charFilter;
		}

	  }else
	  if(xtype=="load_land_filter") {
		if(land_filter=="Y"){
			land_filter="N";
			document.getElementById('load_land_filter').innerHTML='';
			document.getElementById('load_land_filter').style.display='none';
			document.getElementById('land_filter').innerHTML='+ Land :';
		}else
		{
			land_filter="Y";
			document.getElementById('load_land_filter').style.display='';
			document.getElementById('load_land_filter').innerHTML="<div style=\"text-align:center; color:green;\">Land filter laden..</div>";
			xmlhttp.onreadystatechange=load_land_filter;
		}

	  }else
	  if(xtype=="load_region_filter") {
		if(region_filter=="Y"){
			region_filter="N";
			document.getElementById('load_region_filter').innerHTML='';
			document.getElementById('load_region_filter').style.display='none';
			document.getElementById('region_filter').innerHTML='+ Regio :';
		}else
		{
			region_filter="Y";
			document.getElementById('load_region_filter').style.display='';
			document.getElementById('load_region_filter').innerHTML="<div style=\"text-align:center; color:green;\">Regio filter laden..</div>";
			xmlhttp.onreadystatechange=load_region_filter;
		}

	  }else
	  if(xtype=="load_acc_filter") {
		if(acc_filter=="Y"){
			acc_filter="N";
			document.getElementById('load_acc_filter').innerHTML='';
			document.getElementById('load_acc_filter').style.display='none';
			document.getElementById('acc_filter').innerHTML='+ Accommodatie :';
		}else
		{
			acc_filter="Y";
			document.getElementById('load_acc_filter').style.display='';
			document.getElementById('load_acc_filter').innerHTML="<div style=\"text-align:center; color:green;\">Accommodatie filter laden..</div>";
			xmlhttp.onreadystatechange=load_acc_filter;
		}

	  }else
	  if(xtype=="load_bedroom_filter") {
		if(bedroom_filter=="Y"){
			bedroom_filter="N";
			document.getElementById('load_bedroom_filter').innerHTML='';
			document.getElementById('load_bedroom_filter').style.display='none';
			document.getElementById('bedroom_filter').innerHTML='+ Slaapkamer :';
		}else
		{
			bedroom_filter="Y";
			document.getElementById('load_bedroom_filter').style.display='';
			document.getElementById('load_bedroom_filter').innerHTML="<div style=\"text-align:center; color:green;\">Slaapkamer filter laden..</div>";
			xmlhttp.onreadystatechange=load_bedroom_filter;
		}

	  }else
	  if(xtype=="load_person_filter") {
		if(person_filter=="Y"){
			person_filter="N";
			document.getElementById('load_person_filter').innerHTML='';
			document.getElementById('load_person_filter').style.display='none';
			document.getElementById('person_filter').innerHTML='+ Persoon :';
		}else
		{
			person_filter="Y";
			document.getElementById('load_person_filter').style.display='';
			document.getElementById('load_person_filter').innerHTML="<div style=\"text-align:center; color:green;\">Persoon filter laden..</div>";
			xmlhttp.onreadystatechange=load_person_filter;
		}

	  }else
	  if(xtype=="adv_search_show") {
		$j('#adv_search_form').html("<div id=\"uitgebreid_zoeken2\" > Laden.. </div>");		
		xmlhttp.onreadystatechange=adv_search_show_data;
	  }
	  xmlhttp.open("GET",url,true);
	  xmlhttp.send(null);
  }
else
  {
  alert("Your Browser Not Support XMLHTTP.")
  }
}

function checkReadyState(obj)
{
  if(obj.readyState == 4)
  {
    if(obj.status == 200)
    {
      return true;
    }
    else
    {
      //alert("Problem retrieving XML data");
    }
  }
}

function load_frame(xvar,xvar2)
{
	
	if(!xvar2 || xvar2 == ''){
		var idmap = 'map';
	}else{
		var idmap = xvar2;
	}
 	if(hvclicked=="N"){
		jQuery('#'+idmap).html('<iframe src="'+xvar+'" width="476" height="346" marginwidth="0" marginheight="0" frameborder="0" style="background-color:#FFFFFF;" scrolling="no"></iframe>');
	}
}

function adv_search_show_data()
{
  if(checkReadyState(xmlhttp))
  {
		var response = xmlhttp.responseText;
		$j('#adv_search_form').hide();
		$j('#adv_search_form').html(response);
		$j('#adv_search_form').slideDown("slow");
  }
}

// if($page=="booking" OR $page=="map" OR $page=="aanbiedingen")
function load_charFilter()
{
  if(checkReadyState(xmlhttp))
  {
		var response = xmlhttp.responseText;
		document.getElementById('load_charFilter').innerHTML=response;
		document.getElementById('kenmerken_opties').innerHTML='- Kenmerken opties :';
  }
}
function load_land_filter()
{
  if(checkReadyState(xmlhttp))
  {
		var response = xmlhttp.responseText;
		document.getElementById('load_land_filter').innerHTML=response;
		document.getElementById('land_filter').innerHTML='- Land :';
  }
}
function load_region_filter()
{
  if(checkReadyState(xmlhttp))
  {
		var response = xmlhttp.responseText;
		document.getElementById('load_region_filter').innerHTML=response;
		document.getElementById('region_filter').innerHTML='- Regio :';
  }
}
function load_acc_filter()
{
  if(checkReadyState(xmlhttp))
  {
		var response = xmlhttp.responseText;
		document.getElementById('load_acc_filter').innerHTML=response;
		document.getElementById('acc_filter').innerHTML='- Accommodatie :';
  }
}
function load_bedroom_filter()
{
  if(checkReadyState(xmlhttp))
  {
		var response = xmlhttp.responseText;
		document.getElementById('load_bedroom_filter').innerHTML=response;
		document.getElementById('bedroom_filter').innerHTML='- Slaapkamer :';
  }
}
function load_person_filter()
{
  if(checkReadyState(xmlhttp))
  {
		var response = xmlhttp.responseText;
		document.getElementById('load_person_filter').innerHTML=response;
		document.getElementById('person_filter').innerHTML='- Persoon :';
  }
}
// if($page=="booking" OR $page=="map" OR $page=="aanbiedingen")


function onResponse2()
{
  if(checkReadyState(xmlhttp))
  {
  var response = xmlhttp.responseXML.documentElement;
  txt="";
  x=response.getElementsByTagName("region")

  for (i=0;i<x.length;i++)
    {
	   var getval=x.item(i).attributes;
	   valx=getval.getNamedItem("value");
	  if (x[i].firstChild.data!=""){
	  txt += "<option value='"
                    + valx.value
                    + "'>"+ x[i].firstChild.data+"</option>";
       }
	}
	if(txt==""){
	     txt += "";
	}
	txt="<select name='region'>"+txt;
	txt+="</select>";
  document.getElementById('show_region').innerHTML=txt
  }
}

function onResponse_coord()
{
  if(checkReadyState(xmlhttp))
  {
		var response = xmlhttp.responseText;
		document.getElementById('coord_show').innerHTML=response;
  }
}


function onResponse6()
{
  if(checkReadyState(xmlhttp))
  {
  var response = xmlhttp.responseXML.documentElement;
  txt="";
  x=response.getElementsByTagName("region")

  for (i=0;i<x.length;i++)
    {
	   var getval=x.item(i).attributes;
	   valx=getval.getNamedItem("value");
	  if (x[i].firstChild.data!=""){
	  txt += "<option value='"
                    + valx.value
                    + "'>"+ x[i].firstChild.data+"</option>";
       }
	}
	if(txt==""){
	     txt_dis = "disabled=\"disabled\"";
	}else
	{
		txt_dis='';
	}
	txt="<select name='region' onchange=\"load_data('search_acc.php?country='+document.form_search.country_search.value+'&region='+document.form_search.region.value,'search_booking2');\" class=\"selectsearch2\" "+txt_dis+"><option value=''> Regio </option>"+txt;
	txt+="</select>";
  document.getElementById('show_region3').innerHTML=txt;
  load_data('search_acc.php?country='+document.form_search.country_search.value+'&region='+document.form_search.region.value,'search_booking2');
  }
}

function onResponse7()
{
  if(checkReadyState(xmlhttp))
  {
  var response = xmlhttp.responseXML.documentElement;
  txt="";
  x=response.getElementsByTagName("accomodation")

  for (i=0;i<x.length;i++)
    {


	  if(x[i].firstChild.data=="vakantiehuis"){
	    show_data="Vakantiehuis";
	  }else
	  if(x[i].firstChild.data=="appartement"){
	    show_data="Appartement";
	  }else
	  if(x[i].firstChild.data=="pension"){
	    show_data="Pension";
	  }else
	  {
	    x[i].firstChild.data="";
		show_data="";
		txt="";
	  }

	  if (x[i].firstChild.data!=""){
	  txt += "<option value='"
                    + x[i].firstChild.data
                    + "'>"+show_data+"</option>";
       }
	}
	if(txt==""){
	     txt += "<option value=\"vakantiehuis\">Vakantiehuis</option>"
		 +"<option value=\"appartement\">Appartement</option>"
		 +"<option value=\"pension\">Pension</option>";
	}
	txt="<select name='accomodation_type_search' class=\"selectsearch\"><option value=''> Soort Accommodatie </option>"+txt;
	txt+="</select>";
  document.getElementById('acc_object4').innerHTML=txt
  }
}

//if($page=="booking display")
function onResponse8()
{
  if(checkReadyState(xmlhttp))
  {
	 var response = xmlhttp.responseText;
	  document.getElementById('booking_show').innerHTML=response;
	  	if(document.getElementById('typeHouse').innerHTML=="pension"){
			Xvar=document.getElementById('totaldata_pension').innerHTML;
				for(zzz=1;zzz<=Xvar;zzz++){
					new Tip('totaalbeschikbaar'+zzz, "Weergave van het totaal aantal beschikbare/vrije kamers en bedden in een bepaalde week. De beschikbaarheid wordt voortdurend bijgewerkt, maar is onder voorbehoud", {
											title: "Informatie",
											style: jQuery('#set_theme').html(),
											stem: 'bottomLeft',
											hook: { mouse: true, tip: 'bottomLeft' },
											width: 186
										});
				}
			}
	}
}

function onResponse9()
{
  if(checkReadyState(xmlhttp))
  {
	var response = xmlhttp.responseXML.documentElement;
	txt="";
	x=response.getElementsByTagName("date_on")
			
    for (i=0;i<x.length;i++)
    {
		var getval=x.item(i).attributes;
		valx=getval.getNamedItem("value");
		if (x[i].firstChild.data!=""){
			if(jQuery('#cookie_arrival_date').html() != ''){
				if(valx.value == jQuery('#kuki_arrival').html()){
					checkthis="selected=\"selected\"";
				}else
				{
					checkthis='';
				}
			}
		}else
		{		
			checkthis='';		
		}
		
		txt += "<option value='"
                    + valx.value
                    + "' "+checkthis+" >"+ x[i].firstChild.data+"</option>";
					
			if(jQuery('#cookie_arrival_date').html() != ''){
				firstval = jQuery('#kuki_arrival').html();
			}else
			{			
				if(i==0){
					firstval=valx.value;
				}			
			}
       }
	}

	if(txt==""){
	     txt_dis = "disabled=\"disabled\"";
		 txt += "<option value=''> Select </option>";
	}else
	{
		txt_dis='';
	}
	txt="<select name='arrival_days' class='selectsearch' "+txt_dis+">"+txt;
	txt+="</select>";
    document.getElementById('show_booking_day').innerHTML=txt;
	
	if(jQuery('#cookie_arrival_date').val() != '' && jQuery('#get_pages').val() == 'house'){
	
	}
    
	if(txt_dis==''){
		document.form_search.stay_period.disabled=false;
	}else
	{
		document.form_search.stay_period.disabled=true;
	}
  
}
