var ajax = new Array();

function load_ajax_sack()
{
	var head= document.getElementsByTagName('head')[0];
	var script= document.createElement('script');
	script.type= 'text/javascript';
	script.src= 'admin/include/ajax.js';
	head.appendChild(script);

}



function cautare_annonce()
{
	var type=0;
	var stype=0;
	var secteur=0;
	
	var link="";
	
	var type_text=0;
	var stype_text=0;
	var secteur_text=0;
	
	type=document.getElementById('type');
	stype=document.getElementById('stype');
	secteur=document.getElementById('secteur');
	
	
	/*
	type_text=type.options[type.selectedIndex].text;
	
	if(stype.selectedIndex>=0)
		stype_text=stype.options[stype.selectedIndex].text;
		
	secteur_text=secteur.options[secteur.selectedIndex].text;
	
	
	
	var secteur_id=secteur.options[secteur.selectedIndex].value;
	var type_id=type.options[type.selectedIndex].value;
	
	if(stype.selectedIndex>=0)
		var stype_id=stype.options[stype.selectedIndex].value;
	
	
	if(type_id!=0)
		link+=type_text.replace(" ","_");
	
	if(stype_id!=0 && type_id!=0)
		link+=","+stype_text.replace(" ","_");
	
	if(secteur_id!=0)
		link+=","+secteur_text.replace(" ","_");
		
	*/
		
	
	//new
	if(type.selectedIndex>=0)
		var type_id=type.options[type.selectedIndex].value;
	if(stype.selectedIndex>=0)
		var stype_id=stype.options[stype.selectedIndex].value;
	if(secteur.selectedIndex>=0)
		var secteur_id=secteur.options[secteur.selectedIndex].value;
	
	
	var prix_min=document.getElementById('prix_min').value;
	var prix_max=document.getElementById('prix_max').value;
	
	var link_prim="listing.php";
	
	if(type_id>0)
		link+="&type="+type_id;
	if(stype_id>0)
		link+="&stype="+stype_id;
	if(secteur_id>0)
		link+="&secteur="+secteur_id;
		
	if(prix_min!="")
		link+="&prix_min="+prix_min;
	if(prix_max!="")
		link+="&prix_max="+prix_max;
	
	//end new
	link=link.replace("&"," ");
	link=link.replace(/^\s+|\s+$/g, '') ;
	link=link.replace(" ","&");
	if(link.length>0)
		link="?"+link;
		
	self.location="/"+link_prim+link;
	//alert("/"+link_prim+link);
	
}

function update_stype(id_type)
{
	
		document.getElementById('stype').options.length = 0;	
	
		var index = ajax.length;
		ajax[index] = new sack();
		
		ajax[index].requestFile = 'include/ajax_fnc.php?action=update_stype&id_type='+id_type;
		ajax[index].onCompletion = function(){ eval(ajax[index].response) };	
		ajax[index].runAJAX();		// Execute AJAX function
	
}

function trier(link)
{
	if(link!='')
		link="listing.php?"+link+"&";
	else
		link='listing.php?';
	
	var tri_prix=document.getElementById('trier_prix');
	var tri_prix_value=tri_prix.options[tri_prix.selectedIndex].value
	
	var tri_prix_link="tri_prix="+tri_prix_value;
	
	
	var tri_secteur=document.getElementById('trier_secteur');
	var tri_secteur_value=tri_secteur.options[tri_secteur.selectedIndex].value
	
	var tri_secteur_link="tri_secteur="+tri_secteur_value;
	
	
	self.location=link+tri_prix_link+"&"+tri_secteur_link;
	
	
}

