endWidth = 1;
function doMotion(close) {
	//Hander function only - probably not needed..
    var openOutDiv = new Object();
    
    //Allow us to resized    
    endWidth = (endWidth < 2 || close == 'open') ? 494 : 1;
    if (close == 'close') {
		endWidth = 1;
	}
    
    //Does the motion stuff here..
    var slide_out_content = $('slide_out_content');
    var slide_out_div = $('slide_out_div');
    if(endWidth >= 1) {
    	slide_out_content.style.display = 'block';
    	slide_out_div.style.width = '510px';
    }
    zzz = new Tween(slide_out_content.style,'width',Tween.strongEaseInOut,parseInt(slide_out_content.style.width),endWidth,1,'px');
    zzz.fixTime;
    zzz.start();
    
	//Only use the below if you need a handler for end of motion..
    zzz.addListener(openOutDiv);
    openOutDiv.onMotionFinished = function() {
        if(endWidth==1) {
        	slide_out_content.style.display = 'none';
        	slide_out_div.style.width = '16px';
        }
    }
}

function showResults()
{   
    hiddeninput = document.getElementById('SearchShowresult');
    hiddeninput.value = 'true';
    doMotion('close');

}

/*var $property_search_level2 = array(
				'bedrooms'=>array('1','2','3','4','5+'),
				'pool'=>array('yes'=>'Yes','no'=>'No','possible'=>'Possible'),
				'living_space'=>array('Less than 50 m2','Less than 100 m2','More than 100 m2'),
				'heating'=>array('electric'=>'Electric','gas'=>'Gas','fuel'=>'Fuel','rac'=>'Reversible Air Conditioning','geothermic'=>'Geothermic','none'=>'No'),
				'heating_delivery'=>array('radiators'=>'Radiators','underfloor'=>'Underfloor','vents'=>'Vents','mixed'=>'Mixed'),
				'hot_water'=>array('gas'=>'Gas','electric'=>'Electric','fuel'=>'Fuel','solar'=>'Solar','geothermic'=>'Geothermic','none'=>'No'),
				'air_con'=>array('yes'=>'Yes','no'=>'No','part'=>'Part'),
				'parking'=>array('private'=>'Yes – Private','public'=>'Yes – Public','underground'=>'Yes - Underground','1'=>'Yes – 1 car garage','2'=>'Yes – 2 car garage','none'=>'No'),
				'renovation'=>array('none'=>'No','minor'=>'Minor','major'=>'Major'),
				'refurbishment'=>array('none'=>'No','minor'=>'Minor','major'=>'Major'),
				'internet'=>array('none'=>'None','dialup'=>'Dial Up','broadband'=>'Broadband'),
				'renewable_energy'=>array('none'=>'None','solar'=>'Solar Panels','other'=>'Other')
		);*/

function removeAllOptions(selectbox)
{
var i;
for(i=selectbox.options.length-1;i>=0;i--)
{
selectbox.remove(i);
}
}

function addOption(selectbox,text,value )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}

function removeSearchOption(x)
{
	var div_to_hide = $('location_property_' + x);
	//div_to_hide.removeChild()
	//$('location_property_1').removeChild('SearchKey1Level1');
	//$('location_property_1').remove();

	var hidden_input_to_change = $('SearchKey' + x + 'Type');
	var first_select = $('SearchKey' + x + 'Level1');
	var second_select = $('SearchKey' + x + 'Level2');
	first_select.focus();
	first_select.selectedIndex=0;
	second_select.focus();
	set_level2(x);
	hidden_input_to_change.value = 'hidden';
	div_to_hide.hide();
}

function addSearchOption(type)
{
	var added = 0;
	if(type=='location')
	{
		location_search_divs = $$('div.location_search');
		for(x=0;x<location_search_divs.length;x++)
		{
			if(location_search_divs[x].getStyle('display')=='none')
			{
				if(added==0)
				{
					location_search_divs[x].show();
					location_search_div_children = location_search_divs[x].childElements();
					location_search_div_children[0].value = 'location';
					added=1;
				}
			}
		}
	}
	else
	{
		property_search_divs = $$('div.property_search');
		for(x=0;x<property_search_divs.length;x++)
		{
			if(property_search_divs[x].getStyle('display')=='none')
			{
				if(added==0)
				{
					property_search_divs[x].show();
					property_search_div_children = property_search_divs[x].childElements();
					property_search_div_children[0].value = 'property';
					added=1;
				}
			}
		}
	}
}

function changeSliderImage()
{
	contractSelect = $('SearchContract');
	if(contractSelect.value == 'rent')
	{
		background = $('price_slider_background');
		style = new String(background.getStyle('background-image'));
		newstlye = style.replace('slider.png','slider2.png');
		background.style.backgroundImage='url(/img/images/buyer_side_fr/slider2.png)';
		//background.setStyle({'background-image':style});
	}
	else
	{
		background = $('price_slider_background');
		style = background.getStyle('background-image');
		newstyle = style.replace('slider2.png','slider.png');
		background.style.backgroundImage='url(/img/images/buyer_side_fr/slider.png)';
		//background.setStyle({'background-image':style});
	}
}

