/**
 * @author zahir
 */


function formatItem(row)
{
	return row[0];
}

/*
function lookupAjax(){
var oSuggest = $("#CityAjax")[0].autocompleter;
oSuggest.findValue();
return false;
}*/

function findValue(li) 
{
	if( li == null ) return alert("No match!");	
	// if coming from an AJAX call, let's use the CityId as the value
	if( !!li.extra ) var sValue = li.extra[0];	
	// otherwise, let's just display the value in the text box
	else var sValue = li.selectValue;	
	//alert("The value you selected was: " + sValue);
}
//clic sur l'item
function selectItem(li)
{
	findValue(li);
}

$(document).ready(function() 
{	

	if($("#searchprof"))
	{
	    $("#profLocality").autocomplete("/autocomplete/locality",{ minChars:3, width: 180,autoFill:true });	
		
		$("#profActivity").autocomplete("/autocomplete/activity",{cacheLength:1,matchSubset:1,mustMatch :0,autoFill:true});
	
		$("#searchprof").click
		(
			function()
			{
				var is_ok = false;
				is_ok = testSearch($("#profLocality").val(),$("#profActivity").val());

		    	if(is_ok == true)
			 		$("#profform").submit();
				else
				 return false;
			}	
		);		
	}
	
	
	if($("#searchclub"))
	{
	    $("#clubLocality").autocomplete("/autocomplete/locality",{ minChars:3, width: 180,autoFill:true });	
		
		$("#clubActivity").autocomplete("/autocomplete/activity",{cacheLength:1,matchSubset:1,mustMatch :0,autoFill:true});
	
		$("#searchclub").click
		(
			function()
			{
				var is_ok = false;
				is_ok = testSearch($("#clubLocality").val(),$("#clubActivity").val());

		    	if(is_ok == true)
			 		$("#clubform").submit();
				else
				 return false;
			}	
		);			
		
	}
	
	
    $("#partnerLocality").autocomplete("/autocomplete/locality",{ minChars:3, width: 180,autoFill:true });	
	
	$("#partnerActivity").autocomplete("/autocomplete/activity",{cacheLength:1,matchSubset:1,mustMatch :0,autoFill:true});

	$("#search").click
	(
		function()
		{
			var is_ok = false;
			is_ok = testSearch($("#partnerLocality").val(),$("#partnerActivity").val());

		    if(is_ok == true)
			 $("#partnerform").submit();
			else
			 return false;
		}	
	);
		
	// partner form home page
	
	$("#searchepar").click
	(
		function()
		{
			var is_ok = false;
			is_ok = testSearch($("#partnerLocality").val(),$("#partnerActivity").val());

		    if(is_ok == true)
			 $("#partnerform").submit();
			else
			 return false;
		}	
	);	
	
	
	$("#rechequipe").click
	(
		function()
		{
			$("#partcherch_p1").css('color', "#A5C3FF");
			$("#partcherch_p2").css('color', "#A5C3FF");
			$("#teamcherch_p1").css('color', "#FFF");
			$("#teamcherch_p2").css('color', "#FFF");
		}	
	);
	
	$("#rechpartner").click
	(
		function()
		{
			$("#partcherch_p1").css('color', "#FFF");
			$("#partcherch_p2").css('color', "#FFF");
			$("#teamcherch_p1").css('color', "#A5C3FF");
			$("#teamcherch_p2").css('color', "#A5C3FF");
		}	
	);		
	
 });
 
 
 function testSearch(localite,activite)
 {

 	//si il ne rempli ni l'activité ni la localite
 	if(activite == "Activité (tapez 3 car.)" || localite == "ex: 75015,paris,75")
	{

		  return false;
	}
	else if(activite == "ACTIVITÉ (tapez 3 car. et sélectionnez)" || localite == "Localité (ex: 75015,paris,75)")
	{
		return false;
	}
	else
	{
		return true;
	}
 }

