// JavaScript Document
var xmlhttp = false;
if (window.XMLHttpRequest) 
{
	xmlhttp = new XMLHttpRequest();  
	if(xmlhttp.overrideMimeType){       
        xmlhttp.overrideMimeType('text/xml');
    }
} 
else if (window.ActiveXObject) {
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}	
function close_bubble()
{
	thebubble=document.getElementById("bubble");
	thebubble.style.visibility="hidden";
}
//handling options
function make_querystring()
{
	theform=document.getElementById("listestates_form");		
	var theQuery, theOrder, theType;
	//calculating the elements order	
	theOrder=document.getElementById("eo_element").innerHTML;	
	theZipList=document.getElementById("ziplist_element").innerHTML;
	//alert(theOrder);
	theType=document.getElementById("type_to_recover").innerHTML;	
	theQuery="&purpose="+theType+"&eo="+theOrder;	
	if (theform.ajax_huistype)	
		theQuery+='&huistype='+theform.ajax_huistype.value;
	if (theform.ajax_prijsklasse)
		theQuery+='&prijsklasse='+theform.ajax_prijsklasse.value;
	if (theform.ajax_prijs_van)
		theQuery+='&prijs_van='+theform.ajax_prijs_van.value;
	if (theform.ajax_prijs_tot)
		theQuery+='&prijs_tot='+theform.ajax_prijs_tot.value;
	if (theform.ajax_grond)
		theQuery+='&grond='+theform.ajax_grond.value;
	if (theform.ajax_woon)
		theQuery+='&woon='+theform.ajax_woon.value;
	if (theform.ajax_kamers)	
		theQuery+='&kamers='+theform.ajax_kamers.value;	
	theQuery+='&zipList='+theZipList;
	//alert(theQuery);
	return(theQuery);
}

function ajax_select_option(param)
{	
	document.getElementById('current_selector').style.display="";
	if (document.getElementById("plus_button"))
		document.getElementById('plus_button').style.display="none";
	if (document.getElementById("plus_initial_button"))
		document.getElementById('plus_initial_button').style.display="none";
	var theQuery;	
	theQuery=make_querystring();	
	document.getElementById('message').innerHTML = '<img src="i/web/loading.gif" alt="loading" />';		
	var url = 'content_listestates_select_option.cfm?option_id='+param+theQuery;	
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			var a = xmlhttp.responseText;
			//trimming spaces
			document.getElementById('search_container').innerHTML = a.replace(/(^ +| +$)/, "");			
		} 
		else 
		{			
			document.getElementById('message').innerHTML = '<img src="i/web/loading.gif" alt="loading" />';
		}
	};	
	xmlhttp.send(null);	
}
function ajax_add_criteria(param)
{
	var theQuery;
	//alert(document.getElementById('search_container').innerHTML);
	//alert (new_option.value);
	theQuery=make_querystring();
	document.getElementById('message').innerHTML = '<img src="i/web/loading.gif" alt="loading" />';		
	var url = 'content_listestates_add_criteria.cfm?option_id='+param+theQuery;		
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			var a = xmlhttp.responseText;
			//alert("before the error");
			//alert(xmlhttp.responseText);
			document.getElementById('search_container').innerHTML = a.replace(/(^ +| +$)/, "");
			//trimming spaces
			//document.getElementById('search_container').innerHTML = a;
			//document.getElementById('search_container').innerHTML = a.replace(/(^ +| +$)/, "");			
		} 
		else 
		{
			document.getElementById('message').innerHTML = '<img src="i/web/loading.gif" alt="loading" />';
		}
	};
	xmlhttp.send(null);	
}
function ajax_del_criteria(param)
{
	var theQuery;
	theQuery=make_querystring();	
	var url = 'content_listestates_delete_criteria.cfm?option_id='+param+theQuery;	
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() 
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			document.getElementById('search_container').innerHTML = xmlhttp.responseText + ' ';	
			ajax_search_again();
		} 
		else 
		{
			document.getElementById('message').innerHTML = '<img src="i/web/loading.gif" alt="loading" />';
		}
	};
	xmlhttp.send(null);	
	theOrder=document.getElementById("eo_element").innerHTML;	
	if (param==1)
	{		
		document.getElementById('plus_initial_button').style.display="";
	}
	
}