function set_level2(x)
{
	var hidden_input = $('SearchKey' + x + 'Type')
	var first_select = $('SearchKey' + x + 'Level1')
	var second_select = $('SearchKey' + x + 'Level2')
	
	removeAllOptions(second_select);
	
	if(hidden_input.value=='location')
	{
		if(first_select.value=='environment')
		{
			//second_select.innerHTML = '<option value="1">Low Density Population</option><option value="2">Medium Density Population</option><option value="3">High Density Population</option>';
			addOption(second_select,"Peu peulé", "1");
			addOption(second_select,"Moyennement peuplé", "2");
			addOption(second_select,"Très peuplé", "3");

		}
		else if(first_select.value=='0')
		{
			
		}
		else
		{
			//second_select.innerHTML = '<option value="1">Within walking distance</option><option value="2">&lt; 15 mins en voiture</option><option value="3">&lt; 30 mins en voiture</option><option value="4">&lt; 45 mins en voiture</option><option value="5">&lt; 60 mins en voiture</option><option value="6">+ 60 mins en voiture</option>';
			addOption(second_select,"Accessible à pied", "1");
			addOption(second_select,"< 15 mins en voiture", "2");
			addOption(second_select,"< 30 mins en voiture", "3");
			addOption(second_select,"< 45 mins en voiture", "4");
			addOption(second_select,"< 60 mins en voiture", "5");
			addOption(second_select,"+ 60 mins en voiture", "6");

		}
	}
	else if(hidden_input.value=='property')
	{
		if(first_select.value=='bedrooms')
		{
			addOption(second_select,"1", "1");
			addOption(second_select,"2", "2");
			addOption(second_select,"3", "3");
			addOption(second_select,"4", "4");
			addOption(second_select,"5+", ">5");
		}
		else if(first_select.value=='pool')
		{
			addOption(second_select,"Oui", "yes");
			addOption(second_select,"Non", "no");
			addOption(second_select,"Possible", "possible");
		}
		else if(first_select.value=='living_space')
		{
			addOption(second_select,"Moins de 50 m2", "<50");
			addOption(second_select,"Moins de 100 m2", "<100");
			addOption(second_select,"Plus de 100 m2", ">=100");
		}
		else if(first_select.value=='heating')
		{
			addOption(second_select,"Electrique", "electric");
			addOption(second_select,"Gaz", "gas");
			addOption(second_select,"Fioul", "fuel");
			addOption(second_select,"Climatisation réversible", "rac");
			addOption(second_select,"Géothermique", "geothermic");
			addOption(second_select,"Aucun", "none");
		}
		else if(first_select.value=='heating_delivery')
		{
			addOption(second_select,"Radiateurs", "radiators");
			addOption(second_select,"Au sol", "underfloor");
			addOption(second_select,"Bouche d'aération", "vents");
			addOption(second_select,"Mélange / Appareil varié", "mixed");
		}
		else if(first_select.value=='hot_water')
		{
			addOption(second_select,"Gaz", "gas");
			addOption(second_select,"Electrique", "electric");
			addOption(second_select,"Fioul", "fuel");
			addOption(second_select,"Solaire", "solar");
			addOption(second_select,"Géothermic", "geothermic");
			addOption(second_select,"Aucun", "none");
		}
		else if(first_select.value=='air_con')
		{
			addOption(second_select,"Oui", "yes");
			addOption(second_select,"Non", "no");
			addOption(second_select,"Part", "part");
		}
		else if(first_select.value=='parking')
		{
			addOption(second_select,"Oui - Privé", "private");
			addOption(second_select,"Oui - Voie publique", "public");
			addOption(second_select,"Oui - Sous sol", "underground");
			addOption(second_select,"Oui - 1 voiture garage", "1");
			addOption(second_select,"Oui - 2 voitures garage", "2");
			addOption(second_select,"Non", "none");
		}
		else if(first_select.value=='renovation'||first_select.value=='refurbishment')
		{
			addOption(second_select,"No", "none");
			addOption(second_select,"Minimum", "minor");
			addOption(second_select,"Importante", "major");
		}
		else if(first_select.value=='internet')
		{
			addOption(second_select,"Aucun", "none");
			addOption(second_select,"Bas débit", "dialup");
			addOption(second_select,"Haut débit", "broadband");
		}
		else if(first_select.value=='renewable_energy')
		{
			addOption(second_select,"Aucun", "none");
			addOption(second_select,"Paneaux solaires", "solar");
			addOption(second_select,"Autre", "other");
		}
	}
}