//function that makes the search string for the zoek button
function ajax_search_again(){			
	var ajax_already_called;
	ajax_already_called=document.getElementById("ajax_called");	
	var the_form;
	the_form=document.getElementById("listestates_form");
	//checking if ajax is already called, if we call it again, before refreshing the page, we have problems.
	if (ajax_already_called.innerHTML=="0")
	{
		search_again=the_form.action;
		search_again+="&region="+the_form.srch_region.value;
		if((typeof the_form.ajax_huistype)!="undefined")	
			search_again+="&huistype="+the_form.ajax_huistype.value;
		else
			search_again+="&huistype=";
			
		if((typeof the_form.ajax_prijs_van)!="undefined")
			search_again+="&prijs_van="+the_form.ajax_prijs_van.value;
		else
			search_again+="&prijs_van=";
			
		if((typeof the_form.ajax_prijs_tot)!="undefined")
			search_again+="&prijs_tot="+the_form.ajax_prijs_tot.value;
		else
			search_again+="&prijs_tot=";
			
		if((typeof the_form.ajax_grond)!="undefined")
			search_again+="&grond="+the_form.ajax_grond.value;
		else
			search_again+="&grond=";
			
		if((typeof the_form.ajax_woon)!="undefined")
			search_again+="&woon="+the_form.ajax_woon.value;
		else
			search_again+="&woon=";
			
		if((typeof the_form.ajax_kamers)!="undefined")
			search_again+="&kamers="+the_form.ajax_kamers.value;	
		else
			search_again+="&kamers=";
			
		var theOrder="&eo="+document.getElementById("eo_element").innerHTML;
		//var theZipList="&zipList="+document.getElementById("ziplist_element").innerHTML;
		var theZipList="&zipList="+document.getElementById("srch_zipList").value;
		ziplistElementRecover=document.getElementById("ziplist_element").innerHTML;			
		search_again+=theOrder;	
		search_again+=theZipList;
		//alert (search_again);
		//alert (search_again);
		the_form.action=search_again;
		ajax_already_called.innerHTML="1";
	}	
	the_form.submit();		
}

function ajax_save_url()
{
	var the_form;
	the_form=document.getElementById("listestates_form");
	save_search_link+="&region="+the_form.srch_region.value;
	if((typeof the_form.ajax_huistype)!="undefined")	
		save_search_link+="&huistype="+the_form.ajax_huistype.value;
	else
		save_search_link+="&huistype=";
		
	if((typeof the_form.ajax_prijs_van)!="undefined")
		save_search_link+="&prijs_van="+the_form.ajax_prijs_van.value;
	else
		save_search_link+="&prijs_van=";
		
	if((typeof the_form.ajax_prijs_tot)!="undefined")
		save_search_link+="&prijs_tot="+the_form.ajax_prijs_tot.value;
	else
		save_search_link+="&prijs_tot=";
		
	if((typeof the_form.ajax_grond)!="undefined")
		save_search_link+="&grond="+the_form.ajax_grond.value;
	else
		save_search_link+="&grond=";
		
	if((typeof the_form.ajax_woon)!="undefined")
		save_search_link+="&woon="+the_form.ajax_woon.value;
	else
		save_search_link+="&woon=";
		
	if((typeof the_form.ajax_kamers)!="undefined")
		save_search_link+="&kamers="+the_form.ajax_kamers.value;	
	else
		save_search_link+="&kamers=";
		
	var theOrder="&eo="+document.getElementById("eo_element").innerHTML;
	var theZipList="&zipList="+document.getElementById("ziplist_element").innerHTML;
	save_search_link+=theOrder;	
	save_search_link+=theZipList;	
	//alert(save_search_link);
	window.location=save_search_link;
	//setInterval('window.location=save_search_link',5000);
	//alert(save_search_link);
}

function contact_login_profile(){
	var the_form;
	the_form=document.getElementById("listestates_form");
	profile_link="?page=contact_login_profile&region="+the_form.srch_region.value;
	if((typeof the_form.ajax_huistype)!="undefined")	
		profile_link+="&huistype="+the_form.ajax_huistype.value;
	else
		profile_link+="&huistype=";
		
	if((typeof the_form.ajax_prijs_van)!="undefined")
		profile_link+="&prijs_van="+the_form.ajax_prijs_van.value;
	else
		profile_link+="&prijs_van=";
		
	if((typeof the_form.ajax_prijs_tot)!="undefined")
		profile_link+="&prijs_tot="+the_form.ajax_prijs_tot.value;
	else
		profile_link+="&prijs_tot=";
		
	if((typeof the_form.ajax_grond)!="undefined")
		profile_link+="&grond="+the_form.ajax_grond.value;
	else
		profile_link+="&grond=";
		
	if((typeof the_form.ajax_woon)!="undefined")
		profile_link+="&woon="+the_form.ajax_woon.value;
	else
		profile_link+="&woon=";
		
	if((typeof the_form.ajax_kamers)!="undefined")
		profile_link+="&kamers="+the_form.ajax_kamers.value;	
	else
		profile_link+="&kamers=";
		
	var theOrder="&eo="+document.getElementById("eo_element").innerHTML;
	var theZipList="&zipList="+document.getElementById("ziplist_element").innerHTML;
	profile_link+=theOrder;	
	profile_link+=theZipList;	
	window.location=profile_link;
	//window.location="?page=contact_login_profile";
}
function hide_tip(){
	the_tip=document.getElementById("Layer3");
	the_tip.style.display="none"
}
function hide_first_tip(){
	the_tip=document.getElementById("first_tip");
	the_tip.style.display="none"
}
function showzips()
{
	document.getElementById("zip_div").style.display="block";
}
function hidezips()
{
	document.getElementById("zip_div").style.display="none";
}

function calculateTypes()
{
	var inputs = document.getElementsByTagName("input");
	var inputsValues="";
	for(var i = 0; i < inputs.length; i++)
	{
		var type = inputs[i].getAttribute("type");
		if(type == "checkbox"&&inputs[i].checked)
		{
			var brokenstring=inputs[i].id.split("extra_");
			//alert (brokenstring[1]);
			if (brokenstring[1])
				inputsValues+=brokenstring[1]+",";
		}		
	}
	//stripping the last comma
	if (inputsValues.length)
	{
		inputsValues=inputsValues.substr(0,inputsValues.length-1)
	}
	inputsValues="&extraValues="+inputsValues
	return(inputsValues);
}




function activate_type()
{
	
	
	//document.getElementById("").innerHTML
	eoElement=document.getElementById("eo_element").innerHTML;
	//alert(eoElement);
	openedElements=eoElement.split(",");
	var typeOpened;
	typeOpened=false;
	for(i=0;i<5;i++)
	{
		if (openedElements[i]==1)
		{	
			typeOpened=true;
		}
	}
	var new_eo;
	if (typeOpened==false)
	{
		var replaced=false;
		var new_eo="";
		for(i=0;i<5;i++)
		{
			if (i>0)
				new_eo+=",";
			if (openedElements[i]==0&&replaced==false)
			{
				new_eo=new_eo+ 1;
				replaced=true;
			}
			else
				new_eo=new_eo+openedElements[i];
			//alert(new_eo);
		}
	}

	var the_form;
	the_form=document.getElementById("listestates_form");
	profile_link="?page=listestates_extraCriterias&region="+the_form.srch_region.value;
	if((typeof the_form.ajax_huistype)!="undefined")	
		profile_link+="&huistype="+the_form.ajax_huistype.value;
	else
		profile_link+="&huistype=0";
		
	if((typeof the_form.ajax_prijs_van)!="undefined")
		profile_link+="&prijs_van="+the_form.ajax_prijs_van.value;
	else
		profile_link+="&prijs_van=";
		
	if((typeof the_form.ajax_prijs_tot)!="undefined")
		profile_link+="&prijs_tot="+the_form.ajax_prijs_tot.value;
	else
		profile_link+="&prijs_tot=";
		
	if((typeof the_form.ajax_grond)!="undefined")
		profile_link+="&grond="+the_form.ajax_grond.value;
	else
		profile_link+="&grond=";
		
	if((typeof the_form.ajax_woon)!="undefined")
		profile_link+="&woon="+the_form.ajax_woon.value;
	else
		profile_link+="&woon=";
		
	if((typeof the_form.ajax_kamers)!="undefined")
		profile_link+="&kamers="+the_form.ajax_kamers.value;	
	else
		profile_link+="&kamers=";		
	
	theType=document.getElementById("type_to_recover").innerHTML;	
	
	var theExtraValues="&extraValues="+document.getElementById("extraValues_element").innerHTML;
	if (typeOpened)
		var theOrder="&eo="+document.getElementById("eo_element").innerHTML;
	else
		var theOrder="&eo="+new_eo;
	var theZipList="&zipList="+document.getElementById("ziplist_element").innerHTML;
	profile_link+="&purpose="+theType;
	profile_link+=theExtraValues;	
	profile_link+=theOrder;	
	profile_link+=theZipList;	
	//alert (profile_link);
	window.location=profile_link;
}


function save_type()
{

	var the_form;
	the_form=document.getElementById("listestates_form");
	profile_link=the_form.action;
		
				
	inputsValues=calculateTypes();
	//alert(inputsValues);	
	
	
	var theOrder="&eo="+document.getElementById("eo_element").innerHTML;	
	var theZipList="&zipList="+document.getElementById("ziplist_element").innerHTML;
	profile_link+=inputsValues+theOrder;	
	profile_link+=theZipList;	
	//alert (profile_link);
	window.location=profile_link;
}

/*
function activate_type()
{
	//document.getElementById("").innerHTML
	eoElement=document.getElementById("eo_element").innerHTML;
	//alert(eoElement);
	openedElements=eoElement.split(",");
	var typeOpened;
	typeOpened=false;
	for(i=0;i<5;i++)
	{
		if (openedElements[i]==1)
		{	
			typeOpened=true;
		}
	}	
	
	
	
	var the_form;
	the_form=document.getElementById("listestates_form");
	profile_link="?page=new_listestates&region="+the_form.srch_region.value;
	if((typeof the_form.ajax_huistype)!="undefined")	
		profile_link+="&huistype="+the_form.ajax_huistype.value;
	else
		profile_link+="&huistype=";
		
	if((typeof the_form.ajax_prijs_van)!="undefined")
		profile_link+="&prijs_van="+the_form.ajax_prijs_van.value;
	else
		profile_link+="&prijs_van=";
		
	if((typeof the_form.ajax_prijs_tot)!="undefined")
		profile_link+="&prijs_tot="+the_form.ajax_prijs_tot.value;
	else
		profile_link+="&prijs_tot=";
		
	if((typeof the_form.ajax_grond)!="undefined")
		profile_link+="&grond="+the_form.ajax_grond.value;
	else
		profile_link+="&grond=";
		
	if((typeof the_form.ajax_woon)!="undefined")
		profile_link+="&woon="+the_form.ajax_woon.value;
	else
		profile_link+="&woon=";
		
	if((typeof the_form.ajax_kamers)!="undefined")
		profile_link+="&kamers="+the_form.ajax_kamers.value;	
	else
		profile_link+="&kamers=";
		
	if (document.getElementById("extraOptionsShow").innerHTML=="1")
	{
		profile_link+="&extra=0";	
		//we send him to the page with extra=0 meaning closed criterias		
	}
	else
	{
		profile_link+="&extra=1";	
		//alert(typeOpened);
		if (typeOpened==false)
		{
			ajax_add_criteria(0);
		}
		//we send him to the page with extra=1 meaning opened criterias
	}
			
	inputsValues=calculateTypes();
	//alert(inputsValues);
	
	
	
	var theOrder="&eo="+document.getElementById("eo_element").innerHTML;
	var theZipList="&zipList="+document.getElementById("ziplist_element").innerHTML;
	profile_link+=inputsValues+theOrder;	
	profile_link+=theZipList;	
	//alert (profile_link);
	window.location=profile_link;
}


function activate_type()
{
	//operationType=0 => close  else => open
	
	if (document.getElementById("typeButton").innerHTML=="Verbeg extra criteria")
	{
		document.getElementById("typeButton").innerHTML="Toon extra Criteria";
		operationType=0;
	}
	else
	{
		document.getElementById("typeButton").innerHTML="Verbeg extra criteria";
		operationType=1;
	}
	
	//ajax_select_option(1);	
	eoElement=document.getElementById("eo_element").innerHTML;
	//alert(eoElement);
	openedElements=eoElement.split(",");	
	var typeOpened;
	typeOpened=false;
	for(i=0;i<5;i++)
	{
		if (openedElements[i]==1)
		{	
			typeOpened=true;
		}
	}	
	
	if (operationType)
	{
		if (typeOpened==false)
		{
			ajax_add_criteria(0);
		}
		document.getElementById("extraOptions").style.display="";
	}
	else
	{
		//ajax_del_criteria(typePosition);
		document.getElementById("extraOptions").style.display="none";
		
	}
	//onclick=""	
	
}
*/
//-->